Пример #1
0
        public DTResultadoOperacionModel <List <DTMaestroUsuario> > ConsultarRolModalidadUsuario(string Usuario)
        {
            DTMaestroUsuario _DTMU = new DTMaestroUsuario();
            DTResultadoOperacionModel <List <DTMaestroUsuario> > Resultado = new DTResultadoOperacionModel <List <DTMaestroUsuario> >();
            List <DTMaestroUsuario> _DTUsuario = new List <DTMaestroUsuario>();

            try
            {
                Parametros.Add(new Parameter("@IN_Usuario", Usuario));
                DataTable DT_Usuarios = null;//DMAccesoDatos.EjecutarDataSetWithDataTable(ProcedimientosAlmacenados.Sp_ListarRolesModalidades, Parametros);
                _DTUsuario = ConvertData.ConvertirDtoToList <DTMaestroUsuario>(DT_Usuarios);

                if (_DTUsuario != null)
                {
                    Resultado.Respuesta = true;
                    Resultado.Resultado = _DTUsuario;
                }
                else
                {
                    Resultado.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE001);
                    Resultado.Respuesta = false;
                }
            }
            catch (Exception ex)
            {
                GestorLog.RegistrarLogExcepcion(ex);
            }
            return(Resultado);
        }
        public DTResultadoOperacionModel <DTMaestroUsuario> ConsultarUsuario(string _UsuarioWindows)
        {
            DTResultadoOperacionModel <DTMaestroUsuario> resultado = new DTResultadoOperacionModel <DTMaestroUsuario>();

            try
            {
                DTMaestroUsuario _Usuario = new DTMaestroUsuario();

                _Usuario.Usuario = _UsuarioWindows.Split('\\').Last();
                resultado        = new DMLayout().ConsultarUsuario(_Usuario.Usuario);
                if (resultado != null)
                {
                    if (resultado.Resultado.IdUsuario != 0)
                    {
                        resultado.Respuesta = true;
                    }
                    else
                    {
                        resultado.Respuesta = false;
                        resultado.Resultado = _Usuario;
                        resultado.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE021);
                    }
                }
            }
            catch (Exception ex)
            {
                GestorLog.RegistrarLogExcepcion(ex);
                resultado.Mensaje = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE001);
                throw ex;
            }
            return(resultado);
        }
        public ActionResult DescargarPlantilla()
        {
            string RutaPlantilla = ConfigurationManager.AppSettings.Get("PlantillaSolped");
            DTResultadoOperacionModel <string> _DTResultadoModel = new DTResultadoOperacionModel <string>();

            if (System.IO.File.Exists(Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory) + RutaPlantilla))
            {
                string SubRutaActual = Request.RawUrl;
                string RutaCompleta  = Request.Url.OriginalString.ToString();
                var    RutaFilal     = RutaCompleta.Replace(SubRutaActual, "");


                _DTResultadoModel.Resultado = RutaPlantilla.Replace("\\", "//");
                _DTResultadoModel.Respuesta = true;
            }
            else
            {
                _DTResultadoModel.Mensaje = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE013);
            }
            return(Json(_DTResultadoModel, JsonRequestBehavior.AllowGet));
        }
        public string ValidarArchivo(string Plantilla)
        {
            DTResultadoOperacionModel <DTSolped>       DTResultadoModel      = new DTResultadoOperacionModel <DTSolped>();
            DTResultadoOperacionModel <DTErroresExcel> DTResultadoModelCarga = new DTResultadoOperacionModel <DTErroresExcel>();

            //int ConEliminacion = 0;

            try
            {
                DTExcel             _Plantilla = JsonConvert.DeserializeObject <DTExcel>(Plantilla);
                List <DTFilasExcel> filas      = _Plantilla.sheets.First().rows;
                if (filas.Count > 1)
                {
                    //Validar el encabezado
                    List <DTColumnasExcel> columnas = filas.First().cells;

                    if (columnas[0].value.ToString().Trim() == DTEstructuraSolped.SolNro &&
                        columnas[1].value.ToString().Trim() == DTEstructuraSolped.NroOC &&
                        columnas[2].value.ToString().Trim() == DTEstructuraSolped.LineaPedido &&
                        columnas[3].value.ToString().Trim() == DTEstructuraSolped.NroArticulos &&
                        columnas[4].value.ToString().Trim() == DTEstructuraSolped.NroSPE &&
                        columnas[5].value.ToString().Trim() == DTEstructuraSolped.HACAT &&
                        columnas[6].value.ToString().Trim() == DTEstructuraSolped.PersonaSolicitud &&
                        columnas[7].value.ToString().Trim() == DTEstructuraSolped.FechaEnvio &&
                        columnas[8].value.ToString().Trim() == DTEstructuraSolped.Estado &&
                        columnas[9].value.ToString().Trim() == DTEstructuraSolped.Tipo &&
                        columnas[10].value.ToString().Trim() == DTEstructuraSolped.Articulo &&
                        columnas[11].value.ToString().Trim() == DTEstructuraSolped.Cantidad &&
                        columnas[12].value.ToString().Trim() == DTEstructuraSolped.TotalLinea &&
                        columnas[13].value.ToString().Trim() == DTEstructuraSolped.CodigoIVA &&
                        columnas[14].value.ToString().Trim() == DTEstructuraSolped.CuadroCuentas &&
                        columnas[15].value.ToString().Trim() == DTEstructuraSolped.PersonaCreador &&
                        columnas[16].value.ToString().Trim() == DTEstructuraSolped.FechaPedido &&
                        columnas[17].value.ToString().Trim() == DTEstructuraSolped.FechaCreacion &&
                        columnas[18].value.ToString().Trim() == DTEstructuraSolped.FechaEntrega &&
                        columnas[19].value.ToString().Trim() == DTEstructuraSolped.FechaCaducidad &&
                        columnas[20].value.ToString().Trim() == DTEstructuraSolped.Proveedor &&
                        columnas[21].value.ToString().Trim() == DTEstructuraSolped.Cuenta &&
                        columnas[22].value.ToString().Trim() == DTEstructuraSolped.IdOC &&
                        columnas[23].value.ToString().Trim() == DTEstructuraSolped.LeandingCostC &&
                        columnas[24].value.ToString().Trim() == DTEstructuraSolped.EstadoLinea &&
                        columnas[25].value.ToString().Trim() == DTEstructuraSolped.Divisa
                        )
                    {
                        List <DTFilasExcel> ConInformacion = (from dt in filas
                                                              where dt.cells.Count(x => x.value == null) != dt.cells.Count() &&
                                                              dt.index != 0
                                                              select dt).ToList();
                        if (ConInformacion.Count > 0)
                        {
                            BMSolped _BMSolped = new BMSolped();
                            DTResultadoModelCarga = _BMSolped.LeerArchivo(ConInformacion);
                        }
                        else
                        {
                            DTResultadoModelCarga.Respuesta = false;
                            DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                        }
                    }
                    else
                    {
                        DTResultadoModelCarga.Respuesta = false;
                        DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE002);
                    }
                }
                else
                {
                    DTResultadoModelCarga.Respuesta = false;
                    DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                }
            }
            catch (Exception ex)
            {
                DTResultadoModelCarga.Respuesta = false;
                DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE001);
                GestorLog.RegistrarLogExcepcion(ex);
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(DTResultadoModelCarga));
        }
