Exemple #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);
            }
        }
Exemple #2
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);
            }
        }