PageRenderTime 46ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/KSLL_WEB/website/QuanTri/Administration/Login.aspx.cs

http://ki-va-le.googlecode.com/
C# | 139 lines | 103 code | 7 blank | 29 comment | 5 complexity | fa740a0b65da513913a18a8577b5ee91 MD5 | raw file
Possible License(s): LGPL-2.1
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. using TTQT.TTQT_Code;
  13. using TTQT.TTQT_Code.Info;
  14. namespace TTQT.Administration
  15. {
  16. /// <summary>
  17. /// Summary description for Login.
  18. /// </summary>
  19. public partial class Login : System.Web.UI.Page
  20. {
  21. protected void Page_Load(object sender, System.EventArgs e)
  22. {
  23. //Response.Redirect("http://10.53.3.49/qlac/");
  24. //lblLoginStatus.Visible = false;
  25. //string str = txtUserName.ClientID;
  26. //Page.RegisterClientScriptBlock("connecError", "<script language =\"javascript\">\n alert(\""+str+"Không k?t n?i ???c CSDL!\");\n </script>");
  27. //Page.RegisterClientScriptBlock("Focus", "<script language =\"javascript\">\ndocument.getElementById('"+ txtUserName.ClientID+"').focus();</script>");
  28. }
  29. #region Web Form Designer generated code
  30. override protected void OnInit(EventArgs e)
  31. {
  32. //
  33. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  34. //
  35. InitializeComponent();
  36. base.OnInit(e);
  37. }
  38. /// <summary>
  39. /// Required method for Designer support - do not modify
  40. /// the contents of this method with the code editor.
  41. /// </summary>
  42. private void InitializeComponent()
  43. {
  44. }
  45. #endregion
  46. protected void btnLogin_Click(object sender, System.EventArgs e)
  47. {
  48. int pageId = TTQTCommon.ToInt32(Request.QueryString["PageId"], 0);
  49. int userId =
  50. DataAccessObject.instance().checkLogin(this.txtUserName.Text.Trim(),
  51. TTQTCommon.MD5Encrypt(this.txtPassword.Text.Trim()));
  52. if (userId == -100)
  53. {
  54. //Page.RegisterClientScriptBlock("connecError", "<script language =\"javascript\">\n alert(\"Không k?t n?i ???c CSDL!\");\n </script>");
  55. Response.Redirect("../LostConnection.html");
  56. return;
  57. }
  58. if(userId==-101)
  59. {
  60. MyWebUtils.MyWebUtil.alert(this.Page,"User nŕy ?ang b? khóa. B?n vui lňng lięn h? admin chi nhánh ?? m? khóa");
  61. return;
  62. }
  63. if (userId > 0)
  64. {
  65. /***** Kiem tra chay dau ngay *****/
  66. try
  67. {
  68. int result = -1;
  69. SqlConnection conn = new SqlConnection(TTQTCommon.DBConnectionString);
  70. SqlCommand comm = new SqlCommand("Flag_ChayDauNgay_Check", conn);
  71. comm.CommandType = CommandType.StoredProcedure;
  72. try
  73. {
  74. conn.Open();
  75. result = Convert.ToInt32(comm.ExecuteScalar());
  76. }
  77. catch (Exception ex)
  78. {
  79. // Write log method here
  80. }
  81. if (result <= 0) // Ch?a ch?y ??u ngŕy thě ch?y ??u ngŕy
  82. {
  83. comm.CommandText = "_XuLiDauNgay";
  84. comm.Parameters.Clear();
  85. comm.Parameters.AddWithValue("@Ngay",
  86. TTQTCommon.convertDateString(DateTime.Now.ToString("dd/MM/yyyy")));
  87. comm.ExecuteScalar();
  88. conn.Close();
  89. comm.Dispose();
  90. }
  91. }
  92. catch (Exception exxxx) { }
  93. /***** Ket thuc Kiem tra chay dau ngay *****/
  94. Session["group_names"] = DataAccessObject.instance().getAllGroupNamesByUserId(userId);
  95. //TTQTCommon.LoginUser(this.txtUserName.Text.Trim(),this.chkRememberPwd.Checked);
  96. // Add Information to Session
  97. // if(Session["UserId"]==null)
  98. // Session.Add("UserId",userId.ToString());
  99. // else
  100. UserInfo userInfo = DataAccessObject.instance().getUser(userId);
  101. Session["UserInfo"] = userInfo;
  102. DataAccessObject.instance().updateLastLogin(userInfo.userName);
  103. Session["Brn_Code"] = userInfo.Brn_Code;
  104. Session["UserId"] = userId.ToString();
  105. // if(Session["UserName"] ==null)
  106. // Session.Add("UserName",this.txtUserName.Text.Trim());
  107. // else
  108. Session["UserName"] = this.txtUserName.Text.Trim().ToLower();
  109. Session["UserFullName"] = userInfo.fullName + " ( " + userInfo.userName + " )";
  110. Session["IsSuperAdmin"] = userInfo.isSuperAdmin;
  111. Session["SIBSID"] = userInfo.SIBSID;
  112. Session["GroupId"] = userInfo.groupId;
  113. Session["TenChiNhanh"] = userInfo.TenChiNhanh;
  114. // Ghi log
  115. LogInfo logInfo = new LogInfo();
  116. logInfo.Brn_Code = userInfo.Brn_Code;
  117. logInfo.Content = "??ng nh?p";
  118. logInfo.Ip = Request.UserHostAddress;
  119. logInfo.UserName = txtUserName.Text;
  120. logInfo.Type = TTQTCommon.log_DangNhap;
  121. DataAccessObject.instance().addLog(logInfo);
  122. Response.Redirect("../Default.aspx?PageId="+pageId);
  123. // add User information into Context
  124. }
  125. else
  126. {
  127. lblLoginStatus.Text = "Sai tęn ho?c m?t kh?u!";
  128. return;
  129. }
  130. }
  131. }
  132. }