Exemple #1
0
//		public static void SaveSetting(string connectionstring = null, string lastAccLogIn = null, string lastUserName = null,
//			string lastDatabase = null, string lastServerName = null,
//			DateTime? lastStartDate = null, DateTime? lastEndDate = null,
//			int? lastSanLuong = null, int? lastDonGia = null,
//			int? lastSanLuongGiaCongNoiBo = null, int? lastDonGiaGiaCongNoiBo = null,
//			int? lastSanLuongGiaCongNgoai = null, int? lastDonGiaGiaCongNgoai = null,
//			int? lastLuongToiThieu = null, int? lastBoiDuongCa3 = null,
//			string lastTenNVLapBieuChamCong = null, string lastTenNVLapBieuLuong = null, string lastTenTruongBP = null
//			) {
//			if (string.IsNullOrEmpty(connectionstring) == false) Settings.Default.ConnectionStringPath = connectionstring;
//			if (string.IsNullOrEmpty(lastAccLogIn) == false) Settings.Default.LastAccLogIn = lastAccLogIn;
//			if (string.IsNullOrEmpty(lastUserName) == false) Settings.Default.LastUsername = lastUserName;
//			if (string.IsNullOrEmpty(lastDatabase) == false) Settings.Default.LastDatabase = lastDatabase;
//			if (string.IsNullOrEmpty(lastServerName) == false) Settings.Default.LastServerName = lastServerName;
//			if (lastStartDate != null) Settings.Default.LastStartDate = new DateTime(lastStartDate.Value.Year, lastStartDate.Value.Month, lastStartDate.Value.Day);
//			if (lastEndDate != null) Settings.Default.LastEndDate = new DateTime(lastEndDate.Value.Year, lastEndDate.Value.Month, lastEndDate.Value.Day);
//			if (lastSanLuong != null) Settings.Default.LastSanLuong = (int)lastSanLuong;
//			if (lastDonGia != null) Settings.Default.LastDonGia = (int)lastDonGia;
//			if (lastSanLuongGiaCongNoiBo != null) Settings.Default.LastSanluongGiaCongNoibo = (int)lastSanLuongGiaCongNoiBo;
//			if (lastDonGiaGiaCongNoiBo != null) Settings.Default.LastDongiaGiacongNoibo = (int)lastDonGiaGiaCongNoiBo;
//			if (lastSanLuongGiaCongNgoai != null) Settings.Default.LastSanluongGiacongNgoai = (int)lastSanLuongGiaCongNgoai;
//			if (lastDonGiaGiaCongNgoai != null) Settings.Default.LastDongiaGiacongNgoai = (int)lastDonGiaGiaCongNgoai;
//			if (lastLuongToiThieu != null) Settings.Default.LastLuongToiThieu = (int)lastLuongToiThieu;
//			if (lastBoiDuongCa3 != null) Settings.Default.LastBoiDuongCa3 = (int)lastBoiDuongCa3;
//			if (lastTenNVLapBieuChamCong != null) Settings.Default.LastTenNVLapBieuChamCong = lastTenNVLapBieuChamCong;
//			if (lastTenNVLapBieuLuong != null) Settings.Default.LastTenNVLapBieuLuong = lastTenNVLapBieuLuong;
//			if (lastTenTruongBP != null) Settings.Default.LastTenTruongBP = lastTenTruongBP;
//			//if ( != null) Settings.Default. = ();
//			Settings.Default.Save();
//		}

//		#region xử lý load treeView dsnv ở các form

//		#region cách làm không store procedure

//		public static TreeView loadTreePhgBan(TreeView tvDSPhongBan, List<cPhongBan> TatcaPhongban, List<cPhongBan> dsPhongduocThaotac) {
//			tvDSPhongBan.Nodes.Clear();

//			//load tất cả phòng ban vào tree
//			foreach (cPhongBan phong in TatcaPhongban.FindAll(item => item.idParent == 0).OrderBy(item => item.ViTri)) {
//				TreeNode parentNode = new TreeNode { Text = phong.Ten, Tag = phong };
//				tvDSPhongBan.Nodes.Add(parentNode);
//				loadTreeSubNode(ref parentNode, phong.ID, TatcaPhongban);
//			}

