Ejemplo n.º 1
0
        private void button_Operation_Click(object sender, EventArgs e)
        {
            string strOperator;

            try
            {
                strOperator = textBox_Operator.Text.Trim();

                //if (strOperator != "+" && strOperator != "-" && strOperator != "*" && strOperator != "/")
                //   throw new Exception("操作符输入错误");

                Operation Opr = OperationFactory.CreateOperation(strOperator);

                Opr.NumberA = Convert.ToDouble(textBox_NumberA.Text.Trim());
                Opr.NumberB = Convert.ToDouble(textBox_NumberB.Text.Trim());

                textBox_Result.Text = Opr.GetResult().ToString();
            }

            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                textBox_Result.Text = "";
                throw;
            }
            //finally
            //{
            //    MessageBox.Show("欢迎!");
            //}
        }
Ejemplo n.º 2
0
        private void button_Operation_Click(object sender, EventArgs e)
        {
            string strOperator;

            //try
            //{
            strOperator = textBox_Operator.Text.Trim();
            Operation Opr = OperationFactory.CreateOperation(strOperator);

            Opr.NumberA         = Convert.ToDouble(textBox_NumberA.Text.Trim());
            Opr.NumberB         = Convert.ToDouble(textBox_NumberB.Text.Trim());
            textBox_Result.Text = Opr.GetResult().ToString();
            //}
            //catch (System.Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //    textBox_Result.Text = "";
            //}
        }
Ejemplo n.º 3
0
 public Operation SetOperation(string type)
 {
     return(OperationFactory.CreateOperation(type));
 }