Example #1
0
 ///<summary>Inserts one Signalod into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(Signalod signalod,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         signalod.SignalNum=ReplicationServers.GetKey("signalod","SignalNum");
     }
     string command="INSERT INTO signalod (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="SignalNum,";
     }
     command+="FromUser,ITypes,DateViewing,SigType,SigText,SigDateTime,ToUser,AckTime,TaskNum) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(signalod.SignalNum)+",";
     }
     command+=
          "'"+POut.String(signalod.FromUser)+"',"
         +"'"+POut.String(signalod.ITypes)+"',"
         +    POut.Date  (signalod.DateViewing)+","
         +    POut.Int   ((int)signalod.SigType)+","
         +"'"+POut.String(signalod.SigText)+"',"
         +    POut.DateT (signalod.SigDateTime)+","
         +"'"+POut.String(signalod.ToUser)+"',"
         +    POut.DateT (signalod.AckTime)+","
         +    POut.Long  (signalod.TaskNum)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         signalod.SignalNum=Db.NonQ(command,true);
     }
     return signalod.SignalNum;
 }
Example #2
0
 ///<summary>Returns true if Update(Signalod,Signalod) 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(Signalod signalod, Signalod oldSignalod)
 {
     if (signalod.DateViewing.Date != oldSignalod.DateViewing.Date)
     {
         return(true);
     }
     if (signalod.SigDateTime != oldSignalod.SigDateTime)
     {
         return(true);
     }
     if (signalod.FKey != oldSignalod.FKey)
     {
         return(true);
     }
     if (signalod.FKeyType != oldSignalod.FKeyType)
     {
         return(true);
     }
     if (signalod.IType != oldSignalod.IType)
     {
         return(true);
     }
     if (signalod.RemoteRole != oldSignalod.RemoteRole)
     {
         return(true);
     }
     if (signalod.MsgValue != oldSignalod.MsgValue)
     {
         return(true);
     }
     return(false);
 }
Example #3
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <Signalod> TableToList(DataTable table)
        {
            List <Signalod> retVal = new List <Signalod>();
            Signalod        signalod;

            foreach (DataRow row in table.Rows)
            {
                signalod             = new Signalod();
                signalod.SignalNum   = PIn.Long(row["SignalNum"].ToString());
                signalod.DateViewing = PIn.Date(row["DateViewing"].ToString());
                signalod.SigDateTime = PIn.DateT(row["SigDateTime"].ToString());
                signalod.FKey        = PIn.Long(row["FKey"].ToString());
                string fKeyType = row["FKeyType"].ToString();
                if (fKeyType == "")
                {
                    signalod.FKeyType = (KeyType)0;
                }
                else
                {
                    try{
                        signalod.FKeyType = (KeyType)Enum.Parse(typeof(KeyType), fKeyType);
                    }
                    catch {
                        signalod.FKeyType = (KeyType)0;
                    }
                }
                signalod.IType      = (OpenDentBusiness.InvalidType)PIn.Int(row["IType"].ToString());
                signalod.RemoteRole = (OpenDentBusiness.RemotingRole)PIn.Int(row["RemoteRole"].ToString());
                signalod.MsgValue   = PIn.String(row["MsgValue"].ToString());
                retVal.Add(signalod);
            }
            return(retVal);
        }
Example #4
0
 ///<summary>Inserts one Signalod into the database.  Returns the new priKey.</summary>
 internal static long Insert(Signalod signalod)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         signalod.SignalNum=DbHelper.GetNextOracleKey("signalod","SignalNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(signalod,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     signalod.SignalNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(signalod,false);
     }
 }
Example #5
0
 ///<summary>Inserts one Signalod into the database.  Returns the new priKey.</summary>
 internal static long Insert(Signalod signalod)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         signalod.SignalNum = DbHelper.GetNextOracleKey("signalod", "SignalNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(signalod, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     signalod.SignalNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(signalod, false));
     }
 }
