Exemplo n.º 1
0
        public override void InitControl()
        {
            string keyword  = Control.Params["keyword"];
            string format   = Control.Params["format"];
            string parentId = Control.Params["parentId"];
            string role     = Control.Params["role"];

            List <Department> departments;
            string            siteID = SiteConfigs.GetConfig().SiteGroupEnabled ? SiteConfigs.GetConfig().SiteID : string.Empty;

            if (String.Compare("true", format, true) == 0)
            {
                departments = helper.GetDepartmentTreeWithFormat(siteID, parentId);
            }
            else
            {
                departments = helper.GetDepartmentTree(siteID, parentId);
            }

            ddlDepartment.DataSource     = departments;
            ddlDepartment.DataTextField  = "Name";
            ddlDepartment.DataValueField = "ID";
            ddlDepartment.DataBind();
            ddlDepartment.Items.Insert(0, new ListItem("请选择", ""));

            string val = Value as string;

            if (String.IsNullOrEmpty(val))
            {
                if (CurrentAccount != null)
                {
                    foreach (ListItem item in ddlDepartment.Items)
                    {
                        item.Selected = item.Value == CurrentAccount.DepartmentID;
                    }
                }
            }
            else
            {
                ddlDepartment.SelectedValue = val;
            }

            if (!String.IsNullOrEmpty(role) && Security.CurrentAccountID != We7Helper.EmptyGUID)
            {
                List <string> actids = helper.GetRolesOfAccount(Security.CurrentAccountID);
                bool          flag   = false;
                if (actids != null)
                {
                    foreach (string s in actids)
                    {
                        if (s == role.Trim('{', '}'))
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                ddlDepartment.Enabled = flag;
            }

            if (!String.IsNullOrEmpty(Control.Width))
            {
                ddlDepartment.Width = Unit.Parse(Control.Width);
            }
            if (!String.IsNullOrEmpty(Control.Height))
            {
                ddlDepartment.Height = Unit.Parse(Control.Height);
            }

            ddlDepartment.CssClass = Control.CssClass;
            if (Control.Required && !ddlDepartment.CssClass.Contains("required"))
            {
                ddlDepartment.CssClass += " required";
            }
        }