private void btnDelete_Click(object sender, EventArgs e) { if (listViewTraineeCourse.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 traineeCourseID = int.Parse(listViewTraineeCourse.SelectedItems[0].SubItems[0].Text); BusinessLogic.TraineeCourseManager traineeCourseManager = new BusinessLogic.TraineeCourseManager(); BusinessEntity.TraineeCourseEntity oldTraineeCourse = traineeCourseManager.GetSingle(traineeCourseID); traineeCourseManager.Delete(oldTraineeCourse); MessageBox.Show("Trainee's Course Information Deleted Successfully."); LoadTraineeCourses(); } } catch (Exception ex) { //save to log table MessageBox.Show("Delete Failed, Please try again."); } } else { MessageBox.Show("Please select trainee from the list first."); } }
private void btnUpdate_Click(object sender, EventArgs e) { if (listViewTraineeCourse.SelectedItems.Count > 0) { try { if (IsValid()) { int traineeCourseID = int.Parse(listViewTraineeCourse.SelectedItems[0].SubItems[0].Text); BusinessLogic.TraineeCourseManager traineeCourseManager = new BusinessLogic.TraineeCourseManager(); BusinessEntity.TraineeCourseEntity oldTraineeCourse = traineeCourseManager.GetSingle(traineeCourseID); BusinessEntity.TraineeCourseEntity newTraineeCourse = new BusinessEntity.TraineeCourseEntity(); newTraineeCourse.ID = traineeCourseID; newTraineeCourse.TraineeEntity = new BusinessEntity.TraineeEntity(); newTraineeCourse.TraineeEntity.ID = int.Parse(cboTrainee.SelectedValue.ToString()); newTraineeCourse.CourseEntity = new BusinessEntity.CourseEntity(); newTraineeCourse.CourseEntity.ID = int.Parse(cboCourse.SelectedValue.ToString()); newTraineeCourse.RegistrationDate = dtpRegistrationDate.Value; newTraineeCourse.Duration = cboDuration.Text; newTraineeCourse.Cost = decimal.Parse(txtCost.Text); newTraineeCourse.CreatedBy = oldTraineeCourse.CreatedBy; newTraineeCourse.CreatedDate = oldTraineeCourse.CreatedDate; newTraineeCourse.UpdatedBy = this.Tag.ToString(); newTraineeCourse.UpdatedDate = DateTime.Now; traineeCourseManager.Update(newTraineeCourse); MessageBox.Show("Trainee's Course Information Updated Successfully."); LoadTraineeCourses(); } } catch (Exception ex) { //save to log table MessageBox.Show("Update Failed, Please try again."); } } else { MessageBox.Show("Please select trainee's course from the list first."); } }