Example #6
0
        ///<summary></summary>
        protected void OnButtonClicked(int myButton, SigButDef myDef, Signalod mySignal)
        {
            ODLightSignalGridClickEventArgs bArgs = new ODLightSignalGridClickEventArgs(myButton, myDef, mySignal);

            if (ButtonClick != null)
            {
                ButtonClick(this, bArgs);
            }
        }
Example #7
0
 ///<summary>Inserts many Signalods into the database.  Provides option to use the existing priKey.</summary>
 public static void InsertMany(List <Signalod> listSignalods)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle || PrefC.RandomKeys)
     {
         foreach (Signalod signalod in listSignalods)
         {
             Insert(signalod);
         }
     }
     else
     {
         StringBuilder sbCommands = null;
         int           index      = 0;
         while (index < listSignalods.Count)
         {
             Signalod      signalod = listSignalods[index];
             StringBuilder sbRow    = new StringBuilder("(");
             bool          hasComma = false;
             if (sbCommands == null)
             {
                 sbCommands = new StringBuilder();
                 sbCommands.Append("INSERT INTO signalod (");
                 sbCommands.Append("DateViewing,SigDateTime,FKey,FKeyType,IType,RemoteRole,MsgValue) VALUES ");
             }
             else
             {
                 hasComma = true;
             }
             sbRow.Append(POut.Date(signalod.DateViewing)); sbRow.Append(",");
             sbRow.Append(POut.DateT(signalod.SigDateTime)); sbRow.Append(",");
             sbRow.Append(POut.Long(signalod.FKey)); sbRow.Append(",");
             sbRow.Append("'" + POut.String(signalod.FKeyType.ToString()) + "'"); sbRow.Append(",");
             sbRow.Append(POut.Int((int)signalod.IType)); sbRow.Append(",");
             sbRow.Append(POut.Int((int)signalod.RemoteRole)); sbRow.Append(",");
             sbRow.Append("'" + POut.String(signalod.MsgValue) + "'"); sbRow.Append(")");
             if (sbCommands.Length + sbRow.Length + 1 > TableBase.MaxAllowedPacketCount)
             {
                 Db.NonQ(sbCommands.ToString());
                 sbCommands = null;
             }
             else
             {
                 if (hasComma)
                 {
                     sbCommands.Append(",");
                 }
                 sbCommands.Append(sbRow.ToString());
                 if (index == listSignalods.Count - 1)
                 {
                     Db.NonQ(sbCommands.ToString());
                 }
                 index++;
             }
         }
     }
 }
Example #8
0
 ///<summary>Inserts one Signalod into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(Signalod signalod)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(signalod, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             signalod.SignalNum = DbHelper.GetNextOracleKey("signalod", "SignalNum");                  //Cacheless method
         }
         return(InsertNoCache(signalod, true));
     }
 }
Example #9
0
        ///<summary>Updates one Signalod in the database.</summary>
        internal static void Update(Signalod signalod)
        {
            string command = "UPDATE signalod SET "
                             + "FromUser   = '******', "
                             + "ITypes     = '" + POut.String(signalod.ITypes) + "', "
                             + "DateViewing=  " + POut.Date(signalod.DateViewing) + ", "
                             + "SigType    =  " + POut.Int((int)signalod.SigType) + ", "
                             + "SigText    = '" + POut.String(signalod.SigText) + "', "
                             + "SigDateTime=  " + POut.DateT(signalod.SigDateTime) + ", "
                             + "ToUser     = '******', "
                             + "AckTime    =  " + POut.DateT(signalod.AckTime) + ", "
                             + "TaskNum    =  " + POut.Long(signalod.TaskNum) + " "
                             + "WHERE SignalNum = " + POut.Long(signalod.SignalNum);

            Db.NonQ(command);
        }
Example #10
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, Signalod activeSignal)
 {
     if (buttonIndex >= sigButStates.Length)
     {
         return;                //no button to light up.
     }
     sigButStates[buttonIndex].CurrentColor = color;
     if (activeSignal == null)
     {
         sigButStates[buttonIndex].ActiveSignal = null;
     }
     else
     {
         sigButStates[buttonIndex].ActiveSignal = activeSignal.Copy();
     }
     Invalidate();
 }
