Example #1
0
        public ActionResult Index()
        {
            #region Validar Session
            if (string.IsNullOrEmpty(SessionFixed.IdTransaccionSession))
            {
                return(RedirectToAction("Login", new { Area = "", Controller = "Account" }));
            }
            SessionFixed.IdTransaccionSession       = (Convert.ToDecimal(SessionFixed.IdTransaccionSession) + 1).ToString();
            SessionFixed.IdTransaccionSessionActual = SessionFixed.IdTransaccionSession;
            #endregion

            #region Permisos
            seg_Menu_x_Empresa_x_Usuario_Info info = bus_permisos.get_list_menu_accion(Convert.ToInt32(SessionFixed.IdEmpresa), SessionFixed.IdUsuario, "General", "Empresa", "Index");
            ViewBag.Nuevo = info.Nuevo;
            #endregion

            tb_empresa_Info model = new tb_empresa_Info
            {
                IdTransaccionSession = Convert.ToDecimal(SessionFixed.IdTransaccionSession),
                IdEmpresa            = Convert.ToInt32(SessionFixed.IdEmpresa),
            };

            var lst = bus_empresa.get_list(true);
            ListaEmpresa.set_list(lst, model.IdTransaccionSession);
            return(View(model));
        }
        public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
        {
            #region Variables
            tb_empresa_List         ListaEmpresa   = new tb_empresa_List();
            List <tb_empresa_Info>  Lista_Empresa  = new List <tb_empresa_Info>();
            tb_sucursal_List        ListaSucursal  = new tb_sucursal_List();
            List <tb_sucursal_Info> Lista_Sucursal = new List <tb_sucursal_Info>();
            tb_bodega_List          ListaBodega    = new tb_bodega_List();
            List <tb_bodega_Info>   Lista_Bodega   = new List <tb_bodega_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 Empresa
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        tb_empresa_Info info = new tb_empresa_Info
                        {
                            IdEmpresa              = Convert.ToInt32(reader.GetValue(0)),
                            codigo                 = Convert.ToString(reader.GetValue(1)),
                            em_nombre              = Convert.ToString(reader.GetValue(2)),
                            RazonSocial            = Convert.ToString(reader.GetValue(3)),
                            NombreComercial        = Convert.ToString(reader.GetValue(4)),
                            ContribuyenteEspecial  = Convert.ToString(reader.GetValue(5)),
                            em_ruc                 = Convert.ToString(reader.GetValue(6)),
                            em_gerente             = Convert.ToString(reader.GetValue(7)),
                            em_contador            = Convert.ToString(reader.GetValue(8)),
                            em_rucContador         = Convert.ToString(reader.GetValue(9)),
                            em_telefonos           = Convert.ToString(reader.GetValue(10)),
                            em_direccion           = Convert.ToString(reader.GetValue(11)),
                            em_fechaInicioContable = reader.GetDateTime(12),
                            cod_entidad_dinardap   = Convert.ToString(reader.GetValue(13)),
                            em_Email               = Convert.ToString(reader.GetValue(14))
                        };
                        info.em_fechaInicioActividad = info.em_fechaInicioContable;
                        Lista_Empresa.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaEmpresa.set_list(Lista_Empresa, IdTransaccionSession);
                #endregion

                cont = 0;
                reader.NextResult();

                #region Sucursal
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        tb_sucursal_Info info = new tb_sucursal_Info
                        {
                            IdEmpresa                = Convert.ToInt32(reader.GetValue(0)),
                            IdSucursal               = Convert.ToInt32(reader.GetValue(1)),
                            codigo                   = Convert.ToString(reader.GetValue(2)),
                            Su_Descripcion           = Convert.ToString(reader.GetValue(3)),
                            Su_CodigoEstablecimiento = Convert.ToString(reader.GetValue(4)),
                            Su_Ruc                   = Convert.ToString(reader.GetValue(5)),
                            Su_JefeSucursal          = Convert.ToString(reader.GetValue(6)),
                            Su_Telefonos             = Convert.ToString(reader.GetValue(7)),
                            Su_Direccion             = Convert.ToString(reader.GetValue(8)),
                            IdUsuario                = SessionFixed.IdUsuario
                        };
                        Lista_Sucursal.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaSucursal.set_list(Lista_Sucursal, IdTransaccionSession);
                #endregion

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

                #region Bodega
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        tb_bodega_Info info = new tb_bodega_Info
                        {
                            IdEmpresa       = Convert.ToInt32(reader.GetValue(0)),
                            IdSucursal      = Convert.ToInt32(reader.GetValue(1)),
                            IdBodega        = Convert.ToInt32(reader.GetValue(2)),
                            cod_bodega      = Convert.ToString(reader.GetValue(3)),
                            bo_Descripcion  = Convert.ToString(reader.GetValue(4)),
                            IdCtaCtble_Inve = Convert.ToString(reader.GetValue(5)),
                            IdUsuario       = SessionFixed.IdUsuario
                        };
                        Lista_Bodega.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                ListaBodega.set_list(Lista_Bodega, IdTransaccionSession);
                #endregion
            }
        }