예제 #1
0
 void InitNewData(ORD_PurchaseOrderLineResult rst)
 {
     rst.Unit             = "PCS";
     rst.InvType          = cboInvType.SelectedValue.ToStringHasNull();
     rst.NeedDeliveryDate = string.IsNullOrEmpty(txtNeedDeliveryDate.Text) ? null : (DateTime?)txtNeedDeliveryDate.Value;
     rst.NeedPayAmtDate   = string.IsNullOrEmpty(txtNeedPayAmtDate.Text) ? null : (DateTime?)txtNeedPayAmtDate.Value;
 }
예제 #2
0
        private void btnAddRow_Click(object sender, EventArgs e)
        {
            bsOrderLine.AddNew();
            ORD_PurchaseOrderLineResult rst = bsOrderLine.Current as ORD_PurchaseOrderLineResult;

            InitNewData(rst);
        }
예제 #3
0
파일: frmStkIn.cs 프로젝트: halfx/ZNL
 public void SetStkLineObjectValue(STK_InLineResult inLineRst, ORD_PurchaseOrderLineResult purLineRst)
 {
     inLineRst.BuyerID            = purLineRst.BuyerID;
     inLineRst.BuyerName          = purLineRst.BuyerName;
     inLineRst.SourceBillGuid     = purLineRst.POGuid;
     inLineRst.SourceBillLineGuid = purLineRst.POLineGuid;
     inLineRst.SOLineGuid         = purLineRst.SOLineGuid;
     inLineRst.Model        = purLineRst.Model;
     inLineRst.Brand        = purLineRst.Brand;
     inLineRst.Package      = purLineRst.Package;
     inLineRst.Batch        = purLineRst.Batch;
     inLineRst.InvType      = purLineRst.InvType;
     inLineRst.Currency     = purLineRst.Currency;
     inLineRst.Unit         = purLineRst.Unit;
     inLineRst.UnitPrice    = purLineRst.UnitPrice;
     inLineRst.CostPrice    = inLineRst.UnitPrice.ToDecimal() + inLineRst.Freight.ToDecimal();
     inLineRst.Qty          = purLineRst.Qty.ToInt32() - purLineRst.StkInQty.ToInt32();
     inLineRst.Amount       = purLineRst.UnitPrice * purLineRst.Qty;
     inLineRst.SCAmount     = inLineRst.Amount * inLineRst.ExchangeRate;
     inLineRst.TaxRate      = purLineRst.TaxRate;
     inLineRst.Warehouse    = purLineRst.Warehouse;
     inLineRst.Location     = purLineRst.Location;
     inLineRst.IsCut        = true;
     inLineRst.IsPCut       = true;
     inLineRst.IsRaiseTaxes = false;
     inLineRst.IsGive       = inLineRst.IsGive == true ? true : false;
     inLineRst.IsDeleted    = false;
 }
