Exemple #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("欢迎!");
            //}
        }
Exemple #2
0
 private void GetResult(object sender, EventArgs e)
 {
     if (top != null && top.FirstNum != null && top.SecondNum != null && top.Type != Operation.TypeOfOperation.NULL)
     {
         Result.Text = $"Result: {top.GetResult().Result}";
         AddInterface();
     }
     else if (top != null && top.FirstNum != null && top.FirstSub != Operation.SubOperations.NULL)
     {
         Result.Text = $"Result: {top.GetResult().Result}";
         AddInterface();
     }
     else
     {
         MessageBox.Show("Ошибка.");
         return;
     }
 }
 private void EqualAction(object obj)
 {
     oper           = OperateFactory.CreateOperate(Operator);
     oper.NumA      = NumberLists[0];
     oper.NumB      = NumberLists[1];
     Number         = oper.GetResult();
     _numberString  = null;
     NumberLists[0] = Number;
     NumberLists.RemoveAt(1);
 }
Exemple #4
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 = "";
            //}
        }
Exemple #5
0
        static void Main(string[] args)
        {
            List <string> listopersign = new List <string>();

            listopersign.Add("+");
            listopersign.Add("-");
            listopersign.Add("*");
            listopersign.Add("/");
            OperationFactory fac = new OperationFactory();

            foreach (var item in listopersign)
            {
                Operation oper = fac.createOperate(item);
                oper.NumberA = 88.8f;
                oper.NumberB = 11.1f;
                double result = oper.GetResult();
                Console.WriteLine("{0:#.###} {1} {2:#.###} = {3:#.###}", oper.NumberA, item, oper.NumberB, result);
            }
            Console.Read();
        }