示例#1
0
        /// <summary>
        /// 保存
        /// </summary>
        public bool SaveData()
        {
            #region 赋值
            InOutData inoutData = new InOutData();
            inoutData.isIn = true;
            //出入库类型
            inoutData.InOutType = (int)InOutType.OtherIn;
            //出入库状态
            inoutData.InOutStatus = (int)InOutStatus.AllReach;

            //出入库单号
            if (!string.IsNullOrEmpty(textEditInOutCode.Text))
            {
                inoutData.InOutCode = textEditInOutCode.Text;
                if (inoutHelper.ExistInOutCode(inoutData.InOutCode))
                {
                    XtraMessageBox.Show("此单号已存在", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textEditInOutCode.Focus();
                    return(false);
                }
            }
            else
            {
                inoutData.InOutCode = Guid.NewGuid().ToString();
            }

            //出入库时间
            if (string.IsNullOrEmpty(dateEditInTime.Text))
            {
                XtraMessageBox.Show("请填写入库日期", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateEditInTime.Focus();
                return(false);
            }
            inoutData.InOutDateTime = DateTime.Parse(dateEditInTime.Text);

            //业务员及编号
            if (string.IsNullOrEmpty(pceOperator.Text))
            {
                XtraMessageBox.Show("请填写业务员", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                pceOperator.Focus();
                return(false);
            }
            inoutData.Operator     = pceOperator.Text;
            inoutData.OperatorCode = pceOperator.Tag.ToString();

            //付款方式
            inoutData.PayType = comboPayType.SelectedIndex;
            //应付金额
            if (!string.IsNullOrEmpty(textEditNeedToPay.Text))
            {
                inoutData.NeedToPay = double.Parse(textEditNeedToPay.EditValue.ToString());
            }
            else
            {
                inoutData.NeedToPay = 0.0;
            }
            //本次付款金额
            if (!string.IsNullOrEmpty(textEditPayThisTime.Text))
            {
                inoutData.PayThisTime = double.Parse(textEditPayThisTime.EditValue.ToString());
            }
            else
            {
                inoutData.PayThisTime = 0.0;
            }
            //到账日期
            if (!string.IsNullOrEmpty(dateEditIncomeTime.Text))
            {
                inoutData.IncomeTime = DateTime.Parse(dateEditIncomeTime.Text);
            }
            else
            {
                inoutData.IncomeTime = DateTime.MinValue;
            }
            //合计金额
            if (!string.IsNullOrEmpty(textEditTotalFee.Text))
            {
                inoutData.TotalFee = double.Parse(textEditTotalFee.EditValue.ToString());
            }
            else
            {
                inoutData.TotalFee = 0.0;
            }
            //税率
            inoutData.Tax = 0.0;
            //税额
            if (!string.IsNullOrEmpty(textEditAmountTax.Text))
            {
                inoutData.AmountTax = double.Parse(textEditAmountTax.EditValue.ToString());
            }
            else
            {
                inoutData.AmountTax = 0.0;
            }
            //折扣金额
            if (!string.IsNullOrEmpty(textEditDiscountFee.Text))
            {
                inoutData.DiscountFee = double.Parse(textEditDiscountFee.EditValue.ToString());
            }
            else
            {
                inoutData.DiscountFee = 0.0;
            }
            //支付期限
            if (!string.IsNullOrEmpty(textEditPayTerm.Text))
            {
                inoutData.PayTerm = int.Parse(textEditPayTerm.Text);
            }

            //快递公司
            inoutData.FreightCompany = string.Empty;
            inoutData.FreightCode    = string.Empty;
            #endregion

            return(inoutHelper.Save(gvOtherInProduct, inoutData));
        }
示例#2
0
        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="gridView"></param>
        /// <param name="dateEditInTime"></param>
        public bool Save(GridView gridView, InOutData inoutData)
        {
            if (gridView == null || gridView.RowCount == 0)
            {
                XtraMessageBox.Show("没有可保存的数据", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            bool isSelectHouse = HouseSelect(gridView);

            if (!isSelectHouse)
            {
                XtraMessageBox.Show("需要选择仓库", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            bool isSelectLayout = LayoutSelect(gridView);

            if (!isSelectLayout)
            {
                XtraMessageBox.Show("需要选择库位", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }

            //用于存放要保存到数据库的StockProduct
            List <Alading.Entity.StockProduct> stockProductList = new List <StockProduct>();

            //用于存放要保存到数据库的StockHouseProduct
            List <Alading.Entity.StockHouseProduct> stockHouseProList = new List <StockHouseProduct>();

            //用于存放要保存到数据库的StockDetail
            List <Alading.Entity.StockDetail> stockDetailList = new List <StockDetail>();

            List <string> outerSkuIdList = new List <string>();

            List <string> outerIdList = new List <string>();

            for (int rowHandle = 0; rowHandle < gridView.RowCount; rowHandle++)
            {
                DataRow dataRow = gridView.GetDataRow(rowHandle);

                #region 更新StockItem  StockProduct StockHouseProduct
                Alading.Entity.StockProduct stockProduct = new StockProduct();

                stockProduct.SkuOuterID = dataRow["SkuOuterID"] == null ? string.Empty : dataRow["SkuOuterID"].ToString();
                stockProduct.OuterID    = dataRow["OuterId"] == null ? string.Empty : dataRow["OuterId"].ToString();
                //获取入库数量
                double inOutNum = 0.0;
                if (dataRow["Count"] == null || string.IsNullOrEmpty(dataRow["Count"].ToString()))
                {
                    stockProduct.SkuQuantity = 0;
                }
                else if (inoutData.isIn)
                {
                    inOutNum = double.Parse(dataRow["Count"].ToString());
                    stockProduct.SkuQuantity = int.Parse(inOutNum.ToString());
                }
                else
                {
                    inOutNum = double.Parse(dataRow["Count"].ToString());
                    stockProduct.SkuQuantity = -int.Parse(inOutNum.ToString());
                }
                //存放以准备保存到数据库
                stockProductList.Add(stockProduct);

                outerSkuIdList.Add(dataRow["SkuOuterID"].ToString());
                outerIdList.Add(dataRow["OuterId"].ToString());
                #endregion

                #region 添加或更新StockHouseProduct
                StockHouseProduct stockHousePro = new StockHouseProduct();
                stockHousePro.HouseCode  = dataRow["HouseCode"] == null ? string.Empty : dataRow["HouseCode"].ToString();
                stockHousePro.LayoutCode = dataRow["LayoutCode"] == null ? string.Empty : dataRow["LayoutCode"].ToString();
                stockHousePro.SkuOuterID = stockProduct.SkuOuterID;
                stockHousePro.Num        = stockProduct.SkuQuantity;
                stockHousePro.HouseName  = dataRow["HouseName"].ToString();
                stockHousePro.LayoutName = dataRow["LayoutName"].ToString();
                stockHouseProList.Add(stockHousePro);
                #endregion

                #region 添加到StockDetail
                Alading.Entity.StockDetail stockDetail = new StockDetail();

                stockDetail.StockDetailCode   = Guid.NewGuid().ToString();
                stockDetail.ProductSkuOuterId = stockProduct.SkuOuterID;
                stockDetail.InOutCode         = inoutData.InOutCode;
                //仓库编号
                stockDetail.StockHouseCode = dataRow["HouseCode"] == null ? string.Empty : dataRow["HouseCode"].ToString();
                //库位编号
                stockDetail.StockLayOutCode = dataRow["LayoutCode"] == null ? string.Empty : dataRow["LayoutCode"].ToString();
                //商品价格
                stockDetail.Price        = (float)stockProduct.SkuPrice;
                stockDetail.Quantity     = int.Parse(inOutNum.ToString());
                stockDetail.DetailType   = inoutData.InOutType;
                stockDetail.DetailRemark = dataRow["DetailRemark"] == null ? string.Empty : dataRow["DetailRemark"].ToString();
                //税率
                stockDetail.Tax      = dataRow["Tax"] == null ? string.Empty : dataRow["Tax"].ToString();
                stockDetail.TotalFee = dataRow["TotalMoney"] == null ? 0 : float.Parse(dataRow["TotalMoney"].ToString());
                //商品的保质期
                stockDetail.DurabilityDate = System.DateTime.MaxValue;

                stockDetailList.Add(stockDetail);
                #endregion
            }

            #region 添加StockInOut
            //用于存放StockInOut
            List <Alading.Entity.StockInOut> stockInOutList = new List <Alading.Entity.StockInOut>();
            Alading.Entity.StockInOut        stockInOut     = new Alading.Entity.StockInOut();

            //进出库单编号
            stockInOut.InOutCode    = inoutData.InOutCode;
            stockInOut.InOutTime    = inoutData.InOutDateTime;
            stockInOut.OperatorCode = inoutData.OperatorCode;
            //经办人员
            stockInOut.OperatorName = inoutData.Operator;
            stockInOut.InOutType    = inoutData.InOutType;
            //oid赋值
            stockInOut.TradeOrderCode = string.Empty;
            //付款方式
            stockInOut.PayType = inoutData.PayType;
            //保存现金折扣
            stockInOut.DiscountFee = float.Parse(inoutData.DiscountFee.ToString());
            //保存应付应收金额
            stockInOut.DueFee         = float.Parse(inoutData.NeedToPay.ToString());
            stockInOut.InOutStatus    = inoutData.InOutStatus;
            stockInOut.IsSettled      = true;
            stockInOut.PayThisTime    = float.Parse(inoutData.PayThisTime.ToString());
            stockInOut.PayTerm        = inoutData.PayTerm;
            stockInOut.IncomeTime     = inoutData.IncomeTime;
            stockInOut.AmountTax      = float.Parse(inoutData.AmountTax.ToString());
            stockInOut.FreightCompany = inoutData.FreightCompany;
            stockInOut.FreightCode    = inoutData.FreightCode;

            stockInOutList.Add(stockInOut);
            #endregion

            #region 添加或更新PayCharge
            PayCharge payCharge = new PayCharge();
            payCharge.PayChargeCode = Guid.NewGuid().ToString();
            //付款收款方式
            payCharge.PayChargeType = inoutData.InOutType;
            payCharge.InOutCode     = inoutData.InOutCode;
            //付款人编号
            payCharge.PayerCode = string.Empty;
            //付款人名字
            payCharge.PayerName = string.Empty;
            //收款人编号
            payCharge.ChargerCode = string.Empty;
            //收款人名字
            payCharge.ChargerName = string.Empty;
            //操作时间
            payCharge.OperateTime     = DateTime.Parse(DateTime.Now.ToShortDateString());
            payCharge.OperatorCode    = inoutData.OperatorCode;
            payCharge.OperatorName    = inoutData.Operator;
            payCharge.PayChargeRemark = string.Empty;

            payCharge.TotalFee    = inoutData.TotalFee;
            payCharge.NeedToPay   = inoutData.NeedToPay;
            payCharge.AmountTax   = inoutData.AmountTax;
            payCharge.PayThisTime = inoutData.PayThisTime;
            payCharge.DiscountFee = inoutData.DiscountFee;
            payCharge.IncomeDay   = inoutData.PayTerm;
            payCharge.IncomeTime  = inoutData.IncomeTime;
            #endregion

            StockProductService.UpdateStock(stockProductList, stockHouseProList, stockInOutList, stockDetailList, payCharge, outerSkuIdList, outerIdList);
            return(true);
        }