Пример #1
0
        public static void Dzialania(TextBox wejscie, TextBox wyjscie, char akcja, ref bool blad, ref bool szczyt, ref string ost)
        {
            string wej = wejscie.Text;
            string wyj = wyjscie.Text;

            if (wej.EndsWith(","))
            {
                wej          = wej.Replace(",", "");
                wejscie.Text = wej;
            }
            if (akcja != '=')
            {
                if (wyj.Length == 0)
                {
                    wyjscie.Text = wej + ' ' + akcja;
                    szczyt       = false;
                }
                else
                {
                    if ((wyj.EndsWith("+") || wyj.EndsWith("/") || wyj.EndsWith("-") || wyj.EndsWith("*")) && szczyt == false)
                    {
                        wyjscie.Text = wyj.Remove(wyj.Length - 1, 1) + akcja;
                    }
                    else if (wyj.EndsWith("="))
                    {
                        wyjscie.Text = wej + ' ' + akcja;
                    }
                    else
                    {
                        wyjscie.Text = wyj + ' ' + wej + ' ' + akcja;
                        wejscie.Text = Logika.Oblicz(wyj + ' ' + wej, ref blad);
                        szczyt       = false;
                    }
                }
            }
            else
            {
                if (wyj.Length == 0)
                {
                    wyjscie.Text = wej + " =";
                }
                else
                {
                    if (wyj.Last() == '=')
                    {
                        wyjscie.Text = wej + ost + " =";
                        wejscie.Text = Logika.Oblicz(wej + ost, ref blad);
                    }
                    else
                    {
                        ost          = ' ' + wyj.Last().ToString() + ' ' + wej;
                        wejscie.Text = Logika.Oblicz(wyj + ' ' + wej, ref blad);
                        wyjscie.Text = wyj + ' ' + wej + " =";
                    }
                }
                szczyt = false;
            }
            wyjscie.Select(wyjscie.Text.Length, 0);
            wyjscie.Focus();
        }
Пример #2
0
        private void Numer_click(object sender, RoutedEventArgs e)
        {
            Blad();
            Button button = (Button)sender;
            string num    = button.Content.ToString();

            if (sczyt == false)
            {
                if (pamiec.Text.Length != 0 && pamiec.Text.Last() == '=')
                {
                    pamiec.Text = "";
                }
                wejscie.Text = num;
                sczyt        = true;
            }
            else
            {
                if (wejscie.Text.Equals("0"))
                {
                    wejscie.Text = num;
                }
                else
                {
                    if (wejscie.Text.Length < 21)
                    {
                        wejscie.Text += num;
                    }
                }
            }
            Logika.Rozmiar(wejscie);
        }
Пример #3
0
 private void Backspace_click(object sender, RoutedEventArgs e)
 {
     Blad();
     if (sczyt != false)
     {
         if (!wejscie.Text.Equals("0"))
         {
             if ((wejscie.Text.Length == 2 && Double.Parse(wejscie.Text.Replace(',', '.'), CultureInfo.InvariantCulture) < 0) || wejscie.Text.Length == 1)
             {
                 wejscie.Text = "0";
             }
             else
             {
                 wejscie.Text = wejscie.Text.Remove(wejscie.Text.Length - 1, 1);
             }
         }
     }
     else
     {
         if (pamiec.Text.Length != 0)
         {
             pamiec.Text = "";
         }
     }
     Logika.Rozmiar(wejscie);
 }
Пример #4
0
 private void Clearall_click(object sender, RoutedEventArgs e)
 {
     wejscie.Text = "0";
     pamiec.Text  = "";
     sczyt        = false;
     Logika.Rozmiar(wejscie);
 }
Пример #5
0
 private void Clear_click(object sender, RoutedEventArgs e)
 {
     Blad();
     wejscie.Text = "0";
     sczyt        = true;
     Logika.Rozmiar(wejscie);
 }
Пример #6
0
        private void Akcja_click(object sender, RoutedEventArgs e)
        {
            Blad();
            Button but = (Button)sender;

            Logika.Dzialania(wejscie, pamiec, but.Content.ToString().First(), ref blad, ref sczyt, ref ost);
            Logika.Rozmiar(wejscie);
        }
