예제 #1
0
        public WindowStatistics(PreciseShooting competition)
        {
            InitializeComponent();
            this.competition             = competition;
            dataGridIndivi.ItemsSource   = competition.Shooters;
            dataGridShooters.ItemsSource = competition.Shooters;

            CollectionView viewDG = (CollectionView)CollectionViewSource.GetDefaultView(dataGridShooters.ItemsSource);

            viewDG.GroupDescriptions.Add(new PropertyGroupDescription("Team"));

            PIndividual();
            PTeam();
            SetLabels();
        }
예제 #2
0
        // IMPLEMENTACIJA LOADANJA IZ DB
        public void LoadFromDB()
        {
            PreciseShooting competition = new PreciseShooting(long.Parse(labelId.Content.ToString()), labelTitle.Content.ToString(), labelRange.Content.ToString(), DateTime.Parse(labelDate.Content.ToString()), int.Parse(labelType.Content.ToString()), int.Parse(labelShots.Content.ToString()), int.Parse(labelRounds.Content.ToString()));
            Shooter         cshooter;

            if (competition == null)
            {
                return;
            }

            try
            {
                using (SQLiteConnection conn = dBManager.GetConnection())
                {
                    SQLiteCommand command = conn.CreateCommand();
                    command.CommandText = dBManager.sqlLibrary["selectForStatistics"];
                    command.Parameters.Add(new SQLiteParameter("cid", competition.Id));
                    conn.Open();


                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            cshooter = new Shooter(long.Parse(reader["id"].ToString()), reader["name"].ToString(), reader["surname"].ToString(), reader["cname"].ToString(), reader["team"].ToString());

                            List <int?> nullhits = new List <int?>();

                            nullhits.Add(reader.GetInt32(6));
                            nullhits.Add(reader.GetInt32(7));
                            nullhits.Add(reader.GetInt32(8));
                            nullhits.Add(reader.GetInt32(9));
                            nullhits.Add(reader.GetInt32(10));
                            nullhits.Add(reader.GetInt32(11));
                            nullhits.Add(reader.GetInt32(12));
                            nullhits.Add(reader.GetInt32(13));
                            nullhits.Add(reader.GetInt32(14));
                            nullhits.Add(reader.GetInt32(15));
                            nullhits.Add(reader.GetInt32(16));
                            nullhits.Add(reader.GetInt32(17));

                            List <int> hits = new List <int>();
                            // Fill non null
                            foreach (int?hit in nullhits)
                            {
                                if (hit != null)
                                {
                                    hits.Add((int)hit);
                                }
                                else
                                {
                                    break;
                                }
                            }

                            // If shoots length discreptency break
                            if (hits.Count != 13 - competition.TarType)
                            {
                                MessageBox.Show("Data corupted!", "Error!");
                                return;
                            }
                            cshooter.ScoresPRound.Add(hits);

                            //Fill remaining hits with lists filled with zero
                            for (int i = 1; i < competition.Round; i++)
                            {
                                cshooter.ScoresPRound.Add(new List <int>(new int[13 - competition.TarType]));
                            }
                            // Add Constructed shooter
                            competition.Shooters.Add(cshooter);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Exception");
            }
            competition.EndCompetition();
            WindowStatistics statWin = new WindowStatistics(competition);

            statWin.Show();
        }