Beispiel #1
0
        private void ToDecBut_Click(object sender, EventArgs e)
        {
            Fraction fr = new Fraction();

            ControllerSimple.CreateFraction(MainTextBox.Text, ref fr);
            double dec = Calculations.ToDecimal(fr);

            DecFCheckBox.Checked = true;
            MainTextBox.Text     = dec.ToString();
        }
Beispiel #2
0
        private void ResultBut_Click(object sender, EventArgs e)
        {
            // Indiciates whether the string has the right format or not.
            bool format = true;

            // If it's empty.
            if (format)
            {
                if (MainTextBox.Text == "")
                {
                    format = false;
                    MessageBox.Show("The string is empty!", "Input error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // If there are unclosed brackets.
            if (format)
            {
                if (Brac1Count != Brac2Count)
                {
                    format = false;
                    MessageBox.Show("There are unclosed brackets!", "Input error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // If the last symbol is not a digit or the closing bracket.
            if (format)
            {
                if (!Char.IsDigit(MainTextBox.Text[MainTextBox.Text.Length - 1]) &&
                    MainTextBox.Text[MainTextBox.Text.Length - 1] != ')')
                {
                    format = false;
                    MessageBox.Show("The last symbol should be a digit or the closing bracket!", "Input error!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            // If the input string has a right format
            if (format)
            {
                // Calculations.

                // Enabling converters.
                if (SimpFCheckBox.Checked)
                {
                    ToDecBut.Enabled = true;
                }
                else
                {
                    ToSimpleBut.Enabled = true;
                }

                // If it's the decimal calculations.
                string result = "";
                if (DecFCheckBox.Checked)
                {
                    result = ControllerDecimal.DecFracCalcAll(MainTextBox.Text);
                }
                else
                {
                    result = ControllerSimple.SimpFracCalcAll(MainTextBox.Text);
                }

                PreviousStrLabel.Text = MainTextBox.Text + "=" + result;
                MainTextBox.Text      = result;
            }
        }