コード例 #1
0
 private void btnAddInfo_Click(object sender, EventArgs e)
 {
     btnReduce.Enabled = true;
     if (creatingBill)
     {
         int       IdFood      = Int32.Parse(gridView2.GetFocusedRowCellValue("IdFood").ToString());
         int       Number      = Convert.ToInt32(number.Value);
         int       Price       = Int32.Parse(gridView2.GetFocusedRowCellValue("Price").ToString());
         DataRow[] customerRow = billInfo.Select("IdFood =" + IdFood);
         if (customerRow.Length > 0)
         {
             int TotalNumber = Int32.Parse(customerRow[0]["Number"].ToString()) + Number;
             customerRow[0]["Number"] = TotalNumber;
             customerRow[0]["Total"]  = Price * TotalNumber;
         }
         else
         {
             string FoodName = gridView2.GetFocusedRowCellValue("Name").ToString();
             string NameUnit = gridView2.GetFocusedRowCellValue("NameUnit").ToString();
             int    Total    = Price * Number;
             billInfo.Rows.Add(1, 1, IdFood, NameUnit, FoodName, Number, Total);
         }
     }
     else
     {
         if (moving == false)
         {
             int       IdFood      = Int32.Parse(gridView2.GetFocusedRowCellValue("IdFood").ToString());
             int       Number      = Convert.ToInt32(number.Value);
             int       Price       = Int32.Parse(gridView2.GetFocusedRowCellValue("Price").ToString());
             DataRow[] customerRow = billInfo.Select("IdFood =" + IdFood);
             DataRow[] billRow     = ((DataTable)gcBillTakeAway.DataSource).Select("IdBill =" + currentIdBill);
             if (customerRow.Length > 0)
             {
                 int TotalNumber = Int32.Parse(customerRow[0]["Number"].ToString()) + Number;
                 customerRow[0]["Number"] = TotalNumber;
                 customerRow[0]["Total"]  = Price * TotalNumber;
                 BillDetails_BUS.EditNumberOfInfo(new BillDetails_DTO(currentIdBill, IdFood, TotalNumber));
             }
             else
             {
                 string FoodName = gridView2.GetFocusedRowCellValue("Name").ToString();
                 string NameUnit = gridView2.GetFocusedRowCellValue("NameUnit").ToString();
                 int    Total    = Price * Number;
                 billInfo.Rows.Add(1, currentIdBill, IdFood, NameUnit, FoodName, Number, Total);
                 BillDetails_BUS.InsertBillDetail(new BillDetails_DTO(currentIdBill, IdFood, Number));
             }
             Bill_BUS.EditTotalOfBill(currentIdBill, Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString()));
             if (tableofbill.Rows.Count < 1)
             {
                 billRow[0]["TotalPrice"] = Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString());
             }
         }
     }
 }
コード例 #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (billInfo.Rows.Count > 0)
     {
         Bill_DTO newBill = new Bill_DTO(Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString()), 0, DateTime.Now);
         //Bill_DTO newBill = new Bill_DTO(Int32.Parse(tbTotal.Text), 0, DateTime.Now);
         Bill_BUS.InsertBill(newBill);
         currentIdBill = Bill_BUS.GetLastIdBill();
         //xu ly bill info
         for (int i = 0; i < billInfo.Rows.Count; i++)
         {
             int idFood = Int32.Parse(billInfo.Rows[i]["IdFood"].ToString());
             int number = Int32.Parse(billInfo.Rows[i]["Number"].ToString());
             BillDetails_BUS.InsertBillDetail(new BillDetails_DTO(currentIdBill, idFood, number));
         }
         //billInfo.Rows.Clear();
         //xu ly table of bill
         nameBill.Text = "Hóa Đơn - Bàn ";
         for (int i = 0; i < tableofbill.Rows.Count; i++)
         {
             //int status = Int32.Parse(foundRows[0]["Status"].ToString());
             int       idTable   = Int32.Parse(tableofbill.Rows[i]["IdTable"].ToString());
             DataRow[] foundRows = tablelist.Select("IdTable = " + idTable);
             foundRows[0]["Status"] = 1;
             Table_BUS.EditStatusOfTable(idTable, 1);
             BillTable_BUS.AddTableIntoBill(new BillTable_DTO(currentIdBill, idTable));
             ((Button)flowLayoutPanel1.Controls[tableofbill.Rows[i]["IdTable"].ToString()]).Image = (Image)(Properties.Resources.occupy);
             flowLayoutPanel1.Controls[tableofbill.Rows[i]["IdTable"].ToString()].BackColor       = Color.FromArgb(249, 64, 64);
             nameBill.Text += " " + flowLayoutPanel1.Controls[tableofbill.Rows[i]["IdTable"].ToString()].Text.Trim();
         }
         if (tableofbill.Rows.Count < 1)
         {
             gcBillTakeAway.DataSource = Bill_BUS.LoadBillTakeAway();
             nameBill.Text             = "Hóa Đơn - " + currentIdBill + " (Mang về)";
         }
         //tableofbill.Rows.Clear();
         btnCreateBill.Visible = true;
         //btnAddInfo.Enabled = false;
         btnCancel.Visible = false;
         //btnReduce.Enabled = false;
         btnSave.Visible      = false;
         btnPay.Enabled       = true;
         btnPrint.Enabled     = true;
         btnTeminate.Enabled  = true;
         btnMove.Enabled      = true;
         creatingBill         = false;
         refreshTable.Enabled = true;
         //tbTotal.Text = "0";
     }
     else
     {
         MessageBox.Show("Không thể lập hóa đơn trống");
     }
 }