Example #1
0
 void DrawGraph(Graphics g)
 {
     try
     {
         string[] sNoStats       = GTill.Properties.Settings.Default.sNoStatsAbout.Split(',');
         int[]    nNoStats       = new int[sNoStats.Length];
         int      nOfHoursToShow = DateTime.Now.Hour - 8;
         for (int i = 0; i < sNoStats.Length; i++)
         {
             try
             {
                 nNoStats[i] = Convert.ToInt32(sNoStats[i]);
             }
             catch
             {
                 nNoStats[i] = 0;
             }
         }
         int nNameLeft = 0;
         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
         int   nCurrentPieColour = 0;
         Point pBottomLeft       = new Point((this.Width / 8), this.Height - (this.Height / 8));
         float fTotalAmount      = 0.0f;
         for (int i = 0; i < fStaffSales.Length; i++)
         {
             bool bStaffOptedOut = false;
             for (int x = 0; x < nNoStats.Length; x++)
             {
                 if (i == nNoStats[x])
                 {
                     bStaffOptedOut = true;
                 }
             }
             if (fTotalAmount < fStaffSales[i] && !bStaffOptedOut)
             {
                 fTotalAmount = fStaffSales[i];
             }
         }
         float fAmountEachYPixel = (float)fTotalAmount / (float)((this.Height / 4) * 3);
         float fAmountEachXPixel = (float)(nOfHoursToShow * 60) / (float)((this.Width / 4) * 3); // 9 hours @ 60 mins each
         // Go through each sale
         string[] sSales = tEngine.GetListOfTransactionNumbers();
         for (int x = 0; x < 10; x++)
         {
             float  fCumulativeTotal = 0.0f;
             Point  pLastPoint       = pBottomLeft;
             string sStaffName       = "";
             sStaffName = tEngine.GetStaffName(x);
             bool bStaffOptedOut = false;
             for (int i = 0; i < nNoStats.Length; i++)
             {
                 if (x == nNoStats[i])
                 {
                     bStaffOptedOut = true;
                 }
             }
             if (sStaffName != "" && !bStaffOptedOut)
             {
                 for (int i = 0; i < sSales.Length; i++)
                 {
                     string[,] sTransactionInfo = tEngine.GetTransactionInfo(sSales[i]);
                     if (sStaffName == tEngine.ReturnSensibleDateTimeString(sTransactionInfo[0, 2])[1])
                     {
                         // This is one of the staff member's transactions, so plot a point
                         // Work out the value of the transaction
                         float fTransactionValue     = 0.0f;
                         int   nOfItemsInTransaction = Convert.ToInt32(sTransactionInfo[0, 0]);
                         int   nOfPaymentMethods     = Convert.ToInt32(sTransactionInfo[0, 1]);
                         for (int z = 1; z <= nOfItemsInTransaction; z++)
                         {
                             fTransactionValue += (float)Convert.ToDecimal(sTransactionInfo[z, 2]);
                         }
                         for (int z = nOfItemsInTransaction; z <= nOfItemsInTransaction + nOfPaymentMethods; z++)
                         {
                             if (sTransactionInfo[z, 0] == "DEPO")
                             {
                                 fTransactionValue -= (float)Convert.ToDecimal(sTransactionInfo[z, 1]);
                             }
                         }
                         if (sTransactionInfo[0, 3] != "SALE" && sTransactionInfo[0, 3] != "SPECIFICREFUND")
                         {
                             fTransactionValue = 0;
                         }
                         fTransactionValue = TillEngine.TillEngine.FixFloatError(fTransactionValue);
                         fCumulativeTotal += fTransactionValue;
                         fCumulativeTotal  = TillEngine.TillEngine.FixFloatError(fCumulativeTotal);
                         int    yPos          = this.Height - (this.Height / 8) - (int)Math.Round(fCumulativeTotal / fAmountEachYPixel, 0);
                         string stime         = tEngine.ReturnSensibleDateTimeString(sTransactionInfo[0, 2])[0].Split(' ')[1].Replace(':', '.');
                         int    nMinutesTotal = 0;
                         nMinutesTotal += (Convert.ToInt32(stime.Split('.')[0]) * 60) - (9 * 60);
                         nMinutesTotal += Convert.ToInt32(stime.Split('.')[1]);
                         int xPos = (int)Math.Round(nMinutesTotal / fAmountEachXPixel) + (this.Width / 8);
                         g.DrawLine(new Pen(cPieColours[nCurrentPieColour], 3.0f), pLastPoint, new Point(xPos, yPos));
                         pLastPoint = new Point(xPos, yPos);
                     }
                 }
                 if (fStaffSales[x] > 0.0f)
                 {
                     g.DrawString(tEngine.GetStaffName(x), new Font(GTill.Properties.Settings.Default.sFontName, 20.0f), new SolidBrush(cPieColours[nCurrentPieColour]), new PointF((float)nNameLeft, 0.0f));
                     nNameLeft += (int)g.MeasureString(tEngine.GetStaffName(x), new Font(GTill.Properties.Settings.Default.sFontName, 20.0f)).Width;
                     nCurrentPieColour++;
                     if (nCurrentPieColour >= cPieColours.Length)
                     {
                         nCurrentPieColour = 0;
                     }
                 }
             }
         }
         g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), pBottomLeft, new Point(this.Width / 8, this.Height / 8));
         g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), pBottomLeft, new Point(this.Width - (this.Width / 8), this.Height - (this.Height / 8)));
         g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), pBottomLeft, new Point((this.Width / 8) - 15, this.Height - (this.Height / 8)));
         g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point(this.Width / 8, this.Height / 8), new Point((this.Width / 8) - 15, this.Height / 8));
         g.DrawString(tEngine.CurrencySymbol.ToString() + "0.00", new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X - 15 - g.MeasureString(tEngine.CurrencySymbol.ToString() + "0.00", new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Width, pBottomLeft.Y - g.MeasureString(tEngine.CurrencySymbol.ToString() + "0.00", new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2));
         g.DrawString(tEngine.CurrencySymbol.ToString() + TillEngine.TillEngine.FormatMoneyForDisplay(fTotalAmount), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X - 15 - g.MeasureString(tEngine.CurrencySymbol.ToString() + TillEngine.TillEngine.FormatMoneyForDisplay(fTotalAmount), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Width, (this.Height / 8) - g.MeasureString(tEngine.CurrencySymbol.ToString() + TillEngine.TillEngine.FormatMoneyForDisplay(fTotalAmount), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2));
         int nDiff = ((this.Width / 4) * 3) / nOfHoursToShow;
         for (int t = 0; t <= 9; t++)
         {
             g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point((this.Width / 8) + (nDiff * t), pBottomLeft.Y), new Point((this.Width / 8) + (nDiff * t), pBottomLeft.Y + 15));
             g.DrawString((t + 9).ToString(), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF((this.Width / 8) + (nDiff * t) - (g.MeasureString((9 + t).ToString(), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2), this.Height - (this.Height / 8) + 20));
         }
         g.DrawString("Hour", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF((this.Width / 2) - 15, this.Height - 50));
         g.DrawString("Amount", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(this.Width / 8 - g.MeasureString("Amount", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f)).Width - 15, (this.Height / 8) - 50));
         g.DrawString("Cumulative Sales", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF((this.Width / 2) - (g.MeasureString("Hourly Sales", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f)).Width / 2), g.MeasureString("ThomasIsMyName", new Font(GTill.Properties.Settings.Default.sFontName, 20.0f)).Height));
         for (int t = 0; t <= 9; t++)
         {
             g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point(pBottomLeft.X - 15, pBottomLeft.Y - (t * (((this.Height / 4) * 3) / 10))), new Point(pBottomLeft.X, pBottomLeft.Y - (t * (((this.Height / 4) * 3) / 10))));
             g.DrawString(tEngine.CurrencySymbol.ToString() + TillEngine.TillEngine.FormatMoneyForDisplay((fTotalAmount / 10) * t), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X - 15 - (int)g.MeasureString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay((fTotalAmount / 10) * t), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Width, pBottomLeft.Y - (t * (((this.Height / 4) * 3) / 10)) - (g.MeasureString(tEngine.CurrencySymbol.ToString(), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2)));
         }
     }
     catch (Exception ex)
     {
         ;
     }
 }