void tbRefund_KeyDown(object sender, KeyEventArgs e) { TextBox tbCurrent = (TextBox)sender; int nCurrentBox = Convert.ToInt32(tbCurrent.Tag.ToString()[0].ToString()); if (e.Shift && nCurrentBox == 0) { bShiftFunctionKeys = !bShiftFunctionKeys; } if (e.KeyCode == Keys.Enter) { if (nCurrentBox < 2) { tbRefundDetails[nCurrentBox + 1].Focus(); switch (nCurrentBox + 1) { case 0: lblInstruction.Text = "Enter the barcode of the item to refund."; break; case 1: lblInstruction.Text = "Enter the price that was paid for the item."; break; case 2: lblInstruction.Text = "Enter the quantity of the item to refund"; break; } } if (nCurrentBox == 0) { string[] sItemDetails = tEngine.GetItemDetailsForLookup(tbRefundDetails[0].Text); if (sItemDetails == null) { if (tbRefundDetails[0].Text.Length > 1) { fsfiFindBarcode = new frmSearchForItem(ref tEngine); fsfiFindBarcode.FormClosing += new FormClosingEventHandler(fsfiFindBarcode_FormClosing); fsfiFindBarcode.Show(); fsfiFindBarcode.CheckForPartialBarcodeFromScanner(tbRefundDetails[0].Text); } else { lblInstruction.Text = "The barcode that was entered was invalid. Please try again."; tbRefundDetails[0].Focus(); } } else { sBarcodeToRefund = tbRefundDetails[0].Text.ToUpper(); tbRefundDetails[0].BackColor = cFrmBackColour; tbRefundDetails[0].ForeColor = cFrmForeColour; tbRefundDetails[0].Font = new Font(sFontName, 11.0f); tbRefundDetails[0].Text = sItemDetails[0]; tbRefundDetails[1].Text = TillEngine.TillEngine.FormatMoneyForDisplay(TillEngine.TillEngine.fFormattedMoneyString(sItemDetails[1])); tbRefundDetails[1].KeyDown += new KeyEventHandler(frmRefund_KeyDown); tbRefundDetails[1].Tag = "1"; } } else if (nCurrentBox == 2) { for (int i = 0; i < tbRefundDetails.Length; i++) { tbRefundDetails[i].BackColor = cFrmBackColour; tbRefundDetails[i].ForeColor = cFrmForeColour; tbRefundDetails[i].Font = new Font(sFontName, 11.0f); tbRefundDetails[i].Enabled = false; } try { nQuantityToRefund = Convert.ToInt32(tbRefundDetails[2].Text); } catch { nQuantityToRefund = 1; tbRefundDetails[2].Text = "1"; } fAmountToRefund = TillEngine.TillEngine.FixFloatError((float)Convert.ToDecimal(tbRefundDetails[1].Text)); fAmountToRefund *= nQuantityToRefund; fAmountToRefund = TillEngine.TillEngine.FixFloatError(fAmountToRefund); tbRefundDetails[3].Text = TillEngine.TillEngine.FormatMoneyForDisplay(fAmountToRefund); fpiGetPaymentType = new frmPaymentInput(new Point(this.Left, lblRefundDetails[3].Top + 200), new Size(this.Width, this.Height - 70 - (lblRefundDetails[0].Top + 250)), tEngine.GetCreditCards(), fAmountToRefund, false, false, true); fpiGetPaymentType.Show(); fpiGetPaymentType.GetAmountFromUser = false; fpiGetPaymentType.FormClosed += new FormClosedEventHandler(fpiGetPaymentType_FormClosing); } else if (nCurrentBox == 1) { try { fAmountToRefund = (float)Convert.ToDecimal(TillEngine.TillEngine.fFormattedMoneyString(tbRefundDetails[1].Text)); fAmountToRefund = tEngine.fFixFloatError(fAmountToRefund); tbRefundDetails[1].Text = TillEngine.TillEngine.FormatMoneyForDisplay(fAmountToRefund); tbRefundDetails[1].BackColor = cFrmBackColour; tbRefundDetails[1].ForeColor = cFrmForeColour; tbRefundDetails[1].Font = new Font(sFontName, 11.0f); if (sBarcodeToRefund == "$GENERAL_REFUND") { tbRefundDetails[1].Enabled = false; tbRefundDetails[3].Text = tbRefundDetails[1].Text; tbRefundDetails[3].Font = new Font(sFontName, 11.0f); fpiGetPaymentType = new frmPaymentInput(new Point(this.Left, lblRefundDetails[3].Top + 200), new Size(this.Width, this.Height - 70 - (lblRefundDetails[0].Top + 250)), tEngine.GetCreditCards(), fAmountToRefund, false, false, true); fpiGetPaymentType.Show(); fpiGetPaymentType.GetAmountFromUser = false; fpiGetPaymentType.FormClosed += new FormClosedEventHandler(fpiGetPaymentType_FormClosing); } else { tbRefundDetails[2].Text = "1"; tbRefundDetails[2].SelectAll(); } } catch { tbRefundDetails[1].Text = ""; tbRefundDetails[1].Focus(); lblInstruction.Text = "The price that was entered was invalid, please try again."; } } } else if (e.KeyCode == Keys.Escape) { if (nCurrentBox > 0) { tbRefundDetails[nCurrentBox].Text = ""; tbRefundDetails[nCurrentBox - 1].Focus(); } else if (nCurrentBox == 0) { this.Close(); } if (nCurrentBox == 1) { if (sBarcodeToRefund != "$GENERAL_REFUND") { tbRefundDetails[0].BackColor = cFrmForeColour; tbRefundDetails[0].ForeColor = cFrmBackColour; tbRefundDetails[0].Text = ""; tbRefundDetails[0].Font = new Font(sFontName, 16.0f); tbRefundDetails[0].Enabled = true; tbRefundDetails[0].Focus(); tbRefundDetails[1].Tag = "0"; } else { this.Close(); } } else if (nCurrentBox == 2) { tbRefundDetails[1].BackColor = cFrmForeColour; tbRefundDetails[1].ForeColor = cFrmBackColour; tbRefundDetails[1].Text = ""; tbRefundDetails[1].Font = new Font(sFontName, 16.0f); tbRefundDetails[1].Enabled = true; tbRefundDetails[1].Focus(); } } else if (e.KeyCode == Keys.OemQuestion && nCurrentBox == 0) { fsfiFindBarcode = new frmSearchForItem(ref tEngine); fsfiFindBarcode.Show(); fsfiFindBarcode.FormClosing += new FormClosingEventHandler(fsfiLookupBarcode_FormClosing); } else if (e.KeyCode == Keys.Tab) { MessageBox.Show("orite luv"); tbCurrent.Focus(); e.Handled = true; } else if (e.KeyCode == Keys.F1) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F1"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF1"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F2) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F2"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF2"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F3) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F3"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF3"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F4) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F4"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF4"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F5) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F5"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF5"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F6) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F6"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF6"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F7) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F7"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF7"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F8) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F8"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF8"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F9) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F9"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF9"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F10) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F10"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF10"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F11) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F11"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF11"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } else if (e.KeyCode == Keys.F12) { if (!bShiftFunctionKeys) { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("F12"); } else { tbCurrent.Text = tEngine.sBarcodeFromFunctionKey("SF12"); } bShiftFunctionKeys = false; tbCurrent.Focus(); SendKeys.Send("{ENTER}"); } }
void DrawAverageHourlyGraph(Graphics g) { // First work out hourly sales string[] sTransaction = tEngine.GetListOfTransactionNumbers(); string[] sStaff = new string[10]; for (int i = 0; i < 10; i++) { sStaff[i] = tEngine.GetStaffName(i); } float[,] fStaffAverages = new float[10, 9]; // staffnum,hour for (int x = 0; x < 10; x++) { for (int y = 0; y < 9; y++) { fStaffAverages[x, y] = 0; } } for (int i = 0; i < sTransaction.Length; i++) { string[,] sTransactionInfo = tEngine.GetTransactionInfo(sTransaction[i]); int nOfItems = Convert.ToInt32(sTransactionInfo[0, 0]); string[] sSalesData = tEngine.ReturnSensibleDateTimeString(sTransactionInfo[0, 2]); string sTime = sSalesData[0].Split(' ')[1]; string sHour = sTime.Split(':')[0]; int nHour = Convert.ToInt32(sHour); string sStaffName = sSalesData[1].TrimEnd(' ').ToUpper(); int nStaffNum = 0; for (int z = 0; z < sStaff.Length; z++) { if (sStaffName.ToUpper() == sStaff[z].ToUpper()) { nStaffNum = z; break; } } float fAmountSold = 0.0f; for (int x = 1; x <= nOfItems; x++) { fAmountSold += (float)Convert.ToDecimal(sTransactionInfo[x, 2]); } fAmountSold = tEngine.fFixFloatError(fAmountSold); fStaffAverages[nStaffNum, nHour - 9] += fAmountSold; fStaffAverages[nStaffNum, nHour - 9] = tEngine.fFixFloatError(fStaffAverages[nStaffNum, nHour - 9]); } // Work out highest on y axis float fHighest = 0.0f; for (int x = 0; x < 10; x++) { for (int y = 0; y < 9; y++) { if (fStaffAverages[x, y] > fHighest) { fHighest = fStaffAverages[x, y]; } } } float fAmountEachYPixel = fHighest / (((float)this.Height / 4) * 3); float fAmountEachXPixel = 9.0f / (((float)this.Width / 4) * 3); int nColourNumber = 0; int nNameLeft = 0; bool[] bDrawingStaff = new bool[sStaff.Length]; for (int i = 0; i < bDrawingStaff.Length; i++) { bDrawingStaff[i] = false; } for (int x = 0; x < 10; x++) { for (int y = 0; y < 9; y++) { if (fStaffAverages[x, y] != 0.0f) { bDrawingStaff[x] = true; } } } // Draw the graph g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; Point pBottomLeft = new Point((this.Width / 8), this.Height - (this.Height / 8)); for (int i = 1; i < 10; i++) // Staff { if (bDrawingStaff[i]) { Point pLastPoint = pBottomLeft; for (int x = 0; x < 9; x++) // Hours { Point pNewPoint = new Point(Convert.ToInt32(pBottomLeft.X + (x / fAmountEachXPixel) + (0.5 / fAmountEachXPixel)), Convert.ToInt32(pBottomLeft.Y - (fStaffAverages[i, x] / fAmountEachYPixel))); g.DrawLine(new Pen(cPieColours[nColourNumber], 2.0f), pLastPoint, pNewPoint); pLastPoint = pNewPoint; } g.DrawString(tEngine.GetStaffName(i), new Font(GTill.Properties.Settings.Default.sFontName, 20.0f), new SolidBrush(cPieColours[nColourNumber]), new PointF(nNameLeft, 0)); nNameLeft += Convert.ToInt32(g.MeasureString(tEngine.GetStaffName(i), new Font(GTill.Properties.Settings.Default.sFontName, 20.0f)).Width); nColourNumber++; } } // Draw the axes g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), pBottomLeft, new Point(pBottomLeft.X, pBottomLeft.Y - ((this.Height / 4) * 3))); g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), pBottomLeft, new Point(pBottomLeft.X + ((this.Width / 4) * 3), pBottomLeft.Y)); int nYDiff = ((this.Height / 4) * 3) / 10; int nXDiff = ((this.Width / 4) * 3) / 9; for (int i = 0; i < 10; i++) { g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point(pBottomLeft.X - 15, pBottomLeft.Y - (nYDiff * i)), new Point(pBottomLeft.X, pBottomLeft.Y - (nYDiff * i))); g.DrawString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay((fHighest / 10) * i), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X - g.MeasureString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay((fHighest / 10) * i), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Width - 15, pBottomLeft.Y - (nYDiff * i) - (g.MeasureString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay((fHighest / 10) * i), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2))); } g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point(pBottomLeft.X - 15, pBottomLeft.Y - ((this.Height / 4) * 3)), new Point(pBottomLeft.X, pBottomLeft.Y - ((this.Height / 4) * 3))); g.DrawString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay(fHighest), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X - g.MeasureString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay(fHighest), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Width - 15, pBottomLeft.Y - ((this.Height / 4) * 3) - (g.MeasureString(tEngine.CurrencySymbol + TillEngine.TillEngine.FormatMoneyForDisplay(fHighest), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f)).Height / 2))); for (int i = 0; i < 9; i++) { g.DrawLine(new Pen(GTill.Properties.Settings.Default.cFrmForeColour, 2.0f), new Point(pBottomLeft.X + (i * nXDiff) + Convert.ToInt32(0.5 / fAmountEachXPixel), pBottomLeft.Y), new Point(pBottomLeft.X + (i * nXDiff) + Convert.ToInt32(0.5 / fAmountEachXPixel), pBottomLeft.Y + 15)); g.DrawString((i + 9).ToString(), new Font(GTill.Properties.Settings.Default.sFontName, 16.0f), new SolidBrush(GTill.Properties.Settings.Default.cFrmForeColour), new PointF(pBottomLeft.X + (i * nXDiff) + Convert.ToInt32(0.5 / fAmountEachXPixel) - 15, pBottomLeft.Y + 15)); } // Draw the title g.DrawString("Hourly 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)); 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)); }