From: <ro...@us...> - 2006-08-09 14:55:13
|
Revision: 286 Author: rouquin Date: 2006-08-09 07:54:57 -0700 (Wed, 09 Aug 2006) ViewCVS: http://svn.sourceforge.net/tcdb/?rev=286&view=rev Log Message: ----------- Changed split rights list to unassigned and assigned rights. Modified Paths: -------------- Website/App_Code/Right.cs Website/Includes/UserRoles.ascx Website/Includes/UserRoles.ascx.cs Modified: Website/App_Code/Right.cs =================================================================== --- Website/App_Code/Right.cs 2006-08-09 04:47:23 UTC (rev 285) +++ Website/App_Code/Right.cs 2006-08-09 14:54:57 UTC (rev 286) @@ -117,6 +117,20 @@ return rightsList; } + public static List<Right> TCDB_GetRoleRights(Nullable<int> roleID, Nullable<bool> active) + { + tcdbDataSetTableAdapters.db_roleRightTableAdapter rrAdapter = new tcdbDataSetTableAdapters.db_roleRightTableAdapter(); + tcdbDataSet.db_roleRightDataTable rrTable = rrAdapter.GetData(roleID, active); + List<Right> rightsList = new List<Right>(); + + foreach (tcdbDataSet.db_roleRightRow row in rrTable) + { + rightsList.Add(new Right(row.rightsID, row.rightName, row.rightCode, "", row.active)); + } + + return rightsList; + } + public static List<String> TCDB_GetUserRights(int productID, int userID, Nullable<bool> active) { tcdbDataSetTableAdapters.db_userRightsTableAdapter userRightsAdapter = new tcdbDataSetTableAdapters.db_userRightsTableAdapter(); @@ -250,6 +264,28 @@ p_active = right.ACTIVE; } + public override bool Equals(Object obj) + { + bool result = false; + + try + { + Right right = (Right)obj; + + if (right.ID == p_id) + result = true; + } + catch + { + } + return result; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + public int ID { get { return p_id; } Modified: Website/Includes/UserRoles.ascx =================================================================== --- Website/Includes/UserRoles.ascx 2006-08-09 04:47:23 UTC (rev 285) +++ Website/Includes/UserRoles.ascx 2006-08-09 14:54:57 UTC (rev 286) @@ -48,7 +48,7 @@ </td> <td colspan="2" align="left" valign="top" width="34%" style="height: 132px"> <strong>Rights:</strong><br /> - <asp:ListBox ID="rightsList" runat="server" Height="150px" Width="150px" OnInit="rightsList_Init1"> + <asp:ListBox ID="rightsList" runat="server" Height="150px" Width="150px" OnInit="rightsList_Init"> </asp:ListBox> </td> </tr> @@ -102,24 +102,26 @@ </td> </tr> <tr> - <td colspan="2" align="left" valign="top" width="33%"> - </td> - <td colspan="2" align="left" valign="top" width="33%"> - </td> - <td colspan="2" align="left" valign="top" width="34%"> - <strong>Rights:<br /> - <asp:LinkButton ID="newRight" runat="server" CommandName="newRight" OnCommand="newRight">New Right</asp:LinkButton><br /> - </strong> <asp:ListBox ID="rightsList" runat="server" DataSourceID="RightsDataSource" - DataTextField="rightsName" DataValueField="rightsID" SelectionMode="Multiple" - Height="150px" OnDataBound="rightsList_DataBound" Width="150px"> - </asp:ListBox> </td> - </tr> + <td colspan="2" width="45%" valign="top" height="200" align="center"> + <strong>Unassigned Rights:</strong><br /> + <asp:ListBox ID="unassignedList" runat="server" Height="100%" SelectionMode="Multiple" + Width="300px"></asp:ListBox> + </td> + <td colspan="2" height="200" width="10%" valign="middle" align="center"> + <asp:Button ID="assignButton" runat="server" OnCommand="assignSelected" Text="-->" /><br /> + <asp:Button ID="unassignButton" runat="server" OnCommand="unassignSelected" Text="<--" /></td> + <td colspan="2" width="45%" valign="top" height="200" align="center"> + <strong>Assigned Rights:</strong><br /> + <asp:ListBox ID="assignedList" runat="server" Height="100%" SelectionMode="Multiple" + AppendDataBoundItems="True" Width="300px"></asp:ListBox> + </td> + </tr> <tr> <td class="hr" colspan="6"> </td> </tr> <tr> - <td align="left" colspan="6"> + <td align="left" colspan="4"> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:LinkButton> @@ -127,6 +129,7 @@ <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton></td> + <td align="right" colspan="2"><asp:LinkButton CommandName="newRight" ID="newRight" OnCommand="newRight" runat="server" >New Right</asp:LinkButton></td> </tr> </table> </div> @@ -164,18 +167,20 @@ </td> </tr> <tr> - <td colspan="2" align="left" valign="top" width="33%"> - </td> - <td colspan="2" align="left" valign="top" width="33%"> - </td> - <td colspan="2" align="left" valign="top" width="34%"> - <strong>Rights: - <asp:LinkButton ID="newRight" runat="server" CommandName="newRight" OnCommand="newRight">New Right</asp:LinkButton><br /> - </strong> <asp:ListBox ID="rightsList" runat="server" DataSourceID="RightsDataSource" - DataTextField="rightsName" DataValueField="rightsID" SelectionMode="Multiple" - Height="150px" Width="150px"></asp:ListBox> - </td> - </tr> + <td colspan="2" width="45%" valign="top" height="200" align="center"> + <strong>Unassigned Rights:</strong><br /> + <asp:ListBox ID="unassignedList" runat="server" Height="100%" SelectionMode="Multiple" + Width="300px"></asp:ListBox> + </td> + <td colspan="2" height="200" width="10%" valign="middle" align="center"> + <asp:Button ID="assignButton" runat="server" OnCommand="assignSelected" Text="-->" /><br /> + <asp:Button ID="unassignButton" runat="server" OnCommand="unassignSelected" Text="<--" /></td> + <td colspan="2" width="45%" valign="top" height="200" align="center"> + <strong>Assigned Rights:</strong><br /> + <asp:ListBox ID="assignedList" runat="server" Height="100%" SelectionMode="Multiple" + AppendDataBoundItems="True" Width="300px"></asp:ListBox> + </td> + </tr> <tr> <td class="hr" colspan="6"> </td> Modified: Website/Includes/UserRoles.ascx.cs =================================================================== --- Website/Includes/UserRoles.ascx.cs 2006-08-09 04:47:23 UTC (rev 285) +++ Website/Includes/UserRoles.ascx.cs 2006-08-09 14:54:57 UTC (rev 286) @@ -81,12 +81,14 @@ } protected void updateRoleRights() { - ListBox rightsList = (ListBox)FormView1.FindControl("rightsList"); + ListBox rightsList = (ListBox)FormView1.FindControl("assignedList"); // Clear roles tcdbDataSetTableAdapters.db_roleRightTableAdapter rrAdapter = new tcdbDataSetTableAdapters.db_roleRightTableAdapter(); rrAdapter.DeleteRoleRights(roleID, null); + foreach (ListItem item in rightsList.Items) + rrAdapter.InsertRoleRights(roleID, Convert.ToInt32(item.Value)); } protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e) @@ -136,21 +138,6 @@ } } - protected void rightsList_DataBound(object sender, EventArgs e) - { - ListBox rightsList = (ListBox)sender; - - tcdbDataSetTableAdapters.db_roleRightTableAdapter roleRightAdapter = new tcdbDataSetTableAdapters.db_roleRightTableAdapter(); - tcdbDataSet.db_roleRightDataTable roleRightTable = roleRightAdapter.GetData(roleID, true); - - foreach (tcdbDataSet.db_roleRightRow row in roleRightTable) - { - ListItem item = rightsList.Items.FindByValue(row.rightsID.ToString()); - item.Selected = true; - if (!row.active) - item.Attributes.CssStyle.Add("text-decoration", "line-through"); - } - } protected void newRight(object sender, CommandEventArgs e) { Response.Redirect("Right.aspx?mode=new&" + Constants.CODE_ROLE + "=" + roleID); @@ -269,26 +256,80 @@ } else activeBox.Enabled = false; + + if (FormView1.CurrentMode != FormViewMode.ReadOnly) + { + ListBox unassigned = (ListBox)FormView1.FindControl("unassignedList"); + ListBox assigned = (ListBox)FormView1.FindControl("assignedList"); + + // init + unassigned.Items.Clear(); + assigned.Items.Clear(); + + List<Right> roleRights = RightDB.TCDB_GetRoleRights(roleID, active); + List<Right> rights = RightDB.TCDB_GetRightList(active); + foreach (Right right in rights) + { + ListItem item = new ListItem(right.NAME, right.ID.ToString()); + if (!right.ACTIVE) + item.Attributes.CssStyle.Add("text-decoration", "line-through"); + + if (roleRights.Contains(right)) + assigned.Items.Add(item); + else + unassigned.Items.Add(item); + } + } } - protected void rightsList_Init1(object sender, EventArgs e) + protected void editAssignments_Command(object sender, CommandEventArgs e) { + Response.Redirect("~/RoleAssignments.aspx?" + Constants.CODE_PRODUCT + "=" + productID + "&" + Constants.CODE_ROLE + "=" + roleID); + } + + protected void assignSelected(object sender, CommandEventArgs e) + { + ListBox unassigned = (ListBox)FormView1.FindControl("unassignedList"); + ListBox assigned = (ListBox)FormView1.FindControl("assignedList"); + + int[] indices = unassigned.GetSelectedIndices(); + for (int index = indices.Length-1; index >= 0; index--) + { + ListItem item = unassigned.Items[indices[index]]; + + unassigned.Items.Remove(item); + assigned.Items.Add(item); + item.Selected = false; + } + } + protected void unassignSelected(object sender, CommandEventArgs e) + { + ListBox unassigned = (ListBox)FormView1.FindControl("unassignedList"); + ListBox assigned = (ListBox)FormView1.FindControl("assignedList"); + + int[] indices = assigned.GetSelectedIndices(); + for (int index = indices.Length-1; index >= 0; index--) + { + ListItem item = assigned.Items[indices[index]]; + + assigned.Items.Remove(item); + unassigned.Items.Add(item); + item.Selected = false; + } + } + protected void rightsList_Init(object sender, EventArgs e) + { ListBox rightsList = (ListBox)sender; - tcdbDataSetTableAdapters.db_roleRightTableAdapter rrAdapter = new tcdbDataSetTableAdapters.db_roleRightTableAdapter(); - tcdbDataSet.db_roleRightDataTable rrTable = rrAdapter.GetData(roleID, active); - foreach (tcdbDataSet.db_roleRightRow row in rrTable) + List<Right> rights = RightDB.TCDB_GetRoleRights(roleID, active); + foreach (Right right in rights) { - ListItem item = new ListItem(row.rightName, row.rightsID.ToString()); - if (!row.active) + ListItem item = new ListItem(right.NAME, right.ID.ToString()); + if (!right.ACTIVE) item.Attributes.CssStyle.Add("text-decoration", "line-through"); rightsList.Items.Add(item); } } - protected void editAssignments_Command(object sender, CommandEventArgs e) - { - Response.Redirect("~/RoleAssignments.aspx?" + Constants.CODE_PRODUCT + "=" + productID + "&" + Constants.CODE_ROLE + "=" + roleID); - } - } } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |