Esempio n. 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WPFContext context = new WPFContext();

            if (txtname.Text.Length <= 6 || txtpass.Text.Length <= 6)
            {
                MessageBox.Show("Username and password must contain more than 6 characters");
            }
            else
            if (context.Users.All(o => o.Username != txtname.Text))
            {
                user newUs = new user();
                newUs.Username = txtname.Text;
                newUs.Password = txtpass.Text;
                newUs.IsAdmin  = false;

                context.Users.Add(newUs);
                context.SaveChanges();
                MessageBox.Show("Account created successfully");
                flag = 1;
                LoginPage lg = new LoginPage();
                this.NavigationService.Navigate(lg);
            }
            else
            {
                MessageBox.Show("This username already exists");
            }
        }
Esempio n. 2
0
        private void PreviewKeyDownHandler(object sender, KeyEventArgs e, bool isadm, string username)
        {
            WPFContext context = new WPFContext();

            if (Key.Delete == e.Key)
            {
                if (datagr.SelectedIndex != -1)
                {
                    try
                    {
                        if (MessageBox.Show("Are you sure you want to delete this fixture?", "Are you sure?",
                                            MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            flag = 1;
                            datagr.UnselectAll();
                            Fixtures pg = new Fixtures(isadm, username);
                            this.NavigationService.Navigate(pg);
                        }
                        else
                        {
                            var res = context.Results.FirstOrDefault(a => a.ID == datagr.SelectedIndex + 1);
                            context.Results.Remove(res);
                            context.SaveChanges();
                            Fixtures pg = new Fixtures(isadm, username);
                            flag = 1;
                            datagr.UnselectAll();
                            this.NavigationService.Navigate(pg);
                        }
                    }
                    catch { }
                }
            }
        }
Esempio n. 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            WPFContext context  = new WPFContext();
            WPFContext context1 = new WPFContext();


            foreach (user u in context.Users)
            {
                if (txtname.Text == u.Username && txtpass.Text == u.Password)
                {
                    lblerr.Content = "";
                    ActiveUser act = new ActiveUser();

                    act.ActUsername = u.Username;
                    act.ActPassword = u.Password;
                    act.LoggedIn    = DateTime.Now;
                    act.ActIsAdmin  = u.IsAdmin;
                    context1.ActUser.Add(act);
                    context1.SaveChanges();


                    MessageBox.Show("Logged In");
                    logger.Log(act);
                    StartPage startp = new StartPage(act.ActIsAdmin, u.Username);
                    flag = 1;
                    this.NavigationService.Navigate(startp);
                }

                else
                {
                    lblerr.Content = "Wrong username or password";
                }
            }
        }
