Пример #1
0
    private void SetResutlGraph(DataSet iDs)
    {
        DataSet dsGrph = iDs.Copy();

        dsGrph.Tables[0].Columns.Add("GR_RATE_MS", typeof(double));
        dsGrph.Tables[0].Columns.Add("GR_RATE_TS", typeof(double));

        for (int i = 0; i < dsGrph.Tables[0].Rows.Count; i++)
        {
            if (dsGrph.Tables[0].Rows[i]["AC_RATE_MS"].ToString() == "-")
            {
                dsGrph.Tables[0].Rows[i]["AC_RATE_MS"] = "0";
            }
            dsGrph.Tables[0].Rows[i]["GR_RATE_MS"] = Convert.ToDouble(dsGrph.Tables[0].Rows[i]["AC_RATE_MS"].ToString());

            if (dsGrph.Tables[0].Rows[i]["AC_RATE_TS"].ToString() == "-")
            {
                dsGrph.Tables[0].Rows[i]["AC_RATE_TS"] = "0";
            }
            dsGrph.Tables[0].Rows[i]["GR_RATE_TS"] = Convert.ToDouble(dsGrph.Tables[0].Rows[i]["AC_RATE_TS"].ToString());
        }

        // 당월그래프
        MSCharts.DundasChartBase(chartMM, ChartImageType.Jpeg, 385, 230
                                 , BorderSkinStyle.Emboss, ChartBorderLineColor, 2
                                 , Color.FromArgb(0xFF, 0xFF, 0xFE)
                                 , Color.FromArgb(0xFF, 0xFF, 0xFE), Color.FromArgb(0x20, 0x80, 0xD0), ChartDashStyle.Solid
                                 , -1
                                 , ChartHatchStyle.None, MsGradientType.TopBottom, MsAntiAliasing.None);

        chartMM.DataSource = dsGrph;

        Series series1 = MSCharts.CreateSeries(chartMM, "serPlan", "Default", "계획", null, SeriesChartType.Column, 1, GetChartColor2(0), Color.FromArgb(180, 26, 59, 105), Color.FromArgb(64, 0, 0, 0), 1, 9, Color.FromArgb(64, 64, 64));
        Series series2 = MSCharts.CreateSeries(chartMM, "serActl", "Default", "실적", null, SeriesChartType.Column, 1, GetChartColor2(1), Color.FromArgb(180, 26, 59, 105), Color.FromArgb(64, 0, 0, 0), 1, 9, Color.FromArgb(64, 64, 64));
        Series series3 = MSCharts.CreateSeries(chartMM, "serRate", "Default", (kpiType == "BTY" ? "한계초과율" : "달성율"), null, SeriesChartType.Line, 1, GetChartColor2(2), GetChartColor2(2), Color.FromArgb(64, 0, 0, 0), 1, 9, Color.FromArgb(64, 64, 64));

        series3.YAxisType = AxisType.Secondary;

        series1.YValueMembers = "TARGET_MS";
        series2.YValueMembers = "RESULT_MS";
        series3.YValueMembers = "GR_RATE_MS";
        series1.XValueMember  = "MM";

        series1.ToolTip = "#VALY{N0}";
        series2.ToolTip = "#VALY{N0}";
        series3.ToolTip = "#VALY{P0}";

        string sChartArea = chartMM.Series[series2.Name].ChartArea;

        chartMM.ChartAreas[sChartArea].AxisY.LabelStyle.Format  = "N0";
        chartMM.ChartAreas[sChartArea].AxisY2.LabelStyle.Format = "P0";

        //DundasAnimations.DundasChartBase(chartMM, AnimationTheme.None, -1, -1, false, 1);
        //DundasAnimations.GrowingAnimation(chartMM, series1, 1.0, 1.0, true);
        //DundasAnimations.GrowingAnimation(chartMM, series2, 2.0, 2.0, true);
        //DundasAnimations.GrowingAnimation(chartMM, series3, 2.0, 1.0, true);

        chartMM.DataBind();
    }
Пример #2
0
        /// <summary></summary>
        private void InitializeFolderTreeView()
        {
            try
            {
                this.tvFolders.Nodes.Clear();

                DataSet folderSet = AppMediator.SINGLETON.GetFolderList();

                TreeNodeCollection nodeCols = AppMediator.SINGLETON.GetRootTreeNodeCollection(this.tvFolders);

                DataView dataView = folderSet.Copy().Tables[0].DefaultView;
                dataView.RowFilter = "parentid = ''";
                dataView.Sort      = "fileid";

                DataTable dataTable = folderSet.Copy().Tables[0];

                for (int i = 0; i < dataView.Count; i++)
                {
                    DataRowView rowview = dataView[i];

                    string name   = rowview["displayname"].ToString();
                    string fileid = rowview["fileid"].ToString();

                    TreeNode treeNode = new TreeNode(name);
                    treeNode.Tag = rowview.Row;

                    if (rowview["noauth"].ToString() == "0")
                    {
                        treeNode.ForeColor = Color.Red;
                    }

                    nodeCols.Add(treeNode);

                    this.BuildFolder(treeNode, fileid, dataTable);
                }

                this.tvFolders.Sorted = true;

                this.tvFolders.Nodes[0].Expand();
                this.tvFolders.Focus();
            }
            catch (Exception ex)
            {
                OFileLog.SNG.WriteLog(ex.ToString());
            }
        }
Пример #3
0
 private void Tao_dataset()
 {
     ds = new DataSet();
     ds.ReadXml("..\\..\\..\\xml\\d_solankham.xml");
     ds.Tables[0].Columns.Add("sophieu", typeof(decimal));
     dsxml = new DataSet();
     dsxml = ds.Copy();
 }
Пример #4
0
 public void CancelUpdate()
 {
     if (!_dataChanged)
     {
         return;
     }
     DsData = _dsDataTmp.Copy();
 }
Пример #5
0
 public Archive_Data(DataSet ds, ImportTemplateSettings ims, List <string> asl, int rn)
 {
     DataToArchiveDataSet = new DataSet(); //start with clean dataset
     DataToArchiveDataSet = ds.Copy();     //Data to archive from the main data dataset
     ImportSettings       = ims;           //import settings show where in the dataset each field is located
     archiveStringList    = asl;           //string data from main app controls
     ReceiptNumber        = rn;            //receipt number for export data
 }
 public QCPalletSelection(DataSet ds, ImportTemplateSettings ims, List <string> asl, int rn)
 {
     DataForQCDataSet = new DataSet(); //start with clean dataset
     DataForQCDataSet = ds.Copy();     //Data for QC selection from the main data dataset
     ImportSettings   = ims;           //import settings show where in the dataset each field is located
     QCStringList     = asl;           //string data from main app controls
     ReceiptNumber    = rn;            //receipt number for export data
 }
Пример #7
0
 public DataSet getDataSet()
 {
     if (_data == null)
     {
         refreshSource();
     }
     return(_data.Copy());
 }
Пример #8
0
 public DicomFile GetHeader(bool forceComplete)
 {
     if (forceComplete)
     {
         LoadFullHeader();                 //Make sure the full header's loaded.
     }
     //Return a copy of whatever we've got.
     return(new DicomFile(null, MetaInfo.Copy(), DataSet.Copy()));
 }
Пример #9
0
        void ResetTableCt()
        {
            string stt_rec = DsPrint.Tables["TablePH"].DefaultView[0]["stt_rec"].ToString();

            if (DsTmpPrint != null)
            {
                DsPrint = DsTmpPrint.Copy();
                DsPrint.Tables["TablePH"].DefaultView.RowFilter = "stt_rec= '" + stt_rec + "'";
                DsPrint.Tables["TableCT"].DefaultView.RowFilter = "stt_rec= '" + stt_rec + "'";
                DsPrint.Tables["TableCT"].DefaultView.Sort      = "stt_rec0";
                GridSearch.DSource = DsPrint;
            }
            //if (DsTmpPrint != null && DsPrint.Tables["TableCT"].Rows.Count > DsTmpPrint.Rows.Count)
            //{

            //    //lay ra cac dong trang va dong ghi chu
            //    DataRow[] _row = DsPrint.Tables["TableCT"].Select("tag = 1");
            //    foreach (DataRow dr in _row)
            //    {
            //        //delete các row có trong grdcp
            //        DsPrint.Tables["TableCT"].Rows.Remove(dr);
            //    }

            //    DsPrint.Tables["TableCT"].DefaultView.RowFilter = "stt_rec= '" + stt_rec + "'";


            //}
            ////thêm dòng chiết khấu
            //decimal t_ck = Convert.ToDecimal(DsPrint.Tables["TablePH"].DefaultView[0]["t_ck"]);
            //decimal t_ck_nt = Convert.ToDecimal(DsPrint.Tables["TablePH"].DefaultView[0]["t_ck_nt"]);
            //if (t_ck != 0 || t_ck_nt != 0)
            //{
            //    DataRow newrow = DsPrint.Tables["TableCT"].NewRow();
            //    newrow["stt_rec"] = stt_rec;
            //    newrow["ten_vt"] = "Chiết khấu";
            //    newrow["tien2"] = t_ck;
            //    newrow["tien_nt2"] = t_ck_nt;
            //    newrow["tag"] = 1;
            //    DsPrint.Tables["TableCT"].Rows.Add(newrow);
            //}
            //int rowCountCT = DsPrint.Tables["TableCT"].DefaultView.Count;
            ////Thêm số dòng cho đủ ngầm định
            //if (rowCountCT < so_dong_in)
            //{
            //    for (int k = rowCountCT; k < so_dong_in; k++)
            //    {
            //        DataRow row = DsPrint.Tables["TableCT"].NewRow();
            //        row["stt_rec"] = stt_rec;
            //        row["tag"] = 1;
            //        DsPrint.Tables["TableCT"].Rows.Add(row);
            //    }

            //}

            //DsPrint.Tables["TableCT"].DefaultView.RowFilter = "stt_rec= '" + stt_rec + "'";
            //GridSearch.DSource = DsPrint;
        }
