Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        /// <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
        /// <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);
            }
        }