Esempio n. 1
0
        ///<summary>Inserts one AutoCodeItem into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(AutoCodeItem autoCodeItem, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                autoCodeItem.AutoCodeItemNum = ReplicationServers.GetKey("autocodeitem", "AutoCodeItemNum");
            }
            string command = "INSERT INTO autocodeitem (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "AutoCodeItemNum,";
            }
            command += "AutoCodeNum,OldCode,CodeNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(autoCodeItem.AutoCodeItemNum) + ",";
            }
            command +=
                POut.Long(autoCodeItem.AutoCodeNum) + ","
                + "'" + POut.String(autoCodeItem.OldCode) + "',"
                + POut.Long(autoCodeItem.CodeNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                autoCodeItem.AutoCodeItemNum = Db.NonQ(command, true, "AutoCodeItemNum", "autoCodeItem");
            }
            return(autoCodeItem.AutoCodeItemNum);
        }
Esempio n. 2
0
 ///<summary>Inserts one AutoCodeItem into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(AutoCodeItem autoCodeItem,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         autoCodeItem.AutoCodeItemNum=ReplicationServers.GetKey("autocodeitem","AutoCodeItemNum");
     }
     string command="INSERT INTO autocodeitem (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="AutoCodeItemNum,";
     }
     command+="AutoCodeNum,OldCode,CodeNum) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(autoCodeItem.AutoCodeItemNum)+",";
     }
     command+=
              POut.Long  (autoCodeItem.AutoCodeNum)+","
         +"'"+POut.String(autoCodeItem.OldCode)+"',"
         +    POut.Long  (autoCodeItem.CodeNum)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         autoCodeItem.AutoCodeItemNum=Db.NonQ(command,true);
     }
     return autoCodeItem.AutoCodeItemNum;
 }
Esempio n. 3
0
        ///<summary>Inserts one AutoCodeItem into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(AutoCodeItem autoCodeItem, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO autocodeitem (";

            if (!useExistingPK && isRandomKeys)
            {
                autoCodeItem.AutoCodeItemNum = ReplicationServers.GetKeyNoCache("autocodeitem", "AutoCodeItemNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "AutoCodeItemNum,";
            }
            command += "AutoCodeNum,OldCode,CodeNum) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(autoCodeItem.AutoCodeItemNum) + ",";
            }
            command +=
                POut.Long(autoCodeItem.AutoCodeNum) + ","
                + "'" + POut.String(autoCodeItem.OldCode) + "',"
                + POut.Long(autoCodeItem.CodeNum) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                autoCodeItem.AutoCodeItemNum = Db.NonQ(command, true, "AutoCodeItemNum", "autoCodeItem");
            }
            return(autoCodeItem.AutoCodeItemNum);
        }
Esempio n. 4
0
 ///<summary>Inserts one AutoCodeItem into the database.  Returns the new priKey.</summary>
 public static long Insert(AutoCodeItem autoCodeItem)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         autoCodeItem.AutoCodeItemNum = DbHelper.GetNextOracleKey("autocodeitem", "AutoCodeItemNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(autoCodeItem, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     autoCodeItem.AutoCodeItemNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(autoCodeItem, false));
     }
 }
Esempio n. 5
0
        ///<summary></summary>
        public static void Delete(AutoCodeItem Cur)
        {
            string command = "DELETE from autocodeitem WHERE autocodeitemnum = '"
                             + POut.PInt(Cur.AutoCodeItemNum) + "'";

            General.NonQ(command);
        }
Esempio n. 6
0
 ///<summary>Inserts one AutoCodeItem into the database.  Returns the new priKey.</summary>
 internal static long Insert(AutoCodeItem autoCodeItem)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         autoCodeItem.AutoCodeItemNum=DbHelper.GetNextOracleKey("autocodeitem","AutoCodeItemNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(autoCodeItem,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     autoCodeItem.AutoCodeItemNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(autoCodeItem,false);
     }
 }
Esempio n. 7
0
        ///<summary></summary>
        public static void Update(AutoCodeItem Cur)
        {
            string command = "UPDATE autocodeitem SET "
                             + "autocodenum='" + POut.PInt(Cur.AutoCodeNum) + "'"
                             + ",adacode ='" + POut.PString(Cur.ADACode) + "'"
                             + " WHERE autocodeitemnum = '" + POut.PInt(Cur.AutoCodeItemNum) + "'";

            General.NonQ(command);
        }
Esempio n. 8
0
        private void tbAutoItem_CellDoubleClicked(object sender, CellEventArgs e)
        {
            AutoCodeItem     AutoCodeItemCur = listForCode[tbAutoItem.SelectedRow];
            FormAutoItemEdit FormAIE         = new FormAutoItemEdit();

            FormAIE.AutoCodeItemCur = AutoCodeItemCur;
            FormAIE.ShowDialog();
            FillTable();
        }
Esempio n. 9
0
        ///<summary>Updates one AutoCodeItem in the database.</summary>
        public static void Update(AutoCodeItem autoCodeItem)
        {
            string command = "UPDATE autocodeitem SET "
                             + "AutoCodeNum    =  " + POut.Long(autoCodeItem.AutoCodeNum) + ", "
                             + "OldCode        = '" + POut.String(autoCodeItem.OldCode) + "', "
                             + "CodeNum        =  " + POut.Long(autoCodeItem.CodeNum) + " "
                             + "WHERE AutoCodeItemNum = " + POut.Long(autoCodeItem.AutoCodeItemNum);

            Db.NonQ(command);
        }
Esempio n. 10
0
        ///<summary></summary>
        public static void Insert(AutoCodeItem Cur)
        {
            string command = "INSERT INTO autocodeitem (autocodenum,adacode) "
                             + "VALUES ("
                             + "'" + POut.PInt(Cur.AutoCodeNum) + "', "
                             + "'" + POut.PString(Cur.ADACode) + "')";

            //MessageBox.Show(string command);
            Cur.AutoCodeItemNum = General.NonQ(command, true);
        }
Esempio n. 11
0
        ///<summary></summary>
        public static void Update(AutoCodeItem Cur)
        {
            string command = "UPDATE autocodeitem SET "
                             + "AutoCodeNum='" + POut.PInt(Cur.AutoCodeNum) + "'"
                             //+",Oldcode ='"  +POut.PString(Cur.OldCode)+"'"
                             + ",CodeNum ='" + POut.PInt(Cur.CodeNum) + "'"
                             + " WHERE AutoCodeItemNum = '" + POut.PInt(Cur.AutoCodeItemNum) + "'";

            General.NonQ(command);
        }
Esempio n. 12
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<AutoCodeItem> TableToList(DataTable table){
			List<AutoCodeItem> retVal=new List<AutoCodeItem>();
			AutoCodeItem autoCodeItem;
			for(int i=0;i<table.Rows.Count;i++) {
				autoCodeItem=new AutoCodeItem();
				autoCodeItem.AutoCodeItemNum= PIn.Long  (table.Rows[i]["AutoCodeItemNum"].ToString());
				autoCodeItem.AutoCodeNum    = PIn.Long  (table.Rows[i]["AutoCodeNum"].ToString());
				autoCodeItem.OldCode        = PIn.String(table.Rows[i]["OldCode"].ToString());
				autoCodeItem.CodeNum        = PIn.Long  (table.Rows[i]["CodeNum"].ToString());
				retVal.Add(autoCodeItem);
			}
			return retVal;
		}
Esempio n. 13
0
        private void butDelete_Click(object sender, System.EventArgs e)
        {
            if (tbAutoItem.SelectedRow == -1)
            {
                MessageBox.Show(Lan.g(this, "Please select an item first."));
                return;
            }
            AutoCodeItem AutoCodeItemCur = listForCode[tbAutoItem.SelectedRow];

            AutoCodeConds.DeleteForItemNum(AutoCodeItemCur.AutoCodeItemNum);
            AutoCodeItems.Delete(AutoCodeItemCur);
            FillTable();
        }
Esempio n. 14
0
 ///<summary>Inserts one AutoCodeItem into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(AutoCodeItem autoCodeItem)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(autoCodeItem, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             autoCodeItem.AutoCodeItemNum = DbHelper.GetNextOracleKey("autocodeitem", "AutoCodeItemNum");                  //Cacheless method
         }
         return(InsertNoCache(autoCodeItem, true));
     }
 }
Esempio n. 15
0
 ///<summary>Returns true if Update(AutoCodeItem,AutoCodeItem) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(AutoCodeItem autoCodeItem, AutoCodeItem oldAutoCodeItem)
 {
     if (autoCodeItem.AutoCodeNum != oldAutoCodeItem.AutoCodeNum)
     {
         return(true);
     }
     if (autoCodeItem.OldCode != oldAutoCodeItem.OldCode)
     {
         return(true);
     }
     if (autoCodeItem.CodeNum != oldAutoCodeItem.CodeNum)
     {
         return(true);
     }
     return(false);
 }
Esempio n. 16
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AutoCodeItem> TableToList(DataTable table)
        {
            List <AutoCodeItem> retVal = new List <AutoCodeItem>();
            AutoCodeItem        autoCodeItem;

            foreach (DataRow row in table.Rows)
            {
                autoCodeItem = new AutoCodeItem();
                autoCodeItem.AutoCodeItemNum = PIn.Long(row["AutoCodeItemNum"].ToString());
                autoCodeItem.AutoCodeNum     = PIn.Long(row["AutoCodeNum"].ToString());
                autoCodeItem.OldCode         = PIn.String(row["OldCode"].ToString());
                autoCodeItem.CodeNum         = PIn.Long(row["CodeNum"].ToString());
                retVal.Add(autoCodeItem);
            }
            return(retVal);
        }
Esempio n. 17
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <AutoCodeItem> TableToList(DataTable table)
        {
            List <AutoCodeItem> retVal = new List <AutoCodeItem>();
            AutoCodeItem        autoCodeItem;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                autoCodeItem = new AutoCodeItem();
                autoCodeItem.AutoCodeItemNum = PIn.Long(table.Rows[i]["AutoCodeItemNum"].ToString());
                autoCodeItem.AutoCodeNum     = PIn.Long(table.Rows[i]["AutoCodeNum"].ToString());
                autoCodeItem.OldCode         = PIn.String(table.Rows[i]["OldCode"].ToString());
                autoCodeItem.CodeNum         = PIn.Long(table.Rows[i]["CodeNum"].ToString());
                retVal.Add(autoCodeItem);
            }
            return(retVal);
        }
Esempio n. 18
0
 private void FormAutoCodeEdit_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         return;
     }
     if (IsNew)
     {
         for (int i = 0; i < AutoCodeItems.ListForCode.Length; i++)
         {
             AutoCodeItem AutoCodeItemCur = AutoCodeItems.ListForCode[i];
             AutoCodeConds.DeleteForItemNum(AutoCodeItemCur.AutoCodeItemNum);
             AutoCodeItems.Delete(AutoCodeItemCur);
         }
         AutoCodes.Delete(AutoCodeCur);
     }
 }
Esempio n. 19
0
        ///<summary></summary>
        public static void Refresh()
        {
            string    command = "SELECT * from autocodeitem";
            DataTable table   = General.GetTable(command);

            HList = new Hashtable();
            List  = new AutoCodeItem[table.Rows.Count];
            for (int i = 0; i < List.Length; i++)
            {
                List[i] = new AutoCodeItem();
                List[i].AutoCodeItemNum = PIn.PInt(table.Rows[i][0].ToString());
                List[i].AutoCodeNum     = PIn.PInt(table.Rows[i][1].ToString());
                List[i].ADACode         = PIn.PString(table.Rows[i][2].ToString());
                if (!HList.ContainsKey(List[i].ADACode))
                {
                    HList.Add(List[i].ADACode, List[i].AutoCodeNum);
                }
            }
        }