Пример #10
0
    // <Snippet1>
    private void CopyDataSet(DataSet dataSet)
    {
        // Create an object variable for the copy.
        DataSet copyDataSet;

        copyDataSet = dataSet.Copy();

        // Insert code to work with the copy.
    }
Пример #11
0
        public DicomFile LoadDicomFile(LoadSopDicomFileArgs args)
        {
            if (args.ForceCompleteHeader)
            {
                LoadFullHeader(args.IncludePixelData);
            }

            return(new DicomFile(null, MetaInfo.Copy(), DataSet.Copy()));
        }
Пример #12
0
        //Activate This Construntor to log All To Standard output
        //public TestClass():base(true){}

        //Activate this constructor to log Failures to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, false){}


        //Activate this constructor to log All to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, true){}

        //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

        public void run()
        {
            Exception exp = null;

            DataSet ds1 = new DataSet();

            ds1.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
            ds1.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());

            //add data to check GH bug of DataSet.ReadXml of empty strings
            ds1.Tables[1].Rows.Add(new object[] { 7, 1, string.Empty, string.Empty, new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
            ds1.Tables[1].Rows.Add(new object[] { 7, 2, " ", "		", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
            ds1.Tables[1].Rows.Add(new object[] { 7, 3, "", "", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });


            System.IO.StringWriter   sw    = new System.IO.StringWriter();
            System.Xml.XmlTextWriter xmlTW = new System.Xml.XmlTextWriter(sw);

            //write xml file, data only
            ds1.WriteXml(xmlTW);
            //ds1.WriteXml("C:\\Temp\\q.xml");

            //copy both data and schema
            DataSet ds2 = ds1.Copy();

            //clear the data
            ds2.Clear();
            System.IO.StringReader   sr    = new System.IO.StringReader(sw.ToString());
            System.Xml.XmlTextReader xmlTR = new System.Xml.XmlTextReader(sr);
            ds2.ReadXml(xmlTR);

            //check xml data
            try
            {
                BeginCase("ReadXml - Tables count");
                Compare(ds1.Tables.Count, ds2.Tables.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("ReadXml - Table 1 row count");
                Compare(ds1.Tables[0].Rows.Count, ds2.Tables[0].Rows.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("ReadXml - Table 2 row count");
                Compare(ds1.Tables[1].Rows.Count, ds2.Tables[1].Rows.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }
        }
Пример #13
0
        //Activate This Construntor to log All To Standard output
        //public TestClass():base(true){}

        //Activate this constructor to log Failures to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, false){}


        //Activate this constructor to log All to a log file
        //public TestClass(System.IO.TextWriter tw):base(tw, true){}

        //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES

        public void run()
        {
            Exception exp = null;

            DataSet ds1 = new DataSet();

            ds1.Tables.Add(GHTUtils.DataProvider.CreateParentDataTable());
            ds1.Tables.Add(GHTUtils.DataProvider.CreateChildDataTable());

            //add data to check GH bug of DataSet.ReadXml of empty strings
            ds1.Tables[1].Rows.Add(new object[] { 7, 1, string.Empty, string.Empty, new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
            ds1.Tables[1].Rows.Add(new object[] { 7, 2, " ", "		", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });
            ds1.Tables[1].Rows.Add(new object[] { 7, 3, "", "", new DateTime(2000, 1, 1, 0, 0, 0, 0), 35 });


            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            //write xml file, data only
            ds1.WriteXml(ms);

            //copy both data and schema
            DataSet ds2 = ds1.Copy();

            //clear the data
            ds2.Clear();

            ms.Position = 0;
            ds2.ReadXml(ms);


            //check xml data
            try
            {
                BeginCase("ReadXml - Tables count");
                Compare(ds1.Tables.Count, ds2.Tables.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("ReadXml - Table 1 row count");
                Compare(ds1.Tables[0].Rows.Count, ds2.Tables[0].Rows.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            try
            {
                BeginCase("ReadXml - Table 2 row count");
                Compare(ds1.Tables[1].Rows.Count, ds2.Tables[1].Rows.Count);
            }
            catch (Exception ex)     { exp = ex; }
            finally { EndCase(exp); exp = null; }

            ms.Close();
        }
Пример #14
0
        /// <summary>
        /// Assign the DataSet to the report.
        /// </summary>
        private void AssignDataSet()
        {
            DataSet reportData = _reportData.Copy();

            // Remove primary key info. CR9 does not appreciate this information!!!
            foreach (DataTable dataTable in reportData.Tables)
            {
                foreach (DataColumn dataColumn in dataTable.PrimaryKey)
                {
                    dataColumn.AutoIncrement = false;
                }
                dataTable.PrimaryKey = null;
            }

            // Now assign the dataset to all tables in the main report
            //
            _reportDocument.SetDataSource(reportData);

            //for (int i = 0; i < _reportDocument.Database.Tables.Count; ++i)
            //{
            //    Table t = null;
            //    try
            //    {
            //        t = _reportDocument.Database.Tables[reportData.Tables[i].TableName];
            //    }
            //    catch (Exception)
            //    {
            //    }
            //    if (t != null)
            //    {
            //        t.SetDataSource(reportData.Tables[i]);
            //    }
            //    else
            //    {
            //        _reportDocument.Database.Tables[i].SetDataSource(reportData.Tables[i]);
            //    }
            //}


            // Now loop through all the sections and its objects to do the same for the subreports
            //
            foreach (CrystalDecisions.CrystalReports.Engine.Section section in _reportDocument.ReportDefinition.Sections)
            {
                // In each section we need to loop through all the reporting objects
                foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
                {
                    if (reportObject.Kind == ReportObjectKind.SubreportObject)
                    {
                        SubreportObject subReport   = (SubreportObject)reportObject;
                        ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);

                        subDocument.SetDataSource(reportData);
                    }
                }
            }
        }
Пример #15
0
        private void exp_excel(bool print)
        {
            try
            {
                ttb.check_process_Excel();
                ds = dsxml.Copy();
                int be = 2, dong = 4, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1;
                tenfile = ttb.Export_Excel(ds, "dutru");
                oxl     = new Excel.Application();
                owb     = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));
                osheet  = (Excel._Worksheet)owb.ActiveSheet;
                oxl.ActiveWindow.DisplayGridlines = true;

                for (int i = 0; i < be; i++)
                {
                    osheet.get_Range(ttb.getIndex(i) + "1", ttb.getIndex(i) + "1").EntireRow.Insert(Missing.Value);
                }
                osheet.get_Range(ttb.getIndex(be - 1) + dong.ToString(), ttb.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.00";
                osheet.get_Range(ttb.getIndex(0) + "3", ttb.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline;
                int pos = 7;
                foreach (DataRow r in dtmakp.Select("makp<>''", "stt,makp"))
                {
                    osheet.Cells[dong - 1, pos] = r["tenkp"].ToString();
                    pos += 1;
                }
                //osheet.Cells[dong-1,pos]="Tồn "+makho.Text;
                for (int i = 0; i < 6; i++)
                {
                    osheet.Cells[dong - 1, i + 1] = get_ten(i);
                }
                orange           = osheet.get_Range(ttb.getIndex(0) + "1", ttb.getIndex(socot) + sodong.ToString());
                orange.Font.Name = "Arial";
                orange.Font.Size = 8;
                orange.EntireColumn.AutoFit();

                oxl.ActiveWindow.DisplayZeros = false;
                osheet.Cells[1, 2]            = ttb.Syte; osheet.Cells[2, 2] = ttb.Tenbv;
                s_mmyy             = tu.Value.ToString().PadLeft(2, '0') + yyyy.Value.ToString().PadLeft(4, '0').Substring(2, 2);
                osheet.Cells[1, 4] = "TỔNG HỢP DÙ TRÙ";
                string s_title = ttb.title(tu.Value.ToString(), tu.Value.ToString()) + " năm " + yyyy.Value.ToString();
                osheet.Cells[2, 4]         = s_title;
                orange                     = osheet.get_Range(ttb.getIndex(3) + "1", ttb.getIndex(socot - 1) + "2");
                orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection;
                orange.Font.Size           = 12;
                orange.Font.Bold           = true;
                if (print)
                {
                    osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
                }
                else
                {
                    oxl.Visible = true;
                }
            }
            catch { }
        }
Пример #16
0
        private void get_sort()
        {
            dsxml = ds.Copy();
            dsxml.Clear();
            int stt = 0, tt = 1;

            sql = "stt,ten";
            DataRow [] dr = ds.Tables[0].Select("ma<>''", sql);
            for (int i = 0; i < dr.Length; i++)
            {
                if (stt != int.Parse(dr[i]["stt"].ToString()))
                {
                    stt           = int.Parse(dr[i]["stt"].ToString());
                    r2            = dsxml.Tables[0].NewRow();
                    r2["stt"]     = 0;
                    r2["tenhc"]   = dr[i]["tennhom"].ToString().ToUpper();
                    r2["dang"]    = "";
                    r2["ten"]     = "";
                    r2["tenhang"] = "";
                    r2["tennuoc"] = "";
                    for (int j = Convert.ToInt16(tu.Value); j <= Convert.ToInt16(den.Value); j++)
                    {
                        r2["sl_" + j.ToString().PadLeft(2, '0')] = 0;
                    }
                    r2["tongcong"] = 0;
                    dsxml.Tables[0].Rows.Add(r2);
                }
                r2             = dsxml.Tables[0].NewRow();
                r2["manhom"]   = dr[i]["manhom"].ToString();
                r2["tennhom"]  = dr[i]["tennhom"].ToString();
                r2["mabd"]     = dr[i]["mabd"].ToString();
                r2["ma"]       = dr[i]["ma"].ToString();
                r2["ten"]      = dr[i]["ten"].ToString();
                r2["tenhc"]    = dr[i]["tenhc"].ToString();
                r2["dang"]     = dr[i]["dang"].ToString();
                r2["tenhang"]  = dr[i]["tenhang"].ToString();
                r2["tennuoc"]  = dr[i]["tennuoc"].ToString();
                r2["stt"]      = tt;
                r2["tongcong"] = 0;
                for (int j = Convert.ToInt16(tu.Value); j <= Convert.ToInt16(den.Value); j++)
                {
                    r2["sl_" + j.ToString().PadLeft(2, '0')] = dr[i]["sl_" + j.ToString().PadLeft(2, '0')].ToString();
                    r2["tongcong"] = decimal.Parse(r2["tongcong"].ToString()) + decimal.Parse(dr[i]["sl_" + j.ToString().PadLeft(2, '0')].ToString());
                }
                dsxml.Tables[0].Rows.Add(r2);
                tt++;
            }
            dsxml.Tables[0].Columns.Remove("dongia");
            dsxml.Tables[0].Columns.Remove("manhom");
            dsxml.Tables[0].Columns.Remove("mabd");
            dsxml.Tables[0].Columns.Remove("ma");
            dsxml.Tables[0].Columns.Remove("manguon");
            dsxml.Tables[0].Columns.Remove("tennhom");
            dsxml.Tables[0].Columns.Remove("noingoai");
            dsxml.Tables[0].Columns.Remove("idnn");
        }
Пример #17
0
        public int UpdateQuerySet(DataSet ds, String Query)
        {
            DataAdapter = new SqlDataAdapter(Query, DBConnection);
            DataAdapter.Fill(ResultSet);
            ResultSet = ds.Copy();
            int Result = DataAdapter.Update(ResultSet);

            DataAdapter.Dispose();
            return(Result);
        }
Пример #18
0
        private void rptThekho_Load(object sender, System.EventArgs e)
        {
            user = ttb.user;
            theo.SelectedIndex    = 0;
            manguon.DisplayMember = "TEN";
            manguon.ValueMember   = "ID";
            if (ttb.bQuanlynguon(i_nhom))
            {
                manguon.DataSource = ttb.get_data("select * from " + user + ".ttb_dmnguon where nhom=" + i_nhom + " order by stt").Tables[0];
            }
            else
            {
                manguon.DataSource = ttb.get_data("select * from " + user + ".ttb_dmnguon where id=0 or nhom=" + i_nhom + " order by stt").Tables[0];
            }

            kho.DisplayMember = "TEN";
            kho.ValueMember   = "ID";
            sql = "select * from " + user + ".ttb_dmkho where nhom=" + i_nhom;
            if (s_kho != "")
            {
                sql += " and id in (" + s_kho.Substring(0, s_kho.Length - 1) + ")";
            }
            sql           += " order by stt";
            dtkho          = ttb.get_data(sql).Tables[0];
            kho.DataSource = dtkho;

            tmpkho   = ttb.get_data("select * from " + user + ".ttb_dmkho where nhom=" + i_nhom).Tables[0];
            dtkhac   = ttb.get_data("select * from " + user + ".ttb_dmkhac where nhom=0 or nhom=" + i_nhom + " order by stt").Tables[0];
            dtphieu  = ttb.get_data("select * from " + user + ".ttb_loaiphieu where nhom=" + i_nhom + " order by stt").Tables[0];
            dtloaint = ttb.get_data("select * from " + user + ".ttb_dmloaint where nhom=" + i_nhom + " order by stt").Tables[0];
            dtkp     = ttb.get_data("select * from " + ttb.UserMedi + ".d_duockp" + ttb.dbLink + " where nhom like '%" + i_nhom.ToString() + ",%'" + " order by stt").Tables[0];
            string s_field_sel = ttb.f_get_select_field("ttb_dmbd", "image", "a");

            dt = ttb.get_data("select " + s_field_sel + ",b.ten as tenhang,c.ten as tennuoc,d.ten as tennhom from " + user + ".ttb_dmbd a," + user + ".ttb_dmhang b," + user + ".ttb_dmnuoc c," + user + ".ttb_dmnhom d where a.mahang=b.id and a.manuoc=c.id and a.manhom=d.id and a.nhom=" + i_nhom + " order by a.id").Tables[0];
            dsdm.ReadXml("..\\..\\..\\xml\\ttb_thekho.xml");
            ds.ReadXml("..\\..\\..\\xml\\ttb_sochitiet.xml");
            //dsxml.ReadXml("..\\..\\..\\xml\\d_sochitiet.xml");
            dsdm.Tables[0].Columns.Add("Chon", typeof(bool));
            ds.Tables[0].Columns.Add("sltra", typeof(decimal)).DefaultValue = 0;
            ds.Tables[0].Columns.Add("sttra", typeof(decimal)).DefaultValue = 0;
            dsxml = ds.Copy();//
            load_grid();
            AddGridTableStyle();

            this.disabledBackBrush = new SolidBrush(Color.FromArgb(255, 255, 192));
            this.disabledTextBrush = new SolidBrush(Color.FromArgb(255, 0, 0));

            this.alertBackBrush = new SolidBrush(SystemColors.HotTrack);
            this.alertFont      = new Font(this.dataGrid1.Font.Name, this.dataGrid1.Font.Size, FontStyle.Bold);
            this.alertTextBrush = new SolidBrush(Color.White);

            this.currentRowFont      = new Font(this.dataGrid1.Font.Name, this.dataGrid1.Font.Size, FontStyle.Regular);
            this.currentRowBackBrush = new SolidBrush(Color.FromArgb(0, 255, 255));
        }
Пример #19
0
        public static string GetDataSetXML(DataSet dataSet, bool includeSchema,
                                           bool ignoreExtendedProps, bool encodeCDATA)
        {
            string xml = null;

            // clona o DataSet para remover os extended properties que não são necessários...
            using (DataSet xmlDataSet = dataSet.Copy())
            {
                // remove as propriedades extendidas...
                if (ignoreExtendedProps)
                {
                    xmlDataSet.ExtendedProperties.Clear();
                    foreach (DataTable table in xmlDataSet.Tables)
                    {
                        table.ExtendedProperties.Clear();
                        foreach (DataColumn column in table.Columns)
                        {
                            column.ExtendedProperties.Clear();
                        }
                    }
                }

                using (StringWriter writer = new StringWriter())
                {
                    XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
                    xmlWriterSettings.OmitXmlDeclaration = true;
                    xmlWriterSettings.Indent             = true;
                    xmlWriterSettings.IndentChars        = "  ";
                    xmlWriterSettings.NewLineHandling    = NewLineHandling.Entitize;
                    XmlWriter xmlWriter = XmlWriter.Create(writer, xmlWriterSettings);

                    // grava os dados do DataSet...
                    if (includeSchema)
                    {
                        xmlDataSet.WriteXml(xmlWriter, XmlWriteMode.WriteSchema);
                    }
                    else
                    {
                        xmlDataSet.WriteXml(xmlWriter, XmlWriteMode.IgnoreSchema);
                    }

                    // pega o xml...
                    writer.Flush();
                    xml = writer.ToString();
                }
            }

            // codifica como CDATA...
            if (encodeCDATA)
            {
                xml = System.Web.HttpUtility.HtmlEncode(xml);
            }
            return(xml);
        }
Пример #20
0
        private void exp_excel(bool print)
        {
            d.check_process_Excel();
            ds = dsxml.Copy();
            int be = 2, dong = 4, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1;

            tenfile = d.Export_Excel(ds, "cosotutruc");
            oxl     = new Excel.Application();
            owb     = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));
            osheet  = (Excel._Worksheet)owb.ActiveSheet;
            oxl.ActiveWindow.DisplayGridlines = true;

            for (int i = 0; i < be; i++)
            {
                osheet.get_Range(d.getIndex(i) + "1", d.getIndex(i) + "1").EntireRow.Insert(Missing.Value);
            }
            osheet.get_Range(d.getIndex(be - 1) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = "#,##0.00";
            osheet.get_Range(d.getIndex(0) + "3", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle = XlBorderWeight.xlHairline;
            for (int i = 0; i < 8; i++)
            {
                osheet.Cells[dong - 1, i + 1] = get_ten(i);
            }
            orange           = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString());
            orange.Font.Name = "Arial";
            orange.Font.Size = 8;
            orange.EntireColumn.AutoFit();

            oxl.ActiveWindow.DisplayZeros = false;
            osheet.PageSetup.Orientation  = XlPageOrientation.xlLandscape;
            osheet.PageSetup.PaperSize    = XlPaperSize.xlPaperA4;
            osheet.PageSetup.CenterFooter = "Trang : &P/&N";

            osheet.Cells[1, 2] = d.Syte; osheet.Cells[2, 2] = d.Tenbv;
            osheet.Cells[1, 4] = "BÁO CÁO SỬ DỤNG NỘI TRÚ";
            string s_title = "Từ ngày " + tu.Text + " đến ngày " + den.Text;

            if (tu.Text == den.Text)
            {
                s_title = "Ngày " + tu.Text;
            }
            osheet.Cells[2, 4]         = s_title;
            orange                     = osheet.get_Range(d.getIndex(3) + "1", d.getIndex(socot - 1) + "2");
            orange.HorizontalAlignment = XlHAlign.xlHAlignCenterAcrossSelection;
            orange.Font.Size           = 12;
            orange.Font.Bold           = true;
            if (print)
            {
                osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            }
            else
            {
                oxl.Visible = true;
            }
        }
Пример #21
0
        private void ExportXML(string filename, DataSet ds)
        {
            if (Options.UseMappingType != MappingType.Element)
            {
                // create a new copy to avoid changing the original data set.
                ds = ds.Copy();
                DataUtil.SetColumnMapping(ds, Options.UseMappingType);
            }

            ds.WriteXml(filename, Options.UseXmlWriteMode);
        }
Пример #22
0
        private void get_sort()
        {
            dsxml = ds.Copy();
            dsxml.Clear();
            int stt = 0, tt = 1;

            sql = "stt,ten";
            DataRow [] dr = ds.Tables[0].Select("ma<>''", sql);
            for (int i = 0; i < dr.Length; i++)
            {
                if (stt != int.Parse(dr[i]["stt"].ToString()))
                {
                    stt           = int.Parse(dr[i]["stt"].ToString());
                    r2            = dsxml.Tables[0].NewRow();
                    r2["stt"]     = 0;
                    r2["tenhc"]   = dr[i]["tennhom"].ToString().ToUpper();
                    r2["dang"]    = "";
                    r2["tondau"]  = 0;
                    r2["nhap"]    = 0;
                    r2["xuat"]    = 0;
                    r2["toncuoi"] = 0;
                    dsxml.Tables[0].Rows.Add(r2);
                }
                r2              = dsxml.Tables[0].NewRow();
                r2["manhom"]    = dr[i]["manhom"].ToString();
                r2["tennhom"]   = dr[i]["tennhom"].ToString();
                r2["mabd"]      = dr[i]["mabd"].ToString();
                r2["ma"]        = dr[i]["ma"].ToString();
                r2["ten"]       = dr[i]["ten"].ToString();
                r2["tenhc"]     = dr[i]["tenhc"].ToString();
                r2["dang"]      = dr[i]["dang"].ToString();
                r2["tenhang"]   = dr[i]["tenhang"].ToString();
                r2["tennuoc"]   = dr[i]["tennuoc"].ToString();
                r2["noi_ngoai"] = dr[i]["noi_ngoai"].ToString();
                r2["bhyt"]      = dr[i]["bhyt"].ToString();
                r2["giamua"]    = dr[i]["giamua"].ToString();
                r2["tondau"]    = dr[i]["tondau"].ToString();
                r2["nhap"]      = dr[i]["nhap"].ToString();
                r2["xuat"]      = dr[i]["xuat"].ToString();
                r2["toncuoi"]   = decimal.Parse(dr[i]["tondau"].ToString()) + decimal.Parse(dr[i]["nhap"].ToString()) - decimal.Parse(dr[i]["xuat"].ToString());
                r2["stt"]       = tt;
                dsxml.Tables[0].Rows.Add(r2);
                tt++;
            }
            dsxml.Tables[0].Columns.Remove("manhom");
            dsxml.Tables[0].Columns.Remove("mabd");
            //linh
            //dsxml.Tables[0].Columns.Remove("ma");
            dsxml.Tables[0].Columns.Remove("manguon");
            dsxml.Tables[0].Columns.Remove("tennhom");
            dsxml.Tables[0].Columns.Remove("noingoai");
            dsxml.Tables[0].Columns.Remove("idnn");
            dsxml.Tables[0].Columns.Remove("dongia");
        }
Пример #23
0
        private void button2_Click(object sender, EventArgs e)          // отменить изменения в Ingredients
        {
            int currenttopindex = dataGridView2.FirstDisplayedCell.RowIndex;
            int startrowscount  = dataGridView2.Rows.Count;
            int selectedrow     = dataGridView2.CurrentRow.Index;

            ds = initds.Copy();
            dataGridView2.DataSource = ds.Tables["Ingredients"];
            if (currenttopindex < dataGridView2.RowCount)
            {
                dataGridView2.FirstDisplayedScrollingRowIndex = currenttopindex;
                dataGridView2.ClearSelection();
                dataGridView2.Rows[selectedrow].Selected = true;
            }
            else
            {
                dataGridView2.FirstDisplayedScrollingRowIndex = currenttopindex + dataGridView2.Rows.Count - startrowscount;
                dataGridView2.ClearSelection();
                dataGridView2.Rows[dataGridView2.Rows.Count - 1].Selected = true;
            }
        }
Пример #24
0
        public ExeResEdm GetDataSet(string cmdText, DBOperUser dbLogMsg = null, params DbParameter[] parameters)
        {
            DataSet ds = new DataSet();

            parameters = ParameterPrepare(parameters);
            var res = SqlCMD_DT(cmdText, CommandType.Text, adt => adt.Fill(ds), parameters);

            res.ExeModel = ds.Copy();
            res.ExeNum   = ds.Tables.Count;
            WriteLogMsg(dbLogMsg, LogType.查询, "根据" + GetRealSql(cmdText, parameters) + "获取了" + ds.Tables.Count + "张表", "GetDataSet方法");
            return(res);
        }
Пример #25
0
        public void FillObjectListComplexNoChildsReaderTest()
        {
            DataMapper.Default.ClearCache();
            DataMapper.Default.SetConfig(@"..\..\..\DataMapperTest\hierarchy.mapping");

            List <Parent> objs = new List <Parent>();

            var copy = _Hierarchy.Copy();

            copy.Tables[1].Rows.Clear();
            var reader = copy.CreateDataReader();

            DataMapper.Default.FillObjectListComplex <Parent>(reader, objs);
            reader.Close();

            if (objs[0].Id != 1 ||
                objs[0].EntityType == null ||
                objs[0].Name.Length < 3 ||
                objs[0].Childs1.Count != 0 ||
                objs[0].Childs2.Count != 1 ||                  //4
                objs[0].Childs2[0].Childs2.Count != 1
                )
            {
                Assert.Fail("HierarchyTest fails.");
            }

            if (objs[1].Id != 2 ||
                objs[1].EntityType == null ||
                objs[1].Name.Length < 3 ||
                objs[1].Childs1.Count != 0 ||
                objs[1].Childs2.Count != 2 ||                 //5,6
                objs[1].Childs2[0].Id != 5 ||
                objs[1].Childs2[0].EntityType == null ||
                objs[1].Childs2[0].Childs2.Count != 2 ||
                objs[1].Childs2[1].Id != 6 ||
                objs[1].Childs2[1].EntityType == null ||
                objs[1].Childs2[1].Childs2.Count != 0
                )
            {
                Assert.Fail("HierarchyTest fails.");
            }

            if (objs[2].Id != 3 ||
                objs[2].EntityType == null ||
                objs[2].Name.Length < 3 ||
                objs[2].Childs1.Count != 0 ||
                objs[2].Childs2.Count != 0
                )
            {
                Assert.Fail("HierarchyTest fails.");
            }
        }
Пример #26
0
        private void GetSearchModel()
        {
            try
            {
                this.MsgShow(this._mlthandler.GetMessage(Definition.LOADING_DATA));

                this.KillThread();
                this._dtContextInfo = null;

                _llstChartSearchCondition.Clear();
                _llstChartSearchCondition.Add(Definition.DynamicCondition_Condition_key.AREA, this.bcboArea.SelectedValue.ToString());

                DataSet dsModel = this._ws.SearchByArea(_llstChartSearchCondition.GetSerialData());

                //Chris 추가 부분
                if (dsModel != null)
                {
                    if (dsModel.Tables.Count > 0)
                    {
                        this._dsAreaAndSPCModelName = dsModel.Copy();

                        this.bccbo_SPCModelName.IsIncludeAll = true;

                        LinkedList llstItem = this.GetDistinctColumnItemToDataTable(this._dsAreaAndSPCModelName.Tables[0], Definition.CONDITION_KEY_SPC_MODEL_NAME);

                        if (llstItem != null)
                        {
                            int listcount = llstItem.Count;

                            for (int i = 0; i < listcount; i++)
                            {
                                bccbo_SPCModelName.Items.Add(llstItem.GetKey(i).ToString());
                            }
                        }
                    }
                }
                //여기까지

                this.bsprdSPCModel.DataSource = dsModel.Tables[0];

                this._dtContextInfo = dsModel.Tables[1];
            }
            catch (Exception ex) { }
            finally
            {
                this.MsgClose();
            }

            this._threadContextInfo = new Thread(new ThreadStart(WriteContextInfo));
            this._threadContextInfo.Start();
        }
Пример #27
0
        private void exp_excel(bool print)
        {
            d.check_process_Excel();
            ds = dsxml.Copy();
            int dong = 2, sodong = ds.Tables[0].Rows.Count + dong, socot = ds.Tables[0].Columns.Count - 1, dongke = sodong - 1;

            tenfile = d.Export_Excel(ds, "cosotutruc");
            oxl     = new Excel.Application();
            owb     = (Excel._Workbook)(oxl.Workbooks.Open(tenfile, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value));
            osheet  = (Excel._Worksheet)owb.ActiveSheet;
            oxl.ActiveWindow.DisplayGridlines = true;

            osheet.get_Range(d.getIndex(3) + dong.ToString(), d.getIndex(socot + 1) + sodong.ToString()).NumberFormat = format_soluong;
            osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + dongke.ToString()).Borders.LineStyle            = XlBorderWeight.xlHairline;
            int pos = 5;

            foreach (DataRow r in dtmakp.Select("makp<>''", "stt,makp"))
            {
                osheet.Cells[dong - 1, pos] = r["tenkp"].ToString();
                pos += 1;
            }
            for (int i = 0; i < 4; i++)
            {
                osheet.Cells[dong - 1, i + 1] = get_ten(i);
            }
            orange           = osheet.get_Range(d.getIndex(0) + "1", d.getIndex(socot) + sodong.ToString());
            orange.Font.Name = "Arial";
            orange.Font.Size = 10;
            orange.EntireColumn.AutoFit();

            oxl.ActiveWindow.DisplayZeros = false;
            osheet.PageSetup.Orientation  = XlPageOrientation.xlLandscape;
            osheet.PageSetup.PaperSize    = XlPaperSize.xlPaperA4;
            osheet.PageSetup.CenterFooter = "Trang : &P/&N";
            string s_title = "Từ ngày " + tu.Text + " đến ngày " + den.Text;

            if (tu.Text == den.Text)
            {
                s_title = "Ngày " + tu.Text;
            }
            osheet.PageSetup.LeftHeader   = d.Syte + "\n" + d.Tenbv;
            osheet.PageSetup.CenterHeader = "&\"Arial,Bold\"&14BÁO CÁO CƠ SỐ TỦ TRỰC\n" + s_title;
            if (print)
            {
                osheet.PrintOut(Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
            }
            else
            {
                oxl.Visible = true;
            }
        }
Пример #28
0
        private void get_sort()
        {
            dsxml = ds.Copy();
            dsxml.Clear();
            int stt = 0, tt = 1;

            sql = "stt,ten";
            DataRow [] dr = ds.Tables[0].Select("ma<>''", sql);
            for (int i = 0; i < dr.Length; i++)
            {
                if (stt != int.Parse(dr[i]["stt"].ToString()))
                {
                    stt        = int.Parse(dr[i]["stt"].ToString());
                    r2         = dsxml.Tables[0].NewRow();
                    r2["stt"]  = 0;
                    r2["ten"]  = dr[i]["tennhom"].ToString().ToUpper();
                    r2["dang"] = "";
                    foreach (DataRow r5 in dtmakp.Select("makp<>''", "stt,makp"))
                    {
                        r2["sl_" + r5["makp"].ToString().Trim()] = 0;
                    }
                    r2["soluong"] = 0;
                    dsxml.Tables[0].Rows.Add(r2);
                }
                r2            = dsxml.Tables[0].NewRow();
                r2["manhom"]  = dr[i]["manhom"].ToString();
                r2["tennhom"] = dr[i]["tennhom"].ToString();
                r2["mabd"]    = dr[i]["mabd"].ToString();
                r2["ma"]      = dr[i]["ma"].ToString();
                r2["ten"]     = dr[i]["ten"].ToString();
                r2["tenhc"]   = dr[i]["tenhc"].ToString();
                r2["dang"]    = dr[i]["dang"].ToString();
                r2["stt"]     = tt;
                foreach (DataRow r5 in dtmakp.Select("makp<>''", "stt,makp"))
                {
                    r2["sl_" + r5["makp"].ToString().Trim()] = dr[i]["sl_" + r5["makp"].ToString().Trim()].ToString();
                }
                r2["soluong"] = dr[i]["soluong"].ToString();
                dsxml.Tables[0].Rows.Add(r2);
                tt++;
            }
            dsxml.Tables[0].Columns.Remove("manhom");
            dsxml.Tables[0].Columns.Remove("mabd");
            dsxml.Tables[0].Columns.Remove("ma");
            dsxml.Tables[0].Columns.Remove("tenhc");
            dsxml.Tables[0].Columns.Remove("manguon");
            dsxml.Tables[0].Columns.Remove("tennhom");
            dsxml.Tables[0].Columns.Remove("noingoai");
            dsxml.Tables[0].Columns.Remove("idnn");
            dsxml.Tables[0].Columns.Remove("dongia");
        }
Пример #29
0
        private DataSet MergeDataSet(List <CatalogVersion> catalogVersions)
        {
            DataSet mergedDataSet = catalogVersions.First(cv => cv.ReleaseName == "vNext").CatalogDataSet;

            mergedDataSet = mergedDataSet.Copy();

            foreach (DataSet dataSet in catalogVersions.Where(cv => cv.ReleaseName != "vNext").Select(cv => cv.CatalogDataSet))
            {
                foreach (DataTable dataTable in dataSet.Tables)
                {
                    if (!mergedDataSet.Tables.Contains(dataTable.TableName))
                    {
                        DataTable cloneTable = dataTable.Copy();
                        mergedDataSet.Tables.Add(cloneTable);
                    }
                    else
                    {
                        DataTable mergedTable = mergedDataSet.Tables[dataTable.TableName];
                        foreach (DataColumn dataColumn in dataTable.Columns)
                        {
                            if (!mergedTable.Columns.Contains(dataColumn.ColumnName))
                            {
                                DataColumn cloneColumn = new DataColumn
                                {
                                    ColumnName        = dataColumn.ColumnName,
                                    AllowDBNull       = dataColumn.AllowDBNull,
                                    AutoIncrement     = dataColumn.AutoIncrement,
                                    AutoIncrementSeed = dataColumn.AutoIncrementSeed,
                                    AutoIncrementStep = dataColumn.AutoIncrementStep,
                                    Caption           = dataColumn.Caption,
                                    ColumnMapping     = dataColumn.ColumnMapping,
                                    DataType          = dataColumn.DataType,
                                    DateTimeMode      = dataColumn.DateTimeMode,
                                    DefaultValue      = dataColumn.DefaultValue,
                                    Expression        = dataColumn.Expression,
                                    MaxLength         = dataColumn.MaxLength,
                                    Namespace         = dataColumn.Namespace,
                                    Prefix            = dataColumn.Prefix,
                                    ReadOnly          = dataColumn.ReadOnly,
                                    Unique            = dataColumn.Unique,
                                };

                                mergedTable.Columns.Add(cloneColumn);
                            }
                        }
                    }
                }
            }

            return(mergedDataSet);
        }
Пример #30
0
        private void SaveParameterFile()
        {
            string NowTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            try
            {
                DataSet saveData = paramFile.Copy();

                saveData.Tables["Device"].Rows[0]["UpdateTime"] = NowTime;

                saveData.Tables["Var"].Columns.Remove("Message_Name");
                saveData.Tables["Var"].Columns.Remove("Var_Desc");
                saveData.Tables["Var"].Columns.Remove("Var_Obj");
                saveData.Tables["Var"].Columns.Remove("Tables");
                saveData.Tables["Var"].Columns.Remove("Modify");

                using (MemoryStream ms = new MemoryStream())
                {
                    saveData.WriteXml(ms);
                    ms.Position = 0;
                    XmlDocument doc = new System.Xml.XmlDocument();
                    doc.Load(ms);

                    XmlNode root   = doc.SelectSingleNode("NewDataSet");
                    XmlNode device = root.SelectSingleNode("Device");
                    doc.RemoveChild(root);

                    XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "utf-8", "yes");
                    doc.AppendChild(declaration);

                    doc.AppendChild(device);
                    doc.Save(FileName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("保存定值文件失败!\n错误信息:" + ex.Message);
                return;
            }

            deviceTable.Rows[0]["UpdateTime"] = NowTime;
            this.textBoxCreateTime.Text       = NowTime;

            foreach (DataRow var in varTable.Rows)
            {
                var["Modify"] = false;
            }

            SaveToolStripMenuItem.Enabled   = false;
            ReloadToolStripMenuItem.Enabled = false;
        }
Пример #31
0
        public void CloneCopy()
        {
            DataTable table = new DataTable("pTable");
            DataTable table1 = new DataTable("cTable");
            DataSet set = new DataSet();

            set.Tables.Add(table);
            set.Tables.Add(table1);

            DataColumn col = new DataColumn();
            col.ColumnName = "Id";
            col.DataType = Type.GetType("System.Int32");
            table.Columns.Add(col);
            UniqueConstraint uc = new UniqueConstraint("UK1", table.Columns[0]);
            table.Constraints.Add(uc);

            col = new DataColumn();
            col.ColumnName = "Name";
            col.DataType = Type.GetType("System.String");
            table.Columns.Add(col);

            col = new DataColumn();
            col.ColumnName = "Id";
            col.DataType = Type.GetType("System.Int32");
            table1.Columns.Add(col);

            col = new DataColumn();
            col.ColumnName = "Name";
            col.DataType = Type.GetType("System.String");
            table1.Columns.Add(col);
            ForeignKeyConstraint fc = new ForeignKeyConstraint("FK1", table.Columns[0], table1.Columns[0]);
            table1.Constraints.Add(fc);


            DataRow row = table.NewRow();

            row["Id"] = 147;
            row["name"] = "Row1";
            row.RowError = "Error#1";
            table.Rows.Add(row);

            // Set column to RO as commonly used by auto-increment fields.
            // ds.Copy() has to omit the RO check when cloning DataRows 
            table.Columns["Id"].ReadOnly = true;

            row = table1.NewRow();
            row["Id"] = 147;
            row["Name"] = "Row1";
            table1.Rows.Add(row);

            //Setting properties of DataSet
            set.CaseSensitive = true;
            set.DataSetName = "My DataSet";
            set.EnforceConstraints = false;
            set.Namespace = "Namespace#1";
            set.Prefix = "Prefix:1";
            DataRelation dr = new DataRelation("DR", table.Columns[0], table1.Columns[0]);
            set.Relations.Add(dr);
            set.ExtendedProperties.Add("TimeStamp", DateTime.Now);
            CultureInfo cultureInfo = new CultureInfo("ar-SA");
            set.Locale = cultureInfo;

            //Testing Copy ()
            DataSet copySet = set.Copy();
            Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
            Assert.Equal(set.DataSetName, copySet.DataSetName);
            Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
            Assert.Equal(set.HasErrors, copySet.HasErrors);
            Assert.Equal(set.Namespace, copySet.Namespace);
            Assert.Equal(set.Prefix, copySet.Prefix);
            Assert.Equal(set.Relations.Count, copySet.Relations.Count);
            Assert.Equal(set.Tables.Count, copySet.Tables.Count);
            Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
            for (int i = 0; i < copySet.Tables.Count; i++)
            {
                Assert.Equal(set.Tables[i].Rows.Count, copySet.Tables[i].Rows.Count);
                Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
            }
            //Testing Clone ()
            copySet = set.Clone();
            Assert.Equal(set.CaseSensitive, copySet.CaseSensitive);
            Assert.Equal(set.DataSetName, copySet.DataSetName);
            Assert.Equal(set.EnforceConstraints, copySet.EnforceConstraints);
            Assert.False(copySet.HasErrors);
            Assert.Equal(set.Namespace, copySet.Namespace);
            Assert.Equal(set.Prefix, copySet.Prefix);
            Assert.Equal(set.Relations.Count, copySet.Relations.Count);
            Assert.Equal(set.Tables.Count, copySet.Tables.Count);
            Assert.Equal(set.ExtendedProperties["TimeStamp"], copySet.ExtendedProperties["TimeStamp"]);
            for (int i = 0; i < copySet.Tables.Count; i++)
            {
                Assert.Equal(0, copySet.Tables[i].Rows.Count);
                Assert.Equal(set.Tables[i].Columns.Count, copySet.Tables[i].Columns.Count);
            }
        }
Пример #32
0
        public void Copy()
        {
            DataSet ds = new DataSet(), dsTarget = null;
            ds.Tables.Add(DataProvider.CreateParentDataTable());
            ds.Tables.Add(DataProvider.CreateChildDataTable());
            ds.Relations.Add(new DataRelation("myRelation", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]));
            ds.Tables[0].Rows.Add(new object[] { 9, "", "" });
            ds.Tables[1].Columns[2].ReadOnly = true;
            ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns[0], ds.Tables[0].Columns[1] };

            //copy data and schema

            // Copy 1
            dsTarget = ds.Copy();
            //Assert.Equal(ds.GetXmlSchema(), dsTarget.GetXmlSchema() );
            //using my function because GetXmlSchema in not implemented in java
            Assert.Equal(DataProvider.GetDSSchema(ds), DataProvider.GetDSSchema(dsTarget));

            // Copy 2
            Assert.Equal(true, dsTarget.GetXml() == ds.GetXml());
        }
Пример #33
0
        public void Merge_DuplicateConstraints()
        {
            DataSet ds = new DataSet();

            DataTable table1 = ds.Tables.Add("table1");
            DataTable table2 = ds.Tables.Add("table2");

            DataColumn pcol = table1.Columns.Add("col1", typeof(int));
            DataColumn ccol = table2.Columns.Add("col1", typeof(int));

            DataSet ds1 = ds.Copy();

            DataRelation rel = ds.Relations.Add("rel1", pcol, ccol);

            ds1.Tables[1].Constraints.Add("fk", ds1.Tables[0].Columns[0], ds1.Tables[1].Columns[0]);

            // No Exceptions shud be thrown
            ds.Merge(ds1);
            Assert.Equal(1, table2.Constraints.Count);
        }
Пример #34
0
        public void MergeFailed()
        {
            _eventRaised = false;
            DataSet ds1, ds2;
            ds1 = new DataSet();
            ds1.Tables.Add(DataProvider.CreateParentDataTable());
            //add primary key to the FIRST column
            ds1.Tables[0].PrimaryKey = new DataColumn[] { ds1.Tables[0].Columns[0] };

            //create target dataset which is a copy of the source
            ds2 = ds1.Copy();
            //clear the data
            ds2.Clear();
            //add primary key to the SECOND columnn
            ds2.Tables[0].PrimaryKey = new DataColumn[] { ds2.Tables[0].Columns[1] };
            //add a new row that already exists in the source dataset
            //ds2.Tables[0].Rows.Add(ds1.Tables[0].Rows[0].ItemArray);

            //enforce constraints
            ds2.EnforceConstraints = true;
            ds1.EnforceConstraints = true;

            // Add MergeFailed event handler for the table.
            ds2.MergeFailed += new MergeFailedEventHandler(Merge_Failed);

            ds2.Merge(ds1); //will raise MergeFailed event

            // MergeFailed event
            Assert.Equal(true, _eventRaised);
        }
Пример #35
0
        public void CopyClone_RelationWithoutConstraints()
        {
            DataSet ds = new DataSet();

            DataTable table1 = ds.Tables.Add("table1");
            DataTable table2 = ds.Tables.Add("table2");

            DataColumn pcol = table1.Columns.Add("col1", typeof(int));
            DataColumn ccol = table2.Columns.Add("col1", typeof(int));

            DataRelation rel = ds.Relations.Add("rel1", pcol, ccol, false);

            DataSet ds1 = ds.Copy();
            DataSet ds2 = ds.Clone();

            Assert.Equal(1, ds1.Relations.Count);
            Assert.Equal(1, ds2.Relations.Count);

            Assert.Equal(0, ds1.Tables[0].Constraints.Count);
            Assert.Equal(0, ds1.Tables[1].Constraints.Count);

            Assert.Equal(0, ds2.Tables[0].Constraints.Count);
            Assert.Equal(0, ds2.Tables[1].Constraints.Count);
        }
Пример #36
0
        public void Merge_ByDataSet()
        {
            //create source dataset
            var ds = new DataSet();
            DataTable dt = DataProvider.CreateParentDataTable();
            dt.TableName = "Table1";
            ds.Tables.Add(dt.Copy());
            dt.TableName = "Table2";
            //add primary key
            dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
            ds.Tables.Add(dt.Copy());

            //create target dataset (copy of source dataset)
            DataSet dsTarget = ds.Copy();
            int iTable1RowsCount = dsTarget.Tables["Table1"].Rows.Count;

            //Source - add another table, don't exists on the target dataset
            ds.Tables.Add(new DataTable("SomeTable"));
            ds.Tables["SomeTable"].Columns.Add("Id");
            ds.Tables["SomeTable"].Rows.Add(new object[] { 777 });

            //Target - add another table, don't exists on the source dataset
            dsTarget.Tables.Add(new DataTable("SmallTable"));
            dsTarget.Tables["SmallTable"].Columns.Add("Id");
            dsTarget.Tables["SmallTable"].Rows.Add(new object[] { 777 });

            //update existing row
            ds.Tables["Table2"].Select("ParentId=1")[0][1] = "OldValue1";
            //add new row
            object[] arrAddedRow = new object[] { 99, "NewValue1", "NewValue2", new DateTime(0), 0.5, true };
            ds.Tables["Table2"].Rows.Add(arrAddedRow);
            //delete existing rows
            foreach (DataRow dr in ds.Tables["Table2"].Select("ParentId=2"))
            {
                dr.Delete();
            }

            // Merge - changed values
            dsTarget.Merge(ds);
            Assert.Equal("OldValue1", dsTarget.Tables["Table2"].Select("ParentId=1")[0][1]);

            // Merge - added values
            Assert.Equal(arrAddedRow, dsTarget.Tables["Table2"].Select("ParentId=99")[0].ItemArray);

            // Merge - deleted row
            Assert.Equal(0, dsTarget.Tables["Table2"].Select("ParentId=2").Length);

            //Table1 rows count should be double (no primary key)
            // Merge - Unchanged table 1
            Assert.Equal(iTable1RowsCount * 2, dsTarget.Tables["Table1"].Rows.Count);

            //SmallTable rows count should be the same
            // Merge - Unchanged table 2
            Assert.Equal(1, dsTarget.Tables["SmallTable"].Rows.Count);

            //SomeTable - new table
            // Merge - new table
            Assert.Equal(true, dsTarget.Tables["SomeTable"] != null);
        }
Пример #37
0
        public void Merge_ByDataSetPreserve()
        {
            //create source dataset
            var ds = new DataSet();
            DataTable dt = DataProvider.CreateParentDataTable();
            dt.TableName = "Table1";
            ds.Tables.Add(dt.Copy());
            dt.TableName = "Table2";
            //add primary key
            dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
            ds.Tables.Add(dt.Copy());

            //create target dataset (copy of source dataset)
            DataSet dsTarget1 = ds.Copy();
            DataSet dsTarget2 = ds.Copy();
            int iTable1RowsCount = dsTarget1.Tables["Table1"].Rows.Count;

            //update existing row
            string oldValue = ds.Tables["Table2"].Select("ParentId=1")[0][1].ToString();
            ds.Tables["Table2"].Select("ParentId=1")[0][1] = "NewValue";
            //add new row
            object[] arrAddedRow = new object[] { 99, "NewValue1", "NewValue2", new DateTime(0), 0.5, true };
            ds.Tables["Table2"].Rows.Add(arrAddedRow);
            //delete existing rows
            int iDeleteLength = dsTarget1.Tables["Table2"].Select("ParentId=2").Length;
            foreach (DataRow dr in ds.Tables["Table2"].Select("ParentId=2"))
            {
                dr.Delete();
            }

            #region "Merge(ds,true)"
            //only new added rows are merged (preserveChanges = true)
            dsTarget1.Merge(ds, true);
            // Merge - changed values
            Assert.Equal(oldValue, dsTarget1.Tables["Table2"].Select("ParentId=1")[0][1]);

            // Merge - added values
            Assert.Equal(arrAddedRow, dsTarget1.Tables["Table2"].Select("ParentId=99")[0].ItemArray);

            // Merge - deleted row
            Assert.Equal(iDeleteLength, dsTarget1.Tables["Table2"].Select("ParentId=2").Length);
            #endregion

            #region "Merge(ds,false)"
            //all changes are merged (preserveChanges = false)
            dsTarget2.Merge(ds, false);
            // Merge - changed values
            Assert.Equal("NewValue", dsTarget2.Tables["Table2"].Select("ParentId=1")[0][1]);

            // Merge - added values
            Assert.Equal(arrAddedRow, dsTarget2.Tables["Table2"].Select("ParentId=99")[0].ItemArray);

            // Merge - deleted row
            Assert.Equal(0, dsTarget2.Tables["Table2"].Select("ParentId=2").Length);
            #endregion
        }
Пример #38
0
        public void Merge_PrimaryKeys_IncorrectOrder()
        {
            Assert.Throws<DataException>(() =>
           {
               var ds = new DataSet();
               DataTable table1 = ds.Tables.Add("table1");
               DataTable table2 = ds.Tables.Add("table2");
               DataColumn pcol = table1.Columns.Add("col1", typeof(int));
               DataColumn pcol1 = table1.Columns.Add("col2", typeof(int));
               DataColumn ccol = table2.Columns.Add("col1", typeof(int));

               DataSet ds1 = ds.Copy();
               table1.PrimaryKey = new DataColumn[] { pcol, pcol1 };
               ds1.Tables[0].PrimaryKey = new DataColumn[] { ds1.Tables[0].Columns[1], ds1.Tables[0].Columns[0] };

               // Though the key columns are the same, if the order is incorrect
               // Exception must be raised
               ds1.Merge(ds);
           });
        }
Пример #39
0
        public void Merge_ByDataSetPreserveMissingSchemaAction()
        {
            //create source dataset
            var ds = new DataSet();

            DataTable dt = DataProvider.CreateParentDataTable();
            dt.TableName = "Table1";

            dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };

            //add table to dataset
            ds.Tables.Add(dt.Copy());

            dt = ds.Tables[0];

            //create target dataset (copy of source dataset)
            DataSet dsTarget = ds.Copy();

            //add new column (for checking MissingSchemaAction)
            DataColumn dc = new DataColumn("NewColumn", typeof(float));
            //make the column to be primary key
            dt.Columns.Add(dc);

            //add new table (for checking MissingSchemaAction)
            ds.Tables.Add(new DataTable("NewTable"));
            ds.Tables["NewTable"].Columns.Add("NewColumn1", typeof(int));
            ds.Tables["NewTable"].Columns.Add("NewColumn2", typeof(long));
            ds.Tables["NewTable"].Rows.Add(new object[] { 1, 2 });
            ds.Tables["NewTable"].Rows.Add(new object[] { 3, 4 });
            ds.Tables["NewTable"].PrimaryKey = new DataColumn[] { ds.Tables["NewTable"].Columns["NewColumn1"] };

            #region "ds,false,MissingSchemaAction.Add)"
            DataSet dsTarget1 = dsTarget.Copy();
            dsTarget1.Merge(ds, false, MissingSchemaAction.Add);
            // Merge MissingSchemaAction.Add - Column
            Assert.Equal(true, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge MissingSchemaAction.Add - Table
            Assert.Equal(true, dsTarget1.Tables.Contains("NewTable"));

            //failed, should be success by MSDN Library documentation
            //		// Merge MissingSchemaAction.Add - PrimaryKey
            //		Assert.Equal(0, dsTarget1.Tables["NewTable"].PrimaryKey.Length);
            #endregion

            #region "ds,false,MissingSchemaAction.AddWithKey)"
            //MissingSchemaAction.Add,MissingSchemaAction.AddWithKey - behave the same, checked only Add

            //		DataSet dsTarget2 = dsTarget.Copy();
            //		dsTarget2.Merge(ds,false,MissingSchemaAction.AddWithKey);
            //		// Merge MissingSchemaAction.AddWithKey - Column
            //		Assert.Equal(true, dsTarget2.Tables["Table1"].Columns.Contains("NewColumn"));
            //
            //		// Merge MissingSchemaAction.AddWithKey - Table
            //		Assert.Equal(true, dsTarget2.Tables.Contains("NewTable"));
            //
            //		// Merge MissingSchemaAction.AddWithKey - PrimaryKey
            //		Assert.Equal(dsTarget2.Tables["NewTable"].Columns["NewColumn1"], dsTarget2.Tables["NewTable"].PrimaryKey[0]);
            #endregion

            #region "ds,false,MissingSchemaAction.Ignore )"
            DataSet dsTarget4 = dsTarget.Copy();
            dsTarget4.Merge(ds, false, MissingSchemaAction.Ignore);
            // Merge MissingSchemaAction.Ignore - Column
            Assert.Equal(false, dsTarget4.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge MissingSchemaAction.Ignore - Table
            Assert.Equal(false, dsTarget4.Tables.Contains("NewTable"));
            #endregion
        }
Пример #40
0
        public void Merge_ByComplexDataSet()
        {
            //create source dataset
            var ds = new DataSet();

            ds.Tables.Add(DataProvider.CreateParentDataTable());
            ds.Tables.Add(DataProvider.CreateChildDataTable());
            ds.Tables["Child"].TableName = "Child2";
            ds.Tables.Add(DataProvider.CreateChildDataTable());

            //craete a target dataset to the merge operation
            DataSet dsTarget = ds.Copy();

            //craete a second target dataset to the merge operation
            DataSet dsTarget1 = ds.Copy();

            //------------------ make some changes in the second target dataset schema --------------------
            //add primary key
            dsTarget1.Tables["Parent"].PrimaryKey = new DataColumn[] { dsTarget1.Tables["Parent"].Columns["ParentId"] };
            dsTarget1.Tables["Child"].PrimaryKey = new DataColumn[] { dsTarget1.Tables["Child"].Columns["ParentId"], dsTarget1.Tables["Child"].Columns["ChildId"] };

            //add Foreign Key (different name)
            dsTarget1.Tables["Child2"].Constraints.Add("Child2_FK_2", dsTarget1.Tables["Parent"].Columns["ParentId"], dsTarget1.Tables["Child2"].Columns["ParentId"]);

            //add relation (different name)
            //dsTarget1.Relations.Add("Parent_Child_1",dsTarget1.Tables["Parent"].Columns["ParentId"],dsTarget1.Tables["Child"].Columns["ParentId"]);

            //------------------ make some changes in the source dataset schema --------------------
            //add primary key
            ds.Tables["Parent"].PrimaryKey = new DataColumn[] { ds.Tables["Parent"].Columns["ParentId"] };
            ds.Tables["Child"].PrimaryKey = new DataColumn[] { ds.Tables["Child"].Columns["ParentId"], ds.Tables["Child"].Columns["ChildId"] };

            //unique column
            ds.Tables["Parent"].Columns["String2"].Unique = true; //will not be merged

            //add Foreign Key
            ds.Tables["Child2"].Constraints.Add("Child2_FK", ds.Tables["Parent"].Columns["ParentId"], ds.Tables["Child2"].Columns["ParentId"]);

            //add relation
            ds.Relations.Add("Parent_Child", ds.Tables["Parent"].Columns["ParentId"], ds.Tables["Child"].Columns["ParentId"]);

            //add allow null constraint
            ds.Tables["Parent"].Columns["ParentBool"].AllowDBNull = false; //will not be merged

            //add Indentity column
            ds.Tables["Parent"].Columns.Add("Indentity", typeof(int));
            ds.Tables["Parent"].Columns["Indentity"].AutoIncrement = true;
            ds.Tables["Parent"].Columns["Indentity"].AutoIncrementStep = 2;

            //modify default value
            ds.Tables["Child"].Columns["String1"].DefaultValue = "Default"; //will not be merged

            //remove column
            ds.Tables["Child"].Columns.Remove("String2"); //will not be merged

            //-------------------- begin to check ----------------------------------------------
            // merge 1 - make sure the merge method invoked without exceptions
            dsTarget.Merge(ds);
            Assert.Equal("Success", "Success");

            CompareResults_1("merge 1", ds, dsTarget);

            //merge again,
            // merge 2 - make sure the merge method invoked without exceptions
            dsTarget.Merge(ds);
            Assert.Equal("Success", "Success");

            CompareResults_1("merge 2", ds, dsTarget);

            // merge second dataset - make sure the merge method invoked without exceptions
            dsTarget1.Merge(ds);
            Assert.Equal("Success", "Success");

            CompareResults_2("merge 3", ds, dsTarget1);
        }
Пример #41
0
        public void CloneCopy_TestForeignKeyConstraints()
        {
            DataTable dirTable = new DataTable("Directories");

            DataColumn dir_UID = new DataColumn("UID", typeof(int));
            dir_UID.Unique = true;
            dir_UID.AllowDBNull = false;

            dirTable.Columns.Add(dir_UID);

            // Build a simple Files table
            DataTable fileTable = new DataTable("Files");

            DataColumn file_DirID = new DataColumn("DirectoryID", typeof(int));
            file_DirID.Unique = false;
            file_DirID.AllowDBNull = false;

            fileTable.Columns.Add(file_DirID);

            // Build the DataSet
            DataSet ds = new DataSet("TestDataset");
            ds.Tables.Add(dirTable);
            ds.Tables.Add(fileTable);

            // Add a foreign key constraint
            DataColumn[] parentColumns = new DataColumn[1];
            parentColumns[0] = ds.Tables["Directories"].Columns["UID"];

            DataColumn[] childColumns = new DataColumn[1];
            childColumns[0] = ds.Tables["Files"].Columns["DirectoryID"];

            ForeignKeyConstraint fk = new ForeignKeyConstraint("FK_Test", parentColumns, childColumns);
            ds.Tables["Files"].Constraints.Add(fk);
            ds.EnforceConstraints = true;

            Assert.Equal(1, ds.Tables["Directories"].Constraints.Count);
            Assert.Equal(1, ds.Tables["Files"].Constraints.Count);

            // check clone works fine
            DataSet cloned_ds = ds.Clone();
            Assert.Equal(1, cloned_ds.Tables["Directories"].Constraints.Count);
            Assert.Equal(1, cloned_ds.Tables["Files"].Constraints.Count);

            ForeignKeyConstraint clonedFk = (ForeignKeyConstraint)cloned_ds.Tables["Files"].Constraints[0];
            Assert.Equal("FK_Test", clonedFk.ConstraintName);
            Assert.Equal(1, clonedFk.Columns.Length);
            Assert.Equal("DirectoryID", clonedFk.Columns[0].ColumnName);

            UniqueConstraint clonedUc = (UniqueConstraint)cloned_ds.Tables["Directories"].Constraints[0];
            UniqueConstraint origUc = (UniqueConstraint)ds.Tables["Directories"].Constraints[0];
            Assert.Equal(origUc.ConstraintName, clonedUc.ConstraintName);
            Assert.Equal(1, clonedUc.Columns.Length);
            Assert.Equal("UID", clonedUc.Columns[0].ColumnName);

            // check copy works fine
            DataSet copy_ds = ds.Copy();
            Assert.Equal(1, copy_ds.Tables["Directories"].Constraints.Count);
            Assert.Equal(1, copy_ds.Tables["Files"].Constraints.Count);

            ForeignKeyConstraint copyFk = (ForeignKeyConstraint)copy_ds.Tables["Files"].Constraints[0];
            Assert.Equal("FK_Test", copyFk.ConstraintName);
            Assert.Equal(1, copyFk.Columns.Length);
            Assert.Equal("DirectoryID", copyFk.Columns[0].ColumnName);

            UniqueConstraint copyUc = (UniqueConstraint)copy_ds.Tables["Directories"].Constraints[0];
            origUc = (UniqueConstraint)ds.Tables["Directories"].Constraints[0];
            Assert.Equal(origUc.ConstraintName, copyUc.ConstraintName);
            Assert.Equal(1, copyUc.Columns.Length);
            Assert.Equal("UID", copyUc.Columns[0].ColumnName);
        }
Пример #42
0
        public void Merge_ByDataTablePreserveMissingSchemaAction()
        {
            DataTable dt = DataProvider.CreateParentDataTable();
            dt.TableName = "Table1";
            dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };

            //create target dataset (copy of source dataset)
            DataSet dsTarget = new DataSet();
            dsTarget.Tables.Add(dt.Copy());

            //add new column (for checking MissingSchemaAction)
            DataColumn dc = new DataColumn("NewColumn", typeof(float));
            dt.Columns.Add(dc);

            //Update row
            string OldValue = dt.Select("ParentId=1")[0][1].ToString();
            dt.Select("ParentId=1")[0][1] = "NewValue";
            //delete rows
            dt.Select("ParentId=2")[0].Delete();
            //add row
            object[] arrAddedRow = new object[] { 99, "NewRowValue1", "NewRowValue2", new DateTime(0), 0.5, true };
            dt.Rows.Add(arrAddedRow);

            #region "Merge(dt,true,MissingSchemaAction.Ignore )"
            DataSet dsTarget1 = dsTarget.Copy();
            dsTarget1.Merge(dt, true, MissingSchemaAction.Ignore);
            // Merge true,Ignore - Column
            Assert.Equal(false, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge true,Ignore - changed values
            Assert.Equal(OldValue, dsTarget1.Tables["Table1"].Select("ParentId=1")[0][1]);

            // Merge true,Ignore - added values
            Assert.Equal(arrAddedRow, dsTarget1.Tables["Table1"].Select("ParentId=99")[0].ItemArray);

            // Merge true,Ignore - deleted row
            Assert.Equal(true, dsTarget1.Tables["Table1"].Select("ParentId=2").Length > 0);
            #endregion

            #region "Merge(dt,false,MissingSchemaAction.Ignore )"

            dsTarget1 = dsTarget.Copy();
            dsTarget1.Merge(dt, false, MissingSchemaAction.Ignore);
            // Merge true,Ignore - Column
            Assert.Equal(false, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge true,Ignore - changed values
            Assert.Equal("NewValue", dsTarget1.Tables["Table1"].Select("ParentId=1")[0][1]);

            // Merge true,Ignore - added values
            Assert.Equal(arrAddedRow, dsTarget1.Tables["Table1"].Select("ParentId=99")[0].ItemArray);

            // Merge true,Ignore - deleted row
            Assert.Equal(0, dsTarget1.Tables["Table1"].Select("ParentId=2").Length);
            #endregion

            #region "Merge(dt,true,MissingSchemaAction.Add  )"
            dsTarget1 = dsTarget.Copy();
            dsTarget1.Merge(dt, true, MissingSchemaAction.Add);
            // Merge true,Add - Column
            Assert.Equal(true, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge true,Add - changed values
            Assert.Equal(OldValue, dsTarget1.Tables["Table1"].Select("ParentId=1")[0][1]);

            // Merge true,Add - added values
            Assert.Equal(1, dsTarget1.Tables["Table1"].Select("ParentId=99").Length);

            // Merge true,Add - deleted row
            Assert.Equal(true, dsTarget1.Tables["Table1"].Select("ParentId=2").Length > 0);
            #endregion

            #region "Merge(dt,false,MissingSchemaAction.Add  )"
            dsTarget1 = dsTarget.Copy();
            dsTarget1.Merge(dt, false, MissingSchemaAction.Add);
            // Merge true,Add - Column
            Assert.Equal(true, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"));

            // Merge true,Add - changed values
            Assert.Equal("NewValue", dsTarget1.Tables["Table1"].Select("ParentId=1")[0][1]);

            // Merge true,Add - added values
            Assert.Equal(1, dsTarget1.Tables["Table1"].Select("ParentId=99").Length);

            // Merge true,Add - deleted row
            Assert.Equal(0, dsTarget1.Tables["Table1"].Select("ParentId=2").Length);
            #endregion
        }
Пример #43
0
        public void Merge_MissingEventHandler()
        {
            Assert.Throws<DataException>(() =>
               {
                   var ds = new DataSet();
                   DataTable table1 = ds.Tables.Add("table1");

                   DataColumn pcol = table1.Columns.Add("col1", typeof(int));
                   DataColumn pcol1 = table1.Columns.Add("col2", typeof(int));

                   DataSet ds1 = ds.Copy();
                   table1.PrimaryKey = new DataColumn[] { pcol };
                   ds1.Tables[0].PrimaryKey = new DataColumn[] { ds1.Tables[0].Columns[1] };

                   // Exception shud be raised when handler is not set for MergeFailed Event
                   ds1.Merge(ds);
               });
        }
Пример #44
0
        public void Merge_ByDataTable()
        {
            //create source dataset
            var ds = new DataSet();
            //create datatable
            DataTable dt = DataProvider.CreateParentDataTable();
            dt.TableName = "Table1";
            //add a copy of the datatable to the dataset
            ds.Tables.Add(dt.Copy());

            dt.TableName = "Table2";
            //add primary key
            dt.PrimaryKey = new DataColumn[] { dt.Columns[0] };
            ds.Tables.Add(dt.Copy());
            //now the dataset hase two tables

            //create target dataset (copy of source dataset)
            DataSet dsTarget = ds.Copy();

            dt = ds.Tables["Table2"];
            //update existing row
            dt.Select("ParentId=1")[0][1] = "OldValue1";
            //add new row
            object[] arrAddedRow = new object[] { 99, "NewValue1", "NewValue2", new DateTime(0), 0.5, true };
            dt.Rows.Add(arrAddedRow);
            //delete existing rows
            foreach (DataRow dr in dt.Select("ParentId=2"))
            {
                dr.Delete();
            }

            // Merge - changed values
            dsTarget.Merge(dt);
            Assert.Equal("OldValue1", dsTarget.Tables["Table2"].Select("ParentId=1")[0][1]);

            // Merge - added values
            Assert.Equal(arrAddedRow, dsTarget.Tables["Table2"].Select("ParentId=99")[0].ItemArray);

            // Merge - deleted row
            Assert.Equal(0, dsTarget.Tables["Table2"].Select("ParentId=2").Length);

            //when merging a DataTable with TableName=null, GH throw null reference exception.
            ds = new DataSet();
            dt = new DataTable();
            dt.Columns.Add("Col1");
            dt.Rows.Add(new object[] { 1 });

            // Merge - add a table with no name
            ds.Merge(dt);
            Assert.Equal(1, ds.Tables.Count);

            // Merge - add a table with no name - check Rows.Count
            Assert.Equal(dt.Rows.Count, ds.Tables[0].Rows.Count);
        }
Пример #45
0
        public void Merge_MissingColumn()
        {
            Assert.Throws<DataException>(() =>
           {
               var ds = new DataSet();
               DataTable table1 = ds.Tables.Add("table1");
               DataTable table2 = ds.Tables.Add("table2");

               table1.Columns.Add("col1", typeof(int));
               table2.Columns.Add("col1", typeof(int));

               DataSet ds1 = ds.Copy();

               ds1.Tables[0].Columns.Add("col2");

               ds.Merge(ds1, true, MissingSchemaAction.Error);
           });
        }
Пример #46
0
        public void Merge_MissingConstraint()
        {
            DataSet ds = new DataSet();
            DataTable table1 = ds.Tables.Add("table1");
            DataTable table2 = ds.Tables.Add("table2");
            table1.Columns.Add("col1", typeof(int));
            table2.Columns.Add("col1", typeof(int));

            try
            {
                DataSet ds1 = ds.Copy();
                DataSet ds2 = ds.Copy();
                ds2.Tables[0].Constraints.Add("uc", ds2.Tables[0].Columns[0], false);
                ds1.Merge(ds2, true, MissingSchemaAction.Error);
                Assert.False(true);
            }
            catch (DataException e)
            {
            }

            try
            {
                DataSet ds1 = ds.Copy();
                DataSet ds2 = ds.Copy();
                ds2.Tables[0].Constraints.Add("fk", ds2.Tables[0].Columns[0], ds2.Tables[1].Columns[0]);
                ds1.Tables[0].Constraints.Add("uc", ds1.Tables[0].Columns[0], false);
                ds1.Merge(ds2, true, MissingSchemaAction.Error);
                Assert.False(true);
            }
            catch (DataException e)
            {
            }

            try
            {
                DataSet ds1 = ds.Copy();
                DataSet ds2 = ds.Copy();
                ds2.Relations.Add("rel", ds2.Tables[0].Columns[0], ds2.Tables[1].Columns[0], false);
                ds1.Merge(ds2, true, MissingSchemaAction.Error);
                Assert.False(true);
            }
            catch (ArgumentException e)
            {
            }
        }
Пример #47
0
        public void Merge_DuplicateConstraints_1()
        {
            DataSet ds = new DataSet();

            DataTable table1 = ds.Tables.Add("table1");
            DataTable table2 = ds.Tables.Add("table2");

            DataColumn pcol = table1.Columns.Add("col1", typeof(int));
            DataColumn ccol = table2.Columns.Add("col1", typeof(int));
            DataColumn pcol1 = table1.Columns.Add("col2", typeof(int));
            DataColumn ccol1 = table2.Columns.Add("col2", typeof(int));

            DataSet ds1 = ds.Copy();

            table2.Constraints.Add("fk", pcol, ccol);
            ds1.Tables[1].Constraints.Add("fk", ds1.Tables[0].Columns["col2"], ds1.Tables[1].Columns["col2"]);

            // No Exceptions shud be thrown
            ds.Merge(ds1);
            Assert.Equal(2, table2.Constraints.Count);
            Assert.Equal("Constraint1", table2.Constraints[1].ConstraintName);
        }
Пример #48
-1
        public void RejectChanges()
        {
            DataSet ds1, ds2 = new DataSet();
            ds2.Tables.Add(DataProvider.CreateParentDataTable());
            ds1 = ds2.Copy();

            //create changes
            ds2.Tables[0].Rows[0][0] = "70";
            ds2.Tables[0].Rows[1].Delete();
            ds2.Tables[0].Rows.Add(new object[] { 9, "string1", "string2" });

            // RejectChanges
            ds2.RejectChanges();
            Assert.Equal(ds2.GetXml(), ds1.GetXml());
        }