Example #1
0
 public void ClearBox()
 {
     RxBox.Clear();
     FeeBox.Clear();
     OutStandingBox.Clear();
     TreatmentBox.Clear();
     MessageBox.Show("Entry Added");
     this.Close();
 }
        /// <summary>
        /// Checks if the contents of a textbox are in valid incrememnts for that parameter
        /// </summary>
        /// <remarks>For Axis, a valid increment is 1, for other parameters, a valid increment is 0.25</remarks>
        /// <param name="tb">The textbox to check</param>
        /// <param name="box">The Rx parameter - Sphere, Cylinder, Axis or Add</param>
        /// <returns>True if the increment is valid, false otherwise</returns>
        private bool Rx_TextBox_ValidIncrement(TextBox tb, RxBox box)
        {
            float f = Math.Abs(Convert.ToSingle(tb.Text));

            if (box == RxBox.Axis)
            {
                if (f % 1 != 0)
                {
                    return(false);
                }
            }
            else
            {
                if (f % 0.25 != 0)
                {
                    return(false);
                }
            }
            return(true);
        }
        //Checks for valid input for Rx textboxes.  Checks the box passed in through "tb, "
        //using different criteria based on parameter the box represents (determined by "box").
        //Checks for valid ranges, does not check for valid increments.

        /// <summary>
        /// Checks for valid input for an Rx textbox
        /// </summary>
        /// <param name="tb">The box to check the contents of</param>
        /// <param name="box">The Rx parameter - Sphere, Cylinder, Axis or Add</param>
        /// <returns>True if the contents are valid, false otherwise</returns>
        /// <exception cref="System.FormatException">Thrown when the text is not a proper integer or real number</exception>
        private bool Rx_TextBox_Valid(TextBoxBase tb, RxBox box)
        {
            int   pos = tb.Text.LastIndexOf('.');
            float val;

            if (box == RxBox.Axis)
            {
                if (tb.TextLength == 0) //Blank
                {
                    tb.Text = "0";
                }

                try
                { //Is the contents a valid integer?
                    val = Math.Abs(Convert.ToInt16(tb.Text));
                }
                catch
                {
                    return(false);
                }

                tb.DeselectAll();
                tb.Text = val.ToString("0");

                //Checks for valid range
                if (val > AXIS_MAX_VALUE)
                {
                    return(false);
                }
            }
            else //Sphere, Cylinder or Add
            {
                if (tb.TextLength == 0)
                {
                    tb.Text = "0.00";
                }

                try
                { //Is the contents a valid real number?
                    val = Convert.ToSingle(tb.Text);
                }
                catch
                {
                    return(false);
                }

                tb.DeselectAll();
                if (pos > -1) //Handle decimal
                {
                    string ts = tb.Text.Substring(pos + 1);
                    if (ts == "2" || ts == "7")
                    {
                        if (val < 0)
                        {
                            val -= 0.05F;
                        }
                        else
                        {
                            val += 0.05F;
                        }
                    }
                }
                // if(box == RxBox.Cyl)
                //     val = -Math.Abs(val); // CYL is converted later if necessary
                tb.Text = val.ToString("0.00");

                //Checks for valid range
                if (box == RxBox.Sphere)
                {
                    if (val > SPHERE_MAX_VALUE)
                    {
                        return(false);
                    }
                }
                else if (box == RxBox.Cyl)
                {
                    if (-val > CYLINDER_MAX_VALUE)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (val > ADD_MAX_VALUE)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        /// <summary>
        /// Checks if the contents of a textbox are in valid incrememnts for that parameter
        /// </summary>
        /// <remarks>For Axis, a valid increment is 1, for other parameters, a valid increment is 0.25</remarks>
        /// <param name="tb">The textbox to check</param>
        /// <param name="box">The Rx parameter - Sphere, Cylinder, Axis or Add</param>
        /// <returns>True if the increment is valid, false otherwise</returns>
        private bool Rx_TextBox_ValidIncrement(TextBox tb, RxBox box)
        {
            float f = Math.Abs(Convert.ToSingle(tb.Text));

            if(box == RxBox.Axis) {
                if(f % 1 != 0)
                    return false;
            } else {
                if(f % 0.25 != 0)
                    return false;
            }
            return true;
        }
        //Checks for valid input for Rx textboxes.  Checks the box passed in through "tb, "
        //using different criteria based on parameter the box represents (determined by "box").
        //Checks for valid ranges, does not check for valid increments.
        /// <summary>
        /// Checks for valid input for an Rx textbox
        /// </summary>
        /// <param name="tb">The box to check the contents of</param>
        /// <param name="box">The Rx parameter - Sphere, Cylinder, Axis or Add</param>
        /// <returns>True if the contents are valid, false otherwise</returns>
        /// <exception cref="System.FormatException">Thrown when the text is not a proper integer or real number</exception>
        private bool Rx_TextBox_Valid(TextBoxBase tb, RxBox box)
        {
            int pos = tb.Text.LastIndexOf('.');
            float val;

            if(box == RxBox.Axis)
            {
                if(tb.TextLength == 0) //Blank
                    tb.Text = "0";

                try { //Is the contents a valid integer?
                    val = Math.Abs(Convert.ToInt16(tb.Text));
                }
                catch {
                    return false;
                }

                tb.DeselectAll();
                tb.Text = val.ToString("0");

                //Checks for valid range
                if(val > AXIS_MAX_VALUE) {
                    return false;
                }
            }
            else //Sphere, Cylinder or Add
            {
                if(tb.TextLength == 0)
                    tb.Text = "0.00";

                try { //Is the contents a valid real number?
                    val = Convert.ToSingle(tb.Text);
                }
                catch {
                    return false;
                }

                tb.DeselectAll();
                if(pos > -1) //Handle decimal
                {
                    string ts = tb.Text.Substring(pos + 1);
                    if(ts == "2" || ts == "7")
                    {
                        if(val < 0)
                            val -= 0.05F;
                        else
                            val += 0.05F;
                    }
                }
                if(box == RxBox.Cyl)
                    val = -Math.Abs(val);
                tb.Text = val.ToString("0.00");

                //Checks for valid range
                if(box == RxBox.Sphere) {
                    if(val > SPHERE_MAX_VALUE) {
                        return false;
                    }
                } else if(box == RxBox.Cyl) {
                    if(-val > CYLINDER_MAX_VALUE) {
                        return false;
                    }
                } else {
                    if(val > ADD_MAX_VALUE) {
                        return false;
                    }
                }
            }
            return true;
        }