/// <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> /// Loads masterListDictionary on Form load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InventorySaleDetails_Load(object sender, EventArgs e) { for (int i = 0; i < keyList.Count; i++) { if (!Regex.IsMatch(keyList[i].Replace(" ", ""), @"^[a-zA-Z]+$")) { List <string> customerProductOrder = new List <string>(GlobalUtilities.getProductInfoFromDictionary(GlobalUtilities.MASTER, keyList[i])); // Bar Code Product Description Price Quantity Discount productOrderDataGridView.Rows.Add(keyList[i], customerProductOrder[1], customerProductOrder[2], customerProductOrder[3], customerProductOrder[4]); } } }
/// <summary> /// button searches takes the userInput text from the text box and searches the dictionary for the product. /// If the product exists, add it to the DataGridView, /// else neglect the input. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddProductButton_Click(object sender, EventArgs e) { List <string> customerProductOrder = new List <string>(); // Check customerTransactionDictionary. if available find the list and update, else search masterListDictionary and add it into customerTransactionDictionary // then update the DataGridView as necessary if (GlobalUtilities.isInDictionary(GlobalUtilities.CUSTOMER, productBarCodeTextBox.Text)) { DataGridViewRow updateDataGridViewRow = productOrderDataGridView.Rows[rowSearchWithMatchingBarCodes(productBarCodeTextBox.Text)]; int totalQuantityCheck = Int32.Parse(updateDataGridViewRow.Cells[3].Value.ToString()) + (int)quantityNumericUpDown.Value; if (totalQuantityCheck <= 0) { productOrderDataGridView.Rows.RemoveAt(rowSearchWithMatchingBarCodes(productBarCodeTextBox.Text)); GlobalUtilities.setTotalQuantity((Int32.Parse(GlobalUtilities.getTotalQuantity()) - Int32.Parse(updateDataGridViewRow.Cells[3].Value.ToString())).ToString()); GlobalUtilities.setTotalCost(GlobalUtilities.getTotalCost() - Double.Parse(GlobalUtilities.calculatePrice(updateDataGridViewRow.Cells[2].Value.ToString(), updateDataGridViewRow.Cells[3].Value.ToString(), updateDataGridViewRow.Cells[4].Value.ToString()))); (GlobalUtilities.getCustomerTransactionDictionary()).Remove(productBarCodeTextBox.Text); totalQuantityTextBox.Text = GlobalUtilities.getTotalQuantity(); totalCostTextBox.Text = (GlobalUtilities.getTotalCost()).ToString(); productBarCodeTextBox.Focus(); quantityNumericUpDown.Value = 1; productBarCodeTextBox.Text = ""; return; } GlobalUtilities.setTotalQuantity((Int32.Parse(GlobalUtilities.getTotalQuantity()) + Int32.Parse(quantityNumericUpDown.Value.ToString())).ToString()); GlobalUtilities.setTotalCost(GlobalUtilities.getTotalCost() + Double.Parse(GlobalUtilities.calculatePrice(updateDataGridViewRow.Cells[2].Value.ToString(), quantityNumericUpDown.Value.ToString(), updateDataGridViewRow.Cells[4].Value.ToString()))); updateDataGridViewRow.Cells[3].Value = totalQuantityCheck; updateDataGridViewRow.Cells[5].Value = GlobalUtilities.calculatePrice(updateDataGridViewRow.Cells[2].Value.ToString(), updateDataGridViewRow.Cells[3].Value.ToString(), updateDataGridViewRow.Cells[4].Value.ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[1].Value.ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[2].Value.ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[3].Value.ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[4].Value.ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[5].Value.ToString()); GlobalUtilities.addToDictionary(GlobalUtilities.CUSTOMER, productBarCodeTextBox.Text, customerProductOrder); } else { if (GlobalUtilities.getCustomerTransactionDictionary().Count == 20) { // Do not add it to the customer transaction list since it can only have a max of 20 productBarCodeTextBox.Text = ""; return; } if ((int)quantityNumericUpDown.Value <= 0 || String.IsNullOrWhiteSpace(productBarCodeTextBox.Text) || !GlobalUtilities.isInDictionary(GlobalUtilities.MASTER, (productBarCodeTextBox.Text).TrimStart(new Char[] { '0' }))) { return; } customerProductOrder = GlobalUtilities.getProductInfoFromDictionary(GlobalUtilities.MASTER, (productBarCodeTextBox.Text).TrimStart(new Char[] { '0' })); customerProductOrder[3] = (Int32.Parse(customerProductOrder[3]) + (int)quantityNumericUpDown.Value).ToString(); customerProductOrder[5] = GlobalUtilities.calculatePrice(customerProductOrder[2], customerProductOrder[3], customerProductOrder[4]); // Bar Code Product Description Price Quantity Discount Amount productOrderDataGridView.Rows.Add(productBarCodeTextBox.Text, customerProductOrder[1], customerProductOrder[2], customerProductOrder[3], customerProductOrder[4], customerProductOrder[5]); customerProductOrder.RemoveAt(0); GlobalUtilities.addToDictionary(GlobalUtilities.CUSTOMER, productBarCodeTextBox.Text, customerProductOrder); GlobalUtilities.setTotalQuantity((Int32.Parse(GlobalUtilities.getTotalQuantity()) + Int32.Parse(customerProductOrder[2])).ToString()); GlobalUtilities.setTotalCost(GlobalUtilities.getTotalCost() + Double.Parse(GlobalUtilities.calculatePrice(customerProductOrder[1], customerProductOrder[2], customerProductOrder[3]))); } totalQuantityTextBox.Text = GlobalUtilities.getTotalQuantity(); totalCostTextBox.Text = (GlobalUtilities.getTotalCost()).ToString(); productBarCodeTextBox.Text = ""; quantityNumericUpDown.Value = 1; if (canProcessOrder()) { processButton.Enabled = true; } else { processButton.Enabled = false; } productBarCodeTextBox.Focus(); }
/// <summary> /// Builds the body that can host up to 20 customer orders. /// Displays Item number, Description, Quantity, Price, and Amount /// </summary> /// <param name="customerKey"></param> /// <returns></returns> private string buildBodyParagraphArray(string customerKey) { List <string> paraList = new List <string>(); List <string> customerOrder = GlobalUtilities.getProductInfoFromDictionary(GlobalUtilities.CUSTOMER, customerKey); char[] barCodeCharArray = customerKey.ToCharArray(); char[] productDescriptionCharArray = customerOrder[1].ToCharArray(); char[] priceCharArray = customerOrder[2].ToCharArray(); char[] quantityCharArray = customerOrder[3].ToCharArray(); char[] amountCharArray = customerOrder[4].ToCharArray(); // Item Number for (int i = 0; i < 16; i++) { if (i < customerKey.Length) { paraList.Add(barCodeCharArray[i].ToString()); } else { paraList.Add(" "); } } for (int numSpace = 0; numSpace < 3; numSpace++) { paraList.Add(" "); } // Description for (int j = 0; j < 32; j++) { if (j < customerOrder[1].Length) { paraList.Add(productDescriptionCharArray[j].ToString()); } else { paraList.Add(" "); } } for (int numSpace = 0; numSpace < 3; numSpace++) { paraList.Add(" "); } // Quantity for (int k = 0; k < 3; k++) { if (k < customerOrder[3].Length) { paraList.Add(quantityCharArray[k].ToString()); } else { paraList.Add(" "); } } for (int numSpace = 0; numSpace < 3; numSpace++) { paraList.Add(" "); } // Price for (int l = 0; l < 5; l++) { if (l < customerOrder[2].Length) { paraList.Add(priceCharArray[l].ToString()); } else { paraList.Add(" "); } } for (int numSpace = 0; numSpace < 3; numSpace++) { paraList.Add(" "); } // Amount for (int m = 0; m < 9; m++) { if (m < customerOrder[4].Length) { paraList.Add(amountCharArray[m].ToString()); } else { paraList.Add(" "); } } return(string.Join("", paraList)); }