/// <summary>
        /// 根据单据信息操作账务信息与库存信息
        /// </summary>
        /// <param name="dataContext">数据上下文</param>
        /// <param name="bill">单据信息</param>
        public void OpertaionDetailAndStock(DepotManagementDataContext dataContext, S_MaterialReturnedInTheDepot bill)
        {
            MaterialListReturnedInTheDepot listService  = new MaterialListReturnedInTheDepot();
            IFinancialDetailManagement     serverDetail =
                ServerModule.ServerModuleFactory.GetServerModule <IFinancialDetailManagement>();

            var result = from r in dataContext.S_MaterialListReturnedInTheDepot
                         where r.Bill_ID == bill.Bill_ID
                         select r;

            if (result == null || result.Count() == 0)
            {
                throw new Exception("获取单据信息失败");
            }

            foreach (var item in result)
            {
                S_FetchGoodsDetailBill detailInfo = listService.AssignDetailInfo(dataContext, bill, item);
                S_Stock stockInfo = listService.AssignStockInfo(dataContext, bill, item);

                if (detailInfo == null || stockInfo == null)
                {
                    throw new Exception("获取账务信息或者库存信息失败");
                }

                serverDetail.ProcessFetchGoodsDetail(dataContext, detailInfo, stockInfo);
            }

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

            serviceStore.Operation_MES_InProduction(dataContext, bill.Bill_ID);
        }
        bool BillIsFinish(DepotManagementDataContext ctx, string billNo)
        {
            var vardata = from a in ctx.S_MaterialReturnedInTheDepot
                          where a.Bill_ID == billNo
                          select a;

            if (vardata.Count() == 0)
            {
                return(false);
            }
            else if (vardata.Count() == 1)
            {
                S_MaterialReturnedInTheDepot billInfo = vardata.Single();

                if (billInfo.BillStatus == MaterialReturnedInTheDepotBillStatus.已完成.ToString())
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                throw new Exception("单据不唯一");
            }
        }
        void DetailCheck(DepotManagementDataContext ctx, S_MaterialReturnedInTheDepot billInfo)
        {
            IStoreServer serviceStore = ServerModule.ServerModuleFactory.GetServerModule <IStoreServer>();

            var varData = from a in ctx.S_MaterialListReturnedInTheDepot
                          where a.Bill_ID == billInfo.Bill_ID
                          select a;

            foreach (S_MaterialListReturnedInTheDepot item in varData)
            {
                StoreQueryCondition storeQuery = new StoreQueryCondition();

                storeQuery.BatchNo   = item.BatchNo;
                storeQuery.GoodsID   = item.GoodsID;
                storeQuery.Provider  = item.Provider;
                storeQuery.StorageID = billInfo.StorageID;

                if (serviceStore.GetStockInfoOverLoad(ctx, storeQuery) == null)
                {
                    throw new Exception(UniversalFunction.GetGoodsMessage(item.GoodsID)
                                        + "供应商:【" + item.Provider + "】, 批次号:【" + item.BatchNo + "】, 库房ID:【"
                                        + billInfo.StorageID + "】 无库存记录,无法进行退库");
                }
            }
        }
        /// <summary>
        /// 添加领料退库单
        /// </summary>
        /// <param name="bill">领料退库单信息</param>
        /// <param name="returnBill">返回更新后的领料退库单数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功添加领料退库单</returns>
        public bool AddBill(S_MaterialReturnedInTheDepot bill, out IQueryResult returnBill, out string error)
        {
            returnBill = null;
            error      = null;

            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            try
            {
                if (GlobalObject.GeneralFunction.IsNullOrEmpty(bill.Bill_ID))
                {
                    throw new Exception("【单据号】获取失败,请重新再试");
                }

                ctx.S_MaterialReturnedInTheDepot.InsertOnSubmit(bill);
                ctx.SubmitChanges();

                if (!GetAllBill(out returnBill, out error))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }
Пример #5
0
        private void 修改退库类别ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!CheckSelectedRow())
            {
                return;
            }

            if (!CheckDataItem())
            {
                return;
            }

            if (dataGridView1.SelectedRows[0].Cells["质量工程师签名"].Value.ToString() != BasicInfo.LoginName)
            {
                MessageDialog.ShowPromptMessage("只能修改本人签名的记录");
                return;
            }

            S_MaterialReturnedInTheDepot bill = m_billServer.GetBill(txtBill_ID.Text);

            bill.ReturnType = cmbType.Text;

            if (!m_billServer.UpdateBill(bill, out m_queryResult, out m_error))
            {
                MessageDialog.ShowErrorMessage(m_error);
            }

            RefreshDataGridView(m_queryResult);
            PositioningRecord(bill.Bill_ID);
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="operateMode">操作模式</param>
        /// <param name="billNo">领料退库单号</param>
        public FormMaterialListReturnedInTheDepot(CE_BusinessOperateMode operateMode, string billNo)
        {
            InitializeComponent();

            S_MaterialReturnedInTheDepot tempBill = m_serverBill.GetBill(billNo);

            m_lnqWSCode = tempBill == null?
                          m_serverWSBasic.GetPersonnelWorkShop(BasicInfo.LoginID) :
                              m_serverWSBasic.GetPersonnelWorkShop(tempBill.FillInPersonnelCode);

            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw |
                     ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true);
            UpdateStyles();

            m_operateMode = operateMode;
            m_billNo      = billNo;

            if (m_operateMode == CE_BusinessOperateMode.查看)
            {
                toolStrip1.Visible = false;
            }
            else if (m_operateMode == CE_BusinessOperateMode.仓库核实)
            {
                btnAdd.Enabled       = false;
                btnDelete.Enabled    = false;
                btnDeleteAll.Enabled = false;

                txtShelf.ReadOnly  = false;
                txtColumn.ReadOnly = false;
                txtLayer.ReadOnly  = false;
            }

            m_queryGoodsInfo = m_goodsServer.GetGoods(m_billNo);
            RefreshDataGridView(m_queryGoodsInfo);

            // 添加数据定位控件
            m_dataLocalizer = new UserControlDataLocalizer(
                dataGridView1, this.Name, UniversalFunction.SelectHideFields(
                    this.Name, dataGridView1.Name, BasicInfo.LoginID));

            panelTop.Controls.Add(m_dataLocalizer);
            m_dataLocalizer.Dock = DockStyle.Bottom;

            m_strStorage = m_serverStorageInfo.GetStorageID(billNo, "S_MaterialReturnedInTheDepot", "Bill_ID");

            if (m_strStorage == "05")
            {
                label11.Visible          = true;
                cmbProductStatus.Visible = true;
            }

            if (!Convert.ToBoolean(BasicInfo.BaseSwitchInfo[(int)GlobalObject.CE_SwitchName.开启车间管理模块]) || m_strStorage == "11")
            {
                btnProvider.Visible = false;
                btnBatchNo.Visible  = false;
            }
        }
        /// <summary>
        /// 赋值库存信息
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="bill">单据信息</param>
        /// <param name="goodsItem">明细信息</param>
        /// <returns>返回库存信息对象</returns>
        public S_Stock AssignStockInfo(DepotManagementDataContext context, S_MaterialReturnedInTheDepot bill,
                                       S_MaterialListReturnedInTheDepot goodsItem)
        {
            if (goodsItem.ShelfArea == null || goodsItem.ColumnNumber == null || goodsItem.LayerNumber == null)
            {
                throw new Exception("仓库货架、层、列等信息不能为空,请修改后重新提交");
            }

            bool blIsOnlyForRepair = false;

            var resultbill = from a in context.S_MaterialReturnedInTheDepot
                             where a.Bill_ID == bill.Bill_ID
                             select a;

            if (resultbill.Count() != 1)
            {
                throw new Exception("数据不唯一或者为空");
            }
            else
            {
                blIsOnlyForRepair = resultbill.Single().IsOnlyForRepair.ToString() == ""
                    ? false : Convert.ToBoolean(resultbill.Single().IsOnlyForRepair);
            }

            S_Stock stock = new S_Stock();

            // 添加信息到库存
            IStoreServer storeServer = ServerModuleFactory.GetServerModule <IStoreServer>();

            stock.GoodsID         = goodsItem.GoodsID;
            stock.Provider        = goodsItem.Provider;
            stock.ProviderBatchNo = goodsItem.ProviderBatchNo;
            stock.BatchNo         = goodsItem.BatchNo;
            stock.ShelfArea       = goodsItem.ShelfArea;
            stock.ColumnNumber    = goodsItem.ColumnNumber;
            stock.LayerNumber     = goodsItem.LayerNumber;
            stock.ExistCount      = (decimal)goodsItem.ReturnedAmount;
            stock.Date            = ServerModule.ServerTime.Time;
            stock.StorageID       = bill.StorageID;

            if (blIsOnlyForRepair)
            {
                stock.GoodsStatus = 6;
            }

            return(stock);
        }
Пример #8
0
        private void 修改单据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!CheckSelectedRow())
            {
                return;
            }

            if (lblBillStatus.Text != MaterialReturnedInTheDepotBillStatus.新建单据.ToString())
            {
                MessageDialog.ShowPromptMessage("您现在不是处于新建单据状态,无法进行此操作");
                return;
            }

            if (!CheckUserOperation(dataGridView1.SelectedRows[0]))
            {
                return;
            }

            if (!CheckDataItem())
            {
                return;
            }

            BASE_MaterialRequisitionPurpose purpose = txtPurpose.Tag as BASE_MaterialRequisitionPurpose;

            S_MaterialReturnedInTheDepot bill = new S_MaterialReturnedInTheDepot();

            bill.Bill_ID     = txtBill_ID.Text;
            bill.ReturnType  = cmbType.Text;
            bill.Bill_Time   = ServerModule.ServerTime.Time;
            bill.PurposeCode = purpose == null?txtPurpose.Tag.ToString() : purpose.Code;

            bill.ReturnReason    = txtReturnedReason.Text;
            bill.Remark          = txtRemark.Text;
            bill.ReturnMode      = cmbMode.Text;
            bill.IsOnlyForRepair = chkIsOnlyForRepair.Checked;
            bill.StorageID       = UniversalFunction.GetStorageID(cmbStorage.Text);

            if (!m_billServer.UpdateBill(bill, out m_queryResult, out m_error))
            {
                MessageDialog.ShowErrorMessage(m_error);
                return;
            }

            RefreshDataGridView(m_queryResult);
            PositioningRecord(bill.Bill_ID);
        }
        /// <summary>
        /// 修改领料退库单(只修改编制人涉及信息)
        /// </summary>
        /// <param name="bill">领料退库单信息</param>
        /// <param name="returnBill">返回更新后的领料退库单数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功添加领料退库单</returns>
        public bool UpdateBill(S_MaterialReturnedInTheDepot bill, out IQueryResult returnBill, out string error)
        {
            returnBill = null;
            error      = null;

            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            try
            {
                var result = from r in ctx.S_MaterialReturnedInTheDepot where r.Bill_ID == bill.Bill_ID select r;

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

                S_MaterialReturnedInTheDepot updateBill = result.Single();

                updateBill.Bill_Time       = ServerModule.ServerTime.Time;
                updateBill.PurposeCode     = bill.PurposeCode;
                updateBill.ReturnReason    = bill.ReturnReason;
                updateBill.ReturnType      = bill.ReturnType;
                updateBill.Remark          = bill.Remark;
                updateBill.IsOnlyForRepair = bill.IsOnlyForRepair;
                updateBill.ReturnMode      = bill.ReturnMode;
                updateBill.StorageID       = bill.StorageID;

                ctx.SubmitChanges();

                if (!GetAllBill(out returnBill, out error))
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }
Пример #10
0
        /// <summary>
        /// 生成领料退库单
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="billNo">单据号</param>
        void InsertReturnBill(DepotManagementDataContext context, string billNo)
        {
            IMaterialReturnedInTheDepot serverReturnedBill =
                ServerModule.ServerModuleFactory.GetServerModule <IMaterialReturnedInTheDepot>();


            var varList = from a in context.S_ScrapGoods
                          where a.Bill_ID == billNo &&
                          a.ResponsibilityProvider == a.Provider
                          select a;

            if (varList.Count() == 0)
            {
                return;
            }

            var varData = from a in context.S_ScrapBill
                          where a.Bill_ID == billNo
                          select a;

            if (varData.Count() == 0)
            {
                return;
            }

            S_ScrapBill bill = varData.Single();

            //操作主表
            S_MaterialReturnedInTheDepot returnBill = new S_MaterialReturnedInTheDepot();

            var data1 = from a in context.BASE_MaterialRequisitionPurpose
                        where a.Purpose == bill.ProductType &&
                        a.Code.Substring(0, 1) == "F"
                        select a;

            returnBill.Bill_ID             = m_assignBill.AssignNewNo(context, serverReturnedBill, CE_BillTypeEnum.领料退库单.ToString());
            returnBill.Bill_Time           = ServerTime.Time;
            returnBill.BillStatus          = MaterialReturnedInTheDepotBillStatus.已完成.ToString();
            returnBill.Department          = bill.DeclareDepartment;
            returnBill.ReturnType          = "其他退库";//退库类别
            returnBill.FillInPersonnel     = bill.FillInPersonnel;
            returnBill.FillInPersonnelCode = bill.FillInPersonnelCode;
            returnBill.DepartmentDirector  = bill.DepartmentDirector;
            returnBill.QualityInputer      = "";
            returnBill.DepotManager        = BasicInfo.LoginName;
            returnBill.PurposeCode         = data1.First().Code;
            returnBill.ReturnReason        = "由【报废单】:" + billNo + " 生成的报废退库";
            returnBill.Remark          = "系统自动生成";
            returnBill.StorageID       = "01";
            returnBill.ReturnMode      = "领料退库";//退库方式
            returnBill.IsOnlyForRepair = false;
            returnBill.InDepotDate     = ServerTime.Time;

            context.S_MaterialReturnedInTheDepot.InsertOnSubmit(returnBill);
            context.SubmitChanges();

            foreach (S_ScrapGoods goodsInfo in varList)
            {
                View_F_GoodsPlanCost goodsView = UniversalFunction.GetGoodsInfo(context, goodsInfo.GoodsID);

                QueryCondition_Store queryInfo = new QueryCondition_Store();

                queryInfo.BatchNo   = goodsInfo.BatchNo;
                queryInfo.GoodsID   = goodsInfo.GoodsID;
                queryInfo.StorageID = "01";

                S_Stock stockInfo = UniversalFunction.GetStockInfo(context, queryInfo);

                S_MaterialListReturnedInTheDepot detailInfo = new S_MaterialListReturnedInTheDepot();

                detailInfo.BatchNo         = goodsInfo.BatchNo;
                detailInfo.Bill_ID         = returnBill.Bill_ID;
                detailInfo.GoodsID         = goodsInfo.GoodsID;
                detailInfo.Provider        = goodsInfo.Provider;
                detailInfo.ReturnedAmount  = goodsInfo.Quantity;
                detailInfo.Depot           = goodsView.物品类别;
                detailInfo.ColumnNumber    = stockInfo == null ? "" : stockInfo.ColumnNumber;
                detailInfo.LayerNumber     = stockInfo == null ? "" : stockInfo.LayerNumber;
                detailInfo.ShelfArea       = stockInfo == null ? "" : stockInfo.ShelfArea;
                detailInfo.ProviderBatchNo = stockInfo == null ? "" : stockInfo.ProviderBatchNo;
                detailInfo.Remark          = "";

                context.S_MaterialListReturnedInTheDepot.InsertOnSubmit(detailInfo);
                context.SubmitChanges();
            }

            serverReturnedBill.OpertaionDetailAndStock(context, returnBill);
            context.SubmitChanges();
        }
Пример #11
0
        /// <summary>
        /// 插入领料退库表
        /// </summary>
        /// <param name="dataContxt">数据上下文</param>
        /// <param name="billList">扣货子表</param>
        /// <param name="billTable">扣货主表</param>
        /// <param name="billNo">单据号</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>操作成功返回True,操作失败返回False</returns>
        bool InsertMaterialReturnedInTheDepot(DepotManagementDataContext dataContxt, DataTable billList,
                                              DataTable billTable, string billNo, out string error)
        {
            error = null;

            try
            {
                MaterialReturnedInTheDepot serverReturnedBill = new MaterialReturnedInTheDepot();
                string strLLBillNo = m_assignBill.AssignNewNo(serverReturnedBill, "领料退库单");
                string storageID   = UniversalFunction.GetStorageID(billList.Rows[0]["库房名称"].ToString());

                //插入主表信息
                S_MaterialReturnedInTheDepot depotBill = new S_MaterialReturnedInTheDepot();

                depotBill.Bill_ID             = strLLBillNo;
                depotBill.Bill_Time           = ServerTime.Time;
                depotBill.BillStatus          = MaterialReturnedInTheDepotBillStatus.已完成.ToString();
                depotBill.Department          = billList.Rows[0]["部门编码"].ToString();
                depotBill.ReturnType          = "机加退库";//退库类别
                depotBill.FillInPersonnel     = billList.Rows[0]["建单人"].ToString();
                depotBill.FillInPersonnelCode = billList.Rows[0]["建单人编号"].ToString();
                depotBill.DepartmentDirector  = billList.Rows[0]["审核人"].ToString();
                depotBill.QualityInputer      = billList.Rows[0]["质管批准"].ToString();
                depotBill.DepotManager        = billList.Rows[0]["采购确认人"].ToString();

                throw new Exception("用途不明,无法使用此单据");
                //depotBill.PurposeCode = "30";//用途

                //depotBill.ReturnReason = billList.Rows[0]["扣货原因"].ToString();
                //depotBill.Remark = billList.Rows[0]["备注"].ToString() + "(根据物料扣货单【" + billNo + "】系统自动生成)";
                //depotBill.StorageID = storageID;
                //depotBill.ReturnMode = "领料退库";//退库方式
                //depotBill.IsOnlyForRepair = false;
                //depotBill.InDepotDate = ServerTime.Time;

                //dataContxt.S_MaterialReturnedInTheDepot.InsertOnSubmit(depotBill);

                //View_Department department = ServerModuleFactory.GetServerModule<IDepartmentServer>().GetDepartments(depotBill.Department);

                //for (int i = 0; i < billTable.Rows.Count; i++)
                //{
                //    #region 领料退库明细
                //    //插入业务明细
                //    S_MaterialListReturnedInTheDepot lnqDepotList = new S_MaterialListReturnedInTheDepot();

                //    lnqDepotList.Bill_ID = strLLBillNo;
                //    lnqDepotList.GoodsID = Convert.ToInt32(billTable.Rows[i]["物品ID"].ToString());
                //    lnqDepotList.Provider = billTable.Rows[i]["供应商"].ToString();
                //    lnqDepotList.ProviderBatchNo = "";
                //    lnqDepotList.BatchNo = billTable.Rows[i]["批次号"].ToString();
                //    lnqDepotList.ReturnedAmount = Convert.ToDecimal(billTable.Rows[i]["扣货数"].ToString());
                //    lnqDepotList.Remark = billTable.Rows[i]["备注"].ToString();

                //    DataRow dtTemp = GetShelfArea(Convert.ToInt32(billTable.Rows[i]["物品ID"].ToString()),
                //        billTable.Rows[i]["批次号"].ToString(), out error);

                //    lnqDepotList.ShelfArea = dtTemp == null ? "" : dtTemp["货架"].ToString();//货架
                //    lnqDepotList.ColumnNumber = dtTemp == null ? "" : dtTemp["列"].ToString();//列
                //    lnqDepotList.LayerNumber = dtTemp == null ? "" : dtTemp["层"].ToString();//层
                //    lnqDepotList.Depot = dtTemp == null ? "" : dtTemp["材料类别编码"].ToString();

                //    dataContxt.S_MaterialListReturnedInTheDepot.InsertOnSubmit(lnqDepotList);
                //    #endregion
                //}

                //serverReturnedBill.OpertaionDetailAndStock(dataContxt, depotBill);
                //return true;
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Пример #12
0
        /// <summary>
        /// 自动生成领料退库单
        /// </summary>
        /// <param name="contxt">数据上下文</param>
        /// <param name="djh">单据号</param>
        void CreateMaterialReturnedInTheDepot(DepotManagementDataContext contxt, string djh)
        {
            MaterialReturnedInTheDepot serverReturnedBill = new MaterialReturnedInTheDepot();

            try
            {
                string strBillID = m_assignBill.AssignNewNo(serverReturnedBill, CE_BillTypeEnum.领料退库单.ToString());

                S_StorageCheck billInfo = GetBill(contxt, djh);
                List <View_S_StorageCheckList> listInfo = (from a in GetList(contxt, djh) where a.盈亏数量 > 0 select a).ToList();
                S_MaterialReturnedInTheDepot   lnqReturnedInTheDepot = new S_MaterialReturnedInTheDepot();

                if (listInfo.Count > 0)
                {
                    #region 领料退库单主表
                    lnqReturnedInTheDepot.Bill_ID             = strBillID;
                    lnqReturnedInTheDepot.Bill_Time           = ServerTime.Time;
                    lnqReturnedInTheDepot.BillStatus          = "已完成";
                    lnqReturnedInTheDepot.Department          = "ZZ05";
                    lnqReturnedInTheDepot.DepartmentDirector  = UniversalFunction.GetPersonnelInfo(contxt, billInfo.SHRY).姓名;
                    lnqReturnedInTheDepot.DepotManager        = BasicInfo.LoginName;
                    lnqReturnedInTheDepot.FillInPersonnel     = UniversalFunction.GetPersonnelInfo(contxt, billInfo.BZRY).姓名;
                    lnqReturnedInTheDepot.FillInPersonnelCode = billInfo.BZRY;
                    lnqReturnedInTheDepot.InDepotDate         = ServerTime.Time;
                    lnqReturnedInTheDepot.PurposeCode         = UniversalFunction.GetPurpose(CE_PickingPurposeProperty.盘点).Code;
                    lnqReturnedInTheDepot.QualityInputer      = "";
                    lnqReturnedInTheDepot.Remark       = "库房盘点(盘盈)";
                    lnqReturnedInTheDepot.ReturnMode   = "领料退库";
                    lnqReturnedInTheDepot.ReturnReason = "库房盘点(盘盈)";
                    lnqReturnedInTheDepot.ReturnType   = null;
                    lnqReturnedInTheDepot.StorageID    = billInfo.StorageID;

                    contxt.S_MaterialReturnedInTheDepot.InsertOnSubmit(lnqReturnedInTheDepot);

                    #endregion

                    foreach (View_S_StorageCheckList listSingle in listInfo)
                    {
                        #region 领料单退库明细
                        S_MaterialListReturnedInTheDepot lnqReturnedInTheDepotList = new S_MaterialListReturnedInTheDepot();

                        lnqReturnedInTheDepotList.BatchNo         = listSingle.批次号;
                        lnqReturnedInTheDepotList.Bill_ID         = strBillID;
                        lnqReturnedInTheDepotList.ColumnNumber    = listSingle.列;
                        lnqReturnedInTheDepotList.GoodsID         = (int)listSingle.物品ID;
                        lnqReturnedInTheDepotList.LayerNumber     = listSingle.层;
                        lnqReturnedInTheDepotList.Provider        = listSingle.供货单位;
                        lnqReturnedInTheDepotList.ProviderBatchNo = listSingle.供方批次号;
                        lnqReturnedInTheDepotList.Remark          = "库房盘点(盘亏)";
                        lnqReturnedInTheDepotList.ReturnedAmount  = (decimal)listSingle.盈亏数量;
                        lnqReturnedInTheDepotList.ShelfArea       = listSingle.货架;

                        contxt.S_MaterialListReturnedInTheDepot.InsertOnSubmit(lnqReturnedInTheDepotList);

                        #endregion
                    }

                    contxt.SubmitChanges();

                    serverReturnedBill.OpertaionDetailAndStock(contxt, lnqReturnedInTheDepot);
                    contxt.SubmitChanges();

                    m_assignBill.UseBillNo(CE_BillTypeEnum.领料退库单.ToString(), strBillID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        /// <summary>
        /// 赋值账务信息
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="bill">单据信息</param>
        /// <param name="item">明细信息</param>
        /// <returns>返回账务信息对象</returns>
        public S_FetchGoodsDetailBill AssignDetailInfo(DepotManagementDataContext context, S_MaterialReturnedInTheDepot bill,
                                                       S_MaterialListReturnedInTheDepot item)
        {
            IBillTypeServer server   = ServerModuleFactory.GetServerModule <IBillTypeServer>();
            BASE_BillType   billType = server.GetBillTypeFromName("领料退库单");

            if (billType == null)
            {
                throw new Exception("获取不到单据类型信息");
            }

            View_Department department = UniversalFunction.GetDeptInfo(context, bill.Department);

            //单价设置
            decimal dcStockUnitPrice = m_serverStore.GetGoodsUnitPrice(context, item.GoodsID, item.BatchNo, bill.StorageID);

            //S_FetchGoodsDetailBill用于存放每次领料、领料退库的明细信息
            S_FetchGoodsDetailBill detailBill = new S_FetchGoodsDetailBill();

            detailBill.ID               = Guid.NewGuid();
            detailBill.FetchBIllID      = bill.Bill_ID;
            detailBill.BillTime         = ServerTime.Time;
            detailBill.FetchCount       = -item.ReturnedAmount;
            detailBill.GoodsID          = item.GoodsID;
            detailBill.BatchNo          = item.BatchNo;
            detailBill.ProviderBatchNo  = item.ProviderBatchNo;
            detailBill.Provider         = item.Provider;
            detailBill.Price            = -dcStockUnitPrice * (decimal)item.ReturnedAmount;
            detailBill.UnitPrice        = dcStockUnitPrice;
            detailBill.Department       = department.部门名称;
            detailBill.FillInPersonnel  = bill.FillInPersonnel;
            detailBill.FinanceSignatory = null;
            detailBill.DepartDirector   = bill.DepartmentDirector;
            detailBill.DepotManager     = bill.DepotManager;
            detailBill.OperationType    = (int)CE_SubsidiaryOperationType.领料退库;
            detailBill.StorageID        = bill.StorageID;
            detailBill.Remark           = "退库原因:" + bill.ReturnReason + ";备注:" + item.Remark;
            detailBill.FillInDate       = bill.Bill_Time;

            IMaterialRequisitionPurposeServer purposeServer =
                ServerModuleFactory.GetServerModule <IMaterialRequisitionPurposeServer>();

            detailBill.Using = string.Format("领料退库,初始用途:{0}", purposeServer.GetBillPurpose(context, bill.PurposeCode).Purpose);

            return(detailBill);
        }
        /// <summary>
        /// 回退单据
        /// </summary>
        /// <param name="djh">单据号</param>
        /// <param name="billStatus">单据状态</param>
        /// <param name="returnBill">返回回退更新后查询的数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <param name="rebackReason">回退原因</param>
        /// <returns>回退成功返回True,回退失败返回False</returns>
        public bool ReturnBill(string djh, string billStatus,
                               out IQueryResult returnBill, out string error, string rebackReason)
        {
            returnBill = null;
            error      = null;

            try
            {
                DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

                var varData = from a in ctx.S_MaterialReturnedInTheDepot
                              where a.Bill_ID == djh
                              select a;

                string strMsg = "";

                if (varData.Count() == 1)
                {
                    S_MaterialReturnedInTheDepot lnqMRe = varData.Single();

                    switch (billStatus)
                    {
                    case "新建单据":

                        strMsg = string.Format("{0}号领料退库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg, lnqMRe.FillInPersonnelCode, false);

                        lnqMRe.BillStatus         = "新建单据";
                        lnqMRe.DepartmentDirector = null;
                        lnqMRe.QualityInputer     = null;
                        break;

                    case "等待主管审核":

                        strMsg = string.Format("{0}号领料退库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqMRe.DepartmentDirector), false);

                        lnqMRe.BillStatus         = "等待主管审核";
                        lnqMRe.DepartmentDirector = null;
                        lnqMRe.QualityInputer     = null;
                        break;

                    case "等待质检批准":

                        strMsg = string.Format("{0}号领料退库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqMRe.QualityInputer), false);

                        lnqMRe.BillStatus     = "等待质检批准";
                        lnqMRe.QualityInputer = null;
                        break;

                    default:
                        break;
                    }

                    ctx.SubmitChanges();
                }
                else
                {
                    error = "数据不唯一或者此数据已经被删除";
                    return(false);
                }

                return(GetAllBill(out returnBill, out error));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
        /// <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);
            }
        }
Пример #16
0
        private void 设置退库清单ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string billNo = txtBill_ID.Text;

            try
            {
                this.dataGridView1.CellEnter -= new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter);

                if (lblBillStatus.Text == MaterialReturnedInTheDepotBillStatus.已完成.ToString())
                {
                    MessageDialog.ShowPromptMessage("您现在不是处于新建单据状态,无法进行此操作");
                    return;
                }

                if (!CheckDataItem())
                {
                    return;
                }

                if (chkIsOnlyForRepair.Enabled && !chkIsOnlyForRepair.Checked)
                {
                    if (MessageDialog.ShowEnquiryMessage("此单未勾选仅限于返修箱用,是否继续?") == DialogResult.No)
                    {
                        return;
                    }
                }

                // 如果此单据存在则检查选择行
                if (m_billServer.IsExist(txtBill_ID.Text))
                {
                    if (!CheckSelectedRow())
                    {
                        return;
                    }

                    if (!CheckUserOperation(dataGridView1.SelectedRows[0]))
                    {
                        return;
                    }
                }
                else
                {
                    BASE_MaterialRequisitionPurpose purpose = txtPurpose.Tag as BASE_MaterialRequisitionPurpose;

                    // 如果此单据还不存在则创建
                    S_MaterialReturnedInTheDepot bill = new S_MaterialReturnedInTheDepot();

                    bill.Bill_ID             = txtBill_ID.Text;
                    bill.Bill_Time           = ServerModule.ServerTime.Time;
                    bill.BillStatus          = MaterialReturnedInTheDepotBillStatus.新建单据.ToString();
                    bill.Department          = BasicInfo.DeptCode;
                    bill.ReturnType          = cmbType.Text;
                    bill.FillInPersonnel     = BasicInfo.LoginName;
                    bill.FillInPersonnelCode = BasicInfo.LoginID;
                    bill.PurposeCode         = purpose.Code;
                    bill.ReturnReason        = txtReturnedReason.Text;
                    bill.Remark          = txtRemark.Text;
                    bill.StorageID       = UniversalFunction.GetStorageID(cmbStorage.Text);
                    bill.ReturnMode      = cmbMode.Text.Trim();
                    bill.IsOnlyForRepair = chkIsOnlyForRepair.Checked;

                    if (!m_billServer.AddBill(bill, out m_queryResult, out m_error))
                    {
                        MessageDialog.ShowErrorMessage(m_error);
                        return;
                    }
                }

                FormMaterialListReturnedInTheDepot form =
                    new FormMaterialListReturnedInTheDepot(CE_BusinessOperateMode.修改, txtBill_ID.Text);

                form.StrReturnMode     = cmbMode.Text.Trim();
                form.BlIsOnlyForRepair = chkIsOnlyForRepair.Checked;
                form.ShowDialog();
            }
            finally
            {
                this.dataGridView1.CellEnter += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEnter);
            }

            RefreshDataGridView(m_queryResult);
            PositioningRecord(billNo);
        }