예제 #1
0
        /// <summary>
        /// Fill textboxes and Comboboxes for new snapshot entry
        /// </summary>
        /// <param name="fmAddPlayer">The form containing the fields</param>
        /// <param name="SelectedPlayer">The selected player</param>
        public static void PreFillForSnapshot(AddPlayer fmAddPlayer, Player SelectedPlayer)
        {
            List <Control> Controls = new List <Control>();

            tbsCommonCollection.GetTextBoxByName("tbFirst_Name").Text = SelectedPlayer.firstName;
            tbsCommonCollection.GetTextBoxByName("tbLast_Name").Text  = SelectedPlayer.lastName;
            Controls.Add(tbsCommonCollection.GetTextBoxByName("tbFirst_Name"));
            Controls.Add(tbsCommonCollection.GetTextBoxByName("tbLast_Name"));
            string[] bdate = SelectedPlayer.birthDateSplit();
            string   day   = bdate[0];

            if (day.StartsWith("0"))
            {
                day = day.Replace("0", "");
            }
            cbsCollection.GetComboBoxByName("cbBdDay").Text = day;
            Controls.Add(cbsCollection.GetComboBoxByName("cbBdDay"));
            try
            {
                cbsCollection.GetComboBoxByName("cbBdMonth").Text = CultureInfo.InvariantCulture.DateTimeFormat.GetMonthName(int.Parse(bdate[1]));
                Controls.Add(cbsCollection.GetComboBoxByName("cbBdMonth"));
            }
            catch (Exception ex)
            {
                utils.ShowError("Could not parse a valid date from " + SelectedPlayer.fullName + ": " + SelectedPlayer.birthDate);
                utils.Log("Birthdate parse error when creating form for a snapshot. " + Environment.NewLine + ex.ToString());
            }
            cbsCollection.GetComboBoxByName("cbBdYear").Text = bdate[2];
            Controls.Add(cbsCollection.GetComboBoxByName("cbBdYear"));
            ToggleControls(Controls, false);
        }
예제 #2
0
        // Add player event
        private void bt_AddPlayer_Click(object sender, RoutedEventArgs e)
        {
            Window typeSelect = new PlayerSelectWindow();

            typeSelect.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Window addPlayer;

            int[] dateIndex = null;
            if (cbDay.SelectedIndex > -1 && cbMonth.SelectedIndex > -1 && cbYear.SelectedIndex > -1)
            {
                dateIndex = new int[] { cbDay.SelectedIndex, cbMonth.SelectedIndex, cbYear.SelectedIndex };
            }
            if ((bool)typeSelect.ShowDialog())
            {
                addPlayer = new AddPlayer(PlayerType.player, ingameDate: dateIndex);
            }
            else
            {
                addPlayer = new AddPlayer(PlayerType.goalie, ingameDate: dateIndex);
            }
            if ((bool)(addPlayer.ShowDialog()))
            {
                GenerateTreeList(null, true);
                ChartAllTotalAttributes();
            }
        }
예제 #3
0
        // Add snapshot event
        private void bt_AddSnapshot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if ((tvMain.SelectedItem as TreeViewItem).Tag.GetType() != typeof(Player))
                {
                    return;
                }
            }
            catch (Exception)
            {
                return;
            }
            int[] dateIndex = null;
            if (cbDay.SelectedIndex > -1 && cbMonth.SelectedIndex > -1 && cbYear.SelectedIndex > -1)
            {
                dateIndex = new int[] { cbDay.SelectedIndex, cbMonth.SelectedIndex, cbYear.SelectedIndex };
            }
            Player p = null;

            try
            {
                p = ((tvMain.SelectedItem as TreeViewItem).Tag as Player);
            }
            catch (Exception)
            {
                return;
            }
            Window addPlayer = new AddPlayer(p.playerType, true, p, dateIndex);

            if ((bool)(addPlayer.ShowDialog()))
            {
                GenerateTreeList(null, true);
                ChartAllTotalAttributes();
            }
        }
예제 #4
0
        // Save button method (add player or snapshot)
        private static void Bt_Click(object sender, RoutedEventArgs e, PlayerType pt, bool isSnapshot, Player SelectedPlayer, AddPlayer fm)
        {
            try
            {
                if (!DataCheck())
                {
                    return;
                }
                Player p = null;
                if (isSnapshot)
                {
                    if (SelectedPlayer != null)
                    {
                        p = new Player(SelectedPlayer.playerID, SelectedPlayer.firstName, SelectedPlayer.lastName, SelectedPlayer.playerType, SelectedPlayer.birthDate);
                    }
                    else
                    {
                        throw new ArgumentNullException("A player object was expected but received NULL.");
                    }
                }
                else
                {
                    string bDate = Player.ComboToDateStr(new string[] {
                        cbsCollection.GetComboBoxByName("cbBdDay").Text,
                        cbsCollection.GetComboBoxByName("cbBdMonth").Text,
                        cbsCollection.GetComboBoxByName("cbBdYear").Text
                    });

                    p = new Player(dbHelper.GetNewPlayerId(), tbsCommonCollection.GetTextBoxByName("tbFirst_Name").Text,
                                   tbsCommonCollection.GetTextBoxByName("tbLast_Name").Text,
                                   pt,
                                   bDate);
                }

                Snapshot s = new Snapshot(p.playerType);
                foreach (TextBox t in tbsAttrCollection)
                {
                    s.attributes[t.Name.Substring(2, t.Name.Length - 2)] = t.Text;
                }

                s.attributes["Ingame_Date"] = Player.ComboToDateStr(new string[] {
                    cbsCollection.GetComboBoxByName("cbDay").Text,
                    cbsCollection.GetComboBoxByName("cbMonth").Text,
                    cbsCollection.GetComboBoxByName("cbYear").Text
                });
                p.Snapshots.Add(s);
                dbHelper.PlayerAdd(p);
                fm.DialogResult = true;
                fm.Close();
            }
            catch (Exception ex)
            {
                utils.ShowError("Error saving: " + ex.Message);
                utils.Log("Error saving: " + ex.ToString());
            }
        }
예제 #5
0
        /// <summary>
        /// Generates labels and text box for attributes based on the player's type
        /// </summary>
        /// <param name="fmAddPlayer">The form containing the labels</param>
        /// <param name="playerType">Player Type</param>
        /// <param name="isSnapshot">is this a snapshot?</param>
        /// <param name="SelectedPlayer">The selected player (in case of a snapshot)</param>
        /// <param name="dateIndex">The ingame date pushed into an array</param>
        private static void GenerateLabels(AddPlayer fmAddPlayer, PlayerType playerType, bool isSnapshot = false, Player SelectedPlayer = null, int[] dateIndex = null)
        {
            // Clear collections.
            tbsAttrCollection.Clear();
            tbsCommonCollection.Clear();
            cbsCollection.Clear();

            string[] attributes;

            // Check player type and load attributes.
            switch (playerType)
            {
            case (PlayerType.player):
                attributes = dbHelper.playerAttributes;
                break;

            case (PlayerType.goalie):
                attributes = dbHelper.goalieAttributes;
                break;

            default:
                throw new ArgumentException("Player type not recognized");
            }

            // Create common attributes controls
            foreach (string attr in dbHelper.commonAttributes)
            {
                fmAddPlayer.spName.Children.Add(CreateCommonAttributeDockPanel(attr));
            }


            // Add Checkbox
            CheckBox cbUseLast = new CheckBox();

            //cbUseLast.Margin = new Thickness(0, 5, 0, 0);
            cbUseLast.Content = "Pre-fill using last snapshot";
            cbUseLast.Click  += (sender, args) => LoadSnapshot(SelectedPlayer, cbUseLast);
            fmAddPlayer.spName.Children.Add(cbUseLast);

            // Add the in-game date field/combos
            fmAddPlayer.spName.Children.Add(AddIngameDateField(dateIndex));



            // If snapshot, fill the needed info and lock controls
            if (isSnapshot)
            {
                PreFillForSnapshot(fmAddPlayer, SelectedPlayer);
            }

            // Add labels and textbox for every attributes
            for (int i = 0; i < attributes.Count(); i++)
            {
                int indexTechnical = 0;
                if (playerType == PlayerType.player)
                {
                    indexTechnical = 12;
                }
                if (playerType == PlayerType.goalie)
                {
                    indexTechnical = 9;
                }

                DockPanel dp = CreateAttributeDockPanel(attributes[i]);
                if (i == 0 || i < indexTechnical)
                {
                    Grid.SetColumn(dp, 0);
                    Grid.SetRow(dp, i);
                }
                else if (i == indexTechnical || i < indexTechnical + 9)
                {
                    Grid.SetColumn(dp, 1);
                    Grid.SetRow(dp, i - indexTechnical);
                }
                else if (i >= indexTechnical + 9)
                {
                    Grid.SetColumn(dp, 2);
                    Grid.SetRow(dp, i - indexTechnical - 9);
                }
                fmAddPlayer.gridAttributes.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                fmAddPlayer.gridAttributes.Children.Add(dp);
            }

            // Finally add a save button
            Button bt = new Button();

            bt.Content             = "Save";
            bt.Click              += (sender, EventArgs) => { Bt_Click(sender, EventArgs, playerType, isSnapshot, SelectedPlayer, fmAddPlayer); };
            bt.Width               = 200;
            bt.Margin              = new Thickness(0, 20, 0, 0);
            bt.VerticalAlignment   = VerticalAlignment.Center;
            bt.HorizontalAlignment = HorizontalAlignment.Center;
            Grid.SetRow(bt, fmAddPlayer.gridAttributes.RowDefinitions.Count - 1);
            Grid.SetColumn(bt, 1);
            fmAddPlayer.gridAttributes.Children.Add(bt);
        }