Beispiel #1
0
        ///<summary>Inserts one FieldDefLink into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(FieldDefLink fieldDefLink, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO fielddeflink (";

            if (!useExistingPK && isRandomKeys)
            {
                fieldDefLink.FieldDefLinkNum = ReplicationServers.GetKeyNoCache("fielddeflink", "FieldDefLinkNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "FieldDefLinkNum,";
            }
            command += "FieldDefNum,FieldDefType,FieldLocation) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(fieldDefLink.FieldDefLinkNum) + ",";
            }
            command +=
                POut.Long(fieldDefLink.FieldDefNum) + ","
                + POut.Int((int)fieldDefLink.FieldDefType) + ","
                + POut.Int((int)fieldDefLink.FieldLocation) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                fieldDefLink.FieldDefLinkNum = Db.NonQ(command, true, "FieldDefLinkNum", "fieldDefLink");
            }
            return(fieldDefLink.FieldDefLinkNum);
        }
Beispiel #2
0
        ///<summary>Inserts one FieldDefLink into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(FieldDefLink fieldDefLink, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                fieldDefLink.FieldDefLinkNum = ReplicationServers.GetKey("fielddeflink", "FieldDefLinkNum");
            }
            string command = "INSERT INTO fielddeflink (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "FieldDefLinkNum,";
            }
            command += "FieldDefNum,FieldDefType,FieldLocation) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(fieldDefLink.FieldDefLinkNum) + ",";
            }
            command +=
                POut.Long(fieldDefLink.FieldDefNum) + ","
                + POut.Int((int)fieldDefLink.FieldDefType) + ","
                + POut.Int((int)fieldDefLink.FieldLocation) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                fieldDefLink.FieldDefLinkNum = Db.NonQ(command, true, "FieldDefLinkNum", "fieldDefLink");
            }
            return(fieldDefLink.FieldDefLinkNum);
        }
Beispiel #3
0
 ///<summary>Inserts one FieldDefLink into the database.  Returns the new priKey.</summary>
 public static long Insert(FieldDefLink fieldDefLink)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         fieldDefLink.FieldDefLinkNum = DbHelper.GetNextOracleKey("fielddeflink", "FieldDefLinkNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(fieldDefLink, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     fieldDefLink.FieldDefLinkNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(fieldDefLink, false));
     }
 }
Beispiel #4
0
        ///<summary>Updates one FieldDefLink in the database.</summary>
        public static void Update(FieldDefLink fieldDefLink)
        {
            string command = "UPDATE fielddeflink SET "
                             + "FieldDefNum    =  " + POut.Long(fieldDefLink.FieldDefNum) + ", "
                             + "FieldDefType   =  " + POut.Int((int)fieldDefLink.FieldDefType) + ", "
                             + "FieldLocation  =  " + POut.Int((int)fieldDefLink.FieldLocation) + " "
                             + "WHERE FieldDefLinkNum = " + POut.Long(fieldDefLink.FieldDefLinkNum);

            Db.NonQ(command);
        }
Beispiel #5
0
 ///<summary>Inserts one FieldDefLink into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(FieldDefLink fieldDefLink)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(fieldDefLink, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             fieldDefLink.FieldDefLinkNum = DbHelper.GetNextOracleKey("fielddeflink", "FieldDefLinkNum");                  //Cacheless method
         }
         return(InsertNoCache(fieldDefLink, true));
     }
 }
Beispiel #6
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <FieldDefLink> TableToList(DataTable table)
        {
            List <FieldDefLink> retVal = new List <FieldDefLink>();
            FieldDefLink        fieldDefLink;

            foreach (DataRow row in table.Rows)
            {
                fieldDefLink = new FieldDefLink();
                fieldDefLink.FieldDefLinkNum = PIn.Long(row["FieldDefLinkNum"].ToString());
                fieldDefLink.FieldDefNum     = PIn.Long(row["FieldDefNum"].ToString());
                fieldDefLink.FieldDefType    = (OpenDentBusiness.FieldDefTypes)PIn.Int(row["FieldDefType"].ToString());
                fieldDefLink.FieldLocation   = (OpenDentBusiness.FieldLocations)PIn.Int(row["FieldLocation"].ToString());
                retVal.Add(fieldDefLink);
            }
            return(retVal);
        }
Beispiel #7
0
 ///<summary>Returns true if Update(FieldDefLink,FieldDefLink) 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(FieldDefLink fieldDefLink, FieldDefLink oldFieldDefLink)
 {
     if (fieldDefLink.FieldDefNum != oldFieldDefLink.FieldDefNum)
     {
         return(true);
     }
     if (fieldDefLink.FieldDefType != oldFieldDefLink.FieldDefType)
     {
         return(true);
     }
     if (fieldDefLink.FieldLocation != oldFieldDefLink.FieldLocation)
     {
         return(true);
     }
     return(false);
 }
Beispiel #8
0
        ///<summary>Updates one FieldDefLink 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(FieldDefLink fieldDefLink, FieldDefLink oldFieldDefLink)
        {
            string command = "";

            if (fieldDefLink.FieldDefNum != oldFieldDefLink.FieldDefNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FieldDefNum = " + POut.Long(fieldDefLink.FieldDefNum) + "";
            }
            if (fieldDefLink.FieldDefType != oldFieldDefLink.FieldDefType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FieldDefType = " + POut.Int((int)fieldDefLink.FieldDefType) + "";
            }
            if (fieldDefLink.FieldLocation != oldFieldDefLink.FieldLocation)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "FieldLocation = " + POut.Int((int)fieldDefLink.FieldLocation) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE fielddeflink SET " + command
                      + " WHERE FieldDefLinkNum = " + POut.Long(fieldDefLink.FieldDefLinkNum);
            Db.NonQ(command);
            return(true);
        }
Beispiel #9
0
        private void butRight_Click(object sender, EventArgs e)
        {
            //Add the selected field def from the display grid to the _listFieldDefLinks as a new link.  Refill grid.
            if (gridDisplayed.GetSelectedIndex() < 0)
            {
                return;                //Button pressed with nothing selected
            }
            FieldDefLink fieldDefLink = new FieldDefLink();

            switch ((FieldLocations)comboFieldLocation.SelectedIndex)
            {
            case FieldLocations.Account:
            case FieldLocations.Chart:
            case FieldLocations.Family:
            case FieldLocations.GroupNote:
            case FieldLocations.OrthoChart:
                PatFieldDef patFieldDef = (PatFieldDef)gridDisplayed.Rows[gridDisplayed.GetSelectedIndex()].Tag;
                fieldDefLink               = new FieldDefLink();
                fieldDefLink.FieldDefNum   = patFieldDef.PatFieldDefNum;
                fieldDefLink.FieldDefType  = FieldDefTypes.Patient;
                fieldDefLink.FieldLocation = (FieldLocations)comboFieldLocation.SelectedIndex;
                _listFieldDefLinks.Add(fieldDefLink);
                break;

            case FieldLocations.AppointmentEdit:                    //AppointmentEdit is the only place where ApptFields are used.
                ApptFieldDef apptFieldDef = (ApptFieldDef)gridDisplayed.Rows[gridDisplayed.GetSelectedIndex()].Tag;
                fieldDefLink               = new FieldDefLink();
                fieldDefLink.FieldDefNum   = apptFieldDef.ApptFieldDefNum;
                fieldDefLink.FieldDefType  = FieldDefTypes.Appointment;
                fieldDefLink.FieldLocation = (FieldLocations)comboFieldLocation.SelectedIndex;
                _listFieldDefLinks.Add(fieldDefLink);
                break;
            }
            FillGridDisplayed();
            FillGridHidden();
        }
Beispiel #10
0
 ///<summary>Inserts one FieldDefLink into the database.  Returns the new priKey.</summary>
 public static long Insert(FieldDefLink fieldDefLink)
 {
     return(Insert(fieldDefLink, false));
 }