//Allows paging, splitting the data up into smaller groups //so you go to the next page to see the data, //like a book, instead of seeing all the data on one long page protected void LoginGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { DAL_Project.DAL dal = new DAL_Project.DAL(@"Data Source=localhost;Initial Catalog=dbExerciseForScott1;Integrated Security=SSPI"); LoginGridView.DataSource = dal.ExecuteProcedure("spLoginSelect"); LoginGridView.PageIndex = e.NewPageIndex; LoginGridView.DataBind(); }
protected void EditEmployeeButton_Click(object sender, EventArgs e) { if (EditEmployee.Text.Length != 0) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString())) { SqlCommand command = new SqlCommand( "UPDATE [Employee] SET [Name] = @EmpName FROM [User], [Employee] WHERE [User].[UserID] = @UserID AND [User].[EmpID] = [Employee].[EmpID]", con); SqlParameter EmpName = new SqlParameter { ParameterName = "@EmpName", Value = EditEmployee.Text }; command.Parameters.Add(EmpName); SqlParameter UserID = new SqlParameter { ParameterName = "@UserID", Value = LoginGridView.SelectedValue }; command.Parameters.Add(UserID); con.Open(); command.ExecuteNonQuery(); LoginGridView.DataBind(); con.Close(); } } }
// (TO-DO) This and AdminLoginEdit need to have a base page for similiar functionality. protected void Page_Load(object sender, EventArgs e) { if (!Page.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } if (!IsPostBack) { if (PreviousPage is DefaultScreen ds) { qcs.EmpID = ds.EmpID; qcs.PermID = ds.PermID; if (qcs.PermID == 1) { LoginGridView.DataBind(); EditLoginActionNoUserPanel.Visible = true; EditLoginActionUserSelectedPanel.Visible = false; CheckForVisibility(); } else { Response.Redirect("~/LoginEditPage.aspx"); } } else { Response.Redirect("~/DefaultScreen.aspx"); } } LoadControlState(qcs); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); Response.Cache.SetNoStore(); }
private void BindData() { DAL_Project.DAL d = new DAL_Project.DAL(@"Data Source=localhost;Initial Catalog=dbExerciseForScott1;Integrated Security=SSPI"); DataSet ds = new DataSet(); LoginGridView.DataSource = d.ExecuteProcedure("spLoginSelect"); LoginGridView.DataBind(); }
protected void EditPassButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString()); SqlCommand sqlCommand = new SqlCommand("UPDATE [Password] SET [Password] = @Password WHERE [UserID] = @UserID", con); sqlCommand.Parameters.AddWithValue("@Password", EditPasswordText1.Text); sqlCommand.Parameters.AddWithValue("@UserID", LoginGridView.SelectedValue); con.Open(); sqlCommand.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); BackToStart(); }
protected void PermEditButton_Click(object sender, EventArgs e) { // Sets selected employee's permission type SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString()); SqlCommand sqlCommand = new SqlCommand("UPDATE [UserPermissions] SET [TypeID] = @Perm WHERE [UserID] = @UserID", con); sqlCommand.Parameters.AddWithValue("@Perm", PermissionsDropDown.SelectedValue); sqlCommand.Parameters.AddWithValue("@UserID", LoginGridView.SelectedValue); con.Open(); sqlCommand.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); BackToStart(); }
protected void AddUserButton_Click(object sender, EventArgs e) { if (Page.IsValid) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString()); SqlCommand sqlCommand = new SqlCommand("CreateNewEmployee", con) { CommandType = CommandType.StoredProcedure }; sqlCommand.Parameters.AddWithValue("@EmpFName", AddEmpFNameText.Text); sqlCommand.Parameters.AddWithValue("@EmpLName", AddEmpLNameText.Text); sqlCommand.Parameters.AddWithValue("@UserName", AddUserText.Text); sqlCommand.Parameters.AddWithValue("@Password", AddPassText1.Text); sqlCommand.Parameters.AddWithValue("@PermissionsType", AddPermDropDown.SelectedValue); con.Open(); sqlCommand.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); BackToStart(); } }
protected void DeleteUserButton_Click(object sender, EventArgs e) { if (DeleteUserText.Text.Count() > 0) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString()); SqlCommand cmd = new SqlCommand("SELECT U.[Name], E.[EmpID] FROM [Employee] E, [User] U WHERE U.[UserID] = @UserID AND U.[EmpID] = E.[EmpID]", con); cmd.Parameters.AddWithValue("@UserID", LoginGridView.SelectedValue); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd); DataTable table = new DataTable(); sqlDataAdapter.Fill(table); con.Open(); cmd.ExecuteNonQuery(); con.Close(); string name = table.Rows[0]["Name"].ToString().Trim(); if (name == DeleteUserText.Text) { int empID = (int)table.Rows[0]["EmpID"]; cmd = new SqlCommand("DeleteEmployee", con) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@EmpID", empID); con.Open(); cmd.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); DeleteUserText.Text = String.Empty; BackToStart(); } else { RequiredName.Text = "User not found."; } } else { RequiredName.Text = "Enter employee name."; } }
protected void EditEmployeeButton_Click(object sender, EventArgs e) { if (EditEmployeeFName.Text.Length != 0 && EditEmployeeLName.Text.Length != 0) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString())) { SqlCommand command = new SqlCommand( "UPDATE [Employee] " + "SET [FName] = @FName, [LName] = @LName " + "FROM [User] U, [Employee] E " + "WHERE U.[UserID] = @UserID AND E.[EmpID] = U.[EmpID]", con); command.Parameters.AddWithValue("@FName", EditEmployeeFName.Text); command.Parameters.AddWithValue("@LName", EditEmployeeLName.Text); command.Parameters.AddWithValue("@UserID", LoginGridView.SelectedValue); con.Open(); command.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); } BackToStart(); } }
protected void AddUserButton_Click(object sender, EventArgs e) { if (Page.IsValid) { if (AddPassText1.Text == AddPassText2.Text) { System.Diagnostics.Debug.WriteLine("Writing " + AddEmpText.Text + " with user name " + AddUserText.Text + " to DB."); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["QuoteDBConnection"].ToString()); SqlCommand sqlCommand = new SqlCommand("CreateNewEmployee", con) { CommandType = CommandType.StoredProcedure }; sqlCommand.Parameters.AddWithValue("@EmpName", AddEmpText.Text); sqlCommand.Parameters.AddWithValue("@UserName", AddUserText.Text); sqlCommand.Parameters.AddWithValue("@Password", AddPassText1.Text); sqlCommand.Parameters.AddWithValue("@PermissionsType", AddPermDropDown.SelectedValue); con.Open(); sqlCommand.ExecuteNonQuery(); con.Close(); LoginGridView.DataBind(); } } }
// (TO-DO) This and AdminLoginEdit need to have a base page for similiar functionality. protected void Page_Load(object sender, EventArgs e) { if (!Page.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } if (!IsPostBack) { // Gets properties from previous page if (PreviousPage is DefaultScreen ds) { qcs.EmpID = ds.EmpID; qcs.PermID = ds.PermID; } else { Response.Redirect("~/DefaultScreen.aspx"); } if (qcs.PermID == 1) { AddPermDropDown.DataSourceID = "AdminPermissionsDataSource"; PermissionsDropDown.DataSourceID = "AdminPermissionsDataSource"; } else if (qcs.PermID == 2) { AddPermDropDown.DataSourceID = "SManagerPermissionsDataSource"; PermissionsDropDown.DataSourceID = "SManagerPermissionsDataSource"; } else if (qcs.PermID == 3) { AddPermDropDown.DataSourceID = "AssistManagerPermissionsDataSource"; PermissionsDropDown.DataSourceID = "AssistManagerPermissionsDataSource"; } else { Response.Redirect("~/DefaultScreen.aspx"); } } // Changes DataSource of Permissions dropdowns to fit PermissionsID passed to the page // Changes the GridView to show employees with lower permission type (higher number) if (qcs.PermID == 1) { LoginGridView.DataSource = AdminLoginViewDataSource; } else if (qcs.PermID == 2) { LoginGridView.DataSource = SManagerLoginViewDataSource; } else if (qcs.PermID == 3) { LoginGridView.DataSource = AssistManagerLoginViewDataSource; } else { Response.Redirect("~/DefaultScreen.aspx"); } LoginGridView.DataBind(); EditLoginActionNoUserPanel.Visible = true; EditLoginActionUserSelectedPanel.Visible = false; LoadControlState(qcs); CheckForVisibility(); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1)); Response.Cache.SetNoStore(); }
public LoginPage() { LoginGridView S = new LoginGridView (); this.Content = S; BackgroundColor = Color.FromHex ("1976D2"); }