示例#1
0
        public byte[] GenerateReport(List <object> itemList, GridConfigurationBase gridConfig)
        {
            List <GridColumnBase> columnList = gridConfig.GridColumnBases.Where(x => !x.KeyColumn).ToList();

            this.Columns = GetColumns(columnList.Count());

            using (var workbook = new XLWorkbook())
            {
                IXLWorksheet ws = workbook.Worksheets.Add("Info General");

                CreateHeader(columnList, ws);

                foreach (object obj in itemList)
                {
                    int file = itemList.IndexOf(obj) + 2;
                    foreach (GridColumnBase cName in columnList)
                    {
                        int column = columnList.IndexOf(cName);
                        var value  = GridColumnBase.GetKeyValue(obj, cName.PropertyInfo);
                        ws.Cell($"{Columns[column]}{file}")
                        .Value = value;
                    }
                }

                ws.Columns().AdjustToContents();


                using (var ms = new MemoryStream())
                {
                    workbook.SaveAs(ms);
                    return(ms.ToArray());
                }
            }
        }
示例#2
0
        public async Task CreateGridSearch(GridColumnBase gridColumn, List <string> options)
        {
            SearchSelect   = options;
            SearchProperty = gridColumn.PropertyInfo;
            SearchPropName = gridColumn.Name;
            SearchText     = "";
            SearchPropType = await Task.Run(() => GetSearchPropertyType(gridColumn));

            DialogOpen = true;
        }
示例#3
0
        public CellContexMenuOption(GridColumnBase gridColumn, object context, string urlFolder)
        {
            GridColumn  = gridColumn;
            RowValues   = context;
            OneItemList = new List <object>();
            OneItemList.Add(RowValues);
            string keyValue = GridColumnBase.GetKeyValue(context, context.GetType().GetProperty(gridColumn.KeyColumnName)).ToString();

            gridColumn.InitializeContextMenuOptions(keyValue, urlFolder);
        }
示例#4
0
 private PropertyType GetSearchPropertyType(GridColumnBase gridColumn)
 {
     if (SearchProperty != null)
     {
         PropertyType searchType = gridColumn.PropertyType;
         if (searchType != PropertyType.datetime && SearchSelect != null && SearchSelect.Any())
         {
             SearchText = SearchSelect.OrderBy(x => x).FirstOrDefault();
             searchType = PropertyType.list;
         }
         return(searchType);
     }
     return(PropertyType.noType);
 }
示例#5
0
        private XLDataType GetDataType(GridColumnBase gridColumn)
        {
            PropertyType propertyType = gridColumn.PropertyType;

            switch (propertyType)
            {
            case PropertyType.number:
                return(XLDataType.Number);

            case PropertyType.datetime:
                return(XLDataType.DateTime);

            default:
                return(XLDataType.Text);
            }
        }
示例#6
0
        private static string GetColumnsNames(List <GridColumnBase> columnList, System.Data.DataTable dataResult, IXLRow row)
        {
            string readRange = string.Format("{0}:{1}", 1, row.LastCellUsed().Address.ColumnNumber);

            foreach (IXLCell cell in row.Cells(readRange))
            {
                GridColumnBase gridColumn = columnList.FirstOrDefault(x => x.Name == cell.Value.ToString());
                if (gridColumn != null)
                {
                    var columName = gridColumn.PropertyInfo.Name;
                    dataResult.Columns.Add(columName);
                }
                else
                {
                    throw new System.Exception($"Column Name {cell.Value.ToString()} does not match any property in object");
                }
            }

            return(readRange);
        }