Пример #1
0
		///<summary>Inserts one SigButDef into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(SigButDef sigButDef,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				sigButDef.SigButDefNum=ReplicationServers.GetKey("sigbutdef","SigButDefNum");
			}
			string command="INSERT INTO sigbutdef (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="SigButDefNum,";
			}
			command+="ButtonText,ButtonIndex,SynchIcon,ComputerName) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(sigButDef.SigButDefNum)+",";
			}
			command+=
				 "'"+POut.String(sigButDef.ButtonText)+"',"
				+    POut.Int   (sigButDef.ButtonIndex)+","
				+    POut.Byte  (sigButDef.SynchIcon)+","
				+"'"+POut.String(sigButDef.ComputerName)+"')";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				sigButDef.SigButDefNum=Db.NonQ(command,true);
			}
			return sigButDef.SigButDefNum;
		}
Пример #2
0
 ///<summary>Inserts one SigButDef into the database.  Returns the new priKey.</summary>
 internal static long Insert(SigButDef sigButDef)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         sigButDef.SigButDefNum=DbHelper.GetNextOracleKey("sigbutdef","SigButDefNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(sigButDef,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     sigButDef.SigButDefNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(sigButDef,false);
     }
 }
Пример #3
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<SigButDef> TableToList(DataTable table){
			List<SigButDef> retVal=new List<SigButDef>();
			SigButDef sigButDef;
			for(int i=0;i<table.Rows.Count;i++) {
				sigButDef=new SigButDef();
				sigButDef.SigButDefNum= PIn.Long  (table.Rows[i]["SigButDefNum"].ToString());
				sigButDef.ButtonText  = PIn.String(table.Rows[i]["ButtonText"].ToString());
				sigButDef.ButtonIndex = PIn.Int   (table.Rows[i]["ButtonIndex"].ToString());
				sigButDef.SynchIcon   = PIn.Byte  (table.Rows[i]["SynchIcon"].ToString());
				sigButDef.ComputerName= PIn.String(table.Rows[i]["ComputerName"].ToString());
				retVal.Add(sigButDef);
			}
			return retVal;
		}
Пример #4
0
		///<summary>Updates one SigButDef 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(SigButDef sigButDef,SigButDef oldSigButDef){
			string command="";
			if(sigButDef.ButtonText != oldSigButDef.ButtonText) {
				if(command!=""){ command+=",";}
				command+="ButtonText = '"+POut.String(sigButDef.ButtonText)+"'";
			}
			if(sigButDef.ButtonIndex != oldSigButDef.ButtonIndex) {
				if(command!=""){ command+=",";}
				command+="ButtonIndex = "+POut.Int(sigButDef.ButtonIndex)+"";
			}
			if(sigButDef.SynchIcon != oldSigButDef.SynchIcon) {
				if(command!=""){ command+=",";}
				command+="SynchIcon = "+POut.Byte(sigButDef.SynchIcon)+"";
			}
			if(sigButDef.ComputerName != oldSigButDef.ComputerName) {
				if(command!=""){ command+=",";}
				command+="ComputerName = '"+POut.String(sigButDef.ComputerName)+"'";
			}
			if(command==""){
				return false;
			}
			command="UPDATE sigbutdef SET "+command
				+" WHERE SigButDefNum = "+POut.Long(sigButDef.SigButDefNum);
			Db.NonQ(command);
			return true;
		}
Пример #5
0
		///<summary>Updates one SigButDef in the database.</summary>
		public static void Update(SigButDef sigButDef){
			string command="UPDATE sigbutdef SET "
				+"ButtonText  = '"+POut.String(sigButDef.ButtonText)+"', "
				+"ButtonIndex =  "+POut.Int   (sigButDef.ButtonIndex)+", "
				+"SynchIcon   =  "+POut.Byte  (sigButDef.SynchIcon)+", "
				+"ComputerName= '"+POut.String(sigButDef.ComputerName)+"' "
				+"WHERE SigButDefNum = "+POut.Long(sigButDef.SigButDefNum);
			Db.NonQ(command);
		}
Пример #6
0
        ///<summary>Updates one SigButDef 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(SigButDef sigButDef, SigButDef oldSigButDef)
        {
            string command = "";

            if (sigButDef.ButtonText != oldSigButDef.ButtonText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ButtonText = '" + POut.String(sigButDef.ButtonText) + "'";
            }
            if (sigButDef.ButtonIndex != oldSigButDef.ButtonIndex)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ButtonIndex = " + POut.Int(sigButDef.ButtonIndex) + "";
            }
            if (sigButDef.SynchIcon != oldSigButDef.SynchIcon)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SynchIcon = " + POut.Byte(sigButDef.SynchIcon) + "";
            }
            if (sigButDef.ComputerName != oldSigButDef.ComputerName)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ComputerName = '" + POut.String(sigButDef.ComputerName) + "'";
            }
            if (sigButDef.SigElementDefNumUser != oldSigButDef.SigElementDefNumUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumUser = "******"";
            }
            if (sigButDef.SigElementDefNumExtra != oldSigButDef.SigElementDefNumExtra)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumExtra = " + POut.Long(sigButDef.SigElementDefNumExtra) + "";
            }
            if (sigButDef.SigElementDefNumMsg != oldSigButDef.SigElementDefNumMsg)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumMsg = " + POut.Long(sigButDef.SigElementDefNumMsg) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE sigbutdef SET " + command
                      + " WHERE SigButDefNum = " + POut.Long(sigButDef.SigButDefNum);
            Db.NonQ(command);
            return(true);
        }
Пример #7
0
 ///<summary>Inserts one SigButDef into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SigButDef sigButDef)
 {
     return(InsertNoCache(sigButDef, false));
 }
Пример #8
0
        ///<summary>Used in the Button edit dialog.</summary>
        public static void DeleteElements(SigButDef def)
        {
            string command = "DELETE FROM sigbutdefelement WHERE SigButDefNum=" + POut.PInt(def.SigButDefNum);

            General.NonQ(command);
        }