Ejemplo n.º 1
0
        private void TbDeskWidth_Validating(object sender, CancelEventArgs e)
        {
            // Allow user to tab or otherwise move through the field without adding a value
            if (tbDeskWidth.Text.Length == 0)
            {
                return;
            }

            try
            {
                bool CancelProgress = false;

                // Rest error provider
                ErrProv_DeskQuote.Clear();

                // Parse to a number
                int.TryParse(tbDeskWidth.Text, out int userWidth);

                //
                int UserNumber = int.Parse(tbDeskWidth.Text);

                // Check against min max constraints.
                if (userWidth < DeskQuote.MIN_WIDTH)
                {
                    ErrProv_DeskQuote.SetError(tbDeskWidth, "Width must be " + DeskQuote.MIN_WIDTH + " or greater.");
                    CancelProgress = true;
                }

                if (userWidth > DeskQuote.MAX_WIDTH)
                {
                    ErrProv_DeskQuote.SetError(tbDeskWidth, "Width must be " + DeskQuote.MAX_WIDTH + " or less.");
                    CancelProgress = true;
                }

                if (CancelProgress)
                {
                    e.Cancel = true;
                    tbDeskWidth.Select(0, tbDeskWidth.Text.Length);
                }
            }
            catch (Exception exception)
            {
                ErrProv_DeskQuote.SetError(tbDeskWidth, exception.Message);
                tbDeskWidth.Select(0, tbDeskWidth.Text.Length);
                e.Cancel = true;
            }
        }
Ejemplo n.º 2
0
        private void TbDeskDepth_Validating(object sender, CancelEventArgs e)
        {
            // Allow user to tab or otherwise move through the field without adding a value
            if (tbDeskDepth.Text.Length == 0)
            {
                return;
            }

            // Rest error provider.
            ErrProv_DeskQuote.Clear();

            bool CancelProgress = false;
            bool isNum          = int.TryParse(tbDeskDepth.Text, out int UserNumber);

            if (!isNum)
            {
                ErrProv_DeskQuote.SetError(tbDeskDepth, "Please enter a valid number.");
                CancelProgress = true;
            }

            // If we have a valid number, then check total value of the text field against min max constraints.
            if (isNum)
            {
                if (UserNumber < DeskQuote.MIN_DEPTH)
                {
                    ErrProv_DeskQuote.SetError(tbDeskDepth, "Depth must be " + DeskQuote.MIN_DEPTH + " or greater.");
                    CancelProgress = true;
                }
                if (UserNumber > DeskQuote.MAX_DEPTH)
                {
                    ErrProv_DeskQuote.SetError(tbDeskDepth, "Depth must be " + DeskQuote.MAX_DEPTH + " or less.");
                    CancelProgress = true;
                }
            }

            // Carry out cancel process so user doesn't move to the next field.
            if (CancelProgress)
            {
                e.Cancel = true;
                tbDeskDepth.Select(0, tbDeskDepth.Text.Length);
            }
        }