Пример #5
0
        public string ValidarArchivo(string Plantilla, string NombreArchivo, int?Conf = 0)
        {
            string RutaArchivo = string.Empty;
            DTResultadoOperacionModel <DTAthena>       DTResultadoModel      = new DTResultadoOperacionModel <DTAthena>();
            DTResultadoOperacionModel <DTErroresExcel> DTResultadoModelCarga = new DTResultadoOperacionModel <DTErroresExcel>();
            int ConEliminacion = 0;

            try
            {
                DTExcel             _Plantilla = JsonConvert.DeserializeObject <DTExcel>(Plantilla);
                List <DTFilasExcel> filas      = _Plantilla.sheets.First().rows;
                if (filas.Count > 1)
                {
                    //Validar el encabezado
                    List <DTColumnasExcel> columnas = filas.First().cells;

                    if (columnas[0].value.ToString() == DTEstructuraAthena.Item &&
                        columnas[1].value.ToString() == DTEstructuraAthena.PurchasingDocument &&
                        columnas[2].value.ToString() == DTEstructuraAthena.DocumentDate &&
                        columnas[3].value.ToString() == DTEstructuraAthena.Material &&
                        columnas[4].value.ToString() == DTEstructuraAthena.ShortText &&
                        columnas[5].value.ToString() == DTEstructuraAthena.OrderQuantity &&
                        columnas[6].value.ToString() == DTEstructuraAthena.StillDelivered &&
                        columnas[7].value.ToString() == DTEstructuraAthena.OrderUnit &&
                        columnas[8].value.ToString() == DTEstructuraAthena.Netprice &&
                        columnas[9].value.ToString() == DTEstructuraAthena.NetOrderValue &&
                        columnas[10].value.ToString() == DTEstructuraAthena.VendorSupplyingPlant &&
                        columnas[11].value.ToString() == DTEstructuraAthena.Currency &&
                        columnas[12].value.ToString() == DTEstructuraAthena.ReleaseState &&
                        columnas[13].value.ToString() == DTEstructuraAthena.DeletionIndicator &&
                        columnas[14].value.ToString() == DTEstructuraAthena.POHistory)
                    {
                        List <DTFilasExcel> ConInformacion = (from dt in filas
                                                              where dt.cells.Count(x => x.value == null) != dt.cells.Count() &&
                                                              dt.index != 0
                                                              select dt).ToList();
                        if (ConInformacion.Count > 0)
                        {
                            foreach (DTFilasExcel Fila in ConInformacion)
                            {
                                if (Fila.cells[Fila.cells.Count - 2].index == 13 && Fila.cells[Fila.cells.Count - 2].value != null)
                                {
                                    if (Fila.cells[Fila.cells.Count - 2].value.ToString() != "")
                                    {
                                        ConEliminacion++;  //Si finalmente es mayor que cero entonces significa que hay al menos una eliminación.
                                    }
                                }
                            }

                            if (ConEliminacion > 0 && Conf == 0)
                            {
                                DTErroresExcel Eliminar = new DTErroresExcel();
                                Eliminar.Fila = 1;

                                //Preguntar al usuario si realmente quiere reemplazar
                                DTResultadoModelCarga.Respuesta = false;
                                DTResultadoModelCarga.Resultado = Eliminar;
                                DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE007);
                                //Realmente desea reemplazar usuarios?
                            }
                            else
                            {
                                BMAthena _BMIM = new BMAthena();
                                DTResultadoModelCarga = _BMIM.LeerArchivo(ConInformacion, NombreArchivo);
                            }
                        }
                        else
                        {
                            DTResultadoModelCarga.Respuesta = false;
                            DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                        }
                    }
                    else
                    {
                        DTResultadoModelCarga.Respuesta = false;
                        DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE002);
                    }
                }
                else
                {
                    DTResultadoModelCarga.Respuesta = false;
                    DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                }
            }
            catch (Exception ex)
            {
                DTResultadoModelCarga.Respuesta = false;
                DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE001);
                GestorLog.RegistrarLogExcepcion(ex);
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(DTResultadoModelCarga));
        }
Пример #6
0
        public DTResultadoOperacionModel <DTErroresExcel> LeerArchivo(List <DTFilasExcel> fileFactura)
        {
            DTResultadoOperacionModel <DTSolped>       _DTResultadoModel = new DTResultadoOperacionModel <DTSolped>();
            DTResultadoOperacionModel <DTErroresExcel> resultado         = new DTResultadoOperacionModel <DTErroresExcel>();

            List <DTSolped>       ListaCargaSolped     = new List <DTSolped>();
            List <DTErroresExcel> ListaCargaIncompleta = new List <DTErroresExcel>();

            try
            {
                List <DTFilasExcel> informacion = (from dt in fileFactura
                                                   where dt.index != 0
                                                   select dt).ToList();

                foreach (var filas in informacion)
                {
                    DTSolped             _MMExcel = new DTSolped();
                    DTFilaValidaciones[] Fila     = new DTFilaValidaciones[26];
                    Fila[0] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.SolNro, Valor = SUPValidaciones.ObtenerValorExcel(0, filas), Validaciones = 1
                    };
                    Fila[1] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.NroOC, Valor = SUPValidaciones.ObtenerValorExcel(1, filas), Validaciones = 0
                    };
                    Fila[2] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.LineaPedido, Valor = SUPValidaciones.ObtenerValorExcel(2, filas), Validaciones = 5
                    };
                    Fila[3] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.NroArticulos, Valor = SUPValidaciones.ObtenerValorExcel(3, filas), Validaciones = 1
                    };
                    Fila[4] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.NroSPE, Valor = SUPValidaciones.ObtenerValorExcel(4, filas), Validaciones = 0
                    };
                    Fila[5] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.HACAT, Valor = SUPValidaciones.ObtenerValorExcel(5, filas), Validaciones = 6
                    };
                    Fila[6] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.PersonaSolicitud, Valor = SUPValidaciones.ObtenerValorExcel(6, filas), Validaciones = 6
                    };
                    Fila[7] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.FechaEnvio, Valor = SUPValidaciones.ObtenerValorExcel(7, filas), Validaciones = 4
                    };
                    Fila[8] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Estado, Valor = SUPValidaciones.ObtenerValorExcel(8, filas), Validaciones = 6
                    };
                    Fila[9] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Tipo, Valor = SUPValidaciones.ObtenerValorExcel(9, filas), Validaciones = 6
                    };
                    Fila[10] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Articulo, Valor = SUPValidaciones.ObtenerValorExcel(10, filas), Validaciones = 0
                    };
                    Fila[11] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Cantidad, Valor = SUPValidaciones.ObtenerValorExcel(11, filas), Validaciones = 3
                    };
                    Fila[12] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.TotalLinea, Valor = SUPValidaciones.ObtenerValorExcel(12, filas), Validaciones = 3
                    };
                    Fila[13] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.CodigoIVA, Valor = SUPValidaciones.ObtenerValorExcel(13, filas), Validaciones = 0
                    };
                    Fila[14] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.CuadroCuentas, Valor = SUPValidaciones.ObtenerValorExcel(14, filas), Validaciones = 6
                    };
                    Fila[15] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.PersonaCreador, Valor = SUPValidaciones.ObtenerValorExcel(15, filas), Validaciones = 6
                    };
                    Fila[16] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.FechaPedido, Valor = SUPValidaciones.ObtenerValorExcel(16, filas), Validaciones = 4
                    };
                    Fila[17] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.FechaCreacion, Valor = SUPValidaciones.ObtenerValorExcel(17, filas), Validaciones = 2
                    };
                    Fila[18] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.FechaEntrega, Valor = SUPValidaciones.ObtenerValorExcel(18, filas), Validaciones = 4
                    };
                    Fila[19] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.FechaCaducidad, Valor = SUPValidaciones.ObtenerValorExcel(19, filas), Validaciones = 4
                    };
                    Fila[20] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Proveedor, Valor = SUPValidaciones.ObtenerValorExcel(20, filas), Validaciones = 6
                    };
                    Fila[21] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Cuenta, Valor = SUPValidaciones.ObtenerValorExcel(21, filas), Validaciones = 0
                    };
                    Fila[22] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.IdOC, Valor = SUPValidaciones.ObtenerValorExcel(22, filas), Validaciones = 5
                    };
                    Fila[23] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.LeandingCostC, Valor = SUPValidaciones.ObtenerValorExcel(23, filas), Validaciones = 6
                    };
                    Fila[24] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.EstadoLinea, Valor = SUPValidaciones.ObtenerValorExcel(24, filas), Validaciones = 0
                    };
                    Fila[25] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraSolped.Divisa, Valor = SUPValidaciones.ObtenerValorExcel(25, filas), Validaciones = 6
                    };

                    foreach (DTFilaValidaciones valores in Fila)
                    {
                        DTErroresExcel Errores = SUPValidaciones.Validacion(valores, filas.index);
                        if (Errores.Mensaje != string.Empty)
                        {
                            ListaCargaIncompleta.Add(Errores);
                        }
                        else
                        {
                            switch (valores.Nombre)
                            {
                            case DTEstructuraSolped.SolNro:
                                _MMExcel.SolNro = Int32.Parse(valores.Valor);
                                break;

                            case DTEstructuraSolped.NroOC:
                                _MMExcel.NroOC = valores.Valor;
                                break;

                            case DTEstructuraSolped.LineaPedido:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.LineaPedido = Int32.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.NroOC = null;
                                }
                                break;

                            case DTEstructuraSolped.NroArticulos:
                                _MMExcel.NroArticulos = Int32.Parse(valores.Valor);
                                break;

                            case DTEstructuraSolped.NroSPE:
                                _MMExcel.NroSPE = valores.Valor;
                                break;

                            case DTEstructuraSolped.HACAT:
                                _MMExcel.HACAT = valores.Valor;
                                break;

                            case DTEstructuraSolped.PersonaSolicitud:
                                _MMExcel.PersonaSolicitud = valores.Valor;
                                break;

                            case DTEstructuraSolped.FechaEnvio:
                                _MMExcel.FechaEnvio = Errores.Fecha;
                                break;

                            case DTEstructuraSolped.Estado:
                                _MMExcel.Estado = valores.Valor;
                                break;

                            case DTEstructuraSolped.Tipo:
                                _MMExcel.Tipo = valores.Valor;
                                break;

                            case DTEstructuraSolped.Articulo:
                                _MMExcel.Articulo = valores.Valor;
                                break;

                            case DTEstructuraSolped.Cantidad:
                                _MMExcel.Cantidad = decimal.Parse(valores.Valor);
                                break;

                            case DTEstructuraSolped.TotalLinea:
                                string valor = valores.Valor.Replace('.', ',');
                                _MMExcel.TotalLinea = decimal.Parse(valor);
                                break;

                            case DTEstructuraSolped.CodigoIVA:
                                _MMExcel.CodigoIVA = valores.Valor;
                                break;

                            case DTEstructuraSolped.CuadroCuentas:
                                _MMExcel.CuadroCuentas = valores.Valor;
                                break;

                            case DTEstructuraSolped.PersonaCreador:
                                _MMExcel.PersonaCreador = valores.Valor;
                                break;

                            case DTEstructuraSolped.FechaPedido:
                                _MMExcel.FechaPedido = Errores.Fecha;
                                break;

                            case DTEstructuraSolped.FechaCreacion:
                                _MMExcel.FechaCreacion = (DateTime)Errores.Fecha;
                                break;

                            case DTEstructuraSolped.FechaEntrega:
                                _MMExcel.FechaEntrega = Errores.Fecha;
                                break;

                            case DTEstructuraSolped.FechaCaducidad:
                                _MMExcel.FechaCaducidad = Errores.Fecha;
                                break;

                            case DTEstructuraSolped.Proveedor:
                                _MMExcel.Proveedor = valores.Valor;
                                break;

                            case DTEstructuraSolped.Cuenta:
                                _MMExcel.Cuenta = valores.Valor;
                                break;

                            case DTEstructuraSolped.IdOC:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.IdOC = Int32.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.NroOC = null;
                                }
                                break;

                            case DTEstructuraSolped.LeandingCostC:
                                _MMExcel.LeandingCostC = valores.Valor;
                                break;

                            case DTEstructuraSolped.EstadoLinea:
                                _MMExcel.EstadoLinea = valores.Valor;
                                break;

                            case DTEstructuraSolped.Divisa:
                                _MMExcel.Divisa = valores.Valor;
                                break;
                            }
                        }
                    }

                    _MMExcel.Fila = filas.index + 1;

                    //Registros Duplicados
                    List <DTSolped> ExisteRegistroDuplicados = (from dt in ListaCargaSolped
                                                                where dt.SolNro == _MMExcel.SolNro && dt.NroArticulos == _MMExcel.NroArticulos
                                                                select dt).ToList();

                    //Validación Registros Duplicados
                    if (ExisteRegistroDuplicados.Count > 0)
                    {
                        DTErroresExcel _Excel1 = new DTErroresExcel();
                        _Excel1.Mensaje = "Se repiten registros.";
                        _Excel1.Fila    = filas.index + 1;
                        _Excel1.Campo   = DTEstructuraSolped.SolNro + ", " + DTEstructuraSolped.NroArticulos;
                        _Excel1.Valor   = _MMExcel.SolNro.ToString() + ", " + _MMExcel.NroArticulos.ToString();
                        ListaCargaIncompleta.Add(_Excel1);

                        foreach (var item in ExisteRegistroDuplicados)
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "Se repiten registros.";
                            _Excel.Fila    = item.Fila;
                            _Excel.Campo   = DTEstructuraSolped.SolNro + ", " + DTEstructuraSolped.NroArticulos;
                            _Excel.Valor   = _MMExcel.SolNro.ToString() + ", " + _MMExcel.NroArticulos.ToString();
                            ListaCargaIncompleta.Add(_Excel);
                            ListaCargaSolped.RemoveAll(c => c.Fila == item.Fila);
                        }
                    }


                    // consultar si la fila no tiene inconvenientes
                    List <DTErroresExcel> ConInformacion = (from dt in ListaCargaIncompleta
                                                            where dt.Fila == (filas.index + 1)
                                                            select dt).ToList();

                    // si no prensentar inconveniente se agrega a la lista de carga bd.
                    if (ConInformacion.Count == 0)
                    {
                        ListaCargaSolped.Add(_MMExcel);
                    }
                }

                //// inserta los exitoso o setea en 0 los estados
                ConvertToDataTable(ListaCargaSolped);

                if (ListaCargaIncompleta.Count > 0)
                {
                    ConvertToXML(ListaCargaIncompleta);
                }
                _DTResultadoModel.Respuesta = true;
                resultado.Respuesta         = _DTResultadoModel.Respuesta;
            }
            catch (Exception ex)
            {
                _DTResultadoModel.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE008);
                _DTResultadoModel.Respuesta = false;
                GestorLog.RegistrarLogExcepcion(ex);

                resultado.Respuesta = _DTResultadoModel.Respuesta;
                resultado.Mensaje   = _DTResultadoModel.Mensaje;
            }
            return(resultado);
        }
        public DTResultadoOperacionModel <DTErroresExcel> LeerArchivo(List <DTFilasExcel> fileFactura, string MesGasto)
        {
            DTResultadoOperacionModel <DTGastos>       _DTResultadoModel = new DTResultadoOperacionModel <DTGastos>();
            DTResultadoOperacionModel <DTErroresExcel> resultado         = new DTResultadoOperacionModel <DTErroresExcel>();

            List <DTGastos>       ListaCarga           = new List <DTGastos>();
            List <DTErroresExcel> ListaCargaIncompleta = new List <DTErroresExcel>();

            try
            {
                List <DTFilasExcel> informacion = (from dt in fileFactura
                                                   where dt.index != 0
                                                   select dt).ToList();

                foreach (var filas in informacion)
                {
                    DTGastos             _MMExcel = new DTGastos();
                    DTFilaValidaciones[] Fila     = new DTFilaValidaciones[8];
                    Fila[0] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.NomCuenta, Valor = SUPValidaciones.ObtenerValorExcel(0, filas), Validaciones = 6, Id = 1
                    };
                    Fila[1] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.NomCentroC, Valor = SUPValidaciones.ObtenerValorExcel(1, filas), Validaciones = 6
                    };
                    Fila[2] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.NroCuenta, Valor = SUPValidaciones.ObtenerValorExcel(2, filas), Validaciones = 6, Id = 2
                    };
                    Fila[3] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.CentroCoste, Valor = SUPValidaciones.ObtenerValorExcel(3, filas), Validaciones = 5
                    };
                    //Fila[4] = new DTFilaValidaciones() { Nombre = DTEstructuraGastos.Concatenar, Valor = SUPValidaciones.ObtenerValorExcel(4, filas), Validaciones = 6 };
                    Fila[4] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.Tipo, Valor = SUPValidaciones.ObtenerValorExcel(5, filas), Validaciones = 6
                    };
                    Fila[5] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.Mes, Valor = SUPValidaciones.ObtenerValorExcel(6, filas), Validaciones = 7
                    };
                    //Fila[6] = new DTFilaValidaciones() { Nombre = DTEstructuraGastos.Cambios, Valor = SUPValidaciones.ObtenerValorExcel(7, filas), Validaciones = 7 };
                    Fila[6] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.Ajustes, Valor = SUPValidaciones.ObtenerValorExcel(7, filas), Validaciones = 7
                    };
                    Fila[7] = new DTFilaValidaciones()
                    {
                        Nombre = DTEstructuraGastos.TotalMes, Valor = SUPValidaciones.ObtenerValorExcel(8, filas), Validaciones = 7
                    };

                    foreach (DTFilaValidaciones valores in Fila)
                    {
                        DTErroresExcel Errores = SUPValidaciones.Validacion(valores, filas.index);
                        if (Errores.Mensaje != string.Empty)
                        {
                            ListaCargaIncompleta.Add(Errores);
                        }
                        else
                        {
                            switch (valores.Nombre)
                            {
                            case DTEstructuraGastos.NomCuenta:
                                if (valores.Id == 1)
                                {
                                    _MMExcel.NomCuenta = valores.Valor;
                                }
                                else if (valores.Id == 2)
                                {
                                    _MMExcel.NroCuenta = valores.Valor;
                                }
                                break;

                            case DTEstructuraGastos.NomCentroC:
                                _MMExcel.NomCentroC = valores.Valor;
                                break;

                            case DTEstructuraGastos.CentroCoste:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.CentroCoste = double.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.CentroCoste = default;
                                }
                                break;

                            //case DTEstructuraGastos.Concatenar:
                            //    _MMExcel.Concatenar = valores.Valor;
                            //    break;
                            case DTEstructuraGastos.Tipo:
                                _MMExcel.Tipo = valores.Valor;
                                break;

                            case DTEstructuraGastos.Mes:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.Mes = decimal.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.Mes = default;
                                }
                                break;

                            case DTEstructuraGastos.Ajustes:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.Ajustes = decimal.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.Ajustes = default;
                                }
                                break;

                            case DTEstructuraGastos.TotalMes:
                                if (!string.IsNullOrEmpty(valores.Valor))
                                {
                                    _MMExcel.TotalMes = decimal.Parse(valores.Valor);
                                }
                                else
                                {
                                    _MMExcel.TotalMes = default;
                                }
                                break;
                            }
                        }
                    }

                    _MMExcel.Fila = filas.index + 1;

                    //Registros Duplicados
                    List <DTGastos> ExisteRegistroDuplicados = (from dt in ListaCarga
                                                                where dt.NroCuenta == _MMExcel.NroCuenta && dt.CentroCoste == _MMExcel.CentroCoste
                                                                select dt).ToList();

                    //Validación Registros Duplicados
                    if (ExisteRegistroDuplicados.Count > 0)
                    {
                        DTErroresExcel _Excel1 = new DTErroresExcel();
                        _Excel1.Mensaje = "Se repiten registros.";
                        _Excel1.Fila    = filas.index + 1;
                        _Excel1.Campo   = DTEstructuraGastos.NroCuenta + ", " + DTEstructuraGastos.CentroCoste;
                        _Excel1.Valor   = _MMExcel.NroCuenta.ToString() + ", " + _MMExcel.CentroCoste.ToString();
                        ListaCargaIncompleta.Add(_Excel1);

                        foreach (var item in ExisteRegistroDuplicados)
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "Se repiten registros.";
                            _Excel.Fila    = item.Fila;
                            _Excel.Campo   = DTEstructuraGastos.NroCuenta + ", " + DTEstructuraGastos.CentroCoste;
                            _Excel.Valor   = _MMExcel.NroCuenta.ToString() + ", " + _MMExcel.CentroCoste.ToString();
                            ListaCargaIncompleta.Add(_Excel);
                            ListaCarga.RemoveAll(c => c.Fila == item.Fila);
                        }
                    }


                    // consultar si la fila no tiene inconvenientes
                    List <DTErroresExcel> ConInformacion = (from dt in ListaCargaIncompleta
                                                            where dt.Fila == (filas.index + 1)
                                                            select dt).ToList();

                    // si no prensentar inconveniente se agrega a la lista de carga bd.
                    if (ConInformacion.Count == 0)
                    {
                        ListaCarga.Add(_MMExcel);
                    }
                }

                //// inserta los exitoso o setea en 0 los estados
                ConvertToDataTable(ListaCarga, MesGasto);

                if (ListaCargaIncompleta.Count > 0)
                {
                    ConvertToXML(ListaCargaIncompleta);
                }
                _DTResultadoModel.Respuesta = true;
                resultado.Respuesta         = _DTResultadoModel.Respuesta;
            }
            catch (Exception ex)
            {
                _DTResultadoModel.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE008);
                _DTResultadoModel.Respuesta = false;
                GestorLog.RegistrarLogExcepcion(ex);

                resultado.Respuesta = _DTResultadoModel.Respuesta;
                resultado.Mensaje   = _DTResultadoModel.Mensaje;
            }
            return(resultado);
        }
Пример #8
0
        public DTResultadoOperacionModel <DTErroresExcel> LeerArchivo(List <DTFilasExcel> fileFactura, string nombreArchivo)
        {
            DTResultadoOperacionModel <DTAthena>       _DTResultadoModel = new DTResultadoOperacionModel <DTAthena>();
            DTResultadoOperacionModel <DTErroresExcel> resultado         = new DTResultadoOperacionModel <DTErroresExcel>();

            Workbook              _Workbook            = new Workbook();
            List <DTAthena>       ListaCargaAthena     = new List <DTAthena>();
            List <DTErroresExcel> ListaCargaIncompleta = new List <DTErroresExcel>();

            try
            {
                List <DTFilasExcel> informacion = (from dt in fileFactura
                                                   where dt.index != 0
                                                   select dt).ToList();

                foreach (var filas in informacion)
                {
                    DTAthena _MMExcel            = new DTAthena();
                    string   Item                = ObtenerValorExcel(0, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   Document            = ObtenerValorExcel(1, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   Date                = ObtenerValorExcel(2, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   Material            = ObtenerValorExcel(3, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   ShortText           = ObtenerValorExcel(4, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   OrderQty            = ObtenerValorExcel(5, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   DeliveryQty         = ObtenerValorExcel(6, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   OrderUnit           = ObtenerValorExcel(7, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   NetPrice            = ObtenerValorExcel(8, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   NetOrderValue       = ObtenerValorExcel(9, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   VendorSuplyingPlant = ObtenerValorExcel(10, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   Currency            = ObtenerValorExcel(11, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   ReleaseState        = ObtenerValorExcel(12, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   Delete              = ObtenerValorExcel(13, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();
                    string   POHistory           = ObtenerValorExcel(14, filas).Replace(Constantes.ValidacionEncabezados, string.Empty).Trim().ToString();

                    Regex Numeros           = new Regex(Constantes.ExpRegSoloNumeros);
                    Regex ValidandoEspacios = new Regex(Constantes.ExpRegEspaciosBlanco);
                    Regex NumyLetras        = new Regex(Constantes.ExpRegAlfaNumericos);
                    Regex rex            = new Regex(Constantes.ExpRegAlfaNumericos);
                    Regex rexNumeroPunto = new Regex(Constantes.ExpRegNumeroPunto);
                    Regex Letras         = new Regex(Constantes.ExpRegSoloLetras);

                    //Validación casillas de totales
                    if (string.IsNullOrEmpty(Item) && string.IsNullOrEmpty(Document) && string.IsNullOrEmpty(Date) && string.IsNullOrEmpty(ReleaseState))
                    {
                        continue;
                    }
                    //Validación Item
                    if (!string.IsNullOrEmpty(Item))
                    {
                        if (!Numeros.IsMatch(Item))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Item";
                            _Excel.Valor   = Item;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.Item = Int32.Parse(Item);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Item";
                        _Excel.Valor   = Item;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación Document
                    if (!string.IsNullOrEmpty(Document))
                    {
                        if (!Numeros.IsMatch(Document))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Document";
                            _Excel.Valor   = Document;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.Document = Document;
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Document";
                        _Excel.Valor   = Document;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación Date
                    if (!string.IsNullOrEmpty(Date))
                    {
                        DateTime fecha = new DateTime();
                        try
                        {
                            fecha = DateTime.FromOADate(Convert.ToDouble(Date));

                            _MMExcel.Date = Convert.ToDateTime(fecha);
                        }
                        catch (Exception)
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no tiene el formato correcto.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Date";
                            _Excel.Valor   = Date;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Date";
                        _Excel.Valor   = Date;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación Material
                    if (!string.IsNullOrEmpty(Material))
                    {
                        if (!NumyLetras.IsMatch(Material))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Material";
                            _Excel.Valor   = Material;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.Material = Material;
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Material";
                        _Excel.Valor   = Material;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación ShortText
                    if (!string.IsNullOrEmpty(ShortText))
                    {
                        _MMExcel.ShortText = ShortText;
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Short Text";
                        _Excel.Valor   = ShortText;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación OrderQty
                    if (!string.IsNullOrEmpty(OrderQty))
                    {
                        if (!rexNumeroPunto.IsMatch(OrderQty))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Order Quantity";
                            _Excel.Valor   = OrderQty;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.OrderQty = Decimal.Parse(OrderQty);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Order Quantity";
                        _Excel.Valor   = OrderQty;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación DeliveryQty
                    if (!string.IsNullOrEmpty(DeliveryQty))
                    {
                        if (!rexNumeroPunto.IsMatch(DeliveryQty))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Still to be delivered (qty)";
                            _Excel.Valor   = DeliveryQty;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.DeliveryQty = decimal.Parse(DeliveryQty);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Still to be delivered (qty)";
                        _Excel.Valor   = DeliveryQty;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación OrderUnit
                    if (!string.IsNullOrEmpty(OrderUnit))
                    {
                        if (!Letras.IsMatch(OrderUnit))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Order Unit";
                            _Excel.Valor   = OrderUnit;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.OrderUnit = OrderUnit;
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Order Unit";
                        _Excel.Valor   = OrderUnit;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación NetPrice
                    if (!string.IsNullOrEmpty(NetPrice))
                    {
                        if (!rexNumeroPunto.IsMatch(NetPrice))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Net Price";
                            _Excel.Valor   = NetPrice;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.NetPrice = decimal.Parse(NetPrice);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Net Price";
                        _Excel.Valor   = NetPrice;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación NetOrderValue
                    if (!string.IsNullOrEmpty(NetOrderValue))
                    {
                        if (!rexNumeroPunto.IsMatch(NetOrderValue))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Net Order Value";
                            _Excel.Valor   = NetOrderValue;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.NetOrderValue = decimal.Parse(NetOrderValue);
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Net Order Value";
                        _Excel.Valor   = NetOrderValue;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación VendorSuplyingPlant
                    if (!string.IsNullOrEmpty(VendorSuplyingPlant))
                    {
                        _MMExcel.Vendor = VendorSuplyingPlant;
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Vendor/supplying plant";
                        _Excel.Valor   = VendorSuplyingPlant;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación Currency
                    if (!string.IsNullOrEmpty(Currency))
                    {
                        if (!Letras.IsMatch(Currency))
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                            _Excel.Fila    = filas.index + 1;
                            _Excel.Campo   = "Currency";
                            _Excel.Valor   = Currency;
                            ListaCargaIncompleta.Add(_Excel);
                        }
                        else
                        {
                            _MMExcel.Currency = Currency;
                        }
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Currency";
                        _Excel.Valor   = Currency;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación ReleaseState
                    if (!string.IsNullOrEmpty(ReleaseState))
                    {
                        //if (!Numeros.IsMatch(ReleaseState))
                        //{
                        //    DTErroresExcel _Excel = new DTErroresExcel();
                        //    _Excel.Mensaje = "El campo no debe llevar caracteres especiales.";
                        //    _Excel.Fila = filas.index + 1;
                        //    _Excel.Campo = "Item";
                        //    _Excel.Valor = Item;
                        //    ListaCargaIncompleta.Add(_Excel);
                        //}
                        //else
                        //{
                        _MMExcel.ReleaseState = ReleaseState;
                        //}
                    }
                    else
                    {
                        DTErroresExcel _Excel = new DTErroresExcel();
                        _Excel.Mensaje = "El campo se encuentra vacío.";
                        _Excel.Fila    = filas.index + 1;
                        _Excel.Campo   = "Release State";
                        _Excel.Valor   = ReleaseState;
                        ListaCargaIncompleta.Add(_Excel);
                    }

                    //Validación Delete
                    if (!string.IsNullOrEmpty(Delete))
                    {
                        if (Delete == "1" || Delete == "0")
                        {
                            _MMExcel.Delete = Convert.ToBoolean(Convert.ToInt32(Delete));
                        }
                        else
                        {
                            DTErroresExcel _Excel1 = new DTErroresExcel();
                            _Excel1.Mensaje = "El dato no coincide con los parámetros establecidos.";
                            _Excel1.Fila    = filas.index + 1;
                            _Excel1.Campo   = "Delete";
                            _Excel1.Valor   = Delete;
                            ListaCargaIncompleta.Add(_Excel1);
                        }
                    }
                    else
                    {
                        _MMExcel.Delete = false;
                    }

                    //Validación POHistory
                    _MMExcel.POHistory = POHistory;

                    _MMExcel.Fila = filas.index + 1;
                    //Registros Duplicados

                    List <DTAthena> ExisteRegistroDuplicados = (from dt in ListaCargaAthena
                                                                where dt.Document == _MMExcel.Document && dt.Date == _MMExcel.Date && dt.Item == _MMExcel.Item
                                                                select dt).ToList();

                    //Validación Registros Duplicados
                    if (ExisteRegistroDuplicados.Count > 0)
                    {
                        DTErroresExcel _Excel1 = new DTErroresExcel();
                        _Excel1.Mensaje = "Se repiten registros.";
                        _Excel1.Fila    = filas.index + 1;
                        _Excel1.Campo   = "Item,Purchasing Document, Document Date";
                        _Excel1.Valor   = _MMExcel.Item.ToString() + "," + _MMExcel.Document.ToString() + ", " + _MMExcel.Date.ToShortDateString();
                        ListaCargaIncompleta.Add(_Excel1);

                        foreach (var item in ExisteRegistroDuplicados)
                        {
                            DTErroresExcel _Excel = new DTErroresExcel();
                            _Excel.Mensaje = "Se repiten registros.";
                            _Excel.Fila    = item.Fila;
                            _Excel.Campo   = "Item, Purchasing Document, Document Date";
                            _Excel.Valor   = _MMExcel.Item.ToString() + "," + _MMExcel.Document.ToString() + ", " + _MMExcel.Date.ToShortDateString();
                            ListaCargaIncompleta.Add(_Excel);
                            ListaCargaAthena.RemoveAll(c => c.Fila == item.Fila);
                        }
                    }


                    // consultar si la fila no tiene inconvenientes
                    List <DTErroresExcel> ConInformacion = (from dt in ListaCargaIncompleta
                                                            where dt.Fila == (filas.index + 1)
                                                            select dt).ToList();

                    // si no prensentar inconveniente se agrega a la lista de carga bd.
                    if (ConInformacion.Count > 0)
                    {
                    }
                    else
                    {
                        ListaCargaAthena.Add(_MMExcel);
                    }
                }

                // inserta los exitoso o setea en 0 los estados
                ConvertToDataTable(ListaCargaAthena);


                if (ListaCargaIncompleta.Count > 0)
                {
                    ConvertToXML(ListaCargaIncompleta);
                }
                _DTResultadoModel.Respuesta = true;
                resultado.Respuesta         = _DTResultadoModel.Respuesta;
            }
            catch (Exception ex)
            {
                _DTResultadoModel.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE008);
                _DTResultadoModel.Respuesta = false;
                GestorLog.RegistrarLogExcepcion(ex);

                resultado.Respuesta = _DTResultadoModel.Respuesta;
                resultado.Mensaje   = _DTResultadoModel.Mensaje;
            }
            return(resultado);
        }
Пример #9
0
        public ActionResult ExportToExcel(DTFiltros Dtos)
        {
            //DTResultadoOperacionModel<DTConsolidadoExcel> resultado = new DTResultadoOperacionModel<DTConsolidadoExcel>();
            DTResultadoOperacionModel <string> respuesta = new DTResultadoOperacionModel <string>();
            List <DTConsolidadoExcel>          list      = new List <DTConsolidadoExcel>();
            BMConsolidado bMConsolidado = new BMConsolidado();

            list = bMConsolidado.ConsultarConsolidadoExcel(Dtos);
            if (list.Count > 0)
            {
                DataTable dataTable = ConvertData.ConvertToDataTable <DTConsolidadoExcel>(list);
                DataSet   dataSet   = new DataSet();
                dataSet.Tables.Add(dataTable);

                string numbreArchivo = ConfigurationManager.AppSettings.Get("ReporteExcelConsolidado");
                string rutaArchivo   = string.Empty;
                try
                {
                    string RutaServidor  = (string)new AppSettingsReader().GetValue("RutaServidor", typeof(string));
                    string SubRutaActual = Request.RawUrl;
                    string RutaPlantilla = Request.Url.OriginalString.ToString();
                    var    RutaFinal     = RutaPlantilla.Replace(SubRutaActual, "");

                    rutaArchivo = RutaFinal + @"/" + RutaServidor + numbreArchivo + ".xlsx";
                    string rutaVirtual  = Server.MapPath("~/Excel/");
                    string rutaCompleta = rutaVirtual + numbreArchivo + ".xlsx";

                    WindowsImpersonationContext logon = null;

                    Boolean Suplantacion = (Boolean) new AppSettingsReader().GetValue("Impersonate", typeof(Boolean));
                    if (Suplantacion)
                    {
                        string DominioSuplantacion = (string)new AppSettingsReader().GetValue("DominioSuplantacion", typeof(string));
                        string UsuarioSuplantacion = (string)new AppSettingsReader().GetValue("UsuarioSuplantacion", typeof(string));
                        string ClaveSuplantacion   = (string)new AppSettingsReader().GetValue("ClaveSuplantacion", typeof(string));
                        using (new Impersonation(DominioSuplantacion, UsuarioSuplantacion, ClaveSuplantacion))
                        {
                            ConvertData.ToExcelFile(dataTable, rutaCompleta);
                        }
                    }
                    else
                    {
                        ConvertData.ToExcelFile(dataTable, rutaCompleta);
                    }
                    respuesta.Respuesta = true;
                    respuesta.Resultado = rutaArchivo;
                }
                catch (Exception ex)
                {
                    respuesta.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE023);
                    respuesta.Resultado = null;
                    respuesta.Respuesta = false;
                    GestorLog.RegistrarLogExcepcion(ex);
                }
            }
            else
            {
                respuesta.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE024);
                respuesta.Resultado = null;
                respuesta.Respuesta = false;
            }
            return(Json(respuesta, JsonRequestBehavior.AllowGet));
        }
Пример #10
0
        public string ValidarArchivo(string Plantilla)
        {
            string RutaArchivo = string.Empty;
            DTResultadoOperacionModel <DTSolped>       DTResultadoModel      = new DTResultadoOperacionModel <DTSolped>();
            DTResultadoOperacionModel <DTErroresExcel> DTResultadoModelCarga = new DTResultadoOperacionModel <DTErroresExcel>();

            //int ConEliminacion = 0;

            try
            {
                DTExcel             _Plantilla = JsonConvert.DeserializeObject <DTExcel>(Plantilla);
                List <DTFilasExcel> filas      = _Plantilla.sheets.First().rows;
                string MesGastos  = _Plantilla.sheets.First().name;
                bool   FechaGasto = ValidarFechaGasto(MesGastos);

                if (filas.Count > 1)
                {
                    //Validar el encabezado
                    List <DTColumnasExcel> columnas = filas.First().cells;

                    if (columnas[0].value.ToString().Trim() == DTEstructuraGastos.NomCuenta &&
                        columnas[1].value.ToString().Trim() == DTEstructuraGastos.NomCentroC &&
                        columnas[2].value.ToString().Trim() == DTEstructuraGastos.NroCuenta &&
                        columnas[3].value.ToString().Trim() == DTEstructuraGastos.CentroCoste &&
                        columnas[4].value.ToString().Trim() == DTEstructuraGastos.Concatenar &&
                        columnas[5].value.ToString().Trim() == DTEstructuraGastos.Tipo &&
                        columnas[6].value.ToString().Trim() == DTEstructuraGastos.Mes &&
                        columnas[7].value.ToString().Trim() == DTEstructuraGastos.Ajustes &&
                        columnas[8].value.ToString().Trim() == DTEstructuraGastos.TotalMes
                        )
                    {
                        List <DTFilasExcel> ConInformacion = (from dt in filas
                                                              where dt.cells.Count(x => x.value == null) != dt.cells.Count() &&
                                                              dt.index != 0
                                                              select dt).ToList();
                        if (ConInformacion.Count > 0)
                        {
                            if (FechaGasto)
                            {
                                string   MesGastoReal = "01-" + MesGastos;
                                BMGastos _BMGastos    = new BMGastos();
                                DTResultadoModelCarga = _BMGastos.LeerArchivo(ConInformacion, MesGastoReal);
                            }
                            else
                            {
                                DTResultadoModelCarga.Respuesta = false;
                                DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE022);
                            }
                        }
                        else
                        {
                            DTResultadoModelCarga.Respuesta = false;
                            DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                        }
                    }
                    else
                    {
                        DTResultadoModelCarga.Respuesta = false;
                        DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE002);
                    }
                }
                else
                {
                    DTResultadoModelCarga.Respuesta = false;
                    DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE004);
                }
            }
            catch (Exception ex)
            {
                DTResultadoModelCarga.Respuesta = false;
                DTResultadoModelCarga.Mensaje   = DTMensaje.ObtenerObjetoMensaje(DTCodigoMensajes.MENSAJE001);
                GestorLog.RegistrarLogExcepcion(ex);
            }
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(DTResultadoModelCarga));
        }