Advertisement
Pavle_nis

Moj broj

Mar 25th, 2017
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. private void button2_Click(object sender, EventArgs e)
  2.         {
  3.             Vreme.Stop();
  4.             if (textBox1.Text == "")
  5.             {
  6.                 MessageBox.Show("Niste uneli resenje!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  7.                 return;
  8.             }
  9.             string temp = textBox1.Text;
  10.             string output = temp.Substring(temp.Length - 1, 1);
  11.             /*if(!(textBox1.Text.Contains(button3.Text)|| textBox1.Text.Contains(button4.Text)|| textBox1.Text.Contains(button5.Text)|| textBox1.Text.Contains(button6.Text)|| textBox1.Text.Contains(button7.Text)|| textBox1.Text.Contains(button8.Text)))
  12.             {
  13.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  14.                 return;
  15.             }*/
  16.             if(textBox1.Text.StartsWith("+")|| textBox1.Text.StartsWith("-")|| textBox1.Text.StartsWith("*")|| textBox1.Text.StartsWith("/"))
  17.             {
  18.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  19.                 return;
  20.             }
  21.             if (output == button3.Text)
  22.             {
  23.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  24.                 return;
  25.             }
  26.             if (output == button4.Text)
  27.             {
  28.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  29.                 return;
  30.             }
  31.             if (output == button5.Text)
  32.             {
  33.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  34.                 return;
  35.             }
  36.             if (output == button6.Text)
  37.             {
  38.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  39.                 return;
  40.             }
  41.             var count = textBox1.Text.Count(x => x == '(');
  42.             var count2 = textBox1.Text.Count(x => x == ')');
  43.             if (count > count2 || count < count2)
  44.             {
  45.                 MessageBox.Show("Neispravan matematicki izraz!", "Moj Broj", MessageBoxButtons.OK, MessageBoxIcon.Information);
  46.                 return;
  47.             }
  48.             Parser par = new Parser();
  49.             string line = textBox1.Text;
  50.  
  51.             char[] exp = line.ToCharArray();
  52.             int value = par.EvaluateExpression(exp);
  53.  
  54.             textBox1.Text = value + "=" + line;
  55.  
  56.             Resavac re = new Resavac();
  57.             int target;
  58.             int target10;
  59.             int target100;
  60.             int hint1;
  61.             int hint2;
  62.             int hint3;
  63.             int hint4;
  64.             int hint5;
  65.             int hint6;
  66.             tbAnswer.Text = "";
  67.             if (!int.TryParse(label2.Text, out target))
  68.             {
  69.                 // tbTarget.Focus();
  70.                 return;
  71.             }
  72.             if (!int.TryParse(label3.Text, out target10))
  73.             {
  74.                 //tbTarget.Focus();
  75.                 return;
  76.             }
  77.             if (!int.TryParse(label4.Text, out target100))
  78.             {
  79.                 //tbTarget.Focus();
  80.                 return;
  81.             }
  82.             if (!int.TryParse(tbHint1.Text, out hint1))
  83.             {
  84.                 tbHint1.Focus();
  85.                 return;
  86.             }
  87.             if (!int.TryParse(tbHint2.Text, out hint2))
  88.             {
  89.                 tbHint2.Focus();
  90.                 return;
  91.             }
  92.             if (!int.TryParse(tbHint3.Text, out hint3))
  93.             {
  94.                 tbHint3.Focus();
  95.                 return;
  96.             }
  97.             if (!int.TryParse(tbHint4.Text, out hint4))
  98.             {
  99.                 tbHint4.Focus();
  100.                 return;
  101.             }
  102.             if (!int.TryParse(tbHint5.Text, out hint5))
  103.             {
  104.                 tbHint5.Focus();
  105.                 return;
  106.             }
  107.             if (!int.TryParse(tbHint6.Text, out hint6))
  108.             {
  109.                 tbHint6.Focus();
  110.                 return;
  111.             }
  112.             tbAnswer.Text = re.Calculate(target, target10, target100, hint1, hint2, hint3, hint4, hint5, hint6);
  113.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement