Exemplo n.º 1
0
 public string UpdListHotels(List <BEHotel> lstHotels)
 {
     return(DA.UpdListHotels(lstHotels));
 }
Exemplo n.º 2
0
        public string HospedajeImportBL(string filename, string delimiter, BEUser users)
        {
            //  Create the new table
            HotelsDA DA = new HotelsDA();

            string[] nombreArchivo = filename.Split('\\');
            int      index         = nombreArchivo.Length - 1;
            string   resp;
            string   idarchivo = "";

            try
            {
                if (DA.ValidarArchivosCargados(nombreArchivo[index]) == "0")
                {
                    //if (DA.InsArchivoCaragado(filename) == "1")
                    resp = DA.InsArchivoCaragado(nombreArchivo[index], ref idarchivo);
                    if (resp == "1")
                    {
                        List <BELocal> lstLocales = new List <BELocal>();

                        lstLocales = DA.GetLocales();
                        bool   ExisteLocal = false;
                        string codLocal    = string.Empty;
                        filename = filename.ToUpper();

                        resp = "No se encuentra ningun local";

                        foreach (BELocal local in lstLocales)
                        {
                            if (filename.Contains(local.nomLocal))
                            {
                                if (DA.ValidarUsuarioLocal(local.codLocal, users) == "1")
                                {
                                    resp        = "";
                                    ExisteLocal = true;
                                    codLocal    = local.codLocal;
                                }
                                else
                                {
                                    resp = "Usuario " + users.UserName + " no pertenece al local " + local.nomLocal;
                                }
                            }
                            else
                            {
                                resp = "No se reconoce el local en el nombre del archivo";
                            }
                        }

                        if (ExisteLocal == true)
                        {
                            List <BEHotel> lstHotel = new List <BEHotel>();
                            BEHotel        beHotel  = new BEHotel();

                            List <string> lista = new List <string>();

                            //obtengo los datos del fichero.

                            using (StreamReader fic = new StreamReader(filename))
                            {
                                string linea = null;
                                linea = fic.ReadLine();
                                while ((linea != null))
                                {
                                    lista.Add(linea);
                                    linea = fic.ReadLine();
                                }
                                fic.Close();
                            }
                            foreach (string registro in lista)
                            {
                                string[] columnNames = null;
                                beHotel     = new BEHotel();
                                columnNames = registro.Split('|');

                                if (columnNames.Length <= 1)
                                {
                                    throw new Exception("Existe una linea no valida");
                                }

                                beHotel.fechaDocumento  = columnNames[0].Trim().ToUpper();
                                beHotel.serie           = columnNames[1].Trim().ToUpper();
                                beHotel.correlativo     = columnNames[2].Trim().ToUpper();
                                beHotel.ruc             = columnNames[3].Trim().ToUpper();
                                beHotel.agencia         = columnNames[4].Trim().ToUpper();
                                beHotel.pasaporte       = columnNames[5].Trim().ToUpper();
                                beHotel.apellidoMaterno = string.Empty;
                                beHotel.apellidoPaterno = columnNames[6].Trim().ToUpper();
                                string NommbreCompleto = columnNames[7].Trim().ToUpper();
                                if (NommbreCompleto.IndexOf(" ") > 0)
                                {
                                    beHotel.nombre        = NommbreCompleto.Substring(0, NommbreCompleto.IndexOf(" ")).ToUpper();
                                    beHotel.segundoNombre = NommbreCompleto.Substring(NommbreCompleto.IndexOf(" ") + 1, NommbreCompleto.Length - (NommbreCompleto.IndexOf(" ") + 1)).ToUpper();
                                }
                                else
                                {
                                    beHotel.nombre        = NommbreCompleto.ToUpper();
                                    beHotel.segundoNombre = string.Empty;
                                }
                                beHotel.paisPasaporte     = columnNames[8].Trim().ToUpper();
                                beHotel.paisProcedencia   = columnNames[9].Trim().ToUpper();
                                beHotel.fechaIngresoHotel = columnNames[10].Trim().ToUpper();
                                beHotel.fechaSalidaHotel  = columnNames[11].Trim().ToUpper();
                                beHotel.nroFicha          = columnNames[12].Trim().ToUpper();
                                beHotel.x              = columnNames[13].Trim().ToUpper();
                                beHotel.unidad         = columnNames[14].Trim().ToUpper();
                                beHotel.y              = columnNames[15].Trim().ToUpper();
                                beHotel.ingresoPais    = columnNames[16].Trim().ToUpper();
                                beHotel.flagValidacion = "0";
                                beHotel.codLocal       = codLocal;
                                lstHotel.Add(beHotel);
                            }

                            //Log_ImportarDA LOGIDA = new Log_ImportarDA();
                            //LOGIDA.Limpiar_Log();


                            HotelsDA DAH   = new HotelsDA();
                            HotelBL  hotel = new HotelBL();
                            resp = DAH.INSListHotels(lstHotel, users, idarchivo);
                            //respuesta.Substring(0, 1).Equals("0");
                            if (resp.Substring(0, 1).Equals("1"))
                            {
                                List <BEHotel> lstBE  = new List <BEHotel>();
                                List <BEHotel> lstBE2 = new List <BEHotel>();
                                lstBE  = hotel.GetHotelsAll(codLocal);
                                lstBE2 = hotel.aplicarReglas(lstBE);
                                return(DAH.UpdListHotels(lstBE2));
                            }
                            else
                            {
                                throw new Exception(resp);
                            }
                        }
                        else
                        {
                            throw new Exception(resp);
                        }
                    }

                    {
                        throw new Exception(resp);
                    }
                }
                else
                {
                    throw new Exception("El archivo ya se cargo anteriormente");
                }
            }
            catch (Exception ex)
            {
                return("0|  " + ex.Message);
            }
        }