void LoadData(string id) { tbReceiptID.Text = id; BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail(); DataTable detailData = busReceiptDetail.GetDetailByID(id); tbDate.Text = TimeZone.CurrentTimeZone.ToLocalTime((DateTime)detailData.Rows[0]["Time"]).ToString("dd/MM/yyyy"); tbEmployeeName.Text = detailData.Rows[0]["EmployeeName"].ToString(); List <DetailItem> detailItems = new List <DetailItem>(); int total = 0; foreach (DataRow row in detailData.Rows) { string bevName = row["BeverageName"].ToString(); int amount = Int32.Parse(row["Amount"].ToString()); int price = Int32.Parse(row["Total"].ToString()); int unitprice = Int32.Parse(row["UnitPrice"].ToString()); total += price; detailItems.Add(new DetailItem(bevName, amount, unitprice, price)); } dgReceiptDetail.ItemsSource = detailItems; dgReceiptDetail.Items.Refresh(); tbTotal.Text = MoneyToString(total); BUS_Discount busDis = new BUS_Discount(); int disValue = Int32.Parse(busDis.findDiscount(detailData.Rows[0]["DiscountID"].ToString()).DiscountValue.ToString()); tbDiscount.Text = disValue.ToString(); tbTotalPay.Text = MoneyToString((int)(total * (1 - disValue / 100.0))); }
private void btnCash_Click(object sender, RoutedEventArgs e) { if (billItems.Count == 0) { /// return; } if (newReceiptID != "") { MessageBox.Show($"Hóa đơn này đã thanh toán, mã hóa đơn là {newReceiptID}!"); return; } BUS_Discount busDiscount = new BUS_Discount(); DTO_Discount curDiscount = busDiscount.GetCurrentDiscount(); string disID = ""; if (curDiscount.DiscountValue != 0) { disID = curDiscount.DiscountID; } DTO_Receipt newReceipt = new DTO_Receipt("", user, disID); BUS_Receipt busReceipt = new BUS_Receipt(); newReceiptID = busReceipt.CreateReceipt(newReceipt); if (newReceiptID != "") { BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail(); bool result = true; foreach (BillItem item in billItems) { DTO_ReceiptDetail newReceiptDetail = new DTO_ReceiptDetail(newReceiptID, item.id, item.amount, item.unitCost); result = result & busReceiptDetail.CreateReceiptDetail(newReceiptDetail); } if (result) { MessageBox.Show("Tạo hóa đơn thành công!"); } else { MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo chi tiết hóa đơn!"); } } else { MessageBox.Show("Đã xảy ra lỗi trong quá trình tạo hóa đơn!"); } }
private void btSave_Click(object sender, RoutedEventArgs e) { switch (this.type) { case 1: /// Delete Account BUS_ReceiptDetail busReceiptDetail = new BUS_ReceiptDetail(); bool result1 = busReceiptDetail.DeleteDetailByID(deleteid); if (result1) { BUS_Receipt busReceipt = new BUS_Receipt(); if (busReceipt.DeleteReceiptByID(deleteid)) { MessageBox.Show($"Đã xóa hóa đơn {deleteid}."); Window.GetWindow(this).Close(); } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa hóa đơn!"); } } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa chi tiết hóa đơn."); } break; case 2: BUS_Payment bus = new BUS_Payment(); if (bus.deletePayment(deleteid) > 0) { MessageBox.Show($"Đã xóa phiếu chi {deleteid}."); } else { MessageBox.Show($"Đã xảy ra lỗi trong quá trình xóa phiếu chi!"); } Window.GetWindow(this).Close(); break; } }