public static NhanVien Select_NhanVien(Struct.NhanVien.eNhanVien type, string input) { NhanVien nv = new NhanVien(); // kiểm tra nếu có dữ liệu thì xử lý, ko thì break if (GetDataSQL( @"select MaNhanVien, MatKhau, TenNhanVien, SoCMND, GioiTinh, NgaySinh, DiaChi, SoDienThoai, LaQuanTriVien, DuongDanAnhDaiDien from NhanVien where " + type.ToString() + " = '" + input + "'")) { // đọc đến khi hết if (reader.Read()) { // lấy dữ liệu cột MaNhanVien (cột 0) nv.MaNhanVien = reader.GetFieldValue <string>(0); // lấy dữ liệu cột MatKhau (cột 1) nv.MatKhau = reader.GetFieldValue <string>(1); // lấy dữ liệu cột TenNhanVien (cột 2) nv.TenNhanVien = reader.GetFieldValue <string>(2); // lấy dữ liệu cột SoCMND (cột 3) nv.SoCMND = reader.GetFieldValue <string>(3); // lấy dữ liệu cột GioiTinh (cột 4) nv.GioiTinh = reader.GetFieldValue <bool>(4); // lấy dữ liệu cột NgaySinh (cột 5) nv.NgaySinh = reader.GetFieldValue <DateTime>(5); // lấy dữ liệu cột DiaChi (cột 6) nv.DiaChi = reader.GetFieldValue <string>(6); // lấy dữ liệu cột SoDienThoai (cột 7) nv.SoDienThoai = reader.GetFieldValue <string>(7); // lấy dữ liệu cột LaQuanTriVien (cột 8) nv.LaQuanTriVien = reader.GetFieldValue <bool>(8); try { // lấy dữ liệu cột DuongDanAnhDaiDien (cột 9) nv.DuongDanAnhDaiDien = reader.GetFieldValue <string>(9); } catch { nv.DuongDanAnhDaiDien = ""; } // lNhanVien.Add(nv); } reader.Close(); commandSQL.Dispose(); connSQL.Close(); } return(nv); }
/// <summary> /// /// Update table NhanVien /// /// </summary> /// <param name="_typeDataNeedUpdate"> Kiểu dữ liệu cần update</param> /// <param name="_tableNeedUpdate"> Tên cột cần update</param> /// <param name="_input"> Giá trị của cột cần update</param> /// <param name="_tableCheck"></param> /// <param name="_DataCheck"></param> public static void Update_OneTable_NhanVien(string _typeDataNeedUpdate, Struct.NhanVien.eNhanVien _tableNeedUpdate, object _input, Struct.NhanVien.eNhanVien _tableCheck, string _DataCheck) { //try //{ switch (_typeDataNeedUpdate) { case "int": SQL.ListData.GetDataFromSQL.ExecuteNonQuery( @"update NhanVien set " + _tableNeedUpdate.ToString() + " = " + int.Parse(_input.ToString()) + " where " + _tableCheck.ToString() + " = N'" + _DataCheck + "'"); break; case "string": SQL.ListData.GetDataFromSQL.ExecuteNonQuery( @"update NhanVien set " + _tableNeedUpdate.ToString() + " = N'" + _input.ToString() + "' where " + _tableCheck.ToString() + " = N'" + _DataCheck + "'"); break; case "DateTime": SQL.ListData.GetDataFromSQL.ExecuteNonQuery( @"update NhanVien set " + _tableNeedUpdate.ToString() + " = N'" + DateTime.Parse(_input.ToString()) + "' where " + _tableCheck.ToString() + " = N'" + _DataCheck + "'"); break; case "bool": SQL.ListData.GetDataFromSQL.ExecuteNonQuery( @"update NhanVien set " + _tableNeedUpdate.ToString() + " = " + (bool.Parse(_input.ToString()) ? "'True'" : "'False'") + " where " + _tableCheck.ToString() + " = N'" + _DataCheck + "'"); break; default: break; } // MessageBox.Show("Update success!"); return; }