//Ham sua public bool SuaDuLieu(EC_TaiKhoan ec) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "dbo.[TaiKhoan_Update]"; cmd.CommandType = CommandType.StoredProcedure; try { con.MoKetNoi(); // Use connection object of base class cmd.Connection = con.connect; cmd.Parameters.AddWithValue("@ID", ec.ID); cmd.Parameters.AddWithValue("@TenDangNhap", ec.TenDangNhap); cmd.Parameters.AddWithValue("@MatKhau", ec.MatKhau); cmd.ExecuteNonQuery(); return(true); } catch (Exception e) { throw new Exception("Lỗi khi sua mon học", e); } finally { con.DongKetNoi(); cmd.Dispose(); } }
public static bool deleteTK(EC_TaiKhoan tk) { conn = GetData.KetNoi(); string sTruyVan = "TaiKhoan_Delete"; cmd = new SqlCommand(sTruyVan, conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@TaiKhoan", SqlDbType.NVarChar).Value = tk.TaiKhoan; cmd.ExecuteNonQuery(); cmd.Dispose(); conn.Close(); try { GetData.ThucThiTruyVanNonQuery(sTruyVan, conn); //Đóng kết nối GetData.DongKetNoi(conn); return(true); } catch (Exception ex) { //Đóng kết nối GetData.DongKetNoi(conn); return(false); } }
private void btDangNhap_Click(object sender, EventArgs e) { BUS_TaiKhoan busTK = new BUS_TaiKhoan(); List <EC_TaiKhoan> list1 = busTK.SelectByFields("TenDangNhap", txbTenDangNhap.Text); List <EC_TaiKhoan> list2 = busTK.SelectByFields("MatKhau", txbMatKhau.Text); EC_TaiKhoan TaiKhoan = new EC_TaiKhoan(); foreach (EC_TaiKhoan tk1 in list1) { foreach (EC_TaiKhoan tk2 in list2) { if (tk1.ID == tk2.ID) { TaiKhoan = tk1; } } } if (TaiKhoan.ID == "") { DialogResult result = MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); if (result == DialogResult.OK) { txbMatKhau.Text = ""; } return; } ID = TaiKhoan.ID; BUS_QuanLyTrungTam busQL = new BUS_QuanLyTrungTam(); BUS_GiaoVien busGV = new BUS_GiaoVien(); BUS_HocSinh busHS = new BUS_HocSinh(); if (busQL.TaoBang("where ID='" + ID + "'").Rows.Count != 0) { PhanQuyen = 1; // admin co quyen la 1 } else if (busGV.SelectByFields("ID", ID).Count != 0) { PhanQuyen = 2; //Giao vien co quyen la 2 } else if (busHS.SelectByFields("ID", ID).Count != 0) { PhanQuyen = 3; } else { PhanQuyen = 0; } MessageBox.Show("Đăng nhập thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Thread thr = new Thread(NewForm); thr.Start(); this.Close(); }
private void btLuu_Click(object sender, EventArgs e) { if (XacNhan == false) { lbThongBao.Visible = true; pnXacNhan.Visible = true; return; } if (btLuu.Text == "Thêm") { txbMatKhau.Enabled = true; btLuu.Text = "Lưu"; } else if (btLuu.Text == "Lưu") { string ID = TaoID(); string MatKhau = txbMatKhau.Text; if (MatKhau == "") { return; } EC_TaiKhoan ecTK = new EC_TaiKhoan(ID, txbTenDN.Text, Hash.getHashString(MatKhau)); new BUS_TaiKhoan().ThemDuLieu(ecTK); if (cbLoai.SelectedIndex == 0) { EC_QuanLyTrungTam ecQl = new EC_QuanLyTrungTam(); ecQl.ID = ID; new BUS_QuanLyTrungTam().ThemDuLieu(ecQl); } else if (cbLoai.SelectedIndex == 1) { BUS_GiaoVien busGv = new BUS_GiaoVien(); if (busGv.Select_ByPrimaryKey(txbMa.Text) == null) { MessageBox.Show("Không tồn tại giáo viên"); return; } busGv.ThemID(txbMa.Text, ID); } else if (cbLoai.SelectedIndex == 2) { BUS_HocSinh busHS = new BUS_HocSinh(); if (busHS.Select_ByPrimaryKey(txbMa.Text) == null) { MessageBox.Show("Không tồn tại học sinh"); return; } busHS.ThemID(txbMa.Text, ID); } btLuu.Text = "Thêm"; } else { } LoadForm(); }
/// <summary> /// Populate business objects from the data reader /// </summary> /// <param name="dataReader">data reader</param> /// <returns>list of SinhVien</returns> internal List <EC_TaiKhoan> PopulateObjectsFromReader(IDataReader dataReader) { List <EC_TaiKhoan> list = new List <EC_TaiKhoan>(); while (dataReader.Read()) { EC_TaiKhoan businessObject = new EC_TaiKhoan(); PopulateBusinessObjectFromReader(businessObject, dataReader); list.Add(businessObject); } return(list); }
/// <summary> /// Populate business object from data reader /// </summary> /// <param name="businessObject">business object</param> /// <param name="dataReader">data reader</param> internal void PopulateBusinessObjectFromReader(EC_TaiKhoan businessObject, IDataReader dataReader) { businessObject.ID = dataReader.GetString(dataReader.GetOrdinal(EC_TaiKhoan.TaiKhoanFields.ID.ToString())); if (!dataReader.IsDBNull(dataReader.GetOrdinal(EC_TaiKhoan.TaiKhoanFields.TenDangNhap.ToString()))) { businessObject.TenDangNhap = dataReader.GetString(dataReader.GetOrdinal(EC_TaiKhoan.TaiKhoanFields.TenDangNhap.ToString())); } if (!dataReader.IsDBNull(dataReader.GetOrdinal(EC_TaiKhoan.TaiKhoanFields.MatKhau.ToString()))) { businessObject.MatKhau = dataReader.GetString(dataReader.GetOrdinal(EC_TaiKhoan.TaiKhoanFields.MatKhau.ToString())); } }
void LayDuLieu() { DataTable tb = new DataTable(); if (Quyen == 2) { EC_GiaoVien GiaoVien = new BUS_GiaoVien().SelectByFields("ID", ID)[0]; txbTrinhDo.Text = GiaoVien.TrinhDo; lbTrinhDo.Text = "Trình độ"; txbHoTen.Text = GiaoVien.Ten_GiaoVien; txbMa.Text = GiaoVien.Ma_GiaoVien; txbNgaySinh.Text = GiaoVien.NgaySinh.ToString(); txbDiaChi.Text = GiaoVien.DiaChi; txbEmail.Text = GiaoVien.Email; txbSDT.Text = GiaoVien.SDT; comboBox1.SelectedIndex = GiaoVien.GioiTinh == true ? 0 : 1; cbLoaiTaiKhoan.SelectedIndex = 1; if (GiaoVien.Anh != null) { picAvt.Image = HinhAnh.ByteToImage(GiaoVien.Anh); } } else if (Quyen == 3) { EC_HocSinh hs = new BUS_HocSinh().SelectByFields("ID", ID)[0]; txbTrinhDo.Text = hs.Lop.ToString(); lbTrinhDo.Text = "Lớp"; txbHoTen.Text = hs.Ten_HocSinh; txbMa.Text = hs.Ma_HocSinh; txbNgaySinh.Text = hs.NgaySinh.ToString(); txbDiaChi.Text = hs.DiaChi; txbEmail.Text = hs.Email; txbSDT.Text = hs.SDT; comboBox1.SelectedIndex = hs.GioiTinh == true ? 0 : 1; cbLoaiTaiKhoan.SelectedItem = "Học sinh"; if (hs.Anh != null) { picAvt.Image = HinhAnh.ByteToImage(hs.Anh); } } BUS_TaiKhoan busTK = new BUS_TaiKhoan(); EC_TaiKhoan TaiKhoan = busTK.SelectByMa(ID); txbID.Text = ID; txbTenDN.Text = TaiKhoan.TenDangNhap; txbMatKhau.UseSystemPasswordChar = false; txbMatKhau.PasswordChar = '*'; txbMatKhau.Text = TaiKhoan.MatKhau; }
private void btDangNhap_Click(object sender, EventArgs e) { BUS_TaiKhoan busTK = new BUS_TaiKhoan(); List <EC_TaiKhoan> ListTaiKhoan = busTK.SelectByFields(txbTenDangNhap.Text, Hash.getHashString(txbMatKhau.Text)); EC_TaiKhoan TaiKhoan = new EC_TaiKhoan(); if (ListTaiKhoan.Count == 0) { DialogResult result = MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); if (result == DialogResult.OK) { txbMatKhau.Text = ""; } return; } TaiKhoan = ListTaiKhoan[0]; ID = TaiKhoan.ID; BUS_QuanLyTrungTam busQL = new BUS_QuanLyTrungTam(); BUS_GiaoVien busGV = new BUS_GiaoVien(); BUS_HocSinh busHS = new BUS_HocSinh(); if (busQL.Select_BYPrimaryKey(ID).Count > 0) { PhanQuyen = 1; // admin co quyen la 1 } else if (busGV.SelectByFields("ID", ID).Count != 0) { PhanQuyen = 2; //Giao vien co quyen la 2 } else if (busHS.SelectByFields("ID", ID).Count != 0) { PhanQuyen = 3; } else { PhanQuyen = 0; } MessageBox.Show("Đăng nhập thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Thread thr = new Thread(NewForm); thr.Start(); this.Close(); }
private void đăngXuấtToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult h = new DialogResult(); h = MessageBox.Show("Đăng Xuất", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (h.ToString() == "OK") { QuyenKhach(); // Thoát các Form hết foreach (Form f in this.MdiChildren) { f.Close(); } tk = null; frmDangNhap fr = new frmDangNhap(this); fr.ShowDialog(); } }
private void btLuu_Click(object sender, EventArgs e) { if (btLuu.Text == "Lưu") { EC_TaiKhoan ecTK = new EC_TaiKhoan(txbID.Text, txbTenDN.Text, txbMatKhau.Text); busTK.SuaDuLieu(ecTK); btLuu.Text = "Thêm"; txbID.Enabled = txbMa.Enabled = txbTenDN.Enabled = cbLoai.Enabled = true; } else if (btLuu.Text == "Thêm") { string ID = TaoID(); EC_TaiKhoan ecTK = new EC_TaiKhoan(ID, txbTenDN.Text, txbMatKhau.Text); if (cbLoai.SelectedIndex == 0) { EC_QuanLyTrungTam ecQl = new EC_QuanLyTrungTam(); ecQl.ID = ID; } else if (cbLoai.SelectedIndex == 1) { BUS_GiaoVien busGv = new BUS_GiaoVien(); if (busGv.Select_ByPrimaryKey(txbMa.Text) == null) { MessageBox.Show("Không tồn tại giáo viên"); return; } busGv.ThemID(txbMa.Text, ID); } else if (cbLoai.SelectedIndex == 2) { BUS_HocSinh busHS = new BUS_HocSinh(); if (busHS.Select_ByPrimaryKey(txbMa.Text) == null) { MessageBox.Show("Không tồn tại học sinh"); return; } busHS.ThemID(txbMa.Text, ID); } } else { } LoadForm(); }
private void btThem_TaiKhoan_Click(object sender, EventArgs e) { string Ma_HocSinh = txbMa_HocSinh.Text; if (Ma_HocSinh == "") { return; } EC_HocSinh HocSinh = new BUS_HocSinh().Select_ByPrimaryKey(Ma_HocSinh); if (HocSinh.ID == "") { try { string MatKhau = Hash.getHashString(txbMatKhau.Text); string ID = Tao_ID(); EC_TaiKhoan TaiKhoan = new EC_TaiKhoan(ID, txbTenDangNhap.Text, MatKhau); new BUS_TaiKhoan().ThemDuLieu(TaiKhoan); HocSinh.ID = ID; new BUS_HocSinh().SuaDuLieu(HocSinh); MessageBox.Show("Tạo tài khoản thành công", "Thông báo"); } catch { MessageBox.Show("Xem lại các thông tin đã tạo", "Thông báo"); } } else { try { string MatKhau = Hash.getHashString(txbMatKhau.Text); EC_TaiKhoan TaiKhoan = new EC_TaiKhoan(HocSinh.ID, txbTenDangNhap.Text, MatKhau); new BUS_TaiKhoan().ThemDuLieu(TaiKhoan); } catch { MessageBox.Show("Xem lại các thông tin đã tạo", "Thông báo"); } } }
public EC_TaiKhoan Select_ByPrimaryKey(string ID) { SqlCommand sqlCommand = new SqlCommand(); sqlCommand.CommandText = "dbo.[TaiKhoan_Select_By_ID]"; sqlCommand.CommandType = CommandType.StoredProcedure; try { con.MoKetNoi(); // Use connection object of base class sqlCommand.Connection = con.connect; sqlCommand.Parameters.AddWithValue("@ID", ID); IDataReader dataReader = sqlCommand.ExecuteReader(); if (dataReader.Read()) { EC_TaiKhoan businessObject = new EC_TaiKhoan(); PopulateBusinessObjectFromReader(businessObject, dataReader); return(businessObject); } else { return(null); } } catch (Exception ex) { throw new Exception("Lỗi khi lấy tất cả mon học: ", ex); } finally { con.DongKetNoi(); sqlCommand.Dispose(); } }
private void btThayDoiMatKhau_Click(object sender, EventArgs e) { if (btThayDoiMatKhau.Text == "Thay đổi mật khẩu") { if (groupBox1.Enabled == false) { groupBox1.Enabled = true; } btThayDoiMatKhau.Text = "Lưu sửa đổi"; } else if (btThayDoiMatKhau.Text == "Lưu sửa đổi") { if (groupBox1.Enabled == true) { groupBox1.Enabled = false; } BUS_TaiKhoan busTK = new BUS_TaiKhoan(); EC_TaiKhoan ecTK = new EC_TaiKhoan(ID, txbTenDN.Text, Hash.getHashString(txbMatKhau.Text)); busTK.SuaDuLieu(ecTK); btThayDoiMatKhau.Text = "Thay đổi mật khẩu"; } }
public void XoaTK(EC_TaiKhoan EC_TK) { connect.ThucHienLenh(@"delete from tblNhanVien where MaNV = '" + EC_TK.MaNV + "'"); connect.ThucHienLenh(@"delete from tblTaiKhoan where MaNV = '" + EC_TK.MaNV + "'"); }
public void ThemTK(EC_TaiKhoan EC_TK) { connect.ThucHienLenh(@"insert into tblTaiKhoan(MaNV, MatKhau, LoaiTK) values(N'" + EC_TK.MaNV + "', N'" + EC_TK.MatKhau + "', '" + EC_TK.LoaiTK + "') "); }
public void ThemDuLieu(EC_TaiKhoan ec) { sql.ThemDuLieu(ec); }
public void SuaDuLieu(EC_TaiKhoan ec) { sql.SuaDuLieu(ec); }
public bool updateMK(EC_TaiKhoan tk) { return(DA_TaiKhoan.updateMK(tk)); }
public bool getUser(EC_TaiKhoan tk) { return(DA_TaiKhoan.getUser(tk)); }
public bool deleteTK(EC_TaiKhoan tk) { return(DA_TaiKhoan.deleteTK(tk)); }
public void DoiLoai(EC_TaiKhoan EC_TK) { connect.ThucHienLenh(@"update tblTaiKhoan set LoaiTK = '" + EC_TK.LoaiTK + "' where MaNV = '" + EC_TK.MaNV + "'"); }
public bool insertTK(EC_TaiKhoan tk) { return(DA_TaiKhoan.insertTK(tk)); }
public void DoiMatKhau(EC_TaiKhoan EC_TK) { connect.ThucHienLenh(@"update tblTaiKhoan set MatKhau = '" + EC_TK.MatKhau + "' where MaNV = '" + EC_TK.MaNV + "'"); }