Example #1
0
        public void updateSales()
        {
            string dateToday          = DateTime.Today.ToShortDateString();
            string convertedDateToday = dateToday.Replace('/', '_');

            //MessageBox.Show(convertedDateToday);

            for (int i = 0; i < soldItemNames.Length; i++)
            {
                database.selectQuery("SELECT ProductQty,AvgPrice,TotalDebits FROM Sales_" + convertedDateToday + " WHERE ProductName = '" + soldItemNames[i] + "';");
                if (database.numRows > 0)
                {
                    int    currentProductQty;
                    double currentProductAvgPrice;
                    double currentTotalDebits;

                    int    updatedProductQty;
                    double updatedProductAvgPrice;
                    double updatedTotalDebits;

                    int.TryParse(database.sqlDataTable.Rows[0]["ProductQty"].ToString(), out currentProductQty);
                    double.TryParse(database.sqlDataTable.Rows[0]["AvgPrice"].ToString(), out currentProductAvgPrice);
                    double.TryParse(database.sqlDataTable.Rows[0]["TotalDebits"].ToString(), out currentTotalDebits);

                    updatedProductQty      = currentProductQty + int.Parse(soldItemQuantities[i]);
                    updatedProductAvgPrice = ((double.Parse(soldItemPrices[i]) / double.Parse(soldItemQuantities[i])) + (currentProductAvgPrice)) / 2;
                    updatedTotalDebits     = currentTotalDebits + double.Parse(soldItemPrices[i]);

                    database.updateQuery("UPDATE Sales_" + convertedDateToday + " SET ProductQty = '" + updatedProductQty + "', " +
                                         "AvgPrice = '" + updatedProductAvgPrice + "', TotalDebits = '" + updatedTotalDebits + "';");
                }
                else
                {
                    double itemPrice;
                    double itemQty;
                    double itemAvgPrice;

                    double.TryParse(soldItemPrices[i], out itemPrice);
                    double.TryParse(soldItemQuantities[i], out itemQty);
                    itemAvgPrice = itemPrice / itemQty;


                    object[] parameters =
                    {
                        soldItemNames[i],
                        itemQty,
                        itemAvgPrice,
                        itemPrice
                    };
                    database.insertQuery("INSERT INTO Sales_" + convertedDateToday + "(ProductName,ProductQty,AvgPrice,TotalDebits)" +
                                         " VALUES(@p0,@p1,@p2,@p3)", parameters);
                }
            }

            PrintSuccess.getInstance().gsIsPrintSuccessfull = false;
        }
Example #2
0
 public static PrintSuccess getInstance()
 {
     if (Instance == null)
     {
         Instance = new PrintSuccess();
         return(Instance);
     }
     else
     {
         return(Instance);
     }
 }
        private void printReceipt(object sender, PrintPageEventArgs e)
        {
            Graphics graphics   = e.Graphics;
            Font     smallFont  = new Font("Courier New", 7);
            Font     mediumFont = new Font("Courier New", 7, FontStyle.Underline);
            Font     largeFont  = new Font("Courier New", 7, FontStyle.Bold);

            SolidBrush   blackBrush = new SolidBrush(Color.Black);
            float        fontHeight = smallFont.GetHeight();
            StringFormat formater   = new StringFormat();

            formater.Alignment     = StringAlignment.Near;
            formater.LineAlignment = StringAlignment.Near;

            int   startX = 5;
            int   startY = 5;
            float offSet = 30;

            graphics.DrawString("Welcome to Trinity Electricals", largeFont, blackBrush, startX, startY);

            graphics.DrawString("ITEM".PadRight(13) + "QTY".PadRight(5) + "PRICE".PadRight(6) + "AMOUNT".PadLeft(6), mediumFont, blackBrush, startX, startY + fontHeight + 10, formater);

            for (int i = 0; i < itemNames.Length; i++)
            {
                string name   = itemNames[i];
                string qty    = itemQtys[i];
                string price  = (double.Parse(itemPrices[i]) / double.Parse(itemQtys[i])).ToString();
                string Amount = itemPrices[i];

                if (name == string.Empty)
                {
                    break;
                }
                string fullReceiptLine   = name.PadRight(13, '.') + (qty + " X").PadRight(5) + " " + price.PadRight(6);
                string amountReceiptLine = ("Ksh. " + Amount).PadLeft(30);
                graphics.DrawString(fullReceiptLine, smallFont, blackBrush, startX, startY + offSet, formater);
                offSet = offSet + fontHeight + 3;
                graphics.DrawString(amountReceiptLine, smallFont, blackBrush, startX, startY + offSet, formater);
                offSet = offSet + fontHeight + 3;

                StockUpdater.getInstance().updateStock(name, qty);
            }

            double vat = total * .16;

            offSet = offSet + 20;
            graphics.DrawString("Sub Total".PadRight(20, '_') + ("Ksh. " + total.ToString()).PadLeft(10, '_'), mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 10;
            graphics.DrawString("Paid".PadRight(20, '_') + ("Ksh. " + paid.ToString()).PadLeft(10, '_'), mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 10;
            graphics.DrawString("V.A.T".PadRight(20, '_') + ("Ksh. " + vat.ToString()).PadLeft(10, '_'), mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 10;
            graphics.DrawString("Balance".PadRight(20, '_') + ("Ksh. " + balance.ToString()).PadLeft(10, '_'), mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 10;
            graphics.DrawString("Thank You For Shopping With Us", mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 10;
            graphics.DrawString("Served By: " + UserAccessLevel.getInstance().gsCurrentUserName + " ", mediumFont, blackBrush, startX, startY + offSet);
            offSet = offSet + 20;
            graphics.DrawString("Date: " + System.DateTime.Now.ToLongDateString(), mediumFont, blackBrush, startX, startY + offSet, formater);

            PrintSuccess.getInstance().gsIsPrintSuccessfull = true;
        }