コード例 #1
0
        private void Delete_btn_Click(object sender, RoutedEventArgs e)
        {
            MotoGPTeam modified = (MotoGPTeam)Teams_dgw.SelectedItem;

            //if nothing selected, do not respond
            if (modified == null)
            {
                return;
            }

            Delete delete = new Delete();

            delete.ShowDialog();

            //Clicked OK
            if (delete.DialogResult.HasValue && delete.DialogResult.Value)
            {
                //Upserting value
                using (MotoGPContext db = new MotoGPContext())
                {
                    db.Teams.Remove(db.Teams.Find(modified.Name));
                    db.SaveChanges();
                    teams = db.Teams.ToList();
                    Teams_dgw.ItemsSource = teams;
                }
            }
        }
コード例 #2
0
        private void Modify_btn_Click(object sender, RoutedEventArgs e)
        {
            MotoGPTeam modified = (MotoGPTeam)Teams_dgw.SelectedItem;

            //if nothing selected, do not respond
            if (modified == null)
            {
                return;
            }

            AddOrModify addOrModify = new AddOrModify(modified, true);

            addOrModify.ShowDialog();

            //Clicked OK (validated)
            if (addOrModify.DialogResult.HasValue && addOrModify.DialogResult.Value)
            {
                //Upserting value
                using (MotoGPContext db = new MotoGPContext())
                {
                    db.Teams.AddOrUpdate(modified);
                    db.SaveChanges();
                    teams = db.Teams.ToList();
                    Teams_dgw.ItemsSource = teams;
                }
            }
        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();

            //LINQ-able
            using (MotoGPContext db = new MotoGPContext())
            {
                teams = db.Teams.ToList();
            }


            Teams_dgw.ItemsSource = teams; //Changes dynamically with the list
        }
コード例 #4
0
        private void Add_btn_Click(object sender, RoutedEventArgs e)
        {
            MotoGPTeam modified = new MotoGPTeam();

            AddOrModify addOrModify = new AddOrModify(modified, false);

            addOrModify.ShowDialog();

            //Clicked OK (validated)
            if (addOrModify.DialogResult.HasValue && addOrModify.DialogResult.Value)
            {
                //Upserting value
                using (MotoGPContext db = new MotoGPContext())
                {
                    db.Teams.AddOrUpdate(modified);
                    db.SaveChanges();
                    teams = db.Teams.ToList();
                    Teams_dgw.ItemsSource = teams;
                }
            }
        }
コード例 #5
0
        private void OK_btn_Click(object sender, RoutedEventArgs e)
        {
            //Validate everything
            bool isEverythingOK = true;

            Name_err_tb.Text        = "";
            Established_err_tb.Text = "";
            Trophies_err_tb.Text    = "";

            if (Name_tb.Text == null || Name_tb.Text == "")
            {
                isEverythingOK   = false;
                Name_err_tb.Text = "Field must not be empty";
            }
            else if (Name_tb.Text != null && Name_tb.Text.Length > 80)
            {
                isEverythingOK   = false;
                Name_err_tb.Text = "Maximum length is 80 character";
            }
            else
            {
                using (MotoGPContext db = new MotoGPContext())
                {
                    MotoGPTeam team = db.Teams.Find(Name_tb.Text);
                    if (team != null && adding)
                    {
                        isEverythingOK   = false;
                        Name_err_tb.Text = "Name already exists";
                    }
                }
            }

            if (Established_tb.Text != null && Established_tb.Text != "")
            {
                int value = -1;
                if (!int.TryParse(Established_tb.Text, out value))
                {
                    isEverythingOK          = false;
                    Established_err_tb.Text = "Field must contain an integer";
                }
                else if (value < 1)
                {
                    isEverythingOK          = false;
                    Established_err_tb.Text = "Field must contain a positive number";
                }
                else if (value > DateTime.Now.Year)
                {
                    isEverythingOK          = false;
                    Established_err_tb.Text = "Field must not contain a year from future";
                }
            }
            else
            {
                isEverythingOK          = false;
                Established_err_tb.Text = "Field must not be empty";
            }

            if (Trophies_tb.Text != null && Trophies_tb.Text != "")
            {
                int value = -1;
                if (!int.TryParse(Trophies_tb.Text, out value))
                {
                    isEverythingOK       = false;
                    Trophies_err_tb.Text = "Field must contain an integer";
                }
                else if (value < 0)
                {
                    isEverythingOK       = false;
                    Trophies_err_tb.Text = "Field must contain a non negative number";
                }
            }
            else
            {
                isEverythingOK       = false;
                Trophies_err_tb.Text = "Field must not be empty";
            }


            if (isEverythingOK)
            {
                modified.Name        = Name_tb.Text;
                modified.Established = int.Parse(Established_tb.Text);
                modified.Trophies    = int.Parse(Trophies_tb.Text);
                modified.Registered  = Registered_cb.IsChecked == true;
                DialogResult         = true;
                Close();
            }
        }