Ejemplo n.º 1
0
        private void ViewScore_Click(object sender, EventArgs e)
        {
            NotiLabel.Text     = "";
            EditButton.Enabled = true;
            Classes.Enabled    = true;
            Subjects.Enabled   = true;
            listViewInfo       = ListViewInfo.Scoreboard;

            _Id.Text     = "Student ID";
            _Id.Width    = 110;
            _Name.Text   = "Student name";
            _Name.Width  = 190;
            _Info1.Text  = "Class";
            _Info1.Width = 90;
            _Info2.Text  = "Subject ID";
            _Info2.Width = 110;
            _Info3.Text  = "Mid-term";
            _Info3.Width = 80;
            _Info4.Text  = "Final-term";
            _Info4.Width = 80;
            _Info5.Text  = "Other score";
            _Info5.Width = 80;
            _Info6.Text  = "Final score";
            _Info6.Width = 80;
            _Info7.Text  = "Pass";
            _Info7.Width = 60;

            listView.Items.Clear();
            listView.Columns.Clear();
            listView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[]
                                      { _No, _Id, _Name, _Info1, _Info2, _Info3, _Info4, _Info5, _Info6, _Info7 });

            try
            {
                StudentServices service = new StudentServices();
                var             Data    = service.GetScoreboardFromDB(Classes.SelectedItem.ToString(), Subjects.SelectedItem.ToString());
                int             pass    = 0;
                foreach (var data in Data)
                {
                    if (data.Info[6] == "Yes")
                    {
                        pass++;
                    }
                }
                BindDataToListView(Data);
                if (Classes.SelectedItem.ToString() != "All" && Subjects.SelectedItem.ToString() != "All")
                {
                    NotiLabel.Text = $"There are {pass} student(s) ({((float) pass / (float) Data.Count).ToString("p")}) " +
                                     $"of class {Classes.SelectedItem.ToString()} passed this subject.";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (listView.Items.Count == 0)
            {
                NotiLabel.Text = "Nothing is found...";
            }
            listView.View = View.Details;
        }