Exemplo n.º 1
0
        /// <summary>
        /// 赋值库存信息
        /// </summary>
        /// <param name="ctx">数据上下文</param>
        /// <param name="outSourcing">单据信息</param>
        /// <returns>返回库存信息对象</returns>
        S_Stock AssignStockInfo(DepotManagementDataContext ctx, S_CheckOutInDepotForOutsourcingBill outSourcing)
        {
            View_F_GoodsPlanCost tempGoodsLnq = UniversalFunction.GetGoodsInfo(ctx, outSourcing.GoodsID);

            if (tempGoodsLnq == null)
            {
                throw new Exception("无此物品信息");
            }

            S_Stock stock = new S_Stock();

            stock.GoodsID         = outSourcing.GoodsID;
            stock.GoodsCode       = tempGoodsLnq.图号型号;
            stock.GoodsName       = tempGoodsLnq.物品名称;
            stock.Unit            = tempGoodsLnq.单位;
            stock.Spec            = tempGoodsLnq.规格;
            stock.Provider        = outSourcing.Provider;
            stock.ProviderBatchNo = outSourcing.ProviderBatchNo;
            stock.BatchNo         = outSourcing.BatchNo;
            stock.ShelfArea       = outSourcing.ShelfArea;
            stock.ColumnNumber    = outSourcing.ColumnNumber;
            stock.LayerNumber     = outSourcing.LayerNumber;
            stock.ExistCount      = outSourcing.InDepotCount;
            stock.Date            = ServerModule.ServerTime.Time;
            stock.UnitPrice       = outSourcing.UnitPrice;
            stock.StorageID       = outSourcing.StorageID;
            stock.Version         = outSourcing.Version;
            stock.GoodsStatus     = outSourcing.IsOnlyForRepairFlag == true ? 6 : 0;

            return(stock);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 赋值账务信息
        /// </summary>
        /// <param name="ctx">数据上下文</param>
        /// <param name="outSourcing">单据信息</param>
        /// <returns>返回账务信息</returns>
        S_InDepotDetailBill AssignDetailInfo(DepotManagementDataContext ctx, S_CheckOutInDepotForOutsourcingBill outSourcing)
        {
            S_InDepotDetailBill detailBill = new S_InDepotDetailBill();
            var varData = from a in ctx.S_InDepotDetailBill
                          where a.InDepotBillID == outSourcing.Bill_ID
                          select a;

            if (varData.Count() != 0)
            {
                throw new Exception("数据不唯一");
            }
            else
            {
                IBillTypeServer server   = ServerModuleFactory.GetServerModule <IBillTypeServer>();
                BASE_BillType   billType = server.GetBillTypeFromName("委外报检入库单");

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

                detailBill.ID              = Guid.NewGuid();
                detailBill.BillTime        = ServerTime.Time;
                detailBill.FillInPersonnel = outSourcing.DeclarePersonnel;
                detailBill.Department      = UniversalFunction.GetPersonnelInfo(ctx, outSourcing.DeclarePersonnel).部门名称;
                detailBill.FactPrice       = Math.Round(outSourcing.UnitPrice * outSourcing.InDepotCount, 2);
                detailBill.FactUnitPrice   = outSourcing.UnitPrice;
                detailBill.GoodsID         = outSourcing.GoodsID;
                detailBill.BatchNo         = outSourcing.BatchNo;
                detailBill.InDepotBillID   = outSourcing.Bill_ID;
                detailBill.InDepotCount    = outSourcing.InDepotCount;
                detailBill.Price           = Math.Round(outSourcing.UnitPrice * outSourcing.InDepotCount, 2);
                detailBill.UnitPrice       = outSourcing.UnitPrice;
                detailBill.OperationType   = (int)CE_SubsidiaryOperationType.委外报检入库;
                detailBill.Provider        = outSourcing.Provider;
                detailBill.StorageID       = outSourcing.StorageID;
                detailBill.AffrimPersonnel = outSourcing.ManagerPersonnel;
                detailBill.FillInDate      = outSourcing.DeclareTime;
            }

            return(detailBill);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据单据信息操作账务信息与库存信息
        /// </summary>
        /// <param name="dataContext">数据上下文</param>
        /// <param name="bill">单据信息</param>
        public void OpertaionDetailAndStock(DepotManagementDataContext dataContext, S_CheckOutInDepotForOutsourcingBill bill)
        {
            IFinancialDetailManagement serverDetail =
                ServerModule.ServerModuleFactory.GetServerModule <IFinancialDetailManagement>();

            S_InDepotDetailBill detailInfo = AssignDetailInfo(dataContext, bill);
            S_Stock             stockInfo  = AssignStockInfo(dataContext, bill);

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

            if (bill.DeclareCount < bill.InDepotCount)
            {
                throw new Exception("入库数不能大于报检数");
            }

            serverDetail.ProcessInDepotDetail(dataContext, detailInfo, stockInfo);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 变更金额_委外报检入库单
        /// </summary>
        /// <param name="dataContxt">数据上下文</param>
        /// <param name="detailInfo">结算单明细</param>
        void ChangePrice_S_CheckOutInDepotForOutsourcingBill(DepotManagementDataContext dataContxt,
                                                             View_Business_Settlement_ProcurementStatementDetail detailInfo)
        {
            var varOutsourcing = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill
                                 where a.Bill_ID == detailInfo.入库单号 &&
                                 a.GoodsID == detailInfo.物品ID &&
                                 a.BatchNo == detailInfo.批次号
                                 select a;

            //委外报检入库单单价修改
            if (varOutsourcing.Count() != 0)
            {
                S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varOutsourcing.Single();

                lnqOutsourcing.UnitInvoicePrice = detailInfo.发票单价 + (decimal)detailInfo.单件委托材料;
                lnqOutsourcing.InvoicePrice     = lnqOutsourcing.UnitInvoicePrice * detailInfo.入库数量;

                lnqOutsourcing.HavingInvoice = true;
                dataContxt.SubmitChanges();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新出入库的金额
        /// </summary>
        /// <param name="invoiceTable">需要更新的数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>更新成功True,更新失败False</returns>
        public bool UpdatePrice(DataTable invoiceTable, out string error)
        {
            error = null;

            try
            {
                DepotManagementDataContext dataContxt               = CommentParameter.DepotDataContext;
                OrdinaryInDepotBillServer  serverOrdinaryBill       = new OrdinaryInDepotBillServer();
                MaterialRejectBill         serverMaterialRejectBill = new MaterialRejectBill();
                DateTime dtStart = new DateTime();
                DateTime dtEnd   = new DateTime();

                //获得当前日期的月结起始日期与结束日期
                ServerTime.GetMonthlyBalance(ServerTime.Time, out dtStart, out dtEnd);

                for (int i = 0; i <= invoiceTable.Rows.Count - 1; i++)
                {
                    string code = invoiceTable.Rows[i]["GoodsCode"].ToString();
                    string name = invoiceTable.Rows[i]["GoodsName"].ToString();
                    string spec = invoiceTable.Rows[i]["Spec"].ToString();

                    View_F_GoodsPlanCost basicGoods = m_basicGoodsServer.GetGoodsInfo(code, name, spec, out error);

                    if (!GlobalObject.GeneralFunction.IsNullOrEmpty(error))
                    {
                        return(false);
                    }

                    #region 改变入库表的单价(普通入库或者报检入库)

                    var varCheckOutInDepot = from a in dataContxt.S_CheckOutInDepotBill
                                             where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() &&
                                             a.GoodsID == basicGoods.序号 &&
                                             a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString()
                                             select a;

                    //报检入库单单价修改
                    if (varCheckOutInDepot.Count() != 0)
                    {
                        S_CheckOutInDepotBill lnqCheckOutInDepotBill = varCheckOutInDepot.Single();

                        lnqCheckOutInDepotBill.UnitInvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                        lnqCheckOutInDepotBill.InvoicePrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);

                        lnqCheckOutInDepotBill.HavingInvoice = true;
                        dataContxt.SubmitChanges();
                    }
                    else
                    {
                        int intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(),
                                                                       invoiceTable.Rows[i]["GoodsName"].ToString(),
                                                                       invoiceTable.Rows[i]["Spec"].ToString());

                        var varOrdinaryGoods = from a in dataContxt.S_OrdinaryInDepotGoodsBill
                                               where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() &&
                                               a.GoodsID == intGoodsID &&
                                               a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString()
                                               select a;

                        //普通入库单单价修改
                        if (varOrdinaryGoods.Count() != 0)
                        {
                            S_OrdinaryInDepotGoodsBill lnqOrdinaryGoods = varOrdinaryGoods.Single();

                            lnqOrdinaryGoods.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                            lnqOrdinaryGoods.InvoicePrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);

                            lnqOrdinaryGoods.HavingInvoice = true;
                            dataContxt.SubmitChanges();

                            int intFlag = serverOrdinaryBill.GetHavingInvoice(invoiceTable.Rows[i]["Bill_ID"].ToString(), out error);

                            if (intFlag == 4)
                            {
                                return(false);
                            }
                            else
                            {
                                var varOrdinaryBill = from a in dataContxt.S_OrdinaryInDepotBill
                                                      where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString()
                                                      select a;

                                if (varOrdinaryBill.Count() != 0)
                                {
                                    S_OrdinaryInDepotBill lnqOrdinaryBill = varOrdinaryBill.Single();

                                    lnqOrdinaryBill.InvoiceStatus = intFlag;
                                    dataContxt.SubmitChanges();
                                }
                            }
                        }//采购退货单单价修改
                        else
                        {
                            intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(),
                                                                       invoiceTable.Rows[i]["GoodsName"].ToString(),
                                                                       invoiceTable.Rows[i]["Spec"].ToString());

                            var varRejectList = from a in dataContxt.S_MaterialListRejectBill
                                                where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() &&
                                                a.GoodsID == intGoodsID &&
                                                a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString()
                                                select a;

                            if (varRejectList.Count() != 0)
                            {
                                S_MaterialListRejectBill lnqMaterialList = varRejectList.Single();

                                lnqMaterialList.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                                lnqMaterialList.InvoicePrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);

                                lnqMaterialList.HavingInvoice = true;
                                dataContxt.SubmitChanges();

                                int intFlag = serverMaterialRejectBill.SetHavingInvoiceReturn(invoiceTable.Rows[i]["Bill_ID"].ToString(), out error);

                                if (intFlag == 4)
                                {
                                    return(false);
                                }
                                else
                                {
                                    var varReject = from a in dataContxt.S_MaterialRejectBill
                                                    where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString()
                                                    select a;

                                    if (varReject.Count() != 0)
                                    {
                                        S_MaterialRejectBill lnqMaterialBill = varReject.Single();

                                        lnqMaterialBill.InvoiceFlag = intFlag;
                                        dataContxt.SubmitChanges();
                                    }
                                }
                            }
                            else
                            {
                                intGoodsID = m_basicGoodsServer.GetGoodsID(invoiceTable.Rows[i]["GoodsCode"].ToString(),
                                                                           invoiceTable.Rows[i]["GoodsName"].ToString(),
                                                                           invoiceTable.Rows[i]["Spec"].ToString());

                                var varOutsourcing = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill
                                                     where a.Bill_ID == invoiceTable.Rows[i]["Bill_ID"].ToString() &&
                                                     a.GoodsID == intGoodsID &&
                                                     a.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString()
                                                     select a;

                                //委外报检入库单单价修改
                                if (varOutsourcing.Count() != 0)
                                {
                                    S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varOutsourcing.Single();

                                    lnqOutsourcing.UnitInvoicePrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                                    lnqOutsourcing.InvoicePrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);

                                    lnqOutsourcing.HavingInvoice = true;
                                    dataContxt.SubmitChanges();
                                }
                            }
                        }
                    }

                    #endregion

                    #region 改变入库明细表金额
                    var varInDepotBill = from b in dataContxt.S_InDepotDetailBill
                                         where b.GoodsID == basicGoods.序号 &&
                                         b.InDepotBillID == invoiceTable.Rows[i]["Bill_ID"].ToString() &&
                                         b.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString()
                                         select b;

                    if (varInDepotBill.Count() == 1)
                    {
                        S_InDepotDetailBill lnqInDepotBill = varInDepotBill.Single();

                        lnqInDepotBill.InvoiceUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                        lnqInDepotBill.InvoicePrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);

                        if (lnqInDepotBill.FactPrice != Convert.ToDecimal(invoiceTable.Rows[i]["Price"]))
                        {
                            //当查询的记录不在当月的结算日期范围内,插入红冲单据与对冲单据
                            if (lnqInDepotBill.BillTime < dtStart || lnqInDepotBill.BillTime > dtEnd)
                            {
                                var varDetail = from d in dataContxt.S_InDepotDetailBill
                                                where d.GoodsID == basicGoods.序号 &&
                                                d.InDepotBillID.Contains(invoiceTable.Rows[i]["Bill_ID"].ToString()) &&
                                                d.BatchNo == invoiceTable.Rows[i]["BatchNo"].ToString() &&
                                                d.BillTime >= dtStart && d.BillTime <= dtEnd
                                                select d;

                                //判断是否已经在当前结算日期范围内插入了红冲与对冲数据
                                if (varDetail.Count() != 0)
                                {
                                    foreach (var item in varDetail)
                                    {
                                        //针对已经插入的对冲数据进行修改
                                        if (item.InDepotBillID.Contains("(对冲单据)"))
                                        {
                                            item.FactPrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);
                                            item.FactUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                                        }
                                    }
                                }//对没有插入的红冲与对冲的记录进行插入
                                else
                                {
                                    //插一条原始的负记录(红冲单据)
                                    S_InDepotDetailBill lnqOldInDepotBill = new S_InDepotDetailBill();

                                    lnqOldInDepotBill.ID              = Guid.NewGuid();
                                    lnqOldInDepotBill.InDepotBillID   = lnqInDepotBill.InDepotBillID + "(红冲单据)";
                                    lnqOldInDepotBill.BatchNo         = lnqInDepotBill.BatchNo;
                                    lnqOldInDepotBill.BillTime        = ServerTime.Time;
                                    lnqOldInDepotBill.Department      = lnqInDepotBill.Department;
                                    lnqOldInDepotBill.FactUnitPrice   = lnqInDepotBill.FactUnitPrice;
                                    lnqOldInDepotBill.FactPrice       = -lnqInDepotBill.FactPrice;
                                    lnqOldInDepotBill.FillInPersonnel = lnqInDepotBill.FillInPersonnel;
                                    lnqOldInDepotBill.GoodsID         = lnqInDepotBill.GoodsID;
                                    lnqOldInDepotBill.InDepotCount    = -lnqInDepotBill.InDepotCount;
                                    lnqOldInDepotBill.Price           = -lnqInDepotBill.Price;
                                    lnqOldInDepotBill.OperationType   = (int)GlobalObject.CE_SubsidiaryOperationType.财务红冲;
                                    lnqOldInDepotBill.Provider        = lnqInDepotBill.Provider;
                                    lnqOldInDepotBill.Remark          = lnqInDepotBill.Remark;
                                    lnqOldInDepotBill.StorageID       = lnqInDepotBill.StorageID;
                                    lnqOldInDepotBill.UnitPrice       = lnqInDepotBill.UnitPrice;
                                    lnqOldInDepotBill.FillInDate      = lnqInDepotBill.FillInDate;
                                    lnqOldInDepotBill.AffrimPersonnel = lnqInDepotBill.AffrimPersonnel;

                                    IFinancialDetailManagement serverDetail =
                                        ServerModule.ServerModuleFactory.GetServerModule <IFinancialDetailManagement>();
                                    serverDetail.ProcessInDepotDetail(dataContxt, lnqOldInDepotBill, null);

                                    //插一条新的正记录(对冲单据)
                                    S_InDepotDetailBill lnqNewInDepotBill = new S_InDepotDetailBill();

                                    lnqNewInDepotBill.ID              = Guid.NewGuid();
                                    lnqNewInDepotBill.InDepotBillID   = lnqInDepotBill.InDepotBillID + "(对冲单据)";
                                    lnqNewInDepotBill.BatchNo         = lnqInDepotBill.BatchNo;
                                    lnqNewInDepotBill.BillTime        = ServerTime.Time;
                                    lnqNewInDepotBill.Department      = lnqInDepotBill.Department;
                                    lnqNewInDepotBill.FactUnitPrice   = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                                    lnqNewInDepotBill.FactPrice       = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);
                                    lnqNewInDepotBill.FillInPersonnel = lnqInDepotBill.FillInPersonnel;
                                    lnqNewInDepotBill.GoodsID         = lnqInDepotBill.GoodsID;
                                    lnqNewInDepotBill.InDepotCount    = lnqInDepotBill.InDepotCount;
                                    lnqNewInDepotBill.Price           = lnqInDepotBill.Price;
                                    lnqNewInDepotBill.OperationType   = (int)GlobalObject.CE_SubsidiaryOperationType.财务对冲;
                                    lnqNewInDepotBill.Provider        = lnqInDepotBill.Provider;
                                    lnqNewInDepotBill.Remark          = lnqInDepotBill.Remark;
                                    lnqNewInDepotBill.StorageID       = lnqInDepotBill.StorageID;
                                    lnqNewInDepotBill.UnitPrice       = lnqInDepotBill.UnitPrice;
                                    lnqNewInDepotBill.FillInDate      = lnqInDepotBill.FillInDate;
                                    lnqNewInDepotBill.AffrimPersonnel = lnqInDepotBill.AffrimPersonnel;

                                    serverDetail.ProcessInDepotDetail(dataContxt, lnqNewInDepotBill, null);
                                }
                            }
                            else
                            {
                                lnqInDepotBill.FactPrice     = Convert.ToDecimal(invoiceTable.Rows[i]["Price"]);
                                lnqInDepotBill.FactUnitPrice = Convert.ToDecimal(invoiceTable.Rows[i]["UnitPrice"]);
                            }
                        }

                        dataContxt.SubmitChanges();
                    }
                    #endregion
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 删除发票记录
        /// </summary>
        /// <param name="invoiceCode">发票号</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>删除成功返回True,删除失败返回False</returns>
        public bool DeleteInvoiceInfo(string invoiceCode, out string error)
        {
            error = null;

            string str   = "0";
            int    count = 0;

            try
            {
                DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

                OrdinaryInDepotBillServer serverOrdinaryBill = new OrdinaryInDepotBillServer();

                MaterialRejectBill serverMaterialRejectBill = new MaterialRejectBill();

                string strSql = "select * from B_Invoice where InvoiceCode = '" + invoiceCode + "'";

                DataTable dtInvoice = GlobalObject.DatabaseServer.QueryInfo(strSql);

                for (int i = 0; i <= dtInvoice.Rows.Count - 1; i++)
                {
                    count = i;

                    decimal dcOldUnitPrice = 0;

                    if (!GlobalObject.GeneralFunction.IsNullOrEmpty(error))
                    {
                        return(false);
                    }

                    str = "1";

                    #region 改变入库表的单价(普通入库或者报检入库)

                    var varCheckOutInDepot = from a in dataContxt.S_CheckOutInDepotBill
                                             where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() &&
                                             a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) &&
                                             a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString()
                                             select a;

                    if (varCheckOutInDepot.Count() != 0)
                    {
                        S_CheckOutInDepotBill lnqCheckOutInDepot = varCheckOutInDepot.Single();

                        lnqCheckOutInDepot.UnitInvoicePrice = 0;
                        lnqCheckOutInDepot.InvoicePrice     = 0;
                        lnqCheckOutInDepot.HavingInvoice    = false;
                        dcOldUnitPrice = lnqCheckOutInDepot.UnitPrice;
                        dataContxt.SubmitChanges();
                    }
                    else
                    {
                        var varOrdinaryGoods = from a in dataContxt.S_OrdinaryInDepotGoodsBill
                                               where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() &&
                                               a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) &&
                                               a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString()
                                               select a;

                        if (varOrdinaryGoods.Count() != 0)
                        {
                            S_OrdinaryInDepotGoodsBill lnqOrdinaryGoods = varOrdinaryGoods.Single();

                            lnqOrdinaryGoods.InvoiceUnitPrice = 0;
                            lnqOrdinaryGoods.InvoicePrice     = 0;
                            lnqOrdinaryGoods.HavingInvoice    = false;

                            dcOldUnitPrice = lnqOrdinaryGoods.UnitPrice;
                            dataContxt.SubmitChanges();

                            int intFlag = serverOrdinaryBill.GetHavingInvoice(dtInvoice.Rows[i]["Bill_ID"].ToString(), out error);

                            if (intFlag == 4)
                            {
                                return(false);
                            }
                            else
                            {
                                var varOrdinaryBill = from a in dataContxt.S_OrdinaryInDepotBill
                                                      where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString()
                                                      select a;

                                if (varOrdinaryBill.Count() != 0)
                                {
                                    S_OrdinaryInDepotBill lnqOrdinaryBill = varOrdinaryBill.Single();
                                    lnqOrdinaryBill.InvoiceStatus = intFlag;

                                    dataContxt.SubmitChanges();
                                }
                            }
                        }
                        else
                        {
                            var varRejectList = from a in dataContxt.S_MaterialListRejectBill
                                                where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() &&
                                                a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) &&
                                                a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString()
                                                select a;

                            if (varRejectList.Count() != 0)
                            {
                                S_MaterialListRejectBill lnqMaterialList = varRejectList.Single();

                                lnqMaterialList.InvoiceUnitPrice = 0;
                                lnqMaterialList.InvoicePrice     = 0;
                                lnqMaterialList.HavingInvoice    = false;

                                dcOldUnitPrice = lnqMaterialList.UnitPrice;

                                dataContxt.SubmitChanges();

                                int intFlag = serverMaterialRejectBill.SetHavingInvoiceReturn(dtInvoice.Rows[i]["Bill_ID"].ToString(), out error);

                                if (intFlag == 4)
                                {
                                    return(false);
                                }
                                else
                                {
                                    var varRejectBill = from a in dataContxt.S_MaterialRejectBill
                                                        where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString()
                                                        select a;

                                    if (varRejectBill.Count() != 0)
                                    {
                                        S_MaterialRejectBill lnqMaterialBill = varRejectBill.Single();
                                        lnqMaterialBill.InvoiceFlag = intFlag;

                                        dataContxt.SubmitChanges();
                                    }
                                }
                            }
                            else
                            {
                                var varOutsourcing = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill
                                                     where a.Bill_ID == dtInvoice.Rows[i]["Bill_ID"].ToString() &&
                                                     a.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) &&
                                                     a.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString()
                                                     select a;

                                if (varOutsourcing.Count() != 0)
                                {
                                    S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varOutsourcing.Single();

                                    lnqOutsourcing.UnitInvoicePrice = 0;
                                    lnqOutsourcing.InvoicePrice     = 0;
                                    lnqOutsourcing.HavingInvoice    = false;
                                    dcOldUnitPrice = lnqOutsourcing.UnitPrice;

                                    dataContxt.SubmitChanges();
                                }
                            }
                        }
                    }

                    #endregion

                    str = "2";

                    #region 改变入库明细表金额

                    var varInDepotDetail = from b in dataContxt.S_InDepotDetailBill
                                           where b.GoodsID == Convert.ToInt32(dtInvoice.Rows[i]["GoodsID"].ToString()) &&
                                           b.InDepotBillID.Contains(dtInvoice.Rows[i]["Bill_ID"].ToString()) &&
                                           b.BatchNo == dtInvoice.Rows[i]["BatchNo"].ToString()
                                           select b;

                    if (varInDepotDetail.Count() != 0)
                    {
                        if (varInDepotDetail.Count() == 1)
                        {
                            S_InDepotDetailBill lnqInDepotDetailSingle = varInDepotDetail.Single();

                            lnqInDepotDetailSingle.InvoiceUnitPrice = 0;
                            lnqInDepotDetailSingle.InvoicePrice     = 0;
                            lnqInDepotDetailSingle.FactUnitPrice    = dcOldUnitPrice;
                            lnqInDepotDetailSingle.FactPrice        = Math.Round(dcOldUnitPrice * Convert.ToDecimal(lnqInDepotDetailSingle.InDepotCount), 2);
                        }
                        else
                        {
                            var varInDepotDetailList = from a in varInDepotDetail
                                                       where a.InDepotBillID == dtInvoice.Rows[i]["Bill_ID"].ToString()
                                                       select a;

                            S_InDepotDetailBill lnqInDepotDetailData = varInDepotDetailList.Single();

                            lnqInDepotDetailData.InvoiceUnitPrice = 0;
                            lnqInDepotDetailData.InvoicePrice     = 0;
                            lnqInDepotDetailData.FactUnitPrice    = dcOldUnitPrice;
                            lnqInDepotDetailData.FactPrice        = Math.Round(dcOldUnitPrice
                                                                               * Convert.ToDecimal(lnqInDepotDetailData.InDepotCount), 2);

                            var varData7 = from a in varInDepotDetail
                                           where a.InDepotBillID != dtInvoice.Rows[i]["Bill_ID"].ToString()
                                           select a;

                            dataContxt.S_InDepotDetailBill.DeleteAllOnSubmit(varData7);
                        }

                        dataContxt.SubmitChanges();
                    }
                    #endregion
                }

                var varInvoice = from a in dataContxt.B_Invoice
                                 where a.InvoiceCode == invoiceCode
                                 select a;

                if (varInvoice.Count() > 0)
                {
                    dataContxt.B_Invoice.DeleteAllOnSubmit(varInvoice);
                    dataContxt.SubmitChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message + str + count.ToString();
                return(false);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 回退单据
        /// </summary>
        /// <param name="djh">单据号</param>
        /// <param name="billStatus">单据状态</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <param name="rebackReason">回退原因</param>
        /// <returns>回退成功返回True,回退失败返回False</returns>
        public bool ReturnBill(string djh, string billStatus,
                               out string error, string rebackReason)
        {
            error = null;

            try
            {
                DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

                var varData = from a in dataContext.S_CheckOutInDepotForOutsourcingBill
                              where a.Bill_ID == djh
                              select a;

                string strMsg = "";

                if (varData.Count() == 1)
                {
                    S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varData.Single();

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

                        strMsg = string.Format("{0}号委外报检入库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqOutsourcing.DeclarePersonnel), false);

                        lnqOutsourcing.BillStatus = "新建单据";

                        //lnqOutsourcing.CheckoutReport_ID = null;
                        //lnqOutsourcing.Checker = null;
                        //lnqOutsourcing.EligibleCount = 0;
                        //lnqOutsourcing.ConcessionCount = 0;
                        //lnqOutsourcing.ReimbursementCount = 0;
                        //lnqOutsourcing.DeclareWastrelCount = 0;
                        //lnqOutsourcing.QualityInfo = null;
                        //lnqOutsourcing.PeremptorilyEmit = false;
                        lnqOutsourcing.QualityPersonnel = null;
                        lnqOutsourcing.QualityTime      = null;

                        //lnqOutsourcing.DepotManagerAffirmCount = 0;
                        lnqOutsourcing.ArrivePersonnel = null;
                        lnqOutsourcing.ArriveTime      = null;

                        //lnqOutsourcing.Price = Math.Round(lnqOutsourcing.OutsourcingUnitPrice * lnqOutsourcing.DeclareCount, 2);
                        //lnqOutsourcing.UnitPrice = lnqOutsourcing.OutsourcingUnitPrice;
                        //lnqOutsourcing.RawMaterialPrice = 0;
                        lnqOutsourcing.FinancePersonnel = null;
                        lnqOutsourcing.FinanceTime      = null;

                        break;

                    case "等待财务批准":
                        strMsg = string.Format("{0}号委外报检入库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqOutsourcing.FinancePersonnel), false);

                        lnqOutsourcing.BillStatus = "等待财务批准";

                        //lnqOutsourcing.CheckoutReport_ID = null;
                        //lnqOutsourcing.Checker = null;
                        //lnqOutsourcing.EligibleCount = 0;
                        //lnqOutsourcing.ConcessionCount = 0;
                        //lnqOutsourcing.ReimbursementCount = 0;
                        //lnqOutsourcing.DeclareWastrelCount = 0;
                        //lnqOutsourcing.QualityInfo = null;
                        //lnqOutsourcing.PeremptorilyEmit = false;
                        lnqOutsourcing.QualityPersonnel = null;
                        lnqOutsourcing.QualityTime      = null;

                        //lnqOutsourcing.DepotManagerAffirmCount = 0;
                        lnqOutsourcing.ArrivePersonnel = null;
                        lnqOutsourcing.ArriveTime      = null;

                        //lnqOutsourcing.Price = Math.Round(lnqOutsourcing.OutsourcingUnitPrice * lnqOutsourcing.DeclareCount, 2);
                        //lnqOutsourcing.UnitPrice = lnqOutsourcing.OutsourcingUnitPrice;
                        //lnqOutsourcing.RawMaterialPrice = 0;
                        lnqOutsourcing.FinancePersonnel = null;
                        lnqOutsourcing.FinanceTime      = null;

                        break;

                    case "等待仓管确认到货":
                        strMsg = string.Format("{0}号委外报检入库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqOutsourcing.ArrivePersonnel), false);

                        lnqOutsourcing.BillStatus = "等待仓管确认到货";

                        //lnqOutsourcing.CheckoutReport_ID = null;
                        //lnqOutsourcing.Checker = null;
                        //lnqOutsourcing.EligibleCount = 0;
                        //lnqOutsourcing.ConcessionCount = 0;
                        //lnqOutsourcing.ReimbursementCount = 0;
                        //lnqOutsourcing.DeclareWastrelCount = 0;
                        //lnqOutsourcing.QualityInfo = null;
                        //lnqOutsourcing.PeremptorilyEmit = false;
                        lnqOutsourcing.QualityPersonnel = null;
                        lnqOutsourcing.QualityTime      = null;

                        //lnqOutsourcing.DepotManagerAffirmCount = 0;
                        //lnqOutsourcing.Price = Math.Round(lnqOutsourcing.UnitPrice * lnqOutsourcing.DeclareCount, 2);
                        lnqOutsourcing.ArrivePersonnel = null;
                        lnqOutsourcing.ArriveTime      = null;

                        break;

                    case "等待质检机检验":
                        strMsg = string.Format("{0}号委外报检入库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqOutsourcing.QualityPersonnel), false);

                        lnqOutsourcing.BillStatus = "等待质检机检验";
                        //lnqOutsourcing.CheckoutReport_ID = null;
                        //lnqOutsourcing.Checker = null;
                        //lnqOutsourcing.EligibleCount = 0;
                        //lnqOutsourcing.ConcessionCount = 0;
                        //lnqOutsourcing.ReimbursementCount = 0;
                        //lnqOutsourcing.DeclareWastrelCount = 0;
                        //lnqOutsourcing.QualityInfo = null;
                        //lnqOutsourcing.PeremptorilyEmit = false;
                        lnqOutsourcing.QualityPersonnel = null;
                        lnqOutsourcing.QualityTime      = null;

                        break;

                    case "等待质检电检验":

                        strMsg = string.Format("{0}号委外报检入库单已回退,请您重新处理单据; 回退原因为" + rebackReason, djh);
                        m_billMessageServer.PassFlowMessage(djh, strMsg,
                                                            UniversalFunction.GetPersonnelCode(lnqOutsourcing.QualityPersonnel), false);

                        lnqOutsourcing.BillStatus = "等待质检电检验";
                        //lnqOutsourcing.CheckoutReport_ID = null;
                        //lnqOutsourcing.Checker = null;
                        //lnqOutsourcing.EligibleCount = 0;
                        //lnqOutsourcing.ConcessionCount = 0;
                        //lnqOutsourcing.ReimbursementCount = 0;
                        //lnqOutsourcing.DeclareWastrelCount = 0;
                        //lnqOutsourcing.QualityInfo = null;
                        //lnqOutsourcing.PeremptorilyEmit = false;
                        lnqOutsourcing.QualityPersonnel = null;
                        lnqOutsourcing.QualityTime      = null;

                        break;

                    default:
                        break;
                    }

                    dataContext.SubmitChanges();
                    return(true);
                }
                else
                {
                    error = "数据不唯一或者为空";
                    return(false);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 插入报废单
        /// </summary>
        /// <param name="ctx">LINQ数据上下文</param>
        /// <param name="outSourcing">Linq操作数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>插入成功返回True,插入失败返回False</returns>
        public bool AddScrapBill(DepotManagementDataContext ctx,
                                 S_CheckOutInDepotForOutsourcingBill outSourcing, out string error)
        {
            error = null;
            string strBillID = "";

            try
            {
                ScrapBillServer serverScrapBill = new ScrapBillServer();

                S_ScrapBill lnqBill = new S_ScrapBill();

                strBillID = m_assignBill.AssignNewNo(serverScrapBill, CE_BillTypeEnum.报废单.ToString());

                lnqBill.AuthorizeTime     = ServerTime.Time;
                lnqBill.Bill_ID           = strBillID;
                lnqBill.Bill_Time         = ServerTime.Time;
                lnqBill.BillStatus        = "已完成";
                lnqBill.Checker           = outSourcing.Checker;
                lnqBill.DeclareDepartment = m_serverDepartment.GetDeptInfoFromPersonnelInfo(
                    outSourcing.DeclarePersonnel).Rows[0]["DepartmentCode"].ToString();
                lnqBill.DepartmentDirector  = "";
                lnqBill.DepotManager        = outSourcing.ManagerPersonnel;
                lnqBill.DepotTime           = ServerTime.Time;
                lnqBill.FillInPersonnel     = outSourcing.DeclarePersonnel;
                lnqBill.FillInPersonnelCode = UniversalFunction.GetPersonnelCode(outSourcing.DeclarePersonnel);
                lnqBill.NotifyChecker       = UniversalFunction.GetPersonnelCode(outSourcing.Checker);
                lnqBill.ProductType         = "";
                lnqBill.Remark   = "关联委外报检入库单【" + outSourcing.Bill_ID + "】,自动生成";
                lnqBill.Sanction = outSourcing.Checker;

                ctx.S_ScrapBill.InsertOnSubmit(lnqBill);

                S_ScrapGoods lnqGoods = new S_ScrapGoods();

                lnqGoods.BatchNo  = outSourcing.BatchNo;
                lnqGoods.Bill_ID  = strBillID;
                lnqGoods.GoodsID  = outSourcing.GoodsID;
                lnqGoods.Provider = outSourcing.Provider;
                lnqGoods.Quantity = outSourcing.DeclareWastrelCount;
                lnqGoods.Reason   = "检测报废,关联委外报检入库单【" + outSourcing.Bill_ID + "】,自动生成";
                lnqGoods.Remark   = "检测报废,关联委外报检入库单【" + outSourcing.Bill_ID + "】,自动生成";
                lnqGoods.ResponsibilityDepartment = "GYS";
                lnqGoods.ResponsibilityProvider   = outSourcing.Provider;
                lnqGoods.ResponsibilityType       = "返 修 废";
                lnqGoods.UnitPrice    = 0;
                lnqGoods.WastrelType  = 9;
                lnqGoods.WorkingHours = 0;

                ctx.S_ScrapGoods.InsertOnSubmit(lnqGoods);

                m_assignBill.UseBillNo(CE_BillTypeEnum.报废单.ToString(), strBillID);

                return(true);
            }
            catch (Exception ex)
            {
                m_assignBill.CancelBillNo(CE_BillTypeEnum.报废单.ToString(), strBillID);
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// 有检测废的物品直接生成领料单
        /// </summary>
        /// <param name="ctx">数据上下文</param>
        /// <param name="inDepotInfo">报检单信息</param>
        /// <param name="mrBillNo">分配的领料单单号</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>生成成功返回True,生成失败返回False</returns>
        public bool InsertIntoMaterialRequisition(DepotManagementDataContext ctx, S_CheckOutInDepotForOutsourcingBill inDepotInfo,
                                                  out string mrBillNo, out string error)
        {
            error    = null;
            mrBillNo = null;
            string billNo = null;

            MaterialRequisitionServer serverMaterialBill = new MaterialRequisitionServer();

            try
            {
                billNo   = m_assignBill.AssignNewNo(serverMaterialBill, CE_BillTypeEnum.领料单.ToString());
                mrBillNo = billNo;

                var varData = from a in ctx.S_MaterialRequisition
                              where a.Bill_ID == billNo
                              select a;

                S_MaterialRequisition lnqMaterial = null;


                if (varData.Count() != 0)
                {
                    error = string.Format("自动生成的报废物品领料单单号 {0} 已被占用,请尝试重新进行此操作,再三出现无法生成可用的单号时与管理员联系", billNo);
                    return(false);
                }
                else
                {
                    lnqMaterial = new S_MaterialRequisition();

                    lnqMaterial.Bill_ID             = billNo;
                    lnqMaterial.Bill_Time           = ServerModule.ServerTime.Time;
                    lnqMaterial.AssociatedBillNo    = inDepotInfo.Bill_ID;
                    lnqMaterial.AssociatedBillType  = "";
                    lnqMaterial.BillStatus          = "已出库";
                    lnqMaterial.Department          = "ZK03";
                    lnqMaterial.DepartmentDirector  = "";
                    lnqMaterial.DepotManager        = inDepotInfo.ManagerPersonnel;
                    lnqMaterial.FetchCount          = 0;
                    lnqMaterial.FetchType           = "零星领料";
                    lnqMaterial.FillInPersonnel     = inDepotInfo.QualityPersonnel;
                    lnqMaterial.FillInPersonnelCode =
                        UniversalFunction.GetPersonnelInfo(inDepotInfo.QualityPersonnel, CE_HR_PersonnelStatus.在职).工号;
                    lnqMaterial.ProductType  = "";
                    lnqMaterial.PurposeCode  = UniversalFunction.GetPurpose(CE_PickingPurposeProperty.破坏性检测).Code;
                    lnqMaterial.Remark       = "因入库零件进行了破坏性检测,由系统自动生成的破坏件领料单,对应单据号:" + inDepotInfo.Bill_ID;
                    lnqMaterial.StorageID    = inDepotInfo.StorageID;
                    lnqMaterial.OutDepotDate = ServerTime.Time;

                    if (!serverMaterialBill.AutoCreateBill(ctx, lnqMaterial, out error))
                    {
                        return(false);
                    }

                    S_MaterialRequisitionGoods lnqMaterialGoods = new S_MaterialRequisitionGoods();

                    lnqMaterialGoods.Bill_ID      = billNo;
                    lnqMaterialGoods.BasicCount   = 0;
                    lnqMaterialGoods.BatchNo      = inDepotInfo.BatchNo;
                    lnqMaterialGoods.GoodsID      = inDepotInfo.GoodsID;
                    lnqMaterialGoods.ProviderCode = inDepotInfo.Provider;
                    lnqMaterialGoods.RealCount    = Convert.ToDecimal(inDepotInfo.DeclareWastrelCount);
                    lnqMaterialGoods.Remark       = "";
                    lnqMaterialGoods.RequestCount = Convert.ToDecimal(inDepotInfo.DeclareWastrelCount);
                    lnqMaterialGoods.ShowPosition = 1;

                    MaterialRequisitionGoodsServer serverMaterialGoods = new MaterialRequisitionGoodsServer();

                    if (!serverMaterialGoods.AutoCreateGoods(ctx, lnqMaterialGoods, out error))
                    {
                        return(false);
                    }

                    ctx.SubmitChanges();

                    if (!serverMaterialBill.FinishBill(ctx, lnqMaterial.Bill_ID, "", out error))
                    {
                        throw new Exception(error);
                    }

                    ctx.SubmitChanges();
                }

                return(true);
            }
            catch (Exception ex)
            {
                serverMaterialBill.DeleteBill(billNo, out error);
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// 回退单据
        /// </summary>
        /// <param name="billID">单据号</param>
        /// <param name="mrBillID">领料单据号</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>回退成功返回True,回退失败返回False</returns>
        private bool ReturnBillInDepot(string billID, string mrBillID, out string error)
        {
            error = null;

            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

            try
            {
                int     intGoodsID = 0;
                string  strBatchNo = "";
                decimal dcCount    = 0;
                decimal dcWastrel  = 0;
                //报检单状态修改
                var varData1 = from a in dataContxt.S_CheckOutInDepotForOutsourcingBill
                               where a.Bill_ID == billID
                               select a;

                if (varData1.Count() == 1)
                {
                    S_CheckOutInDepotForOutsourcingBill lnqCheck = varData1.Single();

                    intGoodsID          = Convert.ToInt32(lnqCheck.GoodsID);
                    strBatchNo          = lnqCheck.BatchNo.ToString();
                    dcCount             = Convert.ToDecimal(lnqCheck.EligibleCount);
                    dcWastrel           = Convert.ToDecimal(lnqCheck.DeclareWastrelCount);
                    lnqCheck.BillStatus = "等待入库";
                }

                //库存记录的删除/修改
                var varData2 = from a in dataContxt.S_Stock
                               where a.GoodsID == intGoodsID &&
                               a.BatchNo == strBatchNo
                               select a;

                if (varData2.Count() == 1)
                {
                    S_Stock lnqStock = varData2.Single();

                    if (Convert.ToDecimal(lnqStock.ExistCount) == dcCount)
                    {
                        dataContxt.S_Stock.DeleteOnSubmit(lnqStock);
                    }
                    else
                    {
                        lnqStock.ExistCount = Convert.ToDecimal(lnqStock.ExistCount) - dcCount;
                    }
                }

                //入库明细表记录删除
                var varData3 = from a in dataContxt.S_InDepotDetailBill
                               where a.InDepotBillID == billID &&
                               a.BatchNo == strBatchNo &&
                               a.GoodsID == intGoodsID
                               select a;

                if (varData3.Count() == 1)
                {
                    dataContxt.S_InDepotDetailBill.DeleteOnSubmit(varData3.Single());
                }

                //领料单主表删除
                var varData4 = from a in dataContxt.S_MaterialRequisition
                               where a.Bill_ID == mrBillID &&
                               a.PurposeCode == UniversalFunction.GetPurpose(CE_PickingPurposeProperty.破坏性检测).Code
                               select a;

                if (varData4.Count() == 1)
                {
                    dataContxt.S_MaterialRequisition.DeleteOnSubmit(varData4.Single());
                }

                //领料单此表删除
                var varData5 = from a in dataContxt.S_MaterialRequisitionGoods
                               where a.Bill_ID == mrBillID &&
                               a.GoodsID == intGoodsID &&
                               a.BatchNo == strBatchNo
                               select a;

                if (varData5.Count() == 1)
                {
                    dataContxt.S_MaterialRequisitionGoods.DeleteOnSubmit(varData5.Single());
                }

                //出库明细表记录删除
                var varData6 = from a in dataContxt.S_FetchGoodsDetailBill
                               where a.FetchBIllID == mrBillID &&
                               a.BatchNo == strBatchNo &&
                               a.GoodsID == intGoodsID
                               select a;

                if (varData6.Count() == 1)
                {
                    dataContxt.S_FetchGoodsDetailBill.DeleteOnSubmit(varData6.Single());
                }

                dataContxt.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 更新单据状态
        /// </summary>
        /// <param name="outSourcing">Linq操作数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>更新成功返回True,更新失败返回False</returns>
        public bool UpdateBill(S_CheckOutInDepotForOutsourcingBill outSourcing, out string error)
        {
            error = null;

            string mrBillNo = null;

            DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

            ctx.Connection.Open();
            ctx.Transaction = ctx.Connection.BeginTransaction();
            try
            {
                var varData = from a in ctx.S_CheckOutInDepotForOutsourcingBill
                              where a.Bill_ID == outSourcing.Bill_ID
                              select a;

                if (varData.Count() != 1)
                {
                    error = "数据为空或者不唯一";
                    throw new Exception(error);
                }
                else
                {
                    S_CheckOutInDepotForOutsourcingBill lnqOutsourcing = varData.Single();

                    if (lnqOutsourcing.BillStatus != outSourcing.BillStatus)
                    {
                        error = "单据状态错误,请重新刷新单据确认单据状态";
                        throw new Exception(error);
                    }

                    switch (lnqOutsourcing.BillStatus)
                    {
                    case "等待财务批准":
                        lnqOutsourcing.BillStatus       = "等待仓管确认到货";
                        lnqOutsourcing.UnitPrice        = outSourcing.UnitPrice;
                        lnqOutsourcing.Price            = outSourcing.Price;
                        lnqOutsourcing.RawMaterialPrice = outSourcing.RawMaterialPrice;
                        lnqOutsourcing.FinancePersonnel = BasicInfo.LoginName;
                        lnqOutsourcing.FinanceTime      = ServerTime.Time;
                        break;

                    case "等待仓管确认到货":
                        lnqOutsourcing.BillStatus = outSourcing.QualityInfo;
                        lnqOutsourcing.DepotManagerAffirmCount = outSourcing.DepotManagerAffirmCount;
                        lnqOutsourcing.Price           = outSourcing.Price;
                        lnqOutsourcing.ArrivePersonnel = BasicInfo.LoginName;
                        lnqOutsourcing.ArriveTime      = ServerTime.Time;
                        break;

                    case "等待质检机检验":
                        lnqOutsourcing.BillStatus          = "等待质量主管审核";
                        lnqOutsourcing.CheckoutReport_ID   = outSourcing.CheckoutReport_ID;
                        lnqOutsourcing.Checker             = outSourcing.Checker;
                        lnqOutsourcing.EligibleCount       = outSourcing.EligibleCount;
                        lnqOutsourcing.ConcessionCount     = outSourcing.ConcessionCount;
                        lnqOutsourcing.ReimbursementCount  = outSourcing.ReimbursementCount;
                        lnqOutsourcing.DeclareWastrelCount = outSourcing.DeclareWastrelCount;
                        lnqOutsourcing.QualityInfo         = outSourcing.QualityInfo;
                        lnqOutsourcing.PeremptorilyEmit    = outSourcing.PeremptorilyEmit;
                        lnqOutsourcing.QualityPersonnel    = BasicInfo.LoginName;
                        lnqOutsourcing.QualityTime         = ServerTime.Time;
                        break;

                    case "等待质检电检验":
                        lnqOutsourcing.BillStatus          = "等待质量主管审核";
                        lnqOutsourcing.CheckoutReport_ID   = outSourcing.CheckoutReport_ID;
                        lnqOutsourcing.Checker             = outSourcing.Checker;
                        lnqOutsourcing.EligibleCount       = outSourcing.EligibleCount;
                        lnqOutsourcing.ConcessionCount     = outSourcing.ConcessionCount;
                        lnqOutsourcing.ReimbursementCount  = outSourcing.ReimbursementCount;
                        lnqOutsourcing.DeclareWastrelCount = outSourcing.DeclareWastrelCount;
                        lnqOutsourcing.QualityInfo         = outSourcing.QualityInfo;
                        lnqOutsourcing.PeremptorilyEmit    = outSourcing.PeremptorilyEmit;
                        lnqOutsourcing.QualityPersonnel    = BasicInfo.LoginName;
                        lnqOutsourcing.QualityTime         = ServerTime.Time;
                        break;

                    case "等待质量主管审核":
                        lnqOutsourcing.BillStatus          = "等待入库";
                        lnqOutsourcing.IsOnlyForRepairFlag = outSourcing.IsOnlyForRepairFlag;
                        lnqOutsourcing.QASupervisor        = BasicInfo.LoginName;
                        lnqOutsourcing.QASupervisorTime    = ServerTime.Time;
                        break;

                    case "等待入库":
                        lnqOutsourcing.BillStatus       = "已入库";
                        lnqOutsourcing.Price            = outSourcing.Price;
                        lnqOutsourcing.InDepotCount     = outSourcing.InDepotCount;
                        lnqOutsourcing.ShelfArea        = outSourcing.ShelfArea;
                        lnqOutsourcing.ColumnNumber     = outSourcing.ColumnNumber;
                        lnqOutsourcing.LayerNumber      = outSourcing.LayerNumber;
                        lnqOutsourcing.ManagerPersonnel = BasicInfo.LoginName;
                        lnqOutsourcing.ManagerTime      = ServerTime.Time;

                        // 添加信息到入库明细表
                        OpertaionDetailAndStock(ctx, lnqOutsourcing);

                        //若勾选了“包含原材料费”并且报废数大于0,则插入报废单
                        if (outSourcing.IsExigenceCheck && outSourcing.DeclareWastrelCount > 0)
                        {
                            if (!AddScrapBill(ctx, lnqOutsourcing, out error))
                            {
                                throw new Exception(error);
                            }
                        }

                        ctx.SubmitChanges();

                        if ((int)outSourcing.DeclareWastrelCount > 0 && outSourcing.InDepotCount > 0)
                        {
                            if (!InsertIntoMaterialRequisition(ctx, outSourcing, out mrBillNo, out error))
                            {
                                m_assignBill.CancelBillNo(CE_BillTypeEnum.领料单.ToString(), mrBillNo);
                                ReturnBillInDepot(lnqOutsourcing.Bill_ID, mrBillNo, out error);
                                throw new Exception(error);
                            }
                        }

                        break;

                    default:
                        break;
                    }

                    ctx.SubmitChanges();
                }

                ctx.Transaction.Commit();
                return(true);
            }
            catch (Exception ex)
            {
                ctx.Transaction.Rollback();
                error = ex.Message;
                return(false);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="outSourcing">Linq数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>插入成功返回True,插入失败返回False</returns>
        public bool AddBill(S_CheckOutInDepotForOutsourcingBill outSourcing, out string error)
        {
            error = null;

            try
            {
                S_CheckOutInDepotForOutsourcingBill lnqOutsouring = new S_CheckOutInDepotForOutsourcingBill();

                DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

                var varData = from a in ctx.S_CheckOutInDepotForOutsourcingBill
                              where a.Bill_ID == outSourcing.Bill_ID
                              select a;

                if (varData.Count() == 1)
                {
                    lnqOutsouring = varData.Single();

                    lnqOutsouring.Bill_ID              = outSourcing.Bill_ID;
                    lnqOutsouring.BillStatus           = outSourcing.IsIncludeRawMaterial == true ? "等待财务批准" : "等待仓管确认到货";
                    lnqOutsouring.OrderFormNumber      = outSourcing.OrderFormNumber;
                    lnqOutsouring.GoodsID              = outSourcing.GoodsID;
                    lnqOutsouring.Depot                = outSourcing.Depot;
                    lnqOutsouring.BatchNo              = outSourcing.BatchNo;
                    lnqOutsouring.Provider             = outSourcing.Provider;
                    lnqOutsouring.ProviderBatchNo      = outSourcing.ProviderBatchNo;
                    lnqOutsouring.DeclareCount         = outSourcing.DeclareCount;
                    lnqOutsouring.UnitPrice            = outSourcing.UnitPrice;
                    lnqOutsouring.Price                = outSourcing.Price;
                    lnqOutsouring.Remark               = outSourcing.Remark;
                    lnqOutsouring.StorageID            = outSourcing.StorageID;
                    lnqOutsouring.Version              = outSourcing.Version;
                    lnqOutsouring.IsExigenceCheck      = outSourcing.IsExigenceCheck;
                    lnqOutsouring.IsIncludeRawMaterial = outSourcing.IsIncludeRawMaterial;
                    lnqOutsouring.RawMaterialPrice     = outSourcing.RawMaterialPrice;
                    lnqOutsouring.DeclarePersonnel     = outSourcing.DeclarePersonnel;
                    lnqOutsouring.DeclareTime          = outSourcing.DeclareTime;
                    lnqOutsouring.OutsourcingUnitPrice = outSourcing.OutsourcingUnitPrice;
                }
                else if (varData.Count() == 0)
                {
                    lnqOutsouring = new S_CheckOutInDepotForOutsourcingBill();

                    lnqOutsouring.Bill_ID              = outSourcing.Bill_ID;
                    lnqOutsouring.BillStatus           = outSourcing.IsIncludeRawMaterial == true ? "等待财务批准" : "等待仓管确认到货";
                    lnqOutsouring.OrderFormNumber      = outSourcing.OrderFormNumber;
                    lnqOutsouring.GoodsID              = outSourcing.GoodsID;
                    lnqOutsouring.Depot                = outSourcing.Depot;
                    lnqOutsouring.BatchNo              = outSourcing.BatchNo;
                    lnqOutsouring.Provider             = outSourcing.Provider;
                    lnqOutsouring.ProviderBatchNo      = outSourcing.ProviderBatchNo;
                    lnqOutsouring.DeclareCount         = outSourcing.DeclareCount;
                    lnqOutsouring.UnitPrice            = outSourcing.UnitPrice;
                    lnqOutsouring.Price                = outSourcing.Price;
                    lnqOutsouring.Remark               = outSourcing.Remark;
                    lnqOutsouring.StorageID            = outSourcing.StorageID;
                    lnqOutsouring.Version              = outSourcing.Version;
                    lnqOutsouring.IsExigenceCheck      = outSourcing.IsExigenceCheck;
                    lnqOutsouring.IsIncludeRawMaterial = outSourcing.IsIncludeRawMaterial;
                    lnqOutsouring.RawMaterialPrice     = outSourcing.RawMaterialPrice;
                    lnqOutsouring.DeclarePersonnel     = outSourcing.DeclarePersonnel;
                    lnqOutsouring.DeclareTime          = outSourcing.DeclareTime;
                    lnqOutsouring.OutsourcingUnitPrice = outSourcing.OutsourcingUnitPrice;

                    ctx.S_CheckOutInDepotForOutsourcingBill.InsertOnSubmit(lnqOutsouring);
                }
                else
                {
                    error = "数据不唯一";
                    return(false);
                }

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

                ctx.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }