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("欢迎!"); //} }
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 = ""; //} }
public Operation SetOperation(string type) { return(OperationFactory.CreateOperation(type)); }