Copy() public method

Copies both the structure and data for this .
public Copy ( ) : DataSet
return DataSet
Esempio n. 1
0
        /// <summary>
        /// Add new for case : Convert CPO to new PO
        /// </summary>
        /// <param name="pobjMasterVO"></param>
        /// <param name="pdstDetail"></param>
        /// <param name="pdstDelivery"></param>
        ///<author>TuanDM</author>

        public void UpdatePOAndDelScheduleImmediate(object pobjMasterVO, System.Data.DataSet pdstDetail, DataSet pdstDelivery, ArrayList parlCPOIDs)
        {
            //Add Master and Get returning ID
            PO_PurchaseOrderMasterDS dsPOMaster = new PO_PurchaseOrderMasterDS();

            dsPOMaster.Update(pobjMasterVO);
            var voMaster = (PO_PurchaseOrderMasterVO)pobjMasterVO;

            //Update detail
            DataSet dstPODetail = pdstDetail.Copy();
            PO_PurchaseOrderDetailDS dsPODetail = new PO_PurchaseOrderDetailDS();

            foreach (DataRow drowDetail in pdstDetail.Tables[0].Rows)
            {
                if (drowDetail.RowState == DataRowState.Added)
                {
                    drowDetail[PO_PurchaseOrderDetailTable.PURCHASEORDERMASTERID_FLD] = ((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID;
                }
            }
            dsPODetail.UpdateDataSet(pdstDetail);

            //Get PODetail DataSet which includes PURCHASEORDERDETAILID_FLD
            pdstDetail = dsPODetail.ListToGetID(((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID);

            //Create DeliverySchedule -- and add DeliverySchedule
            int intPOLineID = 0;
            PO_DeliveryScheduleDS dsDelivery = new PO_DeliveryScheduleDS();

            for (int i = 0; i < dstPODetail.Tables[0].Rows.Count; i++)
            {
                DataRow[] drowSameDelivery = pdstDelivery.Tables[0].Select(ITM_ProductTable.PRODUCTID_FLD + "='" + dstPODetail.Tables[0].Rows[i][ITM_ProductTable.PRODUCTID_FLD].ToString() + "'");

                intPOLineID = (int)pdstDetail.Tables[0].Select(PO_PurchaseOrderDetailTable.LINE_FLD + "='" + dstPODetail.Tables[0].Rows[i][PO_PurchaseOrderDetailTable.LINE_FLD].ToString() + "'")[0][PO_PurchaseOrderDetailTable.PURCHASEORDERDETAILID_FLD];
                DataSet dstNewDelPO  = dsDelivery.GetDeliverySchedule(intPOLineID);
                int     intbaseCount = dstNewDelPO.Tables[0].Rows.Count;
                for (int j = 0; j < drowSameDelivery.Length; j++)
                {
                    int k = GetIndexForDeliveryLine(dstNewDelPO, (DateTime)drowSameDelivery[j][PO_DeliveryScheduleTable.SCHEDULEDATE_FLD]);
                    if (k > -1)
                    {
                        dstNewDelPO.Tables[0].Rows[k][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD] = (decimal)dstNewDelPO.Tables[0].Rows[k][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD] + (decimal)drowSameDelivery[j][PO_DeliveryScheduleTable.DELIVERYQUANTITY_FLD];
                    }
                    else
                    {
                        drowSameDelivery[j][PO_DeliveryScheduleTable.PURCHASEORDERDETAILID_FLD] = intPOLineID;
                        drowSameDelivery[j][PO_DeliveryScheduleTable.DELIVERYLINE_FLD]          = j + 1 + intbaseCount;
                        dstNewDelPO.Tables[0].ImportRow(drowSameDelivery[j]);
                    }
                }
                dsDelivery.UpdateDataSet(dstNewDelPO);
            }

            //Update CPODetail
            MTR_CPODS dsCPO = new MTR_CPODS();

            dsCPO.SetPOMasterID(parlCPOIDs, ((PO_PurchaseOrderMasterVO)pobjMasterVO).PurchaseOrderMasterID);
        }
        // spajanje sadrzaja 2 data set-a
        private System.Data.DataSet SpojPodatke(System.Data.DataSet ds1, System.Data.DataSet ds2)
        {
            System.Data.DataSet dsZajedno;

            dsZajedno = ds1.Copy();
            dsZajedno.Merge(ds2);

            return(dsZajedno);
        }
	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();
		//write xml file, data only
		ds1.WriteXml(sw);

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

		System.IO.StringReader sr = new System.IO.StringReader(sw.GetStringBuilder().ToString());
		ds2.ReadXml(sr);

		//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;}
		
		sr.Close();
		sw.Close();


	}
Esempio n. 4
0
 public PostToFile(string mstTable, string key, string selectFields, string where, string delFlag, DataSet dsSite, string action, bool logFlg,string userName)
 {
     this.mstTable = mstTable;
     this.selectFields = selectFields;
     this.where = where;
     this.delFlag = delFlag;
     this.dsSite = dsSite.Copy();
     this.action = action;
     this.logFlg = logFlg;
     this.key = key;
     this.userName = userName;
 }
Esempio n. 5
0
        public static void SaveSounds(DataSet ds)
        {
            DataSet newDs = ds.Copy();
            foreach (DataTable dt in newDs.Tables)
            {
                dt.Columns.Remove("buffer");
            }

            StreamWriter xmlWriter = new StreamWriter("settings\\sound_data.xml");
            newDs.WriteXml(xmlWriter);
            xmlWriter.Close();
        }
 public void Execute(byte[] reportData, DataSet ds)
 {
     if (this.caller != null)
     {
         string str = ds.Tables["YW_ZQRSF"].Rows[0]["PROJECT_ID"].ToString();
         string localpath = FileUtility.Combine(new string[] { FileUtility.ApplicationRootPath, "CameraProject", str });
         DataSet set = ds.Copy();
         set.Tables.Add(this.AddImgTable(localpath, this.caller.CIS[0].Identifies, "ZRFPics"));
         set.Tables.Add(this.AddImgTable(localpath, this.caller.CIS[1].Identifies, "SRFPics"));
         PrintHelper.PrintOrShowRDLC("二手房转让确认书", true, reportData, set, null, null, null);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// 测试不同schema的DataSet 合并规则
        /// 合并会将Schema同步过去
        /// </summary>
        public static void DataSetMerageTest()
        {
            var dsSource = new DataSet();
            var dtSrc = new DataTable("SrcDT");
            dtSrc.Columns.Add("Id", typeof(string));
            dtSrc.Columns.Add("COde", typeof(string));
            dsSource.Tables.Add(dtSrc);

            var dest = dsSource.Copy();
            dtSrc.Columns.Add("Desc", typeof(string));
            var dr = dtSrc.NewRow();
            dr["Id"] = "1";
            dr["Code"] = "No001";
            dr["Desc"] = "First";
            dtSrc.Rows.Add(dr);
            dest.Merge(dsSource);

        }
Esempio n. 8
0
        public void Update(DataSet ds, IDbCommandBuilder dbCommandBuilder, IDbTransaction dbTransaction)
        {
            DataSet dsCopy = ds.Copy();
            dsCopy.AcceptChanges();

            DataSetTableIterator iterator = new DataSetTableIterator(dsCopy, true);

            foreach (DataTable dataTable in iterator)
            {
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    // Modify every table row.
                    dataRow.BeginEdit();
                    dataRow.EndEdit();
                }

                OnUpdate(dsCopy, dbCommandBuilder, dbTransaction, dataTable.TableName);
            }
        }
Esempio n. 9
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,ds2 = new DataSet();
		ds2.Tables.Add(GHTUtils.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"});
        		
		try
		{
			BeginCase("RejectChanges");
			ds2.RejectChanges();
			Compare(ds1.GetXml(),ds2.GetXml());
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

	}
Esempio n. 10
0
		public void ReadXml_ByXmlReader()
		{
			DataSet ds1 = new DataSet();
			ds1.Tables.Add(DataProvider.CreateParentDataTable());
			ds1.Tables.Add(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
			// ReadXml - Tables count
			Assert.AreEqual(ds2.Tables.Count , ds1.Tables.Count , "DS342");

			// ReadXml - Table 1 row count
			Assert.AreEqual(ds2.Tables[0].Rows.Count, ds1.Tables[0].Rows.Count , "DS343");

			// ReadXml - Table 2 row count
			Assert.AreEqual(ds2.Tables[1].Rows.Count, ds1.Tables[1].Rows.Count , "DS344");
		}
Esempio n. 11
0
		[Test] 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.AreEqual(ds2.GetXml(), ds1.GetXml(), "DS345");
		}
Esempio n. 12
0
		public void ReadXml_Strm()
		{
			DataSet ds1 = new DataSet();
			ds1.Tables.Add(DataProvider.CreateParentDataTable());
			ds1.Tables.Add(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
			// ReadXml - Tables count
			Assert.AreEqual(ds2.Tables.Count , ds1.Tables.Count , "DS300");

			// ReadXml - Table 1 row count
			Assert.AreEqual(ds2.Tables[0].Rows.Count, ds1.Tables[0].Rows.Count , "DS301");

			// ReadXml - Table 2 row count
			Assert.AreEqual(ds2.Tables[1].Rows.Count, ds1.Tables[1].Rows.Count , "DS302");

			ms.Close();
		}
Esempio n. 13
0
		[Test] 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.AreEqual(ds.GetXmlSchema(), dsTarget.GetXmlSchema() , "DS19");
			//using my function because GetXmlSchema in not implemented in java
			Assert.AreEqual(DataProvider.GetDSSchema(ds), DataProvider.GetDSSchema (dsTarget) , "DS20");

			// Copy 2
			Assert.AreEqual(true, dsTarget.GetXml() == ds.GetXml(), "DS21");
		}
Esempio n. 14
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.AreEqual (1, table2.Constraints.Count, "#1 Constraints shudnt be duplicated");
		}
Esempio n. 15
0
		public void ReadXml_Strg()
		{
			string sTempFileName = "tmpDataSet_ReadWriteXml_43894.xml"  ;

			DataSet ds1 = new DataSet();
			ds1.Tables.Add(DataProvider.CreateParentDataTable());
			ds1.Tables.Add(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});

			//write xml file, data only
			ds1.WriteXml(sTempFileName);

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

			ds2.ReadXml(sTempFileName);

			//check xml data
			// ReadXml - Tables count
			Assert.AreEqual(ds2.Tables.Count , ds1.Tables.Count , "DS297");

			// ReadXml - Table 1 row count
			Assert.AreEqual(ds2.Tables[0].Rows.Count, ds1.Tables[0].Rows.Count , "DS298");

			// ReadXml - Table 2 row count
			Assert.AreEqual(ds2.Tables[1].Rows.Count, ds1.Tables[1].Rows.Count , "DS299");

			//try to delete the file
			System.IO.File.Delete(sTempFileName);
		}
Esempio n. 16
0
		[Test] public void Merge_ByComplexDataSet()
		{
			//create source dataset
			DataSet ds = new DataSet();

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

			// Console.WriteLine(ds.Tables[0].TableName + ds.Tables[1].TableName + ds.Tables[2].TableName);
			// Console.WriteLine(ds.Tables[2].Rows.Count.ToString());

			//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.AreEqual("Success", "Success", "DS204");

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

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

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

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

			CompareResults_2("merge 3",ds,dsTarget1);
		}
        /// <summary>
        /// Sub-function that is called when we detect that we have a request-xml-message.
        /// </summary>
        /// <param name="Set">The incoming message as a dataset (= tables)</param>
        /// <returns>The result of the request.</returns>
        private DataSet RequestsProcess(DataSet Set)
        {
            DataSet ReqSet = new DataSet();
            
            string ReqName = Set.Tables["Request"].Rows[0]["RequestName"].ToString().ToLower(); //Get the actual name of the request

            #region request
            //Create the message that we will send to the database.
            string cmd = "call " + ReqName + "(";
            if (Set.Tables.Count <= 1)
            {
                if (Set.Tables[0].Columns.Count >= 2)
                    cmd += "'" + Set.Tables["Request"].Rows[0]["arg"] + "'";
            }
            else
            {
                try
                {
                    foreach (DataRow rows in Set.Tables["arg"].Rows)
                    {
                        cmd += "'" + rows["arg_Text"] + "',";
                    }
                    cmd = cmd.Substring(0, cmd.LastIndexOf(","));
                }
                catch (Exception e_cmd)
                {
                    SocketServer.LogError(e_cmd, "LogServer.txt");
                }
            }
            cmd += ");";


            if (ReqName == "gethistorytime")    //in case we have gethistorytime, we should check if we have an endtime-argument in the request.
            {   //check if the timestamp (end) is an actual value or just null
                try
                {
                    int index = cmd.LastIndexOf("''");
                    if (index >= 20)
                    {
                        cmd = cmd.Remove(cmd.LastIndexOf("''"));
                        cmd += "current_timstamp());";
                    }
                }
                catch (Exception e)
                {
                    SocketServer.LogError(e, "LogServer.txt");
                }
            }


            try
            {
                if ((ReqName.IndexOf("get") != -1) || (ReqName.IndexOf("check") != -1))
                {   //this is simply a get information, so check which DB we wanted to use for this
                    if (UseMySQLForInfo)
                        ReqSet = MySQLConn.Query(cmd);
                    else
                        ReqSet = DB2Conn.Query(cmd);
                }
                else
                {
#if (DB2ALLOWED)
                    try
                    {
                        if (DB2AllowedConn)
                            ReqSet = DB2Conn.Query(cmd);
                    }
                    catch (Exception e_DB2)
                    {
                        SocketServer.LogError(e_DB2, "LogServer.txt");
                    }
#endif
#if (MYSQLALLOWED)
                    try
                    {
                        if(MySQLAllowedConn)
                            ReqSet = MySQLConn.Query(cmd);
                    }
                    catch (Exception e_mysql)
                    {
                        SocketServer.LogError(e_mysql, "LogServer.txt");
                    }
#endif
                }
#endregion
                #region reply
                /********************************************************************************
                 *                                                                              *
                 *                   PREPARE THE REPLY THAT WILL BE SEND BACK TO THE GUI        *
                 *                   if you want to add a new request, you have to add          *
                 *                   it here into the if-else if structure.                     *
                 *                                                                              *
                 *******************************************************************************/

                //Depending on the request we have to send the xml back in a specific format
                //The column and table/dataset-names we get back from the database are not always as they should be,
                //so sometimes they have to be renamed.
                if (ReqName == "getnodeinfo")
                {
                    try
                    {
                        //Sensormeasurements as reply;
                        //Time can be a problem, so to be save:
                        ReqSet.DataSetName = "SensorMeasurements";
                        ReqSet.Tables[0].TableName = "Sensor";
                        DataSet tempSet = new DataSet("SensorMeasurements");
                        tempSet.Tables.Add(ReqSet.Tables[0].Clone());
                        tempSet.Tables[0].Columns["Time"].DataType = typeof(string);
                        tempSet.Tables[0].Rows.Add(ReqSet.Tables[0].Rows[0].ItemArray);
                        return tempSet;
                    }
                    catch (IOException e_io)
                    {
                        return CreateReplyInt(0);
                    }
                }
                else if (ReqName == "getnodetype")
                {
                    try
                    {
                        //SensorTypes as reply;
                        //DataSet has to be recreated to have the correct syntax
                        DataSet temp = new DataSet("SensorTypes");
                        temp.Tables.Add("SensorType");
                        temp.Tables[0].Columns.Add("typeid");
                        temp.Tables[0].Columns.Add("typename");
                        DataRow tempRow = temp.Tables[0].NewRow();
                        tempRow["typename"] = ReqSet.Tables[0].Rows[0][0];
                        temp.Tables[0].Rows.Add(tempRow);
                        return temp;
                    }
                    catch (IOException)
                    {
                        return CreateReplyInt(0);
                    }
                }
                else if (ReqName == "getsensortypesfromdb")
                {
                    //SensorTypes as reply
                    ReqSet.DataSetName = "SensorTypes";
                    ReqSet.Tables[0].TableName = "SensorType";
                    ReqSet.Tables[0].Columns["idSensortype"].ColumnName = "typeid";
                    ReqSet.Tables[0].Columns["Typename"].ColumnName = "typename";
                    return ReqSet;
                }
                else if ((ReqName == "adduser") || (ReqName == "changepassword")
                    || (ReqName == "checklogin") || (ReqName == "checkusername")
                    || (ReqName == "checksensorid") || (ReqName == "setpositionsensor")
                    || (ReqName == "addmaptodb") || (ReqName == "addsensortodb")
                    || (ReqName == "checkmap") || (ReqName == "checksensorid2"))
                {
                    //Reply (int) as reply
                    ReqSet.DataSetName = "Replies";
                    ReqSet.Tables[0].TableName = "Reply";
                    ReqSet.Tables[0].Columns[0].ColumnName = "INT";
                    if (ReqSet.Tables[0].Rows.Count == 0)
                    {
                        DataRow newRow = ReqSet.Tables[0].NewRow();
                        newRow[0] = 0;
                        ReqSet.Tables[0].Rows.Add(newRow);
                    }
                    return ReqSet;
                }
                else if ((ReqName == "gethistorytime") || (ReqName == "gethistorylast") || (ReqName == "getLochistorylast"))
                {
                    try
                    {
                        //Reply HistoryOfSensorMeasurements
                        if ((ReqSet.Tables.Count == 1) && (ReqSet.Tables[0].Rows.Count >= 1))
                        {
                            DataSet tempSet = new DataSet();
                            tempSet.ReadXmlSchema(@"xml\HistoryTest.xml");
                            DataRow newRow = tempSet.Tables["Sensor"].NewRow();
                            newRow["ID"] = Set.Tables[1].Rows[0]["arg_text"];
                            newRow["MeasurementType"] = Set.Tables[1].Rows[1]["arg_text"];
                            newRow["Sensor_Id"] = 1;
                            tempSet.Tables["Sensor"].Rows.Add(newRow);
                            foreach (DataRow row in ReqSet.Tables[0].Rows)
                            {
                                DataRow newRow2 = tempSet.Tables["Measurement"].NewRow();
                                newRow2[0] = row.ItemArray[1];
                                newRow2[1] = row.ItemArray[2];
                                newRow2[2] = row.ItemArray[0];
                                tempSet.Tables["Measurement"].Rows.Add(newRow2);
                            }

                            ReqSet = tempSet.Copy();
                            return ReqSet;
                        }
                        else
                        {
                            //No results that match the info we want...
                            //return CreateReplyInt(0);
                        }
                    }
                    catch (IOException e_io)
                    {
                        return CreateReplyInt(0);
                    }
                }
                else if ((ReqName == "getallsensors") || (ReqName == "getalltelosb") || (ReqName == "getsensors"))
                {
                    //MapSensors as reply
                    ReqSet.DataSetName = "AllSensors";
                    ReqSet.Tables[0].TableName = "Sensor";
                    return ReqSet;
                }
                else if (ReqName == "getnodelocinfo")
                {
                    ReqSet.DataSetName = "LocMeasurements";
                    ReqSet.Tables[0].TableName = "Position";
                    DataSet tempSet = new DataSet("LocMeasurements");
                    tempSet.Tables.Add(ReqSet.Tables[0].Clone());
                    tempSet.Tables[0].Columns["Time"].DataType = typeof(string);
                    tempSet.Tables[0].Rows.Add(ReqSet.Tables[0].Rows[0].ItemArray);
                    return tempSet;
                }
                else if (ReqName == "getstatus")
                {
                    ReqSet.DataSetName = "StatusData";
                    ReqSet.Tables[0].TableName = "Status";
                    return ReqSet;
                }
                else if (ReqName == "getnodeactions")
                {
                    //NodeActions as reply
                    ReqSet.DataSetName = "NodeActions";
                    ReqSet.Tables[0].TableName = "SensorNode";
                    ReqSet.Tables[0].Columns[0].ColumnName = "AvailAction";
                    return ReqSet;
                }
                else if (ReqName == "getnodeid")
                {
                    ReqSet.DataSetName = "NodeIDs";
                    ReqSet.Tables[0].TableName = "NodeID";
                    return ReqSet;
                }
                else if (ReqName == "getwsnid")
                {
                    ReqSet.DataSetName = "WSNIDs";
                    ReqSet.Tables[0].TableName = "WSNID";
                    return ReqSet;
                }
            }
            catch (Exception e)
            {
                SocketServer.LogError(e, "LogServer.txt");

                //Create an error-xml-msg
                ReqSet = CreateReplyInt(0);
            }

            /********************************************************************************
             *                                                                              *
             *        END OF THE DIFFERENT REQUESTS AND THEIR CORRESPONDING REPLIES        *
             *                                                                              *
             *******************************************************************************/
                #endregion

            return ReqSet;
        }
Esempio n. 18
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;
	
		//create source dataset
		DataSet ds = new DataSet();
		DataTable dt = GHTUtils.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();
		}

		try
		{
			BeginCase("Merge - changed values");
			dsTarget.Merge(ds);
			Compare(dsTarget.Tables["Table2"].Select("ParentId=1")[0][1] , "OldValue1");
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
        
		try
		{
			BeginCase("Merge - added values");
			Compare(dsTarget.Tables["Table2"].Select("ParentId=99")[0].ItemArray  , arrAddedRow);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		try
		{
			BeginCase("Merge - deleted row");
			Compare(dsTarget.Tables["Table2"].Select("ParentId=2").Length ,0);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		

		//Table1 rows count should be double (no primary key)
		try
		{
			BeginCase("Merge - Unchanged table 1");
			Compare(dsTarget.Tables["Table1"].Rows.Count ,iTable1RowsCount * 2);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		//SmallTable rows count should be the same
		try
		{
			BeginCase("Merge - Unchanged table 2");
			Compare(dsTarget.Tables["SmallTable"].Rows.Count ,1);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		//SomeTable - new table
		try
		{
			BeginCase("Merge - new table");
			Compare(dsTarget.Tables["SomeTable"] != null, true);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

	}
Esempio n. 19
0
        internal static bool VerifySqlProjFile(DataSet ds, string sqlProjPath)
        {
            DataTable dt = null;
              bool hasChanges = false;
              string ver = "2.6.0.0";
              string asmName = "yukondeploy,version=2.6.0.0,culture=neutral,publickeytoken=837e5cc1726a2c56";

              dt = ds.Tables["UsingTask"];
              foreach (DataRow row in dt.Rows)
              {
            if (!row["AssemblyName"].ToString().Contains(ver))
            {
              row["AssemblyName"] = asmName;
              hasChanges = true;
            }

              }

              //create the table which will hold the projfile with
              DataTable dtFile = new DataTable();
              dtFile.Columns.Add(new DataColumn("TableName", typeof(string)));
              dtFile.Columns.Add(new DataColumn("ColumnName", typeof(string)));
              dtFile.Columns.Add(new DataColumn("TypeName", typeof(string)));
              dtFile.Columns.Add(new DataColumn("ObjectValue", typeof(object)));
              dtFile.Columns.Add(new DataColumn("MapType", typeof(MappingType)));

              //add values
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Assemblyname", "System.String", "$(AssemblyName)", MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Alterassembly", "System.Boolean", false, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Uncheckeddata", "System.Boolean", false, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Permissionset", "System.Int32", 0, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "ConnectDatabase", "System.Boolean", true, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Connectionstring", "System.String", "server=localhost;database=[DB_NAME];Integrated Security='SSPI'", MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Infermethods", "System.Boolean", false, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "DropTable", "System.Boolean", true, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Uploadsource", "System.Boolean", false, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourceextension", "System.String", "cs", MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Sourcepath", "System.String", "$(MSBuildProjectDirectory)", MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Usedeployattributes", "System.Boolean", true, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Deploydbgsymbols", "System.Boolean", true, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Debugpath", "System.String", "$(TargetDir)$(TargetName).pdb", MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Castudtcolto", "System.Int32", 0, MappingType.Element });
              dtFile.Rows.Add(new object[] { "PropertyGroup", "Serverversion", "System.Int32", 0, MappingType.Element });
              dtFile.Rows.Add(new object[] { "DeployAssembly", "UsingDMDeployAttributes", "System.String", "$(Usedeployattributes)", MappingType.Attribute });
              dtFile.Rows.Add(new object[] { "DeployAssembly", "DeployDebugSymbols", "System.String", "$(Deploydbgsymbols)", MappingType.Attribute });
              dtFile.Rows.Add(new object[] { "DeployAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });
              dtFile.Rows.Add(new object[] { "DeployAssembly", "SqlServerVersion", "System.String", "$(Serverversion)", MappingType.Attribute });
              dtFile.Rows.Add(new object[] { "DeployTypes", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });
              dtFile.Rows.Add(new object[] { "DropAssembly", "TypeToCastUDTTo", "System.String", "$(Castudtcolto)", MappingType.Attribute });

              bool ret = false;

              //read off the values and check against the proj-file
              foreach (DataRow r in dtFile.Rows)
              {
            ret = CheckDataSet2(ds, r["TableName"].ToString(), r["ColumnName"].ToString(), r["TypeName"].ToString(), (object)r["ObjectValue"], (MappingType)r["MapType"]);
            if (ret)
              hasChanges = true;
              }

              if (hasChanges)
              {
            ds.AcceptChanges();
            DataSet dsUpdate = null;
            dsUpdate = ds.Copy();
            XmlDataDocument doc = new XmlDataDocument(dsUpdate);
            doc.Save(sqlProjPath);
            ds.Clear();
            ds.Dispose();

              }
              return hasChanges;
        }
Esempio n. 20
0
		public void Merge_MissingEventHandler ()
		{
			DataSet 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);
		}
Esempio n. 21
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.AreEqual (1, ds1.Relations.Count, "#1");
			Assert.AreEqual (1, ds2.Relations.Count, "#2");

			Assert.AreEqual (0, ds1.Tables [0].Constraints.Count, "#3");
			Assert.AreEqual (0, ds1.Tables [1].Constraints.Count, "#4");

			Assert.AreEqual (0, ds2.Tables [0].Constraints.Count, "#5");
			Assert.AreEqual (0, ds2.Tables [1].Constraints.Count, "#6");
		}
Esempio n. 22
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.AreEqual (2, table2.Constraints.Count, "#1 fk constraint shud be merged");
			Assert.AreEqual ("Constraint1", table2.Constraints [1].ConstraintName, "#2 constraint name shud be changed");
		}
Esempio n. 23
0
		[Test] 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.AreEqual(true , EventRaised , "DS158");
		}
Esempio n. 24
0
		[Test] public void Merge_ByDataTable()
		{
			//create source dataset
			DataSet 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.AreEqual("OldValue1", dsTarget.Tables["Table2"].Select("ParentId=1")[0][1] , "DS240");

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

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

			//test case added due to a reported bug from infogate
			//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.AreEqual(1, ds.Tables.Count, "DS243");

			// Merge - add a table with no name - check Rows.Count
			Assert.AreEqual(dt.Rows.Count , ds.Tables[0].Rows.Count , "DS244");
		}
Esempio n. 25
0
 void gridViewNgayNghiPhep_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
 {
     DataRow row = gridViewNgayNghiPhep.GetDataRow(e.RowHandle);
     if (row == null) return;
     row.ClearErrors();
     ds = (gridControlNgayNghiPhep.DataSource as DataTable).DataSet;
     if (!HelpInputData.ValidateRow(gridViewNgayNghiPhep, row, GetRule()))
     {
         e.Valid = false;
         return;
     }
     if (string.Compare(row["SANG"].ToString(), "Y") != 0 && string.Compare(row["CHIEU"].ToString(), "Y") != 0) {
         e.Valid = false;
         row.SetColumnError("SANG","Vui lòng vào thông tin \"Sáng\"!");
         row.SetColumnError("CHIEU", "Vui lòng vào thông tin \"Chiều\"!");
         return;
     }
     DataSet newDs = new DataSet();
     newDs = ds.Copy();
     HelpDataSet.MergeDataSet(new string[] { "NGAY" }, newDs, dsforValidate);
     if (CheckDuplicate(row, newDs))
     {
         e.Valid = false;
         row.SetColumnError("NGAY", "Thông tin \"Ngày nghỉ phép\" đã được sử dụng!");
         return;
     }
 }
Esempio n. 26
0
		[Test] 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.AreEqual(false, dsTarget1.Tables["Table1"].Columns.Contains("NewColumn"), "DS245");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

			#region "Merge(dt,false/true,MissingSchemaAction.Error  )"
			//		dsTarget1 = dsTarget.Copy();
			//		// Merge true,Error - Column
			//		try {
			//			dsTarget1.Merge(dt,true,MissingSchemaAction.Error );
			//			Assert.Fail("DS261: Merge Failed to throw InvalidOperationException");
			//		}
			//		catch (InvalidOperationException) {}
			//		catch (AssertionException exc) {throw  exc;}
			//		catch (Exception exc)
			//		{
			//			Assert.Fail("DS262: Merge. Wrong exception type. Got:" + exc);
			//		}
			//
			//		// Merge false,Error - Column
			//		try {
			//			dsTarget1.Merge(dt,false,MissingSchemaAction.Error );
			//			Assert.Fail("DS263: Merge Failed to throw InvalidOperationException");
			//		}
			//		catch (InvalidOperationException) {}
			//		catch (AssertionException exc) {throw  exc;}
			//		catch (Exception exc)
			//		{
			//			Assert.Fail("DS264: Merge. Wrong exception type. Got:" + exc);
			//		}
			#endregion
		}
Esempio n. 27
0
		public void Merge_MissingColumn  ()
		{
			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));

			DataSet ds1 = ds.Copy ();

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

			ds.Merge (ds1, true, MissingSchemaAction.Error);
		}
Esempio n. 28
0
		public void Merge_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));

			DataSet ds1 = ds.Copy ();
			DataRelation rel = ds1.Relations.Add ("rel1", ds1.Tables[0].Columns[0], 
								ds1.Tables [1].Columns [0], false);

			ds.Merge (ds1);
			Assert.AreEqual (1, ds.Relations.Count , "#1");
			Assert.AreEqual (0, ds.Tables [0].Constraints.Count , "#2");
			Assert.AreEqual (0, ds.Tables [1].Constraints.Count , "#3");
		}
        private void barButtonItem4_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                DatabaseFB db = HelpDB.getDatabase();
                System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("ST_LICH_LAM_VIEC");
                DateTime NgayDauTuan = HelpDateExt.DayFirstOfWeek((DateTime)this.bardateEdit_NgayDauTuan.EditValue);

                if (LCoDinh == false)
                    db.AddInParameter(cmd, "@DNGAY_DAU_TUAN", DbType.DateTime, NgayDauTuan);
                else
                {
                    db.AddInParameter(cmd, "@DNGAY_DAU_TUAN", DbType.DateTime, null);
                    return;
                }
                DataSet ds = new DataSet();
                db.LoadDataSet(cmd, ds, "ST_LICH_LAM_VIEC");
                DataView view = ds.Tables[0].DefaultView;
                view.Sort = "TEN_NV ASC";
                DataSet dsCopy=ds.Copy();
                DataSet dsSort =DALichLamViec.SortDataSet(dsCopy,view);
                _Print print = new _Print();
                print.ReportNameFile = "EMB" + typeof(RPT_LichLamViec).FullName;

                print.MainForm = this;
                print.MainDataset = dsSort;
                print.SubDataset = new DataSet[] { HeaderDataSet() };
                print.execPreviewWith();
            }
            catch (Exception ex)
            {
                HelpMsgBox.ShowErrorMessage(ex.Message);
            }
            finally
            {
                if (FrameworkParams.wait != null) FrameworkParams.wait.Finish();
            }
        }
Esempio n. 30
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.Fail ("#1 If uniqueconstraint is missing, exception shud be thrown");
			}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.Fail ("#2 If foreignkeyconstraint is missing, exception shud be thrown");
			}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.Fail ("#2 If datarelation is missing, exception shud be thrown");
			}catch (ArgumentException e) {
			}
		}
Esempio n. 31
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;
	
		//create source dataset
		DataSet ds = new DataSet();
		DataTable dt = GHTUtils.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);
		try
		{
			BeginCase("Merge - changed values");
			Compare(dsTarget1.Tables["Table2"].Select("ParentId=1")[0][1] , oldValue);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
        
		try
		{
			BeginCase("Merge - added values");
			Compare(dsTarget1.Tables["Table2"].Select("ParentId=99")[0].ItemArray  , arrAddedRow);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		try
		{
			BeginCase("Merge - deleted row");
			Compare(dsTarget1.Tables["Table2"].Select("ParentId=2").Length ,iDeleteLength);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		#endregion

		#region "Merge(ds,false)"
		//all changes are merged (preserveChanges = false)
		dsTarget2.Merge(ds,false);
		try
		{
			BeginCase("Merge - changed values");
			Compare(dsTarget2.Tables["Table2"].Select("ParentId=1")[0][1] , "NewValue");
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
        
		try
		{
			BeginCase("Merge - added values");
			Compare(dsTarget2.Tables["Table2"].Select("ParentId=99")[0].ItemArray  , arrAddedRow);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}

		try
		{
			BeginCase("Merge - deleted row");
			Compare(dsTarget2.Tables["Table2"].Select("ParentId=2").Length ,0);
		}
		catch(Exception ex)	{exp = ex;}
		finally	{EndCase(exp); exp = null;}
		#endregion
	}
Esempio n. 32
0
		public void Merge_PrimaryKeys_IncorrectOrder ()
		{
			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 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);
		}