private void btnAdd_Click(object sender, EventArgs e) { Lecture lecture = new Lecture(); lecture.L_ID = this.txtLectureID.Text.Trim(); lecture.L_name = this.txtLecturename.Text.Trim(); lecture.L_fullname = this.txtFullname.Text.Trim(); lecture.L_department = this.cmbDepartment.Text.Trim(); lecture.L_gender = this.cmbGender.Text.Trim(); lecture.L_birthday = DateTime.Parse(this.dateTimeBirthday.Text.Trim()); lecture.L_email = this.txtEmail.Text.Trim(); lecture.L_phone = this.txtPhone.Text.Trim(); if (LectureController.addLecture(lecture) == false) { MessageBox.Show("Error in adding a new lecture!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; }
private void btnUpdate_Click(object sender, EventArgs e) { Lecture lecture = new Lecture(); lecture.L_ID = this.dgvLecture.CurrentRow.Cells[0].Value.ToString(); if (lecture.L_ID.Length <= 0) { return; } if (this.dgvLecture.CurrentRow.Cells[1].Value is null) { this.dgvLecture.CurrentRow.Cells[1].Value = ""; } lecture.L_name = this.txtLecturename.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[2].Value is null) { this.dgvLecture.CurrentRow.Cells[2].Value = ""; } lecture.L_fullname = this.txtFullname.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[3].Value is null) { this.dgvLecture.CurrentRow.Cells[3].Value = ""; } lecture.L_department = this.cmbDepartment.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[4].Value is null) { this.dgvLecture.CurrentRow.Cells[4].Value = ""; } lecture.L_gender = this.cmbGender.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[5].Value is null) { this.dgvLecture.CurrentRow.Cells[5].Value = ""; } lecture.L_birthday = this.dateTimeBirthday.Value; if (this.dgvLecture.CurrentRow.Cells[6].Value is null) { this.dgvLecture.CurrentRow.Cells[6].Value = ""; } lecture.L_phone = this.txtPhone.Text.Trim(); if (this.dgvLecture.CurrentRow.Cells[7].Value is null) { this.dgvLecture.CurrentRow.Cells[7].Value = ""; } lecture.L_email = this.txtEmail.Text.Trim(); if (LectureController.UpdateLecture(lecture) == false) { MessageBox.Show("Cannot update!!!"); } else { MessageBox.Show("Update success", "Note", MessageBoxButtons.OK); BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; } }
public frmLecture() { InitializeComponent(); this.cID.DataPropertyName = nameof(Lecture.L_ID); this.cLecturename.DataPropertyName = nameof(Lecture.L_name); this.cFullname.DataPropertyName = nameof(Lecture.L_fullname); this.cDepartment.DataPropertyName = nameof(Lecture.L_department); this.cGender.DataPropertyName = nameof(Lecture.L_gender); this.cBirthday.DataPropertyName = nameof(Lecture.L_birthday); this.cPhone.DataPropertyName = nameof(Lecture.L_phone); this.cEmail.DataPropertyName = nameof(Lecture.L_email); this.cmbGender.DataSource = listgender; this.cmbDepartment.DataSource = listdepartment; BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; }
private void btnDelete_Click(object sender, EventArgs e) { if (this.dgvLecture.SelectedRows.Count <= 0) { return; } string idlecture = this.dgvLecture.SelectedRows[0].Cells[0].Value.ToString().Trim(); if (LectureController.DeleteLecture(idlecture) == false) { MessageBox.Show("Cannot delete lecture!!!"); } else { MessageBox.Show("Delete success!!!", "Note", MessageBoxButtons.OK); BindingSource source = new BindingSource(); source.DataSource = LectureController.getAllLecture(); this.dgvLecture.DataSource = source; } }