private void BtnDelete_Click(object sender, EventArgs e) { DialogResult dlg = MessageBox.Show("Bạn muốn xóa hội viên này ?", "Xóa hội viên", MessageBoxButtons.YesNo); if (dlg == DialogResult.Yes) { Database.QuanLyHoiVien.DSHVModel ds = new Database.QuanLyHoiVien.DSHVModel(); ds.Delete(hoiVien.ma.ToString().Trim()); MessageBox.Show("Xóa thành công."); Log.Insert("Xóa hội viên " + hoiVien.ma); LoadMemberListForm(); } }
private void BtnUpdate_Click(object sender, EventArgs e) { if (textBoxID.Text == "" || textBoxTen.Text == "" || textBoxTuoi.Text == "" || (radioButtonNam.Checked == false && radioButtonNu.Checked == false) || textBoxSDT.Text == "") { MessageBox.Show("Chưa đủ thông tin"); return; } DataTable dataTable = (new Database.QuanLyHoiVien.DSHVModel().GetData("Select ma from Member where ma='" + textBoxID.Text.ToString().Trim() + "'")); if (dataTable.Rows.Count == 0) { MessageBox.Show("ID chưa tồn tại"); } else if (dataTable.Rows.Count == 1) { hoiVien.ma = textBoxID.Text; hoiVien.ten = textBoxTen.Text; hoiVien.tuoi = Convert.ToInt32(textBoxTuoi.Text.ToString()); hoiVien.gioiTinh = (radioButtonNam.Checked ? "Nam" : "Nữ"); hoiVien.sdt = textBoxSDT.Text; hoiVien.ngayThamGia = dateTimePickerNgayThamGia.Value; hoiVien.ngayTKetThuc = dateTimePickerNgayKetThuc.Value; Database.QuanLyHoiVien.DSHVModel MemberListFormModel = new Database.QuanLyHoiVien.DSHVModel(); try { if (cb_endDayincluded.Checked == true) { MemberListFormModel.FullUpdate(hoiVien); } else { MemberListFormModel.Insert(hoiVien); } MessageBox.Show("Cập nhật thành công."); Log.Insert("Cập nhật thông tin hội viên " + hoiVien.ma); LoadMemberListForm(); } catch (Exception) { MessageBox.Show("Lỗi! Cập nhật thất bại!"); } } else { } }
private void LoadMemberListForm() { DataTable dataTable = new DataTable(); dataTable = new Database.QuanLyHoiVien.DSHVModel().GetData("Select * from Member"); this.dataGridViewHoiVien.DataSource = dataTable; dataGridViewHoiVien.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; SetHeader(); //using (MainDataClassesDataContext db = new MainDataClassesDataContext()) { // this.dataGridViewHoiVien.DataSource = from m in db.Members // select m; //} //dataGridViewHoiVien.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; //SetHeader(); }
private void BtnOK_Click(object sender, EventArgs e) { if (textBoxID.Text.Trim() == "" || textBoxTen.Text.Trim() == "" || textBoxTuoi.Text.Trim() == "" || (radioButtonNam.Checked == false && radioButtonNu.Checked == false) || textBoxSDT.Text.Trim() == "") { MessageBox.Show("Chưa đủ thông tin"); return; } else { DataTable dataTable = (new Database.QuanLyHoiVien.DSHVModel().GetData("Select ma from Member where ma='" + textBoxID.Text.ToString().Trim() + "'")); if (dataTable.Rows.Count == 1) { MessageBox.Show("ID đã tồn tại"); } else { Database.QuanLyHoiVien.DSHVModel MemberModel = new Database.QuanLyHoiVien.DSHVModel(); hoiVien.ma = textBoxID.Text; hoiVien.ten = textBoxTen.Text; hoiVien.tuoi = Convert.ToInt32(textBoxTuoi.Text.ToString()); hoiVien.gioiTinh = (radioButtonNam.Checked ? "Nam" : "Nữ"); hoiVien.sdt = textBoxSDT.Text; hoiVien.ngayThamGia = dateTimePickerNgayThamGia.Value; try { MemberModel.Insert(hoiVien); MessageBox.Show("Đăng ký thành công."); log.Insert("Thêm hội viên " + hoiVien.ma); } catch (Exception) { MessageBox.Show("Có lỗi xảy ra. Vui Lòng thử lại."); } } } }