Ejemplo n.º 1
0
        public void OpenFile()
        {
            _foundEntities = new List <T>();
            _exceptions    = new List <Exception>();


            if (_openFileService.ShowDialog(this) != true)
            {
                return;
            }

            FilePath = _openFileService.FileName;
            // 获取有效的Sheet表
            Dictionary <string, DataTable> foundSheets = ColumnNameMapping.GetValidExcelSheats(FilePath);

            _sheets = new Dictionary <string, DataTable>(_nameOfSheets.Count);

            foreach (var sheet in _nameOfSheets)
            {
                if (foundSheets.ContainsKey(sheet.Key))
                {
                    _sheets[sheet.Key]           = foundSheets[sheet.Key];
                    _sheets[sheet.Key].TableName = sheet.Key;
                    _sheets[sheet.Key].CheckColumnExist(sheet.Value); //检查sheet表中列是否存在
                    _sheets[sheet.Key].BlankRowsRemove();             //除去数据都为空的行
                    _sheets[sheet.Key].AsEnumerable().DuplicateCheckAndExtract(Validation, ValidationRow, DuplicateRow,
                                                                               CatchException);
                }
                if (foundSheets.Count == 0)
                {
                    _exceptions.Add(new Exception("档案格式有误!"));
                }
            }
            ReadingCompleted(_foundEntities);
        }
Ejemplo n.º 2
0
        private static Dictionary <PropertyInfo, string> getPropertyMapping <T>(List <string> columnNames, ColumnNameMapping[] customNameMappings)
        {
            Dictionary <PropertyInfo, string> mapping = new Dictionary <PropertyInfo, string>();
            T temp = System.Activator.CreateInstance <T>();
            IEnumerable <PropertyInfo> properties =
                from p in Utilities.GetProperties(temp)
                where p.CanWrite
                select p;

            using (IEnumerator <PropertyInfo> enumerator = properties.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    PropertyInfo property   = enumerator.Current;
                    string       columnName = null;
                    if (customNameMappings != null)
                    {
                        ColumnNameMapping columnNameMapping = customNameMappings.FirstOrDefault((ColumnNameMapping m) => property.Name == m.ColumnName);
                        if (columnNameMapping != null && columnNames.Contains(columnNameMapping.ColumnName))
                        {
                            columnName = columnNameMapping.ColumnName;
                        }
                    }
                    if (columnName == null)
                    {
                        columnName = columnNames.FirstOrDefault((string p) => property.Name.Equals(p.Pascalize(), System.StringComparison.CurrentCultureIgnoreCase));
                    }
                    mapping[property] = columnName;
                }
            }
            return(mapping);
        }
Ejemplo n.º 3
0
        private void Reading()
        {
            //run
            InvalidExcelFileFormat = !ColumnNameMapping.ReadAssignmentExcelSheets(FilePath, date => _dates.Add(new DateTerm(date, _dates.Count == 0 ? "{0:M/d}" : "{0:d }")
            {
                IsHoliday        = date.IsHoliday(Country.Local),
                IsDaylightSaving = date.IsDaylightSaving(TimeZoneInfo.Local)
            }), rows =>
            {
                Status           = "Running";
                ProcessInfo      = "Loading assignment types";
                Processing       = true;
                _assignmentTypes = _shiftDispatcherModel.GetAllShiftTypes().ToDictionary(o => o.Name);

                Processing   = false;
                ProcessInfo  = null;
                Process      = 0;
                TotalProcess = rows;
                _passedRows  = rows;
                _calendarEventModel.LoadGlobalCalendar(ImportRange.Start, ImportRange.End);
            }, ExamingItemArray, DuplicationRowFound, DuplicationCheck);

            //completed
            Status    = "Ready";
            _imported = false;

            NotifyOfPropertyChange(() => ImportRange);
            NotifyOfPropertyChange(() => Dates);
            NotifyOfPropertyChange(() => PassedRows);
            NotifyOfPropertyChange(() => UnreachableRows);
            NotifyOfPropertyChange(() => HasArrangedRows);
            NotifyOfPropertyChange(() => OperationFailRows);

            this.QuietlyReload(ref _bindableAgents, "BindableAgents");
        }