private void btnSubmit_Click(Object sender, EventArgs e) { string mess = ""; if (txtUser.Text.Trim() == "") { mess += "- กรุณาป้อน Username<br/>"; } if (txtPass.Text.Trim() == "") { mess += "- กรุณาป้อน Password<br/>"; } if (mess == "") { string sql = "SELECT * FROM tbl_emp_user join tbl_privilege on privilege_id = emp_user_privilege WHERE emp_user_name ='" + txtUser.Text.Trim() + "' AND emp_user_pass = '******'"; MySqlDataReader rs = dBScript.selectSQL(sql); if (rs.Read()) { if (!rs.IsDBNull(0)) { //if (rs.GetString("emp_status_login") != "1") //{ // Storee Session Session.Add("User", txtUser.Text); Session.Add("UserName", rs.GetString("emp_name")); Session.Add("UserPrivilegeId", rs.GetString("privilege_id")); Session.Add("UserPrivilege", rs.GetString("privilege_name")); if (rs.GetString("privilege_id") == "5") { Session.Add("emp_login_id", rs.GetString("emp_user_id")); } else { Session.Add("emp_login_id", null); } Session.Timeout = 600; // now Storing Cookies & config. HttpCookie newCookie = new HttpCookie("HRSLogin"); newCookie["User"] = txtUser.Text; newCookie["UserName"] = rs.GetString("emp_name"); newCookie["UserPrivilegeId"] = rs.GetString("privilege_id"); newCookie["UserPrivilege"] = rs.GetString("privilege_name"); if (rs.GetString("privilege_id") == "5") { newCookie["emp_login_id"] = rs.GetString("emp_user_id"); } else { newCookie["emp_login_id"] = null; } newCookie.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(newCookie); //Page.ClientScript.RegisterStartupScript(Page.GetType(), "Message Box", "<script language = 'javascript'>alert('dd')</script>"); dBScript.userLoginUpdate(txtUser.Text); Response.Redirect("/"); /*} * else * { * mess += "- ***ไม่อนุญาติให้มีการเข้าใช้งานด้วยรหัสเดียวกันซ้ำ"; * }*/ } else { mess += "- Username หรือ Password ไม่ถูกต้อง"; } } else { mess += "- Username หรือ Password ไม่ถูกต้อง"; } } if (mess != "") { MsgBox(mess); } else { msgBox.Text = ""; } }