/// <summary> /// enables or disables the text boxes based on whether or not /// the preceeding identifiers were toggled on the PaymentAndCustomerType form, /// also disables the proceedButton to force the user to calculate customer's change /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PaymentCalculator_Load(object sender, EventArgs e) { proceedButton.Enabled = false; if (GlobalUtilities.getCashPaymentIdentifier() != true) { cashTextBox.ReadOnly = true; } if (GlobalUtilities.getCreditPaymentIdentifier() != true) { creditTextBox.ReadOnly = true; } if (GlobalUtilities.getDebitPaymentIdentifier() != true) { debitTextBox.ReadOnly = true; } if (GlobalUtilities.getCheckPaymentIdentifier() != true) { checkTextBox.ReadOnly = true; } if (GlobalUtilities.getSalaryDeductionPaymentIdentifier() != true) { salaryDeductionTextBox.ReadOnly = true; } totalAmountTextBox.Text = String.Format("{0:n}", GlobalUtilities.getTotalCost()); changeTextBox.Text = "0"; }
/// <summary> /// Builds the total paragraph to display total quantity and amount /// </summary> /// <returns></returns> private string buildTotalParagraphArray() { List <string> paraList = new List <string>(); paraList.Add(" Total "); char[] totalQuantity = GlobalUtilities.getTotalQuantity().ToCharArray(); char[] totalCost = String.Format("{0:n}", GlobalUtilities.getTotalCost()).ToCharArray(); for (int i = 0; i < 15; i++) { if (i < GlobalUtilities.getTotalQuantity().Length) { paraList.Add(totalQuantity[i].ToString()); } else { paraList.Add(" "); } } for (int j = 0; j < 9; j++) { if (j < GlobalUtilities.getTotalCost().ToString().Length) { paraList.Add(totalCost[j].ToString()); } else { paraList.Add(" "); } } return(string.Join("", paraList)); }
/// <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> /// Generates the user's Word document receipt /// </summary> private void createWordDocument() { try { string filePath = (GlobalUtilities.getMasterFilePath()).Remove((GlobalUtilities.getMasterFilePath()).LastIndexOf('\\') + 1); string[] dateArray = (DateTime.Now.Date.ToString("dd/MM/yyyy")).Split('/'); string[] timeArray = (DateTime.Now.ToString("h:mm:ss tt")).Split(':'); string wordFilePath = filePath + GlobalUtilities.getCustomerName() + "_" + dateArray[0] + "-" + dateArray[1] + "-" + dateArray[2] + "_" + timeArray[0] + "-" + timeArray[1] + "-" + timeArray[2] + ".docx"; Word.Application wordApp = new Microsoft.Office.Interop.Word.Application(); wordApp.ShowAnimation = false; wordApp.Visible = false; object missing = System.Reflection.Missing.Value; Word.Document wordDocument = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing); Word.Range rng = wordDocument.Paragraphs[1].Range; Word.Paragraph para = wordDocument.Paragraphs.Add(ref missing); // Sets the font format for the document to be monospace (easier to edit characters/words to print) wordDocument.Content.SetRange(0, 0); object styleName = "No Spacing"; rng.set_Style(ref styleName); rng.Font.Size = 11; rng.Font.Name = "Consolas"; rng.Select(); // There are a total of 77 possible characters per line // Indentation to align the Word doc text para.Range.Text = Environment.NewLine; // Cashier, Time and Customer Number info para.Range.Text = "Cashier: " + GlobalUtilities.getCashierName() + Environment.NewLine; para.Range.Text = "Cust. Add.: " + GlobalUtilities.getCustomerAddress() + Environment.NewLine; para.Range.Text = "Cust. Tel.: " + GlobalUtilities.getCashierName() + Environment.NewLine; para.Range.Text = "Time: " + timeArray[0] + ":" + timeArray[1] + ":" + timeArray[2] + Environment.NewLine; // Some indentation to align text para.Range.Text = Environment.NewLine; // Customer details: Customer Name, address, TIN, Business Style, Data, Terms, OSCA/PWD ID No., Cardholder's Signature para.Range.Text = buildCharacterParagraphArray(11, GlobalUtilities.getCustomerName(), 38, 10, DateTime.Now.Date.ToString("dd/MM/yyyy")) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(11, GlobalUtilities.getCustomerAddress(), 38, 11, GlobalUtilities.getCustomerTerms()) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(8, GlobalUtilities.getCustomerTIN(), 41, 21, GlobalUtilities.getCustomerOSCA()) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(17, GlobalUtilities.getCustomerBusinessStyle(), 33, 19, "") + Environment.NewLine; // Customer order details title para.Range.Text = Environment.NewLine; para.Range.Text = "Item Number Description Qty Price Amount" + Environment.NewLine; para.Range.Text = Environment.NewLine; // Customer order details breakdown List <string> keyList = new List <string>(GlobalUtilities.getCustomerTransactionDictionary().Keys); for (int i = 0; i < GlobalUtilities.getCustomerTransactionDictionary().Count; i++) { para.Range.Text = buildBodyParagraphArray(keyList[i]) + Environment.NewLine; } for (int j = 0; j < (20 - GlobalUtilities.getCustomerTransactionDictionary().Count); j++) { para.Range.Text = Environment.NewLine; } para.Range.Text = Environment.NewLine; para.Range.Text = buildTotalParagraphArray() + Environment.NewLine; // Sales data double vatSales = GlobalUtilities.getTotalCost() * 0.88; double vat = GlobalUtilities.getTotalCost() * 0.12; para.Range.Text = Environment.NewLine; para.Range.Text = Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(68, "", 0, 0, vatSales.ToString()) + Environment.NewLine; para.Range.Text = Environment.NewLine; para.Range.Text = Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(68, "", 0, 0, String.Format("{0:n}", GlobalUtilities.getTotalCost())) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(68, "", 0, 0, vat.ToString()) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(68, "", 0, 0, String.Format("{0:n}", GlobalUtilities.getTotalCost())) + Environment.NewLine; para.Range.Text = Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(62, "", 0, 0, String.Format("{0:n}", GlobalUtilities.getTotalCustomerPayment())) + Environment.NewLine; para.Range.Text = buildCharacterParagraphArray(62, "", 0, 0, String.Format("{0:n}", Double.Parse(GlobalUtilities.getTotalChange()))) + Environment.NewLine; //Save the document GlobalUtilities.setCustomerOrderFilePath(wordFilePath); object documentFilePath = GlobalUtilities.getCustomerOrderFilePath(); wordDocument.SaveAs2(ref documentFilePath); wordDocument.Close(ref missing, ref missing, ref missing); wordDocument = null; wordApp.Quit(ref missing, ref missing, ref missing); wordApp = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } }