Ejemplo n.º 1
0
    // 获得部门列表(按权限范围获取部门列表,例如对哪些部门有某种管理权限的)

    #region protected DataTable GetDepartmentByPermissionScope(bool userDepartment = false, bool insertBlank = false, string permissionItemCode = "Resource.ManagePermission")
    /// <summary>
    /// 按权限范围获取部门列表
    /// </summary>
    /// <param name="permissionItemCode">操作权限项</param>
    /// <param name="insertBlank">插入空行</param>
    /// <param name="userDepartment">若没数据库至少显示用户自己的部门</param>
    protected DataTable GetDepartmentByPermissionScope(bool userDepartment = false, bool insertBlank = false, string permissionItemCode = "Resource.ManagePermission")
    {
        DataTable dtDepartment = null;
        var       manager      = new BaseOrganizationManager(UserCenterDbHelper, UserInfo);

        if (UserInfo.IsAdministrator)
        {
            dtDepartment = manager.GetOrganizationDataTable();
        }
        else
        {
            var permissionService = new BasePermissionService();
            dtDepartment = permissionService.GetOrganizationDTByPermission(UserInfo, UserInfo.Id.ToString(), permissionItemCode);

            // BasePermissionScopeManager permissionScopeManager = new BasePermissionScopeManager(dbHelper, userInfo);
            // dtDepartment = permissionScopeManager.GetOrganizationDT(userInfo.Id, permissionItemCode, false);
        }
        // 至少要列出自己的部门的(其实这里还看是否存在了)
        if (userDepartment)
        {
            if (!string.IsNullOrEmpty(UserInfo.DepartmentId))
            {
                if (!BaseUtil.Exists(dtDepartment, BaseOrganizationEntity.FieldId, UserInfo.DepartmentId))
                {
                    dtDepartment.Merge(manager.GetDataTableById(UserInfo.DepartmentId));
                }
            }
        }
        dtDepartment.DefaultView.Sort = BaseOrganizationEntity.FieldSortCode;
        return(dtDepartment);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 获取组织的树形选项
    /// </summary>
    /// <param name="dropDownList">下拉控件</param>
    /// <param name="insertBlank">插入空行</param>
    /// <param name="userCompanySelected">默认选中自己的公司</param>
    /// <param name="userSubCompanySelected">默认选中自己的子公司</param>
    /// <param name="userDepartmentSelected">默认选中自己的部门</param>
    /// <param name="userSubDepartmentSelected">默认选中自己的子部门</param>
    /// <param name="userWorkgroupSelected">默认选中自己的工作组</param>
    protected void GetOrganizationTree(DropDownList dropDownList, bool insertBlank = true, bool userCompanySelected = false, bool userSubCompanySelected = false, bool userDepartmentSelected = false, bool userSubDepartmentSelected = false, bool userWorkgroupSelected = false)
    {
        dropDownList.Items.Clear();
        var manager = new BaseOrganizationManager(UserCenterDbHelper, UserInfo);
        //2017.12.20增加默认的HttpRuntime.Cache缓存
        var cacheKey = "DataTable.BaseOrganizationTree";
        //var cacheTime = default(TimeSpan);
        var cacheTime = TimeSpan.FromMilliseconds(86400000);
        var dt        = CacheUtil.Cache <DataTable>(cacheKey, () => manager.GetOrganizationTree(), true, false, cacheTime);

        if (dt != null && dt.Rows.Count > 0)
        {
            dropDownList.DataValueField = BaseOrganizationEntity.FieldId;
            dropDownList.DataTextField  = BaseOrganizationEntity.FieldName;
            dropDownList.DataSource     = dt;
            dropDownList.DataBind();
        }

        if (insertBlank)
        {
            dropDownList.Items.Insert(0, new ListItem());
        }
        if (userCompanySelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.CompanyId);
        }
        if (userSubCompanySelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.SubCompanyId);
        }
        if (userDepartmentSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.DepartmentId);
        }
        if (userSubDepartmentSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.SubDepartmentId);
        }
        if (userWorkgroupSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.WorkgroupId);
        }
    }
Ejemplo n.º 3
0
    // 获取所有的部门列表

    #region protected void GetDepartment(DropDownList ddlDepartment, bool insertBlank = true, bool userDepartmentSelected = true)

    /// <summary>
    /// 获取部门列表
    /// </summary>
    /// <param name="dropDownList">下拉控件</param>
    /// <param name="insertBlank">插入空行</param>
    /// <param name="parentId">父级编号</param>
    /// <param name="categoryCode">组织分类(Company,SubCompany,Department,SubDepartment,Workgroup)</param>
    /// <param name="userCompanySelected">默认选中自己的公司</param>
    /// <param name="userSubCompanySelected">默认选中自己的子公司</param>
    /// <param name="userDepartmentSelected">默认选中自己的部门</param>
    /// <param name="userSubDepartmentSelected">默认选中自己的子部门</param>
    /// <param name="userWorkgroupSelected">默认选中自己的工作组</param>
    protected void GetOrganizationDataTable(DropDownList dropDownList, bool insertBlank = true, string parentId = null, string categoryCode = "Department", bool userCompanySelected = false, bool userSubCompanySelected = false, bool userDepartmentSelected = false, bool userSubDepartmentSelected = false, bool userWorkgroupSelected = false)
    {
        //dropDownList.Items.Clear();
        var manager        = new BaseOrganizationManager(UserCenterDbHelper, UserInfo);
        var dtOrganization = manager.GetOrganizationDataTable(parentId, false, categoryCode);

        dropDownList.SelectedValue = null;
        if (dtOrganization != null && dtOrganization.Rows.Count > 0)
        {
            dtOrganization.DefaultView.Sort = BaseOrganizationEntity.FieldSortCode;
            dropDownList.DataValueField     = BaseOrganizationEntity.FieldId;
            dropDownList.DataTextField      = BaseOrganizationEntity.FieldName;
            dropDownList.DataSource         = dtOrganization;
        }
        dropDownList.DataBind();
        if (insertBlank)
        {
            dropDownList.Items.Insert(0, new ListItem());
        }
        if (userCompanySelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.CompanyId);
        }
        if (userSubCompanySelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.SubCompanyId);
        }
        if (userDepartmentSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.DepartmentId);
        }
        if (userSubDepartmentSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.SubDepartmentId);
        }
        if (userWorkgroupSelected)
        {
            WebUtil.SetDropDownListValue(dropDownList, UserInfo.WorkgroupId);
        }
    }
Ejemplo n.º 4
0
    // 获得部门列表(按权限范围)

    #region protected void GetDepartment(DropDownList ddlDepartment, bool insertBlank = true, bool userDepartmentSelected = true)
    /// <summary>
    /// 获取部门列表
    /// </summary>
    /// <param name="ddlDepartment">部门选项</param>
    /// <param name="insertBlank">插入空行</param>
    /// <param name="userDepartmentSelected">默认选中自己的部门</param>
    protected void GetDepartment(DropDownList ddlDepartment, bool insertBlank = true, bool userDepartmentSelected = true)
    {
        var manager = new BaseOrganizationManager(UserCenterDbHelper, UserInfo);
        var dt      = manager.GetOrganizationDataTable();

        ddlDepartment.SelectedValue = null;
        if (dt != null && dt.Rows.Count > 0)
        {
            dt.DefaultView.Sort          = BaseOrganizationEntity.FieldSortCode;
            ddlDepartment.DataValueField = BaseOrganizationEntity.FieldId;
            ddlDepartment.DataTextField  = BaseOrganizationEntity.FieldName;
            ddlDepartment.DataSource     = dt;
            ddlDepartment.DataBind();
        }

        if (insertBlank)
        {
            ddlDepartment.Items.Insert(0, new ListItem());
        }
        if (userDepartmentSelected)
        {
            WebUtil.SetDropDownListValue(ddlDepartment, UserInfo.DepartmentId);
        }
    }