Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. Line 159: l_oSQLCommand.Connection = l_oConnection;
  2. Line 160: l_oConnection.Open();
  3. Line 161: l_oResult = l_oSQLCommand.ExecuteScalar();
  4. Line 162: if (l_oConnection.State == ConnectionState.Open) l_oConnection.Close();
  5. Line 163: }
  6.  
  7. protected void lbtnSave_Click(object sender, EventArgs e)
  8. {
  9. divError.Visible = true;
  10. if (AdminSecurity.PagePerm((iAdminID > 0)))
  11. {
  12. if (FormValidation())
  13. {
  14. AdminSecurity AS = new AdminSecurity();
  15. AS.UserName = txtUserName.Text;
  16. AS.Password = txtPassword.Text;
  17. AS.IsAdmin = ddlIsAdmin.SelectedValue == "N" ? false : true;
  18. AS.IsActive = ddlIsActive.SelectedValue == "N" ? false : true;
  19. AS.AdminID = iAdminID;
  20. AS.EmployeeID = Convert.ToInt32(ddlEmployee.SelectedValue);
  21. if (AS.SaveUser() != "")
  22. {
  23. AS.RoleID = Convert.ToInt32(ddlRoles.SelectedValue);
  24. AS.Status = 'Y';
  25. AS.AdminID = AS.AdminID;
  26. DataTable dt = AS.SelectModules();
  27. foreach (DataRow dtrow in dt.Rows)
  28. {
  29. AS.ModuleID = Convert.ToInt32(dtrow["ModuleID"]);
  30. AS.Permission = 'F';
  31. if (AS.SaveUserModule())
  32. {
  33. divError.InnerHtml = "<h5>Success !</h5><ul><li>Users saved successfully</li></ul>";
  34. divError.Attributes.Add("class", "alert alert-success");
  35. }
  36. else
  37. {
  38. divError.InnerHtml = "<h5>Error !</h5><ul><li>Users Saved failed. Try again!</li></ul>";
  39. }
  40.  
  41. }
  42. Response.Redirect("ViewAdmin.aspx");
  43. divError.InnerHtml = "<h5>Success !</h5><ul><li>Users saved successfully</li></ul>";
  44. divError.Attributes.Add("class", "alert alert-success");
  45. }
  46. else
  47. divError.InnerHtml = "<h5>Error !</h5><ul><li>Users submited failed. Try again!</li></ul>";
  48. }
  49. }
  50. else
  51. {
  52. divError.InnerHtml = "<h5>Warning !</h5><ul><li>Access Denied!</li></ul>";
  53. divError.Attributes.Add("class", "alert alert-warning");
  54. }
  55. }
  56.  
  57. #region "Save User"
  58. public string SaveUser()
  59. {
  60. string l_sStatus = string.Empty;
  61. SQLDataAccessLayer l_oDAL = new SQLDataAccessLayer();
  62. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@AdminID", SqlDbType.TinyInt, 0, ParameterDirection.Input, this.AdminID);
  63. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@EmployeeID", SqlDbType.TinyInt, 10, ParameterDirection.Input, this.EmployeeID);
  64. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@UserName", SqlDbType.VarChar, 30, ParameterDirection.Input, this.UserName);
  65. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@IsAdmin", SqlDbType.Bit, 0, ParameterDirection.Input, this.IsAdmin);
  66. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, this.IsActive);
  67. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@Password", SqlDbType.VarChar, 15, ParameterDirection.Input, this.Password);
  68. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@CreatedBy", SqlDbType.VarChar, 50, ParameterDirection.Input, this.CreatedBy);
  69. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@CreatedDate", SqlDbType.VarChar, 50, ParameterDirection.Input, this.CreatedDate);
  70. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@ModifiedBy", SqlDbType.VarChar, 50, ParameterDirection.Input, this.ModifiedBy);
  71. l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@ModifiedDate", SqlDbType.VarChar, 50, ParameterDirection.Input, this.ModifiedDate);
  72. if (!CheckDuplicateUser(l_oDAL))
  73. {
  74.  
  75. if (!checkEmployee(this.EmployeeID, l_oDAL))
  76. {
  77.  
  78. if (this.AdminID == 0)
  79. {
  80. l_sQuery = "INSERT INTO AdminLogin (EmployeeID,UserName, Password, IsAdmin, IsActive,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate) VALUES (@EmployeeID,@UserName, @Password, @IsAdmin, @IsActive,@CreatedBy,@CreatedDate,@ModifiedBy,@ModifiedDate); "
  81. + "SELECT @@IDENTITY;";
  82. l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
  83. AdminID = Convert.ToInt16(l_oDAL.ExecuteScalarCmd(l_oDAL.SQLCommand));
  84.  
  85. l_oDAL = null;
  86. if (AdminID == 0)
  87. l_sStatus = "F";
  88. else
  89. l_sStatus = "S";
  90. }
  91. }
  92. else
  93. {
  94. l_sQuery = "UPDATE AdminLogin SET EmployeeID=@EmployeeID,UserName=@UserName,IsAdmin=@IsAdmin,IsActive=@IsActive,CreatedBy=@CreatedBy,CreatedDate=@CreatedDate,ModifiedBy=@ModifiedBy,ModifiedDate=@ModifiedDate WHERE EmployeeID=@EmployeeID;DELETE FROM Ins_UserModules WHERE AdminID=@AdminID";
  95. l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
  96. bool l_bStatus = Convert.ToBoolean(l_oDAL.ExecuteNonQueryCmd(l_oDAL.SQLCommand));
  97. l_oDAL = null;
  98. if (l_bStatus)
  99. l_sStatus = "S";
  100. else
  101. l_sStatus = "F";
  102. }
  103. }
  104. else
  105. l_sStatus = "D";
  106.  
  107. return l_sStatus;
  108. }
  109. #endregion
  110.  
  111. #region "Check Duplicate User"
  112. public bool CheckDuplicateUser(SQLDataAccessLayer l_oDAL)
  113. {
  114. l_sQuery = "SELECT COUNT(AdminID) FROM AdminLogin WHERE AdminID<>@AdminID AND UserName=@UserName";
  115. l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
  116. bool l_bStatus = Convert.ToBoolean(l_oDAL.ExecuteScalarCmd(l_oDAL.SQLCommand));
  117. l_oDAL = null;
  118. return l_bStatus;
  119. }
  120. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement