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.");
            }
        }