Example #1
0
        ///<summary>Also handles detaching all payments and claimpayments.  Throws exception if deposit is attached as a source document to a transaction.  The program should have detached the deposit from the transaction ahead of time, so I would never expect the program to throw this exception unless there was a bug.</summary>
        public static void Delete(Deposit dep)
        {
            //check dependencies
            string command = "";

            if (dep.DepositNum != 0)
            {
                command = "SELECT COUNT(*) FROM transaction WHERE DepositNum =" + POut.PInt(dep.DepositNum);
                if (PIn.PInt(General.GetCount(command)) > 0)
                {
                    throw new ApplicationException(Lan.g("Deposits", "Cannot delete deposit because it is attached to a transaction."));
                }
            }

            /*/check claimpayment
             * command="SELECT COUNT(*) FROM claimpayment WHERE DepositNum ="+POut.PInt(DepositNum);
             * if(PIn.PInt(General.GetCount(command))>0){
             *      throw new InvalidProgramException(Lan.g("Deposits","Cannot delete deposit because it has payments attached"));
             * }*/
            //ready to delete
            command = "UPDATE payment SET DepositNum=0 WHERE DepositNum=" + POut.PInt(dep.DepositNum);
            General.NonQ(command);
            command = "UPDATE claimpayment SET DepositNum=0 WHERE DepositNum=" + POut.PInt(dep.DepositNum);
            General.NonQ(command);
            command = "DELETE FROM deposit WHERE DepositNum=" + POut.PInt(dep.DepositNum);
            General.NonQ(command);
        }
Example #2
0
        ///<summary>Surround with try-catch</summary>
        public static void Delete(int employeeNum)
        {
            //appointment.Assistant will not block deletion
            //schedule.EmployeeNum will not block deletion
            string command = "SELECT COUNT(*) FROM clockevent WHERE EmployeeNum=" + POut.PInt(employeeNum);

            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException(Lan.g("FormEmployeeSelect",
                                                     "Not allowed to delete employee because of attached clock events."));
            }
            command = "SELECT COUNT(*) FROM timeadjust WHERE EmployeeNum=" + POut.PInt(employeeNum);
            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException(Lan.g("FormEmployeeSelect",
                                                     "Not allowed to delete employee because of attached time adjustments."));
            }
            command = "SELECT COUNT(*) FROM userod WHERE EmployeeNum=" + POut.PInt(employeeNum);
            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException(Lan.g("FormEmployeeSelect",
                                                     "Not allowed to delete employee because of attached user."));
            }
            command = "UPDATE appointment SET Assistant=0 WHERE Assistant=" + POut.PInt(employeeNum);
            General.NonQ(command);
            command = "DELETE FROM schedule WHERE EmployeeNum=" + POut.PInt(employeeNum);
            General.NonQ(command);
            command = "DELETE FROM employee WHERE EmployeeNum =" + POut.PInt(employeeNum);
            General.NonQ(command);
        }
Example #3
0
        ///<summary>Used when printing recall cards to make a commlog entry for everyone at once.</summary>
        public static void InsertForRecallPostcard(int patNum)
        {
            int    recallType = Commlogs.GetTypeAuto(CommItemTypeAuto.RECALL);
            string command;

            if (recallType != 0)
            {
                command = "SELECT COUNT(*) FROM  commlog WHERE ";
                if (FormChooseDatabase.DBtype == DatabaseType.Oracle)
                {
                    command += "TO_DATE(CommDateTime) = " + POut.PDate(MiscData.GetNowDateTime());
                }
                else                  //Assume MySQL
                {
                    command += "DATE(CommDateTime) = CURDATE()";
                }
                command += " AND PatNum=" + POut.PInt(patNum) + " AND CommType=" + POut.PInt(recallType)
                           + " AND Mode_=2 AND SentOrReceived=1";
                if (General.GetCount(command) != "0")
                {
                    return;
                }
            }
            Commlog com = new Commlog();

            com.PatNum         = patNum;
            com.CommDateTime   = DateTime.Now;
            com.CommType       = recallType;
            com.Mode_          = CommItemMode.Mail;
            com.SentOrReceived = CommSentOrReceived.Sent;
            com.Note           = Lan.g("FormRecallList", "Sent recall postcard");
            Insert(com);
        }
Example #4
0
        ///<summary>Surround with try/catch.</summary>
        public static void Update(Carrier Cur)
        {
            string    command;
            DataTable table;

            if (CultureInfo.CurrentCulture.Name.Substring(3) == "CA")           //en-CA or fr-CA
            {
                if (Cur.IsCDA)
                {
                    if (Cur.ElectID == "")
                    {
                        throw new ApplicationException(Lan.g("Carriers", "EDI Code required."));
                    }
                    if (!Regex.IsMatch(Cur.ElectID, "^[0-9]{6}$"))
                    {
                        throw new ApplicationException(Lan.g("Carriers", "EDI Code must be exactly 6 numbers."));
                    }
                    command = "SELECT CarrierNum FROM carrier WHERE "
                              + "ElectID = '" + POut.PString(Cur.ElectID) + "' "
                              + "AND IsCDA=1 "
                              + "AND CarrierNum != " + POut.PInt(Cur.CarrierNum);
                    table = General.GetTable(command);
                    if (table.Rows.Count > 0)                   //if there already exists a Canadian carrier with that ElectID
                    {
                        throw new ApplicationException(Lan.g("Carriers", "EDI Code already in use."));
                    }
                }
                //so the edited carrier looks good, but now we need to make sure that the original was allowed to be changed.
                command = "SELECT ElectID,IsCDA FROM carrier WHERE CarrierNum = '" + POut.PInt(Cur.CarrierNum) + "'";
                table   = General.GetTable(command);
                if (PIn.PBool(table.Rows[0][1].ToString()) &&            //if original carrier IsCDA
                    PIn.PString(table.Rows[0][0].ToString()) != Cur.ElectID)                      //and the ElectID was changed
                {
                    command = "SELECT COUNT(*) FROM etrans WHERE CarrierNum= " + POut.PInt(Cur.CarrierNum)
                              + " OR CarrierNum2=" + POut.PInt(Cur.CarrierNum);
                    if (General.GetCount(command) != "0")
                    {
                        throw new ApplicationException(Lan.g("Carriers", "Not allowed to change EDI Code because it's in use in the claim history."));
                    }
                }
            }
            command = "UPDATE carrier SET "
                      + "CarrierName= '" + POut.PString(Cur.CarrierName) + "' "
                      + ",Address= '" + POut.PString(Cur.Address) + "' "
                      + ",Address2= '" + POut.PString(Cur.Address2) + "' "
                      + ",City= '" + POut.PString(Cur.City) + "' "
                      + ",State= '" + POut.PString(Cur.State) + "' "
                      + ",Zip= '" + POut.PString(Cur.Zip) + "' "
                      + ",Phone= '" + POut.PString(Cur.Phone) + "' "
                      + ",ElectID= '" + POut.PString(Cur.ElectID) + "' "
                      + ",NoSendElect= '" + POut.PBool(Cur.NoSendElect) + "' "
                      + ",IsCDA= '" + POut.PBool(Cur.IsCDA) + "' "
                      + ",IsPMP= '" + POut.PBool(Cur.IsPMP) + "' "
                      + ",CDAnetVersion= '" + POut.PString(Cur.CDAnetVersion) + "' "
                      + ",CanadianNetworkNum= '" + POut.PInt(Cur.CanadianNetworkNum) + "' "
                      + "WHERE CarrierNum = '" + POut.PInt(Cur.CarrierNum) + "'";
            //MessageBox.Show(string command);
            General.NonQ(command);
        }
Example #5
0
        private static bool KeyInUse(string tablename, string field, int keynum)
        {
            string command = "SELECT COUNT(*) FROM " + tablename + " WHERE " + field + "=" + keynum.ToString();

            if (General.GetCount(command) == "0")
            {
                return(false);
            }
            return(true);           //already in use
        }
Example #6
0
        ///<summary>Attaches a req to an appointment.  Importantly, it also sets the patNum to match the apt.</summary>
        public static void AttachToApt(int reqStudentNum, int aptNum)
        {
            string command = "SELECT PatNum FROM appointment WHERE AptNum=" + POut.PInt(aptNum);
            string patNum  = General.GetCount(command);

            command = "UPDATE reqstudent SET AptNum=" + POut.PInt(aptNum)
                      + ", PatNum=" + patNum
                      + " WHERE ReqStudentNum=" + POut.PInt(reqStudentNum);
            General.NonQ(command);
        }
Example #7
0
        ///<summary></summary>
        public static bool IsReconciled(Transaction trans)
        {
            string command = "SELECT COUNT(*) FROM journalentry WHERE ReconcileNum !=0"
                             + " AND TransactionNum=" + POut.PInt(trans.TransactionNum);

            if (General.GetCount(command) == "0")
            {
                return(false);
            }
            return(true);
        }
Example #8
0
        ///<summary>Called just before Allocate in FormPayment.butOK click.  If true, then it will prompt the user before allocating.</summary>
        public static bool AllocationRequired(double payAmt, int patNum)
        {
            string command = "SELECT EstBalance FROM patient "
                             + "WHERE PatNum = " + POut.PInt(patNum);
            double estBal = PIn.PDouble(General.GetCount(command));

            if (payAmt > estBal)
            {
                return(true);
            }
            return(false);
        }
Example #9
0
        ///<summary>Called whenever user wants to edit patient info.  Not allowed to if patient edit window is open at a terminal.  Once patient is done at terminal, then staff allowed back into patient edit window.</summary>
        public static bool PatIsInUse(int patNum)
        {
            string command = "SELECT COUNT(*) FROM terminalactive WHERE PatNum=" + POut.PInt(patNum)
                             + " AND (TerminalStatus=" + POut.PInt((int)TerminalStatusEnum.PatientInfo)
                             + " OR TerminalStatus=" + POut.PInt((int)TerminalStatusEnum.UpdateOnly) + ")";

            if (General.GetCount(command) == "0")
            {
                return(false);
            }
            return(true);
        }
Example #10
0
        /*
         * ///<summary></summary>
         * public static void CheckIfDeletedLastBlockout(DateTime schedDate){
         *      string command="SELECT COUNT(*) FROM schedule WHERE SchedType='"+POut.PInt((int)ScheduleType.Blockout)+"' "
         +"AND SchedDate="+POut.PDate(schedDate);
         *      DataTable table=General.GetTable(command);
         *      if(table.Rows[0][0].ToString()=="0") {
         *              Schedule sched=new Schedule();
         *              sched.SchedDate=schedDate;
         *              sched.SchedType=ScheduleType.Blockout;
         *              sched.Status=SchedStatus.Closed;
         *              Insert(sched);
         *      }
         * }*/

        public static bool DateIsHoliday(DateTime date)
        {
            string command = "SELECT COUNT(*) FROM schedule WHERE Status=2 " //holiday
                             + "AND SchedType=0 "                            //practice
                             + "AND SchedDate= " + POut.PDate(date);
            string result = General.GetCount(command);

            if (result == "0")
            {
                return(false);
            }
            return(true);
        }
Example #11
0
        ///<summary>Throws exception if Reconcile is in use.</summary>
        public static void Delete(Reconcile reconcile)
        {
            //check to see if any journal entries are attached to this Reconcile
            string command = "SELECT COUNT(*) FROM journalentry WHERE ReconcileNum=" + POut.PInt(reconcile.ReconcileNum);

            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException(Lan.g("FormReconcileEdit",
                                                     "Not allowed to delete a Reconcile with existing journal entries."));
            }
            command = "DELETE FROM reconcile WHERE ReconcileNum = " + POut.PInt(reconcile.ReconcileNum);
            General.NonQ(command);
        }
Example #12
0
        ///<summary>Called from FormPayPlan.  Also deletes all attached payplancharges.  Throws exception if there are any paysplits attached.</summary>
        public static void Delete(PayPlan plan)
        {
            string command = "SELECT COUNT(*) FROM paysplit WHERE PayPlanNum=" + plan.PayPlanNum.ToString();

            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException
                          (Lan.g("PayPlans", "You cannot delete a payment plan with payments attached.  Unattach the payments first."));
            }
            command = "DELETE FROM payplancharge WHERE PayPlanNum=" + plan.PayPlanNum.ToString();
            General.NonQ(command);
            command = "DELETE FROM payplan WHERE PayPlanNum =" + plan.PayPlanNum.ToString();
            General.NonQ(command);
        }
Example #13
0
        ///<summary>Throws exception if account is in use.</summary>
        public static void Delete(Account acct)
        {
            //check to see if account has any journal entries
            string command = "SELECT COUNT(*) FROM journalentry WHERE AccountNum=" + POut.PInt(acct.AccountNum);

            if (General.GetCount(command) != "0")
            {
                throw new ApplicationException(Lan.g("FormAccountEdit",
                                                     "Not allowed to delete an account with existing journal entries."));
            }
            //Check various preference entries
            command = "SELECT ValueString FROM preference WHERE PrefName='AccountingDepositAccounts'";
            string result = General.GetCount(command);

            string[] strArray = result.Split(new char[] { ',' });
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i] == acct.AccountNum.ToString())
                {
                    throw new ApplicationException(Lan.g("FormAccountEdit", "Account is in use in the setup section."));
                }
            }
            command = "SELECT ValueString FROM preference WHERE PrefName='AccountingIncomeAccount'";
            result  = General.GetCount(command);
            if (result == acct.AccountNum.ToString())
            {
                throw new ApplicationException(Lan.g("FormAccountEdit", "Account is in use in the setup section."));
            }
            command = "SELECT ValueString FROM preference WHERE PrefName='AccountingCashIncomeAccount'";
            result  = General.GetCount(command);
            if (result == acct.AccountNum.ToString())
            {
                throw new ApplicationException(Lan.g("FormAccountEdit", "Account is in use in the setup section."));
            }
            //check AccountingAutoPay entries
            for (int i = 0; i < AccountingAutoPays.AList.Count; i++)
            {
                strArray = ((AccountingAutoPay)AccountingAutoPays.AList[i]).PickList.Split(new char[] { ',' });
                for (int s = 0; s < strArray.Length; s++)
                {
                    if (strArray[s] == acct.AccountNum.ToString())
                    {
                        throw new ApplicationException(Lan.g("FormAccountEdit", "Account is in use in the setup section."));
                    }
                }
            }
            command = "DELETE FROM account WHERE AccountNum = " + POut.PInt(acct.AccountNum);
            General.NonQ(command);
        }
Example #14
0
        ///<summary></summary>
        public static void InsertOrUpdate(bool isNew, Userod user)
        {
            //make sure username is not already taken
            string command;

            if (isNew)
            {
                command = "SELECT COUNT(*) FROM userod WHERE UserName='******'";
            }
            else
            {
                command = "SELECT COUNT(*) FROM userod WHERE UserName='******' "
                          + "AND UserNum !=" + POut.PInt(user.UserNum);           //it's ok if the name matches the current username
            }
            DataTable table = General.GetTable(command);

            if (table.Rows[0][0].ToString() != "0")
            {
                throw new Exception(Lan.g("Userods", "UserName already in use."));
            }
            //make sure that there would still be at least one user with security admin permissions
            if (!isNew)
            {
                command = "SELECT COUNT(*) FROM grouppermission "
                          + "WHERE PermType='" + POut.PInt((int)Permissions.SecurityAdmin) + "' "
                          + "AND UserGroupNum=" + POut.PInt(user.UserGroupNum);
                if (General.GetCount(command) == "0")              //if this user would not have admin
                //make sure someone else has admin
                {
                    command = "SELECT COUNT(*) FROM userod,grouppermission "
                              + "WHERE grouppermission.PermType='" + POut.PInt((int)Permissions.SecurityAdmin) + "'"
                              + " AND userod.UserGroupNum=grouppermission.UserGroupNum"
                              + " AND userod.UserNum != " + POut.PInt(user.UserNum);
                    if (General.GetCount(command) == "0")                  //there are no other users with this permission
                    {
                        throw new Exception(Lan.g("Users", "At least one user must have Security Admin permission."));
                    }
                }
            }
            if (isNew)
            {
                Insert(user);
            }
            else
            {
                Update(user);
            }
        }
Example #15
0
        ///<summary></summary>
        public static void InsertOrUpdate(bool isNew, Userod user)
        {
            //should add a check that employeenum and provnum are not both set.
            //make sure username is not already taken
            string command;
            int    excludeUserNum;

            if (isNew)
            {
                excludeUserNum = 0;
            }
            else
            {
                excludeUserNum = user.UserNum;              //it's ok if the name matches the current username
            }
            if (!IsUserNameUnique(user.UserName, excludeUserNum))
            {
                throw new Exception(Lan.g("Userods", "UserName already in use."));
            }
            //make sure that there would still be at least one user with security admin permissions
            if (!isNew)
            {
                command = "SELECT COUNT(*) FROM grouppermission "
                          + "WHERE PermType='" + POut.PInt((int)Permissions.SecurityAdmin) + "' "
                          + "AND UserGroupNum=" + POut.PInt(user.UserGroupNum);
                if (General.GetCount(command) == "0")              //if this user would not have admin
                //make sure someone else has admin
                {
                    command = "SELECT COUNT(*) FROM userod,grouppermission "
                              + "WHERE grouppermission.PermType='" + POut.PInt((int)Permissions.SecurityAdmin) + "'"
                              + " AND userod.UserGroupNum=grouppermission.UserGroupNum"
                              + " AND userod.IsHidden =0"
                              + " AND userod.UserNum != " + POut.PInt(user.UserNum);
                    if (General.GetCount(command) == "0")                  //there are no other users with this permission
                    {
                        throw new Exception(Lan.g("Users", "At least one user must have Security Admin permission."));
                    }
                }
            }
            if (isNew)
            {
                Insert(user);
            }
            else
            {
                Update(user);
            }
        }