Exemple #1
0
 /// <summary>
 /// 药库月结
 /// </summary>
 /// <param name="regPeople">月结操作人员</param>
 /// <param name="regDept">月结药剂科室</param>
 public override void MonthAccount(int regPeople, int regDept)
 {
     try
     {
         //锁住当前库房,确保月结时不会进行其他操作
         ConfigManager.BeginCheck(regDept);
         oleDb.BeginTransaction();
         DateTime      currentTime = XcDate.ServerDateTime;
         int           accountDay  = ConfigManager.GetAccountDay(regDept);
         YP_AccountHis lastAccount = new YK_AccountQuery().GetLastAccountHis(regDept);
         if (lastAccount != null)
         {
             if (currentTime.Day == accountDay && currentTime.Month != lastAccount.AccountMonth)
             {
                 currentTime = MonthAccountAction(regPeople, regDept, currentTime, false);
                 oleDb.CommitTransaction();
             }
             else
             {
                 throw new Exception("当前日期不是月结日期或本月已做过月结,无法进行月结");
             }
         }
         else
         {
             if (currentTime.Day == accountDay)
             {
                 MonthAccountAction(regPeople, regDept, currentTime, true);
                 oleDb.CommitTransaction();
             }
             else
             {
                 throw new Exception("当前日期不是月结日期,无法进行月结");
             }
         }
         //解锁库房
         ConfigManager.EndCheck(regDept);
     }
     catch (Exception error)
     {
         if (oleDb.IsInTransaction)
         {
             oleDb.RollbackTransaction();
         }
         //解锁库房
         ConfigManager.EndCheck(regDept);
         throw error;
     }
 }
Exemple #2
0
        /// <summary>
        /// 取消药库月结
        /// </summary>
        /// <param name="regPeople">月结人员</param>
        /// <param name="regDept">月结科室</param>
        public override void CancelMonthAccount(int regPeople, int regDept)
        {
            try
            {
                oleDb.BeginTransaction();
                string strWhere = "";
                //获取当前时间
                DateTime currentTime = XcDate.ServerDateTime;
                //获取月结日
                int accountDay = ConfigManager.GetAccountDay(regDept);
                //获取上次月结记录
                YP_AccountHis lastAccount = new YK_AccountQuery().GetLastAccountHis(regDept);
                if (lastAccount == null)
                {
                    throw new Exception("没有月结历史记录,请先进行初始化月结");
                }
                if (BindEntity <YP_AccountHis> .CreateInstanceDAL(oleDb, BLL.Tables.YK_ACCOUNTHIS).GetListArray(BLL.Tables.yk_accounthis.DEPTID
                                                                                                                + oleDb.EuqalTo() + lastAccount.DeptID).Count <= 1)
                {
                    throw new Exception("初始化月结不允许取消");
                }
                //判断是否可以取消月结
                if (currentTime.Month == lastAccount.AccountMonth && currentTime > lastAccount.RegTime)
                {
                    IBaseDAL <YP_AccountHis> accountHisDao = BindEntity <YP_AccountHis> .CreateInstanceDAL(oleDb,
                                                                                                           HIS.BLL.Tables.YK_ACCOUNTHIS);

                    IBaseDAL <YP_Account> accountDao = BindEntity <YP_Account> .CreateInstanceDAL(oleDb, HIS.BLL.Tables.YK_ACCOUNT);

                    //删除前次月结历史记录
                    accountHisDao.Delete(lastAccount.AccountHistoryID);
                    //删除本月期末台帐
                    strWhere = "AccountMonth=" + currentTime.Month.ToString() + " AND " + "AccountType=1" +
                               " AND DeptID=" + regDept.ToString();
                    accountDao.Delete(strWhere);
                    int nextMonth;
                    if (currentTime.Month == 12)
                    {
                        nextMonth = 1;
                    }
                    else
                    {
                        nextMonth = currentTime.Month + 1;
                    }
                    //删除下月月期初台帐
                    strWhere = "AccountMonth=" + nextMonth.ToString() + " AND " + "AccountType=0" +
                               " AND DeptID=" + regDept.ToString();
                    accountDao.Delete(strWhere);
                    //将已经月结过的台帐记录设置成未月结
                    strWhere = "AccountMonth=" + currentTime.Month.ToString() +
                               " AND DeptID=" + regDept.ToString();
                    accountDao.Update(strWhere, "Balance_Flag=0");
                    //将下月的台帐记录中的会计月记录设置成当前月
                    strWhere = "AccountMonth=" + nextMonth.ToString() +
                               " AND DeptID=" + regDept.ToString();
                    accountDao.Update(strWhere, "AccountMonth=" + currentTime.Month.ToString());
                    oleDb.CommitTransaction();
                }
                else
                {
                    throw new Exception("本月还没有进行月结,因此无法取消月结");
                }
            }
            catch (Exception error)
            {
                oleDb.RollbackTransaction();
                throw error;
            }
        }