예제 #1
0
		///<summary>Inserts one CustReference into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(CustReference custReference,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				custReference.CustReferenceNum=ReplicationServers.GetKey("custreference","CustReferenceNum");
			}
			string command="INSERT INTO custreference (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="CustReferenceNum,";
			}
			command+="PatNum,DateMostRecent,Note,IsBadRef) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(custReference.CustReferenceNum)+",";
			}
			command+=
				     POut.Long  (custReference.PatNum)+","
				+    POut.Date  (custReference.DateMostRecent)+","
				+"'"+POut.String(custReference.Note)+"',"
				+    POut.Bool  (custReference.IsBadRef)+")";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				custReference.CustReferenceNum=Db.NonQ(command,true);
			}
			return custReference.CustReferenceNum;
		}
예제 #2
0
 ///<summary>Inserts one CustReference into the database.  Returns the new priKey.</summary>
 public static long Insert(CustReference custReference)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         custReference.CustReferenceNum = DbHelper.GetNextOracleKey("custreference", "CustReferenceNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(custReference, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     custReference.CustReferenceNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(custReference, false));
     }
 }
예제 #3
0
        ///<summary>Inserts one CustReference into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(CustReference custReference, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                custReference.CustReferenceNum = ReplicationServers.GetKey("custreference", "CustReferenceNum");
            }
            string command = "INSERT INTO custreference (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "CustReferenceNum,";
            }
            command += "PatNum,DateMostRecent,Note,IsBadRef) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(custReference.CustReferenceNum) + ",";
            }
            command +=
                POut.Long(custReference.PatNum) + ","
                + POut.Date(custReference.DateMostRecent) + ","
                + "'" + POut.String(custReference.Note) + "',"
                + POut.Bool(custReference.IsBadRef) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                custReference.CustReferenceNum = Db.NonQ(command, true, "CustReferenceNum", "custReference");
            }
            return(custReference.CustReferenceNum);
        }
예제 #4
0
        ///<summary>Inserts one CustReference into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(CustReference custReference, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO custreference (";

            if (!useExistingPK && isRandomKeys)
            {
                custReference.CustReferenceNum = ReplicationServers.GetKeyNoCache("custreference", "CustReferenceNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "CustReferenceNum,";
            }
            command += "PatNum,DateMostRecent,Note,IsBadRef) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(custReference.CustReferenceNum) + ",";
            }
            command +=
                POut.Long(custReference.PatNum) + ","
                + POut.Date(custReference.DateMostRecent) + ","
                + "'" + POut.String(custReference.Note) + "',"
                + POut.Bool(custReference.IsBadRef) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                custReference.CustReferenceNum = Db.NonQ(command, true, "CustReferenceNum", "custReference");
            }
            return(custReference.CustReferenceNum);
        }
예제 #5
0
        private void gridMain_CellDoubleClick(object sender, UI.ODGridClickEventArgs e)
        {
            CustReference     refCur = CustReferences.GetOne(PIn.Long(RefTable.Rows[e.Row]["CustReferenceNum"].ToString()));
            FormReferenceEdit FormRE = new FormReferenceEdit(refCur);

            FormRE.ShowDialog();
            FillMain(true);
        }
예제 #6
0
        ///<summary>Updates one CustReference in the database.</summary>
        public static void Update(CustReference custReference)
        {
            string command = "UPDATE custreference SET "
                             + "PatNum          =  " + POut.Long(custReference.PatNum) + ", "
                             + "DateMostRecent  =  " + POut.Date(custReference.DateMostRecent) + ", "
                             + "Note            = '" + POut.String(custReference.Note) + "', "
                             + "IsBadRef        =  " + POut.Bool(custReference.IsBadRef) + " "
                             + "WHERE CustReferenceNum = " + POut.Long(custReference.CustReferenceNum);

            Db.NonQ(command);
        }
예제 #7
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<CustReference> TableToList(DataTable table){
			List<CustReference> retVal=new List<CustReference>();
			CustReference custReference;
			for(int i=0;i<table.Rows.Count;i++) {
				custReference=new CustReference();
				custReference.CustReferenceNum= PIn.Long  (table.Rows[i]["CustReferenceNum"].ToString());
				custReference.PatNum          = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				custReference.DateMostRecent  = PIn.Date  (table.Rows[i]["DateMostRecent"].ToString());
				custReference.Note            = PIn.String(table.Rows[i]["Note"].ToString());
				custReference.IsBadRef        = PIn.Bool  (table.Rows[i]["IsBadRef"].ToString());
				retVal.Add(custReference);
			}
			return retVal;
		}
예제 #8
0
 ///<summary>Inserts one CustReference into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(CustReference custReference)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(custReference, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             custReference.CustReferenceNum = DbHelper.GetNextOracleKey("custreference", "CustReferenceNum");                  //Cacheless method
         }
         return(InsertNoCache(custReference, true));
     }
 }
예제 #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <CustReference> TableToList(DataTable table)
        {
            List <CustReference> retVal = new List <CustReference>();
            CustReference        custReference;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                custReference = new CustReference();
                custReference.CustReferenceNum = PIn.Long(table.Rows[i]["CustReferenceNum"].ToString());
                custReference.PatNum           = PIn.Long(table.Rows[i]["PatNum"].ToString());
                custReference.DateMostRecent   = PIn.Date(table.Rows[i]["DateMostRecent"].ToString());
                custReference.Note             = PIn.String(table.Rows[i]["Note"].ToString());
                custReference.IsBadRef         = PIn.Bool(table.Rows[i]["IsBadRef"].ToString());
                retVal.Add(custReference);
            }
            return(retVal);
        }
예제 #10
0
 private void butOK_Click(object sender, EventArgs e)
 {
     if (gridMain.SelectedIndices.Length < 1)
     {
         MsgBox.Show(this, "Select at least one reference.");
         return;
     }
     SelectedCustRefs = new List <CustReference>();
     for (int i = 0; i < gridMain.SelectedIndices.Length; i++)
     {
         CustReference custRef = CustReferences.GetOne(PIn.Long(RefTable.Rows[gridMain.SelectedIndices[i]]["CustReferenceNum"].ToString()));
         custRef.DateMostRecent = DateTime.Now;
         CustReferences.Update(custRef);
         SelectedCustRefs.Add(custRef);
     }
     DialogResult = DialogResult.OK;
 }
예제 #11
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <CustReference> TableToList(DataTable table)
        {
            List <CustReference> retVal = new List <CustReference>();
            CustReference        custReference;

            foreach (DataRow row in table.Rows)
            {
                custReference = new CustReference();
                custReference.CustReferenceNum = PIn.Long(row["CustReferenceNum"].ToString());
                custReference.PatNum           = PIn.Long(row["PatNum"].ToString());
                custReference.DateMostRecent   = PIn.Date(row["DateMostRecent"].ToString());
                custReference.Note             = PIn.String(row["Note"].ToString());
                custReference.IsBadRef         = PIn.Bool(row["IsBadRef"].ToString());
                retVal.Add(custReference);
            }
            return(retVal);
        }
예제 #12
0
        ///<summary>Updates one CustReference 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(CustReference custReference, CustReference oldCustReference)
        {
            string command = "";

            if (custReference.PatNum != oldCustReference.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(custReference.PatNum) + "";
            }
            if (custReference.DateMostRecent.Date != oldCustReference.DateMostRecent.Date)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DateMostRecent = " + POut.Date(custReference.DateMostRecent) + "";
            }
            if (custReference.Note != oldCustReference.Note)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Note = '" + POut.String(custReference.Note) + "'";
            }
            if (custReference.IsBadRef != oldCustReference.IsBadRef)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "IsBadRef = " + POut.Bool(custReference.IsBadRef) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE custreference SET " + command
                      + " WHERE CustReferenceNum = " + POut.Long(custReference.CustReferenceNum);
            Db.NonQ(command);
            return(true);
        }
예제 #13
0
 ///<summary>Returns true if Update(CustReference,CustReference) 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(CustReference custReference, CustReference oldCustReference)
 {
     if (custReference.PatNum != oldCustReference.PatNum)
     {
         return(true);
     }
     if (custReference.DateMostRecent.Date != oldCustReference.DateMostRecent.Date)
     {
         return(true);
     }
     if (custReference.Note != oldCustReference.Note)
     {
         return(true);
     }
     if (custReference.IsBadRef != oldCustReference.IsBadRef)
     {
         return(true);
     }
     return(false);
 }
예제 #14
0
		///<summary>Inserts one CustReference into the database.  Returns the new priKey.</summary>
		public static long Insert(CustReference custReference){
			if(DataConnection.DBtype==DatabaseType.Oracle) {
				custReference.CustReferenceNum=DbHelper.GetNextOracleKey("custreference","CustReferenceNum");
				int loopcount=0;
				while(loopcount<100){
					try {
						return Insert(custReference,true);
					}
					catch(Oracle.DataAccess.Client.OracleException ex){
						if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
							custReference.CustReferenceNum++;
							loopcount++;
						}
						else{
							throw ex;
						}
					}
				}
				throw new ApplicationException("Insert failed.  Could not generate primary key.");
			}
			else {
				return Insert(custReference,false);
			}
		}
예제 #15
0
 public FormReferenceEdit(CustReference refCur)
 {
     InitializeComponent();
     Lan.F(this);
     RefCur = refCur;
 }
예제 #16
0
		///<summary>Updates one CustReference in the database.</summary>
		public static void Update(CustReference custReference){
			string command="UPDATE custreference SET "
				+"PatNum          =  "+POut.Long  (custReference.PatNum)+", "
				+"DateMostRecent  =  "+POut.Date  (custReference.DateMostRecent)+", "
				+"Note            = '"+POut.String(custReference.Note)+"', "
				+"IsBadRef        =  "+POut.Bool  (custReference.IsBadRef)+" "
				+"WHERE CustReferenceNum = "+POut.Long(custReference.CustReferenceNum);
			Db.NonQ(command);
		}
예제 #17
0
 ///<summary>Inserts one CustReference into the database.  Returns the new priKey.</summary>
 public static long Insert(CustReference custReference)
 {
     return(Insert(custReference, false));
 }
예제 #18
0
		///<summary>Updates one CustReference 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(CustReference custReference,CustReference oldCustReference){
			string command="";
			if(custReference.PatNum != oldCustReference.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(custReference.PatNum)+"";
			}
			if(custReference.DateMostRecent != oldCustReference.DateMostRecent) {
				if(command!=""){ command+=",";}
				command+="DateMostRecent = "+POut.Date(custReference.DateMostRecent)+"";
			}
			if(custReference.Note != oldCustReference.Note) {
				if(command!=""){ command+=",";}
				command+="Note = '"+POut.String(custReference.Note)+"'";
			}
			if(custReference.IsBadRef != oldCustReference.IsBadRef) {
				if(command!=""){ command+=",";}
				command+="IsBadRef = "+POut.Bool(custReference.IsBadRef)+"";
			}
			if(command==""){
				return false;
			}
			command="UPDATE custreference SET "+command
				+" WHERE CustReferenceNum = "+POut.Long(custReference.CustReferenceNum);
			Db.NonQ(command);
			return true;
		}