Exemplo n.º 1
0
        /// <summary>
        /// 结合权限获取所有单位
        /// </summary>
        /// <param name="companyId">单位编号</param>
        /// <param name="controlId">下拉控件ID</param>
        /// <param name="defaultSelId">默认选中的ID</param>
        /// <param name="defaultSel">是否默认选中本部门</param>
        /// <returns></returns>
        public string GetDepartmentDropList(string companyId, string controlId, string defaultSelId, bool defaultSel = false)
        {
            var str = new StringBuilder();

            try
            {
                var user = CurrentUser.CrmUser;
                str.AppendFormat("document.getElementById('{0}').options.length = 1;", controlId);

                if (string.IsNullOrEmpty(companyId))
                {
                    return(str.ToString());
                }

                var departments = new CrmDepartmentBll().GetAllDepartment(new CrmDepartmentEntity()
                {
                    CompanyId = companyId
                });

                //验证是有获取所有执法单位的权限,如没有只查本单位的权限
                var isAllEnforcementUnit = new MembershipManager().VerificationPermissions(user.Id, "Department", "Operation");
                departments = isAllEnforcementUnit
                               ? departments
                               : departments.Where(x => x.Id == user.DeptId).ToList();
                var i = 1;
                if (departments.Any() && departments.Count >= 1)
                {
                    str.Append("document.getElementById('" + controlId + "').options[" + 0 + "] = new Option('==请选择==', 'all', false, false);");
                }
                else if (departments.Any() && departments.Count == 1)
                {
                    i = 0;
                }
                foreach (var t in departments.Where(t => !string.IsNullOrEmpty(t.FullName)))
                {
                    str.Append("document.getElementById('" + controlId + "').options[" + i + "] = new Option('" + t.FullName + "', '" + t.Id + "',false, false);");

                    //默认选中本部门(多个部门,默认不要选中)
                    if ((defaultSel && user.DeptId == t.Id) || t.Id == defaultSelId)
                    {
                        str.Append("document.getElementById('" + controlId + "').options[" + i + "].selected=true;");
                    }
                    else if (departments.Count == 1 && (user.DeptId == t.Id || t.Id == defaultSelId))
                    {
                        str.Append("document.getElementById('" + controlId + "').options[" + i + "].selected=true;");
                    }

                    i++;
                }
            }
            catch (Exception)
            {
                //ignored
            }
            return(str.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// 请求部门下拉框数据
        /// </summary>
        /// <history>
        /// 修改描述:时间+作者+描述
        /// </history>
        /// <param name="companyId">单位编号</param>
        /// <param name="selectId">控件编号</param>
        /// <returns></returns>
        public string DropList(string companyId, string selectId)
        {
            var str = new StringBuilder();

            try
            {
                str.AppendFormat("document.getElementById('{0}').options.length = 1;", selectId);
                if (!string.IsNullOrEmpty(companyId))
                {
                    var departments = new CrmDepartmentBll().GetAllDepartment(new CrmDepartmentEntity()
                    {
                        CompanyId = companyId
                    });

                    var i = 1;
                    foreach (var t in departments.Where(t => !string.IsNullOrEmpty(t.FullName)))
                    {
                        str.Append("document.getElementById('" + selectId + "').options[" + i + "] = new Option('" +
                                   t.FullName + "', '" + t.Id + "', false, false);");
                        i++;
                    }
                }
            }
            catch (Exception)
            {
                //ignored
            }

            return(str.ToString());
        }
Exemplo n.º 3
0
        /// <summary>
        /// 结合权限获取所有单位
        /// </summary>
        /// <param name="companyId">单位编号</param>
        /// <param name="controlId">下拉控件ID</param>
        /// <param name="defaultSelId">默认选中的ID</param>
        /// <param name="defaultSel">是否默认选中本部门</param>
        /// <returns></returns>
        public string GetDepartmentDropListWorkFlow(string companyId, string controlId, string defaultSelId, bool defaultSel = false)
        {
            var str = new StringBuilder();

            try
            {
                var user = CurrentUser.CrmUser;
                str.AppendFormat("document.getElementById('{0}').options.length = 1;", controlId);

                if (string.IsNullOrEmpty(companyId))
                {
                    return(str.ToString());
                }

                var departments = new CrmDepartmentBll().GetAllDepartment(new CrmDepartmentEntity()
                {
                    CompanyId = companyId
                });

                var i = 1;

                foreach (var t in departments.Where(t => !string.IsNullOrEmpty(t.FullName)))
                {
                    str.Append("document.getElementById('" + controlId + "').options[" + i + "] = new Option('" + t.FullName + "', '" + t.Id + "',false, false);");

                    //默认选中本部门(多个部门,默认不要选中)
                    if ((defaultSel && user.DeptId == t.Id) || t.Id == defaultSelId)
                    {
                        str.Append("document.getElementById('" + controlId + "').options[" + i + "].selected=true;");
                    }
                    else if (departments.Count == 1 && (user.DeptId == t.Id || t.Id == defaultSelId))
                    {
                        str.Append("document.getElementById('" + controlId + "').options[" + i + "].selected=true;");
                    }

                    i++;
                }
            }
            catch (Exception)
            {
                //ignored
            }
            return(str.ToString());
        }