Пример #7
0
 private void Enter_click(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         e.Handled = true;
         Logika.PerformClick(rownanie);
     }
 }
Пример #8
0
 private void Blad()
 {
     if (blad == true)
     {
         Logika.PerformClick(clearall);
         blad = false;
         ost  = "";
     }
 }
Пример #9
0
 private void Kropka_click(object sender, RoutedEventArgs e)
 {
     Blad();
     if (!wejscie.Text.Contains(',') && wejscie.Text.Length < 21)
     {
         wejscie.Text += ',';
         Logika.Rozmiar(wejscie);
         sczyt = true;
     }
 }
Пример #10
0
 private void  Zero_click(object sender, RoutedEventArgs e)
 {
     Blad();
     if (sczyt == false)
     {
         wejscie.Text = "0";
         sczyt        = true;
     }
     else if (!wejscie.Text.Equals("0") && wejscie.Text.Length < 21)
     {
         wejscie.Text += '0';
         Logika.Rozmiar(wejscie);
     }
 }
Пример #11
0
 private void Negacja_click(object sender, RoutedEventArgs e)
 {
     Blad();
     if (Double.Parse(wejscie.Text.Replace(',', '.'), CultureInfo.InvariantCulture) != 0)
     {
         if (Double.Parse(wejscie.Text.Replace(',', '.'), CultureInfo.InvariantCulture) < 0)
         {
             wejscie.Text = wejscie.Text.Remove(0, 1);
         }
         else
         {
             if (wejscie.Text.Length < 21)
             {
                 wejscie.Text = '-' + wejscie.Text;
             }
         }
     }
     sczyt = true;
     Logika.Rozmiar(wejscie);
 }
Пример #12
0
 private void Window_KeyDown(object sender, KeyEventArgs e)
 {
     if (!(Keyboard.IsKeyDown(Key.RightShift) || Keyboard.IsKeyDown(Key.LeftShift)))
     {
         if (e.Key == Key.D1 || e.Key == Key.NumPad1)
         {
             Logika.PerformClick(jeden);
         }
         else if (e.Key == Key.D2 || e.Key == Key.NumPad2)
         {
             Logika.PerformClick(dwa);
         }
         else if (e.Key == Key.D3 || e.Key == Key.NumPad3)
         {
             Logika.PerformClick(trzy);
         }
         else if (e.Key == Key.D4 || e.Key == Key.NumPad4)
         {
             Logika.PerformClick(cztery);
         }
         else if (e.Key == Key.D5 || e.Key == Key.NumPad5)
         {
             Logika.PerformClick(piec);
         }
         else if (e.Key == Key.D6 || e.Key == Key.NumPad6)
         {
             Logika.PerformClick(szesc);
         }
         else if (e.Key == Key.D7 || e.Key == Key.NumPad7)
         {
             Logika.PerformClick(siedem);
         }
         else if (e.Key == Key.D8 || e.Key == Key.NumPad8)
         {
             Logika.PerformClick(osiem);
         }
         else if (e.Key == Key.D9 || e.Key == Key.NumPad9)
         {
             Logika.PerformClick(dziewiec);
         }
         else if (e.Key == Key.D0 || e.Key == Key.NumPad0)
         {
             Logika.PerformClick(zero);
         }
         else if (e.Key == Key.Back)
         {
             Logika.PerformClick(backspace);
         }
         else if (e.Key == Key.OemComma || e.Key == Key.OemPeriod)
         {
             Logika.PerformClick(kropka);
         }
         else if (e.Key == Key.OemMinus)
         {
             Logika.PerformClick(minus);
         }
         else if (e.Key == Key.Enter || e.Key == Key.OemPlus)
         {
             Logika.PerformClick(rownanie);
         }
         else if (e.Key == Key.OemQuestion)
         {
             Logika.PerformClick(dzielenie);
         }
         else if (e.Key == Key.Multiply)
         {
             Logika.PerformClick(mnozenie);
         }
     }
     else
     {
         if (e.Key == Key.OemPlus)
         {
             Logika.PerformClick(dodawanie);
         }
         else if (e.Key == Key.D8)
         {
             Logika.PerformClick(mnozenie);
         }
     }
 }