Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7.  
  8. namespace WebApplication1
  9. {
  10.     public partial class WebForm1 : System.Web.UI.Page
  11.     {
  12.         private double a, b;
  13.         private bool isNumbers(ref double a, ref double b)
  14.         {
  15.             return Double.TryParse(tbLeft.Text, out a) && Double.TryParse(tbRight.Text, out b);
  16.         }
  17.  
  18.         private void showErrorInput()
  19.         {
  20.             result.Text = "Ошибка ввода данных!";
  21.         }
  22.         protected void Page_Load(object sender, EventArgs e)
  23.         {
  24.  
  25.         }
  26.  
  27.         protected void addition_Click(object sender, EventArgs e)
  28.         {
  29.             if (isNumbers(ref a, ref b))
  30.             {
  31.                 result.Text = (a + b).ToString();
  32.             }
  33.             else
  34.             {
  35.                 showErrorInput();
  36.             }
  37.         }
  38.  
  39.         protected void multiplication_Click(object sender, EventArgs e)
  40.         {
  41.             if (isNumbers(ref a, ref b))
  42.             {
  43.                 result.Text = (a * b).ToString();
  44.             }
  45.             else
  46.             {
  47.                 showErrorInput();
  48.             }
  49.         }
  50.  
  51.         protected void division_Click(object sender, EventArgs e)
  52.         {
  53.             if (isNumbers(ref a, ref b) && b!=0)
  54.             {
  55.                 result.Text = (a / b).ToString();
  56.             }
  57.             else
  58.             {
  59.                 showErrorInput();
  60.             }
  61.         }
  62.  
  63.         protected void subtraction_Click(object sender, EventArgs e)
  64.         {
  65.             if (isNumbers(ref a, ref b))
  66.             {
  67.                 result.Text = (a - b).ToString();
  68.             }
  69.             else
  70.             {
  71.                 showErrorInput();
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement