Beispiel #1
0
 ///<summary>Inserts one FormPat into the database.  Returns the new priKey.</summary>
 internal static long Insert(FormPat formPat)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         formPat.FormPatNum = DbHelper.GetNextOracleKey("formpat", "FormPatNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(formPat, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     formPat.FormPatNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(formPat, false));
     }
 }
Beispiel #2
0
        ///<summary></summary>
        public static void Insert(FormPat Cur)
        {
            if (PrefB.RandomKeys)
            {
                Cur.FormPatNum = MiscData.GetKey("formpat", "FormPatNum");
            }
            string command = "INSERT INTO formpat (";

            if (PrefB.RandomKeys)
            {
                command += "FormPatNum,";
            }
            command += "PatNum,FormDateTime) VALUES(";
            if (PrefB.RandomKeys)
            {
                command += "'" + POut.PInt(Cur.FormPatNum) + "', ";
            }
            command +=
                "'" + POut.PInt(Cur.PatNum) + "', "
                + POut.PDateT(Cur.FormDateTime) + ")";
            if (PrefB.RandomKeys)
            {
                General.NonQ(command);
            }
            else
            {
                Cur.FormPatNum = General.NonQ(command, true);
            }
        }
Beispiel #3
0
        public static FormPat GetOne(int formPatNum)
        {
            string    command = "SELECT * FROM formpat WHERE FormPatNum=" + POut.PInt(formPatNum);
            DataTable table   = General.GetTable(command);

            if (table.Rows.Count == 0)
            {
                return(null);               //should never happen.
            }
            FormPat form = new FormPat();

            form.FormPatNum   = formPatNum;
            form.PatNum       = PIn.PInt(table.Rows[0][1].ToString());
            form.FormDateTime = PIn.PDateT(table.Rows[0][2].ToString());
            form.QuestionList = new List <Question>();
            command           = "SELECT * FROM question WHERE FormPatNum=" + POut.PInt(formPatNum);
            table             = General.GetTable(command);
            Question quest;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                quest             = new Question();
                quest.QuestionNum = PIn.PInt(table.Rows[i][0].ToString());
                quest.PatNum      = PIn.PInt(table.Rows[i][1].ToString());
                quest.ItemOrder   = PIn.PInt(table.Rows[i][2].ToString());
                quest.Description = PIn.PString(table.Rows[i][3].ToString());
                quest.Answer      = PIn.PString(table.Rows[i][4].ToString());
                quest.FormPatNum  = PIn.PInt(table.Rows[i][5].ToString());
                form.QuestionList.Add(quest);
            }
            return(form);
        }
Beispiel #4
0
        ///<summary>Inserts one FormPat into the database.  Provides option to use the existing priKey.</summary>
        internal static long Insert(FormPat formPat, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                formPat.FormPatNum = ReplicationServers.GetKey("formpat", "FormPatNum");
            }
            string command = "INSERT INTO formpat (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "FormPatNum,";
            }
            command += "PatNum,FormDateTime) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(formPat.FormPatNum) + ",";
            }
            command +=
                POut.Long(formPat.PatNum) + ","
                + POut.DateT(formPat.FormDateTime) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                formPat.FormPatNum = Db.NonQ(command, true);
            }
            return(formPat.FormPatNum);
        }
Beispiel #5
0
        ///<summary>Inserts one FormPat into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(FormPat formPat, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO formpat (";

            if (!useExistingPK && isRandomKeys)
            {
                formPat.FormPatNum = ReplicationServers.GetKeyNoCache("formpat", "FormPatNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "FormPatNum,";
            }
            command += "PatNum,FormDateTime) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(formPat.FormPatNum) + ",";
            }
            command +=
                POut.Long(formPat.PatNum) + ","
                + POut.DateT(formPat.FormDateTime) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                formPat.FormPatNum = Db.NonQ(command, true, "FormPatNum", "formPat");
            }
            return(formPat.FormPatNum);
        }
Beispiel #6
0
        ///<summary>Updates one FormPat 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(FormPat formPat, FormPat oldFormPat)
        {
            string command = "";

            if (formPat.PatNum != oldFormPat.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(formPat.PatNum) + "";
            }
            if (formPat.FormDateTime != oldFormPat.FormDateTime)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FormDateTime = " + POut.DateT(formPat.FormDateTime) + "";
            }
            if (command == "")
            {
                return;
            }
            command = "UPDATE formpat SET " + command
                      + " WHERE FormPatNum = " + POut.Long(formPat.FormPatNum);
            Db.NonQ(command);
        }
Beispiel #7
0
 ///<summary>Inserts one FormPat into the database.  Returns the new priKey.</summary>
 internal static long Insert(FormPat formPat)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         formPat.FormPatNum=DbHelper.GetNextOracleKey("formpat","FormPatNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(formPat,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     formPat.FormPatNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(formPat,false);
     }
 }
Beispiel #8
0
        ///<summary>Updates one FormPat in the database.</summary>
        internal static void Update(FormPat formPat)
        {
            string command = "UPDATE formpat SET "
                             + "PatNum      =  " + POut.Long(formPat.PatNum) + ", "
                             + "FormDateTime=  " + POut.DateT(formPat.FormDateTime) + " "
                             + "WHERE FormPatNum = " + POut.Long(formPat.FormPatNum);

            Db.NonQ(command);
        }
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<FormPat> TableToList(DataTable table){
			List<FormPat> retVal=new List<FormPat>();
			FormPat formPat;
			for(int i=0;i<table.Rows.Count;i++) {
				formPat=new FormPat();
				formPat.FormPatNum  = PIn.Long  (table.Rows[i]["FormPatNum"].ToString());
				formPat.PatNum      = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				formPat.FormDateTime= PIn.DateT (table.Rows[i]["FormDateTime"].ToString());
				retVal.Add(formPat);
			}
			return retVal;
		}
Beispiel #10
0
 ///<summary>Returns true if Update(FormPat,FormPat) 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(FormPat formPat, FormPat oldFormPat)
 {
     if (formPat.PatNum != oldFormPat.PatNum)
     {
         return(true);
     }
     if (formPat.FormDateTime != oldFormPat.FormDateTime)
     {
         return(true);
     }
     return(false);
 }
Beispiel #11
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <FormPat> TableToList(DataTable table)
        {
            List <FormPat> retVal = new List <FormPat>();
            FormPat        formPat;

            foreach (DataRow row in table.Rows)
            {
                formPat              = new FormPat();
                formPat.FormPatNum   = PIn.Long(row["FormPatNum"].ToString());
                formPat.PatNum       = PIn.Long(row["PatNum"].ToString());
                formPat.FormDateTime = PIn.DateT(row["FormDateTime"].ToString());
                retVal.Add(formPat);
            }
            return(retVal);
        }
Beispiel #12
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        internal static List <FormPat> TableToList(DataTable table)
        {
            List <FormPat> retVal = new List <FormPat>();
            FormPat        formPat;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                formPat              = new FormPat();
                formPat.FormPatNum   = PIn.Long(table.Rows[i]["FormPatNum"].ToString());
                formPat.PatNum       = PIn.Long(table.Rows[i]["PatNum"].ToString());
                formPat.FormDateTime = PIn.DateT(table.Rows[i]["FormDateTime"].ToString());
                retVal.Add(formPat);
            }
            return(retVal);
        }
Beispiel #13
0
 ///<summary>Inserts one FormPat into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FormPat formPat)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(formPat, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             formPat.FormPatNum = DbHelper.GetNextOracleKey("formpat", "FormPatNum");                  //Cacheless method
         }
         return(InsertNoCache(formPat, true));
     }
 }
        private void butQuest_Click(object sender, EventArgs e)
        {
            FormPat form = new FormPat();

            form.PatNum       = PatCur.PatNum;
            form.FormDateTime = DateTime.Now;
            FormFormPatEdit FormP = new FormFormPatEdit();

            FormP.FormPatCur = form;
            FormP.IsNew      = true;
            FormP.ShowDialog();
            if (FormP.DialogResult == DialogResult.OK)
            {
                DialogResult = DialogResult.OK;
            }
        }
Beispiel #15
0
		///<summary>Inserts one FormPat into the database.  Provides option to use the existing priKey.</summary>
		public static long Insert(FormPat formPat,bool useExistingPK){
			if(!useExistingPK && PrefC.RandomKeys) {
				formPat.FormPatNum=ReplicationServers.GetKey("formpat","FormPatNum");
			}
			string command="INSERT INTO formpat (";
			if(useExistingPK || PrefC.RandomKeys) {
				command+="FormPatNum,";
			}
			command+="PatNum,FormDateTime) VALUES(";
			if(useExistingPK || PrefC.RandomKeys) {
				command+=POut.Long(formPat.FormPatNum)+",";
			}
			command+=
				     POut.Long  (formPat.PatNum)+","
				+    POut.DateT (formPat.FormDateTime)+")";
			if(useExistingPK || PrefC.RandomKeys) {
				Db.NonQ(command);
			}
			else {
				formPat.FormPatNum=Db.NonQ(command,true);
			}
			return formPat.FormPatNum;
		}
Beispiel #16
0
 ///<summary>Inserts one FormPat into the database.  Returns the new priKey.</summary>
 public static long Insert(FormPat formPat)
 {
     return(Insert(formPat, false));
 }
Beispiel #17
0
 ///<summary>Updates one FormPat in the database.</summary>
 internal static void Update(FormPat formPat)
 {
     string command="UPDATE formpat SET "
         +"PatNum      =  "+POut.Long  (formPat.PatNum)+", "
         +"FormDateTime=  "+POut.DateT (formPat.FormDateTime)+" "
         +"WHERE FormPatNum = "+POut.Long(formPat.FormPatNum);
     Db.NonQ(command);
 }
Beispiel #18
0
 ///<summary>Inserts one FormPat into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FormPat formPat)
 {
     return(InsertNoCache(formPat, false));
 }
Beispiel #19
0
 ///<summary>Updates one FormPat 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(FormPat formPat,FormPat oldFormPat)
 {
     string command="";
     if(formPat.PatNum != oldFormPat.PatNum) {
         if(command!=""){ command+=",";}
         command+="PatNum = "+POut.Long(formPat.PatNum)+"";
     }
     if(formPat.FormDateTime != oldFormPat.FormDateTime) {
         if(command!=""){ command+=",";}
         command+="FormDateTime = "+POut.DateT(formPat.FormDateTime)+"";
     }
     if(command==""){
         return;
     }
     command="UPDATE formpat SET "+command
         +" WHERE FormPatNum = "+POut.Long(formPat.FormPatNum);
     Db.NonQ(command);
 }