//			// lập ds các node chứa các phòng ban được thao tác
//			TreeNode root = tvDSPhongBan.TopNode;

//			List<TreeNode> dsNodeThaotac = new List<TreeNode>();
//			GetListNode_Thaotac(root, dsPhongduocThaotac, ref dsNodeThaotac); // lấy tất cả các node chứa phòng ban được thao tác

//			// thêm vào danh sách các node không được thao tác nhưng nằm trên đường dẫn đến node được thao tác
//			for (int i = 0; i < dsNodeThaotac.Count; i++) {
//				TreeNode node = dsNodeThaotac[i];
//				GetNodesInPath(node.Parent, dsNodeThaotac);
//			}

//			// loại bỏ các node ko được thao tác và không thuộc đường dẫn đến node thao tác
//			RemoveNodeNotInPath(ref root, dsNodeThaotac);

//			return tvDSPhongBan;
//		}

//		private static bool RemoveNodeNotInPath(ref TreeNode root, List<TreeNode> nodesInPath) {
//			if (root == null)
//				return false;

//			if (root.Nodes.Count > 0) {
//				int i = 0;
//				// sử dụng kiểu này vì khi xoá 1 node thì danh sách node bị thay đổi --> foreach ko cho phép
//				// sử dụng for i thì khi xoá node, node sau dồn lên, index i phải giữ nguyên ko được ++
//				while (i < root.Nodes.Count) {
//					TreeNode node = root.Nodes[i];
//					bool kq = RemoveNodeNotInPath(ref node, nodesInPath);
//					if (kq == false) i++; // điều kiện tăng i là nếu xoá được node, ngược lại hết đường thì dừng,
//				}
//			}

//			bool found1 = false;
//			for (int i = 0; i < nodesInPath.Count; i++) {
//				TreeNode node = nodesInPath[i];
//				if (root != node) continue;
//				else {
//					found1 = true;
//					break;
//				}
//			}
//			if (found1 == false) {
//				root.Remove();
//				return true;
//			}
//			return false;

//		}

//		private static void GetNodesInPath(TreeNode root, List<TreeNode> nodes) {
//			if (root == null) return;

//			// nếu curr đã nằm trong ds node được thao tác thì trùng ko add thêm
//			bool found = false;
//			for (int i = nodes.Count - 1; i >= 0; i--) {
//				if (nodes[i] != root) continue;
//				found = true; //nodes[i] == root ==> đã tồn tại trong danh sách -> break vòng lặp, ko add mà tiếp tục
//				break;
//			}
//			if (found == false) nodes.Add(root); // ko tìm thấy --> đó là node mới--> add node mới
//			GetNodesInPath(root.Parent, nodes); // tiếp tục kiểm tra node cha của node hiện tại
//		}

//		private static void GetListNode_Thaotac(TreeNode root, List<cPhongBan> dsPhongduocThaotac, ref List<TreeNode> nodes) {
//			if (root == null) return;

//			// nếu currNode được phép thao tác thì add current node
//			for (int i = 0; i < dsPhongduocThaotac.Count; i++) {
//				cPhongBan phongDuocThaotac = dsPhongduocThaotac[i];
//				cPhongBan phongDangXet = (cPhongBan)root.Tag;
//				if (phongDangXet.ID == phongDuocThaotac.ID) {
//					phongDangXet.ChoPhep = true;
//					nodes.Add(root);
//				}
//			}

//			if (root.Nodes.Count > 0) {
//				// nếu có node con thì add các node con thoả điều kiện
//				for (int i = 0; i < root.Nodes.Count; i++) {
//					TreeNode node = root.Nodes[i];
//					GetListNode_Thaotac(node, dsPhongduocThaotac, ref nodes);
//				}
//			}
//			// ko có node con thì dừng

//		}

//		public static void loadTreeSubNode(ref TreeNode ParentNode, int idPhongBanTrucThuoc, List<cPhongBan> dsphongban) {
//			List<cPhongBan> childs = dsphongban.Where(item => item.idParent == idPhongBanTrucThuoc).OrderBy(item => item.ViTri).ToList();
//			foreach (cPhongBan phong in childs) {
//				TreeNode child = new TreeNode { Text = phong.Ten, Tag = phong, ToolTipText = phong.Ten };
//				ParentNode.Nodes.Add(child);
//				loadTreeSubNode(ref child, phong.ID, dsphongban);
//			}
//		}

//		public static void GetIDNodeAndChildNode(TreeNode root, ref List<int> listID) {
//			if (root == null) return;

//			cPhongBan phong = (cPhongBan)root.Tag;
//			if (phong != null && phong.ChoPhep) listID.Add(phong.ID);

//			if (root.Nodes.Count > 0) {
//				foreach (TreeNode node in root.Nodes) {
//					GetIDNodeAndChildNode(node, ref listID);
//				}
//			}
//			// xuốn đến đây tương đương root.Nodes.Count== 0; return
//		}

//		#endregion

//		#region cách làm có store procedure
//		public static TreeView loadTreePhgBan(TreeView tvDSPhongBan) {
//			tvDSPhongBan.Nodes.Clear();
//			DataTable tableDSPhong = SqlDataAccessHelper.ExecSPQuery(SPName.RelationDept_DocTatCaPhongBan.ToString());
//			DataTable tableDSPhongThacTac = SqlDataAccessHelper.ExecSPQuery(SPName.RelationDept_DocDSPhongDuocThaoTac.ToString(),
//				new SqlParameter("@UserID", XL2.currUserID));

//			var rowsPhong = (from DataRow row in tableDSPhong.Rows select row).OrderBy(s => (int)s["ViTri"]);
//			var relationID_0 = rowsPhong.Where(o => (int)o["RelationID"] == 0).ToList().OrderBy(s => (int)s["ViTri"]);
//			var rowsPhongThaoTac = (from DataRow row in tableDSPhongThacTac.Rows select row).OrderBy(s => (int)s["ViTri"]);

//			foreach (var dataRowView in relationID_0) {
//				TreeNode parentNode = new TreeNode { Text = dataRowView["Description"].ToString(), Tag = dataRowView };
//				tvDSPhongBan.Nodes.Add(parentNode);
//				loadTreeSubNode(ref parentNode, (int)dataRowView["ID"], rowsPhong/*TatcaPhongban*/);
//			}

//			// lập ds các node chứa các phòng ban được thao tác
//			TreeNode root = TopNode(tvDSPhongBan.TopNode);
//			List<TreeNode> dsNodeThaotac = new List<TreeNode>();
//			GetListNode_Thaotac(root, rowsPhongThaoTac.ToList(), ref dsNodeThaotac);// lấy tất cả các node chứa phòng ban được thao tác
//			// loại bỏ các node ko được thao tác và không thuộc đường dẫn đến node thao tác
//			RemoveNodeNotInPath(ref root, dsNodeThaotac);


//			return tvDSPhongBan;
//		}



//		public static void loadTreeSubNode(ref TreeNode ParentNode, int idPhongBanTrucThuoc, IOrderedEnumerable<DataRow> dsphongban /*List<cPhongBan> dsphongban*/) {
//			IOrderedEnumerable<DataRow> childs = dsphongban.Where(item => (int)item["RelationID"] == idPhongBanTrucThuoc).ToList().OrderBy(item => (int)item["ViTri"]);
//			foreach (DataRow phong in childs) {
//				TreeNode child = new TreeNode { Text = phong["Description"].ToString(), Tag = phong };
//				ParentNode.Nodes.Add(child);
//				loadTreeSubNode(ref child, (int)phong["ID"], dsphongban);
//			}
//		}

//		private static void GetListNode_Thaotac(TreeNode root, List<DataRow> dsPhongduocThaotac, ref List<TreeNode> nodes) {
//			if (root == null) return;

//			// nếu currNode được phép thao tác thì add current node
//			for (int i = 0; i < dsPhongduocThaotac.Count; i++) {
//				DataRow phongDangXet = (DataRow)root.Tag; // isyes phongDangXet = 0
//				DataRow phongDuocThaotac = dsPhongduocThaotac[i]; //isyes phongDuocThaotac =1
//				if ((int)phongDangXet["ID"] == (int)phongDuocThaotac["ID"]) {
//					phongDangXet["IsYes"] = 1;
//					nodes.Add(root);
//				}
//			}

//			if (root.Nodes.Count > 0) { // nếu có node con thì add các node con thoả điều kiện
//				for (int i = 0; i < root.Nodes.Count; i++) {
//					TreeNode node = root.Nodes[i];
//					GetListNode_Thaotac(node, dsPhongduocThaotac, ref nodes);
//				}
//			}
//			// ko có node con thì dừng

//		}

//		public static void GetIDNodeAndChildNode1(TreeNode root, ref List<int> listID) {
//			if (root == null) return;

//			DataRow phong = (DataRow)root.Tag;
//			if (phong != null && (int)phong["IsYes"] == 1) listID.Add((int)phong["ID"]);

//			if (root.Nodes.Count > 0) {
//				foreach (TreeNode node in root.Nodes) {
//					GetIDNodeAndChildNode1(node, ref listID);
//				}
//			}
//			// xuốn đến đây tương đương root.Nodes.Count== 0; return
//		}
//		#endregion

//		#endregion

//		public static void ChuanBiDSLichTrinhVaCa() {

//			XL.DSCaMoRong.Clear();
//			XL.DSCa.Clear();

//			//lấy danh sách tất cả các ca
//			var tableDSCa = DAO5.LayDSCa();
//			List<cCa> tempList = new List<cCa>();
//			foreach (DataRow row in tableDSCa.Rows) {
//				#region transfer dữ liệu từ row sang đối tượng
//				var iShiftID = (int)row["ShiftID"];
//				var sShiftCode = row["ShiftCode"].ToString();

//				TimeSpan tsOnDuty;
//				TimeSpan.TryParse(row["Onduty"].ToString(), out tsOnDuty);
//				TimeSpan tOffDuty;
//				TimeSpan.TryParse(row["Offduty"].ToString(), out tOffDuty);
//				var iDayCount = (int)row["DayCount"];
//				tOffDuty = tOffDuty.Add(new TimeSpan(iDayCount, 0, 0, 0));
//				TimeSpan timespanStartNightTime, timespanEndddNightTime;
//				if (row["StartNT"] == DBNull.Value || TimeSpan.TryParse(row["StartNT"].ToString(), out timespanStartNightTime) == false) timespanStartNightTime = XL2._22h00;//ver 4.0.0.4
//				if (row["EndNT"] == DBNull.Value || TimeSpan.TryParse(row["EndNT"].ToString(), out timespanEndddNightTime) == false) timespanEndddNightTime = XL2._06h00;//ver 4.0.0.4

//				var tOnLunch = XL2._0gio;
//				var tOffLunch = XL2._0gio;
//				if (row["OnLunch"] != DBNull.Value && row["OffLunch"] != DBNull.Value) {
//					TimeSpan.TryParse(row["OnLunch"].ToString(), out tOnLunch);
//					TimeSpan.TryParse(row["OffLunch"].ToString(), out tOffLunch);
//				}
//				var LunchMin = tOffLunch.Subtract(tOnLunch);

//				var tempWorkingTime = int.Parse(row["WorkingTime"].ToString());
//				var kyhieucc = row["KyHieuCC"].ToString();
//				var tachcadem = (row["IsSplited"] != DBNull.Value) && (bool)row["IsSplited"];
//				var idCaTruoc = (row["ShiftID1"] != DBNull.Value) ? (int)row["ShiftID1"] : -1;
//				var idCaSauuu = (row["ShiftID2"] != DBNull.Value) ? (int)row["ShiftID2"] : -1;
//				var isextend = (row["IsExtended"] != DBNull.Value) && (bool)row["IsExtended"];
//				var tempShift = new cCa {
//					ID = iShiftID,
//					Code = sShiftCode,
//					TOD_Duty = new TS { Onn = tsOnDuty, Off = tOffDuty },
//					PhutOnnInn = (int)row["OnTimeIn"],
//					PhutCutInn = (int)row["CutIn"],
//					PhutOnnOut = (int)row["OnTimeOut"],
//					PhutCutOut = (int)row["CutOut"],
//					PhutToiThieuTinhOT = (int)row["AfterOT"],
//					PhutChoTre = (int)row["LateGrace"],
//					PhutChoSom = (int)row["EarlyGrace"],
//					//LateeMin = tLateGrace,
//					//EarlyMin = tEarlyGrace,
//					Workingday = (Single)row["Workingday"],
//					WorkingTimeTS = new TimeSpan(0, tempWorkingTime, 0),
//					PhutNghiTrua = Convert.ToInt32(LunchMin.TotalMinutes),
//					TachCaDem = tachcadem,
//					idCaTruoc = idCaTruoc,
//					idCaSauuu = idCaSauuu,
//					KyHieuCC = kyhieucc,
//					MoTa = row["Description"].ToString(),
//					IsExtended = isextend,
//					TOD_NightTime = new TS { Onn = timespanStartNightTime, Off = timespanEndddNightTime }
//				};
//					//tempShift.TOD_NhanDienVao = new TS { Onn = tempShift.ThoiDiemOnnInn(), Off = tod_CutIn },
//					//tempShift.TOD_NhanDienRaa = new TS { Onn = tod_OnTimeOut, Off = tod_CutOut },
//				#endregion

