private void SaveButton_Click(object sender, EventArgs e)
        {
            float mid = -1, final = -1, other = -1, score = -1;

            float.TryParse(Mid.Text, out mid);
            if (mid < 0 || mid > 10)
            {
                NotiLabel.Text = "Mid-term score must be between 0 and 10.";
                return;
            }
            float.TryParse(Final.Text, out final);
            if (final < 0 || final > 10)
            {
                NotiLabel.Text = "Final-term score must be between 0 and 10.";
                return;
            }
            float.TryParse(Other.Text, out other);
            if (other < 0 || other > 10)
            {
                NotiLabel.Text = "Other score must be between 0 and 10.";
                return;
            }
            float.TryParse(Score.Text, out score);
            if (score < 0 || score > 10)
            {
                NotiLabel.Text = "Final score must be between 0 and 10.";
                return;
            }

            var newInfo = new Information();

            newInfo.Id      = sID.Text;
            newInfo.Info    = new string[4];
            newInfo.Info[0] = mid.ToString();
            newInfo.Info[1] = final.ToString();
            newInfo.Info[2] = other.ToString();
            newInfo.Info[3] = score.ToString();

            try
            {
                var    service = new StudentServices();
                string temp    = $"Update BangDiem Set DiemGK = {newInfo.Info[0]}, DiemCK = {newInfo.Info[1]}, " +
                                 $"DiemKhac = {newInfo.Info[2]}, DiemTong = {newInfo.Info[3]}" +
                                 $"Where MSSV = '{newInfo.Id}' and MaLop = '{Class.Text}' and MaMon = '{Subject.Text}'";
                MessageBox.Show(temp);
                if (service.InsertScoreToDB(newInfo, Class.Text, Subject.Text))
                {
                    Close();
                }
                else
                {
                    MessageBox.Show($"Score of this student cannot be update!!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Score of this student cannot be update!!" + Environment.NewLine + ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void ImportButton_Click(object sender, EventArgs e)
        {
            StudentServices service = new StudentServices();
            int             i       = 0;

            if (listViewInfo == ListViewInfo.Students)
            {
                try
                {
                    service.InsertClassToDB(currClass);
                    Classes.Items.Add(currClass);

                    foreach (Information data in FileData)
                    {
                        try
                        {
                            service.InsertStudentToDB(data, currClass);
                            i++;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show($"Student with ID '{data.Id}' cannot be imported!!"
                                            + Environment.NewLine + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Class '{currClass}' cannot be imported!!" + Environment.NewLine + ex.Message);
                }
                NotiLabel.Text = $"{i} student(s) have been imported to class '{currClass}' successfully.";
            }
            else if (listViewInfo == ListViewInfo.Schedule)
            {
                try
                {
                    service.InsertClassToDB(currClass);
                    Classes.Items.Add(currClass);
                }
                catch { }

                foreach (Information data in FileData)
                {
                    try
                    {
                        service.InsertScheduleToDB(data, currClass);
                        i++;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Subject with ID '{data.Id}' cannot be imported!!"
                                        + Environment.NewLine + ex.Message);
                    }
                }

                NotiLabel.Text = $"{i} subject(s) from schedule have been imported for class '{currClass}' successfully.";
            }
            else if (listViewInfo == ListViewInfo.Scoreboard)
            {
                try
                {
                    service.InsertClassToDB(currClass);
                    Classes.Items.Add(currClass);
                }
                catch { }

                foreach (Information data in FileData)
                {
                    try
                    {
                        if (service.InsertScoreToDB(data, currClass, currSubject))
                        {
                            i++;
                        }
                        else
                        {
                            MessageBox.Show($"Score of student with ID '{data.Id}' cannot be imported!!");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Score of student with ID '{data.Id}' cannot be imported!!"
                                        + Environment.NewLine + ex.Message);
                    }
                }

                NotiLabel.Text = $"{i} student(s)' score have been imported for class '{currClass}' successfully.";
            }
            ImportButton.Enabled = false;
        }