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

            if (!useExistingPK && isRandomKeys)
            {
                requiredFieldCondition.RequiredFieldConditionNum = ReplicationServers.GetKeyNoCache("requiredfieldcondition", "RequiredFieldConditionNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "RequiredFieldConditionNum,";
            }
            command += "RequiredFieldNum,ConditionType,Operator,ConditionValue,ConditionRelationship) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(requiredFieldCondition.RequiredFieldConditionNum) + ",";
            }
            command +=
                POut.Long(requiredFieldCondition.RequiredFieldNum) + ","
                + "'" + POut.String(requiredFieldCondition.ConditionType.ToString()) + "',"
                + POut.Int((int)requiredFieldCondition.Operator) + ","
                + "'" + POut.String(requiredFieldCondition.ConditionValue) + "',"
                + POut.Int((int)requiredFieldCondition.ConditionRelationship) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                requiredFieldCondition.RequiredFieldConditionNum = Db.NonQ(command, true, "RequiredFieldConditionNum", "requiredFieldCondition");
            }
            return(requiredFieldCondition.RequiredFieldConditionNum);
        }
Ejemplo n.º 2
0
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <RequiredFieldCondition> TableToList(DataTable table)
        {
            List <RequiredFieldCondition> retVal = new List <RequiredFieldCondition>();
            RequiredFieldCondition        requiredFieldCondition;

            foreach (DataRow row in table.Rows)
            {
                requiredFieldCondition = new RequiredFieldCondition();
                requiredFieldCondition.RequiredFieldConditionNum = PIn.Long(row["RequiredFieldConditionNum"].ToString());
                requiredFieldCondition.RequiredFieldNum          = PIn.Long(row["RequiredFieldNum"].ToString());
                string conditionType = row["ConditionType"].ToString();
                if (conditionType == "")
                {
                    requiredFieldCondition.ConditionType = (RequiredFieldName)0;
                }
                else
                {
                    try{
                        requiredFieldCondition.ConditionType = (RequiredFieldName)Enum.Parse(typeof(RequiredFieldName), conditionType);
                    }
                    catch {
                        requiredFieldCondition.ConditionType = (RequiredFieldName)0;
                    }
                }
                requiredFieldCondition.Operator              = (OpenDentBusiness.ConditionOperator)PIn.Int(row["Operator"].ToString());
                requiredFieldCondition.ConditionValue        = PIn.String(row["ConditionValue"].ToString());
                requiredFieldCondition.ConditionRelationship = (OpenDentBusiness.LogicalOperator)PIn.Int(row["ConditionRelationship"].ToString());
                retVal.Add(requiredFieldCondition);
            }
            return(retVal);
        }
Ejemplo n.º 3
0
 ///<summary>Inserts one RequiredFieldCondition into the database.  Returns the new priKey.</summary>
 public static long Insert(RequiredFieldCondition requiredFieldCondition)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         requiredFieldCondition.RequiredFieldConditionNum = DbHelper.GetNextOracleKey("requiredfieldcondition", "RequiredFieldConditionNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(requiredFieldCondition, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     requiredFieldCondition.RequiredFieldConditionNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(requiredFieldCondition, false));
     }
 }
Ejemplo n.º 4
0
        ///<summary>Updates one RequiredFieldCondition 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(RequiredFieldCondition requiredFieldCondition, RequiredFieldCondition oldRequiredFieldCondition)
        {
            string command = "";

            if (requiredFieldCondition.RequiredFieldNum != oldRequiredFieldCondition.RequiredFieldNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "RequiredFieldNum = " + POut.Long(requiredFieldCondition.RequiredFieldNum) + "";
            }
            if (requiredFieldCondition.ConditionType != oldRequiredFieldCondition.ConditionType)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ConditionType = '" + POut.String(requiredFieldCondition.ConditionType.ToString()) + "'";
            }
            if (requiredFieldCondition.Operator != oldRequiredFieldCondition.Operator)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "Operator = " + POut.Int((int)requiredFieldCondition.Operator) + "";
            }
            if (requiredFieldCondition.ConditionValue != oldRequiredFieldCondition.ConditionValue)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ConditionValue = '" + POut.String(requiredFieldCondition.ConditionValue) + "'";
            }
            if (requiredFieldCondition.ConditionRelationship != oldRequiredFieldCondition.ConditionRelationship)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ConditionRelationship = " + POut.Int((int)requiredFieldCondition.ConditionRelationship) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE requiredfieldcondition SET " + command
                      + " WHERE RequiredFieldConditionNum = " + POut.Long(requiredFieldCondition.RequiredFieldConditionNum);
            Db.NonQ(command);
            return(true);
        }
