Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Line 159: l_oSQLCommand.Connection = l_oConnection;
- Line 160: l_oConnection.Open();
- Line 161: l_oResult = l_oSQLCommand.ExecuteScalar();
- Line 162: if (l_oConnection.State == ConnectionState.Open) l_oConnection.Close();
- Line 163: }
- protected void lbtnSave_Click(object sender, EventArgs e)
- {
- divError.Visible = true;
- if (AdminSecurity.PagePerm((iAdminID > 0)))
- {
- if (FormValidation())
- {
- AdminSecurity AS = new AdminSecurity();
- AS.UserName = txtUserName.Text;
- AS.Password = txtPassword.Text;
- AS.IsAdmin = ddlIsAdmin.SelectedValue == "N" ? false : true;
- AS.IsActive = ddlIsActive.SelectedValue == "N" ? false : true;
- AS.AdminID = iAdminID;
- AS.EmployeeID = Convert.ToInt32(ddlEmployee.SelectedValue);
- if (AS.SaveUser() != "")
- {
- AS.RoleID = Convert.ToInt32(ddlRoles.SelectedValue);
- AS.Status = 'Y';
- AS.AdminID = AS.AdminID;
- DataTable dt = AS.SelectModules();
- foreach (DataRow dtrow in dt.Rows)
- {
- AS.ModuleID = Convert.ToInt32(dtrow["ModuleID"]);
- AS.Permission = 'F';
- if (AS.SaveUserModule())
- {
- divError.InnerHtml = "<h5>Success !</h5><ul><li>Users saved successfully</li></ul>";
- divError.Attributes.Add("class", "alert alert-success");
- }
- else
- {
- divError.InnerHtml = "<h5>Error !</h5><ul><li>Users Saved failed. Try again!</li></ul>";
- }
- }
- Response.Redirect("ViewAdmin.aspx");
- divError.InnerHtml = "<h5>Success !</h5><ul><li>Users saved successfully</li></ul>";
- divError.Attributes.Add("class", "alert alert-success");
- }
- else
- divError.InnerHtml = "<h5>Error !</h5><ul><li>Users submited failed. Try again!</li></ul>";
- }
- }
- else
- {
- divError.InnerHtml = "<h5>Warning !</h5><ul><li>Access Denied!</li></ul>";
- divError.Attributes.Add("class", "alert alert-warning");
- }
- }
- #region "Save User"
- public string SaveUser()
- {
- string l_sStatus = string.Empty;
- SQLDataAccessLayer l_oDAL = new SQLDataAccessLayer();
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@AdminID", SqlDbType.TinyInt, 0, ParameterDirection.Input, this.AdminID);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@EmployeeID", SqlDbType.TinyInt, 10, ParameterDirection.Input, this.EmployeeID);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@UserName", SqlDbType.VarChar, 30, ParameterDirection.Input, this.UserName);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@IsAdmin", SqlDbType.Bit, 0, ParameterDirection.Input, this.IsAdmin);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, this.IsActive);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@Password", SqlDbType.VarChar, 15, ParameterDirection.Input, this.Password);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@CreatedBy", SqlDbType.VarChar, 50, ParameterDirection.Input, this.CreatedBy);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@CreatedDate", SqlDbType.VarChar, 50, ParameterDirection.Input, this.CreatedDate);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@ModifiedBy", SqlDbType.VarChar, 50, ParameterDirection.Input, this.ModifiedBy);
- l_oDAL.AddParamToSQLCmd(l_oDAL.SQLCommand, "@ModifiedDate", SqlDbType.VarChar, 50, ParameterDirection.Input, this.ModifiedDate);
- if (!CheckDuplicateUser(l_oDAL))
- {
- if (!checkEmployee(this.EmployeeID, l_oDAL))
- {
- if (this.AdminID == 0)
- {
- l_sQuery = "INSERT INTO AdminLogin (EmployeeID,UserName, Password, IsAdmin, IsActive,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate) VALUES (@EmployeeID,@UserName, @Password, @IsAdmin, @IsActive,@CreatedBy,@CreatedDate,@ModifiedBy,@ModifiedDate); "
- + "SELECT @@IDENTITY;";
- l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
- AdminID = Convert.ToInt16(l_oDAL.ExecuteScalarCmd(l_oDAL.SQLCommand));
- l_oDAL = null;
- if (AdminID == 0)
- l_sStatus = "F";
- else
- l_sStatus = "S";
- }
- }
- else
- {
- 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";
- l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
- bool l_bStatus = Convert.ToBoolean(l_oDAL.ExecuteNonQueryCmd(l_oDAL.SQLCommand));
- l_oDAL = null;
- if (l_bStatus)
- l_sStatus = "S";
- else
- l_sStatus = "F";
- }
- }
- else
- l_sStatus = "D";
- return l_sStatus;
- }
- #endregion
- #region "Check Duplicate User"
- public bool CheckDuplicateUser(SQLDataAccessLayer l_oDAL)
- {
- l_sQuery = "SELECT COUNT(AdminID) FROM AdminLogin WHERE AdminID<>@AdminID AND UserName=@UserName";
- l_oDAL.SetCommandType(l_oDAL.SQLCommand, CommandType.Text, l_sQuery);
- bool l_bStatus = Convert.ToBoolean(l_oDAL.ExecuteScalarCmd(l_oDAL.SQLCommand));
- l_oDAL = null;
- return l_bStatus;
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement