private void btnCapNhat_Click(object sender, EventArgs e) { if (txtMatkhaucu.Text == "" || txtMatkhaumoi.Text == "") { MessageBox.Show("Bạn cần nhập đầy đủ thông tin!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (txtNhaplaimatkhau.Text != txtMatkhaumoi.Text) { MessageBox.Show("Mật khẩu nhập lại không khớp!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { TAIKHOAN tk = db.TAIKHOANs.Single(x => x.TENDANGNHAP.Equals(nguoidung)); if (tk.MATKHAU == txtMatkhaucu.Text) { tk.MATKHAU = txtMatkhaumoi.Text; db.SaveChanges(); MessageBox.Show("Đỗi mật khẩu thành công!!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Mật khẩu cũ không đúng!!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }
private void LVTK_SelectedIndexChanged(object sender, EventArgs e) { ListView lv = sender as ListView; if (lv.SelectedItems.Count == 1) { ID = int.Parse(lv.SelectedItems[0].SubItems[0].Text); txtTennguoidung.Text = lv.SelectedItems[0].SubItems[1].Text; txtTendangnhap.Text = lv.SelectedItems[0].SubItems[2].Text; txtMatkhau.Text = lv.SelectedItems[0].SubItems[3].Text;; TAIKHOAN tk = db.TAIKHOANs.Find(ID); if (tk.TYPE == 0) { cboPhanQuyen.SelectedIndex = 0; } else if (tk.TYPE == 1) { cboPhanQuyen.SelectedIndex = 1; } else if (tk.TYPE == 2) { cboPhanQuyen.SelectedIndex = 2; } else { cboPhanQuyen.SelectedIndex = -1; } } }
private void btnEdit_Click(object sender, EventArgs e) { if (ID == null) { MessageBox.Show("Bạn chưa chọn tài khoản để sửa!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { TAIKHOAN tk = db.TAIKHOANs.Find(ID); tk.TENNGUOIDUNG = txtTennguoidung.Text; tk.TENDANGNHAP = txtTendangnhap.Text; tk.MATKHAU = txtMatkhau.Text; if (cboPhanQuyen.SelectedIndex == 0) { tk.TYPE = 0; } else if (cboPhanQuyen.SelectedIndex == 1) { tk.TYPE = 1; } else if (cboPhanQuyen.SelectedIndex == 2) { tk.TYPE = 2; } db.SaveChanges(); MessageBox.Show("Sửa thông tin thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); fmPhanquyen_Load(sender, e); } }
private void btnDelete_Click(object sender, EventArgs e) { if (ID == null) { MessageBox.Show("Bạn chưa chọn tài khoản để Xóa!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { TAIKHOAN tk = db.TAIKHOANs.Find(ID); db.TAIKHOANs.Remove(tk); db.SaveChanges(); MessageBox.Show("Xóa thông tin thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); fmPhanquyen_Load(sender, e); } }
private void btnAdd_Click(object sender, EventArgs e) { if (txtTennguoidung.Text == "" || txtMatkhau.Text == "" || txtTendangnhap.Text == "") { XtraMessageBox.Show("Bạn cần điền đầy đủ thông tin!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtNhaplaimatkhau.Text != txtMatkhau.Text) { XtraMessageBox.Show("Mật khẩu nhập lại không khớp!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string User = txtTendangnhap.Text; List <TAIKHOAN> tk = db.TAIKHOANs.Where(x => x.TENDANGNHAP.Equals(User)).ToList(); if (tk.Count != 0) { XtraMessageBox.Show("Tài khoản này đã có người đăng ký", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } TAIKHOAN Newtk = new TAIKHOAN(); Newtk.TENNGUOIDUNG = txtTennguoidung.Text; Newtk.TENDANGNHAP = txtTendangnhap.Text; Newtk.MATKHAU = txtMatkhau.Text; if (cboPhanQuyen.SelectedIndex == 0) { Newtk.TYPE = 0; } else if (cboPhanQuyen.SelectedIndex == 1) { Newtk.TYPE = 1; } else if (cboPhanQuyen.SelectedIndex == 2) { Newtk.TYPE = 2; } db.TAIKHOANs.Add(Newtk); db.SaveChanges(); XtraMessageBox.Show("Đăng ký thành công!", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }