Example #1
0
        private void btnLoadDataFromMRRB_Click(object sender, EventArgs e)
        {
            if (!CheckData())
            {
                return;
            }

            FormQueryInfo dialog = QueryInfoDialog.GetMaterialRequisitionBillDialog(BasicInfo.LoginID, CE_BillTypeEnum.领料退库单);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string billNo = dialog.GetStringDataItem("退库单号");

                if (MessageDialog.ShowEnquiryMessage("您确定要导入 " + billNo
                                                     + " 领料单的信息吗?此过程需要一段时间,是否继续?") == DialogResult.No)
                {
                    return;
                }

                IMaterialReturnedInTheDepot     billServer  = ServerModuleFactory.GetServerModule <IMaterialReturnedInTheDepot>();
                IMaterialListReturnedInTheDepot goodsServer = ServerModuleFactory.GetServerModule <IMaterialListReturnedInTheDepot>();

                View_S_MaterialReturnedInTheDepot            bill       = billServer.GetBillView(billNo);
                List <View_S_MaterialListReturnedInTheDepot> lstMRGoods = (from r in goodsServer.GetGoods(billNo) select r).ToList();

                if (lstMRGoods.Count > 0)
                {
                    if (是否一次性物品.Checked && GlobalObject.GeneralFunction.IsNullOrEmpty(m_productNumber))
                    {
                        m_productNumber = cmbProductCode.Text;
                    }

                    List <StorageGoods> lstGoods = new List <StorageGoods>(lstMRGoods.Count);

                    foreach (var item in lstMRGoods)
                    {
                        StorageGoods goods = new StorageGoods();

                        goods.GoodsCode = item.图号型号;
                        goods.GoodsName = item.物品名称;
                        goods.Spec      = item.规格;
                        goods.Provider  = item.供应商;
                        goods.BatchNo   = item.批次号;
                        goods.Quantity  = -(decimal)item.退库数;
                        goods.StorageID = bill.库房代码;

                        lstGoods.Add(goods);
                    }

                    if (!m_mbpServer.AddFromBill(BasicInfo.LoginID, Convert.ToInt32(
                                                     cmbPurpose.SelectedValue), m_productNumber, billNo, lstGoods, out m_error))
                    {
                        MessageDialog.ShowErrorMessage(m_error);
                    }
                    else
                    {
                        MessageDialog.ShowPromptMessage("操作成功");

                        SearchData(0);
                    }
                }
            }
        }
        /// <summary>
        /// 完成领料退库单
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="storeManager">仓库管理员</param>
        /// <param name="returnBill">返回更新后重新查询的领料退库单数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功添加领料退库单</returns>
        public bool FinishBill(string billNo, string storeManager, out IQueryResult returnBill, out string error)
        {
            returnBill = null;
            error      = null;

            try
            {
                DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

                if (!FinishFrock(ctx, billNo, out error))
                {
                    return(false);
                }

                //检查总成领用数量是否都设置了流水码
                if (!m_serverProductCode.IsFitCountInReturnBill(billNo, out error))
                {
                    return(false);
                }

                var result = from r in ctx.S_MaterialReturnedInTheDepot where r.Bill_ID == billNo select r;

                if (result.Count() == 0)
                {
                    error = string.Format("没有找到单据号为 {0} 的领料退库单信息,无法进行此操作", billNo);
                    return(false);
                }

                S_MaterialReturnedInTheDepot bill = result.Single();

                if (bill.BillStatus == MaterialReturnedInTheDepotBillStatus.已完成.ToString())
                {
                    error = "单据不能重复退库";
                    return(false);
                }

                bill.DepotManager = storeManager;
                bill.BillStatus   = MaterialReturnedInTheDepotBillStatus.已完成.ToString();
                bill.InDepotDate  = ServerTime.Time;

                if (bill.ReturnMode == "领料退库")
                {
                    DetailCheck(ctx, bill);//在退库模式为领料退库的模式情况下,只能退库房存在的库存记录的物品
                }

                IMaterialListReturnedInTheDepot goodsServer = ServerModuleFactory.GetServerModule <IMaterialListReturnedInTheDepot>();

                //操作账务信息与库存信息
                OpertaionDetailAndStock(ctx, bill);

                //操作总成库存状态
                var varList = from a in ctx.S_MaterialListReturnedInTheDepot
                              where a.Bill_ID == bill.Bill_ID
                              select a;

                foreach (var item in varList)
                {
                    bool blIsRepaired = false;

                    if (bill.StorageID == "05" && Convert.ToBoolean(item.RepairStatus))
                    {
                        blIsRepaired = true;
                    }

                    if (!m_serverProductCode.UpdateProductStock(ctx, bill.Bill_ID, "领料退库", bill.StorageID, blIsRepaired, item.GoodsID, out error))
                    {
                        return(false);
                    }

                    IStoreServer serverStore = ServerModuleFactory.GetServerModule <IStoreServer>();

                    YX_AfterServiceStock lnqAfterService = new YX_AfterServiceStock();

                    lnqAfterService.GoodsID        = item.GoodsID;
                    lnqAfterService.OperationCount = Convert.ToDecimal(item.ReturnedAmount);
                    lnqAfterService.RepairStatus   = Convert.ToBoolean(item.RepairStatus);
                    lnqAfterService.StorageID      = bill.StorageID;

                    if (!serverStore.OperationYXAfterService(ctx, lnqAfterService, out error))
                    {
                        return(false);
                    }
                }

                // 正式使用单据号
                m_assignBill.UseBillNo(ctx, "领料退库单", bill.Bill_ID);

                ctx.SubmitChanges();

                return(GetAllBill(out returnBill, out error));
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }