Esempio n. 1
0
        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}");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sets up the form's controls
        /// </summary>
        public void SetupForm()
        {
            sCurrentKeyBeingEdited = "";
            lblTitle           = new Label();
            lblTitle.BackColor = cFrmBackColour;
            lblTitle.ForeColor = cFrmForeColour;
            lblTitle.Font      = new Font(sFontName, 14.0f);
            lblTitle.AutoSize  = false;
            lblTitle.Location  = new Point(0, 0);
            lblTitle.Size      = new Size(this.Width, 25);
            lblTitle.TextAlign = ContentAlignment.MiddleCenter;
            lblTitle.Text      = "Define Preset Keys";
            this.Controls.Add(lblTitle);

            int nTotalWidth = (this.Width / 3) * 2;

            lblColumnTitles = new Label[3];
            for (int i = 0; i < lblColumnTitles.Length; i++)
            {
                lblColumnTitles[i]           = new Label();
                lblColumnTitles[i].BackColor = cFrmBackColour;
                lblColumnTitles[i].ForeColor = cFrmForeColour;
                lblColumnTitles[i].Font      = new Font(sFontName, 16.0f);
                lblColumnTitles[i].Top       = lblTitle.Top + (lblTitle.Height * 2);
                lblColumnTitles[i].AutoSize  = true;
                this.Controls.Add(lblColumnTitles[i]);
            }

            lblColumnTitles[0].Text = "Key";
            lblColumnTitles[1].Text = "Barcode";
            lblColumnTitles[2].Text = "Description";
            lblColumnTitles[0].Left = (this.Width / 2) - (nTotalWidth / 2);
            lblColumnTitles[1].Left = lblColumnTitles[0].Left + 75;
            lblColumnTitles[2].Left = lblColumnTitles[1].Left + 200;

            lbKeyName                       = new ListBox();
            lbKeyName.BackColor             = cFrmBackColour;
            lbKeyName.ForeColor             = cFrmForeColour;
            lbKeyName.Font                  = new Font(sFontName, 16.0f);
            lbKeyName.Top                   = lblColumnTitles[0].Top + (lblColumnTitles[0].Height * 2);
            lbKeyName.Left                  = lblColumnTitles[0].Left;
            lbKeyName.Width                 = 100;
            lbKeyName.BorderStyle           = BorderStyle.None;
            lbKeyName.Height                = this.Height - lbKeyName.Top - 100;
            lbKeyName.SelectedIndexChanged += new EventHandler(lbKeyName_SelectedIndexChanged);
            lbKeyName.KeyDown              += new KeyEventHandler(lbKeyName_KeyDown);
            this.Controls.Add(lbKeyName);

            lbKeyCode                       = new ListBox();
            lbKeyCode.BackColor             = cFrmBackColour;
            lbKeyCode.ForeColor             = cFrmForeColour;
            lbKeyCode.Font                  = new Font(sFontName, 16.0f);
            lbKeyCode.Top                   = lbKeyName.Top;
            lbKeyCode.Left                  = lblColumnTitles[1].Left;
            lbKeyCode.Width                 = 225;
            lbKeyCode.Height                = this.Height - lbKeyCode.Top - 100;
            lbKeyCode.BorderStyle           = BorderStyle.None;
            lbKeyCode.SelectedIndexChanged += new EventHandler(lbKeyName_SelectedIndexChanged);
            lbKeyCode.KeyDown              += new KeyEventHandler(lbKeyName_KeyDown);
            this.Controls.Add(lbKeyCode);

            lbDescription                       = new ListBox();
            lbDescription.BackColor             = cFrmBackColour;
            lbDescription.ForeColor             = cFrmForeColour;
            lbDescription.Font                  = new Font(sFontName, 16.0f);
            lbDescription.Top                   = lbKeyName.Top;
            lbDescription.Left                  = lblColumnTitles[2].Left;
            lbDescription.Width                 = nTotalWidth - 200 - 75;
            lbDescription.Height                = this.Height - lbDescription.Top - 100;
            lbDescription.BorderStyle           = BorderStyle.None;
            lbDescription.SelectedIndexChanged += new EventHandler(lbKeyName_SelectedIndexChanged);
            lbDescription.KeyDown              += new KeyEventHandler(lbKeyName_KeyDown);
            this.Controls.Add(lbDescription);

            lbKeyCode.BringToFront();
            lbDescription.BringToFront();

            lblInstruction           = new Label();
            lblInstruction.Text      = "Press Enter to change the currently selected key, or ESC to return to the till";
            lblInstruction.BackColor = cFrmBackColour;
            lblInstruction.ForeColor = cFrmForeColour;
            lblInstruction.Font      = new Font(sFontName, 14.0f);
            lblInstruction.AutoSize  = false;
            lblInstruction.Width     = this.Width - 40;
            lblInstruction.Height    = 30;
            lblInstruction.Top       = this.Height - 60;
            lblInstruction.Left      = 20;
            lblInstruction.TextAlign = ContentAlignment.MiddleCenter;
            this.Controls.Add(lblInstruction);

            for (int i = 0; i < 12; i++)
            {
                lbKeyName.Items.Add("F" + (i + 1).ToString());
                string sItemBarcode = tEngine.sBarcodeFromFunctionKey("F" + (i + 1).ToString());
                if (sItemBarcode.TrimEnd('\0').TrimEnd(' ') != "")
                {
                    string[] sItemDetails = tEngine.GetItemDetailsForLookup(sItemBarcode.TrimEnd('\0').TrimEnd(' '));
                    lbDescription.Items.Add(sItemDetails[0]);
                }
                else
                {
                    lbDescription.Items.Add("Undefined Key");
                }
                lbKeyCode.Items.Add(sItemBarcode);
            }
            for (int i = 0; i < 12; i++)
            {
                lbKeyName.Items.Add("SF" + (i + 1).ToString());
                string sItemBarcode = tEngine.sBarcodeFromFunctionKey("SF" + (i + 1).ToString());
                if (sItemBarcode.TrimEnd('\0').TrimEnd(' ') != "")
                {
                    string[] sItemDetails = tEngine.GetItemDetailsForLookup(sItemBarcode.TrimEnd('\0').TrimEnd(' '));
                    lbDescription.Items.Add(sItemDetails[0]);
                }
                else
                {
                    lbDescription.Items.Add("Undefined Key");
                }
                lbKeyCode.Items.Add(sItemBarcode);
            }

            lbKeyCode.SelectedIndex     = 0;
            lbDescription.SelectedIndex = 0;
            lbKeyName.SelectedIndex     = 0;
        }