private void SaveButton_Click(object sender, EventArgs e)
 {
     if (sID.Text == "")
     {
         NotiLabel.Text = "Please enter student ID!!";
     }
     else
     {
         var newStudent = new Information();
         newStudent.Id   = sID.Text;
         newStudent.Name = Name.Text;
         newStudent.Info = new string[3];
         if (Male.Checked)
         {
             newStudent.Info[0] = "Nam";
         }
         else
         {
             newStudent.Info[0] = "Nữ";
         }
         newStudent.Info[1] = IdCard.Text;
         newStudent.Info[2] = DOB.Text;
         try
         {
             var service = new StudentServices();
             service.InsertStudentToDB(newStudent, Classes.Text);
             Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Beispiel #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;
        }