Пример #1
0
        public IList <T_importacao_modelo_tandem_urs> ReadFile_TandemUniversal(string filePath, int idImport = -1)
        {
            var sheet = GetSheet(filePath, true, 1);

            var sheet0 = GetSheet(filePath, true, 1);

            var props = typeof(T_importacao_modelo_tandem_urs).GetProperties();
            var list  = new List <T_importacao_modelo_tandem_urs>();

            try
            {
                for (int row = T_importacao_modelo_tandem_urs.FirstRow;
                     row <= T_importacao_modelo_tandem_urs.FirstRow + T_importacao_modelo_tandem_urs.CountRowsBlock; row++)
                {
                    var obj = new T_importacao_modelo_tandem_urs()
                    {
                        id_t_importacao = idImport
                    };

                    foreach (var p in props)
                    {
                        var column = ((Column)p.GetCustomAttribute(typeof(Column)));
                        if (column == null)
                        {
                            continue;
                        }

                        if (p.PropertyType == typeof(Nullable <Double>) || p.PropertyType == typeof(Double))
                        {
                            p.SetValue(obj, GetNumericCellValue(sheet, row, column.Value, idImport));
                        }

                        else if (p.PropertyType == typeof(Nullable <int>) || p.PropertyType == typeof(int))
                        {
                            p.SetValue(obj, GetIntegerCellValue(sheet, row, column.Value, idImport));
                        }

                        else if (p.PropertyType == typeof(string))
                        {
                            p.SetValue(obj, GetStringCellValue(sheet0, sheet, row, column.Value));
                        }

                        else
                        {
                            string message = $"Get cell value não implementado para {p.PropertyType} da propriedade {p.Name} da classe T_importacao_modelo_tandem_urs";
                            throw new NotImplementedException(message);
                        }
                    }

                    ImportMultipleData <T_importacao_modelo_tandem_urs> .AddIfIsNotEmpty(list, obj);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }

            return(list);
        }
Пример #2
0
        public IList <T_importacao_modelo_bd> ReadFile_BD(string filePath, int idImport = -1)
        {
            var sheet = GetSheet(filePath);

            var    props = typeof(T_importacao_modelo_bd).GetProperties();
            var    list = new List <T_importacao_modelo_bd>();
            string indexValue, indexValueOld = string.Empty;
            bool   _continue = true;

            try
            {
                for (int row = T_importacao_modelo_bd.FirstRow; _continue; row++)
                {
                    var obj = new T_importacao_modelo_bd()
                    {
                        id_t_importacao = idImport
                    };

                    foreach (var p in props)
                    {
                        var column = ((Column)p.GetCustomAttribute(typeof(Column)));
                        if (column == null)
                        {
                            continue;
                        }

                        var round = ((Round)p.GetCustomAttribute(typeof(Round)));

                        if (p.PropertyType == typeof(Nullable <Double>) || p.PropertyType == typeof(Double))
                        {
                            p.SetValue(obj, GetNumericCellValue(sheet, row, column.Value, idImport, round?.Value));
                        }

                        else if (p.PropertyType == typeof(Nullable <int>) || p.PropertyType == typeof(int))
                        {
                            p.SetValue(obj, GetIntegerCellValue(sheet, row, column.Value, idImport));
                        }

                        else if (p.PropertyType == typeof(string))
                        {
                            indexValue = GetStringCellValue(sheet, sheet, row, column.Value);////****

                            if (p.Name.Equals("tipo_bd_value"))
                            {
                                if (string.IsNullOrWhiteSpace(indexValue))
                                {
                                    int result = (row - T_importacao_modelo_bd.FirstRow + 1) % T_importacao_modelo_bd.CountRowsBlock;

                                    if (result == 0)
                                    {
                                        var next_index_bd = sheet.GetRow(row + 1).GetCell(column.Value);

                                        if (next_index_bd == null || string.IsNullOrWhiteSpace(next_index_bd.ToString().Trim()))
                                        {
                                            _continue = false; continue;
                                        }
                                    }

                                    indexValue = indexValueOld;
                                }
                                indexValueOld = indexValue;
                            }

                            p.SetValue(obj, indexValue);
                        }
                        else
                        {
                            string message = $"Get cell value não implementado para {p.PropertyType} da propriedade {p.Name} da classe T_importacao_modelo_bd";
                            throw new NotImplementedException(message);
                        }
                    }
                    ImportMultipleData <T_importacao_modelo_bd> .AddIfIsNotEmpty(list, obj);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                throw new Exception(ex.Message);
            }

            return(list);
        }