private void btnDelete_Click(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                try
                {
                    DialogResult result = MessageBox.Show("Are you sure you want to delete the selected record?", "Training Information Management System", MessageBoxButtons.YesNo);
                    if (result == DialogResult.OK)
                    {
                        int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);
                        BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                        BusinessEntity.TraineeEntity oldTrainee     = traineeManager.GetSingle(traineeID);

                        traineeManager.Delete(oldTrainee);
                        MessageBox.Show("Trainee Information Deleted Successfully.");
                        LoadTrainees();
                    }
                }
                catch (Exception ex)
                {
                    //save to log table
                    MessageBox.Show("Delete Failed, Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please select trainee from the list first.");
            }
        }
        public void UpdateTraineePhoto(int traineeID, string fileName)
        {
            Image img = Image.FromFile(fileName);

            byte[] buffer = this.ImageToByteArray(img);

            BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
            BusinessEntity.TraineeEntity trainee        = traineeManager.GetSingle(traineeID);
            trainee.Photo = buffer;
            traineeManager.Update(trainee);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                try
                {
                    if (IsValid())
                    {
                        int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);
                        BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                        BusinessEntity.TraineeEntity oldTrainee     = traineeManager.GetSingle(traineeID);

                        BusinessEntity.TraineeEntity newTrainee = new BusinessEntity.TraineeEntity();

                        newTrainee.ID                     = traineeID;
                        newTrainee.Fullname               = txtFullname.Text;
                        newTrainee.BirthDate              = dtpBirthDate.Value;
                        newTrainee.GenderEntity           = new BusinessEntity.GenderEntity();
                        newTrainee.GenderEntity.ID        = int.Parse(cboGender.SelectedValue.ToString());
                        newTrainee.AcademicLevelEntity    = new BusinessEntity.AcademicLevelEntity();
                        newTrainee.AcademicLevelEntity.ID = int.Parse(cboAcademicLevel.SelectedValue.ToString());
                        newTrainee.BranchEntity           = new BusinessEntity.BranchEntity();
                        newTrainee.BranchEntity.ID        = int.Parse(cboBranch.SelectedValue.ToString());
                        newTrainee.Address                = txtAddress.Text;
                        newTrainee.PhoneNumber            = txtPhoneNumber.Text;
                        newTrainee.CreatedBy              = oldTrainee.CreatedBy;
                        newTrainee.CreatedDate            = oldTrainee.CreatedDate;
                        newTrainee.UpdatedBy              = this.Tag.ToString();
                        newTrainee.UpdatedDate            = DateTime.Now;

                        traineeManager.Update(newTrainee);
                        if (txtPhotoLocation.Text != string.Empty)
                        {
                            UpdateTraineePhoto(newTrainee.ID, txtPhotoLocation.Text);
                        }

                        MessageBox.Show("Trainee Information Updated Successfully.");
                        LoadTrainees();
                    }
                }
                catch (Exception ex)
                {
                    //save to log table
                    MessageBox.Show("Update Failed, Please try again.");
                }
            }
            else
            {
                MessageBox.Show("Please select trainee from the list first.");
            }
        }
Ejemplo n.º 4
0
        private void listViewTrainee_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewTrainee.SelectedItems.Count > 0)
            {
                int traineeID = int.Parse(listViewTrainee.SelectedItems[0].SubItems[0].Text);

                BusinessLogic.TraineeManager traineeManager = new BusinessLogic.TraineeManager();
                BusinessEntity.TraineeEntity trainee        = traineeManager.GetSingle(traineeID);

                txtFullname.Text      = trainee.Fullname;
                dtpBirthDate.Text     = trainee.BirthDate.ToString();
                cboGender.Text        = trainee.GenderEntity.Title;
                cboAcademicLevel.Text = trainee.AcademicLevelEntity.Title;
                txtAddress.Text       = trainee.Address;
                txtPhoneNumber.Text   = trainee.PhoneNumber;

                this.pictureBoxPhoto.Image    = this.GetDataToImage(trainee.Photo);
                this.pictureBoxPhoto.SizeMode = PictureBoxSizeMode.Zoom;
            }
        }