示例#1
0
 private void Initialize()
 {
     foreach (var item in SpreadsheetReader.ReadSheetNames(this.path))
     {
         var viewModel = new SheetTreeViewItemViewModel(item)
         {
             Parent = this
         };
     }
 }
示例#2
0
        private void ReadTables(CremaDataSet dataSet, IDataBase dataBase, string filename, string itemNames)
        {
            var sheetNames = SpreadsheetReader.ReadSheetNames(filename);
            var tableInfos = dataBase.Dispatcher.Invoke(() =>
            {
                var query = from table in dataBase.TableContext.Tables
                            let tableName2 = SpreadsheetUtility.Ellipsis(table.Name)
                                             join sheetName in sheetNames on tableName2 equals sheetName
                                             where table.Name.GlobMany(itemNames) || table.Path.GlobMany(itemNames)
                                             orderby table.Name
                                             select table.TableInfo;

                return(query.ToArray());
            });

            var typeInfos = dataBase.Dispatcher.Invoke(() =>
            {
                var query = from table in dataBase.TableContext.Tables
                            let tableName2 = SpreadsheetUtility.Ellipsis(table.Name)
                                             join sheetName in sheetNames on tableName2 equals sheetName
                                             where table.Name.GlobMany(itemNames) || table.Path.GlobMany(itemNames)
                                             from column in table.TableInfo.Columns
                                             where CremaDataTypeUtility.IsBaseType(column.DataType) == false
                                             let type = dataBase.TypeContext[column.DataType] as IType
                                                        where type != null
                                                        select type.TypeInfo;

                return(query.Distinct().ToArray());
            });

            foreach (var item in typeInfos)
            {
                dataSet.Types.Add(item);
            }

            foreach (var item in tableInfos)
            {
                if (item.TemplatedParent != string.Empty)
                {
                    continue;
                }
                if (item.ParentName == string.Empty)
                {
                    dataSet.Tables.Add(item);
                }
                else
                {
                    dataSet.Tables[item.ParentName].Childs.Add(item);
                }
            }

            foreach (var item in tableInfos)
            {
                if (item.TemplatedParent != string.Empty && item.ParentName == string.Empty)
                {
                    var dataTable = dataSet.Tables[item.TemplatedParent];
                    dataTable.Inherit(item.TableName);
                }
            }

            var progress = new ConsoleProgress(this.Out)
            {
                Style = ConsoleProgressStyle.None
            };

            using (var reader = new SpreadsheetReader(filename))
            {
                reader.Read(dataSet, progress);
            }
        }