private void DgvGoodAdd(List <EtSale> sales)
 {
     DgvGoodInfo.Rows.Clear();
     sales = SaleDao.QueryBySaleID(sales[0].SaleID);
     for (int i = 0; i < sales.Count; i++)
     {
         goods = GoodDao.QueryByGoodID(sales[i].Good.GoodID);
         DgvGoodInfo.Rows.Add(new object[] {
             goods[0].GoodID,
             goods[0].Category.CategoryName,
             goods[0].Category.Unit,
             goods[0].Price
         });
     }
 }
示例#2
0
 private void BtnInsert_Click(object sender, EventArgs e)
 {
     try {
         EtSale sale = new EtSale {
             SaleID = 0,
             Good   = GoodDao.QueryByGoodID(int.Parse(CmbGoodID.SelectedItem.ToString().Split(' ')[0]))[0]
         };
         sale.Profit     = int.Parse(TxtPrice.Text) - sale.Good.Cost;
         sale.Good.Price = int.Parse(TxtPrice.Text);
         sale.Good.State = Enums.EState.已出售;
         FrmSale.Sales.Add(sale);
         Close();
     }
     catch (Exception) {
         MsgBoxUtil.ErrMsgBox("输入不得为空!");
     }
 }
        private EtSale ParseSale(IRow row)
        {
            if ("" == row.GetCell(0).ToString())
            {
                errInfo = "商品不存在";
                hasErr  = true;
                return(null);
            }
            int           goodID = int.Parse(row.GetCell(0).ToString());
            List <EtGood> goods  = GoodDao.QueryByGoodID(goodID);

            if (0 == goods.Count || goods[0].State != Enums.EState.未出售)
            {
                errInfo = "商品不存在";
                hasErr  = true;
                return(null);
            }
            if ("" == row.GetCell(1).ToString())
            {
                errInfo = "销售日期不能为空";
                hasErr  = true;
                return(null);
            }
            string saleDate = row.GetCell(1).ToString();

            if ("" == row.GetCell(2).ToString())
            {
                errInfo = "售价不能为空";
                hasErr  = true;
                return(null);
            }
            int    price = int.Parse(row.GetCell(2).ToString());
            EtSale sale  = new EtSale {
                SaleID   = 0,
                Good     = goods[0],
                SaleDate = saleDate,
                Profit   = price - goods[0].Cost
            };

            return(sale);
        }
 private void BtnQuery_Click(object sender, EventArgs e)
 {
     if (TxtQuery.Text != "")
     {
         List <EtSale> subSales = new List <EtSale>();
         List <EtGood> subGoods = new List <EtGood>();
         string        query    = TxtQuery.Text;
         string        RegexStr = "^[0-9]+$";
         if (RdoSale.Checked)
         {
             if (Regex.IsMatch(query, RegexStr))
             {
                 subSales = SaleDao.QueryBySaleID(int.Parse(query));
                 if (subSales.Count == 0)
                 {
                     subSales = SaleDao.QueryByStaffID(int.Parse(query));
                 }
             }
             if (subSales.Count == 0)
             {
                 MsgBoxUtil.ErrMsgBox("未找到销售单!");
             }
             else
             {
                 subGoods = GoodDao.QueryByGoodID(subSales[0].Good.GoodID);
             }
         }
         else
         {
             if (Regex.IsMatch(query, RegexStr))
             {
                 subGoods = GoodDao.QueryByGoodID(int.Parse(query));
             }
             else
             {
                 subGoods = GoodDao.QueryByCategoryID(CategoryDao.QueryByCategoryName(query)[0].CategoryID);
             }
             if (subGoods.Count == 0)
             {
                 MsgBoxUtil.ErrMsgBox("未找到商品!");
             }
             else
             {
                 for (int i = 0; i < subGoods.Count; i++)
                 {
                     if (subGoods[i].State == Enums.EState.已出售)
                     {
                         subSales.Add(SaleDao.QueryByGoodID(subGoods[i].GoodID)[0]);
                     }
                     else
                     {
                         subGoods.RemoveAt(i);
                         i--;
                     }
                 }
             }
         }
         DgvAdd(subSales, subGoods);
     }
     else
     {
         MsgBoxUtil.ErrMsgBox("请输入查询条件!");
     }
 }