Ejemplo n.º 1
0
        private bool IsExisted()
        {
            SalesListDetail salesListDetail = null;
            // linq查询判断商品明细中是否已经存在跟商品条码相同的商品
            var pList = from p in salesListDetailList
                        where string.Equals(p.ProductId, this.textBoxProductId.Text.Trim())
                        select p;

            // 在明细列表中找到了与添加的商品
            if (pList.Count() > 0)
            {
                salesListDetail = pList.First();
                // 数量累加
                salesListDetail.Quantity += Convert.ToInt32(this.textBoxCount.Text.Trim());
                // 计算合计
                salesListDetail.SubTotalMoney = CalculateSubTotal(salesListDetail.UnitPrice,
                                                                  salesListDetail.Discount,
                                                                  salesListDetail.Quantity);
                this.bs.ResetBindings(true);
                return(true);
            }
            else
            {
                return(false);
            }
        }
    protected void Button_DelItem_Click(object sender, EventArgs e) //删除一个选项
    {
        int[] arr = ListBox1.GetSelectedIndices();
        int   len = arr.Length;

        for (int i = 0; i < len; ++i)
        {
            string strdel = ListBox1.Items[arr[i]].Text;
            ListBox1.Items.Remove(strdel);
            Response.Write(arr[i].ToString() + " " + strdel);
            SalesListDetail sld = new SalesListDetail();
            sld = saleslist[arr[i]];
            decimal curTot = Convert.ToDecimal(TextBox_Cur_TotMoney.Text) - sld.SubTotalMoney;
            TextBox_Cur_TotMoney.Text = curTot.ToString();
            saleslist.Remove(sld);
            string pid = sld.ProductId;
            if (htProidToCnt.Contains(pid))
            {
                int preCnt = (int)htProidToCnt[pid];
                htProidToCnt.Remove(pid);
                if (preCnt > sld.Quantity)
                {
                    htProidToCnt.Add(pid, preCnt - sld.Quantity);
                }
            }
        }
    }
