Beispiel #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;
        }
Beispiel #2
0
        /// <summary>
        /// Updates Excel sheet and closes the application
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ProcessButton_Click(object sender, EventArgs e)
        {
            addProductButton.PerformClick();
            try
            {
                // Opens Excel Sheet
                xlApp               = new Excel.Application();
                xlApp.Visible       = false;
                xlApp.DisplayAlerts = false;
                xlWorkbook          = xlApp.Workbooks.Open(GlobalUtilities.getMasterFilePath(), 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
                xlWorksheet         = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1);

                // Edits Excel Sheet
                Excel.Range xlRange = xlWorksheet.UsedRange;

                for (int i = 1; i <= xlRange.Rows.Count + 10; i++)
                {
                    if (((Microsoft.Office.Interop.Excel.Range)xlWorksheet.Cells[i, 5]).Value != null)
                    {
                        object cellValue       = ((Microsoft.Office.Interop.Excel.Range)xlWorksheet.Cells[i, 5]).Value;
                        string cellValueString = cellValue.ToString();
                        if (GlobalUtilities.getMasterListDictionary().ContainsKey(cellValueString.TrimStart(new Char[] { '0' })) && !Regex.IsMatch(cellValueString.Replace(" ", ""), @"^[a-zA-Z]+$"))
                        {
                            List <string> tempMasterListDictionaryProduct = new List <string>(GlobalUtilities.getMasterListDictionary()[cellValueString.TrimStart(new Char[] { '0' })]);
                            object        quantityCellValue = ((Microsoft.Office.Interop.Excel.Range)xlWorksheet.Cells[i, 6]).Value;
                            string        quantityCellValueString;
                            if (quantityCellValue != null)
                            {
                                quantityCellValueString = quantityCellValue.ToString();
                            }
                            else
                            {
                                quantityCellValueString = "0";
                            }
                            if (!string.IsNullOrWhiteSpace(quantityCellValueString))
                            {
                                xlWorksheet.Cells[i, 6] = Double.Parse(quantityCellValueString) + Double.Parse(tempMasterListDictionaryProduct[4].ToString());
                            }
                            else
                            {
                                xlWorksheet.Cells[i, 6] = Double.Parse(tempMasterListDictionaryProduct[4].ToString());
                            }
                        }
                    }
                }

                // Saves Excel sheet
                xlWorkbook.SaveAs(GlobalUtilities.getMasterFilePath());
                xlWorkbook.Close(true, Type.Missing, Type.Missing);
                xlApp.Quit();
                if (xlWorkbook != null)
                {
                    Marshal.ReleaseComObject(xlWorkbook);
                }                                                                 //release each workbook like this
                if (xlWorksheet != null)
                {
                    Marshal.ReleaseComObject(xlWorksheet);
                }                                                                   //release each worksheet like this
                if (xlApp != null)
                {
                    Marshal.ReleaseComObject(xlApp);
                }                   //release the Excel application
                xlWorkbook  = null; //set each memory reference to null.
                xlWorksheet = null;
                xlApp       = null;
                GC.Collect();
            }
            catch (Exception ex)
            {
                // Saves Excel sheet
                xlApp.Quit();
                //release all memory - stop EXCEL.exe from hanging around.
                if (xlWorkbook != null)
                {
                    Marshal.ReleaseComObject(xlWorkbook);
                }                                                                 //release each workbook like this
                if (xlWorksheet != null)
                {
                    Marshal.ReleaseComObject(xlWorksheet);
                }                                                                   //release each worksheet like this
                if (xlApp != null)
                {
                    Marshal.ReleaseComObject(xlApp);
                }                   //release the Excel application
                xlWorkbook  = null; //set each memory reference to null.
                xlWorksheet = null;
                xlApp       = null;
                GC.Collect();
                MessageBox.Show(ex.Message);
            }

            this.Close();
            Application.Exit();
        }