Esempio n. 20
0
        public void AllowedNullValueInternally()
        {
            using (var container = new RhetosTestContainer())
            {
                DeleteOldData(container);

                var context = container.Resolve <Common.ExecutionContext>();

                var s1 = new TestAutoCode.Simple {
                    ID = Guid.NewGuid(), Code = null
                };

                AutoCodeHelper.UpdateCodesWithoutCache(
                    context.SqlExecuter, "TestAutoCode.Simple", "Code",
                    new[] { AutoCodeItem.Create(s1, s1.Code) },
                    (item, newCode) => item.Code = newCode);

                Assert.AreEqual("1", s1.Code);
            }
        }
Esempio n. 21
0
        ///<summary>Updates one AutoCodeItem in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(AutoCodeItem autoCodeItem, AutoCodeItem oldAutoCodeItem)
        {
            string command = "";

            if (autoCodeItem.AutoCodeNum != oldAutoCodeItem.AutoCodeNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AutoCodeNum = " + POut.Long(autoCodeItem.AutoCodeNum) + "";
            }
            if (autoCodeItem.OldCode != oldAutoCodeItem.OldCode)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OldCode = '" + POut.String(autoCodeItem.OldCode) + "'";
            }
            if (autoCodeItem.CodeNum != oldAutoCodeItem.CodeNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "CodeNum = " + POut.Long(autoCodeItem.CodeNum) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE autocodeitem SET " + command
                      + " WHERE AutoCodeItemNum = " + POut.Long(autoCodeItem.AutoCodeItemNum);
            Db.NonQ(command);
            return(true);
        }
Esempio n. 22
0
 ///<summary>Inserts one AutoCodeItem into the database.  Returns the new priKey.</summary>
 public static long Insert(AutoCodeItem autoCodeItem)
 {
     return(Insert(autoCodeItem, false));
 }
Esempio n. 23
0
		///<summary>Updates one AutoCodeItem in the database.</summary>
		public static void Update(AutoCodeItem autoCodeItem){
			string command="UPDATE autocodeitem SET "
				+"AutoCodeNum    =  "+POut.Long  (autoCodeItem.AutoCodeNum)+", "
				+"OldCode        = '"+POut.String(autoCodeItem.OldCode)+"', "
				+"CodeNum        =  "+POut.Long  (autoCodeItem.CodeNum)+" "
				+"WHERE AutoCodeItemNum = "+POut.Long(autoCodeItem.AutoCodeItemNum);
			Db.NonQ(command);
		}
Esempio n. 24
0
		///<summary>Updates one AutoCodeItem in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
		public static bool Update(AutoCodeItem autoCodeItem,AutoCodeItem oldAutoCodeItem){
			string command="";
			if(autoCodeItem.AutoCodeNum != oldAutoCodeItem.AutoCodeNum) {
				if(command!=""){ command+=",";}
				command+="AutoCodeNum = "+POut.Long(autoCodeItem.AutoCodeNum)+"";
			}
			if(autoCodeItem.OldCode != oldAutoCodeItem.OldCode) {
				if(command!=""){ command+=",";}
				command+="OldCode = '"+POut.String(autoCodeItem.OldCode)+"'";
			}
			if(autoCodeItem.CodeNum != oldAutoCodeItem.CodeNum) {
				if(command!=""){ command+=",";}
				command+="CodeNum = "+POut.Long(autoCodeItem.CodeNum)+"";
			}
			if(command==""){
				return false;
			}
			command="UPDATE autocodeitem SET "+command
				+" WHERE AutoCodeItemNum = "+POut.Long(autoCodeItem.AutoCodeItemNum);
			Db.NonQ(command);
			return true;
		}