public ServiceResponseData SaveBill()
        {
            string                belongSys     = requestData.GetData <string>(0);
            DS_ApplyHead          head          = requestData.GetData <DS_ApplyHead>(1);
            IDGBill               iProcess      = NewObject <DGBillFactory>().GetBillProcess(DGConstant.OP_DS_APPLYPLAN);
            List <DS_ApplyDetail> details       = requestData.GetData <List <DS_ApplyDetail> >(2);
            List <int>            deleteDetails = requestData.GetData <List <int> >(3);

            oleDb.BeginTransaction();
            try
            {
                foreach (int detailID in deleteDetails)
                {
                    NewObject <DS_ApplyDetail>().delete(detailID);
                }

                iProcess.SaveBill(head, details);
                oleDb.CommitTransaction();
                responseData.AddData(true);
            }
            catch (Exception error)
            {
                oleDb.RollbackTransaction();
                responseData.AddData(false);
                responseData.AddData(error.Message);
            }

            return(responseData);
        }
        /// <summary>
        /// 从界面获取药库入库表头信息
        /// </summary>
        /// <returns>药库入库表头信息</returns>
        public DS_ApplyHead GetHeadInfo()
        {
            DS_ApplyHead inHead = new DS_ApplyHead();

            frmCommon.GetValue <DS_ApplyHead>(inHead);
            inHead.ToDeptName = cbWareHourse.Text;
            return(inHead);
        }
        public ServiceResponseData GetEditBillHead()
        {
            int          billID = requestData.GetData <int>(0);
            DS_ApplyHead head   = (DS_ApplyHead)NewObject <DS_ApplyHead>().getmodel(billID);

            responseData.AddData(head);
            return(responseData);
        }
        public void RefreshHead(string frmName)
        {
            DS_ApplyHead editHead = frmdeApplyDetails.GetHeadInfo();

            if (frmdeApplyDetails.CurrentApplyHead != null)
            {
                frmdeApplyDetails.CurrentApplyHead.ToDeptID   = editHead.ToDeptID;
                frmdeApplyDetails.CurrentApplyHead.ToDeptName = editHead.ToDeptName;
                frmdeApplyDetails.CurrentApplyHead.Remark     = editHead.Remark;
                frmdeApplyDetails.CurrentApplyHead.RegTime    = editHead.RegTime;
            }
        }
 /// <summary>
 /// 初始化控件状态
 /// </summary>
 /// <param name="head">表头对象</param>
 public void InitControStatus(DS_ApplyHead head)
 {
     if (head.ApplyHeadID == 0)
     {
         btnNewBill.Enabled   = true;
         cbWareHourse.Enabled = true;
     }
     else
     {
         btnNewBill.Enabled   = false;
         cbWareHourse.Enabled = false;
     }
 }
        /// <summary>
        /// 删除申请单
        /// </summary>
        /// <param name="billID">主键KEY</param>
        public override void DeleteBill(int billID)
        {
            DS_ApplyHead inHead = (DS_ApplyHead)NewObject <DS_ApplyHead>().getmodel(billID);

            if (inHead.AuditFlag == 1)
            {
                throw new Exception("当前单据已经审核,无法删除");
            }
            else
            {
                inHead.DelFlag = 1;
                inHead.save();
            }
        }
        public bool InitBillHead(string remark, string todeptId, string todeptName, int id)
        {
            if (LoginUserInfo.DeptId == 0)
            {
                MessageBoxShowSimple("当前用户没有选择领药科室");
                return(false);
            }

            if (id == 0)
            {
                DS_ApplyHead head = new DS_ApplyHead();
                head.ApplyHeadID   = id;
                head.RegEmpID      = LoginUserInfo.EmpId;
                head.UpdateTime    = DateTime.Now;
                head.RegEmpName    = LoginUserInfo.EmpName;
                head.Remark        = remark;
                head.RegTime       = DateTime.Now;
                head.ApplyDeptID   = selectedDeptID;
                head.ApplyDeptName = LoginUserInfo.DeptName.ToString();
                head.ToDeptID      = Convert.ToInt32(todeptId);
                head.ToDeptName    = todeptName;
                frmdeApplyDetails.BindInHeadInfo(head);
            }
            else
            {
                Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(id);
                });
                ServiceResponseData retdata   = InvokeWcfService("DrugProject.Service", "ApplyStoreController", "GetEditBillHead", requestAction);
                DS_ApplyHead        storeHead = retdata.GetData <DS_ApplyHead>(0);
                if (storeHead.AuditFlag == 1)
                {
                    MessageBoxShowSimple("当前单据已经审核,不能修改");
                    return(false);
                }

                storeHead.ApplyDeptID = selectedDeptID;
                frmdeApplyDetails.CurrentApplyHead = storeHead;
                frmdeApplyDetails.BindInHeadInfo(storeHead);
            }

            frmdeApplyDetails.InitControStatus(frmdeApplyDetails.CurrentApplyHead);
            return(true);
        }
        /// <summary>
        /// 保存药房入库单
        /// </summary>
        /// <typeparam name="THead">药房入库单表头模板</typeparam>
        /// <typeparam name="TDetail">药房入库单明细模板</typeparam>
        /// <param name="billHead">药房入库单表头</param>
        /// <param name="billDetails">药房入库单明细</param>
        public override void SaveBill <THead, TDetail>(THead billHead, List <TDetail> billDetails)
        {
            DS_ApplyHead          inHead   = billHead as DS_ApplyHead;
            List <DS_ApplyDetail> inDetals = billDetails as List <DS_ApplyDetail>;

            inHead.RegTime = System.DateTime.Now;
            string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, inHead.ApplyDeptID, DGConstant.OP_DS_APPLYPLAN);

            inHead.BillNO = Convert.ToInt64(serialNO);
            BindDb(inHead);
            inHead.save();
            if (inHead.ApplyHeadID > 0)
            {
                foreach (DS_ApplyDetail detail in inDetals)
                {
                    detail.ApplyHeadID = inHead.ApplyHeadID;
                    BindDb(detail);
                    detail.save();
                }
            }
        }
 /// <summary>
 /// 绑定领药表头数据
 /// </summary>
 /// <param name="head">领药表头数据</param>
 public void BindInHeadInfo(DS_ApplyHead head)
 {
     CurrentApplyHead = head;
 }
        public ServiceResponseData SaveBillFromApply()
        {
            string                   belongSys     = requestData.GetData <string>(0);
            string                   busiType      = requestData.GetData <string>(1);
            IDGBill                  iProcess      = NewObject <DGBillFactory>().GetBillProcess(busiType);
            DGBillResult             result        = new DGBillResult();
            DW_OutStoreHead          head          = requestData.GetData <DW_OutStoreHead>(2);
            List <DW_OutStoreDetail> details       = requestData.GetData <List <DW_OutStoreDetail> >(3);
            List <int>               deleteDetails = requestData.GetData <List <int> >(4);

            oleDb.BeginTransaction();
            try
            {
                foreach (int detailID in deleteDetails)
                {
                    NewObject <DW_OutStoreDetail>().delete(detailID);
                }

                iProcess.SaveBill(head, details);
                DS_ApplyHead applyHead = (DS_ApplyHead)NewObject <DS_ApplyHead>().getmodel(head.ApplyHeadId);
                applyHead.OutStoreHeadID = head.OutStoreHeadID;
                applyHead.AuditFlag      = 1;
                applyHead.AuditEmpID     = LoginUserInfo.EmpId;
                applyHead.AuditEmpName   = LoginUserInfo.EmpName;
                applyHead.AuditTime      = DateTime.Now;
                applyHead.save();

                foreach (var s in details)
                {
                    DS_ApplyDetail detailApply = NewObject <DS_ApplyDetail>().getlist <DS_ApplyDetail>("ApplyHeadId = " + applyHead.ApplyHeadID + " and DrugID=" + s.DrugID + " and BatchNO= '" + s.BatchNO + " '").FirstOrDefault();
                    if (detailApply != null)
                    {
                        detailApply.FactAmount = s.Amount;
                        detailApply.save();
                    }
                }

                Basic_SystemConfig config = NewObject <IDGDao>().GetDeptParameters(head.DeptID, "AutoAuditOutStore");
                if (config != null)
                {
                    //是否配置需要审核
                    if (config.Value == "1")
                    {
                        result = iProcess.AuditBill(head.OutStoreHeadID, LoginUserInfo.EmpId, LoginUserInfo.EmpName, LoginUserInfo.WorkId);
                    }
                }

                if (result.Result == 0)
                {
                    oleDb.CommitTransaction();
                }
                else
                {
                    oleDb.RollbackTransaction();
                }

                responseData.AddData(result);
            }
            catch (Exception error)
            {
                oleDb.RollbackTransaction();
                responseData.AddData(false);
                responseData.AddData(error.Message);
            }

            return(responseData);
        }