Lottorivit.xaml.cs 3.14 KB
Newer Older
M1888's avatar
M1888 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Lottokone
{
    /// <summary>
    /// Interaction logic for Lottorivit.xaml
    /// </summary>
    public partial class Lottorivit : Window
    {
M1888's avatar
M1888 committed
22 23 24 25

        private Button btnSave;
        private Label lblInfo;

M1888's avatar
M1888 committed
26 27 28 29 30 31 32 33
        public Lottorivit()
        {
            InitializeComponent();
            NaytaKontrollit();
        }

        public void NaytaKontrollit()
        {
M1888's avatar
M1888 committed
34 35
            
            /*
M1888's avatar
M1888 committed
36 37 38 39 40
            StackPanel rivit = new StackPanel();
            for (int i = 0; i < Properties.Settings.Default.Vakiorivit; i++)
            {
                StackPanel rivi = new StackPanel();
                rivi.Orientation = Orientation.Horizontal;
M1888's avatar
M1888 committed
41 42 43 44 45 46 47
                rivi.Name = $"spRivi{i}";
                Grid.SetRow(rivi, i);

                Label l = new Label();
                l.Content = $"Rivi {i}: ";
                rivi.Children.Add(l);

M1888's avatar
M1888 committed
48 49 50 51 52
                for (int j = 0; j < 7; j++)
                {
                    TextBox tb = new TextBox();
                    tb.Style = Resources["Lottonumero"] as Style;
                    tb.TextChanged += txbChanged;
M1888's avatar
M1888 committed
53
                    Grid.SetColumn(tb, j);
M1888's avatar
M1888 committed
54 55 56 57 58
                    rivi.Children.Add(tb);
                }
                rivit.Children.Add(rivi);
            }
            grdRivit.Children.Add(rivit);
M1888's avatar
M1888 committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
            
            StackPanel spAlarivi = new StackPanel();
            Grid.SetRow(spAlarivi, Properties.Settings.Default.Vakiorivit);

            btnSave = new Button();
            btnSave.Content = "Tallenna";
            btnSave.Click += btnSave_Click;
            spAlarivi.Children.Add(btnSave);

            lblInfo = new Label();
            lblInfo.Style = Resources["Isompi"] as Style;
            spAlarivi.Children.Add(lblInfo);

            grdRivit.Children.Add(spAlarivi);*/
        }

        public void btnSave_Click(object sender, RoutedEventArgs e)
        {

M1888's avatar
M1888 committed
78 79 80 81 82
        }

        public void txbChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = sender as TextBox;
M1888's avatar
M1888 committed
83
            if (tb != null)
M1888's avatar
M1888 committed
84
            {
M1888's avatar
M1888 committed
85 86
                bool ok = true;
                if (int.TryParse(tb.Text, out int result))
M1888's avatar
M1888 committed
87
                {
M1888's avatar
M1888 committed
88
                    if (result < 1)
M1888's avatar
M1888 committed
89
                    {
M1888's avatar
M1888 committed
90
                        ok = false;
M1888's avatar
M1888 committed
91 92 93
                    }
                    else if (result > 40)
                    {
M1888's avatar
M1888 committed
94
                        ok = false;
M1888's avatar
M1888 committed
95 96 97 98
                    }
                }
                else
                {
M1888's avatar
M1888 committed
99 100 101 102 103 104 105 106 107 108 109
                    ok = false;
                }
                if (ok)
                {
                    lblInfo.Content = "";
                    btnSave.IsEnabled = true;
                }
                else
                {
                    lblInfo.Content = "Syötä vain numeroita 1-40";
                    btnSave.IsEnabled = false;
M1888's avatar
M1888 committed
110 111 112 113 114
                }
            }
        }
    }
}