Example #11
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<Signalod> TableToList(DataTable table){
			List<Signalod> retVal=new List<Signalod>();
			Signalod signalod;
			for(int i=0;i<table.Rows.Count;i++) {
				signalod=new Signalod();
				signalod.SignalNum  = PIn.Long  (table.Rows[i]["SignalNum"].ToString());
				signalod.FromUser   = PIn.String(table.Rows[i]["FromUser"].ToString());
				signalod.ITypes     = PIn.String(table.Rows[i]["ITypes"].ToString());
				signalod.DateViewing= PIn.Date  (table.Rows[i]["DateViewing"].ToString());
				signalod.SigType    = (OpenDentBusiness.SignalType)PIn.Int(table.Rows[i]["SigType"].ToString());
				signalod.SigText    = PIn.String(table.Rows[i]["SigText"].ToString());
				signalod.SigDateTime= PIn.DateT (table.Rows[i]["SigDateTime"].ToString());
				signalod.ToUser     = PIn.String(table.Rows[i]["ToUser"].ToString());
				signalod.AckTime    = PIn.DateT (table.Rows[i]["AckTime"].ToString());
				signalod.TaskNum    = PIn.Long  (table.Rows[i]["TaskNum"].ToString());
				retVal.Add(signalod);
			}
			return retVal;
		}
Example #12
0
        ///<summary>Inserts one Signalod into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(Signalod signalod, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO signalod (";

            if (!useExistingPK && isRandomKeys)
            {
                signalod.SignalNum = ReplicationServers.GetKeyNoCache("signalod", "SignalNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "SignalNum,";
            }
            command += "DateViewing,SigDateTime,FKey,FKeyType,IType,RemoteRole,MsgValue) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(signalod.SignalNum) + ",";
            }
            command +=
                POut.Date(signalod.DateViewing) + ","
                + POut.DateT(signalod.SigDateTime) + ","
                + POut.Long(signalod.FKey) + ","
                + "'" + POut.String(signalod.FKeyType.ToString()) + "',"
                + POut.Int((int)signalod.IType) + ","
                + POut.Int((int)signalod.RemoteRole) + ","
                + DbHelper.ParamChar + "paramMsgValue)";
            if (signalod.MsgValue == null)
            {
                signalod.MsgValue = "";
            }
            OdSqlParameter paramMsgValue = new OdSqlParameter("paramMsgValue", OdDbType.Text, POut.StringParam(signalod.MsgValue));

            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command, paramMsgValue);
            }
            else
            {
                signalod.SignalNum = Db.NonQ(command, true, "SignalNum", "signalod", paramMsgValue);
            }
            return(signalod.SignalNum);
        }
Example #13
0
        ///<summary>Updates one Signalod in the database.</summary>
        public static void Update(Signalod signalod)
        {
            string command = "UPDATE signalod SET "
                             + "DateViewing=  " + POut.Date(signalod.DateViewing) + ", "
                             + "SigDateTime=  " + POut.DateT(signalod.SigDateTime) + ", "
                             + "FKey       =  " + POut.Long(signalod.FKey) + ", "
                             + "FKeyType   = '" + POut.String(signalod.FKeyType.ToString()) + "', "
                             + "IType      =  " + POut.Int((int)signalod.IType) + ", "
                             + "RemoteRole =  " + POut.Int((int)signalod.RemoteRole) + ", "
                             + "MsgValue   =  " + DbHelper.ParamChar + "paramMsgValue "
                             + "WHERE SignalNum = " + POut.Long(signalod.SignalNum);

            if (signalod.MsgValue == null)
            {
                signalod.MsgValue = "";
            }
            OdSqlParameter paramMsgValue = new OdSqlParameter("paramMsgValue", OdDbType.Text, POut.StringParam(signalod.MsgValue));

            Db.NonQ(command, paramMsgValue);
        }
