///<summary>Inserts one HistAppointment into the database. Returns the new priKey.</summary> public static long Insert(HistAppointment histAppointment) { if (DataConnection.DBtype == DatabaseType.Oracle) { histAppointment.HistApptNum = DbHelper.GetNextOracleKey("histappointment", "HistApptNum"); int loopcount = 0; while (loopcount < 100) { try { return(Insert(histAppointment, true)); } catch (Oracle.ManagedDataAccess.Client.OracleException ex) { if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated")) { histAppointment.HistApptNum++; loopcount++; } else { throw ex; } } } throw new ApplicationException("Insert failed. Could not generate primary key."); } else { return(Insert(histAppointment, false)); } }
///<summary>Updates one HistAppointment in the database.</summary> public static void Update(HistAppointment histAppointment) { string command = "UPDATE histappointment SET " + "HistUserNum = " + POut.Long(histAppointment.HistUserNum) + ", " //HistDateTStamp not allowed to change + "HistApptAction = " + POut.Int((int)histAppointment.HistApptAction) + ", " + "ApptSource = " + POut.Int((int)histAppointment.ApptSource) + ", " + "AptNum = " + POut.Long(histAppointment.AptNum) + ", " + "PatNum = " + POut.Long(histAppointment.PatNum) + ", " + "AptStatus = " + POut.Int((int)histAppointment.AptStatus) + ", " + "Pattern = '" + POut.String(histAppointment.Pattern) + "', " + "Confirmed = " + POut.Long(histAppointment.Confirmed) + ", " + "TimeLocked = " + POut.Bool(histAppointment.TimeLocked) + ", " + "Op = " + POut.Long(histAppointment.Op) + ", " + "Note = " + DbHelper.ParamChar + "paramNote, " + "ProvNum = " + POut.Long(histAppointment.ProvNum) + ", " + "ProvHyg = " + POut.Long(histAppointment.ProvHyg) + ", " + "AptDateTime = " + POut.DateT(histAppointment.AptDateTime) + ", " + "NextAptNum = " + POut.Long(histAppointment.NextAptNum) + ", " + "UnschedStatus = " + POut.Long(histAppointment.UnschedStatus) + ", " + "IsNewPatient = " + POut.Bool(histAppointment.IsNewPatient) + ", " + "ProcDescript = '" + POut.String(histAppointment.ProcDescript) + "', " + "Assistant = " + POut.Long(histAppointment.Assistant) + ", " + "ClinicNum = " + POut.Long(histAppointment.ClinicNum) + ", " + "IsHygiene = " + POut.Bool(histAppointment.IsHygiene) + ", " //DateTStamp can only be set by MySQL + "DateTimeArrived = " + POut.DateT(histAppointment.DateTimeArrived) + ", " + "DateTimeSeated = " + POut.DateT(histAppointment.DateTimeSeated) + ", " + "DateTimeDismissed = " + POut.DateT(histAppointment.DateTimeDismissed) + ", " + "InsPlan1 = " + POut.Long(histAppointment.InsPlan1) + ", " + "InsPlan2 = " + POut.Long(histAppointment.InsPlan2) + ", " + "DateTimeAskedToArrive= " + POut.DateT(histAppointment.DateTimeAskedToArrive) + ", " + "ProcsColored = " + DbHelper.ParamChar + "paramProcsColored, " + "ColorOverride = " + POut.Int(histAppointment.ColorOverride.ToArgb()) + ", " + "AppointmentTypeNum = " + POut.Long(histAppointment.AppointmentTypeNum) + ", " //SecUserNumEntry excluded from update //SecDateEntry not allowed to change + "Priority = " + POut.Int((int)histAppointment.Priority) + " " + "WHERE HistApptNum = " + POut.Long(histAppointment.HistApptNum); if (histAppointment.Note == null) { histAppointment.Note = ""; } OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringNote(histAppointment.Note)); if (histAppointment.ProcsColored == null) { histAppointment.ProcsColored = ""; } OdSqlParameter paramProcsColored = new OdSqlParameter("paramProcsColored", OdDbType.Text, POut.StringParam(histAppointment.ProcsColored)); Db.NonQ(command, paramNote, paramProcsColored); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <HistAppointment> TableToList(DataTable table) { List <HistAppointment> retVal = new List <HistAppointment>(); HistAppointment histAppointment; foreach (DataRow row in table.Rows) { histAppointment = new HistAppointment(); histAppointment.HistApptNum = PIn.Long(row["HistApptNum"].ToString()); histAppointment.HistUserNum = PIn.Long(row["HistUserNum"].ToString()); histAppointment.HistDateTStamp = PIn.DateT(row["HistDateTStamp"].ToString()); histAppointment.HistApptAction = (OpenDentBusiness.HistAppointmentAction)PIn.Int(row["HistApptAction"].ToString()); histAppointment.ApptSource = (OpenDentBusiness.EServiceTypes)PIn.Int(row["ApptSource"].ToString()); histAppointment.AptNum = PIn.Long(row["AptNum"].ToString()); histAppointment.PatNum = PIn.Long(row["PatNum"].ToString()); histAppointment.AptStatus = (OpenDentBusiness.ApptStatus)PIn.Int(row["AptStatus"].ToString()); histAppointment.Pattern = PIn.String(row["Pattern"].ToString()); histAppointment.Confirmed = PIn.Long(row["Confirmed"].ToString()); histAppointment.TimeLocked = PIn.Bool(row["TimeLocked"].ToString()); histAppointment.Op = PIn.Long(row["Op"].ToString()); histAppointment.Note = PIn.String(row["Note"].ToString()); histAppointment.ProvNum = PIn.Long(row["ProvNum"].ToString()); histAppointment.ProvHyg = PIn.Long(row["ProvHyg"].ToString()); histAppointment.AptDateTime = PIn.DateT(row["AptDateTime"].ToString()); histAppointment.NextAptNum = PIn.Long(row["NextAptNum"].ToString()); histAppointment.UnschedStatus = PIn.Long(row["UnschedStatus"].ToString()); histAppointment.IsNewPatient = PIn.Bool(row["IsNewPatient"].ToString()); histAppointment.ProcDescript = PIn.String(row["ProcDescript"].ToString()); histAppointment.Assistant = PIn.Long(row["Assistant"].ToString()); histAppointment.ClinicNum = PIn.Long(row["ClinicNum"].ToString()); histAppointment.IsHygiene = PIn.Bool(row["IsHygiene"].ToString()); histAppointment.DateTStamp = PIn.DateT(row["DateTStamp"].ToString()); histAppointment.DateTimeArrived = PIn.DateT(row["DateTimeArrived"].ToString()); histAppointment.DateTimeSeated = PIn.DateT(row["DateTimeSeated"].ToString()); histAppointment.DateTimeDismissed = PIn.DateT(row["DateTimeDismissed"].ToString()); histAppointment.InsPlan1 = PIn.Long(row["InsPlan1"].ToString()); histAppointment.InsPlan2 = PIn.Long(row["InsPlan2"].ToString()); histAppointment.DateTimeAskedToArrive = PIn.DateT(row["DateTimeAskedToArrive"].ToString()); histAppointment.ProcsColored = PIn.String(row["ProcsColored"].ToString()); histAppointment.ColorOverride = Color.FromArgb(PIn.Int(row["ColorOverride"].ToString())); histAppointment.AppointmentTypeNum = PIn.Long(row["AppointmentTypeNum"].ToString()); histAppointment.SecUserNumEntry = PIn.Long(row["SecUserNumEntry"].ToString()); histAppointment.SecDateTEntry = PIn.DateT(row["SecDateTEntry"].ToString()); histAppointment.Priority = (OpenDentBusiness.ApptPriority)PIn.Int(row["Priority"].ToString()); histAppointment.ProvBarText = PIn.String(row["ProvBarText"].ToString()); histAppointment.PatternSecondary = PIn.String(row["PatternSecondary"].ToString()); retVal.Add(histAppointment); } return(retVal); }
///<summary>Inserts one HistAppointment into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(HistAppointment histAppointment) { if (DataConnection.DBtype == DatabaseType.MySql) { return(InsertNoCache(histAppointment, false)); } else { if (DataConnection.DBtype == DatabaseType.Oracle) { histAppointment.HistApptNum = DbHelper.GetNextOracleKey("histappointment", "HistApptNum"); //Cacheless method } return(InsertNoCache(histAppointment, true)); } }
///<summary>Inserts one HistAppointment into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(HistAppointment histAppointment, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO histappointment ("; if (!useExistingPK && isRandomKeys) { histAppointment.HistApptNum = ReplicationServers.GetKeyNoCache("histappointment", "HistApptNum"); } if (isRandomKeys || useExistingPK) { command += "HistApptNum,"; } command += "HistUserNum,HistDateTStamp,HistApptAction,ApptSource,AptNum,PatNum,AptStatus,Pattern,Confirmed,TimeLocked,Op,Note,ProvNum,ProvHyg,AptDateTime,NextAptNum,UnschedStatus,IsNewPatient,ProcDescript,Assistant,ClinicNum,IsHygiene,DateTStamp,DateTimeArrived,DateTimeSeated,DateTimeDismissed,InsPlan1,InsPlan2,DateTimeAskedToArrive,ProcsColored,ColorOverride,AppointmentTypeNum,SecUserNumEntry,SecDateTEntry,Priority,ProvBarText,PatternSecondary) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(histAppointment.HistApptNum) + ","; } command += POut.Long(histAppointment.HistUserNum) + "," + DbHelper.Now() + "," + POut.Int((int)histAppointment.HistApptAction) + "," + POut.Int((int)histAppointment.ApptSource) + "," + POut.Long(histAppointment.AptNum) + "," + POut.Long(histAppointment.PatNum) + "," + POut.Int((int)histAppointment.AptStatus) + "," + "'" + POut.String(histAppointment.Pattern) + "'," + POut.Long(histAppointment.Confirmed) + "," + POut.Bool(histAppointment.TimeLocked) + "," + POut.Long(histAppointment.Op) + "," + DbHelper.ParamChar + "paramNote," + POut.Long(histAppointment.ProvNum) + "," + POut.Long(histAppointment.ProvHyg) + "," + POut.DateT(histAppointment.AptDateTime) + "," + POut.Long(histAppointment.NextAptNum) + "," + POut.Long(histAppointment.UnschedStatus) + "," + POut.Bool(histAppointment.IsNewPatient) + "," + "'" + POut.String(histAppointment.ProcDescript) + "'," + POut.Long(histAppointment.Assistant) + "," + POut.Long(histAppointment.ClinicNum) + "," + POut.Bool(histAppointment.IsHygiene) + "," + POut.DateT(histAppointment.DateTStamp) + "," + POut.DateT(histAppointment.DateTimeArrived) + "," + POut.DateT(histAppointment.DateTimeSeated) + "," + POut.DateT(histAppointment.DateTimeDismissed) + "," + POut.Long(histAppointment.InsPlan1) + "," + POut.Long(histAppointment.InsPlan2) + "," + POut.DateT(histAppointment.DateTimeAskedToArrive) + "," + DbHelper.ParamChar + "paramProcsColored," + POut.Int(histAppointment.ColorOverride.ToArgb()) + "," + POut.Long(histAppointment.AppointmentTypeNum) + "," + POut.Long(histAppointment.SecUserNumEntry) + "," + POut.DateT(histAppointment.SecDateTEntry) + "," + POut.Int((int)histAppointment.Priority) + "," + "'" + POut.String(histAppointment.ProvBarText) + "'," + "'" + POut.String(histAppointment.PatternSecondary) + "')"; if (histAppointment.Note == null) { histAppointment.Note = ""; } OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringNote(histAppointment.Note)); if (histAppointment.ProcsColored == null) { histAppointment.ProcsColored = ""; } OdSqlParameter paramProcsColored = new OdSqlParameter("paramProcsColored", OdDbType.Text, POut.StringParam(histAppointment.ProcsColored)); if (useExistingPK || isRandomKeys) { Db.NonQ(command, paramNote, paramProcsColored); } else { histAppointment.HistApptNum = Db.NonQ(command, true, "HistApptNum", "histAppointment", paramNote, paramProcsColored); } return(histAppointment.HistApptNum); }
///<summary>Inserts one HistAppointment into the database. Returns the new priKey. Doesn't use the cache.</summary> public static long InsertNoCache(HistAppointment histAppointment) { return(InsertNoCache(histAppointment, false)); }
///<summary>Returns true if Update(HistAppointment,HistAppointment) 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(HistAppointment histAppointment, HistAppointment oldHistAppointment) { if (histAppointment.HistUserNum != oldHistAppointment.HistUserNum) { return(true); } //HistDateTStamp not allowed to change if (histAppointment.HistApptAction != oldHistAppointment.HistApptAction) { return(true); } if (histAppointment.ApptSource != oldHistAppointment.ApptSource) { return(true); } if (histAppointment.AptNum != oldHistAppointment.AptNum) { return(true); } if (histAppointment.PatNum != oldHistAppointment.PatNum) { return(true); } if (histAppointment.AptStatus != oldHistAppointment.AptStatus) { return(true); } if (histAppointment.Pattern != oldHistAppointment.Pattern) { return(true); } if (histAppointment.Confirmed != oldHistAppointment.Confirmed) { return(true); } if (histAppointment.TimeLocked != oldHistAppointment.TimeLocked) { return(true); } if (histAppointment.Op != oldHistAppointment.Op) { return(true); } if (histAppointment.Note != oldHistAppointment.Note) { return(true); } if (histAppointment.ProvNum != oldHistAppointment.ProvNum) { return(true); } if (histAppointment.ProvHyg != oldHistAppointment.ProvHyg) { return(true); } if (histAppointment.AptDateTime != oldHistAppointment.AptDateTime) { return(true); } if (histAppointment.NextAptNum != oldHistAppointment.NextAptNum) { return(true); } if (histAppointment.UnschedStatus != oldHistAppointment.UnschedStatus) { return(true); } if (histAppointment.IsNewPatient != oldHistAppointment.IsNewPatient) { return(true); } if (histAppointment.ProcDescript != oldHistAppointment.ProcDescript) { return(true); } if (histAppointment.Assistant != oldHistAppointment.Assistant) { return(true); } if (histAppointment.ClinicNum != oldHistAppointment.ClinicNum) { return(true); } if (histAppointment.IsHygiene != oldHistAppointment.IsHygiene) { return(true); } //DateTStamp can only be set by MySQL if (histAppointment.DateTimeArrived != oldHistAppointment.DateTimeArrived) { return(true); } if (histAppointment.DateTimeSeated != oldHistAppointment.DateTimeSeated) { return(true); } if (histAppointment.DateTimeDismissed != oldHistAppointment.DateTimeDismissed) { return(true); } if (histAppointment.InsPlan1 != oldHistAppointment.InsPlan1) { return(true); } if (histAppointment.InsPlan2 != oldHistAppointment.InsPlan2) { return(true); } if (histAppointment.DateTimeAskedToArrive != oldHistAppointment.DateTimeAskedToArrive) { return(true); } if (histAppointment.ProcsColored != oldHistAppointment.ProcsColored) { return(true); } if (histAppointment.ColorOverride != oldHistAppointment.ColorOverride) { return(true); } if (histAppointment.AppointmentTypeNum != oldHistAppointment.AppointmentTypeNum) { return(true); } //SecUserNumEntry excluded from update //SecDateEntry not allowed to change if (histAppointment.Priority != oldHistAppointment.Priority) { return(true); } return(false); }
///<summary>Updates one HistAppointment 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(HistAppointment histAppointment, HistAppointment oldHistAppointment) { string command = ""; if (histAppointment.HistUserNum != oldHistAppointment.HistUserNum) { if (command != "") { command += ","; } command += "HistUserNum = " + POut.Long(histAppointment.HistUserNum) + ""; } //HistDateTStamp not allowed to change if (histAppointment.HistApptAction != oldHistAppointment.HistApptAction) { if (command != "") { command += ","; } command += "HistApptAction = " + POut.Int((int)histAppointment.HistApptAction) + ""; } if (histAppointment.ApptSource != oldHistAppointment.ApptSource) { if (command != "") { command += ","; } command += "ApptSource = " + POut.Int((int)histAppointment.ApptSource) + ""; } if (histAppointment.AptNum != oldHistAppointment.AptNum) { if (command != "") { command += ","; } command += "AptNum = " + POut.Long(histAppointment.AptNum) + ""; } if (histAppointment.PatNum != oldHistAppointment.PatNum) { if (command != "") { command += ","; } command += "PatNum = " + POut.Long(histAppointment.PatNum) + ""; } if (histAppointment.AptStatus != oldHistAppointment.AptStatus) { if (command != "") { command += ","; } command += "AptStatus = " + POut.Int((int)histAppointment.AptStatus) + ""; } if (histAppointment.Pattern != oldHistAppointment.Pattern) { if (command != "") { command += ","; } command += "Pattern = '" + POut.String(histAppointment.Pattern) + "'"; } if (histAppointment.Confirmed != oldHistAppointment.Confirmed) { if (command != "") { command += ","; } command += "Confirmed = " + POut.Long(histAppointment.Confirmed) + ""; } if (histAppointment.TimeLocked != oldHistAppointment.TimeLocked) { if (command != "") { command += ","; } command += "TimeLocked = " + POut.Bool(histAppointment.TimeLocked) + ""; } if (histAppointment.Op != oldHistAppointment.Op) { if (command != "") { command += ","; } command += "Op = " + POut.Long(histAppointment.Op) + ""; } if (histAppointment.Note != oldHistAppointment.Note) { if (command != "") { command += ","; } command += "Note = " + DbHelper.ParamChar + "paramNote"; } if (histAppointment.ProvNum != oldHistAppointment.ProvNum) { if (command != "") { command += ","; } command += "ProvNum = " + POut.Long(histAppointment.ProvNum) + ""; } if (histAppointment.ProvHyg != oldHistAppointment.ProvHyg) { if (command != "") { command += ","; } command += "ProvHyg = " + POut.Long(histAppointment.ProvHyg) + ""; } if (histAppointment.AptDateTime != oldHistAppointment.AptDateTime) { if (command != "") { command += ","; } command += "AptDateTime = " + POut.DateT(histAppointment.AptDateTime) + ""; } if (histAppointment.NextAptNum != oldHistAppointment.NextAptNum) { if (command != "") { command += ","; } command += "NextAptNum = " + POut.Long(histAppointment.NextAptNum) + ""; } if (histAppointment.UnschedStatus != oldHistAppointment.UnschedStatus) { if (command != "") { command += ","; } command += "UnschedStatus = " + POut.Long(histAppointment.UnschedStatus) + ""; } if (histAppointment.IsNewPatient != oldHistAppointment.IsNewPatient) { if (command != "") { command += ","; } command += "IsNewPatient = " + POut.Bool(histAppointment.IsNewPatient) + ""; } if (histAppointment.ProcDescript != oldHistAppointment.ProcDescript) { if (command != "") { command += ","; } command += "ProcDescript = '" + POut.String(histAppointment.ProcDescript) + "'"; } if (histAppointment.Assistant != oldHistAppointment.Assistant) { if (command != "") { command += ","; } command += "Assistant = " + POut.Long(histAppointment.Assistant) + ""; } if (histAppointment.ClinicNum != oldHistAppointment.ClinicNum) { if (command != "") { command += ","; } command += "ClinicNum = " + POut.Long(histAppointment.ClinicNum) + ""; } if (histAppointment.IsHygiene != oldHistAppointment.IsHygiene) { if (command != "") { command += ","; } command += "IsHygiene = " + POut.Bool(histAppointment.IsHygiene) + ""; } //DateTStamp can only be set by MySQL if (histAppointment.DateTimeArrived != oldHistAppointment.DateTimeArrived) { if (command != "") { command += ","; } command += "DateTimeArrived = " + POut.DateT(histAppointment.DateTimeArrived) + ""; } if (histAppointment.DateTimeSeated != oldHistAppointment.DateTimeSeated) { if (command != "") { command += ","; } command += "DateTimeSeated = " + POut.DateT(histAppointment.DateTimeSeated) + ""; } if (histAppointment.DateTimeDismissed != oldHistAppointment.DateTimeDismissed) { if (command != "") { command += ","; } command += "DateTimeDismissed = " + POut.DateT(histAppointment.DateTimeDismissed) + ""; } if (histAppointment.InsPlan1 != oldHistAppointment.InsPlan1) { if (command != "") { command += ","; } command += "InsPlan1 = " + POut.Long(histAppointment.InsPlan1) + ""; } if (histAppointment.InsPlan2 != oldHistAppointment.InsPlan2) { if (command != "") { command += ","; } command += "InsPlan2 = " + POut.Long(histAppointment.InsPlan2) + ""; } if (histAppointment.DateTimeAskedToArrive != oldHistAppointment.DateTimeAskedToArrive) { if (command != "") { command += ","; } command += "DateTimeAskedToArrive = " + POut.DateT(histAppointment.DateTimeAskedToArrive) + ""; } if (histAppointment.ProcsColored != oldHistAppointment.ProcsColored) { if (command != "") { command += ","; } command += "ProcsColored = " + DbHelper.ParamChar + "paramProcsColored"; } if (histAppointment.ColorOverride != oldHistAppointment.ColorOverride) { if (command != "") { command += ","; } command += "ColorOverride = " + POut.Int(histAppointment.ColorOverride.ToArgb()) + ""; } if (histAppointment.AppointmentTypeNum != oldHistAppointment.AppointmentTypeNum) { if (command != "") { command += ","; } command += "AppointmentTypeNum = " + POut.Long(histAppointment.AppointmentTypeNum) + ""; } //SecUserNumEntry excluded from update //SecDateEntry not allowed to change if (histAppointment.Priority != oldHistAppointment.Priority) { if (command != "") { command += ","; } command += "Priority = " + POut.Int((int)histAppointment.Priority) + ""; } if (command == "") { return(false); } if (histAppointment.Note == null) { histAppointment.Note = ""; } OdSqlParameter paramNote = new OdSqlParameter("paramNote", OdDbType.Text, POut.StringNote(histAppointment.Note)); if (histAppointment.ProcsColored == null) { histAppointment.ProcsColored = ""; } OdSqlParameter paramProcsColored = new OdSqlParameter("paramProcsColored", OdDbType.Text, POut.StringParam(histAppointment.ProcsColored)); command = "UPDATE histappointment SET " + command + " WHERE HistApptNum = " + POut.Long(histAppointment.HistApptNum); Db.NonQ(command, paramNote, paramProcsColored); return(true); }