Exemple #1
0
        private string ImportFXRates(DataSet ds)
        {
            string res = String.Empty;

            //курсы пишутся через механизм импорта;
            //т.к. максимальное количество параметров в SQL запросе 2100, то пишется кусками по 1000 строк
            const int pageSize = 1000;
            DataSet   tempDataSet;
            DataTable tempDataTable;

            FormModel model = FormModelRepository.GetFormModel("FXRate", FormModelType.ImportExport);

            ds.Tables[0].Columns[CurrencyCodeColumnName].ColumnName = "Currency";
            ds.Tables[0].TableName = model.Caption.Replace(" ", "_");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i = i + pageSize)
            {
                tempDataSet             = new DataSet();
                tempDataTable           = new DataTable();
                tempDataTable           = ds.Tables[0].AsEnumerable().Skip(i).Take(pageSize).CopyToDataTable();
                tempDataTable.TableName = ds.Tables[0].TableName;
                tempDataSet.Tables.Add(tempDataTable);

                ImportResult result = ImportExportHelper.Import(model.MainViewName, tempDataSet);
                res += result.GetReport(new ImportResultTextFormatter()) + Environment.NewLine;
            }

            return(res);
        }
        public ActionResult UploadExcel(string name, string type = "Xlsx")
        {
            var fileName = Guid.NewGuid().ToString("N");

            var filePath = Server.MapPath(Settings.Current["TemporaryFolderForImportExport"]);

            ExcelType excelType;

            ExcelType.TryParse(type, true, out excelType);

            try
            {
                if (Request.Files.Count != 1 || Request.Files[0] == null)
                {
                    return new ContentResult
                           {
                               ContentType = "text/html",
                               Content     = DynamicEntityJSONDataSource.GetNotSuccess("Неверное количество файлов в запросе.")
                           }
                }
                ;


                var ds = ExcelHelper.FromExcel(Request.Files[0].InputStream, fileName, filePath, excelType);


                var result = ImportExportHelper.Import(name, ds);

                var report = result.GetReport(new ImportResultTextFormatter());


                return(new ContentResult
                {
                    ContentType = "text/html",
                    Content = DynamicEntityJSONDataSource.GetSuccess(report.Replace("\r\n", "&lt;/br&gt;"))
                });
            }
            catch (OptimaJet.DynamicEntities.Exceptions.DynamicEntitiesConvertException ex)
            {
                string msg = String.Format("{0}: {1}.", LocalizationProvider.Provider.Get("Error of template loading"),
                                           LocalizationProvider.Provider.Get("Incorrect format of fields in file"));

                Logger.Log.Error(ex.Message, ex);
                return(new ContentResult
                {
                    ContentType = "text/html",
                    Content = DynamicEntityJSONDataSource.GetNotSuccess(msg)
                });
            }
            catch (Exception ex)
            {
                Logger.Log.Error(LocalizationProvider.Provider.Get("Error of template loading") + " " + name, ex);
                return(new ContentResult
                {
                    ContentType = "text/html",
                    Content = DynamicEntityJSONDataSource.GetNotSuccess(ex.Message)
                });
            }
            finally
            {
                try
                {
                    var fullName = ExcelHelper.GetFullFilePath(fileName, filePath, excelType);

                    if (System.IO.File.Exists(fullName))
                    {
                        System.IO.File.Delete(fullName);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log.Error("Ошибка удаления временного файла", ex);
                }
            }
        }
Exemple #3
0
        public async Task <SaveAllSpecies> Import()
        {
            SaveAllSpecies import = await ImportExportHelper.Import();

            return(import);
        }