예제 #4
0
        /// <summary>
        /// 删除实体
        /// </summary>
        /// <param name="param">删除条件实体</param>
        /// <returns></returns>
        public WCFAddUpdateResult DelInfo(ORD_PurchaseOrderLineParam param)
        {
            this.CheckSession();
            WCFAddUpdateResult ret = new WCFAddUpdateResult();
            int affect             = 0;

            try
            {
                #region 判断
                if (param.POLineGuid == null)
                {
                    throw new WarnException("请指定明细GUID!");
                }
                #endregion
                WhereClip whereClip = GetWhereClip(param);
                ORD_PurchaseOrderLineResult info = new ORD_PurchaseOrderLineResult();
                info.IsDeleted = true;
                affect         = this.Update <ORD_PurchaseOrderLineResult>(info, whereClip);
                #region 设置返回值
                ret.Key = affect;
                #endregion
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (System.Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(ret);
        }
예제 #5
0
        public ORD_PurchaseOrderLineResult GetInfo(ORD_PurchaseOrderLineParam param)
        {
            ORD_PurchaseOrderLineResult ret = new ORD_PurchaseOrderLineResult();
            ExeResult rst = new ExeResult();

            rst = this.Execute("ZNLCRM.BLL.PPM.ORD_PurchaseOrderLineBLL", "GetInfo", param);
            ret = rst == null ? new ORD_PurchaseOrderLineResult() : rst.Result as ORD_PurchaseOrderLineResult;
            return(ret);
        }
예제 #6
0
        private void btnInsertBefore_Click(object sender, EventArgs e)
        {
            if (dgvPurchaseOrderLine.CurrentCell == null)
            {
                btnAddRow_Click(null, null);
                return;
            }
            ORD_PurchaseOrderLineResult rst = new  ORD_PurchaseOrderLineResult();

            InitNewData(rst);
            bsOrderLine.Insert(dgvPurchaseOrderLine.CurrentRow.Index, rst);
        }
예제 #7
0
 private void btnDelRow_Click(object sender, EventArgs e)
 {
     if (this.bsOrderLine.Current != null)
     {
         Guid?poLineGuid = null;
         ORD_PurchaseOrderLineResult delResult = this.bsOrderLine.Current as ORD_PurchaseOrderLineResult;
         poLineGuid = delResult.POLineGuid;
         if (poLineGuid != null)
         {
             delResult.IsDeleted = true;
             delList.Add(delResult);
         }
         bsOrderLine.RemoveCurrent();
     }
 }
예제 #8
0
        /// <summary>
        /// 获取一条信息记录
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ORD_PurchaseOrderLineResult GetInfo(ORD_PurchaseOrderLineParam param)
        {
            this.CheckSession();
            ORD_PurchaseOrderLineResult rst = new ORD_PurchaseOrderLineResult();

            #region 判断
            if (param.POLineGuid == null)
            {
                throw new WarnException("请指定明细GUID!");
            }
            #endregion
            #region 获取实体

            rst = this.Select <ORD_PurchaseOrderLineResult>(GetWhereClip(param));

            #endregion
            return(rst);
        }
예제 #9
0
        /// <summary>
        /// 删除订单明细
        /// </summary>
        private void DeleteOrderDetail()
        {
            ORD_PurchaseOrderLineParam p = new ORD_PurchaseOrderLineParam();

            p.POGuid     = poguid;
            p.POLineGuid = poLineGuid;
            ORD_PurchaseOrderLineResult r = orderLineLogic.GetInfo(p);

            if (r != null)
            {
                if (MessageBox.Show("请确认是否要删除该记录", "操作提示",
                                    MessageBoxButtons.OKCancel,
                                    MessageBoxIcon.Question) == DialogResult.OK)
                {
                    WCFAddUpdateResult result = this.AsyncExecute <WCFAddUpdateResult, ORD_PurchaseOrderLineParam>(
                        p, orderLineLogic.DelInfo, a => { SearchDtl(1); });
                    if (GetOrderDetailCountsByID(poguid) == 0)
                    {
                        DeletePurchaseOrder(false);
                    }
                }
            }
        }
예제 #10
0
 public void SetOrderLineObjectValue(ORD_PurchaseOrderLineResult purLineRst, ORD_PurchaseNoticeResult noticeResult)
 {
     purLineRst.SOGuid             = noticeResult.SOGuid;
     purLineRst.SOBillNo           = noticeResult.SOBillNo;
     purLineRst.SOLineGuid         = noticeResult.SOLineGuid;
     purLineRst.SOLineCode         = noticeResult.SOLineCode;
     purLineRst.SOModel            = noticeResult.Model;
     purLineRst.SOBrand            = noticeResult.Brand;
     purLineRst.SOBatch            = noticeResult.Batch;
     purLineRst.SOPackage          = noticeResult.Package;
     purLineRst.SOQty              = noticeResult.SaleQty;
     purLineRst.SONeedDeliveryDate = noticeResult.NeedDeliveryDate;
     purLineRst.NoticeGuid         = noticeResult.NoticeGuid;
     purLineRst.Model              = noticeResult.Model;
     purLineRst.Brand              = noticeResult.Brand;
     purLineRst.Package            = noticeResult.Package;
     purLineRst.Batch              = noticeResult.Batch;
     purLineRst.InvType            = string.IsNullOrEmpty(noticeResult.InvType) ? "补货库存" : noticeResult.InvType;
     purLineRst.Unit             = noticeResult.Unit;
     purLineRst.Qty              = noticeResult.NoticeQty.ToInt32() - noticeResult.PurchaseQty.ToInt32();
     purLineRst.Amount           = purLineRst.UnitPrice * purLineRst.Qty;
     purLineRst.NeedDeliveryDate = string.IsNullOrEmpty(txtNeedDeliveryDate.Text) ? null : (DateTime?)txtNeedDeliveryDate.Value;
     purLineRst.NeedPayAmtDate   = string.IsNullOrEmpty(txtNeedPayAmtDate.Text) ? null : (DateTime?)txtNeedPayAmtDate.Value;
 }
예제 #11
0
        private void GetLastHistoryPrice(string oprType)
        {
            string        supplierName = "";
            int           supplierID   = 0;
            List <string> modelList    = new List <string>();
            List <string> brandList    = new List <string>();

            #region 供应商名称
            supplierID   = this.txtSupplierID.Text.ToInt32();
            supplierName = this.txtSupplierName.Text;
            if (supplierName.Trim() == "" || supplierID <= 0)
            {
                return;
            }
            #endregion
            #region 更改了供应商
            if (oprType == "supplier")
            {
                foreach (DataGridViewRow row in this.dgvPurchaseOrderLine.Rows)
                {
                    if (row.Cells["colModel"].Value.ToStringHasNull().Trim() == "")
                    {
                        continue;
                    }
                    if (row.Cells["colNTaxPrice"].Tag.ToDecimal() != row.Cells["colNTaxPrice"].Value.ToDecimal() &&
                        row.Cells["colUnitPrice"].Tag.ToDecimal() != row.Cells["colUnitPrice"].Value.ToDecimal())
                    {
                        continue;
                    }
                    modelList.Add(row.Cells["colModel"].Value.ToStringHasNull());
                    if (row.Cells["colBrand"].Value.ToStringHasNull().Trim() != "" && !brandList.Contains(row.Cells["colBrand"].Value.ToStringHasNull().Trim()))
                    {
                        brandList.Add(row.Cells["colBrand"].Value.ToStringHasNull());
                    }
                }
            }
            #endregion
            #region 更改了型号和品牌
            else if ((oprType == "model" || oprType == "brand") && this.dgvPurchaseOrderLine.CurrentCell != null)
            {
                DataGridViewRow row = this.dgvPurchaseOrderLine.Rows[this.dgvPurchaseOrderLine.CurrentCell.RowIndex];
                if (row.Cells["colModel"].Value.ToStringHasNull().Trim() != "" &&
                    (row.Cells["colNTaxPrice"].Tag.ToDecimal() == row.Cells["colNTaxPrice"].Value.ToDecimal() ||
                     row.Cells["colUnitPrice"].Tag.ToDecimal() == row.Cells["colUnitPrice"].Value.ToDecimal()))
                {
                    modelList.Add(row.Cells["colModel"].Value.ToStringHasNull());
                    if (row.Cells["colBrand"].Value.ToStringHasNull().Trim() != "" &&
                        !brandList.Contains(row.Cells["colBrand"].Value.ToStringHasNull().Trim()))
                    {
                        brandList.Add(row.Cells["colBrand"].Value.ToStringHasNull());
                    }
                }
            }
            #endregion
            #region 获取历史单价
            if (modelList.Count <= 0)
            {
                return;
            }
            ORD_PurchaseOrderLogic logic = new ORD_PurchaseOrderLogic(this);
            ORD_PurchaseOrderParam param = new ORD_PurchaseOrderParam();
            param.SupplierID = supplierID;
            param.ModelList  = modelList.ToArray();
            param.BrandList  = brandList.ToArray();
            List <ORD_PurchaseOrderLineResult> rst = logic.GetLastHisstoryPrice(param);
            #endregion
            string model = "", brand = "";
            ORD_PurchaseOrderLineResult findInfo = new ORD_PurchaseOrderLineResult();
            #region 更改了供应商
            if (oprType == "supplier")
            {
                foreach (DataGridViewRow row in this.dgvPurchaseOrderLine.Rows)
                {
                    if (row.Cells["colModel"].Value.ToStringHasNull().Trim() == "")
                    {
                        continue;
                    }
                    if (row.Cells["colNTaxPrice"].Tag.ToDecimal() != row.Cells["colNTaxPrice"].Value.ToDecimal() &&
                        row.Cells["colUnitPrice"].Tag.ToDecimal() != row.Cells["colUnitPrice"].Value.ToDecimal())
                    {
                        continue;
                    }
                    model = row.Cells["colModel"].Value.ToStringHasNull().ToLower();
                    brand = row.Cells["colBrand"].Value.ToStringHasNull().ToLower();
                    if (brand.ToStringHasNull().Trim() == "")
                    {
                        findInfo = rst.Find(a => a.Model.ToLower() == model);
                    }
                    else
                    {
                        findInfo = rst.Find(a => a.Model.ToLower() == model && a.Brand.ToStringHasNull().ToLower() == brand);
                    }
                    if (findInfo != null)
                    {
                        row.Cells["colUnitPrice"].Value = findInfo.UnitPrice;
                        row.Cells["colNTaxPrice"].Value = findInfo.NTaxPrice;
                        row.Cells["colUnitPrice"].Tag   = findInfo.UnitPrice;
                        row.Cells["colNTaxPrice"].Tag   = findInfo.NTaxPrice;
                    }
                    else
                    {
                        row.Cells["colUnitPrice"].Value = "";
                        row.Cells["colNTaxPrice"].Value = "";
                        row.Cells["colUnitPrice"].Tag   = null;
                        row.Cells["colNTaxPrice"].Tag   = null;
                    }
                }
            }
            #endregion
            #region 更改了型号和品牌
            else if ((oprType == "model" || oprType == "brand") && this.dgvPurchaseOrderLine.CurrentCell != null)
            {
                DataGridViewRow row = this.dgvPurchaseOrderLine.Rows[this.dgvPurchaseOrderLine.CurrentCell.RowIndex];
                if (row.Cells["colModel"].Value.ToStringHasNull().Trim() == "")
                {
                    return;
                }
                if (row.Cells["colNTaxPrice"].Tag.ToDecimal() != row.Cells["colNTaxPrice"].Value.ToDecimal() &&
                    row.Cells["colUnitPrice"].Tag.ToDecimal() != row.Cells["colUnitPrice"].Value.ToDecimal())
                {
                    return;
                }
                model = row.Cells["colModel"].Value.ToStringHasNull().ToLower();
                brand = row.Cells["colBrand"].Value.ToStringHasNull().ToLower();
                if (brand.ToStringHasNull().Trim() == "")
                {
                    findInfo = rst.Find(a => a.Model.ToLower() == model);
                }
                else
                {
                    findInfo = rst.Find(a => a.Model.ToLower() == model && a.Brand.ToStringHasNull().ToLower() == brand);
                }
                if (findInfo != null)
                {
                    row.Cells["colUnitPrice"].Value = findInfo.UnitPrice;
                    row.Cells["colNTaxPrice"].Value = findInfo.NTaxPrice;
                    row.Cells["colUnitPrice"].Tag   = findInfo.UnitPrice;
                    row.Cells["colNTaxPrice"].Tag   = findInfo.NTaxPrice;
                }
                else
                {
                    row.Cells["colUnitPrice"].Value = "";
                    row.Cells["colNTaxPrice"].Value = "";
                    row.Cells["colUnitPrice"].Tag   = null;
                    row.Cells["colNTaxPrice"].Tag   = null;
                }
            }
            #endregion
        }
예제 #12
0
        private void ImportByNoticeList(bool isMutiSelect)
        {
            if (!string.IsNullOrEmpty(txtBuyerName.Text))
            {
                frmSelectForPurchaseList frm = new frmSelectForPurchaseList(isMutiSelect);
                frm.BuyerID = txtBuyerID.Text.ToInt32();
                Guid?  noticeGuid = Guid.Empty;
                string model      = string.Empty;
                if (!isMutiSelect)//单选时
                {
                    model      = dgvPurchaseOrderLine.CurrentRow.Cells["colModel"].Value.ToStringHasNull();
                    noticeGuid = dgvPurchaseOrderLine.CurrentRow.Cells["colNoticeGuid"].Value.ToGuid();
                }

                if (!string.IsNullOrEmpty(model))
                {
                    frm.Model = model;
                }
                if (noticeGuid != Guid.Empty)//如果已经存在关联的源单据明细,则只筛选此条明细
                {
                    frm.NoticeGuid = noticeGuid;
                }
                else//如果是新行,则排除掉已经存在列表里面的所有的源单据明细
                {
                    Guid?[] noNoticeGuids = addOrModifyList.Where(a => a.NoticeGuid.ToGuid() != Guid.Empty).Select(a => a.NoticeGuid).Distinct().ToArray();
                    frm.NoNoticeGuids = noNoticeGuids;
                }
                frm.BringToFront();
                frm.StartPosition = FormStartPosition.CenterScreen;
                DialogResult rst = frm.ShowDialog();
                if (rst == DialogResult.OK)
                {
                    List <ORD_PurchaseNoticeResult> rstList = frm.GetSelectList <ORD_PurchaseNoticeResult>();
                    if (rstList != null && rstList.Count > 0)
                    {
                        foreach (ORD_PurchaseNoticeResult noticeResult in rstList)
                        {
                            bool isAddNew = true;
                            foreach (DataGridViewRow row in dgvPurchaseOrderLine.Rows)
                            {
                                //如果是已经存在的行,则利用现成的行进行编辑

                                if (row.Cells["colNoticeGuid"].Value.ToGuid() == noticeResult.NoticeGuid)
                                {
                                    isAddNew = false;

                                    ORD_PurchaseOrderLineResult orderLineResult = bsOrderLine[row.Index] as ORD_PurchaseOrderLineResult;
                                    SetOrderLineObjectValue(orderLineResult, noticeResult);
                                    break;
                                }
                            }
                            if (isAddNew)
                            {
                                if (!isMutiSelect)//单选
                                {
                                    ORD_PurchaseOrderLineResult orderLineResult = bsOrderLine.Current as ORD_PurchaseOrderLineResult;
                                    SetOrderLineObjectValue(orderLineResult, noticeResult);
                                }
                                else//多选
                                {
                                    ORD_PurchaseOrderLineResult orderLineResult = new ORD_PurchaseOrderLineResult();
                                    SetOrderLineObjectValue(orderLineResult, noticeResult);
                                    bsOrderLine.Add(orderLineResult);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("请先选择采购员!");
            }
        }
예제 #13
0
        public bool AuditStkInBill(STK_InParam param)
        {
            bool auditFlag = true;

            try
            {
                STK_InResult inResult = this.GetInfo(param);;

                if (inResult != null)
                {
                    bool isAllowAudit = true;

                    if (inResult.ApproveStatus == "待提交")
                    {
                        isAllowAudit = false;
                        throw new WarnException("入库单当前状态为:【待提交】,请先提交!");
                    }
                    else if (inResult.ApproveStatus == "审核完成")
                    {
                        isAllowAudit = false;
                        throw new WarnException("入库单当前状态为:【审核完成】,禁止重复审核!");
                    }
                    if (isAllowAudit)
                    {
                        inResult.Status        = "Complete";
                        inResult.ApproveStatus = "审核完成";
                        WCFAddUpdateResult ret = this.AddOrUpdate(inResult);
                        if (ret.KeyGuid.ToGuid() == Guid.Empty)
                        {
                            auditFlag = false;
                        }
                        else
                        {
                            #region 定义相关变量(可重复使用)
                            STK_InLineBLL stkInLineBLL = new STK_InLineBLL();
                            stkInLineBLL.SessionInfo = this.SessionInfo;
                            STK_StockBLL stkStockBLL = new STK_StockBLL();
                            stkStockBLL.SessionInfo = this.SessionInfo;
                            STK_StockSheetBLL stkStockSheetBLL = new STK_StockSheetBLL();
                            stkStockSheetBLL.SessionInfo = this.SessionInfo;
                            STK_StockReserveBLL reserveBLL = new STK_StockReserveBLL();
                            reserveBLL.SessionInfo = this.SessionInfo;

                            ORD_SalesOrderBLL saleOrderBLL = new ORD_SalesOrderBLL();
                            saleOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesOrderLineBLL saleOrderLineBLL = new ORD_SalesOrderLineBLL();
                            saleOrderLineBLL.SessionInfo = this.SessionInfo;

                            ORD_PurchaseOrderBLL purOrderBLL = new ORD_PurchaseOrderBLL();
                            purOrderBLL.SessionInfo = this.SessionInfo;
                            ORD_PurchaseOrderLineBLL purOrderLineBLL = new ORD_PurchaseOrderLineBLL();
                            purOrderLineBLL.SessionInfo = this.SessionInfo;

                            ORD_SalesReturnBLL returnBLL = new ORD_SalesReturnBLL();
                            returnBLL.SessionInfo = this.SessionInfo;
                            ORD_SalesReturnLineBLL returnLineBLL = new ORD_SalesReturnLineBLL();
                            returnLineBLL.SessionInfo = this.SessionInfo;

                            Guid?[] _ItemCodes = null;
                            List <STK_InLineResult> stkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                            {
                                StkInGuid = inResult.StkInGuid
                            });
                            #endregion
                            #region 形成库存,回写库存ID到入库明细,形成库存流水,预留库存 ,回写采购单,销售单的入库数量和入库状态
                            List <STK_StockResult>      stkStockList      = new List <STK_StockResult>();
                            List <STK_StockSheetResult> stkStockSheetList = new List <STK_StockSheetResult>();
                            if (stkInLineList != null && stkInLineList.Count > 0)
                            {
                                if (inResult.BillType == "SOR_IN")
                                {
                                    _ItemCodes   = stkInLineList.Where(a => a.ItemCode != null).Select(a => a.ItemCode).Distinct().ToArray();
                                    stkStockList = stkStockBLL.GetList(new STK_StockParam()
                                    {
                                        ItemCodes = _ItemCodes
                                    });
                                }
                                #region 形成库存,回写库存ID,形成流水
                                STK_StockResult      stkStockResult      = null;
                                STK_StockSheetResult stkStockSheetResult = null;
                                foreach (STK_InLineResult stkInLineResult in stkInLineList)
                                {
                                    //形成ItemCode,如果是采购入库则new一个实体,如果是销售退货入库则使用传递过来的退货明细的itemCode
                                    Guid?itemCode = null;

                                    #region 形成库存

                                    if (inResult.BillType == "PO_IN")//采购入库
                                    {
                                        itemCode                     = Guid.NewGuid();
                                        stkStockResult               = new STK_StockResult();
                                        stkStockResult.BuyerID       = stkInLineResult.BuyerID;
                                        stkStockResult.BuyerName     = stkInLineResult.BuyerName;
                                        stkStockResult.POGuid        = stkInLineResult.SourceBillGuid;
                                        stkStockResult.POBillNo      = stkInLineResult.SourceBillNo;
                                        stkStockResult.POLineGuid    = stkInLineResult.SourceBillLineGuid;
                                        stkStockResult.StkInGuid     = inResult.StkInGuid;
                                        stkStockResult.StkInBillNo   = inResult.BillNo;
                                        stkStockResult.StkInLineGuid = stkInLineResult.StkInLineGuid;
                                        stkStockResult.ItemCode      = itemCode;
                                        stkStockResult.Model         = stkInLineResult.Model;
                                        stkStockResult.Brand         = stkInLineResult.Brand;
                                        stkStockResult.Batch         = stkInLineResult.Batch;
                                        stkStockResult.Package       = stkInLineResult.Package;
                                        stkStockResult.Quality       = stkInLineResult.Quality;
                                        stkStockResult.MPQ           = stkInLineResult.MPQ;
                                        stkStockResult.MarkCode      = stkInLineResult.MarkCode;
                                        stkStockResult.Remark        = stkInLineResult.Remark;
                                        stkStockResult.Warehouse     = stkInLineResult.Warehouse;
                                        stkStockResult.Location      = stkInLineResult.Location;
                                        stkStockResult.InvType       = stkInLineResult.InvType;
                                        stkStockResult.InvQty        = stkInLineResult.Qty;
                                        stkStockResult.BookedQty     = 0;
                                        stkStockResult.UsableQty     = stkInLineResult.Qty;
                                        stkStockResult.Unit          = stkInLineResult.Unit;
                                        stkStockResult.Currency      = stkInLineResult.Currency;
                                        stkStockResult.BuyPrice      = stkInLineResult.CostPrice;
                                        stkStockResult.BuyPriceRMB   = stkInLineResult.CostPrice * stkInLineResult.ExchangeRate;
                                        stkStockList.Add(stkStockResult);

                                        stkInLineResult.ItemCode = itemCode; //回写入库明细的库存ID
                                    }
                                    else if (inResult.BillType == "SOR_IN")  //销售退货入库
                                    {
                                        itemCode                  = stkInLineResult.ItemCode;
                                        stkStockResult            = stkStockList.FirstOrDefault(a => a.ItemCode == stkInLineResult.ItemCode);
                                        stkStockResult.InvQty    += stkInLineResult.Qty;
                                        stkStockResult.UsableQty += stkInLineResult.Qty;
                                    }
                                    else if (inResult.BillType == "ZX_IN")
                                    {
                                    }
                                    #endregion

                                    #region 形成流水
                                    stkStockSheetResult                    = new STK_StockSheetResult();
                                    stkStockSheetResult.OperEmpID          = stkInLineResult.BuyerID;
                                    stkStockSheetResult.OperEmpName        = stkInLineResult.BuyerName;
                                    stkStockSheetResult.SSType             = 1;
                                    stkStockSheetResult.SourceBillGuid     = inResult.StkInGuid;
                                    stkStockSheetResult.SourceBillNo       = inResult.BillNo;
                                    stkStockSheetResult.SourceBillLineGuid = stkInLineResult.StkInLineGuid;
                                    stkStockSheetResult.ItemCode           = itemCode;
                                    stkStockSheetResult.Model              = stkInLineResult.Model;
                                    stkStockSheetResult.Brand              = stkInLineResult.Brand;
                                    stkStockSheetResult.Batch              = stkInLineResult.Batch;
                                    stkStockSheetResult.Package            = stkInLineResult.Package;
                                    stkStockSheetResult.Quality            = stkInLineResult.Quality;
                                    stkStockSheetResult.MPQ                = stkInLineResult.MPQ;
                                    stkStockSheetResult.MarkCode           = stkInLineResult.MarkCode;
                                    stkStockSheetResult.Currency           = stkInLineResult.Currency;
                                    stkStockSheetResult.FlowQty            = stkInLineResult.Qty;
                                    stkStockSheetResult.FlowPrice          = stkInLineResult.CostPrice;
                                    stkStockSheetResult.FlowAmount         = stkInLineResult.Amount;
                                    stkStockSheetList.Add(stkStockSheetResult);
                                    #endregion
                                }
                                stkStockBLL.UpdateOrInsertList(stkStockList);
                                stkStockSheetBLL.UpdateOrInsertList(stkStockSheetList);
                                stkInLineBLL.UpdateOrInsertList(stkInLineList);
                                #endregion
                                #region 预留库存
                                if (inResult.BillType == "PO_IN")//采购入库
                                {
                                    //有关联销售的采购入库会有销售明细Guid
                                    List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList();
                                    if (tempInLineList != null && tempInLineList.Count > 0)
                                    {
                                        Guid?[] POLineGuids = tempInLineList.Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        List <ORD_PurchaseOrderLineResult> purOrderLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                        {
                                            POLineGuids = POLineGuids
                                        });
                                        foreach (STK_InLineResult stkInLineResult in   tempInLineList)
                                        {
                                            //入库明细所对应的采购明细
                                            ORD_PurchaseOrderLineResult purOrderLineResult = purOrderLineList.FirstOrDefault(a => a.POLineGuid == stkInLineResult.SourceBillLineGuid);
                                            if (purOrderLineResult != null)
                                            {
                                                //创建预留明细
                                                STK_StockReserveResult reserveResult = new STK_StockReserveResult();
                                                reserveResult.SourceBillGuid     = purOrderLineResult.SOGuid;     //销售单guid
                                                reserveResult.SourceBillNo       = purOrderLineResult.SOBillNo;   //销售单编号
                                                reserveResult.SourceBillLineGuid = purOrderLineResult.SOLineGuid; //销售明细guid
                                                reserveResult.SourceBillType     = "销售出库";
                                                reserveResult.ReserveType        = 1;                             //采购预留
                                                reserveResult.OperType           = false;                         //系统预留
                                                reserveResult.StkInLineGuid      = stkInLineResult.StkInLineGuid; // 入库明细guid
                                                reserveResult.ItemCode           = stkInLineResult.ItemCode;
                                                reserveResult.OperFlag           = true;                          //增加
                                                reserveBLL.OperateReserve(reserveResult);
                                            }
                                        }
                                    }
                                }
                                #endregion
                                #region 回写关联单据的入库数量和入库状态
                                //入库单关联的入库明细
                                if (stkInLineList != null && stkInLineList.Count > 0)
                                {
                                    #region 定义相关变量(可重复使用)
                                    Guid?[] SOGuids     = null;
                                    Guid?[] SOLineGuids = null;

                                    Guid?   POGuid      = null;
                                    Guid?[] POLineGuids = null;

                                    Guid?   SRGuid      = null;
                                    Guid?[] SRLineGuids = null;

                                    Guid?[] StkInGuids = null;
                                    Guid?[] effInGuids = null;

                                    List <ORD_SalesReturnLineResult>   returnLineList = null;
                                    List <ORD_PurchaseOrderLineResult> purLineList    = null;

                                    List <STK_InResult>     inList         = null;
                                    List <STK_InLineResult> linkInLineList = null;
                                    List <STK_InLineResult> effInLineList  = null;
                                    #endregion
                                    if (inResult.BillType == "PO_IN")
                                    {
                                        #region 更新采购明细的入库数量和采购主单的入库状态
                                        //关联的采购主单
                                        POGuid = inResult.SourceBillGuid;
                                        //关联的采购明细ID集合
                                        POLineGuids = stkInLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        if (POLineGuids != null && POLineGuids.Length > 0)
                                        {
                                            //采购明细
                                            purLineList = purOrderLineBLL.GetList(new ORD_PurchaseOrderLineParam()
                                            {
                                                POLineGuids = POLineGuids
                                            });

                                            //采购明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SourceBillLineGuids = POLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //采购明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_PurchaseOrderLineResult purLineResult in purLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SourceBillLineGuid == purLineResult.POLineGuid).Sum(a => a.Qty.ToInt32());
                                                        purLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            purOrderLineBLL.UpdateOrInsertList(purLineList);
                                            purOrderBLL.UpdateStatus(new ORD_PurchaseOrderParam()
                                            {
                                                POGuid = POGuid
                                            });
                                        }
                                        #endregion
                                        #region 更新销售明细的入库数量和销售主单的入库状态

                                        List <STK_InLineResult> tempInLineList = stkInLineList.Where(a => a.SOLineGuid != null).ToList();
                                        if (tempInLineList != null)
                                        {
                                            //获取关联的销售明细ID集合
                                            SOLineGuids = tempInLineList.Select(a => a.SOLineGuid).Distinct().ToArray();
                                            List <ORD_SalesOrderLineResult> saleOrderLineList = saleOrderLineBLL.GetList(new ORD_SalesOrderLineParam()
                                            {
                                                SOLineGuids = SOLineGuids
                                            });
                                            //获取关联的销售明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SOLineGuids = SOLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //销售明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_SalesOrderLineResult saleLineResult in saleOrderLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SOLineGuid == saleLineResult.SOLineGuid).Sum(a => a.Qty.ToInt32());
                                                        saleLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            saleOrderLineBLL.UpdateOrInsertList(saleOrderLineList);
                                            SOGuids = saleOrderLineList.Select(a => a.SOGuid).Distinct().ToArray();
                                            foreach (Guid soguid in SOGuids)
                                            {
                                                saleOrderBLL.UpdateStatus(new ORD_SalesOrderParam()
                                                {
                                                    SOGuid = soguid
                                                });
                                            }
                                        }
                                        #endregion
                                    }
                                    else if (inResult.BillType == "SOR_IN")
                                    {
                                        #region 更新销售退货明细的入库数量和退货主单的入库状态
                                        //关联的销售退货主单
                                        SRGuid = inResult.SourceBillGuid;
                                        //关联的销售退货明细ID集合
                                        SRLineGuids = stkInLineList.Where(a => a.SourceBillLineGuid != null).Select(a => a.SourceBillLineGuid).Distinct().ToArray();
                                        if (SRLineGuids != null && SRLineGuids.Length > 0)
                                        {
                                            //退货明细
                                            returnLineList = returnLineBLL.GetList(new ORD_SalesReturnLineParam()
                                            {
                                                SRLineGuids = SRLineGuids
                                            });

                                            //退货明细所关联的入库明细
                                            linkInLineList = stkInLineBLL.GetList(new STK_InLineParam()
                                            {
                                                SourceBillLineGuids = SRLineGuids
                                            });
                                            StkInGuids = linkInLineList.Select(a => a.StkInGuid).Distinct().ToArray();
                                            if (StkInGuids != null && StkInGuids.Length > 0)
                                            {
                                                //退货明细所关联的入库明细对应的入库主单
                                                inList = this.GetList(new STK_InParam()
                                                {
                                                    StkInGuids = StkInGuids, Status = "Complete"
                                                });
                                                if (inList != null && inList.Count > 0)
                                                {
                                                    effInGuids    = inList.Select(a => a.StkInGuid).Distinct().ToArray();
                                                    effInLineList = linkInLineList.Where(a => effInGuids.Contains(a.StkInGuid)).ToList();
                                                    foreach (ORD_SalesReturnLineResult returnLineResult in returnLineList)
                                                    {
                                                        int?qty = effInLineList.Where(a => a.SourceBillLineGuid == returnLineResult.SRLineGuid).Sum(a => a.Qty.ToInt32());
                                                        returnLineResult.StkInQty = qty;
                                                    }
                                                }
                                            }
                                            returnLineBLL.UpdateOrInsertList(returnLineList);
                                        }

                                        #endregion
                                    }
                                    else if (inResult.BillType == "ZX_IN")
                                    {
                                    }
                                }
                                #endregion
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    throw new WarnException("要审核的采购单在系统中不存在!");
                }
            }
            catch (WarnException exp)
            {
                throw exp;
            }
            catch (Exception exp)
            {
                LogInfoBLL.WriteLog(this.SessionInfo, exp);
                throw exp;
            }
            return(auditFlag);
        }