コード例 #1
0
        /// <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;
        }
コード例 #2
0
ファイル: SaleDetails.cs プロジェクト: miggyst/FONZYApp
        /// <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();
        }
コード例 #3
0
ファイル: ChooseMasterFile.cs プロジェクト: miggyst/FONZYApp
        /// <summary>
        /// masterFile button will open a file explorer for the user to use and search
        /// for the master file to fill the data hash set within the GlobalUtilities file,
        /// then redirects it to CashierAndEventInfo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MasterFileButton_Click(object sender, EventArgs e)
        {
            try
            {
                // Opens file explorer and stores filename, and the contents of the excel file to global utilities
                OpenFileDialog openFileDialog = new OpenFileDialog();
                openFileDialog.Filter = "Excel Worksheets|*.xls; *.xlsx";
                if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    GlobalUtilities.setMasterFilePath(openFileDialog.FileName);
                }

                // Stores excel data onto Dictionary
                Excel.Application xlApp       = new Excel.Application();
                Excel.Workbook    xlWorkbook  = xlApp.Workbooks.Open(GlobalUtilities.getMasterFilePath(), 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                Excel.Worksheet   xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);
                Excel.Range       xlRange     = xlWorksheet.UsedRange;

                int    row = xlRange.Rows.Count;
                int    col = xlRange.Columns.Count;
                string eanCodePlaceholder = "";

                for (int rowCount = 1; rowCount <= row; rowCount++)
                {
                    // Creating a list to contain the excel data
                    List <string> productListInfo = new List <string>();

                    for (int colCount = 1; colCount <= col; colCount++)
                    {
                        /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
                        * Legend:                                                                                                       *
                        * Material #   | Material Description      | Selling Price     | Discount       | EAN Code     | Quantity       *
                        * --------------------------------------------------------------------------------------------------------------*
                        * column 1     | colum 2                   | column 3          | column 4       | column 5     | column6        *
                        * type double  | type string               | type double       | type double    | type double  | {null} no input*
                        * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

                        // Stores data into dictionary
                        Object obj = (xlRange.Cells[rowCount, colCount] as Excel.Range).Value;
                        if (colCount == 5) // EAN Code, to be used in the dictionary
                        {
                            eanCodePlaceholder = obj.ToString();
                        }
                        else // Material #, Material Description, Selling Price, Discount, and Quantity
                        {
                            if (colCount == 6)
                            {
                                productListInfo.Add("0");
                            }
                            else if (obj != null)
                            {
                                productListInfo.Add(obj.ToString());
                            }
                        }
                    }
                    GlobalUtilities.addToDictionary(GlobalUtilities.MASTER, eanCodePlaceholder, productListInfo);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            this.Close();
            if (applicationType == GlobalUtilities.TRANSACTION_MODE)
            {
                CashierAndEventInfo cashierAndEventInfo = new CashierAndEventInfo();
                cashierAndEventInfo.ShowDialog();
            }
            else if (applicationType == GlobalUtilities.INVENTORY_MODE)
            {
                InventorySaleDetails inventorySaleDetails = new InventorySaleDetails();
                inventorySaleDetails.ShowDialog();
            }
        }