/// <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> /// Increases/Decreases the quantity value of the product in the masterListDictionary /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddProductButton_Click(object sender, EventArgs e) { if (String.IsNullOrWhiteSpace(productBarCodeTextBox.Text) || !GlobalUtilities.isInDictionary(GlobalUtilities.MASTER, (productBarCodeTextBox.Text).TrimStart(new Char[] { '0' }))) { productBarCodeTextBox.Focus(); //quantityNumericUpDown.Value = 1; //productBarCodeTextBox.Text = ""; return; } List <string> customerProductOrder = new List <string>(); List <string> masterListDictionaryProduct = new List <string>(GlobalUtilities.getMasterListDictionary()[(productBarCodeTextBox.Text).TrimStart(new Char[] { '0' })]); DataGridViewRow updateDataGridViewRow = productOrderDataGridView.Rows[rowSearchWithMatchingBarCodes((productBarCodeTextBox.Text).TrimStart(new Char[] { '0' }))]; int totalQuantityCheck = Int32.Parse(updateDataGridViewRow.Cells[3].Value.ToString()) + (int)quantityNumericUpDown.Value; if (totalQuantityCheck <= 0) { GlobalUtilities.setTotalQuantity((Int32.Parse(GlobalUtilities.getTotalQuantity()) - Int32.Parse(updateDataGridViewRow.Cells[3].Value.ToString())).ToString()); totalQuantityTextBox.Text = GlobalUtilities.getTotalQuantity(); updateDataGridViewRow.Cells[3].Value = "0"; productBarCodeTextBox.Focus(); quantityNumericUpDown.Value = 1; productBarCodeTextBox.Text = ""; return; } GlobalUtilities.setTotalQuantity((Int32.Parse(GlobalUtilities.getTotalQuantity()) + Int32.Parse(quantityNumericUpDown.Value.ToString())).ToString()); updateDataGridViewRow.Cells[3].Value = totalQuantityCheck; // Material #, Material Description, Selling Price, Discount, and Quantity customerProductOrder.Add(masterListDictionaryProduct[0].ToString()); customerProductOrder.Add(masterListDictionaryProduct[1].ToString()); customerProductOrder.Add(masterListDictionaryProduct[2].ToString()); customerProductOrder.Add(masterListDictionaryProduct[3].ToString()); customerProductOrder.Add(updateDataGridViewRow.Cells[3].Value.ToString()); GlobalUtilities.addToDictionary(GlobalUtilities.MASTER, productBarCodeTextBox.Text, customerProductOrder); totalQuantityTextBox.Text = GlobalUtilities.getTotalQuantity(); productBarCodeTextBox.Focus(); productBarCodeTextBox.Text = String.Empty; quantityNumericUpDown.Value = 1; }
/// <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(); }