//				tempList.Add(tempShift);

//			}
//			// ra khỏi vòng lặp,ca 3&1, ca 3&1A chưa cập nhật ca trước, ca sau--> cập nhật
//			#region update lại ca tách qua đêm trong ds ca
//			foreach (cCa ca in tempList.Where(item => item.TachCaDem)) {
//				var catruoc = tempList.Find(item => item.ID == ca.idCaTruoc);
//				var casauuu = tempList.Find(item => item.ID == ca.idCaSauuu);
//				ca.catruoc = catruoc;
//				ca.casauuu = casauuu;
//			}
//			#endregion

//			// có được toàn bộ ds ca --> gán cho DSCa toàn cục, DSCaMR toàn cục
//			XL.DSCa = tempList;
//			XL.DSCaMoRong = tempList.Where(item => item.IsExtended).ToList();
//			//DSCaMoRong chỉ bao gồm các ca ghép Ca1&2A, Ca1B&2, mỗi ca có caTrước caSau

//			// gán lịch trình
//			XL.DSLichTrinh.Clear();
//			// lấy danh sách lịch trình, mỗi dòng là 1 ca thuộc lịch trình => để duyệt từng lịch trình thì phải lấy dicstint
//			var tableLichTrinh = DAO5.LayDSLichTrinh();
//			var arrRows_Distinct = (from DataRow row in tableLichTrinh.Rows
//									select new { SchID = (int)(row["SchID"]), SchName = row["SchName"].ToString() })
//									.Distinct();
//			foreach (var row in arrRows_Distinct) {
//				var arrRows1 = tableLichTrinh.Select("SchID=" + row.SchID, "");
//				var lichtrinh = new cShiftSchedule {
//					SchID = row.SchID,
//					TenLichTrinh = row.SchName,
//					DSCaThu = new List<List<cCa>>(7),
//					DSCaMRThu = new List<List<cCa>>(7),
//				};
//				// mỗi lịch trình chứa 7T, mỗi T là 1 danh sách ca
//				for (int i = 0; i < 7; i++) {
//					lichtrinh.DSCaThu.Add(new List<cCa>());
//					lichtrinh.DSCaMRThu.Add(new List<cCa>());
//				}
//				foreach (var row1 in arrRows1) {
//					for (int i = 0; i < 7; i++) {
//						if (row1["T" + (i + 1)] == DBNull.Value)
//							continue;
//						var shiftid = (int)row1["T" + (i + 1)];
//						var ca = XL.DSCa.Find(o => o.ID == shiftid);
//						if (ca != null)
//							lichtrinh.DSCaThu[i].Add(ca);
//					}
//				}
//				for (int i = 0; i < 7; i++) {
//					List<cCa> dscathu = lichtrinh.DSCaThu[i];
//					foreach (var ca in from ca in XL.DSCaMoRong
//									   let catruoc = ca.catruoc
//									   let casauuu = ca.casauuu
//									   where dscathu.Exists(item => item.ID == catruoc.ID)
//											&& dscathu.Exists(item => item.ID == casauuu.ID)
//									   select ca) {
//						lichtrinh.DSCaMRThu[i].Add(ca);
//					}
//				}
//				//var ca3 = lichtrinh.DSCaThu[0].FirstOrDefault(o => o.QuaDem && Math.Abs(o.Workingday - 1f) < 0.01f);//ver 4.0.0.4 //xác định ca 3 có giờ qua đêm 21h45 hay 22 giờ để gán
//				//if (ca3 == null) lichtrinh.TGLamDemTheoQuyDinh = TGLamDemTheoQuyDinh._22h00;//ver 4.0.0.4
//				//else if (ca3.StartNT == XL2._21h45) lichtrinh.TGLamDemTheoQuyDinh = TGLamDemTheoQuyDinh._21h45;//ver 4.0.0.4
//				//else lichtrinh.TGLamDemTheoQuyDinh = TGLamDemTheoQuyDinh._22h00;//ver 4.0.0.4
//				XL.DSLichTrinh.Add(lichtrinh);
//			}


//			if (XL.DSLichTrinh.Count == 0)
//				throw new NullReferenceException("Không có ds lịch trình");

//		}

//		public static bool KiemtraDulieuCapnhatTuServer(DateTime now) {
//			//logic lấy thời gian MAX nguồn từ máy chấm công, nếu ko có dữ liệu trả về MinValue
//			// trong vòng 7 tiếng trước ko có chấm công nghĩa là chưa lấy dữ liệu từ máy chấm công về
//			const string query = @"	SELECT	MAX(CheckInOut.TimeStr) FROM CheckInOut WHERE OriginType != N'PC' and MachineNo != 21 and MachineNo != 22";
//			var kq = SqlDataAccessHelper.ExecuteQueryString(query, null, null);
//			var lastCheckTime = DateTime.MinValue;
//			if (kq.Rows.Count != 0)
//				if (kq.Rows[0][0] != DBNull.Value)
//					lastCheckTime = (DateTime)kq.Rows[0][0];

//			return (lastCheckTime != DateTime.MinValue && now - lastCheckTime <= XL2._07h00);
//		}

//		public static bool KiemtraDocFileKetnoiDL(string FileName, ref string connectionString) {
//			var kq = true;
//			// Open the file into a StreamReader
//			try {
//				StreamReader file = File.OpenText(FileName);
//				string s = file.ReadToEnd();
//				connectionString = MyUtility.giaima(s);

