เริ่มกันเลย
Create new window application project in ProjectType select Visual C# template : Window Application then rename project to MachClient in Name field. Drag textbox , lable and button to From like this.

Select browse to : Web service in this solution



if (comboBox_Operator.SelectedIndex == -1)
{
MessageBox.Show("กรุณาเลือก operator");
return;
}
MyService.Service myservice = new HelloClient.MyService.Service();
if (comboBox_Operator.SelectedIndex == 0)
{
label_Result.Text = myservice.add(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}
else if (comboBox_Operator.SelectedIndex == 1)
{
label_Result.Text = myservice.sub(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}
else if (comboBox_Operator.SelectedIndex == 2)
{
label_Result.Text = myservice.multi(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text)).ToString();
}
Explain:
Read text check condition if textbox1 and textbox2 is not empty.
Green text create instance of MathService.
แล้วทีนี้ก็ลอง รันโปรเจคดูนะครับจะได้ผลเป็นยังไงบวกลบคูณเลขถูกเปล่าว อันนี้ผมเขียนแบบง่าย ๆ ไม่มีการรตรวจสอบว่าถ้า input เป็น text จะทำยังไง ง่ายอีกละ ก็ให้ exception แล้วบอกว่า อะไรก็ได้เช่น กรุณาป้อนตัวเลขค่ะ เอาไว้มาต่อกันครั้งหน้าดีกว่าครับ
No comments:
Post a Comment