示例#1
0
 public void Initialize <T>(
     // 给定一个 加载器,用于给 ButtonEdit 控制
     ControlLoader loader,
     // 要加载的控件
     string controlPath,
     // 当下拉面板被拉下的时候(加载器,控件对象,输入框,是否第一次加载)
     Action <T, ASPxButtonEdit, HiddenField, bool> show,
     // 当值被选定的时候
     Func <T, ASPxButtonEdit, HiddenField, bool> set,
     // 清除值
     Action <ASPxButtonEdit> clear = null,
     // 额外配置 Loader
     Action <ControlLoader.Configurator <T> > config = null) where T : BaseControl
 {
     Initialize <T>(loader, controlPath, (b, h) => true, show, set, clear, config);
 }
示例#2
0
        public void Initialize <T>(
            // 给定一个 加载器,用于给 ButtonEdit 控制
            ControlLoader loader,
            // 要加载的控件
            string controlPath,
            // 检查事前条件
            Func <ASPxButtonEdit, HiddenField, bool> preShow,
            // 当下拉面板被拉下的时候(加载器,控件对象,输入框,是否第一次加载)
            Action <T, ASPxButtonEdit, HiddenField, bool> show,
            // 当值被选定的时候
            Func <T, ASPxButtonEdit, HiddenField, bool> set,
            // 清除值
            Action <ASPxButtonEdit> clear = null,
            // 额外配置 Loader
            Action <ControlLoader.Configurator <T> > config = null) where T : BaseControl
        {
            // 观察下拉按钮
            b.ValidationSettings.CausesValidation = false;
            b.ButtonClick += (s, e) =>
            {
                switch (e.ButtonIndex)
                {
                case 0:     // 弹出

                    // 事前检验
                    if (!preShow(BE, h))
                    {
                        return;
                    }

                    // 如果没有加载则进行加载
                    if (loader.HostingControl == null)
                    {
                        loader.Begin <T>(controlPath, null, c => show(c, b, h, true), config);
                    }
                    else
                    {
                        if (loader.HostingControl is T)
                        {
                            T c = loader.HostingControl as T;
                            show(c, b, h, false);

                            // -- 拷贝 loader 的实现片段 --
                            if (config != null)
                            {
                                loader.ForConfigurator <T>(config, null, new ControlLoader.Configurator <T>(c, loader));
                                loader.ForConfigurator <T>(cc =>
                                {
                                    if (cc.FooterLoaded)
                                    {
                                        return;                      // 已经在 configurator 中加载页脚
                                    }
                                    loader.LoadFooter <Loader.Footer>(execute: f =>
                                    {
                                        f.SpecifyButtonSetting(cc.Buttons);
                                        f.Execute();
                                    });
                                }, () =>
                                {
                                    loader.LoadFooter <Loader.Footer>(execute: f => f.Execute());
                                });
                            }

                            // 重新展示
                            loader.Show();
                        }
                        else
                        {
                            loader.Begin <T>(controlPath, null, c => show(c, b, h, true), config);
                        }
                    }

                    break;

                case 1:     // 点击编辑按钮

                    if (clear != null)
                    {
                        clear(b);
                    }
                    else
                    {
                        Text = Value = null;
                    }

                    break;
                }
            };

            // 观察 Loader 的状态,捕获 OK 事件
            loader.EventSinked += (c, eType, param) =>
            {
                if (eType == EventTypes.OK)
                {
                    if (loader.HostingControl is T)
                    {
                        if (set((loader.HostingControl as T), b, h))
                        {
                            loader.Close();
                        }
                    }
                }
            };
        }
示例#3
0
文件: BasePage.cs 项目: zdtx/zdtx
        /// <summary>
        /// Linq 数据导出Excel表格
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="section">标识,例如 Contract,InStorage,等,与 Export 子目录同</param>
        /// <param name="data"></param>
        /// <param name="headers"></param>
        protected virtual string _ExportToExcel <T>(
            string prefix, List <T> data, string[] headers, Controls.ControlLoader pop = null)
        {
            PropertyInfo[] properties = typeof(T).GetProperties();
            if (headers.Length < properties.Length)
            {
                throw new ArgumentException("表头数量不够,请检查", "headers");
            }
            if (headers.Distinct().Count() < headers.Length)
            {
                throw new ArgumentException("表头命名不能重复,请检查", "headers");
            }

            var ds     = new DataSet();
            var tb     = ds.Tables.Add();
            var folder = "____temp/export";

            // 放表头
            for (int i = 0; i < properties.Length; i++)
            {
                tb.Columns.Add(new DataColumn()
                {
                    Caption     = headers[i],
                    ColumnName  = properties[i].Name,
                    DataType    = properties[i].PropertyType,
                    AllowDBNull = true
                });
            }

            // 放数据
            data.ForEach(d =>
            {
                var row = tb.NewRow();
                for (int i = 0;
                     i < properties.Length; i++)
                {
                    row[i] = properties[i].GetValue(d, null);
                }
                tb.Rows.Add(row);
            });

            ds.AcceptChanges();
            var file = string.Format("{0}_{1}.xls", prefix, Guid.NewGuid().ToISFormatted()).ToLower();
            var path = Util.GetPhysicalPath(folder);

            new ExportExcel().ExportExcelData(path, file, tb);
            if (pop == null)
            {
                return(file);
            }
            pop.Begin <Controls.MessagePanel>("~/_controls.helper/messagepanel.ascx",
                                              null, c =>
            {
                var l = new WebUI.HyperLink()
                {
                    CssClass    = "aBtn",
                    Text        = "点击此处下载 / 浏览",
                    Target      = "_blank",
                    NavigateUrl = string.Format("~/{0}/{1}", folder, file)
                };
                l.Font.Bold = true;
                l.Font.Size = 12;
                c.MessageBody.Controls.Add(l);
                c.Title = "成功";
            }, c =>
            {
                c
                .Width(400)
                .Height(300)
                .Title("文件导出")
                ;
            });
            return(file);
        }
示例#4
0
文件: BasePage.cs 项目: zdtx/zdtx
 protected virtual string _ExportToExcel <T, TSource>(string section, List <TSource> data,
                                                      string[] headers, Func <TSource, T> itemGet, Controls.ControlLoader pop = null)
 {
     return(_ExportToExcel <T>(section, Exp <T> .Transform(data, itemGet), headers, pop));
 }
示例#5
0
 public Configurator(T control, ControlLoader loader)
 {
     _Loader  = loader;
     _Control = control;
 }