Ejemplo n.º 5
0
        ///<summary>Updates one RequiredFieldCondition in the database.</summary>
        public static void Update(RequiredFieldCondition requiredFieldCondition)
        {
            string command = "UPDATE requiredfieldcondition SET "
                             + "RequiredFieldNum         =  " + POut.Long(requiredFieldCondition.RequiredFieldNum) + ", "
                             + "ConditionType            = '" + POut.String(requiredFieldCondition.ConditionType.ToString()) + "', "
                             + "Operator                 =  " + POut.Int((int)requiredFieldCondition.Operator) + ", "
                             + "ConditionValue           = '" + POut.String(requiredFieldCondition.ConditionValue) + "', "
                             + "ConditionRelationship    =  " + POut.Int((int)requiredFieldCondition.ConditionRelationship) + " "
                             + "WHERE RequiredFieldConditionNum = " + POut.Long(requiredFieldCondition.RequiredFieldConditionNum);

            Db.NonQ(command);
        }
Ejemplo n.º 6
0
 ///<summary>Inserts one RequiredFieldCondition into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(RequiredFieldCondition requiredFieldCondition)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(requiredFieldCondition, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             requiredFieldCondition.RequiredFieldConditionNum = DbHelper.GetNextOracleKey("requiredfieldcondition", "RequiredFieldConditionNum");                  //Cacheless method
         }
         return(InsertNoCache(requiredFieldCondition, true));
     }
 }
Ejemplo n.º 7
0
 ///<summary>Returns true if Update(RequiredFieldCondition,RequiredFieldCondition) 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(RequiredFieldCondition requiredFieldCondition, RequiredFieldCondition oldRequiredFieldCondition)
 {
     if (requiredFieldCondition.RequiredFieldNum != oldRequiredFieldCondition.RequiredFieldNum)
     {
         return(true);
     }
     if (requiredFieldCondition.ConditionType != oldRequiredFieldCondition.ConditionType)
     {
         return(true);
     }
     if (requiredFieldCondition.Operator != oldRequiredFieldCondition.Operator)
     {
         return(true);
     }
     if (requiredFieldCondition.ConditionValue != oldRequiredFieldCondition.ConditionValue)
     {
         return(true);
     }
     if (requiredFieldCondition.ConditionRelationship != oldRequiredFieldCondition.ConditionRelationship)
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 8
0
        private void butOK_Click(object sender, EventArgs e)
        {
            if (listConditionType.SelectedIndex == -1)
            {
                MsgBox.Show(this, "Please select a condition type.");
                return;
            }
            RequiredFieldName      selectedField = _listIndexFieldNames[listConditionType.SelectedIndex];
            RequiredFieldCondition condition;

            switch (selectedField)
            {
            //Types that are continuous values
            case RequiredFieldName.Birthdate:
            case RequiredFieldName.AdmitDate:
            case RequiredFieldName.DateTimeDeceased:
                if (textConditionValue1.Text == "")
                {
                    MsgBox.Show(this, "Please enter a condition value.");
                    return;
                }
                if (comboOperator1.SelectedIndex == -1)
                {
                    MsgBox.Show(this, "Please select an operator from the drop down list.");
                    return;
                }
                //Construct the first condition
                RequiredFieldCondition condition1 = new RequiredFieldCondition();
                condition1.RequiredFieldNum = _reqField.RequiredFieldNum;
                condition1.ConditionType    = selectedField;
                int      agePlaceholder;
                DateTime datePlaceholder;
                if (selectedField == RequiredFieldName.Birthdate && !Int32.TryParse(textConditionValue1.Text, out agePlaceholder))
                {
                    MsgBox.Show(this, "Please enter a valid integer.");
                    return;
                }
                else if ((selectedField == RequiredFieldName.AdmitDate || selectedField == RequiredFieldName.DateTimeDeceased) &&
                         !DateTime.TryParse(textConditionValue1.Text, out datePlaceholder))
                {
                    MsgBox.Show(this, "Please enter a valid date.");
                    return;
                }
                condition1.ConditionValue = textConditionValue1.Text;
                condition1.Operator       = (ConditionOperator)(comboOperator1.SelectedIndex + 2);              //Plus 2 because Equals and NotEquals are not in the combo box
                RequiredFieldConditions.DeleteAll(_listReqFieldConds.Select(x => x.RequiredFieldConditionNum).ToList());
                if (textConditionValue2.Text == "")
                {
                    RequiredFieldConditions.Insert(condition1);
                    break;
                }
                //Construct the second condition if it is not blank
                if (comboOperator2.SelectedIndex == -1)
                {
                    MsgBox.Show(this, "Please select an operator from the drop down list.");
                    return;
                }
                if (listRelationships.SelectedIndex == -1)
                {
                    MsgBox.Show(this, "Please select 'And' or 'Or'.");
                    return;
                }
                RequiredFieldCondition condition2 = new RequiredFieldCondition();
                condition2.RequiredFieldNum = _reqField.RequiredFieldNum;
                condition2.ConditionType    = selectedField;
                if (selectedField == RequiredFieldName.Birthdate && !Int32.TryParse(textConditionValue2.Text, out agePlaceholder))
                {
                    MsgBox.Show(this, "Please enter a valid integer.");
                    return;
                }
                else if ((selectedField == RequiredFieldName.AdmitDate || selectedField == RequiredFieldName.DateTimeDeceased) &&
                         !DateTime.TryParse(textConditionValue2.Text, out datePlaceholder))
                {
                    MsgBox.Show(this, "Please enter a valid date.");
                    return;
                }
                condition2.ConditionValue = textConditionValue2.Text;
                condition2.Operator       = (ConditionOperator)(comboOperator2.SelectedIndex + 2); //Plus 2 because Equals and NotEquals are not in the combo box
                if (listRelationships.SelectedIndex == 0)                                          //'And' is selected
                {
                    condition1.ConditionRelationship = LogicalOperator.And;
                    condition2.ConditionRelationship = LogicalOperator.And;
                }
                else                          //'Or' is selected
                {
                    condition1.ConditionRelationship = LogicalOperator.Or;
                    condition2.ConditionRelationship = LogicalOperator.Or;
                }
                RequiredFieldConditions.Insert(condition1);
                RequiredFieldConditions.Insert(condition2);
                break;

            //Types that store the foreign key of the value
            case RequiredFieldName.BillingType:
            case RequiredFieldName.Clinic:
            case RequiredFieldName.PrimaryProvider:
                if (listRelationships.SelectedIndex == -1)
                {
                    MsgBox.Show(this, "Please select 'Is' or 'Is not'.");
                    return;
                }
                if (listConditionValues.SelectedIndices.Count == 0)
                {
                    MsgBox.Show(this, "Please select a condition value.");
                    return;
                }
                List <long> listFkNums = new List <long>();
                if (selectedField == RequiredFieldName.PrimaryProvider)
                {
                    for (int i = 0; i < listConditionValues.SelectedIndices.Count; i++)
                    {
                        listFkNums.Add(_listProvs[listConditionValues.SelectedIndices[i]].ProvNum);
                    }
                }
                else if (selectedField == RequiredFieldName.BillingType)
                {
                    for (int i = 0; i < listConditionValues.SelectedIndices.Count; i++)
                    {
                        listFkNums.Add(_listBillingTypeDefs[listConditionValues.SelectedIndices[i]].DefNum);
                    }
                }
                else                            //selectedField==RequiredFieldName.Clinic
                {
                    for (int i = 0; i < listConditionValues.SelectedIndices.Count; i++)
                    {
                        if (listConditionValues.SelectedIndices[i] == 0)                                //'Unassigned'
                        {
                            listFkNums.Add(0);
                        }
                        else
                        {
                            listFkNums.Add(_listClinics[listConditionValues.SelectedIndices[i] - 1].ClinicNum);                                  //Subtract 1 to account for 'Unassigned'
                        }
                    }
                }
                //Delete the original conditions
                RequiredFieldConditions.DeleteAll(_listReqFieldConds.Select(x => x.RequiredFieldConditionNum).ToList());
                //Insert the new conditions
                condition = new RequiredFieldCondition();
                condition.RequiredFieldNum = _reqField.RequiredFieldNum;
                condition.ConditionType    = selectedField;
                if (listRelationships.SelectedIndex == 0)                       //'Is' is selected
                {
                    condition.Operator = ConditionOperator.Equals;
                }
                else                          //'Is not' is selected
                {
                    condition.Operator = ConditionOperator.NotEquals;
                }
                for (int i = 0; i < listFkNums.Count; i++)
                {
                    condition.ConditionValue = listFkNums[i].ToString();
                    RequiredFieldConditions.Insert(condition);
                }
                break;

            //Types that store the value of listConditionValues
            case RequiredFieldName.StudentStatus:
            case RequiredFieldName.PatientStatus:
            case RequiredFieldName.Position:
            case RequiredFieldName.Gender:
            case RequiredFieldName.Language:
            case RequiredFieldName.MedicaidID:
            case RequiredFieldName.MedicaidState:
                if (listRelationships.SelectedIndex == -1)
                {
                    MsgBox.Show(this, "Please select 'Is' or 'Is not'.");
                    return;
                }
                if (listConditionValues.SelectedIndices.Count == 0)
                {
                    MsgBox.Show(this, "Please select a value.");
                    return;
                }
                //Delete the original conditions
                RequiredFieldConditions.DeleteAll(_listReqFieldConds.Select(x => x.RequiredFieldConditionNum).ToList());
                //Insert the new conditions
                condition = new RequiredFieldCondition();
                condition.RequiredFieldNum = _reqField.RequiredFieldNum;
                condition.ConditionType    = selectedField;
                if (listRelationships.SelectedIndex == 0)                       //'Is' is selected
                {
                    condition.Operator = ConditionOperator.Equals;
                }
                else                          //'Is not' is selected
                {
                    condition.Operator = ConditionOperator.NotEquals;
                }
                for (int i = 0; i < listConditionValues.SelectedIndices.Count; i++)
                {
                    condition.ConditionValue = listConditionValues.Items[listConditionValues.SelectedIndices[i]].ToString();
                    RequiredFieldConditions.Insert(condition);
                }
                break;
            }
            DialogResult = DialogResult.OK;
        }
 ///<summary>Inserts one RequiredFieldCondition into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(RequiredFieldCondition requiredFieldCondition)
 {
     return(InsertNoCache(requiredFieldCondition, false));
 }