Пример #1
0
 private void CertDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == CertDataGridView.Columns["ViewStudentImage"].Index && e.RowIndex >= 0)
     {
         int       certId    = int.Parse(CertDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString());
         CertModel certModel = managingCertService.GetSingleCertById(certId);
         string    imageName = managingStudentService.GetStudentImage(certModel.StudentId);
         if (string.IsNullOrEmpty(imageName))
         {
             //MessageBox.Show("Không tìm thấy ảnh", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh", "Cảnh báo", MessageBoxIcon.Warning);
             notificationForm.ShowDialog();
             return;
         }
         string           path             = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
         ShowingImageForm showingImageForm = new ShowingImageForm(Path.Combine(@"C:\JbCert_Resource\StudentImages\", imageName));
         showingImageForm.ShowDialog();
     }
     else if (e.ColumnIndex == CertDataGridView.Columns["ViewBlankCertImage"].Index && e.RowIndex >= 0)
     {
         int       certId    = int.Parse(CertDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString());
         CertModel certModel = managingCertService.GetSingleCertById(certId);
         string    imageName = managingBlankCertService.GetBlankCertImage(certModel.BlankCertId);
         if (string.IsNullOrEmpty(imageName))
         {
             //MessageBox.Show("Không tìm thấy ảnh", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
             NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh", "Cảnh báo", MessageBoxIcon.Warning);
             notificationForm.ShowDialog();
             return;
         }
         string           path             = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
         ShowingImageForm showingImageForm = new ShowingImageForm(Path.Combine(@"C:\JbCert_Resource\Images\", imageName));
         showingImageForm.ShowDialog();
     }
 }
        private void StudentDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == StudentDataGridView.Columns["Edit"].Index && e.RowIndex >= 0)
            {
                int             studentId         = int.Parse(StudentDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString());
                EditStudentForm editBlankCertForm = new EditStudentForm(studentId);
                editBlankCertForm.ShowDialog();
            }
            else if (e.ColumnIndex == StudentDataGridView.Columns["Avatar"].Index && e.RowIndex >= 0)
            {
                try
                {
                    int    studentId = int.Parse(StudentDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString());
                    string imageName = managingStudentService.GetStudentImage(studentId);
                    if (string.IsNullOrEmpty(imageName))
                    {
                        //MessageBox.Show("Không tìm thấy ảnh", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh", "Cảnh báo", MessageBoxIcon.Warning);
                        notificationForm.ShowDialog();
                        return;
                    }

                    string           path             = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                    ShowingImageForm showingImageForm = new ShowingImageForm(Path.Combine(@"C:\JbCert_Resource\StudentImages", imageName));
                    showingImageForm.ShowDialog();
                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error);
                    notificationForm.ShowDialog();
                }
            }
            else if (e.ColumnIndex == StudentDataGridView.Columns["Delete"].Index && e.RowIndex >= 0)
            {
                DialogResult dialogResult = MessageBox.Show("Đồng ý xóa?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialogResult == DialogResult.Yes)
                {
                    try
                    {
                        int studentId = int.Parse(StudentDataGridView.Rows[e.RowIndex].Cells["Id"].Value.ToString());
                        int result    = managingStudentService.DeleteStudent(studentId);
                        if (result > 0)
                        {
                            //MessageBox.Show("Xóa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            NotificationForm notificationForm = new NotificationForm("Xóa thành công", "Thông báo", MessageBoxIcon.Information);
                            notificationForm.ShowDialog();
                            LoadStudentList();
                        }
                        else
                        {
                            //MessageBox.Show("Xóa không thành công", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            NotificationForm notificationForm = new NotificationForm("Xóa không thành công", "Cảnh báo", MessageBoxIcon.Warning);
                            notificationForm.ShowDialog();
                        }
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error);
                        notificationForm.ShowDialog();
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //no delete
                }
            }
        }
Пример #3
0
        private void EditCertForm_Load(object sender, EventArgs e)
        {
            try
            {
                // load school
                SchoolComboBox.DataSource    = managingSchoolService.GetAllSchool();
                SchoolComboBox.DisplayMember = "SchoolName";
                SchoolComboBox.ValueMember   = "Id";

                // load ethnic
                EthnicComboBox.DataSource    = managingStudentService.GetAllEthnic();
                EthnicComboBox.DisplayMember = "EthnicName";
                EthnicComboBox.ValueMember   = "Id";

                // load ranking
                RankingComboBox.DataSource    = managingStudentService.GetAllRanking();
                RankingComboBox.DisplayMember = "RankingName";
                RankingComboBox.ValueMember   = "Id";

                // load gender
                GenderComboBox.Items.Add("Nam");
                GenderComboBox.Items.Add("Nữ");

                // load major
                List <MajorModel> majorModels = managingStudentService.GetAllMajor();
                majorModels.Add(new MajorModel()
                {
                    Id        = -1,
                    MajorName = "Không có chuyên ngành"
                });
                MajorComboBox.DataSource    = majorModels;
                MajorComboBox.DisplayMember = "MajorName";
                MajorComboBox.ValueMember   = "Id";

                // load learning Mode
                LearningModeComboBox.DataSource    = managingStudentService.GetAllLearningMode();
                LearningModeComboBox.DisplayMember = "LearningModeName";
                LearningModeComboBox.ValueMember   = "Id";


                certModel    = managingCertService.GetSingleCertById(_certId);
                studentModel = managingStudentService.GetSingleStudentById(certModel.StudentId);

                FullnameTextBox.Text         = studentModel.FullName;
                SchoolComboBox.SelectedValue = studentModel.SchoolId;
                BornedAddressTextBox.Text    = studentModel.BornedAddress;
                AddressTextBox.Text          = studentModel.Address;
                DobTextBox.Text                    = studentModel.Dob.ToString("dd/MM/yyyy");
                HouseHoldTextBox.Text              = studentModel.HouseHold;
                ScoreTextBox.Text                  = studentModel.Score.ToString();
                GraduatingYearTextBox.Text         = studentModel.GraduatingYear.ToString();
                RankingComboBox.SelectedValue      = studentModel.RankingId;
                MajorComboBox.SelectedValue        = studentModel.MajorId;
                LearningModeComboBox.SelectedValue = studentModel.LearningModeId;
                EthnicComboBox.SelectedValue       = studentModel.EthnicId;
                GenderComboBox.SelectedItem        = studentModel.Gender;

                SerialTextBox.Text          = certModel.Serial;
                ReferenceNumberTextBox.Text = certModel.ReferenceNumber;

                // load student image
                string imageName = managingStudentService.GetStudentImage(certModel.StudentId);
                if (string.IsNullOrEmpty(imageName))
                {
                    //MessageBox.Show("Không tìm thấy ảnh", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh", "Lỗi", MessageBoxIcon.Error);
                    notificationForm.ShowDialog();
                    return;
                }
                string path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                using (FileStream fs = new FileStream(Path.Combine(@"C:\JbCert_Resource\StudentImages\", imageName), FileMode.Open))
                {
                    StudentImagePictureBox.Image = Image.FromStream(fs);
                }

                // load blankcert image
                imageName = managingBlankCertService.GetBlankCertImage(certModel.BlankCertId);
                if (string.IsNullOrEmpty(imageName))
                {
                    //MessageBox.Show("Không tìm thấy ảnh", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh", "Lỗi", MessageBoxIcon.Error);
                    notificationForm.ShowDialog();
                    return;
                }
                path = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
                using (FileStream fs = new FileStream(Path.Combine(@"C:\JbCert_Resource\Images\", imageName), FileMode.Open))
                {
                    BlankCertImagePictureBox.Image = Image.FromStream(fs);
                }
            }
            catch (FileNotFoundException FileNotFoundEx)
            {
                NotificationForm notificationForm = new NotificationForm("Không tìm thấy ảnh, vui lòng cập nhật lại ảnh", "Cảnh báo", MessageBoxIcon.Warning);
                notificationForm.ShowDialog();
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error);
                notificationForm.ShowDialog();
            }
        }