示例#1
0
        private void PickUp(object o, string prefix, string label, DCInfo info)
        {
            //反射元标记MetaData,筛选[属性名/ParameterAttribute]键值对
            Dictionary <string, ParameterAttribute> dictParams = BaseControlHelper.FilterParamAttrs(o, prefix);

            //获取DataControlParameters集合
            DCPartInfo part = CreateDCPart(info, label);

            part.Params = GetDataControlParameters(dictParams);

            //排序
            SortParam(part);
        }
示例#2
0
        /// <summary>
        /// 取得指定目录下的控件
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="prefixPath">前置目录 Weidget/We7Controls</param>
        private void LoadDataControls(List <DataControlInfo> controls, string dir, string prefixPath, string group)
        {
            DirectoryInfo di = new DirectoryInfo(dir);

            if (!di.Exists)
            {
                return;
            }

            DirectoryInfo[] cdi = di.GetDirectories();
            DataControlInfo dci = new DataControlInfo();

            for (int i = 0; i < cdi.Length; i++)
            {
                try
                {
                    FileInfo[] fs = cdi[i].GetFiles("*.ascx");
                    if (fs != null && fs.Length > 0)
                    {
                        // DataControlInfo dci = new DataControlInfo();
                        dci.Group = group;

                        foreach (FileInfo fileInfo in fs)
                        {
                            string virtualPath = string.Format("{0}/{1}/{2}", prefixPath, cdi[i].Name, fileInfo.Name);
                            //获取控件上的描述属性,组描述属性
                            DataControl ctrl = BaseControlHelper.GetDataControlInfo(virtualPath);
                            if (ctrl != null)
                            {
                                ctrl.FileName = virtualPath;
                                ctrl.Name     = fileInfo.Name.Replace(".ascx", "");
                                dci.Controls.Add(ctrl);

                                //组描述设置
                                if (string.IsNullOrEmpty(dci.GroupLabel) && !string.IsNullOrEmpty(ctrl.GroupLabel))
                                {
                                    dci.GroupLabel = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1));
                                }
                                if (string.IsNullOrEmpty(dci.GroupIcon) && !string.IsNullOrEmpty(ctrl.GroupIcon))
                                {
                                    dci.GroupIcon = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1));
                                }
                                if (string.IsNullOrEmpty(dci.GroupDesc) && !string.IsNullOrEmpty(ctrl.GroupDesc))
                                {
                                    dci.GroupDesc = prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1));
                                }
                                if (string.IsNullOrEmpty(dci.GroupDefaultType) && !string.IsNullOrEmpty(ctrl.GroupDefaultType))
                                {
                                    dci.GroupDefaultType = ctrl.GroupDefaultType;
                                }
                            }
                        }
                        if (dci.Controls != null && dci.Controls.Count > 0)
                        {
                            //Default.ascx放前面,排序
                            dci.Controls.Sort(SortDataControl);
                            dci.DefaultControl = dci.Controls[0];
                            dci.Default        = dci.Controls[0].Name;
                            // dci.Name = dci.Controls[0].Name.Split('.')[0];
                            dci.Desc = dci.Controls[0].Description;
                            if (string.IsNullOrEmpty(dci.Name))
                            {
                                dci.Name = new CNspellTranslator().GetSpells(prefixPath.Substring(prefixPath.LastIndexOf('/') + 1, prefixPath.Length - (prefixPath.LastIndexOf('/') + 1))) + DateTime.Now.Ticks;
                            }
                            if (string.IsNullOrEmpty(dci.GroupLabel))
                            {
                                dci.GroupLabel = dci.Desc;
                            }
                            if (string.IsNullOrEmpty(dci.GroupIcon))
                            {
                                dci.GroupIcon = dci.Desc;
                            }
                            if (string.IsNullOrEmpty(dci.GroupDesc))
                            {
                                dci.GroupDesc = dci.Desc;
                            }
                            if (string.IsNullOrEmpty(dci.GroupDefaultType))
                            {
                                dci.GroupDefaultType = dci.Default;
                            }
                            else
                            {
                                //验证默认控件是否存在
                                string filePath = string.Format("{0}\\{1}.ascx", cdi[i].FullName, dci.GroupDefaultType);
                                if (!File.Exists(filePath))
                                {
                                    dci.GroupDefaultType = dci.Default;
                                }
                            }
                        }
                    }
                    else
                    {
                        LoadDataControls(controls, cdi[i].FullName, prefixPath + "/" + cdi[i].Name, group);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            if (dci != null && dci.Controls.Count > 0)
            {
                controls.Add(dci);
            }
        }