// // // CARLO - END // // // // // VINCENT - START // // private void ProcessTransaction() { TableOrder tableOrder = fTableOrder.GetTableOrder(); tableOrder.SetPaymentMethod(fPayment.TextBlock_PaymentMethod.Text); System.Diagnostics.Debug.WriteLine(tableOrder.GetPaymentMethod()); //Set fTableOrder visuals fTableOrder.DisableForm(); //Save Transaction to accdb Database SaveTransactionToDatabase(); //Clear TableOrder temporary database fTableOrder.GetTableOrder().ClearTableOrder(); fTableOrder.GetTableOrder().SetTableStatus(TableOrder.CLOSED_BILL); }
private void SaveTransactionToDatabase() { TableOrder tableOrder = fTableOrder.GetTableOrder(); String path = Assembly.GetExecutingAssembly().Location; path = path.Replace("bin\\Debug\\ICTProjectPOS.exe", "RestaurantDB.accdb"); String connectionString = String.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", path); OleDbConnection connection = new OleDbConnection(connectionString); //OPEN CONNECTION connection.Open(); String employeeID = "EMP001"; DateTime dateTime = new DateTime(); dateTime = DateTime.Now; OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = "SELECT COUNT(*) FROM Invoice"; cmd.Connection = connection; int invoiceNumber = (int)cmd.ExecuteScalar() + 1; cmd.CommandText = "INSERT INTO Invoice([InvoiceNum],[TableNum],[EmployeeID], [DineDate], [DineTime], [TotalOrder], [PayMethod]) VALUES (?, ?, ?, ?, ?, ?, ?)"; cmd.Parameters.AddWithValue("InvoiceNum", invoiceNumber); cmd.Parameters.AddWithValue("TableNum", tableOrder.GetTableNumber()); cmd.Parameters.AddWithValue("EmployeeId", employeeID); cmd.Parameters.AddWithValue("DineDate", dateTime.Date); cmd.Parameters.AddWithValue("DineTime", dateTime.TimeOfDay); cmd.Parameters.AddWithValue("TotalOrder", tableOrder.GetAmountDue()); cmd.Parameters.AddWithValue("PayMethod", tableOrder.GetPaymentMethod()); cmd.ExecuteNonQuery(); connection.Close(); connection.Open(); foreach (Item item in tableOrder.GetItemsOrdered()) { OleDbCommand cmd2 = new OleDbCommand(); cmd2.Connection = connection; cmd2.CommandText = "SELECT * FROM Item WHERE ItemName LIKE ?"; cmd2.Parameters.AddWithValue("ItemName", "%" + item.GetName() + "%"); string itemID = ""; OleDbDataReader dr = cmd2.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { itemID = dr[0].ToString(); } } OleDbCommand cmd3 = new OleDbCommand(); cmd3.Connection = connection; cmd3.CommandText = "INSERT INTO InvoiceItem ([InvoiceNum], [ItemID], [Quantity]) Values (?, ?, ?)"; cmd3.Parameters.AddWithValue("@InvoiceNum", invoiceNumber); cmd3.Parameters.AddWithValue("@ItemID", itemID); cmd3.Parameters.AddWithValue("@Quantity", item.GetQuantity()); cmd3.ExecuteNonQuery(); } //CLOSE CONNECTION connection.Close(); }