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!"); } }
public string CreateReceipt(DTO_Receipt newReceipt) { DataTable receipts = GetReceipt(-1, 0); if (receipts.Rows.Count != 0) { string lastID = receipts.Rows[receipts.Rows.Count - 1]["ReceiptID"].ToString(); newReceipt.ReceiptID = "R" + (Convert.ToInt32(lastID.Replace("R", "")) + 1) .ToString() .PadLeft(9, '0'); } else { newReceipt.ReceiptID = "R000000001"; } //insert SQLite string sql = $"INSERT INTO Receipt (ReceiptID, Time, EmployeeID, DiscountID) VALUES ('{newReceipt.ReceiptID}', DateTime('now'), '{newReceipt.EmployeeID}', '{newReceipt.DiscountID}')"; if (newReceipt.DiscountID == "") { sql = $"INSERT INTO Receipt (ReceiptID, Time, EmployeeID) VALUES ('{newReceipt.ReceiptID}', DateTime('now'), '{newReceipt.EmployeeID}')"; } SQLiteCommand insert = new SQLiteCommand(sql, getConnection().OpenAndReturn()); try { insert.ExecuteNonQuery(); return(newReceipt.ReceiptID); } catch (Exception ex) { Console.WriteLine(ex.Message); return(""); } }
public string CreateReceipt(DTO_Receipt newReceipt) { return(dalReceipt.CreateReceipt(newReceipt)); }