private void BindLocationsAndDepartments(int PermissionId)
    {
        IUsersProfile mUserProfile = null;

        mUserProfile            = AppService.Create <IUsersProfile>();
        mUserProfile.AppManager = this.mappmanager;

        // retrieve existing locations and departments
        DataTable dt = mUserProfile.RetrieveUserPermissionAccess(PermissionId);

        if (dt != null)
        {
            if (dt.Rows.Count > 0)
            {
                DataTable dtLocations = dt.DefaultView.ToTable(true, "City", "LocationId");

                tvLocations.Nodes.Clear();
                for (int i = 0; i < dtLocations.Rows.Count; i++)
                {
                    TreeNode childNode = new TreeNode();
                    childNode.Text     = Convert.ToString(dtLocations.Rows[i]["City"]);
                    childNode.Value    = Convert.ToString(dtLocations.Rows[i]["LocationId"]);
                    childNode.Expanded = true;

                    DataRow[] drDept = dt.Select("LocationId = " + Convert.ToString(dtLocations.Rows[i]["LocationId"]));

                    if (drDept.Length > 0)
                    {
                        foreach (DataRow dr in drDept)
                        {
                            TreeNode SubNode = new TreeNode();
                            SubNode.Text  = Convert.ToString(dr["Name"]);
                            SubNode.Value = Convert.ToString(dr["DepartmentId"]);
                            childNode.ChildNodes.Add(SubNode);
                        }
                    }

                    tvLocations.Nodes.Add(childNode);
                }
            }
        }

        foreach (TreeNode node in tvLocations.Nodes)
        {
            RemoveNodesLink(node);
        }
    }
示例#2
0
    private void BindPermissonAccess()
    {
        IUsersProfile mUserProfile = null;

        mUserProfile            = AppService.Create <IUsersProfile>();
        mUserProfile.AppManager = this.mAppManager;

        // retrieve existing locations and departments
        DataTable dt = mUserProfile.RetrieveUserPermissionAccess(PermissionId);

        if (dt != null)
        {
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    foreach (TreeNode node in tvLocations.Nodes)
                    {
                        if (Convert.ToInt32(node.Value) == Convert.ToInt32(dr["LocationId"]))
                        {
                            node.Checked = true;

                            if (node.ChildNodes.Count > 0)
                            {
                                //Check all the child nodes.
                                foreach (TreeNode childNode in node.ChildNodes)
                                {
                                    if (Convert.ToInt32(childNode.Value) == Convert.ToInt32(dr["DepartmentId"]))
                                    {
                                        childNode.Checked = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }