/// <summary> /// gvUserCompanies_RowDeleting /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void gvUserCompanies_RowDeleting(object sender, GridViewDeleteEventArgs e) { try { TransactionResult result; // Get the selected row's company id int companyIDToDelete = Convert.ToInt32(gvUserCompanies.DataKeys[e.RowIndex].Value); int userIDToDelete = Convert.ToInt32(txtUserID.Text); // Delete the selected user company CompanyXUsersDL deleteUserCompany = new CompanyXUsersDL(); deleteUserCompany.UserID = userIDToDelete; deleteUserCompany.CompanyID = companyIDToDelete; deleteUserCompany.ScreenMode = ScreenMode.Delete; deleteUserCompany.AddEditOption = 2; // Added on 20/06/2014 result = deleteUserCompany.Commit(); // Display the status of the delete System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script>alert('" + result.Message.ToString() + ".');"); sb.Append("</script>"); ScriptManager.RegisterStartupScript(this.Page, typeof(string), "MyScript", sb.ToString(), false); // If successfully deleted, get the user details if (result.Status == TransactionStatus.Success) { GetUserDetails(Convert.ToInt32(txtUserID.Text), true); tcntAllUserTabs.ActiveTab = tpnlCompanies; } } catch (Exception ex) { ErrorLog.LogErrorMessageToDB("AddEditUser.aspx", "", "gvUserCompanies_RowDeleting", ex.Message.ToString(), new ACEConnection()); } }
/// <summary> /// btnUserCompanyAdd_Click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUserCompanyAdd_Click(object sender, EventArgs e) { try { // Create a new CompanyXUsersDL Object CompanyXUsersDL compUser = new CompanyXUsersDL(); // Set whether Add / Edit if (txtCompanyID.Text != "0") { compUser.AddEditOption = 1; } else { compUser.AddEditOption = 0; } // Assign values to the CompanyXUsersDL Object compUser.CompanyID = Convert.ToInt32(ddlCompany.SelectedValue); compUser.UserID = Convert.ToInt32(txtUserID.Text); compUser.RoleID = Convert.ToInt32(ddlCompanyRole.SelectedValue); if (chkDefault.Checked == true) { compUser.IsDefault = true; } else { compUser.IsDefault = false; } // Add / Edit the User Company TransactionResult result; compUser.ScreenMode = ScreenMode.Add; result = compUser.Commit(); // Display the Status - Whether successfully saved or not System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script>alert('" + result.Message.ToString() + ".');"); sb.Append("</script>"); ScriptManager.RegisterStartupScript(this.Page, typeof(string), "MyScript", sb.ToString(), false); // If successful, get the user details if (result.Status == TransactionStatus.Success) { txtCompanyID.Text = "0"; ddlCompany.ClearSelection(); ddlCompany.Enabled = true; ddlCompanyRole.ClearSelection(); chkDefault.Checked = false; chkDefault.Enabled = true; tcntAllUserTabs.ActiveTab = tpnlCompanies; LoadDropDownLists(); GetUserDetails(Convert.ToInt32(txtUserID.Text.ToString()), true); lblPopupHeading.Text = "Add User Company"; btnUserCompanyAdd.Text = "Save"; } } catch (Exception ex) { ErrorLog.LogErrorMessageToDB("AddEditUser.aspx", "", "btnUserCompanyAdd_Click", ex.Message.ToString(), new ACEConnection()); } }