Example #14
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <Signalod> TableToList(DataTable table)
        {
            List <Signalod> retVal = new List <Signalod>();
            Signalod        signalod;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                signalod             = new Signalod();
                signalod.SignalNum   = PIn.Long(table.Rows[i]["SignalNum"].ToString());
                signalod.FromUser    = PIn.String(table.Rows[i]["FromUser"].ToString());
                signalod.ITypes      = PIn.String(table.Rows[i]["ITypes"].ToString());
                signalod.DateViewing = PIn.Date(table.Rows[i]["DateViewing"].ToString());
                signalod.SigType     = (SignalType)PIn.Int(table.Rows[i]["SigType"].ToString());
                signalod.SigText     = PIn.String(table.Rows[i]["SigText"].ToString());
                signalod.SigDateTime = PIn.DateT(table.Rows[i]["SigDateTime"].ToString());
                signalod.ToUser      = PIn.String(table.Rows[i]["ToUser"].ToString());
                signalod.AckTime     = PIn.DateT(table.Rows[i]["AckTime"].ToString());
                signalod.TaskNum     = PIn.Long(table.Rows[i]["TaskNum"].ToString());
                retVal.Add(signalod);
            }
            return(retVal);
        }
Example #15
0
        ///<summary>Inserts one Signalod into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(Signalod signalod, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                signalod.SignalNum = ReplicationServers.GetKey("signalod", "SignalNum");
            }
            string command = "INSERT INTO signalod (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "SignalNum,";
            }
            command += "FromUser,ITypes,DateViewing,SigType,SigText,SigDateTime,ToUser,AckTime,TaskNum) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(signalod.SignalNum) + ",";
            }
            command +=
                "'" + POut.String(signalod.FromUser) + "',"
                + "'" + POut.String(signalod.ITypes) + "',"
                + POut.Date(signalod.DateViewing) + ","
                + POut.Int((int)signalod.SigType) + ","
                + "'" + POut.String(signalod.SigText) + "',"
                + POut.DateT(signalod.SigDateTime) + ","
                + "'" + POut.String(signalod.ToUser) + "',"
                + POut.DateT(signalod.AckTime) + ","
                + POut.Long(signalod.TaskNum) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                signalod.SignalNum = Db.NonQ(command, true);
            }
            return(signalod.SignalNum);
        }
Example #16
0
        ///<summary>Updates one Signalod 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(Signalod signalod, Signalod oldSignalod)
        {
            string command = "";

            if (signalod.DateViewing.Date != oldSignalod.DateViewing.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateViewing = " + POut.Date(signalod.DateViewing) + "";
            }
            if (signalod.SigDateTime != oldSignalod.SigDateTime)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigDateTime = " + POut.DateT(signalod.SigDateTime) + "";
            }
            if (signalod.FKey != oldSignalod.FKey)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FKey = " + POut.Long(signalod.FKey) + "";
            }
            if (signalod.FKeyType != oldSignalod.FKeyType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FKeyType = '" + POut.String(signalod.FKeyType.ToString()) + "'";
            }
            if (signalod.IType != oldSignalod.IType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IType = " + POut.Int((int)signalod.IType) + "";
            }
            if (signalod.RemoteRole != oldSignalod.RemoteRole)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RemoteRole = " + POut.Int((int)signalod.RemoteRole) + "";
            }
            if (signalod.MsgValue != oldSignalod.MsgValue)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "MsgValue = " + DbHelper.ParamChar + "paramMsgValue";
            }
            if (command == "")
            {
                return(false);
            }
            if (signalod.MsgValue == null)
            {
                signalod.MsgValue = "";
            }
            OdSqlParameter paramMsgValue = new OdSqlParameter("paramMsgValue", OdDbType.Text, POut.StringParam(signalod.MsgValue));

            command = "UPDATE signalod SET " + command
                      + " WHERE SignalNum = " + POut.Long(signalod.SignalNum);
            Db.NonQ(command, paramMsgValue);
            return(true);
        }
Example #17
0
        ///<summary>Updates one Signalod 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>
        internal static void Update(Signalod signalod, Signalod oldSignalod)
        {
            string command = "";

            if (signalod.FromUser != oldSignalod.FromUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FromUser = '******'";
            }
            if (signalod.ITypes != oldSignalod.ITypes)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ITypes = '" + POut.String(signalod.ITypes) + "'";
            }
            if (signalod.DateViewing != oldSignalod.DateViewing)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateViewing = " + POut.Date(signalod.DateViewing) + "";
            }
            if (signalod.SigType != oldSignalod.SigType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigType = " + POut.Int((int)signalod.SigType) + "";
            }
            if (signalod.SigText != oldSignalod.SigText)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigText = '" + POut.String(signalod.SigText) + "'";
            }
            if (signalod.SigDateTime != oldSignalod.SigDateTime)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "SigDateTime = " + POut.DateT(signalod.SigDateTime) + "";
            }
            if (signalod.ToUser != oldSignalod.ToUser)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ToUser = '******'";
            }
            if (signalod.AckTime != oldSignalod.AckTime)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AckTime = " + POut.DateT(signalod.AckTime) + "";
            }
            if (signalod.TaskNum != oldSignalod.TaskNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "TaskNum = " + POut.Long(signalod.TaskNum) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE signalod SET " + command
                      + " WHERE SignalNum = " + POut.Long(signalod.SignalNum);
            Db.NonQ(command);
        }
Example #18
0
		///<summary>Updates one Signalod 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(Signalod signalod,Signalod oldSignalod){
			string command="";
			if(signalod.FromUser != oldSignalod.FromUser) {
				if(command!=""){ command+=",";}
				command+="FromUser = '******'";
			}
			if(signalod.ITypes != oldSignalod.ITypes) {
				if(command!=""){ command+=",";}
				command+="ITypes = '"+POut.String(signalod.ITypes)+"'";
			}
			if(signalod.DateViewing != oldSignalod.DateViewing) {
				if(command!=""){ command+=",";}
				command+="DateViewing = "+POut.Date(signalod.DateViewing)+"";
			}
			if(signalod.SigType != oldSignalod.SigType) {
				if(command!=""){ command+=",";}
				command+="SigType = "+POut.Int   ((int)signalod.SigType)+"";
			}
			if(signalod.SigText != oldSignalod.SigText) {
				if(command!=""){ command+=",";}
				command+="SigText = '"+POut.String(signalod.SigText)+"'";
			}
			if(signalod.SigDateTime != oldSignalod.SigDateTime) {
				if(command!=""){ command+=",";}
				command+="SigDateTime = "+POut.DateT(signalod.SigDateTime)+"";
			}
			if(signalod.ToUser != oldSignalod.ToUser) {
				if(command!=""){ command+=",";}
				command+="ToUser = '******'";
			}
			if(signalod.AckTime != oldSignalod.AckTime) {
				if(command!=""){ command+=",";}
				command+="AckTime = "+POut.DateT(signalod.AckTime)+"";
			}
			if(signalod.TaskNum != oldSignalod.TaskNum) {
				if(command!=""){ command+=",";}
				command+="TaskNum = "+POut.Long(signalod.TaskNum)+"";
			}
			if(command==""){
				return false;
			}
			command="UPDATE signalod SET "+command
				+" WHERE SignalNum = "+POut.Long(signalod.SignalNum);
			Db.NonQ(command);
			return true;
		}
Example #19
0
		///<summary>Updates one Signalod in the database.</summary>
		public static void Update(Signalod signalod){
			string command="UPDATE signalod SET "
				+"FromUser   = '******', "
				+"ITypes     = '"+POut.String(signalod.ITypes)+"', "
				+"DateViewing=  "+POut.Date  (signalod.DateViewing)+", "
				+"SigType    =  "+POut.Int   ((int)signalod.SigType)+", "
				+"SigText    = '"+POut.String(signalod.SigText)+"', "
				+"SigDateTime=  "+POut.DateT (signalod.SigDateTime)+", "
				+"ToUser     = '******', "
				+"AckTime    =  "+POut.DateT (signalod.AckTime)+", "
				+"TaskNum    =  "+POut.Long  (signalod.TaskNum)+" "
				+"WHERE SignalNum = "+POut.Long(signalod.SignalNum);
			Db.NonQ(command);
		}
Example #20
0
 ///<summary>Inserts one Signalod into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(Signalod signalod)
 {
     return(InsertNoCache(signalod, false));
 }
Example #21
0
        private void butMerge_Click(object sender, EventArgs e)
        {
            if (_patTo.PatNum == _patFrom.PatNum)
            {
                MsgBox.Show(this, "Cannot merge a patient account into itself. Please select a different patient to merge from.");
                return;
            }
            string msgText = "";

            if (_patFrom.FName.Trim().ToLower() != _patTo.FName.Trim().ToLower() ||
                _patFrom.LName.Trim().ToLower() != _patTo.LName.Trim().ToLower() ||
                _patFrom.Birthdate != _patTo.Birthdate)
            {            //mismatch
                msgText = Lan.g(this, "The two patients do not have the same first name, last name, and birthdate.");
                if (Programs.UsingEcwTightOrFullMode())
                {
                    msgText += "\r\n" + Lan.g(this, "The patients must first be merged from within eCW, then immediately merged in the same order in Open Dental.  "
                                              + "If the patients are not merged in this manner, some information may not properly bridge between eCW and Open Dental.");
                }
                msgText += "\r\n\r\n"
                           + Lan.g(this, "Into patient name") + ": " + Patients.GetNameFLnoPref(_patTo.LName, _patTo.FName, "") + ", "     //using Patients.GetNameFLnoPref to omit MiddleI
                           + Lan.g(this, "Into patient birthdate") + ": " + _patTo.Birthdate.ToShortDateString() + "\r\n"
                           + Lan.g(this, "From patient name") + ": " + Patients.GetNameFLnoPref(_patFrom.LName, _patFrom.FName, "") + ", " //using Patients.GetNameFLnoPref to omit MiddleI
                           + Lan.g(this, "From patient birthdate") + ": " + _patFrom.Birthdate.ToShortDateString() + "\r\n\r\n"
                           + Lan.g(this, "Merge the patient on the bottom into the patient shown on the top?");
                if (MessageBox.Show(msgText, "", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;                    //The user chose not to merge
                }
            }
            else              //name and bd match
            {
                if (!MsgBox.Show(this, MsgBoxButtons.YesNo, "Merge the patient at the bottom into the patient shown at the top?"))
                {
                    return;                    //The user chose not to merge.
                }
            }
            if (_patFrom.PatNum == _patFrom.Guarantor)
            {
                Family fam = Patients.GetFamily(_patFrom.PatNum);
                if (fam.ListPats.Length > 1)
                {
                    msgText = Lan.g(this, "The patient you have chosen to merge from is a guarantor.  Merging this patient into another account will cause all "
                                    + "family members of the patient being merged from to be moved into the same family as the patient account being merged into.") + "\r\n"
                              + Lan.g(this, "Do you wish to continue with the merge?");
                    if (MessageBox.Show(msgText, "", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        return;                        //The user chose not to merge.
                    }
                }
            }
            Cursor = Cursors.WaitCursor;
            List <Task> listPatientTasks  = Tasks.RefreshPatientTickets(_patFrom.PatNum);        //Get this before the merge, because the merge updates Task.KeyNum.
            bool        isSuccessfulMerge = false;

            try {
                isSuccessfulMerge = Patients.MergeTwoPatients(_patTo.PatNum, _patFrom.PatNum);
            }
            catch (Exception ex) {
                SecurityLogs.MakeLogEntry(Permissions.PatientMerge, _patTo.PatNum,
                                          "Error occurred while merging Patient: " + _patFrom.GetNameFL() + "\r\nPatNum From: " + _patFrom.PatNum + "\r\nPatNum To: " + _patTo.PatNum);
                Cursor = Cursors.Default;
                FriendlyException.Show(Lan.g(this, "Unable to fully merge patients.  Contact support."), ex);
            }
            if (isSuccessfulMerge)
            {
                //The patient has been successfully merged.
                #region Refresh Patient's Tasks
                List <Signalod> listSignals = new List <Signalod>();
                foreach (Task task in listPatientTasks)
                {
                    Signalod signal = new Signalod();
                    signal.IType       = InvalidType.Task;
                    signal.FKeyType    = KeyType.Task;
                    signal.FKey        = task.TaskNum;
                    signal.DateViewing = DateTime.MinValue;                  //Mimics Signalods.SetInvalid()
                    listSignals.Add(signal);
                }
                Signalods.SetInvalid(InvalidType.TaskPatient, KeyType.Undefined, _patTo.PatNum); //Ensure anyone viewing Patient tab of new pat gets refreshed.
                Signalods.Insert(listSignals.ToArray());                                         //Refreshes existing tasks in all other tabs.
                //Causes Task area and open Task Edit windows to refresh immediately.  No popups, alright to pass empty lists for listRefreshedTaskNotes and
                //listBlockedTaskLists.
                FormOpenDental.S_HandleRefreshedTasks(listSignals, listPatientTasks.Select(x => x.TaskNum).ToList(), listPatientTasks, new List <TaskNote>()
                                                      , new List <UserOdPref>());
                #endregion
                //Now copy the physical images from the old patient to the new if they are using an AtoZ image share.
                //This has to happen in the UI because the middle tier server might not have access to the image share.
                //If the users are storing images within the database, those images have already been taken care of in the merge method above.
                int fileCopyFailures = 0;
                if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
                {
                    #region Copy AtoZ Documents
                    //Move the patient documents within the 'patFrom' A to Z folder to the 'patTo' A to Z folder.
                    //We have to be careful here of documents with the same name. We have to rename such documents
                    //so that no documents are overwritten/lost.
                    string   atoZpath  = ImageStore.GetPreferredAtoZpath();
                    string   atozFrom  = ImageStore.GetPatientFolder(_patFrom, atoZpath);
                    string   atozTo    = ImageStore.GetPatientFolder(_patTo, atoZpath);
                    string[] fromFiles = Directory.GetFiles(atozFrom);
                    if (atozFrom == atozTo)
                    {
                        //Very rarely, two patients have the same image folder.  PatFrom and PatTo both have Documents that point to the same file.  Since we
                        //are about to copy the image file for PatFrom to PatTo's directory and delete the file from PatFrom's directory, we would break the
                        //file reference for PatTo's Document.  In this case, skip deleting the original file, since PatTo's Document still references it.
                        Documents.MergePatientDocuments(_patFrom.PatNum, _patTo.PatNum);
                    }
                    else
                    {
                        foreach (string fileCur in fromFiles)
                        {
                            string fileName     = Path.GetFileName(fileCur);
                            string destFileName = fileName;
                            string destFilePath = ODFileUtils.CombinePaths(atozTo, fileName);
                            if (File.Exists(destFilePath))
                            {
                                //The file being copied has the same name as a possibly different file within the destination a to z folder.
                                //We need to copy the file under a unique file name and then make sure to update the document table to reflect
                                //the change.
                                destFileName = _patFrom.PatNum.ToString() + "_" + fileName;
                                destFilePath = ODFileUtils.CombinePaths(atozTo, destFileName);
                                while (File.Exists(destFilePath))
                                {
                                    destFileName = _patFrom.PatNum.ToString() + "_" + fileName + "_" + DateTime.Now.ToString("yyyyMMddhhmmss");
                                    destFilePath = ODFileUtils.CombinePaths(atozTo, destFileName);
                                }
                            }
                            try {
                                File.Copy(fileCur, destFilePath);                                //Will throw exception if file already exists.
                            }
                            catch (Exception ex) {
                                ex.DoNothing();
                                fileCopyFailures++;
                                continue;                                //copy failed, increment counter and move onto the next file
                            }
                            //If the copy did not fail, try to delete the old file.
                            //We can now safely update the document FileName and PatNum to the "to" patient.
                            Documents.MergePatientDocument(_patFrom.PatNum, _patTo.PatNum, fileName, destFileName);
                            try {
                                File.Delete(fileCur);
                            }
                            catch (Exception ex) {
                                ex.DoNothing();
                                //If we were unable to delete the file then it is probably because someone has the document open currently.
                                //Just skip deleting the file. This means that occasionally there will be an extra file in their backup
                                //which is just clutter but at least the merge is guaranteed this way.
                            }
                        }
                    }
                    #endregion Copy AtoZ Documents
                }                //end if AtoZFolderUsed
                else if (CloudStorage.IsCloudStorage)
                {
                    string atozFrom = ImageStore.GetPatientFolder(_patFrom, "");
                    string atozTo   = ImageStore.GetPatientFolder(_patTo, "");
                    if (atozFrom == atozTo)
                    {
                        //Very rarely, two patients have the same image folder.  PatFrom and PatTo both have Documents that point to the same file.  Since we
                        //are about to copy the image file for PatFrom to PatTo's directory and delete the file from PatFrom's directory, we would break the
                        //file reference for PatTo's Document.  In this case, skip deleting the original file, since PatTo's Document still references it.
                        Documents.MergePatientDocuments(_patFrom.PatNum, _patTo.PatNum);
                    }
                    else
                    {
                        FormProgress FormP = new FormProgress();
                        FormP.DisplayText          = "Moving Documents...";
                        FormP.NumberFormat         = "F";
                        FormP.NumberMultiplication = 1;
                        FormP.MaxVal = 100;                      //Doesn't matter what this value is as long as it is greater than 0
                        FormP.TickMS = 1000;
                        OpenDentalCloud.Core.TaskStateMove state = CloudStorage.MoveAsync(atozFrom
                                                                                          , atozTo
                                                                                          , new OpenDentalCloud.ProgressHandler(FormP.OnProgress));
                        if (FormP.ShowDialog() == DialogResult.Cancel)
                        {
                            state.DoCancel   = true;
                            fileCopyFailures = state.CountTotal - state.CountSuccess;
                        }
                        else
                        {
                            fileCopyFailures = state.CountFailed;
                        }
                    }
                }
                Cursor = Cursors.Default;
                if (fileCopyFailures > 0)
                {
                    MessageBox.Show(Lan.g(this, "Some files belonging to the from patient were not copied.") + "\r\n"
                                    + Lan.g(this, "Number of files not copied") + ": " + fileCopyFailures);
                }
                //Make log entry here not in parent form because we can merge multiple patients at a time.
                SecurityLogs.MakeLogEntry(Permissions.PatientMerge, _patTo.PatNum,
                                          "Patient: " + _patFrom.GetNameFL() + "\r\nPatNum From: " + _patFrom.PatNum + "\r\nPatNum To: " + _patTo.PatNum);
                textPatientIDFrom.Text    = "";
                textPatientNameFrom.Text  = "";
                textPatFromBirthdate.Text = "";
                //This will cause CheckUIState() to disabled the merge button until the user selects a new _patFrom.
                _patFrom = null;
                CheckUIState();
                MsgBox.Show(this, "Patients merged successfully.");
            }            //end MergeTwoPatients
            Cursor = Cursors.Default;
        }
Example #22
0
 /// <summary></summary>
 /// <param name="myButton"></param>
 public ODLightSignalGridClickEventArgs(int myButton, SigButDef myDef, Signalod mySignal)
 {
     buttonIndex  = myButton;
     buttonDef    = myDef;
     activeSignal = mySignal;
 }