private void btnReduce_Click(object sender, EventArgs e) { if (creatingBill) { int IdFood = Int32.Parse(gridView3.GetFocusedRowCellValue("IdFood").ToString()); int reduceNumber = Convert.ToInt32(number.Value); int Total = Int32.Parse(gridView3.GetFocusedRowCellValue("Total").ToString()); int Number = Int32.Parse(gridView3.GetFocusedRowCellValue("Number").ToString()); int Price = Total / Number; DataRow[] customerRow = billInfo.Select("IdFood =" + IdFood); if (reduceNumber >= Number) { customerRow[0].Delete(); } else { customerRow[0]["Number"] = Number - reduceNumber; customerRow[0]["Total"] = (Number - reduceNumber) * Price; } } else { if (moving == false) { int IdFood = Int32.Parse(gridView3.GetFocusedRowCellValue("IdFood").ToString()); int reduceNumber = Convert.ToInt32(number.Value); int Total = Int32.Parse(gridView3.GetFocusedRowCellValue("Total").ToString()); int Number = Int32.Parse(gridView3.GetFocusedRowCellValue("Number").ToString()); int Price = Total / Number; DataRow[] customerRow = billInfo.Select("IdFood =" + IdFood); DataRow[] billRow = ((DataTable)gcBillTakeAway.DataSource).Select("IdBill =" + currentIdBill); if (reduceNumber >= Number) { if (billInfo.Rows.Count > 1) { customerRow[0].Delete(); BillDetails_BUS.DeleteBillInfo(currentIdBill, IdFood); Bill_BUS.EditTotalOfBill(currentIdBill, Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString())); // billRow[0]["TotalPrice"] = Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString()); } else { MessageBox.Show("Không thể để hóa đơn trống."); } } else { customerRow[0]["Number"] = Number - reduceNumber; customerRow[0]["Total"] = (Number - reduceNumber) * Price; BillDetails_BUS.EditNumberOfInfo(new BillDetails_DTO(currentIdBill, IdFood, Number - reduceNumber)); Bill_BUS.EditTotalOfBill(currentIdBill, Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString())); if (tableofbill.Rows.Count < 1) { billRow[0]["TotalPrice"] = Int32.Parse(gridColumn6.SummaryItem.SummaryValue.ToString()); } } } } }
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()); } } } }