示例#1
0
 public ImportController(CadSysContext _context, IRepo _repo, IExcelConfigurationRepo _excelConfiguration, ServiceBuilder _serviceBuilder)
 {
     context            = _context;
     repo               = _repo;
     excelConfiguration = _excelConfiguration;
     serviceBuilder     = _serviceBuilder;
     dXFRepo            = (IFileRepo)serviceBuilder.GetService("DXFRepo");
 }
示例#2
0
 public ProcessController(DropBoxBase _dropBox, CadSysContext _context, IRepo _repo, IExcelConfigurationRepo _excelConfiguration, ServiceBuilder serviceBuilder)
 {
     dropBox            = _dropBox;
     context            = _context;
     repo               = _repo;
     excelConfiguration = _excelConfiguration;
     dxfRepo            = (IFileRepo)serviceBuilder.GetService("DXFRepo");
     excelRepo          = (IFileRepo)serviceBuilder.GetService("ExcelRepo");
 }
示例#3
0
 public ExportController(CadSysContext _context, IExcelConfigurationRepo _excelConfiguration, ServiceBuilder _serviceBuilder, IExporter _cadGenExporter, IHubContext <MessagesHub> _hubContext, DropBoxBase _dropBoxBase)
 {
     context            = _context;
     excelConfiguration = _excelConfiguration;
     dXFRepo            = (IFileRepo)_serviceBuilder.GetService("DXFRepo");
     cadGenExporter     = _cadGenExporter;
     hubContext         = _hubContext;
     dropBoxBase        = _dropBoxBase;
 }
示例#4
0
        public static Task <List <List <T> > > GetGroupedDTOs <T>(MemoryStream stream, string fileName, ImportConfig config, IExcelConfigurationRepo excelConfig) where T : Output, new()
        {
            return(Task.Run(() =>
            {
                stream.Position = 0;

                IWorkbook wbk;

                if (fileName.EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase))
                {
                    wbk = new HSSFWorkbook(stream); //This will read 2007 Excel format
                }
                else if (fileName.EndsWith(".xlsx", StringComparison.InvariantCultureIgnoreCase))
                {
                    wbk = new XSSFWorkbook(stream);
                }
                else
                {
                    throw new Exception("This format is not supported");
                }

                var sheet = wbk.GetSheetAt(0);    //get first sheet from workbook

                IRow headerRow = sheet.GetRow(0); //Get Header Row

                var columnNames = Utils.GetColumnNames(headerRow);

                excelConfig.Save(1, typeof(T).Name, fileName, columnNames);

                var result = new List <List <T> >();

                var miniResult = new List <T>();

                var firstRow = sheet.FirstRowNum;
                var lastRow = sheet.LastRowNum;

                for (int i = (firstRow + 1); i <= lastRow; i++) //Read Excel File
                {
                    var row = sheet.GetRow(i);

                    try
                    {
                        if (miniResult.Count > 0 && (row == null || row.All(x => x.CellType == CellType.Blank)))
                        {
                            result.Add(miniResult);
                            miniResult = new List <T>();
                        }
                        else
                        {
                            if (row != null && row.Any(x => x.CellType != CellType.Blank))
                            {
                                miniResult.Add(GetDTO <T>(row, columnNames.ToList(), i));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                }

                if (miniResult.Count > 0)
                {
                    result.Add(miniResult);
                }

                return result;
            }));
        }
示例#5
0
        public static Task <ConcurrentBag <T> > GetDTOs <T>(MemoryStream stream, string fileName, ImportConfig config, IExcelConfigurationRepo excelConfig) where T : Output, new()
        {
            return(Task.Run(() =>
            {
                var result = new ConcurrentBag <T>();

                stream.Position = 0;

                IWorkbook wbk;

                if (fileName.EndsWith(".xls", StringComparison.InvariantCultureIgnoreCase))
                {
                    wbk = new HSSFWorkbook(stream); //This will read 2007 Excel format
                }
                else if (fileName.EndsWith(".xlsx", StringComparison.InvariantCultureIgnoreCase))
                {
                    wbk = new XSSFWorkbook(stream);
                }
                else
                {
                    throw new Exception("This format is not supported");
                }

                var sheet = wbk.GetSheetAt(0);    //get first sheet from workbook

                IRow headerRow = sheet.GetRow(0); //Get Header Row

                var columnNames = Utils.GetColumnNames(headerRow);

                excelConfig.Save(1, typeof(T).Name, fileName, columnNames);

                var firstRow = sheet.FirstRowNum;
                var lastRow = sheet.LastRowNum;

                for (int i = (firstRow + 1); i <= lastRow; i++) //Read Excel File
                {
                    var row = sheet.GetRow(i);

                    if (row == null && config.IgnoreNullRows)
                    {
                        continue;
                    }
                    try
                    {
                        if (row.All(x => x == null || string.IsNullOrEmpty(x.ToString())))
                        {
                            continue;
                        }
                    }
                    catch
                    {
                        System.Diagnostics.Debugger.Break();
                    }
                    result.Add(GetDTO <T>(row, columnNames.ToList(), i));
                }

                return result;
            }));
        }
示例#6
0
 public HomeController(IExcelConfigurationRepo _excelConfig, ServiceBuilder _serviceBuilder)
 {
     excelConfig = _excelConfig;
     dXFRepo     = (IFileRepo)_serviceBuilder.GetService("DXFRepo");
 }