/// <summary> /// Updates the cashier's Excel sheet to include customer order /// </summary> private void updateCashierExcelSheet() { try { // Opens Excel Sheet Excel.Application xlApp = new Excel.Application(); xlApp.Visible = false; xlApp.DisplayAlerts = false; Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(GlobalUtilities.getCashierAndEventFilePath(), 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); Excel.Worksheet xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); // Edits Excel Sheet Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count + 1; string date = DateTime.Now.Date.ToString("dd/MM/yyyy"); string time = DateTime.Now.ToString("h:mm:ss tt"); List <string> keyList = new List <string>(GlobalUtilities.getCustomerTransactionDictionary().Keys); double percentCash = Math.Round((Double.Parse(GlobalUtilities.getCashPayment()) / GlobalUtilities.getTotalCustomerPayment()), 2); double percentDebit = Math.Round((Double.Parse(GlobalUtilities.getDebitPayment()) / GlobalUtilities.getTotalCustomerPayment()), 2); double percentCredit = Math.Round((Double.Parse(GlobalUtilities.getCreditPayment()) / GlobalUtilities.getTotalCustomerPayment()), 2); double percentCheck = Math.Round((Double.Parse(GlobalUtilities.getCheckPayment()) / GlobalUtilities.getTotalCustomerPayment()), 2); double percentSalaryDeduction = Math.Round((Double.Parse(GlobalUtilities.getSalaryDeductionPayment()) / GlobalUtilities.getTotalCustomerPayment()), 2); for (int i = 0; i < GlobalUtilities.getCustomerTransactionDictionary().Count; i++) { List <string> customerOrder = GlobalUtilities.getProductInfoFromDictionary(GlobalUtilities.CUSTOMER, keyList[i]); xlWorksheet.Cells[rowCount + i, 1] = GlobalUtilities.getCustomerName(); xlWorksheet.Cells[rowCount + i, 2] = keyList[i]; xlWorksheet.Cells[rowCount + i, 3] = customerOrder[1]; xlWorksheet.Cells[rowCount + i, 4] = customerOrder[2]; xlWorksheet.Cells[rowCount + i, 5] = customerOrder[3]; xlWorksheet.Cells[rowCount + i, 6] = customerOrder[4]; xlWorksheet.Cells[rowCount + i, 7] = GlobalUtilities.getCustomerType(); xlWorksheet.Cells[rowCount + i, 8] = GlobalUtilities.getCashPayment(); xlWorksheet.Cells[rowCount + i, 9] = GlobalUtilities.getDebitPayment(); xlWorksheet.Cells[rowCount + i, 10] = GlobalUtilities.getCreditPayment(); xlWorksheet.Cells[rowCount + i, 11] = GlobalUtilities.getCheckPayment(); xlWorksheet.Cells[rowCount + i, 12] = GlobalUtilities.getSalaryDeductionPayment(); xlWorksheet.Cells[rowCount + i, 13] = date; xlWorksheet.Cells[rowCount + i, 14] = time; } // Saves Excel sheet xlWorkbook.SaveAs(GlobalUtilities.getCashierAndEventFilePath()); xlWorkbook.Close(true, Type.Missing, Type.Missing); xlApp.Quit(); Marshal.ReleaseComObject(xlWorksheet); Marshal.ReleaseComObject(xlWorkbook); Marshal.ReleaseComObject(xlApp); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// calculates the customer's change (total amount - customer payment), /// this will determine whether or not the cashier can proceed to the next form /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CalculateButton_Click(object sender, EventArgs e) { GlobalUtilities.setCashPayment(cashTextBox.Text); GlobalUtilities.setCreditPayment(creditTextBox.Text); GlobalUtilities.setDebitPayment(debitTextBox.Text); GlobalUtilities.setCheckPayment(checkTextBox.Text); GlobalUtilities.setSalaryDeductionPayment(salaryDeductionTextBox.Text); GlobalUtilities.setTotalCustomerPayment(); GlobalUtilities.setTotalChange(); changeTextBox.Text = String.Format("{0:n}", GlobalUtilities.getTotalChange()); totalCustomerPaymentTextBox.Text = String.Format("{0:n}", (Double.Parse(GlobalUtilities.getCashPayment()) + Double.Parse(GlobalUtilities.getCreditPayment()) + Double.Parse(GlobalUtilities.getDebitPayment()) + Double.Parse(GlobalUtilities.getCheckPayment()) + Double.Parse(GlobalUtilities.getSalaryDeductionPayment())).ToString()); if (Double.Parse(GlobalUtilities.getTotalChange()) >= 0) { proceedButton.Enabled = true; } else { proceedButton.Enabled = false; } }