Example #1
0
        public static Operation createOperate(string operate)
        {
            Operation oper = null;

            switch (operate)
            {
            case "+":
            {
                oper = new OperationAdd();
                break;
            }

            case "-":
            {
                oper = new OperationSub();
                break;
            }

            case "*":
            {
                oper = new OperationMul();
                break;
            }

            case "/":
            {
                oper = new OperationDiv();
                break;
            }

            case "sqr":
            {
                oper = new OperationSqr();
                break;
            }

            case "sqrt":
            {
                oper = new OperationSqrt();
                break;
            }

            case "+/-":
            {
                oper = new OperationReverse();
                break;
            }
            }

            return(oper);
        }
Example #2
0
        private void btnCount_Click(object sender, EventArgs e)
        {
            if (txtNum1.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("操作数不能为空!");
                this.txtNum1.Focus();
                return;
            }
            if (txtNum2.Text.Trim().Equals(string.Empty))
            {
                MessageBox.Show("被操作数不能为空!");
                this.txtNum2.Focus();
                return;
            }
            try
            {
                string    s    = this.cbxSign.SelectedItem.ToString().Trim();
                Operation oper = new Operation();
                switch (s)
                {
                case "+":

                    oper = new OperationAdd();
                    break;

                case "-":

                    oper = new OperationMinus();
                    break;

                case "*":

                    oper = new OperationRide();
                    break;

                case "/":

                    oper = new OperationDiv();
                    break;
                }
                oper.NumberA        = double.Parse(this.txtNum1.Text.Trim());
                oper.NumberB        = double.Parse(this.txtNum2.Text.Trim());
                this.lblResult.Text = oper.GetReault().ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Example #3
0
        public static Operation createOperate(string operate)
        {
            Operation oper = null;
            switch (operate)
            {
                case "+":
                    {
                        oper = new OperationAdd();
                        break;
                    }
                case "-":
                    {
                        oper = new OperationSub();
                        break;
                    }
                case "*":
                    {
                        oper = new OperationMul();
                        break;
                    }
                case "/":
                    {
                        oper = new OperationDiv();
                        break;
                    }
                case "sqr":
                    {
                        oper = new OperationSqr();
                        break;
                    }
                case "sqrt":
                    {
                        oper = new OperationSqrt();
                        break;
                    }
                case "+/-":
                    {
                        oper = new OperationReverse();
                        break;
                    }
            }

            return oper;
        }