Пример #1
0
        ///<summary>Inserts one PlannedAppt into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(PlannedAppt plannedAppt, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO plannedappt (";

            if (!useExistingPK && isRandomKeys)
            {
                plannedAppt.PlannedApptNum = ReplicationServers.GetKeyNoCache("plannedappt", "PlannedApptNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "PlannedApptNum,";
            }
            command += "PatNum,AptNum,ItemOrder) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(plannedAppt.PlannedApptNum) + ",";
            }
            command +=
                POut.Long(plannedAppt.PatNum) + ","
                + POut.Long(plannedAppt.AptNum) + ","
                + POut.Int(plannedAppt.ItemOrder) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                plannedAppt.PlannedApptNum = Db.NonQ(command, true, "PlannedApptNum", "plannedAppt");
            }
            return(plannedAppt.PlannedApptNum);
        }
Пример #2
0
        ///<summary>Inserts one PlannedAppt into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(PlannedAppt plannedAppt, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                plannedAppt.PlannedApptNum = ReplicationServers.GetKey("plannedappt", "PlannedApptNum");
            }
            string command = "INSERT INTO plannedappt (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "PlannedApptNum,";
            }
            command += "PatNum,AptNum,ItemOrder) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(plannedAppt.PlannedApptNum) + ",";
            }
            command +=
                POut.Long(plannedAppt.PatNum) + ","
                + POut.Long(plannedAppt.AptNum) + ","
                + POut.Int(plannedAppt.ItemOrder) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                plannedAppt.PlannedApptNum = Db.NonQ(command, true);
            }
            return(plannedAppt.PlannedApptNum);
        }
Пример #3
0
 ///<summary>Inserts one PlannedAppt into the database.  Returns the new priKey.</summary>
 public static long Insert(PlannedAppt plannedAppt)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         plannedAppt.PlannedApptNum = DbHelper.GetNextOracleKey("plannedappt", "PlannedApptNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(plannedAppt, true));
             }
             catch (Oracle.DataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     plannedAppt.PlannedApptNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(plannedAppt, false));
     }
 }
Пример #4
0
 ///<summary>Inserts one PlannedAppt into the database.  Provides option to use the existing priKey.</summary>
 internal static long Insert(PlannedAppt plannedAppt,bool useExistingPK)
 {
     if(!useExistingPK && PrefC.RandomKeys) {
         plannedAppt.PlannedApptNum=ReplicationServers.GetKey("plannedappt","PlannedApptNum");
     }
     string command="INSERT INTO plannedappt (";
     if(useExistingPK || PrefC.RandomKeys) {
         command+="PlannedApptNum,";
     }
     command+="PatNum,AptNum,ItemOrder) VALUES(";
     if(useExistingPK || PrefC.RandomKeys) {
         command+=POut.Long(plannedAppt.PlannedApptNum)+",";
     }
     command+=
              POut.Long  (plannedAppt.PatNum)+","
         +    POut.Long  (plannedAppt.AptNum)+","
         +    POut.Int   (plannedAppt.ItemOrder)+")";
     if(useExistingPK || PrefC.RandomKeys) {
         Db.NonQ(command);
     }
     else {
         plannedAppt.PlannedApptNum=Db.NonQ(command,true);
     }
     return plannedAppt.PlannedApptNum;
 }