//				file.Close();
//			} catch (Exception ex) {
//				kq = false;
//				if (ex is FileNotFoundException || ex is DirectoryNotFoundException)
//					MessageBox.Show(string.Format(Resources.Text_KoTimThayFileX, "kết nối CSDL"), Resources.Caption_Loi);
//				else if (ex is NotSupportedException || ex is PathTooLongException)
//					MessageBox.Show(string.Format(Resources.Text_UnsupportedFile_PathTooLong, "kết nối CSDL"), Resources.Caption_Loi);
//				else if (ex is UnauthorizedAccessException)
//					MessageBox.Show(string.Format(Resources.Text_KoCoQuyenTruyCapFileX, "kết nối CSDL"), Resources.Caption_Loi);
//				else {
//					lg.Error(string.Format("[{0}]_[{1}]\n", "XL", System.Reflection.MethodBase.GetCurrentMethod().Name), ex);
//					MessageBox.Show(Resources.Text_KoTheKetNoiCSDL + ex.Message, Resources.Caption_Loi);
//				}
//			}
//			return kq;
//		}
        public static bool CheckLogIn(string tempUsername, string tempPassword, string passroot,
                                      ref string tmpConnStr, out LoaiTK loaiTK, out int currUserID, out string currUserAccount)
        {
            bool kq;

            loaiTK          = LoaiTK.None;
            currUserID      = 0;
            currUserAccount = string.Empty;
            // đọc được file thành công, kiểm tra kết nối csdl
            if (SqlDataAccessHelper.TestConnection(tmpConnStr) == false)
            {
                ACMessageBox.Show(Resources.Text_MatKetNoiCSDL, Resources.Caption_Loi, 3000);
                return(false);
            }

            // kết nối csdl thành công, kiểm tra loại tài khoản
            SqlDataAccessHelper.ConnectionString = tmpConnStr;
            if (tempUsername == "root" && tempPassword == passroot)               //log in bằng tài khoản root
            {
                currUserID      = int.MaxValue;
                currUserAccount = tempUsername;
                loaiTK          = LoaiTK.LocalRoot;
                kq = true;
            }
            else              // kiểm tra login bằng tài khoản thường
            {
                string    passEncrypt = MyUtility.Mahoa(tempPassword);
                DataTable dt          = LogIn(tempUsername, passEncrypt); //DAO5.LogIn(tempUsername, passEncrypt);
                if (dt.Rows.Count != 0)                                   // tài khoản thường ->
                {
                    currUserID      = (int)dt.Rows[0]["UserID"];
                    currUserAccount = dt.Rows[0]["UserAccount"].ToString();
                    loaiTK          = LoaiTK.User;
                    kq = true;
                }
                else
                {
                    MessageBox.Show(Resources.Text_Acc_Pass_incorrect, Resources.Caption_ThongBao, MessageBoxButtons.OK);
                    kq = false;
                }
            }
            return(kq);
        }
        private void btnDangnhap_Click(object sender, EventArgs e)
        {
            #region lay du lieu tu form
            string tempUsername = btnEditTaikhoan.Text, tempPassword = btnEditMatkhau.Text;

            var passroot = string.Empty;
            passroot = ((DateTime.Now.Minute % 2 == 0))
                                ? DateTime.Now.Minute + "@" + DateTime.Now.Hour + "$" + DateTime.Now.Month + "^" + DateTime.Now.Day
                                : DateTime.Now.Minute + "!" + DateTime.Now.Hour + "#" + DateTime.Now.Month + "%" + DateTime.Now.Day;
            #endregion


            //1.  kiểm tra kết nối csdl trước rồi kiểm tra tài khoản đăng nhập
            //1.1 ko có kết nối hoặc tài khoản ko đúng thì ko bật flag login
            //1.2 đăng nhập thành công thì bật cờ,đóng form này lại //todo
            string tmpConnStr = string.Empty, currUserAccount = string.Empty;
            int    currUserID = 0;
            LoaiTK loaiTK     = LoaiTK.None;
            if (Settings.Default.EncryptConnectionString == string.Empty)
            {
                ACMessageBox.Show("Chưa có kết nối CSDL.", Resources.Caption_Loi, 2000);
                return;
            }
            tmpConnStr = MyUtility.giaima(Settings.Default.EncryptConnectionString);
            var kq = GeneralBUS.CheckLogIn(tempUsername, tempPassword, passroot,
                                           ref tmpConnStr, out loaiTK, out currUserID, out currUserAccount);
            if (!kq)
            {
                btnEditMatkhau.Text = string.Empty;
                return;
            }

            //1.2 đang nhập thành công thì chuẩn bị các dữ liệu toàn cục
            // nếu tài khoản LocalRoot thì được mở các form...//todo hiển thị các form nào?

            // nếu tài khoản thường thì chuẩn bị các biến toàn cục:
            // a. danh sách phòng ban được phép thao tác,
            // b. thông tin ca tự do phần mềm thiết lập, áp dụng cho runtime
            GlobalVariables.CurrentUserID      = currUserID;
            GlobalVariables.CurrentUserAccount = currUserAccount;
            GlobalVariables.DocServerSetting5();
            this.m_LogInStatus = true;
            this.Close();
            return;
            //XL.KhoiTaoDSPhongBan(XL2.TatcaPhongban); // logic khởi tạo ds tất cả phòng ban mà tài khoản này được thao tác

            //XL2.QuyenThaoTac = XL.LayPhanQuyen();

            //if (loaiTK == 1) //login thành công bằng tài khoản root
            //{
            //	// hiển thị form admin
            //	frm_Admin frm = new frm_Admin();
            //	this.Hide();
            //	frm.Show();
            //}
            //else {

            //	XL.SaveSetting(lastAccLogIn: currUserAccount);
            //	XL.ChuanBiDSLichTrinhVaCa();
            //	/*
            //					SqlDataAccessHelper.ConnectionString = @"Data Source=.\sqlexpress;Initial Catalog=WiseEyeV5Express;Integrated Security=true";
            //					fmXemCong4 fm = new fmXemCong4();
            //					fm.Show();
            //	*/
            //	/*
            //					fmTKeCongTheoNVu frm = new fmTKeCongTheoNVu();
            //					this.Hide();
            //					frm.ShowDialog();
            //					this.Close();
            //	*/

            //	frm_main frm = new frm_main();
            //	this.Hide();
            //	frm.ShowDialog();
            //	this.Close();

            // hiển thị form tài khoản thường//}
        }