示例#1
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));
        }
示例#2
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 { }
        }
示例#3
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  { }
        }
示例#4
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));
        }
示例#5
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 { }
            }
        }
示例#6
0
        private void ShowPlayers(bool isadm, string username)
        {
            WPFContext       context   = new WPFContext();
            List <Label>     lblNumber = new List <Label>(2);
            List <Hyperlink> hplPlayer = new List <Hyperlink>();
            List <TextBlock> txtPlayer = new List <TextBlock>();

            int h   = -350;
            int id  = 1;
            int col = 0;

            foreach (player p in context.Players)
            {
                lblNumber.Add(new Label());
                txtPlayer.Add(new TextBlock());
                hplPlayer.Add(new Hyperlink());
                lblNumber.Add(new Label());

                try
                {
                    var getrecord = context.Players.Where(a => a.teamNumber == p.teamNumber).SingleOrDefault();
                    Gr.Children.Add(txtPlayer[id - 1]);
                    Gr.Children.Add(lblNumber[id - 1]);

                    hplPlayer[id - 1].Inlines.Add(getrecord.name + " " + getrecord.surename);
                    hplPlayer[id - 1].Foreground      = Brushes.Black;
                    hplPlayer[id - 1].FontWeight      = FontWeights.Bold;
                    hplPlayer[id - 1].TextDecorations = null;

                    txtPlayer[id - 1].Inlines.Add(hplPlayer[id - 1]);
                    txtPlayer[id - 1].SetValue(Grid.RowProperty, 1);
                    txtPlayer[id - 1].SetValue(Grid.ColumnProperty, col + 1);
                    txtPlayer[id - 1].Height   = 40;
                    txtPlayer[id - 1].Margin   = new Thickness(0, h, 0, 0);
                    txtPlayer[id - 1].FontSize = 20;

                    lblNumber[id - 1].Content = getrecord.teamNumber.ToString();
                    lblNumber[id - 1].SetValue(Grid.RowProperty, 1);
                    lblNumber[id - 1].SetValue(Grid.ColumnProperty, col);
                    lblNumber[id - 1].Height              = 40;
                    lblNumber[id - 1].Margin              = new Thickness(0, h - 10, 0, 0);
                    lblNumber[id - 1].Foreground          = new SolidColorBrush(Colors.Transparent);
                    lblNumber[id - 1].FontSize            = 20;
                    lblNumber[id - 1].Foreground          = Brushes.Black;
                    lblNumber[id - 1].HorizontalAlignment = HorizontalAlignment.Center;

                    PlayerInfo playerInfo = new PlayerInfo(p, isadm, username);
                    hplPlayer[id - 1].Click += new RoutedEventHandler((sender, e) => hlclick(sender, e, playerInfo));

                    h += 60;
                    id++;
                    if (id == 14)
                    {
                        col += 2;
                        h    = -350;
                    }
                }
                catch (NullReferenceException e)
                {
                    continue;
                }
            }
        }