Exemplo n.º 1
0
        public OutputData DoAction(IInputData input)
        {
            try
            {
                FileInfo info = input.PostObject.Convert <FileInfo>();
                if (string.IsNullOrEmpty(info.FileName))
                {
                    throw new WebPostException(string.Empty,
                                               new FieldErrorInfo("Import", "FileName", "没有文件,请上传Excel文件"));
                }

                ImportResultData result = new ImportResultData(fMetaData);
                ExcelImporter.ExcelImport(Context, info.ServerPath, fMetaData, result);
                var errorCollection = fResolver.Import(result.ImportDataSet, input);
                result.ImportFieldInfoError(errorCollection);
                result.SaveTemp();

                return(OutputData.CreateObject(result));
            }
            catch (WebPostException ex)
            {
                return(OutputData.CreateToolkitObject(ex.CreateErrorResult()));
            }
            catch (Exception ex)
            {
                return(OutputData.CreateToolkitObject(new WebErrorResult(ex.Message)));
            }
        }
Exemplo n.º 2
0
        public override OutputData DoAction(IInputData input)
        {
            string          source = input.QueryString["Source"];
            string          path   = Path.Combine(BaseAppSetting.Current.XmlPath, @"Import", source + ".xml");
            ImportConfigXml config = new ImportConfigXml();

            config.ReadXmlFromFile(path);
            string filePath = @"C:\Users\zll\Downloads\角色.xls";

            var             meta = config.Import.MetaData.CreateObject(input);
            Tk5ListMetaData data = meta as Tk5ListMetaData;

            var resolver = config.Import.Resolver.CreateObject(this);
            MetaDataTableResolver metaResolver = resolver as MetaDataTableResolver;

            TkDebug.AssertNotNull(metaResolver, "metaResolver", this);

            ImportError errResult = new ImportError();
            var         dataSet   = ExcelImporter.ExcelImport(filePath, data, errResult);
            FieldErrorInfoCollection importResult = metaResolver.Import(dataSet, input);

            if (importResult.Count > 0)
            {
                var positions = (from item in importResult
                                 orderby item.Position descending
                                 select item.Position).Distinct();

                foreach (var errorInfo in importResult)
                {
                    DataRow errorRow = dataSet.Tables[errorInfo.TableName].Rows[errorInfo.Position];

                    ImportWarningItem errorItem = new ImportWarningItem(errorRow["OriginalRowNum"].Value <int>(),
                                                                        resolver.GetFieldInfo(errorInfo.NickName).DisplayName, (string)errorRow[errorInfo.NickName], errorInfo.Message);
                    errResult.Add(errorItem);
                }

                foreach (var index in positions)
                {
                    resolver.HostTable.Rows.RemoveAt(index);
                }
            }

            DataSet webReport = null;

            if (errResult.Count > 0)
            {
                byte[] dataFile = ExcelUtil.ExcelReport(filePath, data, errResult);
                webReport = ExcelUtil.DataSetReport(filePath, data, errResult);
            }

            return(OutputData.CreateObject(new ImportResultData(DataSet, webReport, errResult)));
        }