Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 32.97 KB | None | 0 0
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3. Imports Datex.Common.Corporate.Users
  4. Imports ClientLibrary.Web.UI
  5. Imports ClientLibrary.Properties
  6. Imports System.Collections.Generic
  7. Imports ClientLibrary
  8. Imports ClientLibrary.Properties.RM
  9. Imports Datex.Common.Corporate.Users.Roles
  10. Imports Telerik.Web.UI
  11.  
  12. Partial Class e_UserRole
  13.     Inherits ClientPageBS
  14.  
  15. #Region " Web Form Designer Generated Code "
  16.  
  17.     'This call is required by the Web Form Designer.
  18.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  19.  
  20.     End Sub
  21.  
  22.  
  23.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  24.         'CODEGEN: This method call is required by the Web Form Designer
  25.         'Do not modify it using the code editor.
  26.         InitializeComponent()
  27.     End Sub
  28.  
  29. #End Region
  30.  
  31. #Region " Value Storing Properties "
  32.  
  33.     Protected Property UserRoleID() As Int16
  34.         Get
  35.             Return CInt(Me.ViewState("userroleid"))
  36.         End Get
  37.         Set(ByVal Value As Int16)
  38.             Me.ViewState("userroleid") = Value
  39.         End Set
  40.     End Property
  41.  
  42.     Protected Property UserID() As Int16
  43.         Get
  44.             Return CInt(Me.ViewState("userid"))
  45.         End Get
  46.         Set(ByVal Value As Int16)
  47.             Me.ViewState("userid") = Value
  48.         End Set
  49.     End Property
  50.  
  51.     Protected Property RoleID() As Integer
  52.         Get
  53.             Return Me.ViewState("roleid")
  54.         End Get
  55.         Set(ByVal value As Integer)
  56.             Me.ViewState("roleid") = value
  57.         End Set
  58.     End Property
  59.  
  60.     Protected Const m_Action As String = "a"
  61.     Protected Property Action() As String
  62.         Get
  63.             Dim state As String = CStr(Me.ViewState("action"))
  64.  
  65.             If state = "" Then
  66.                 Return m_Action
  67.             Else
  68.                 Return state
  69.             End If
  70.         End Get
  71.         Set(ByVal Value As String)
  72.             Me.ViewState("action") = Value
  73.         End Set
  74.     End Property
  75.  
  76.     'BASE-2869
  77.     Protected Property DoesCommercialManagement As Boolean
  78.         Get
  79.             Return Me.ViewState("DoesCommercialManagement")
  80.         End Get
  81.         Set(ByVal value As Boolean)
  82.             Me.ViewState("DoesCommercialManagement") = value
  83.         End Set
  84.     End Property
  85.  
  86.     Protected Property DoesResidentialManagement As Boolean
  87.         Get
  88.             Return Me.ViewState("DoesResidentialManagement")
  89.         End Get
  90.         Set(ByVal value As Boolean)
  91.             Me.ViewState("DoesResidentialManagement") = value
  92.         End Set
  93.     End Property
  94.  
  95.     Dim dynamicDict As New Dictionary(Of String, String)
  96. #End Region
  97.  
  98.     Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
  99.         If Not Page.IsPostBack Then
  100.             'BASE-2869
  101.             DoesCommercialManagement = False
  102.             Boolean.TryParse(ConfigurationManager.AppSettings("DoesCommercialManagement"), DoesCommercialManagement)
  103.  
  104.             DoesResidentialManagement = False
  105.             Boolean.TryParse(ConfigurationManager.AppSettings("DoesResidentialManagement"), DoesResidentialManagement)
  106.  
  107.             If DoesCommercialManagement Then
  108.                 FillBuildings()
  109.             End If
  110.  
  111.             If DoesResidentialManagement Then
  112.                 PopulateApartmentSelect()
  113.             End If
  114.  
  115.             FillRoles()
  116.             FillUsers()
  117.             FillEntities()
  118.  
  119.             'There should be a userid that is available to us
  120.             UserID = Request.QueryString("userid")
  121.             UserRoleID = Request.QueryString("userroleid")
  122.             RoleID = Request.QueryString("roleid")
  123.  
  124.             'Go by action
  125.             If UserRoleID = 0 Then
  126.                 'If UserRoleID = 0 AND UserID = 0, we have an 'ADD USER TO ROLE' case
  127.                 If UserID = 0 Then
  128.                     lstUsers.Enabled = True
  129.                     lstRole.Enabled = False
  130.                     lstRole.SelectedValue = RoleID
  131.                 Else 'If UserRoleID = 0 but a User exists, we have a 'ADD ROLE TO USER' case
  132.                     lstUsers.Items.FindByValue(UserID).Selected = True
  133.                     lstRole.Enabled = True
  134.                     lstUsers.Enabled = False
  135.                 End If
  136.  
  137.                 'Add a please select to the roles
  138.                 lstRole.Items.Insert(0, New ListItem("Please Select", "-1"))
  139.  
  140.                 'Hide the buildings by default
  141.                 pnlCommercialBuildings.Visible = False
  142.                 pnlCommercialDynamic.Visible = False
  143.  
  144.                 pnlResidentialDynamic.Visible = False
  145.                 pnlResidentialSelect.Visible = False
  146.  
  147.                 ViewState("header") = "Add Role"
  148.             Else 'The UserRoleID exists
  149.                 'Grab the user role id from the querystring
  150.                 UserRoleID = CInt(Request.QueryString("userroleid"))
  151.                 'Grab the User Role
  152.                 Dim r As New UserRole(UserRoleID)
  153.  
  154.                 'Select their role
  155.                 'Try
  156.                 lstRole.Items.FindByValue(r.RoleID).Selected = True
  157.                 lstUsers.Items.FindByValue(r.UserID).Selected = True
  158.                 lstRole.Enabled = False
  159.                 lstUsers.Enabled = False
  160.                 'Catch
  161.                 'We couldn't find it, so add a please select
  162.                 'lstRole.Items.Insert(0, New ListItem("Please Select", "-1"))
  163.  
  164.                 'lstRole.Enabled = True
  165.                 'End Try
  166.  
  167.                 'Check for the is main
  168.                 If r.IsMain Then
  169.                     chkIsMain.Checked = True
  170.                 Else
  171.                     chkIsMain.Checked = False
  172.                 End If
  173.  
  174.                 If DoesCommercialManagement Then
  175.                     'Check to see if the role uses buildings
  176.                     If r.Role.BldgAccess = 1 Then 'selected
  177.                         lblRole.Text = " Selected Buildings <br/> To change, go to User Settings/Manage Roles"
  178.                         pnlCommercialBuildings.Visible = True
  179.                         pnlCommercialDynamic.Visible = False
  180.                         'Grab the buildings they've previously selected
  181.                         'Dim mRBC As New RoleBuildingCollection(r.UserRoleID)
  182.  
  183.                         'For Each b As RoleBuilding In mRBC
  184.                         '    Try
  185.                         '        lstPropertySource.Transfer(lstPropertySource.FindItemByValue(Trim(b.BldgID)), lstPropertySource, lstPropertyDestination)
  186.                         '    Catch : End Try
  187.                         'Next
  188.  
  189.                         'Base-3853 Load Select2 for buildings
  190.                         Page.ClientScript.RegisterStartupScript(
  191.                          Me.GetType(),
  192.                          "checkPostback",
  193.                          "loadBuildingsForUser('" & r.UserRoleID & "')", True)
  194.  
  195.                     ElseIf r.Role.BldgAccess = 2 Then 'dynamic
  196.                         pnlCommercialDynamic.Visible = True
  197.                         pnlCommercialBuildings.Visible = False
  198.                         Dim mRole As New Role(lstRole.SelectedValue)
  199.  
  200.                         Select Case r.Role.DynamicRole
  201.                             Case "LEASING AGENT"
  202.                                 lblKeyValue.Text = "Please select a Leasing Agent"
  203.                             Case "MANAGER"
  204.                                 lblKeyValue.Text = "Please select a Property Manager"
  205.                             Case "PROP ACCT."
  206.                                 lblKeyValue.Text = "Please select a Property Accountant"
  207.                             Case "REGION"
  208.                                 lblKeyValue.Text = "Please select a Region"
  209.                             Case "ASSET MANAGER"
  210.                                 lblKeyValue.Text = "Please select an Asset Manager"
  211.                         End Select
  212.  
  213.                         lblRole.Text = " Dynamic Buildings(" & mRole.DynamicRole & ") <br/> To change, go to User Settings/Manage Roles"
  214.  
  215.                         ViewState("dynamicrole") = mRole.DynamicRole
  216.  
  217.                         'BASE-7253
  218.                         dynamicDict.Add("DynamicRole", mRole.DynamicRole)
  219.                         dynamicDict.Add("Dropdown", "ddlDynamic")
  220.  
  221.                         BindKeyNames()
  222.                         ddlDynamic.Items.Insert(0, New ListItem("Select One", 0))
  223.  
  224.                         Page.ClientScript.RegisterStartupScript(
  225.                         Me.GetType(),
  226.                         "checkPostback",
  227.                         "loadDynamicKeynameRoles('" & mRole.DynamicRole & "'" & ",'" & Me.UserID & "'" & ",'" & r.RoleID & "'" & ")", True)
  228.  
  229.                         Try
  230.                             ddlDynamic.SelectedValue = r.KeyValue
  231.                             dynamicDict.Add("SelectedValue", r.KeyValue)
  232.                         Catch ex As Exception
  233.                         End Try
  234.                     ElseIf r.Role.BldgAccess = 4 Then '
  235.                         lblRole.Text = " Selected Entities <br/> To change, go to User Settings/Manage Roles"
  236.                         pnlEntities.Visible = True
  237.                         pnlCommercialBuildings.Visible = False
  238.                         pnlCommercialDynamic.Visible = False
  239.  
  240.                         Page.ClientScript.RegisterStartupScript(
  241.                           Me.GetType(),
  242.                           "checkPostback",
  243.                           "loadEntitiesForUser('" & r.UserRoleID & "')", True)
  244.  
  245.                     Else
  246.                         lblRole.Text = "This role has access to all buildings. <br /> To change, go to Administration > User Administration > Manage Roles"
  247.                         pnlCommercialDynamic.Visible = False
  248.                         pnlCommercialBuildings.Visible = False
  249.                     End If
  250.                 End If
  251.  
  252.                 If DoesResidentialManagement Then
  253.                     'Check to see if the role uses Apartments
  254.                     If r.Role.ApartmentAccess = 1 Then 'selected
  255.                         lblRole.Text = " Selected Apartments <br/> To change, go to User Settings/Manage Roles"
  256.                         pnlResidentialSelect.Visible = True
  257.                         pnlResidentialDynamic.Visible = False
  258.  
  259.                         'Base-3853 Load Select2 for apartments
  260.                         Page.ClientScript.RegisterStartupScript(
  261.                          Me.GetType(),
  262.                          "checkPostback",
  263.                          "loadApartmentsForUser('" & r.UserRoleID & "')", True)
  264.  
  265.                     ElseIf r.Role.ApartmentAccess = 2 Then 'dynamic
  266.                         pnlResidentialDynamic.Visible = True
  267.                         pnlResidentialSelect.Visible = False
  268.                         Dim role As New Role(lstRole.SelectedValue)
  269.  
  270.                         Select Case r.Role.DynamicRole
  271.                             Case "RM MANAGER"
  272.                                 lblResidentialKeyValue.Text = "Please select a Residential Manager:"
  273.                         End Select
  274.  
  275.                         lblRole.Text = " Dynamic Apartments(" & role.DynamicRole & ") <br/> To change, go to User Settings/Manage Roles"
  276.  
  277.                         ViewState("dynamicrole") = role.DynamicRole
  278.  
  279.                         'BASE-7253
  280.                         dynamicDict.Add("DynamicRole", role.DynamicRole)
  281.                         dynamicDict.Add("Dropdown", "ddlResidentialDynamic")
  282.                         BindKeyNames()
  283.  
  284.                         ddlResidentialDynamic.Items.Insert(0, New ListItem("Select One", 0))
  285.  
  286.                         Try
  287.                             ddlResidentialDynamic.SelectedValue = r.KeyValue
  288.                             dynamicDict.Add("SelectedValue", r.KeyValue)
  289.                         Catch ex As Exception
  290.                         End Try
  291.  
  292.                         Page.ClientScript.RegisterStartupScript(
  293.                            Me.GetType(),
  294.                            "checkPostback",
  295.                           "loadDynamicKeynameRoles('" & role.DynamicRole & "'" & ",'" & Me.UserID & "'" & ",'" & r.RoleID & "'" & ")", True)
  296.                     ElseIf r.Role.ApartmentAccess = 4 Then '
  297.                         lblRole.Text = " Selected Entities <br/> To change, go to User Settings/Manage Roles"
  298.                         pnlEntities.Visible = True
  299.                         pnlResidentialSelect.Visible = False
  300.                         pnlResidentialDynamic.Visible = False
  301.  
  302.                         Page.ClientScript.RegisterStartupScript(
  303.                       Me.GetType(),
  304.                       "checkPostback",
  305.                       "loadEntitiesForUser('" & r.UserRoleID & "')", True)
  306.                     Else
  307.  
  308.                         'BASE-7252
  309.                         'Since this is page is handling both cases of Commercial / Residential
  310.                         'We need to check if there is a BldgAccess Role currently
  311.                         'Otherwise, in this else case it will change the lblRole.Text when it shouldn't.
  312.                         If String.IsNullOrEmpty(r.Role.BldgAccess) Then
  313.                             lblRole.Text = "This role has access to all properties. <br /> To change, go to Administration > User Administration > Manage Roles"
  314.                         End If
  315.  
  316.                         pnlResidentialDynamic.Visible = False
  317.                         pnlResidentialSelect.Visible = False
  318.                     End If
  319.                 End If
  320.  
  321.                 ViewState("header") = "Edit Role"
  322.             End If
  323.  
  324.             lblRole.Font.Bold = True
  325.             lblRole.Font.Italic = True
  326.  
  327.             'Set the action of the cancel button
  328.             cmdCancel.Attributes.Add("OnClick", "Javascript: self.close();")
  329.         End If
  330.  
  331.         'Setup the base page
  332.         MyBase.Title = ConfigurationManager.AppSettings("CompanyName") & " - " & ViewState("header")
  333.         MyBase.PageHeaderText = ViewState("header")
  334.         MyBase.IsDialog = True
  335.     End Sub
  336.  
  337.     Private Sub FillEntities()
  338.         Dim dt As New DataTable
  339.         Using dv = Entity.GetEntities()
  340.             dt = dv.ToTable
  341.             dt.Columns.Add("ENTITYNAMEWITHID", GetType(System.String), "ENTITYID + ' - ' + ENTITYNAME")
  342.             lstEntitiesSource.DataSource = dt
  343.             lstEntitiesSource.DataTextField = "ENTITYNAMEWITHID"
  344.             lstEntitiesSource.DataValueField = "EntityId"
  345.             lstEntitiesSource.DataBind()
  346.         End Using
  347.     End Sub
  348.  
  349.     Private Sub FillRoles()
  350.         Dim mRC As List(Of Role) = Role.GetRoles(True)
  351.  
  352.         Me.lstRole.DataSource = mRC
  353.         Me.lstRole.DataTextField = "RoleName"
  354.         Me.lstRole.DataValueField = "RoleID"
  355.         Me.lstRole.DataBind()
  356.     End Sub
  357.  
  358.     Private Sub FillBuildings()
  359.         Dim buildings As List(Of Building) = Building.GetBuildingNames()
  360.  
  361.         Me.lstPropertySource.DataSource = buildings
  362.         Me.lstPropertySource.DataTextField = "BuildingName"
  363.         Me.lstPropertySource.DataValueField = "BuildingID"
  364.         Me.lstPropertySource.DataBind()
  365.     End Sub
  366.  
  367.     Private Sub PopulateApartmentSelect()
  368.         Dim apartments As List(Of Apartment) = Apartment.GetApartments(True)
  369.  
  370.         rlbApartmentSource.DataSource = apartments
  371.         rlbApartmentSource.DataTextField = "PropName"
  372.         rlbApartmentSource.DataValueField = "RMPropID"
  373.         rlbApartmentSource.DataBind()
  374.     End Sub
  375.  
  376.     Private Sub BindKeyNames()
  377.         If DoesCommercialManagement Then
  378.             Dim rss As SqlDataReader = Datex.Common.Corporate.Users.Role.getKeyNameByRolenames(Me.ViewState("dynamicrole"))
  379.  
  380.             Me.ddlDynamic.DataSource = rss
  381.             Me.ddlDynamic.DataTextField = "Description"
  382.             Me.ddlDynamic.DataValueField = "Keyname"
  383.             Me.ddlDynamic.DataBind()
  384.  
  385.             rss.Close()
  386.         End If
  387.  
  388.         If DoesResidentialManagement Then
  389.             Dim residentialDynamicRoles = Role.GetResidentialKeyNamesByRoleName(CType(ViewState("dynamicrole"), String))
  390.  
  391.             ddlResidentialDynamic.DataSource = residentialDynamicRoles
  392.             ddlResidentialDynamic.DataTextField = "Description"
  393.             ddlResidentialDynamic.DataValueField = "Keyname"
  394.             ddlResidentialDynamic.DataBind()
  395.         End If
  396.  
  397.         Dim jsonString As String = Newtonsoft.Json.JsonConvert.SerializeObject(dynamicDict)
  398.  
  399.         hdnDynamicRole.Value = jsonString
  400.     End Sub
  401.  
  402.     Private Sub FillUsers()
  403.         Dim users As List(Of DatexUser) = Datex.Common.Corporate.Users.DatexUser.GetUsers(1)
  404.  
  405.         Me.lstUsers.DataSource = users
  406.         Me.lstUsers.DataTextField = "FullName"
  407.         Me.lstUsers.DataValueField = "UserID"
  408.         Me.lstUsers.DataBind()
  409.     End Sub
  410.  
  411.     Private Sub lstRole_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstRole.SelectedIndexChanged
  412.         'Get the current selected value
  413.         Dim m_SelectedValue As Int16 = CInt(Me.lstRole.SelectedItem.Value)
  414.  
  415.         If m_SelectedValue > 0 Then
  416.             Dim r As New Role(m_SelectedValue)
  417.  
  418.             If DoesCommercialManagement Then
  419.                 If r.BldgAccess = 0 Then 'All
  420.  
  421.                     pnlBuildings.Visible = False
  422.                     pnlDynamic.Visible = False
  423.                     pnlEntities.Visible = False
  424.                     pnlResidentialDynamic.Visible = False
  425.                     pnlResidentialSelect.Visible = False
  426.  
  427.                     Me.lblRole.Text = "All Buildings <br/> To change, go to User Settings/Manage Roles"
  428.                 ElseIf r.BldgAccess = 1 Then 'Selected
  429.                     Me.pnlBuildings.Visible = True
  430.                     Me.pnlDynamic.Visible = False
  431.                     Me.pnlResidentialDynamic.Visible = False
  432.                     Me.pnlResidentialSelect.Visible = False
  433.                     pnlEntities.Visible = False
  434.  
  435.  
  436.                     Me.lblRole.Text = "Selected Buildings <br/> To change, go to User Settings/Manage Roles"
  437.  
  438.                     'Base-3853 Load all apartments into Select2
  439.                     'For user to select from
  440.                     Page.ClientScript.RegisterStartupScript(
  441.                       Me.GetType(),
  442.                       "checkPostback",
  443.                       "loadAllBuildings()", True)
  444.  
  445.                 ElseIf r.BldgAccess = 2 Then 'Dynamic
  446. <<<<<<< HEAD
  447.                     Me.pnlDynamic.Visible = True
  448.                     Me.pnlBuildings.Visible = False
  449.                     Me.pnlResidentialDynamic.Visible = False
  450.                     Me.pnlResidentialSelect.Visible = False
  451.                     Me.pnlEntities.Visible = False
  452.  
  453. =======
  454.                     Me.pnlCommercialBuildings.Visible = False
  455.                     Me.pnlCommercialDynamic.Visible = True
  456. >>>>>>> origin/MRK2
  457.                     Me.ViewState("dynamicrole") = r.DynamicRole
  458.  
  459.                     dynamicDict.Add("DynamicRole", r.DynamicRole)
  460.                     dynamicDict.Add("Dropdown", "ddlDynamic")
  461.  
  462.                     BindKeyNames()
  463.  
  464.  
  465.                     Me.lblRole.Text = " Dynamic Buildings(" & r.DynamicRole & ") <br/> To change, go to User Settings/Manage Roles"
  466.  
  467.                     Select Case r.DynamicRole
  468.                         Case "LEASING AGENT"
  469.                             lblKeyValue.Text = "Please select a Leasing Agent"
  470.                         Case "MANAGER"
  471.                             lblKeyValue.Text = "Please select a Property Manager"
  472.                         Case "PROP ACCT."
  473.                             lblKeyValue.Text = "Please select a Property Accountant"
  474.                         Case "REGION"
  475.                             lblKeyValue.Text = "Please select a Region"
  476.                         Case "ASSET MANAGER"
  477.                             lblKeyValue.Text = "Please select an Asset Manager"
  478.                     End Select
  479.                     'Base-984 mtr support for multiple entities
  480.  
  481.                     Page.ClientScript.RegisterStartupScript(
  482.                        Me.GetType(),
  483.                        "checkPostback",
  484.                        "loadDynamicKeynameRoles('" & r.DynamicRole & "'" & ",'" & 0 & "'" & ")", True)
  485.                 ElseIf r.BldgAccess = 4 Then
  486.                     pnlEntities.Visible = True
  487. <<<<<<< HEAD
  488.                     pnlBuildings.Visible = False
  489.                     pnlDynamic.Visible = False
  490.                     pnlResidentialDynamic.Visible = False
  491.                     pnlResidentialSelect.Visible = False
  492. =======
  493.                     pnlCommercialBuildings.Visible = False
  494.                     pnlCommercialDynamic.Visible = False
  495. >>>>>>> origin/MRK2
  496.                     lblRole.Text = "Selected Entities <br/> To change, go to User Settings/Manage Roles"
  497.  
  498.                     Page.ClientScript.RegisterStartupScript(
  499.                         Me.GetType(),
  500.                         "checkPostback",
  501.                         "loadEntitiesForUser('" & UserRoleID & "')", True)
  502.                 End If
  503.             End If
  504.  
  505.             'Residential
  506.             If DoesResidentialManagement Then
  507.                 If r.ApartmentAccess = 0 Then 'All
  508.                     pnlResidentialSelect.Visible = False
  509.                     pnlResidentialDynamic.Visible = False
  510.                     pnlBuildings.Visible = False
  511.                     pnlDynamic.Visible = False
  512.                     pnlEntities.Visible = False
  513.  
  514.                     lblRole.Text = "All Apartments <br/> To change, go to User Settings/Manage Roles"
  515.                 ElseIf r.ApartmentAccess = 1 Then 'Selected
  516.                     pnlResidentialSelect.Visible = True
  517.                     pnlResidentialDynamic.Visible = False
  518.                     pnlBuildings.Visible = False
  519.                     pnlDynamic.Visible = False
  520.                     pnlEntities.Visible = False
  521.  
  522.                     lblRole.Text = "Selected Apartments <br/> To change, go to User Settings/Manage Roles"
  523.  
  524.  
  525.                     'Base-3853 Load all apartments into Select2
  526.                     'For user to select from
  527.                     Page.ClientScript.RegisterStartupScript(
  528.                       Me.GetType(),
  529.                       "checkPostback",
  530.                       "loadAllApartments()", True)
  531.  
  532.                 ElseIf r.ApartmentAccess = 2 Then 'Dynamic
  533.                     pnlResidentialDynamic.Visible = True
  534.                     pnlResidentialSelect.Visible = False
  535.                     pnlBuildings.Visible = False
  536.                     pnlDynamic.Visible = False
  537.                     pnlEntities.Visible = False
  538.  
  539.                     ViewState("dynamicrole") = r.DynamicRole
  540.  
  541.                     'BASE-7253
  542.                     dynamicDict.Add("DynamicRole", r.DynamicRole)
  543.                     dynamicDict.Add("Dropdown", "ddlResidentialDynamic")
  544.  
  545.                     BindKeyNames()
  546.                     lblRole.Text = " Dynamic Apartments(" & r.DynamicRole & ") <br/> To change, go to User Settings/Manage Roles"
  547.  
  548.                     Select Case r.DynamicRole
  549.                         Case "RM MANAGER"
  550.                             lblKeyValue.Text = "Please select a Residential Manager"
  551.                     End Select
  552.  
  553.                     Page.ClientScript.RegisterStartupScript(
  554.                            Me.GetType(),
  555.                            "checkPostback",
  556.                           "loadDynamicKeynameRoles('" & r.DynamicRole & "'" & ",'" & Me.UserID & "'" & ",'" & r.RoleID & "'" & ")", True)
  557.                     'Base-984 mtr support for multiple entities
  558.                 ElseIf r.ApartmentAccess = 4 Then
  559.                     pnlEntities.Visible = True
  560. <<<<<<< HEAD
  561.                     pnlBuildings.Visible = False
  562.                     pnlDynamic.Visible = False
  563.                     pnlResidentialDynamic.Visible = False
  564.                     pnlResidentialSelect.Visible = False
  565. =======
  566.                     pnlResidentialSelect.Visible = False
  567.                     pnlResidentialDynamic.Visible = False
  568. >>>>>>> origin/MRK2
  569.                     lblRole.Text = "Selected Entities <br/> To change, go to User Settings/Manage Roles"
  570.  
  571.                     Page.ClientScript.RegisterStartupScript(
  572.                         Me.GetType(),
  573.                         "checkPostback",
  574.                         "loadEntitiesForUser('" & UserRoleID & "')", True)
  575.                 End If
  576.             End If
  577.  
  578.         Else
  579.  
  580.             pnlBuildings.Visible = False
  581.             pnlDynamic.Visible = False
  582.             pnlEntities.Visible = False
  583.             pnlResidentialDynamic.Visible = False
  584.             pnlResidentialSelect.Visible = False
  585.             Me.lblRole.Text = ""
  586.  
  587.         End If
  588.     End Sub
  589.  
  590.     Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
  591.         'Setup an empty container
  592.         Dim r As UserRole
  593.  
  594.         'Check to see what we're doing
  595.         If Me.UserRoleID = 0 Then 'SETTING ME.USERID <> 0 FIXES ADD USER AND ADD ROLE; SETTING ME.USERID = 0 FIXES EDIT ROLE
  596.  
  597.             Dim strList() As String = hdnDynamicRoleList.Value.Split(",")
  598.  
  599.             If strList.GetLength(0) > 0 Then
  600.  
  601.                 'Need to remove the current dynamic roles assigned to that user
  602.                 UserRoleCollection.DeleteDynamicRolesByUserId(Me.lstUsers.SelectedItem.Value, Me.lstRole.SelectedItem.Value)
  603.  
  604.                 For Each s As String In strList
  605.                     r = New UserRole
  606.                     r.RoleID = Me.lstRole.SelectedItem.Value
  607.                     r.IsMain = Me.chkIsMain.Checked
  608.                     r.UserID = Me.lstUsers.SelectedItem.Value
  609.  
  610.                     Dim mRole As New Role(r.RoleID)
  611.                     If mRole.BldgAccess = 2 Then
  612.                         r.KeyValue = s
  613.                     End If
  614.  
  615.                     If mRole.ApartmentAccess = 2 Then
  616.                         r.KeyValue = s
  617.                     End If
  618.  
  619.                     r.Save()
  620.                 Next
  621.  
  622.             Else
  623.  
  624.                 r = New UserRole
  625.                 'Fill in the basics of it
  626.                 r.RoleID = Me.lstRole.SelectedItem.Value
  627.                 r.IsMain = Me.chkIsMain.Checked
  628.                 r.UserID = Me.lstUsers.SelectedItem.Value
  629.  
  630.                 Dim mRole As New Role(r.RoleID)
  631.                 If mRole.BldgAccess = 2 AndAlso Me.ddlDynamic.Items.Count > 0 Then
  632.                     r.KeyValue = Me.ddlDynamic.SelectedItem.Value
  633.                 End If
  634.  
  635.                 If mRole.ApartmentAccess = 2 AndAlso Me.ddlResidentialDynamic.Items.Count > 0 Then
  636.                     r.KeyValue = Me.ddlResidentialDynamic.SelectedItem.Value
  637.                 End If
  638.  
  639.                 r.Save()
  640.  
  641.             End If
  642.  
  643.         Else
  644.  
  645.             Dim strList() As String = hdnDynamicRoleList.Value.Split(",")
  646.  
  647.             If strList.GetLength(0) > 0 Then
  648.                 'Need to remove the current dynamic roles assigned to that user
  649.                 UserRoleCollection.DeleteDynamicRolesByUserId(Me.lstUsers.SelectedItem.Value, Me.lstRole.SelectedItem.Value)
  650.  
  651.                 For Each s As String In strList
  652.                     r = New UserRole
  653.                     r.RoleID = Me.lstRole.SelectedItem.Value
  654.                     r.IsMain = Me.chkIsMain.Checked
  655.                     r.UserID = Me.lstUsers.SelectedItem.Value
  656.  
  657.                     Dim mRole As New Role(r.RoleID)
  658.                     If mRole.BldgAccess = 2 Then
  659.                         r.KeyValue = s
  660.                     End If
  661.  
  662.                     If mRole.ApartmentAccess = 2 Then
  663.                         r.KeyValue = s
  664.                     End If
  665.  
  666.                     r.Save()
  667.                 Next
  668.             Else
  669.                 r = New UserRole
  670.                 'Fill in the basics of it
  671.                 r.RoleID = Me.lstRole.SelectedItem.Value
  672.                 r.IsMain = Me.chkIsMain.Checked
  673.                 r.UserID = Me.lstUsers.SelectedItem.Value
  674.  
  675.                 Dim mRole As New Role(r.RoleID)
  676.                 If mRole.BldgAccess = 2 AndAlso Me.ddlDynamic.Items.Count > 0 Then
  677.                     r.KeyValue = Me.ddlDynamic.SelectedItem.Value
  678.                 End If
  679.  
  680.                 If mRole.ApartmentAccess = 2 AndAlso Me.ddlResidentialDynamic.Items.Count > 0 Then
  681.                     r.KeyValue = Me.ddlResidentialDynamic.SelectedItem.Value
  682.                 End If
  683.  
  684.                 r.Save()
  685.             End If
  686.         End If
  687.  
  688.         'Save it so we know we're up to date
  689.  
  690.         'Check to see if we're working with buildings
  691.         If Me.pnlCommercialBuildings.Visible Then
  692.             'First, just make sure we don't have any buildings in the db from this user
  693.             RoleBuildingCollection.Delete(r.UserRoleID)
  694.  
  695.             'Base-3853
  696.             Dim list As String() = hdnBuildingList.Value.Split(",")
  697.  
  698.             If list.Length > 0 Then
  699.                 For Each Building In list
  700.                     Dim rb As New RoleBuilding
  701.  
  702.                     rb.BldgID = Building
  703.                     rb.DateAdded = DateTime.Now()
  704.                     rb.UserRoleID = r.UserRoleID
  705.                     rb.Save()
  706.                 Next
  707.             End If
  708.  
  709.             'Now add in the new buildings that they've selected
  710.             'For Each l As RadListBoxItem In Me.lstPropertyDestination.Items
  711.             '    Dim rb As New RoleBuilding
  712.  
  713.             '    rb.BldgID = l.Value
  714.             '    rb.DateAdded = DateTime.Now()
  715.             '    rb.UserRoleID = r.UserRoleID
  716.  
  717.             '    rb.Save()
  718.             'Next
  719.         End If
  720.  
  721.         If Me.pnlResidentialSelect.Visible Then
  722.             RoleApartment.DeleteByUserRole(r.UserRoleID)
  723.  
  724.             'Base-3853
  725.             Dim list As String() = hdnApartmentList.Value.Split(",")
  726.  
  727.             If list.Length > 0 Then
  728.                 For Each Apartment In list
  729.                     Dim ra As New RoleApartment
  730.  
  731.                     ra.RMPROPID = Apartment
  732.                     ra.DateAdded = DateTime.Now()
  733.                     ra.UserRoleID = r.UserRoleID
  734.                     ra.Save()
  735.                 Next
  736.             End If
  737.  
  738.             'For Each rlbi As RadListBoxItem In rlbApartmentDestination.Items
  739.             '    Dim ra As New RoleApartment
  740.  
  741.             '    ra.RMPROPID = rlbi.Value
  742.             '    ra.DateAdded = DateTime.Now()
  743.             '    ra.UserRoleID = r.UserRoleID
  744.  
  745.             '    ra.Save()
  746.             'Next
  747.         End If
  748.  
  749.         If pnlEntities.Visible Then
  750.             RoleEntityCollection.Delete(r.UserRoleID)
  751.  
  752.             'BASE-5986
  753.             Dim list As String() = hdnEntityList.Value.Split(",")
  754.             If list.Length > 0 Then
  755.                 For Each entityId In list
  756.                     Dim re As New RoleEntity
  757.                     re.EntityId = Trim(entityId)
  758.                     re.DateAdded = DateTime.Now()
  759.                     re.UserRoleId = r.UserRoleID
  760.                     re.Save()
  761.                 Next
  762.             End If
  763.  
  764.             'For Each l As RadListBoxItem In lstEntitiesDestination.Items
  765.             '    Dim re As New RoleEntity
  766.             '    re.EntityId = Trim(l.Value)
  767.             '    re.DateAdded = DateTime.Now()
  768.             '    re.UserRoleId = r.UserRoleID
  769.             '    re.Save()
  770.             'Next
  771.         End If
  772.         'Before we leave, we need to clear the cache
  773.         Me.Cache.Remove("TopLevelMenu" & Me.UserID)
  774.  
  775.         'See if they want us to recalculate the assignments for this role
  776.         If Me.chkRefactor.Checked Then
  777.             'Let's get started
  778.             AssignmentRecalc.RecalculateForUserRole(r)
  779.         End If
  780.  
  781.         'Response.Redirect("../um/e_role.aspx?action=e&roleid=" & r.RoleID)
  782.         'I'm done with it, close and refresh
  783.         ' Me.Page.Controls.Add(New LiteralControl("<script language=Javascript>RefreshParentPage();CloseOnReload();</script>"))
  784.  
  785.         'Redirect the telerik modal back to the role page
  786.         'Me.Page.Controls.Add(New LiteralControl("<script language=Javascript>location.href='e_role.aspx?action=e&roleid=" & Me.UserRoleID & "';</script>"))
  787.  
  788.         Page.ClientScript.RegisterStartupScript(
  789.               Me.GetType(),
  790.               "ReloadPage",
  791.               " RefreshParentPage();", True)
  792.  
  793.         'Page.ClientScript.RegisterStartupScript(
  794.         '      Me.GetType(),
  795.         '      "ReloadPage",
  796.         '      "location.href='e_role.aspx?action=e&userTab=1&roleid=" & Me.RoleID & "'", True)
  797.     End Sub
  798.  
  799.     'set titles for rad box controls
  800.     Protected Sub lstPropertySource_ItemDataBound(sender As Object, e As RadListBoxItemEventArgs)
  801.         Dim lblPropertySourceHeader As Label = lstPropertySource.Header.FindControl("lblPropertySourceHeader")
  802.         lblPropertySourceHeader.Text = "Properties"
  803.  
  804.         Dim lblPropertyDestHeader As Label = lstPropertyDestination.Header.FindControl("lblPropertyDestHeader")
  805.         lblPropertyDestHeader.Text = "Selected Properties"
  806.     End Sub
  807.  
  808.     Protected Sub rlbApartmentSource_ItemDataBound(sender As Object, e As RadListBoxItemEventArgs)
  809.         Dim lblApartmentSourceHeader = CType(rlbApartmentSource.Header.FindControl("lblApartmentSourceHeader"), Label)
  810.         lblApartmentSourceHeader.Text = "Properties"
  811.  
  812.         Dim lblApartmentDestHeader = CType(rlbApartmentDestination.Header.FindControl("lblApartmentDestHeader"), Label)
  813.         lblApartmentDestHeader.Text = "Selected Properties"
  814.     End Sub
  815. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement