/// <summary> /// 药房月结 /// </summary> /// <param name="regPeople">月结操作人员编码</param> /// <param name="regDept">月结科室编码</param> public override void MonthAccount(int regPeople, int regDept) { try { //锁住当前月结库房,确保月结时不进行任何操作 DateTime currentTime = XcDate.ServerDateTime; int accountDay = ConfigManager.GetAccountDay(regDept); YP_AccountHis lastAccount = new YF_AccountQuery().GetLastAccountHis(regDept); ConfigManager.BeginCheck(regDept); if (lastAccount != null) { if (currentTime.Day == accountDay && currentTime.Month != lastAccount.AccountMonth) { currentTime = MonthAccountAction(regPeople, regDept, currentTime, false); } else { throw new Exception("当前日期不是月结日期或当月已做过月结,无法进行月结"); } } else { if (currentTime.Day == accountDay) { currentTime = MonthAccountAction(regPeople, regDept, currentTime, false); } else { throw new Exception("当前日期不是月结日期,无法进行月结"); } } //库房解锁 ConfigManager.EndCheck(regDept); } catch (Exception error) { //库房解锁 ConfigManager.EndCheck(regDept); throw error; } }
/// <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 YF_AccountQuery().GetLastAccountHis(regDept); if (lastAccount == null) { throw new Exception("没有月结历史记录,请先进行初始化月结"); } if (BindEntity <YP_AccountHis> .CreateInstanceDAL(oleDb, BLL.Tables.YF_ACCOUNTHIS).GetListArray(BLL.Tables.yf_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.YF_ACCOUNTHIS); IBaseDAL <YP_Account> accountDao = BindEntity <YP_Account> .CreateInstanceDAL(oleDb, HIS.BLL.Tables.YF_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; } }