Ejemplo n.º 3
0
        //添加新商品到销售明细,返回false则表明失败
        private bool AddProductList()
        {
            Product product = objProductService.GetProductInfo(this.txtProductId.Text.Trim());

            if (product == null)//未查到商品的情况下,允许手工添加
            {
                DialogResult result = MessageBox.Show("未查询到商品信息,手工录入商品,请检查单价和折扣是否录入正确,确定吗?", "询问信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result != DialogResult.Yes)
                {
                    return(false);
                }
                //先判断单价和折扣是否输入正确
                if (!DataValidate.IsDecimalNum(this.txtUnitPrice.Text.Trim()) || Convert.ToDecimal(this.txtUnitPrice.Text.Trim()) == 0)
                {
                    MessageBox.Show("手工录入商品,单价输入不正确", "提示信息");
                    this.txtUnitPrice.SelectAll();
                    this.txtUnitPrice.Focus();
                    return(false);
                }
                if (!DataValidate.IsDecimalNum(this.txtDiscount.Text.Trim()))
                {
                    MessageBox.Show("手工录入商品,折扣输入不正确", "提示信息");
                    this.txtDiscount.SelectAll();
                    this.txtDiscount.Focus();
                    return(false);
                }
                product = new Product()
                {
                    ProductId       = this.txtProductId.Text.Trim(),
                    ProductFullName = "手工录入商品",
                    UnitPrice       = Convert.ToDecimal(this.txtUnitPrice.Text.Trim()),
                    Discount        = Convert.ToDouble(this.txtDiscount.Text.Trim())
                };
            }
            SalesListDetail objSaleDetail = new SalesListDetail()
            {
                ProductId       = product.ProductId,
                ProductFullName = product.ProductFullName,
                UnitPrice       = product.UnitPrice,
                Discount        = product.Discount,
                Quantity        = Convert.ToInt32(this.txtQuantity.Text.Trim())
            };

            objSaleDetail.SubTotalMoney = objSaleDetail.Quantity * objSaleDetail.UnitPrice;
            if (objSaleDetail.Discount != 0)
            {
                objSaleDetail.SubTotalMoney *= Convert.ToDecimal(objSaleDetail.Discount / 10);
                objSaleDetail.SubTotalMoney  = Decimal.Round(objSaleDetail.SubTotalMoney, 2);
            }
            objSaleDetail.Num = this.mainSaleList.SalesListDetail.Count + 1;
            this.mainSaleList.SalesListDetail.Add(objSaleDetail);
            return(true);
        }
Ejemplo n.º 4
0
        private void AddtoDetailList(Products objProduct, int count)
        {
            // 封装
            SalesListDetail salesListDetail = new SalesListDetail()
            {
                // 封装流水号
                SerialNumber = this.textBoxSerialNumber.Text,
                ProductId    = objProduct.ProductId,
                ProductName  = objProduct.ProductName,
                UnitPrice    = objProduct.UnitPrice,
                Discount     = objProduct.Discount,
                Quantity     = count
            };

            // 计算合计
            salesListDetail.SubTotalMoney = CalculateSubTotal(salesListDetail.UnitPrice,
                                                              salesListDetail.Discount,
                                                              salesListDetail.Quantity);
            this.salesListDetailList.Add(salesListDetail);

            this.bs.ResetBindings(true);
        }
Ejemplo n.º 5
0
 private void TxtProductId_KeyDown(object sender, KeyEventArgs e)
 {
     if (this.txtProductId.Text.Trim().Length != 0 && e.KeyValue == 13) //回车键
     {
         if (!DataValidate.IsInteger(this.txtQuantity.Text.Trim()))     //查找商品前先检查数量输入是否正确
         {
             MessageBox.Show("数量输入不正确", "校验提示");
             this.txtQuantity.SelectAll();
             this.txtQuantity.Focus();
             return;
         }
         try
         {
             if (this.dgvProdutList.RowCount == 0 || this.lblSerialNum.Text.Length == 0)//第一次扫描生成序列号
             {
                 this.lblTotalMoney.Text    = "0.00";
                 this.lblReceivedMoney.Text = "0.00";
                 this.lblReturnMoney.Text   = "0.00";
                 this.lblSerialNum.Text     = CreateSerialNum();
             }
             var pList = from p in this.mainSaleList.SalesListDetail where p.ProductId.Equals(this.txtProductId.Text.Trim()) select p;
             if (pList.Count() > 0)//已经在列表中
             {
                 SalesListDetail objSalesDetail = pList.FirstOrDefault <SalesListDetail>();
                 objSalesDetail.Quantity     += Convert.ToInt32(this.txtQuantity.Text.Trim());
                 objSalesDetail.SubTotalMoney = objSalesDetail.Quantity * objSalesDetail.UnitPrice;
                 if (objSalesDetail.Discount != 0)
                 {
                     objSalesDetail.SubTotalMoney *= Convert.ToDecimal(objSalesDetail.Discount / 10);
                     objSalesDetail.SubTotalMoney  = Decimal.Round(objSalesDetail.SubTotalMoney, 2);
                 }
             }
             else
             {
                 bool addResult = AddProductList();
                 if (!addResult)
                 {
                     return;
                 }
             }
             //显示数据(测试不使用BindingSource)
             this.dgvProdutList.DataSource = null;
             this.bs.DataSource            = this.mainSaleList.SalesListDetail;
             //if (this.mainSaleList.SalesListDetail != null && this.mainSaleList.SalesListDetail.Count > 0)//第一次绑定时候判断是否有值,否则会引发点击dgv异常
             //this.dgvProdutList.DataSource = this.mainSaleList.SalesListDetail;
             this.dgvProdutList.DataSource = this.bs;
             this.bs.MoveLast();
             //更新商品总金额
             this.lblTotalMoney.Text = (from d in this.mainSaleList.SalesListDetail select d.SubTotalMoney).Sum().ToString();
             //还原输入列表
             this.txtProductId.Clear();
             this.txtQuantity.Text  = "1";
             this.txtUnitPrice.Text = "0.00";
             this.txtDiscount.Text  = "0";
         }
         catch (Exception ex)
         {
             MessageBox.Show("扫码出现异常,请重试" + ex.Message, "错误提示");
             return;
         }
     }
 }