Пример #5
0
 ///<summary>Inserts one PlannedAppt into the database.  Returns the new priKey.</summary>
 internal static long Insert(PlannedAppt plannedAppt)
 {
     if(DataConnection.DBtype==DatabaseType.Oracle) {
         plannedAppt.PlannedApptNum=DbHelper.GetNextOracleKey("plannedappt","PlannedApptNum");
         int loopcount=0;
         while(loopcount<100){
             try {
                 return Insert(plannedAppt,true);
             }
             catch(Oracle.DataAccess.Client.OracleException ex){
                 if(ex.Number==1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")){
                     plannedAppt.PlannedApptNum++;
                     loopcount++;
                 }
                 else{
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else {
         return Insert(plannedAppt,false);
     }
 }
Пример #6
0
        ///<summary>Updates one PlannedAppt in the database.</summary>
        public static void Update(PlannedAppt plannedAppt)
        {
            string command = "UPDATE plannedappt SET "
                             + "PatNum        =  " + POut.Long(plannedAppt.PatNum) + ", "
                             + "AptNum        =  " + POut.Long(plannedAppt.AptNum) + ", "
                             + "ItemOrder     =  " + POut.Int(plannedAppt.ItemOrder) + " "
                             + "WHERE PlannedApptNum = " + POut.Long(plannedAppt.PlannedApptNum);

            Db.NonQ(command);
        }
Пример #7
0
		///<summary>Converts a DataTable to a list of objects.</summary>
		public static List<PlannedAppt> TableToList(DataTable table){
			List<PlannedAppt> retVal=new List<PlannedAppt>();
			PlannedAppt plannedAppt;
			for(int i=0;i<table.Rows.Count;i++) {
				plannedAppt=new PlannedAppt();
				plannedAppt.PlannedApptNum= PIn.Long  (table.Rows[i]["PlannedApptNum"].ToString());
				plannedAppt.PatNum        = PIn.Long  (table.Rows[i]["PatNum"].ToString());
				plannedAppt.AptNum        = PIn.Long  (table.Rows[i]["AptNum"].ToString());
				plannedAppt.ItemOrder     = PIn.Int   (table.Rows[i]["ItemOrder"].ToString());
				retVal.Add(plannedAppt);
			}
			return retVal;
		}
Пример #8
0
 ///<summary>Inserts one PlannedAppt into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(PlannedAppt plannedAppt)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(plannedAppt, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             plannedAppt.PlannedApptNum = DbHelper.GetNextOracleKey("plannedappt", "PlannedApptNum");                  //Cacheless method
         }
         return(InsertNoCache(plannedAppt, true));
     }
 }
Пример #9
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <PlannedAppt> TableToList(DataTable table)
        {
            List <PlannedAppt> retVal = new List <PlannedAppt>();
            PlannedAppt        plannedAppt;

            foreach (DataRow row in table.Rows)
            {
                plannedAppt = new PlannedAppt();
                plannedAppt.PlannedApptNum = PIn.Long(row["PlannedApptNum"].ToString());
                plannedAppt.PatNum         = PIn.Long(row["PatNum"].ToString());
                plannedAppt.AptNum         = PIn.Long(row["AptNum"].ToString());
                plannedAppt.ItemOrder      = PIn.Int(row["ItemOrder"].ToString());
                retVal.Add(plannedAppt);
            }
            return(retVal);
        }
Пример #10
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <PlannedAppt> TableToList(DataTable table)
        {
            List <PlannedAppt> retVal = new List <PlannedAppt>();
            PlannedAppt        plannedAppt;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                plannedAppt = new PlannedAppt();
                plannedAppt.PlannedApptNum = PIn.Long(table.Rows[i]["PlannedApptNum"].ToString());
                plannedAppt.PatNum         = PIn.Long(table.Rows[i]["PatNum"].ToString());
                plannedAppt.AptNum         = PIn.Long(table.Rows[i]["AptNum"].ToString());
                plannedAppt.ItemOrder      = PIn.Int(table.Rows[i]["ItemOrder"].ToString());
                retVal.Add(plannedAppt);
            }
            return(retVal);
        }
Пример #11
0
 ///<summary>Returns true if Update(PlannedAppt,PlannedAppt) 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(PlannedAppt plannedAppt, PlannedAppt oldPlannedAppt)
 {
     if (plannedAppt.PatNum != oldPlannedAppt.PatNum)
     {
         return(true);
     }
     if (plannedAppt.AptNum != oldPlannedAppt.AptNum)
     {
         return(true);
     }
     if (plannedAppt.ItemOrder != oldPlannedAppt.ItemOrder)
     {
         return(true);
     }
     return(false);
 }
Пример #12
0
        private List <PlannedAppt> ExtractPlannedAppts(Patient pat, DataTable tablePlannedAppts)
        {
            List <PlannedAppt> listPlannedAppts = new List <PlannedAppt>();

            //Essentially a TableToList method, but since the DataTable doesn't have a PatNum row, pull from the Pat object.
            for (int i = 0; i < tablePlannedAppts.Rows.Count; i++)
            {
                DataRow     row         = tablePlannedAppts.Rows[i];
                PlannedAppt plannedAppt = new PlannedAppt();
                plannedAppt.PlannedApptNum = PIn.Long(row["PlannedApptNum"].ToString());
                plannedAppt.PatNum         = pat.PatNum;               //data.TablePlannedAppts will not have PatNum column.
                plannedAppt.AptNum         = PIn.Long(row["AptNum"].ToString());
                plannedAppt.ItemOrder      = PIn.Int(row["ItemOrder"].ToString());
                listPlannedAppts.Add(plannedAppt);
            }
            return(listPlannedAppts.OrderBy(x => x.ItemOrder).ToList());
        }
Пример #13
0
        ///<summary>Updates one PlannedAppt 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(PlannedAppt plannedAppt, PlannedAppt oldPlannedAppt)
        {
            string command = "";

            if (plannedAppt.PatNum != oldPlannedAppt.PatNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "PatNum = " + POut.Long(plannedAppt.PatNum) + "";
            }
            if (plannedAppt.AptNum != oldPlannedAppt.AptNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "AptNum = " + POut.Long(plannedAppt.AptNum) + "";
            }
            if (plannedAppt.ItemOrder != oldPlannedAppt.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(plannedAppt.ItemOrder) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE plannedappt SET " + command
                      + " WHERE PlannedApptNum = " + POut.Long(plannedAppt.PlannedApptNum);
            Db.NonQ(command);
            return(true);
        }
Пример #14
0
		///<summary>Updates one PlannedAppt 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(PlannedAppt plannedAppt,PlannedAppt oldPlannedAppt){
			string command="";
			if(plannedAppt.PatNum != oldPlannedAppt.PatNum) {
				if(command!=""){ command+=",";}
				command+="PatNum = "+POut.Long(plannedAppt.PatNum)+"";
			}
			if(plannedAppt.AptNum != oldPlannedAppt.AptNum) {
				if(command!=""){ command+=",";}
				command+="AptNum = "+POut.Long(plannedAppt.AptNum)+"";
			}
			if(plannedAppt.ItemOrder != oldPlannedAppt.ItemOrder) {
				if(command!=""){ command+=",";}
				command+="ItemOrder = "+POut.Int(plannedAppt.ItemOrder)+"";
			}
			if(command==""){
				return;
			}
			command="UPDATE plannedappt SET "+command
				+" WHERE PlannedApptNum = "+POut.Long(plannedAppt.PlannedApptNum);
			Db.NonQ(command);
		}
Пример #15
0
		///<summary>Updates one PlannedAppt in the database.</summary>
		public static void Update(PlannedAppt plannedAppt){
			string command="UPDATE plannedappt SET "
				+"PatNum        =  "+POut.Long  (plannedAppt.PatNum)+", "
				+"AptNum        =  "+POut.Long  (plannedAppt.AptNum)+", "
				+"ItemOrder     =  "+POut.Int   (plannedAppt.ItemOrder)+" "
				+"WHERE PlannedApptNum = "+POut.Long(plannedAppt.PlannedApptNum);
			Db.NonQ(command);
		}
