Ejemplo n.º 1
0
 ///<summary>Inserts one SigMessage into the database.  Returns the new priKey.</summary>
 public static long Insert(SigMessage sigMessage)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         sigMessage.SigMessageNum = DbHelper.GetNextOracleKey("sigmessage", "SigMessageNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(sigMessage, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     sigMessage.SigMessageNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(sigMessage, false));
     }
 }
Ejemplo n.º 2
0
        ///<summary></summary>
        protected void OnButtonClicked(int myButton, SigButDef myDef, SigMessage mySignal)
        {
            ODLightSignalGridClickEventArgs bArgs = new ODLightSignalGridClickEventArgs(myButton, myDef, mySignal);

            if (ButtonClick != null)
            {
                ButtonClick(this, bArgs);
            }
        }
Ejemplo n.º 3
0
 ///<summary>Inserts one SigMessage into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SigMessage sigMessage)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(sigMessage, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             sigMessage.SigMessageNum = DbHelper.GetNextOracleKey("sigmessage", "SigMessageNum");                  //Cacheless method
         }
         return(InsertNoCache(sigMessage, true));
     }
 }
Ejemplo n.º 4
0
 ///<summary>Sets the specified buttonIndex to a color and attaches the signal responsible.  This is also used for the manual ack to increase responsiveness.  buttonIndex is 0-based.</summary>
 public void SetButtonActive(int buttonIndex, Color color, SigMessage activeSigMessage)
 {
     if (!IsValidSigButState(buttonIndex))
     {
         return;                //no button to light up.
     }
     sigButStates[buttonIndex].CurrentColor = color;
     if (activeSigMessage == null)
     {
         sigButStates[buttonIndex].ActiveSignal = null;
     }
     else
     {
         sigButStates[buttonIndex].ActiveSignal = activeSigMessage.Copy();
     }
     Invalidate();
 }
Ejemplo n.º 5
0
 ///<summary>Returns true if Update(SigMessage,SigMessage) 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(SigMessage sigMessage, SigMessage oldSigMessage)
 {
     if (sigMessage.ButtonText != oldSigMessage.ButtonText)
     {
         return(true);
     }
     if (sigMessage.ButtonIndex != oldSigMessage.ButtonIndex)
     {
         return(true);
     }
     if (sigMessage.SynchIcon != oldSigMessage.SynchIcon)
     {
         return(true);
     }
     if (sigMessage.FromUser != oldSigMessage.FromUser)
     {
         return(true);
     }
     if (sigMessage.ToUser != oldSigMessage.ToUser)
     {
         return(true);
     }
     //MessageDateTime not allowed to change
     if (sigMessage.AckDateTime != oldSigMessage.AckDateTime)
     {
         return(true);
     }
     if (sigMessage.SigText != oldSigMessage.SigText)
     {
         return(true);
     }
     if (sigMessage.SigElementDefNumUser != oldSigMessage.SigElementDefNumUser)
     {
         return(true);
     }
     if (sigMessage.SigElementDefNumExtra != oldSigMessage.SigElementDefNumExtra)
     {
         return(true);
     }
     if (sigMessage.SigElementDefNumMsg != oldSigMessage.SigElementDefNumMsg)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
        ///<summary>Updates one SigMessage in the database.</summary>
        public static void Update(SigMessage sigMessage)
        {
            string command = "UPDATE sigmessage SET "
                             + "ButtonText           = '" + POut.String(sigMessage.ButtonText) + "', "
                             + "ButtonIndex          =  " + POut.Int(sigMessage.ButtonIndex) + ", "
                             + "SynchIcon            =  " + POut.Byte(sigMessage.SynchIcon) + ", "
                             + "FromUser             = '******', "
                             + "ToUser               = '******', "
                             //MessageDateTime not allowed to change
                             + "AckDateTime          =  " + POut.DateT(sigMessage.AckDateTime) + ", "
                             + "SigText              = '" + POut.String(sigMessage.SigText) + "', "
                             + "SigElementDefNumUser =  "******", "
                             + "SigElementDefNumExtra=  " + POut.Long(sigMessage.SigElementDefNumExtra) + ", "
                             + "SigElementDefNumMsg  =  " + POut.Long(sigMessage.SigElementDefNumMsg) + " "
                             + "WHERE SigMessageNum = " + POut.Long(sigMessage.SigMessageNum);

            Db.NonQ(command);
        }
Ejemplo n.º 7
0
        ///<summary>Inserts one SigMessage into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(SigMessage sigMessage, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO sigmessage (";

            if (!useExistingPK && isRandomKeys)
            {
                sigMessage.SigMessageNum = ReplicationServers.GetKeyNoCache("sigmessage", "SigMessageNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "SigMessageNum,";
            }
            command += "ButtonText,ButtonIndex,SynchIcon,FromUser,ToUser,MessageDateTime,AckDateTime,SigText,SigElementDefNumUser,SigElementDefNumExtra,SigElementDefNumMsg) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(sigMessage.SigMessageNum) + ",";
            }
            command +=
                "'" + POut.String(sigMessage.ButtonText) + "',"
                + POut.Int(sigMessage.ButtonIndex) + ","
                + POut.Byte(sigMessage.SynchIcon) + ","
                + "'" + POut.String(sigMessage.FromUser) + "',"
                + "'" + POut.String(sigMessage.ToUser) + "',"
                + DbHelper.Now() + ","
                + POut.DateT(sigMessage.AckDateTime) + ","
                + "'" + POut.String(sigMessage.SigText) + "',"
                + POut.Long(sigMessage.SigElementDefNumUser) + ","
                + POut.Long(sigMessage.SigElementDefNumExtra) + ","
                + POut.Long(sigMessage.SigElementDefNumMsg) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                sigMessage.SigMessageNum = Db.NonQ(command, true, "SigMessageNum", "sigMessage");
            }
            return(sigMessage.SigMessageNum);
        }
Ejemplo n.º 8
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <SigMessage> TableToList(DataTable table)
        {
            List <SigMessage> retVal = new List <SigMessage>();
            SigMessage        sigMessage;

            foreach (DataRow row in table.Rows)
            {
                sigMessage = new SigMessage();
                sigMessage.SigMessageNum         = PIn.Long(row["SigMessageNum"].ToString());
                sigMessage.ButtonText            = PIn.String(row["ButtonText"].ToString());
                sigMessage.ButtonIndex           = PIn.Int(row["ButtonIndex"].ToString());
                sigMessage.SynchIcon             = PIn.Byte(row["SynchIcon"].ToString());
                sigMessage.FromUser              = PIn.String(row["FromUser"].ToString());
                sigMessage.ToUser                = PIn.String(row["ToUser"].ToString());
                sigMessage.MessageDateTime       = PIn.DateT(row["MessageDateTime"].ToString());
                sigMessage.AckDateTime           = PIn.DateT(row["AckDateTime"].ToString());
                sigMessage.SigText               = PIn.String(row["SigText"].ToString());
                sigMessage.SigElementDefNumUser  = PIn.Long(row["SigElementDefNumUser"].ToString());
                sigMessage.SigElementDefNumExtra = PIn.Long(row["SigElementDefNumExtra"].ToString());
                sigMessage.SigElementDefNumMsg   = PIn.Long(row["SigElementDefNumMsg"].ToString());
                retVal.Add(sigMessage);
            }
            return(retVal);
        }
Ejemplo n.º 9
0
 /// <summary></summary>
 /// <param name="myButton"></param>
 public ODLightSignalGridClickEventArgs(int myButton, SigButDef myDef, SigMessage mySignal)
 {
     buttonIndex  = myButton;
     buttonDef    = myDef;
     activeSignal = mySignal;
 }
Ejemplo n.º 10
0
        ///<summary>Updates one SigMessage 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(SigMessage sigMessage, SigMessage oldSigMessage)
        {
            string command = "";

            if (sigMessage.ButtonText != oldSigMessage.ButtonText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ButtonText = '" + POut.String(sigMessage.ButtonText) + "'";
            }
            if (sigMessage.ButtonIndex != oldSigMessage.ButtonIndex)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ButtonIndex = " + POut.Int(sigMessage.ButtonIndex) + "";
            }
            if (sigMessage.SynchIcon != oldSigMessage.SynchIcon)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SynchIcon = " + POut.Byte(sigMessage.SynchIcon) + "";
            }
            if (sigMessage.FromUser != oldSigMessage.FromUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FromUser = '******'";
            }
            if (sigMessage.ToUser != oldSigMessage.ToUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ToUser = '******'";
            }
            //MessageDateTime not allowed to change
            if (sigMessage.AckDateTime != oldSigMessage.AckDateTime)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AckDateTime = " + POut.DateT(sigMessage.AckDateTime) + "";
            }
            if (sigMessage.SigText != oldSigMessage.SigText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigText = '" + POut.String(sigMessage.SigText) + "'";
            }
            if (sigMessage.SigElementDefNumUser != oldSigMessage.SigElementDefNumUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumUser = "******"";
            }
            if (sigMessage.SigElementDefNumExtra != oldSigMessage.SigElementDefNumExtra)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumExtra = " + POut.Long(sigMessage.SigElementDefNumExtra) + "";
            }
            if (sigMessage.SigElementDefNumMsg != oldSigMessage.SigElementDefNumMsg)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigElementDefNumMsg = " + POut.Long(sigMessage.SigElementDefNumMsg) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE sigmessage SET " + command
                      + " WHERE SigMessageNum = " + POut.Long(sigMessage.SigMessageNum);
            Db.NonQ(command);
            return(true);
        }
Ejemplo n.º 11
0
 ///<summary>Inserts one SigMessage into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(SigMessage sigMessage)
 {
     return(InsertNoCache(sigMessage, false));
 }