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

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "SigElementNum,";
            }
            command += "SigElementDefNum,SignalNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(sigElement.SigElementNum) + ",";
            }
            command +=
                POut.Long(sigElement.SigElementDefNum) + ","
                + POut.Long(sigElement.SignalNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                sigElement.SigElementNum = Db.NonQ(command, true);
            }
            return(sigElement.SigElementNum);
        }
Exemplo n.º 2
0
 ///<summary>Inserts one SigElement into the database.  Returns the new priKey.</summary>
 public static long Insert(SigElement sigElement)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         sigElement.SigElementNum = DbHelper.GetNextOracleKey("sigelement", "SigElementNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(sigElement, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     sigElement.SigElementNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(sigElement, false));
     }
 }
Exemplo n.º 3
0
        ///<summary>Updates one SigElement 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.</summary>
        public static void Update(SigElement sigElement, SigElement oldSigElement)
        {
            string command = "";

            if (sigElement.SigElementDefNum != oldSigElement.SigElementDefNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNum = " + POut.Long(sigElement.SigElementDefNum) + "";
            }
            if (sigElement.SignalNum != oldSigElement.SignalNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SignalNum = " + POut.Long(sigElement.SignalNum) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE sigelement SET " + command
                      + " WHERE SigElementNum = " + POut.Long(sigElement.SigElementNum);
            Db.NonQ(command);
        }
Exemplo n.º 4
0
 ///<summary>Inserts one SigElement into the database.  Returns the new priKey.</summary>
 internal static long Insert(SigElement sigElement)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         sigElement.SigElementNum=DbHelper.GetNextOracleKey("sigelement","SigElementNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(sigElement,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     sigElement.SigElementNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(sigElement,false);
     }
 }
Exemplo n.º 5
0
        /*
         * ///<summary>This will never happen</summary>
         * public void Update(){
         *      string command= "UPDATE sigelement SET "
         +"FromUser = '******'"
         +",ITypes = '"     +POut.PInt   ((int)ITypes)+"'"
         +",DateViewing = '"+POut.PDate  (DateViewing)+"'"
         +",SigType = '"    +POut.PInt   ((int)SigType)+"'"
         +" WHERE SigElementNum = '"+POut.PInt(SigElementNum)+"'";
         *      DataConnection dcon=new DataConnection();
         *      General.NonQ(command);
         * }*/

        ///<summary></summary>
        public static void Insert(SigElement se)
        {
            if (PrefB.RandomKeys)
            {
                se.SigElementNum = MiscData.GetKey("sigelement", "SigElementNum");
            }
            string command = "INSERT INTO sigelement (";

            if (PrefB.RandomKeys)
            {
                command += "SigElementNum,";
            }
            command += "SigElementDefNum,SignalNum"
                       + ") VALUES(";
            if (PrefB.RandomKeys)
            {
                command += "'" + POut.PInt(se.SigElementNum) + "', ";
            }
            command +=
                "'" + POut.PInt(se.SigElementDefNum) + "', "
                + "'" + POut.PInt(se.SignalNum) + "')";
            if (PrefB.RandomKeys)
            {
                General.NonQ(command);
            }
            else
            {
                se.SigElementNum = General.NonQ(command, true);
            }
        }
Exemplo n.º 6
0
        ///<summary>Gets all SigElements for a set of Signals, ordered by type: user,extras, message.</summary>
        public static SigElement[] GetElements(Signal[] signalList)
        {
            if (signalList.Length == 0)
            {
                return(new SigElement[0]);
            }
            string command = "SELECT sigelement.* FROM sigelement,sigelementdef WHERE "
                             + "sigelement.SigElementDefNum=sigelementdef.SigElementDefNum AND (";

            for (int i = 0; i < signalList.Length; i++)
            {
                if (i > 0)
                {
                    command += " OR ";
                }
                command += "SignalNum=" + POut.PInt(signalList[i].SignalNum);
            }
            command += ") ORDER BY sigelementdef.SigElementType";
            DataTable table = General.GetTable(command);

            SigElement[] List = new SigElement[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                List[i] = new SigElement();
                List[i].SigElementNum    = PIn.PInt(table.Rows[i][0].ToString());
                List[i].SigElementDefNum = PIn.PInt(table.Rows[i][1].ToString());
                List[i].SignalNum        = PIn.PInt(table.Rows[i][2].ToString());
            }
            //Array.Sort(List);
            return(List);
        }
Exemplo n.º 7
0
        ///<summary>Updates one SigElement in the database.</summary>
        public static void Update(SigElement sigElement)
        {
            string command = "UPDATE sigelement SET "
                             + "SigElementDefNum=  " + POut.Long(sigElement.SigElementDefNum) + ", "
                             + "SignalNum       =  " + POut.Long(sigElement.SignalNum) + " "
                             + "WHERE SigElementNum = " + POut.Long(sigElement.SigElementNum);

            Db.NonQ(command);
        }
Exemplo n.º 8
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<SigElement> TableToList(DataTable table){
			List<SigElement> retVal=new List<SigElement>();
			SigElement sigElement;
			for(int i=0;i<table.Rows.Count;i++) {
				sigElement=new SigElement();
				sigElement.SigElementNum   = PIn.Long  (table.Rows[i]["SigElementNum"].ToString());
				sigElement.SigElementDefNum= PIn.Long  (table.Rows[i]["SigElementDefNum"].ToString());
				sigElement.SignalNum       = PIn.Long  (table.Rows[i]["SignalNum"].ToString());
				retVal.Add(sigElement);
			}
			return retVal;
		}
Exemplo n.º 9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SigElement> TableToList(DataTable table)
        {
            List <SigElement> retVal = new List <SigElement>();
            SigElement        sigElement;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                sigElement = new SigElement();
                sigElement.SigElementNum    = PIn.Long(table.Rows[i]["SigElementNum"].ToString());
                sigElement.SigElementDefNum = PIn.Long(table.Rows[i]["SigElementDefNum"].ToString());
                sigElement.SignalNum        = PIn.Long(table.Rows[i]["SignalNum"].ToString());
                retVal.Add(sigElement);
            }
            return(retVal);
        }
Exemplo n.º 10
0
        //<summary>There's no such thing as deleting a SigElement</summary>

        /*public void Delete(){
         *      string command= "DELETE from SigElement WHERE SigElementNum = '"
         +POut.PInt(SigElementNum)+"'";
         *      DataConnection dcon=new DataConnection();
         *      General.NonQ(command);
         * }*/

        ///<summary>Loops through the supplied sigElement list and pulls out all elements for one specific signal.</summary>
        public static SigElement[] GetForSig(SigElement[] elementList, int signalNum)
        {
            ArrayList AL = new ArrayList();

            for (int i = 0; i < elementList.Length; i++)
            {
                if (elementList[i].SignalNum == signalNum)
                {
                    AL.Add(elementList[i].Copy());
                }
            }
            SigElement[] retVal = new SigElement[AL.Count];
            AL.CopyTo(retVal);
            return(retVal);
        }
Exemplo n.º 11
0
		///<summary>Inserts one SigElement into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(SigElement sigElement,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				sigElement.SigElementNum=ReplicationServers.GetKey("sigelement","SigElementNum");
			}
			string command="INSERT INTO sigelement (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="SigElementNum,";
			}
			command+="SigElementDefNum,SignalNum) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(sigElement.SigElementNum)+",";
			}
			command+=
				     POut.Long  (sigElement.SigElementDefNum)+","
				+    POut.Long  (sigElement.SignalNum)+")";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				sigElement.SigElementNum=Db.NonQ(command,true);
			}
			return sigElement.SigElementNum;
		}
Exemplo n.º 12
0
		///<summary>Updates one SigElement 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(SigElement sigElement,SigElement oldSigElement){
			string command="";
			if(sigElement.SigElementDefNum != oldSigElement.SigElementDefNum) {
				if(command!=""){ command+=",";}
				command+="SigElementDefNum = "+POut.Long(sigElement.SigElementDefNum)+"";
			}
			if(sigElement.SignalNum != oldSigElement.SignalNum) {
				if(command!=""){ command+=",";}
				command+="SignalNum = "+POut.Long(sigElement.SignalNum)+"";
			}
			if(command==""){
				return false;
			}
			command="UPDATE sigelement SET "+command
				+" WHERE SigElementNum = "+POut.Long(sigElement.SigElementNum);
			Db.NonQ(command);
			return true;
		}
Exemplo n.º 13
0
		///<summary>Updates one SigElement in the database.</summary>
		public static void Update(SigElement sigElement){
			string command="UPDATE sigelement SET "
				+"SigElementDefNum=  "+POut.Long  (sigElement.SigElementDefNum)+", "
				+"SignalNum       =  "+POut.Long  (sigElement.SignalNum)+" "
				+"WHERE SigElementNum = "+POut.Long(sigElement.SigElementNum);
			Db.NonQ(command);
		}