Esempio n. 1
0
        public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
        {
            #region Variables
            ro_empleado_Bus         bus_empleado = new ro_empleado_Bus();
            Af_Activo_fijo_tipo_Bus bus_tipo     = new Af_Activo_fijo_tipo_Bus();

            Af_Activo_fijo_tipo_List             ListaTipo       = new Af_Activo_fijo_tipo_List();
            List <Af_Activo_fijo_tipo_Info>      Lista_Tipo      = new List <Af_Activo_fijo_tipo_Info>();
            Af_Activo_fijo_Categoria_List        ListaCategoria  = new Af_Activo_fijo_Categoria_List();
            List <Af_Activo_fijo_Categoria_Info> Lista_Categoria = new List <Af_Activo_fijo_Categoria_Info>();
            Af_Departamento_List        ListaDepartamento        = new Af_Departamento_List();
            List <Af_Departamento_Info> Lista_Departamento       = new List <Af_Departamento_Info>();
            Af_Catalogo_List            ListaCatalogo            = new Af_Catalogo_List();
            List <Af_Catalogo_Info>     Lista_Catalogo           = new List <Af_Catalogo_Info>();
            Af_Activo_fijo_List         ListaActivoFijo          = new Af_Activo_fijo_List();
            List <Af_Activo_fijo_Info>  Lista_ActivoFijo         = new List <Af_Activo_fijo_Info>();
            Af_Marca_List         ListaMarcaAF  = new Af_Marca_List();
            Af_Modelo_List        ListaModeloAF = new Af_Modelo_List();
            List <Af_Marca_Info>  Lista_Marca   = new List <Af_Marca_Info>();
            List <Af_Modelo_Info> Lista_Modelo  = new List <Af_Modelo_Info>();
            Af_Area_List          ListaAreaAF   = new Af_Area_List();
            List <Af_Area_Info>   Lista_Area    = new List <Af_Area_Info>();
            //Af_Activo_fijo_CtaCble_List ListaActivoFijoCtaCble = new Af_Activo_fijo_CtaCble_List();
            List <Af_Activo_fijo_CtaCble_Info> Lista_ActivoFijoCtaCble = new List <Af_Activo_fijo_CtaCble_Info>();

            int     cont = 0;
            decimal IdTransaccionSession = Convert.ToDecimal(SessionFixed.IdTransaccionSessionActual);
            int     IdEmpresa            = Convert.ToInt32(SessionFixed.IdEmpresa);
            #endregion


            Stream stream = new MemoryStream(e.UploadedFile.FileBytes);
            if (stream.Length > 0)
            {
                IExcelDataReader reader = null;
                reader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                #region Tipo
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Activo_fijo_tipo_Info info = new Af_Activo_fijo_tipo_Info
                        {
                            IdEmpresa              = IdEmpresa,
                            IdActivoFijoTipo       = Convert.ToInt32(reader.GetValue(0)),
                            CodActivoFijo          = reader.GetString(1),
                            Af_Descripcion         = reader.GetString(2),
                            Af_Porcentaje_depre    = Convert.ToDouble(reader.GetValue(3)),
                            Af_anio_depreciacion   = Convert.ToInt32(reader.GetValue(4)),
                            IdCtaCble_Activo       = Convert.ToString(reader.GetValue(6)),
                            IdCtaCble_Dep_Acum     = Convert.ToString(reader.GetValue(7)),
                            IdCtaCble_Gastos_Depre = Convert.ToString(reader.GetValue(8)),
                            Se_Deprecia            = reader.GetString(5) == "SI" ? true : false,
                            IdCtaCble_CostoVenta   = Convert.ToString(reader.GetValue(9)),
                            IdCtaCble_Mejora       = Convert.ToString(reader.GetValue(10)),
                            IdCtaCble_Baja         = Convert.ToString(reader.GetValue(11)),
                            IdCtaCble_Retiro       = Convert.ToString(reader.GetValue(12)),
                            IdUsuario              = SessionFixed.IdUsuario
                        };
                        Lista_Tipo.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaTipo.set_list(Lista_Tipo, IdTransaccionSession);
                #endregion

                cont = 0;
                //Para avanzar a la siguiente hoja de excel
                reader.NextResult();

                #region Categoria
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Activo_fijo_Categoria_Info info = new Af_Activo_fijo_Categoria_Info
                        {
                            IdEmpresa        = IdEmpresa,
                            IdCategoriaAF    = Convert.ToInt32(reader.GetValue(0)),
                            IdActivoFijoTipo = Convert.ToInt32(reader.GetValue(1)),
                            CodCategoriaAF   = string.IsNullOrEmpty(Convert.ToString(reader.GetValue(2))) ? null : Convert.ToString(reader.GetValue(2)),
                            Descripcion      = Convert.ToString(reader.GetValue(3)),
                            IdUsuario        = SessionFixed.IdUsuario
                        };
                        Lista_Categoria.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaCategoria.set_list(Lista_Categoria, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region Area
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Area_Info info = new Af_Area_Info
                        {
                            IdEmpresa         = IdEmpresa,
                            IdArea            = Convert.ToInt32(reader.GetValue(0)),
                            Descripcion       = Convert.ToString(reader.GetValue(1)),
                            IdUsuarioCreacion = SessionFixed.IdUsuario
                        };
                        Lista_Area.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaAreaAF.set_list(Lista_Area, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region Departamento
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Departamento_Info info = new Af_Departamento_Info
                        {
                            IdEmpresa         = IdEmpresa,
                            IdDepartamento    = Convert.ToInt32(reader.GetValue(0)),
                            IdArea            = Convert.ToInt32(reader.GetValue(1)),
                            Descripcion       = Convert.ToString(reader.GetValue(2)),
                            IdUsuarioCreacion = SessionFixed.IdUsuario
                        };
                        Lista_Departamento.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaDepartamento.set_list(Lista_Departamento, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region Catalogo
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Catalogo_Info info = new Af_Catalogo_Info
                        {
                            IdCatalogo     = Convert.ToString(reader.GetValue(0)),
                            IdTipoCatalogo = Convert.ToString(reader.GetValue(1)),
                            Descripcion    = Convert.ToString(reader.GetValue(2)),
                            IdUsuario      = SessionFixed.IdUsuario
                        };
                        info.IdCatalogo     = info.IdCatalogo.Trim();
                        info.IdTipoCatalogo = info.IdTipoCatalogo.Trim();

                        Lista_Catalogo.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaCatalogo.set_list(Lista_Catalogo, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();
                reader.NextResult();

                #region Marca
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Marca_Info info = new Af_Marca_Info
                        {
                            IdEmpresa         = Convert.ToInt32(SessionFixed.IdEmpresa),
                            IdMarca           = Convert.ToInt32(reader.GetValue(0)),
                            ma_Descripcion    = Convert.ToString(reader.GetValue(1)),
                            IdUsuarioCreacion = SessionFixed.IdUsuario
                        };

                        Lista_Marca.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaMarcaAF.set_list(Lista_Marca, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region Modelo
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        Af_Modelo_Info info = new Af_Modelo_Info
                        {
                            IdEmpresa         = Convert.ToInt32(SessionFixed.IdEmpresa),
                            IdModelo          = Convert.ToInt32(reader.GetValue(0)),
                            mo_Descripcion    = Convert.ToString(reader.GetValue(1)),
                            IdUsuarioCreacion = SessionFixed.IdUsuario
                        };

                        Lista_Modelo.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaModeloAF.set_list(Lista_Modelo, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region ActivoFijo
                tb_persona_Bus  bus_persona    = new tb_persona_Bus();
                var             ListaPersonas  = bus_persona.get_list(false);
                tb_persona_List Lista_Personas = new tb_persona_List();
                Lista_Personas.set_list(ListaPersonas, IdTransaccionSession);

                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        var IdTipo               = Convert.ToInt32(reader.GetValue(3));
                        var ini_depre            = Convert.ToDateTime(reader.GetValue(12));
                        var info_custodio        = Lista_Personas.get_list(IdTransaccionSession).Where(q => q.pe_cedulaRuc == Convert.ToString(reader.GetValue(20))).FirstOrDefault();
                        var info_encargado       = Lista_Personas.get_list(IdTransaccionSession).Where(q => q.pe_cedulaRuc == Convert.ToString(reader.GetValue(21))).FirstOrDefault();
                        var info_tipo_activofijo = ListaTipo.get_list(IdTransaccionSession).Where(q => q.IdActivoFijoTipo == IdTipo).FirstOrDefault();

                        Af_Activo_fijo_Info info = new Af_Activo_fijo_Info
                        {
                            IdEmpresa            = IdEmpresa,
                            IdUsuarioCreacion    = SessionFixed.IdUsuario,
                            IdActivoFijo         = Convert.ToInt32(reader.GetValue(0)),
                            CodActivoFijo        = string.IsNullOrEmpty(Convert.ToString(reader.GetValue(1))) ? null : Convert.ToString(reader.GetValue(1)),
                            Af_Codigo_Barra      = string.IsNullOrEmpty(Convert.ToString(reader.GetValue(22))) ? null : Convert.ToString(reader.GetValue(22)),
                            Af_Nombre            = Convert.ToString(reader.GetValue(2)),
                            IdCategoriaAF        = Convert.ToInt32(reader.GetValue(4)),
                            IdActivoFijoTipo     = Convert.ToInt32(reader.GetValue(3)),
                            IdSucursal           = Convert.ToInt32(reader.GetValue(5)),
                            IdArea               = Convert.ToInt32(reader.GetValue(6)),
                            IdDepartamento       = Convert.ToInt32(reader.GetValue(7)),
                            IdMarca              = Convert.ToInt32(reader.GetValue(8)),
                            IdModelo             = Convert.ToInt32(reader.GetValue(9)),
                            IdEmpleadoCustodio   = info_custodio == null ? 0 : info_custodio.IdPersona,
                            IdEmpleadoEncargado  = info_encargado == null ? 0 : info_encargado.IdPersona,
                            Af_fecha_compra      = Convert.ToDateTime(reader.GetValue(11)),
                            Af_fecha_ini_depre   = ini_depre,
                            Af_costo_compra      = Convert.ToDouble(reader.GetValue(14)),
                            Af_Depreciacion_acum = Convert.ToDouble(reader.GetValue(15)),
                            Af_ValorSalvamento   = Convert.ToDouble(reader.GetValue(23)),
                            Af_NumSerie          = string.IsNullOrEmpty(Convert.ToString(reader.GetValue(10))) ? null : Convert.ToString(reader.GetValue(10)),
                            Estado_Proceso       = "TIP_ESTADO_AF_ACTIVO",
                            Af_fecha_fin_depre   = ini_depre.AddYears(info_tipo_activofijo.Af_anio_depreciacion),
                            Af_Meses_depreciar   = (info_tipo_activofijo.Af_anio_depreciacion * 12),
                            Af_porcentaje_deprec = info_tipo_activofijo.Af_Porcentaje_depre,
                            Af_Vida_Util         = info_tipo_activofijo.Af_anio_depreciacion,
                            Af_observacion       = Convert.ToString(reader.GetValue(19)),
                            Cantidad             = Convert.ToInt32(reader.GetValue(24))
                        };

                        Lista_ActivoFijo.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaActivoFijo.set_list(Lista_ActivoFijo, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region ActivoFijo_CtaCble
                //while (reader.Read())
                //{
                //    if (!reader.IsDBNull(0) && cont > 0)
                //    {
                //        Af_Activo_fijo_CtaCble_Info info = new Af_Activo_fijo_CtaCble_Info
                //        {
                //            IdEmpresa = IdEmpresa,
                //            IdActivoFijo = Convert.ToInt32(reader.GetValue(0)),
                //            IdDepartamento = Convert.ToInt32(reader.GetValue(1)),
                //            IdCtaCble = Convert.ToString(reader.GetValue(2)),
                //            Porcentaje = Convert.ToDouble(reader.GetValue(3))
                //        };
                //        Lista_ActivoFijoCtaCble.Add(info);
                //    }
                //    else
                //        cont++;
                //}
                //ListaActivoFijoCtaCble.set_list(Lista_ActivoFijoCtaCble, IdTransaccionSession);
                #endregion
            }
        }