// -----------------------------------------------------------------------------------------
        // Rows=[Value], ColumnDefinitions=[Tech-Name, Name, Width-Percentage, Row-Field-Extractor]
        public void PageWriteTable <TRow>(string ClassName, IRecognizableComposite SourceOwner, IEnumerable <TRow> Rows,
                                          params Capsule <string, string, double, Func <TRow, IMModelClass> >[] ColumnDefinitions)
            where TRow : IMModelClass
        {
            var Records = Rows.Select(
                row =>
            {
                var Values = new List <string>();

                // Travel Colum-Defs...
                foreach (var ColValueDef in ColumnDefinitions)
                {
                    var Entity = (ColValueDef.Value3 == null
                                              ? row : ColValueDef.Value3(row));

                    var Spec = "";
                    if (Entity != null)
                    {
                        var ColDef = Entity.ClassDefinition.GetPropertyDef(ColValueDef.Value0, false);

                        var Value = (ColDef == null ? null : ColDef.Read(Entity));
                        Spec      = GetRecordValueAsHtmlString(Value, SourceOwner, row);
                    }

                    Values.Add(Spec);
                }

                return((IEnumerable <string>)Values);
            });

            var ColDefs = ColumnDefinitions.Select(
                def => Capsule.Create(def.Value0, def.Value1, def.Value2)).ToArray();

            this.PageWriteTable(ClassName, Records, ColDefs);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initialize a new <see cref="GridLayout"/> instance from the column definitions.
 /// The instance doesn't care about whether the definitions are rows or columns.
 /// It will not calculate the column or row differently.
 /// </summary>
 internal GridLayout([NotNull] ColumnDefinitions columns)
 {
     if (columns == null)
     {
         throw new ArgumentNullException(nameof(columns));
     }
     _conventions = columns.Count == 0
         ? new List <LengthConvention> {
         new LengthConvention()
     }
         : columns.Select(x => new LengthConvention(x.Width, x.MinWidth, x.MaxWidth)).ToList();
 }
Exemplo n.º 3
0
 protected override IReadOnlyList <OracleColumn> BuildColumns()
 {
     return(ColumnDefinitions.Select(c => c.ColumnDescription).ToArray());
 }
Exemplo n.º 4
0
        public override void ExecuteResult(ControllerContext context)
        {
            using (var pck = new ExcelPackage())
            {
                var ws = pck.Workbook.Worksheets.Add(WorksheetName);

                if (ColumnDefinitions == null)
                {
                    ws.Cells["A1"].LoadFromCollection(_records, true, TableStyles.None);
                }
                else
                {
                    ws.Cells["A1"].LoadFromCollection(_records, true, TableStyles.None, BindingFlags.Default, ColumnDefinitions.Select(x => x.MemberInfo).ToArray());
                    Format(ws, ColumnDefinitions);
                }

                const string contentType       = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                var          fileContentResult = new FileContentResult(pck.GetAsByteArray(), contentType)
                {
                    FileDownloadName = FileDownloadName
                };
                fileContentResult.ExecuteResult(context);
            }
        }
Exemplo n.º 5
0
 private string GenerateScriptFromColumnDefinitions()
 {
     return(string.Join(RowColumnScriptPartJoinDelimiter, CompactStringDefinition(ColumnDefinitions.Select(cd => RowColumnDefinition.FromColumnDefinition(cd).ToString()))));
 }
Exemplo n.º 6
0
        public virtual void EndInit()
        {
            //==============================================
            //              创建过滤条件
            //==============================================
            AllFilters = new List <FilterControlBase>();

            foreach (FilterDefinition fd in FilterDefinitions)
            {
                FilterControlBase fc = (FilterControlBase)Activator.CreateInstance(fd.FilterControlType, true);
                fc.DataPropertyName = fd.DataPropertyName;
                fc.Title            = fd.Title;
                if (!fd.FilterOperator.IsNullOrWhiteSpace())
                {
                    fc.FilterOperator = fd.FilterOperator;
                }
                fc.Parent = pFilters;
                AllFilters.Add(fc);
            }
            //==============================================
            //                  创建表格
            //==============================================

            //空白组默认设置为页面标题
            ColumnDefinitions.ForEach(c => { if (c.GroupName.IsNullOrWhiteSpace())
                                             {
                                                 c.GroupName = Text;
                                             }
                                      });

            //创建Tab页
            tabContainer.TabPages.Clear();
            var queryGroups = ColumnDefinitions.Select(c => c.GroupName).Distinct().ToArray();

            foreach (string g in queryGroups)
            {
                tabContainer.TabPages.Add(g);
                //创建表格
                GridViewer dgv = new GridViewer();

                //添加列
                foreach (var col in ColumnDefinitions.Where(c => c.GroupName == g))
                {
                    dgv.CreateColumn(col.ColumnType, col.Title, col.DataPropertyName, col.Name, col.Width, col.SortMode, col.SortOrder, col.Visible, col.Index, col.Frozen);
                }
                dgv.Dock   = DockStyle.Fill;
                dgv.Parent = tabContainer.TabPages[tabContainer.TabCount - 1];

                //TODO: 暂不支持排序
            }

            //只有一个表格则不显示TabControl
            if (tabContainer.TabPages.Count == 1)
            {
                Control dgv = tabContainer.TabPages[0].Controls[0];
                dgv.Parent = this;
                Controls.Remove(tabContainer);
                tabContainer = null; //dispose
                dgv.BringToFront();
            }

            //所有表格
            AllGridView = this.FindChildControl(c => c is DataGridView).OfType <DataGridView>().ToList();

            //==============================================
            //               生成Select语句
            //==============================================
            var query = from dgv in AllGridView
                        from col in dgv.Columns.OfType <DataGridViewColumn>()
                        where !col.DataPropertyName.IsNullOrWhiteSpace()
                        select col.DataPropertyName;

            List <string> fields = new List <string>();

            foreach (string col in query.Distinct())
            {
                fields.Add("[{0}] AS '{1}'".FormatWith(col.Replace(".", "].["), col));
            }

            Sentence_Select = string.Join(", ", fields.ToArray());

            //==============================================
            //          关联表格的选择及滚动
            //==============================================
            if (AllGridView.Count > 1)
            {
                DataGridView dgv = AllGridView[0];

                for (int i = 1; i < AllGridView.Count; i++)
                {
                    DataGridView tmp = AllGridView[i];
                    dgv.SyncSelectedRowIndex(tmp);
                    dgv.SyncRowHeight(tmp);
                    dgv.SyncVerticalScroll(tmp);
                }
            }

            //==============================================
            //                  注册表格事件
            //==============================================
            //注册事件
            AllGridView.ForEach(d =>
            {
                d.ColumnHeaderMouseClick += ColumnHeaderMouseClick;
                d.SelectionChanged       += SelectionChanged;
                d.CellDoubleClick        += CellDoubleClick;
            });
        }