Esempio n. 4
0
 void btnRemove_Click(object sender, RoutedEventArgs e, bool isadm, string username)
 {
     try
     {
         WPFContext context = new WPFContext();
         if (MessageBox.Show("Are you sure you want to remove this user?", "Are you sure?",
                             MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
         {
             datagr.UnselectAll();
         }
         else
         {
             var res = context.Users.FirstOrDefault(a => a.UserID == datagr.SelectedIndex + 1);
             if (res.IsAdmin == true)
             {
                 MessageBox.Show("This user is admin and cannot be deleted");
             }
             else
             {
                 context.Users.Remove(res);
                 context.SaveChanges();
                 datagr.ItemsSource = null;
                 flag1 = 1;
                 OrderFix();
                 FillPage(isadm, username);
             }
         }
     }
     catch { }
 }
Esempio n. 5
0
        private void Btnadd_Click(object sender, RoutedEventArgs e)
        {
            WPFContext context = new WPFContext();

            //player newP = new player();

            try
            {
                foreach (TextBox t in this.gri2.Children.OfType <TextBox>())
                {
                    if (t.Text == string.Empty)
                    {
                        t.Text = "Empty";
                    }
                }
                foreach (ComboBox cb in this.gri2.Children.OfType <ComboBox>())
                {
                    if (cb.Text == string.Empty)
                    {
                        cb.Text = "Empty";
                    }
                }
                foreach (TextBox t in this.gri.Children.OfType <TextBox>())
                {
                    if (t.Text == string.Empty)
                    {
                        t.Text = "Empty";
                    }
                }
                DateTime dt = new DateTime(Convert.ToInt32(txtyear.Text),
                                           Convert.ToInt32(txtmonth.Text), Convert.ToInt32(txtday.Text));
                player newP = new player();
                newP.name        = txtName.Text.ToString();
                newP.surename    = txtSure.Text.ToString();
                newP.dateOfBirth = dt;
                newP.Nationality = cmbnat.SelectedItem.ToString();
                newP.position    = cmbpos.SelectedItem.ToString();
                newP.teamNumber  = Convert.ToInt32(txtnumb.Text);
                newP.careergoals = Convert.ToInt32(txtgoal.Text);
                newP.img         = txtimg.Text.ToString();
                if (!context.Players.All(o => o.teamNumber != newP.teamNumber))
                {
                    MessageBox.Show("Player with this team number already exists");
                }
                else if (!File.Exists(txtimg.Text.ToString()))
                {
                    MessageBox.Show("Invalid image source");
                }
                else
                {
                    MessageBox.Show("Player created");
                    context.Players.Add(newP);
                    context.SaveChanges();
                }
            }
            catch
            {
                MessageBox.Show("Incorrect input");
            }
        }
Esempio n. 6
0
        public void AddFix(List <fixtures> orderFix)
        {
            WPFContext context = new WPFContext();

            foreach (fixtures m in orderFix)
            {
                context.Results.Add(m);
            }
            context.SaveChanges();
        }
Esempio n. 7
0
 public static void Actuserdel(string usern)
 {
     try
     {
         WPFContext context = new WPFContext();
         var        act     = context.ActUser.Where(x => x.ActUsername == usern).FirstOrDefault();
         context.ActUser.Remove(act);
         context.SaveChanges();
     }
     catch { }
 }
Esempio n. 8
0
        public void AddTeams(List <team> orderTeams)
        {
            WPFContext context = new WPFContext();



            foreach (team t in orderTeams)
            {
                context.Teams.Add(t);
            }
            context.SaveChanges();
        }
Esempio n. 9
0
        public void AddUsers(List <user> orderFix)
        {
            WPFContext context = new WPFContext();



            foreach (user m in orderFix)
            {
                context.Users.Add(m);
            }
            context.SaveChanges();
        }
Esempio n. 10
0
        void Checked(object sender, RoutedEventArgs e)
        {
            WPFContext context = new WPFContext();

            try
            {
                var player = context.Users.First(a => a.UserID == datagr.SelectedIndex + 1);

                player.IsAdmin = true;
                MessageBox.Show("User is now admin");
                context.SaveChanges();
            }
            catch { }
        }
Esempio n. 11
0
        void Unchecked(object sender, RoutedEventArgs e)
        {
            WPFContext context = new WPFContext();

            try
            {
                var player = context.Users.First(a => a.UserID == datagr.SelectedIndex + 1);
                if (player.Username == "admin")
                {
                    MessageBox.Show("Administrator righs for this user cannot be removed");
                    player.IsAdmin = true;
                }
                else
                {
                    player.IsAdmin = false;
                    MessageBox.Show("User is no more admin");
                    context.SaveChanges();
                }
            }
            catch { }
        }
Esempio n. 12
0
        void SetAge()
        {
            WPFContext context1 = new WPFContext();

            foreach (player p in context1.Players)
            {
                p.age = DateTime.Now.Year - p.dateOfBirth.Year;
                if (p.dateOfBirth.Month > DateTime.Now.Month)
                {
                    p.age--;
                }
                else if (p.dateOfBirth.Month == DateTime.Now.Month)
                {
                    if (p.dateOfBirth.Day > DateTime.Now.Day)
                    {
                        p.age--;
                    }
                }
            }
            context1.SaveChanges();
        }
Esempio n. 13
0
        public void OrderTeams()
        {
            WPFContext context = new WPFContext();

            foreach (team tm in context.Teams)
            {
                tm.Points = (tm.Won * 3 + tm.Drawn);
                tm.GD     = tm.GF - tm.GA;
                tm.Played = tm.Won + tm.Lost + tm.Drawn;
            }
            context.SaveChanges();
            int         max        = context.Teams.Max(a => a.Points);
            List <team> orderTeams = (from p in context.Teams select p)
                                     .OrderByDescending(a => a.Points).ThenByDescending(a => a.GD).ToList();

            for (int i = 0; i < orderTeams.Count; i++)
            {
                orderTeams[i].Position = i + 1;
            }
            delete();
            create();
            AddTeams(orderTeams);
        }
Esempio n. 14
0
        public PlayerInfo2(player data, bool isadm, string username) : this()
        {
            WPFContext context = new WPFContext();

            lblName.Content = data.name.ToString();
            lblSure.Content = data.surename.ToString();
            Image imag = new Image();

            imag.Source = new BitmapImage(new Uri(data.img.ToString()));
            gri.Children.Add(imag);
            imag.SetValue(Grid.ColumnProperty, 0);
            imag.Height = 200;
            imag.Width  = 200;
            //  < Image Grid.Column = "0" Height = "200" Width = "200" Margin = "100,60,100,190" />
            imag.Margin = new Thickness(40, 50, 40, 100);
            imag.HorizontalAlignment = HorizontalAlignment.Left;
            imag.VerticalAlignment   = VerticalAlignment.Top;
            foreach (Control c in this.gri2.Children.OfType <Control>())
            {
                c.FontWeight = FontWeights.Bold;
            }
            txtapp.Text  = data.appearances.ToString();
            txtass.Text  = data.assists.ToString();
            txtyc.Text   = data.YC.ToString();
            txtrc.Text   = data.Rc.ToString();
            txtcarg.Text = data.careergoals.ToString();
            txtval.Text  = "€" + data.value.ToString() + " million";

            var player = context.Players.First(a => a.teamNumber == data.teamNumber);

            txtcarg.Text = (player.careergoals + player.goalsScored).ToString();

            txtapp.TextChanged += new TextChangedEventHandler(txtappchanged);
            txtass.TextChanged += new TextChangedEventHandler(txtasschanged);
            txtyc.TextChanged  += new TextChangedEventHandler(txtycchanged);
            txtrc.TextChanged  += new TextChangedEventHandler(txtrchanged);
            backhl.Click       += new RoutedEventHandler((sender, e) => backHL_Click(sender, e, data, isadm, username));
            pgPlInfo.Unloaded  += new RoutedEventHandler((sender, e) => Page_Unloaded(sender, e, username, flag));

            if (isadm == true)
            {
                foreach (TextBox t in this.gri2.Children.OfType <TextBox>())
                {
                    t.IsReadOnly = false;
                }
            }
            else
            {
                foreach (TextBox t in this.gri2.Children.OfType <TextBox>())
                {
                    t.IsReadOnly = true;
                }
            }
            void txtappchanged(object sender, RoutedEventArgs e)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtapp.Text, "[^0-9]"))
                {
                    MessageBox.Show("Please enter only numbers.");
                    txtapp.Text = txtapp.Text.Remove(txtapp.Text.Length - 1);
                }
                try
                {
                    int newst = Int32.Parse(txtapp.Text);
                    player.appearances = newst;
                    context.SaveChanges();
                }
                catch { }
            }

            void txtasschanged(object sender, RoutedEventArgs e)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtass.Text, "[^0-9]"))
                {
                    MessageBox.Show("Please enter only numbers.");
                    txtass.Text = txtass.Text.Remove(txtass.Text.Length - 1);
                }
                try
                {
                    int newst = Int32.Parse(txtass.Text);
                    player.assists = newst;
                    context.SaveChanges();
                }
                catch { }
            }

            void txtycchanged(object sender, RoutedEventArgs e)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtyc.Text, "[^0-9]"))
                {
                    MessageBox.Show("Please enter only numbers.");
                    txtyc.Text = txtyc.Text.Remove(txtapp.Text.Length - 1);
                }

                try
                {
                    int newst = Int32.Parse(txtyc.Text);
                    player.YC = newst;
                    context.SaveChanges();
                }
                catch { }
            }

            void txtrchanged(object sender, RoutedEventArgs e)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtrc.Text, "[^0-9]"))
                {
                    MessageBox.Show("Please enter only numbers.");
                    txtrc.Text = txtrc.Text.Remove(txtrc.Text.Length - 1);
                }

                try
                {
                    int newst = Int32.Parse(txtrc.Text);
                    player.Rc = newst;
                    context.SaveChanges();
                }
                catch { }
            }
        }
Esempio n. 15
0
        public PlayerInfo(player data, bool isadm, string username) : this()
        {
            WPFContext context = new WPFContext();

            lblName.Content = data.name.ToString();
            lblSure.Content = data.surename.ToString();
            txtdate.Text    = data.dateOfBirth.ToString("  dd MMMM yyyy");
            SetAge();
            txtage.Text   = data.age.ToString();
            txtnat.Text   = data.Nationality.ToString();
            txtpos.Text   = data.position.ToString();
            cmbday.Text   = data.dateOfBirth.Day.ToString();
            cmbmonth.Text = data.dateOfBirth.Month.ToString();
            cmbyear.Text  = data.dateOfBirth.Year.ToString();
            cmbnat.Text   = data.Nationality.ToString();
            cmbpos.Text   = data.position.ToString();
            txtnumb.Text  = data.teamNumber.ToString();
            txtgoal.Text  = data.goalsScored.ToString();


            Image imag = new Image();

            imag.Source = new BitmapImage(new Uri(data.img.ToString()));
            gri.Children.Add(imag);
            imag.SetValue(Grid.ColumnProperty, 0);
            imag.Height = 200;
            imag.Width  = 200;
            imag.Margin = new Thickness(40, 50, 40, 100);
            imag.HorizontalAlignment = HorizontalAlignment.Left;
            imag.VerticalAlignment   = VerticalAlignment.Top;
            foreach (Control c in this.gri2.Children.OfType <Control>())
            {
                c.FontWeight = FontWeights.Bold;
            }


            if (isadm == true)
            {
                foreach (TextBox t in this.gri2.Children.OfType <TextBox>())
                {
                    t.IsReadOnly       = false;
                    txtdate.Visibility = Visibility.Hidden;
                    txtnat.Visibility  = Visibility.Hidden;
                    txtpos.Visibility  = Visibility.Hidden;
                    btndel.Visibility  = Visibility.Visible;
                }
            }
            else
            {
                foreach (TextBox t in this.gri2.Children.OfType <TextBox>())
                {
                    t.IsReadOnly        = true;
                    cmbnat.IsEnabled    = false;
                    cmbpos.IsEnabled    = false;
                    cmbday.Visibility   = Visibility.Hidden;
                    cmbmonth.Visibility = Visibility.Hidden;
                    cmbyear.Visibility  = Visibility.Hidden;
                    aplch.Visibility    = Visibility.Hidden;
                    cmbnat.Visibility   = Visibility.Hidden;
                    cmbpos.Visibility   = Visibility.Hidden;
                }
            }

            void cmbnatchanged(object sender, RoutedEventArgs e)
            {
                var player = context.Players.First(a => a.teamNumber == data.teamNumber);



                try
                {
                    string nat = cmbnat.SelectedItem.ToString();
                    player.Nationality = nat;
                    context.SaveChanges();
                    SetAge();
                }
                catch { }
                SetAge();
            }

            void cmbposchanged(object sender, RoutedEventArgs e)
            {
                var player = context.Players.First(a => a.teamNumber == data.teamNumber);

                try
                {
                    string pos = cmbpos.SelectedItem.ToString();
                    player.position = pos;
                    context.SaveChanges();
                }
                catch { }
            }

            void cmbdatechanged(object sender, RoutedEventArgs e)
            {
                var player = context.Players.First(a => a.teamNumber == data.teamNumber);

                try
                {
                    int      year  = Int32.Parse(cmbyear.SelectedItem.ToString());
                    int      month = Int32.Parse(cmbmonth.SelectedItem.ToString());
                    int      day   = Int32.Parse(cmbday.SelectedItem.ToString());
                    DateTime dt    = new DateTime(year, month, day);
                    DateTime now   = DateTime.Now;
                    if (DateTime.Compare(dt, now) > 0)
                    {
                        MessageBox.Show("Incorrect input");
                    }
                    player.dateOfBirth = dt;
                    context.SaveChanges();
                }
                catch { }
            }

            void txtgoalchanged(object sender, RoutedEventArgs e)
            {
                var player = context.Players.First(a => a.teamNumber == data.teamNumber);

                if (System.Text.RegularExpressions.Regex.IsMatch(txtgoal.Text, "[^0-9]"))
                {
                    MessageBox.Show("Please enter only numbers.");
                    txtgoal.Text = txtgoal.Text.Remove(txtgoal.Text.Length - 1);
                }

                try
                {
                    int newg = Int32.Parse(txtgoal.Text);
                    player.goalsScored = newg;
                    context.SaveChanges();
                }
                catch { }
            }

            void myButton_Click(object sender, RoutedEventArgs e)
            {
                try
                {
                    var player = context.Players.First(a => a.teamNumber == data.teamNumber);
                    if (txtnumb.Text == string.Empty)
                    {
                        MessageBox.Show("Feild Empty");
                    }
                    if (System.Text.RegularExpressions.Regex.IsMatch(txtnumb.Text, "[^0-9]"))
                    {
                        MessageBox.Show("Please enter only numbers.");
                        txtnumb.Text = txtnumb.Text.Remove(txtnumb.Text.Length - 1);
                    }
                    else
                    {
                        int newg = Int32.Parse(txtnumb.Text);
                        if (context.Players.All(o => o.teamNumber != newg))
                        {
                            player.teamNumber = newg;
                            context.SaveChanges();
                            MessageBox.Show("Player number changed");
                        }
                        else
                        {
                            MessageBox.Show("Player with this team number already exists");
                            txtnumb.Text = string.Empty;
                        }
                    }
                }



                catch { }
            }

            void btndel_Click(object sender, RoutedEventArgs e)
            {
                var player = context.Players.First(a => a.teamNumber == data.teamNumber);

                if (MessageBox.Show("Are you sure you want to delete this player?", "Are you sure?",
                                    MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                {
                }
                else
                {
                    context.Players.Remove(player);
                    context.SaveChanges();
                    flag = 1;
                    Players pl = new Players(isadm, username);
                    this.NavigationService.Navigate(pl);
                }
            }

            cmbday.SelectionChanged   += new SelectionChangedEventHandler(cmbdatechanged);
            cmbmonth.SelectionChanged += new SelectionChangedEventHandler(cmbdatechanged);
            cmbyear.SelectionChanged  += new SelectionChangedEventHandler(cmbdatechanged);
            cmbnat.SelectionChanged   += new SelectionChangedEventHandler(cmbnatchanged);
            txtgoal.TextChanged       += new TextChangedEventHandler(txtgoalchanged);
            cmbpos.SelectionChanged   += new SelectionChangedEventHandler(cmbposchanged);
            MoreInfoHL.Click          += new RoutedEventHandler((sender, e) => MoreInfoHL_Click(sender, e, data, isadm, username));
            backhl.Click      += new RoutedEventHandler((sender, e) => backHL_Click(sender, e, isadm, username));
            aplch.Click       += myButton_Click;
            btndel.Click      += btndel_Click;
            pgPlInfo.Unloaded += new RoutedEventHandler((sender, e) => Page_Unloaded(sender, e, username, flag));
        }
Esempio n. 16
0
        public void fillpage(bool isadm, string username)
        {
            int        won = 0, lost = 0, drawn = 0;
            int        goalsf  = 0;
            int        goalsa  = 0;
            WPFContext context = new WPFContext();


            foreach (fixtures m in context.Results)
            {
                if (m.hometeam == "Chelsea")
                {
                    goalsf += Int32.Parse(m.result.Substring(0, 1));
                    goalsa += Int32.Parse(m.result.Substring(2, 1));
                    if (Int32.Parse(m.result.Substring(0, 1)) >
                        Int32.Parse(m.result.Substring(2, 1)))
                    {
                        won++;
                    }
                    else if (Int32.Parse(m.result.Substring(0, 1)) ==
                             Int32.Parse(m.result.Substring(2, 1)))
                    {
                        drawn++;
                    }
                    else
                    {
                        lost++;
                    }
                }
                if (m.awayteam == "Chelsea")
                {
                    goalsf += Int32.Parse(m.result.Substring(2, 1));
                    goalsa += Int32.Parse(m.result.Substring(0, 1));
                    if (Int32.Parse(m.result.Substring(0, 1)) >
                        Int32.Parse(m.result.Substring(2, 1)))
                    {
                        lost++;
                    }
                    else if (Int32.Parse(m.result.Substring(0, 1)) ==
                             Int32.Parse(m.result.Substring(2, 1)))
                    {
                        drawn++;
                    }
                    else
                    {
                        won++;
                    }
                }
            }
            foreach (team t in context.Teams)
            {
                if (t.Club == "Chelsea")
                {
                    t.GF    = goalsf;
                    t.GA    = goalsa;
                    t.Won   = won;
                    t.Lost  = lost;
                    t.Drawn = drawn;
                }
            }
            foreach (team tm in context.Teams)
            {
                tm.Points = (tm.Won * 3 + tm.Drawn);
                tm.GD     = tm.GF - tm.GA;
                tm.Played = tm.Won + tm.Lost + tm.Drawn;
            }
            context.SaveChanges();
            WPFContext context1 = new WPFContext();

            List <team> teamlist;

            teamlist = context.Teams.ToList();
            if (isadm == true)
            {
                var newList = teamlist.OrderBy(x => x.Position).ToList();
                datagr.ItemsSource        = newList;
                colPosition.IsReadOnly    = true;
                colPlayed.IsReadOnly      = true;
                colGD.IsReadOnly          = true;
                colPoints.IsReadOnly      = true;
                colID.Visibility          = Visibility.Hidden;
                datagr.CanUserSortColumns = false;
            }

            if (isadm == false)
            {
                var newList = teamlist.OrderBy(x => x.Position).ToList();
                teamlist.Sort((x, y) => string.Compare(x.Position.ToString(), y.Position.ToString()));
                datagr.ItemsSource = newList;
                datagr.IsReadOnly  = true;
                colID.Visibility   = Visibility.Hidden;
            }
            hplback.Click             += new RoutedEventHandler((sender, e) => hplback_Click_1(sender, e, isadm, username));
            pgRanking.Unloaded        += new RoutedEventHandler((sender, e) => Page_Unloaded(sender, e, username, flag));
            datagr.CurrentCellChanged += new EventHandler <EventArgs>((sender, e) =>
                                                                      Datagr_CurrentCellChanged(sender, e, isadm, username));
        }
Esempio n. 17
0
        private void Datagr_CurrentCellChanged(object sender, EventArgs e, bool isadm, string username)
        {
            WPFContext context = new WPFContext();

            try
            {
                var LastID = context.Teams.OrderByDescending(a => a.ID).FirstOrDefault().ID;
                if ((datagr.SelectedIndex + 1) > LastID)
                {
                    team t = new team();
                    t.ID = LastID + 1;
                    context.Teams.Add(t);
                }
                DataGridRow  r         = (DataGridRow)datagr.ItemContainerGenerator.ContainerFromIndex(datagr.SelectedIndex);
                DataGridCell RowColumn = datagr.Columns[datagr.CurrentColumn.DisplayIndex].GetCellContent(r).Parent as DataGridCell;
                string       CellValue = ((TextBlock)RowColumn.Content).Text;



                if ((datagr.SelectedIndex + 1) > LastID && (datagr.SelectedIndex + 1) < 20)
                {
                    team t = new team();
                    t.ID = LastID + 1;
                    context.Teams.Add(t);
                    context.SaveChanges();
                }
                var team = context.Teams.First(a => a.Position == datagr.SelectedIndex + 1);

                if (datagr.CurrentColumn.DisplayIndex == 2)

                {
                    team.Club = CellValue;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }

                if (datagr.CurrentColumn.DisplayIndex == 4)

                {
                    int newg = Convert.ToInt32(CellValue);
                    team.Won = newg;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 5)

                {
                    int newg = Convert.ToInt32(CellValue);
                    team.Drawn = newg;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 6)

                {
                    int newg = Convert.ToInt32(CellValue);
                    team.Lost = newg;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 7)

                {
                    int newg = Convert.ToInt32(CellValue);
                    team.GF = newg;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 8)

                {
                    int newg = Convert.ToInt32(CellValue);
                    team.GA = newg;
                    context.SaveChanges();
                    OrderTeams();
                    fillpage(isadm, username);
                }
            }
            catch  { }
        }
Esempio n. 18
0
        private void Datagr_CurrentCellChanged(object sender, EventArgs e, bool isadm, string username)
        {
            WPFContext context = new WPFContext();

            try
            {
                var LastID = context.Results.OrderByDescending(a => a.ID).FirstOrDefault().ID;
                if ((datagr.SelectedIndex + 1) > LastID)
                {
                    fixtures t = new fixtures();
                    t.ID = LastID + 1;
                    context.Results.Add(t);
                }
                DataGridRow  r         = (DataGridRow)datagr.ItemContainerGenerator.ContainerFromIndex(datagr.SelectedIndex);
                DataGridCell RowColumn = datagr.Columns[datagr.CurrentColumn.DisplayIndex].GetCellContent(r).Parent as DataGridCell;
                string       CellValue = ((TextBlock)RowColumn.Content).Text;



                if ((datagr.SelectedIndex + 1) > LastID)
                {
                    fixtures t = new fixtures();
                    t.ID = LastID + 1;
                    context.Results.Add(t);
                    context.SaveChanges();
                }
                var res = context.Results.First(a => a.ID == datagr.SelectedIndex + 1);

                if (datagr.CurrentColumn.DisplayIndex == 0)

                {
                    res.date = CellValue;
                    context.SaveChanges();
                    OrderFix();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 1)

                {
                    res.hometeam = CellValue;
                    context.SaveChanges();
                    OrderFix();
                    fillpage(isadm, username);
                }
                if (datagr.CurrentColumn.DisplayIndex == 2)

                {
                    try
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(CellValue.Substring(0, 1), "[^0-9]") ||
                            (CellValue.Substring(1, 1) != "-") ||
                            System.Text.RegularExpressions.Regex.IsMatch(CellValue.Substring(2, 1), "[^0-9]"))
                        {
                            MessageBox.Show("Incorrect input. Example input: '0-0'");
                            OrderFix();
                            fillpage(isadm, username);
                        }
                        else
                        {
                            res.result = CellValue;
                            context.SaveChanges();
                            OrderFix();
                            fillpage(isadm, username);
                        }
                    }
                    catch { }
                }
                if (datagr.CurrentColumn.DisplayIndex == 3)

                {
                    res.awayteam = CellValue;
                    context.SaveChanges();
                    OrderFix();
                    fillpage(isadm, username);
                }
            }
            catch { }
        }