Пример #16
0
        ///<summary></summary>
        public static PlannedApptStatus CreatePlannedAppt(Patient pat, int itemOrder, List <long> listPreSelectedProcNums = null)
        {
            if (!Security.IsAuthorized(Permissions.AppointmentCreate))
            {
                return(PlannedApptStatus.Failure);
            }
            if (PatRestrictionL.IsRestricted(pat.PatNum, PatRestrict.ApptSchedule))
            {
                return(PlannedApptStatus.Failure);
            }
            if (PromptForMerge(pat, out pat))
            {
                FormOpenDental.S_Contr_PatientSelected(pat, true, false);
            }
            if (pat.PatStatus.In(PatientStatus.Archived, PatientStatus.Deceased))
            {
                MsgBox.Show("Appointments", "Appointments cannot be scheduled for " + pat.PatStatus.ToString().ToLower() + " patients.");
                return(PlannedApptStatus.Failure);
            }
            Appointment AptCur = new Appointment();

            AptCur.PatNum      = pat.PatNum;
            AptCur.ProvNum     = pat.PriProv;
            AptCur.ClinicNum   = pat.ClinicNum;
            AptCur.AptStatus   = ApptStatus.Planned;
            AptCur.AptDateTime = DateTimeOD.Today;
            List <Procedure> listProcs = Procedures.GetManyProc(listPreSelectedProcNums, false);        //Returns empty list if null.

            //If listProcs is empty then AptCur.Pattern defaults to PrefName.AppointmentWithoutProcsDefaultLength value.
            //See Appointments.GetApptTimePatternForNoProcs().
            AptCur.Pattern    = Appointments.CalculatePattern(pat, AptCur.ProvNum, AptCur.ProvHyg, listProcs, isMake5Minute: true);
            AptCur.TimeLocked = PrefC.GetBool(PrefName.AppointmentTimeIsLocked);
            Appointments.Insert(AptCur);
            PlannedAppt plannedAppt = new PlannedAppt();

            plannedAppt.AptNum    = AptCur.AptNum;
            plannedAppt.PatNum    = pat.PatNum;
            plannedAppt.ItemOrder = itemOrder;
            PlannedAppts.Insert(plannedAppt);
            Procedures.UpdateAptNums(listPreSelectedProcNums, plannedAppt.AptNum, true);          //Simply returns if listPreSelectedProcNums is null
            FormApptEdit FormApptEdit = new FormApptEdit(AptCur.AptNum);

            FormApptEdit.IsNew = true;
            FormApptEdit.ShowDialog();
            if (FormApptEdit.DialogResult != DialogResult.OK)
            {
                Procedures.UpdateAptNums(listPreSelectedProcNums, 0, true);              //Simply returns if listPreSelectedProcNums is null
                return(PlannedApptStatus.FillGridNeeded);
            }
            //Only set the appointment hygienist to this patient's secondary provider if one was not manually set within the edit window.
            if (AptCur.ProvHyg < 1)
            {
                List <Procedure> myProcList  = Procedures.GetProcsForSingle(AptCur.AptNum, true);
                bool             allProcsHyg = (myProcList.Count > 0 && myProcList.Select(x => ProcedureCodes.GetProcCode(x.CodeNum)).ToList().All(x => x.IsHygiene));
                //Automatically set the appointments hygienist to the secondary provider of the patient if one is set.
                if (allProcsHyg && pat.SecProv != 0)
                {
                    Appointment aptOld = AptCur.Copy();
                    AptCur.ProvNum = pat.SecProv;
                    Appointments.Update(AptCur, aptOld);
                }
            }
            Patient patOld = pat.Copy();

            pat.PlannedIsDone = false;
            Patients.Update(pat, patOld);
            FormOpenDental.S_RefreshCurrentModule(isClinicRefresh: false);           //if procs were added in appt, then this will display them
            return(PlannedApptStatus.Success);
        }
Пример #17
0
 ///<summary>Inserts one PlannedAppt into the database.  Returns the new priKey.</summary>
 public static long Insert(PlannedAppt plannedAppt)
 {
     return(Insert(plannedAppt, false));
 }