Exemplo n.º 1
0
        public void inicializar(HotSale hots)
        {
            if (Sesion.user != null)
            {
                simpleButton1.Visible = true;
            }
            else
            {
                simpleButton1.Visible = false;
            }
            hot = hots;
            Propiedad prop;

            using (ContextoEntity conexion = new ContextoEntity())
            {
                prop = conexion.Propiedads.Where(p => p.id == hot.idPropiedad).First();
            }
            nombreLabel.Text    = prop.nombre;
            ciudadLabel.Text    = prop.ciudad;
            ubicacionLabel.Text = prop.ubicaciòn;
            provinciaLabel.Text = prop.provincia;
            paisLabel.Text      = prop.pais;
            fechaLabel.Text     = Semanizador.LunesDeSemana(hot.añoReservado, hot.semanaReservada).Date.ToString();
            montoLabel.Text     = hot.monto.ToString();
        }
Exemplo n.º 2
0
        public void cancelarGanador(xucReservasFuturas UcQueLoLlama)
        {
            try
            {
                using (ContextoEntity conec = new ContextoEntity())
                {
                    if (Semanizador.LunesDeSemana(this.añoReservado, this.semanaReservada) >= DateTime.Now.AddMonths(6))
                    {
                        this.usuario.agregarCredito();
                        conec.Entry(this.usuario).State = System.Data.Entity.EntityState.Modified;
                    }


                    //conec.ReservaDirectas.Remove(ReservaDirecta.getOneById(this.id));
                    conec.Entry(this).State = System.Data.Entity.EntityState.Deleted;
                    conec.SaveChanges();
                }
                UcQueLoLlama.inicializar();
                MessageBox.Show("Se canceló la reserva con éxito");
            }
            catch (Exception e)
            {
                MessageBox.Show("Hubo un error en la cancelación de la reserva");
                throw e;
            }
        }
Exemplo n.º 3
0
        private void DarDeBaja_Click(object sender, EventArgs e)
        {
            Propiedad    propiedadSeleccionado = (Propiedad)gridView1.GetFocusedRow();
            string       st     = string.Concat("Seguro que desea Borrar la propiedad ", propiedadSeleccionado.id, "?");
            DialogResult result = MessageBox.Show(st, "Salir", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                using (ContextoEntity conec = new ContextoEntity())
                {
                    var propiedadaborrar = conec.Propiedads.Where(p => p.id == propiedadSeleccionado.id).First();
                    var fotito           = conec.fotos.Where(p => p.idPropiedad == propiedadaborrar.id).ToList();
                    if (tieneReserva(propiedadaborrar.id) && tieneHotsale(propiedadaborrar.id))
                    {
                        if (tieneSubasta(propiedadaborrar.id))
                        {
                            if (res != null)
                            {
                                foreach (ReservaDirecta r in res)
                                {
                                    if (DateTime.Now.AddMonths(6) <= r.fechaReservada)
                                    {
                                        var us = conec.usuarios.Where(p => p.mail == r.idUsuario).First();
                                        us.token++;
                                        conec.Entry(us).State = System.Data.Entity.EntityState.Modified;
                                    }
                                    var re = conec.ReservaDirectas.Where(p => p.id == r.id).First();
                                    conec.ReservaDirectas.Remove(re);
                                    conec.SaveChanges();
                                }
                                res = null;
                            }
                            if (hot != null)
                            {
                                foreach (HotSale r in hot)
                                {
                                    if (DateTime.Now.AddMonths(6) <= Semanizador.LunesDeSemana(r.añoReservado, r.semanaReservada) && r.idUsuario != null)
                                    {
                                        var us = conec.usuarios.Where(p => p.mail == r.idUsuario).First();
                                        us.token++;
                                        conec.Entry(us).State = System.Data.Entity.EntityState.Modified;
                                    }
                                    var re = conec.HotSales.Where(p => p.id == r.id).First();
                                    conec.HotSales.Remove(re);
                                    conec.SaveChanges();
                                }
                                hot = null;
                            }
                            conec.fotos.RemoveRange(fotito);
                            conec.Propiedads.Remove(propiedadaborrar);
                            conec.SaveChanges();
                            inicializar();
                            gridControl1.Update();
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
        public List <string> semanasDisponibles()
        {
            int           primeraSemana = Semanizador.getSemanaDelAño(DateTime.Now.AddMonths(6));
            int           ultimaSemana  = Semanizador.getSemanaDelAño(DateTime.Now.AddMonths(12));
            List <string> st            = new List <string>();
            int           i;

            if (primeraSemana >= ultimaSemana)
            {
                for (i = primeraSemana; i <= 52; i++)
                {
                    if (this.EstaLibre(i, DateTime.Now.Year, false))
                    {
                        string aux = Semanizador.LunesDeSemana(DateTime.Now.Year, i).ToString("dd/MM/yyyy");
                        st.Add(aux);
                    }
                }
                for (i = 1; i <= ultimaSemana; i++)
                {
                    if (this.EstaLibre(i, DateTime.Now.Year + 1, false))
                    {
                        string aux = Semanizador.LunesDeSemana(DateTime.Now.Year + 1, i).ToString("dd/MM/yyyy");
                        st.Add(aux);
                    }
                }
            }
            else
            {
                if (Semanizador.getSemanaDelAño(DateTime.Now) < primeraSemana)
                {
                    for (i = primeraSemana; i <= ultimaSemana; i++)
                    {
                        if (this.EstaLibre(i, DateTime.Now.Year, false))
                        {
                            string aux = Semanizador.LunesDeSemana(DateTime.Now.Year, i).ToString("dd/MM/yyyy");
                            st.Add(aux);
                        }
                    }
                }
                else
                {
                    for (i = primeraSemana; i <= ultimaSemana; i++)
                    {
                        if (this.EstaLibre(i, DateTime.Now.Year + 1, false))
                        {
                            string aux = Semanizador.LunesDeSemana(DateTime.Now.Year + 1, i).ToString("dd/MM/yyyy");
                            st.Add(aux);
                        }
                    }
                }
            }
            return(st);
        }
Exemplo n.º 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            Propiedad    st = encontrarCual(comboBox1.AccessibilityObject.Value);
            DialogResult m  = MessageBox.Show("Desea crear el Hotsale?", "Crear Hotsale", MessageBoxButtons.YesNo);

            if (m == DialogResult.Yes)
            {
                if (st != null)
                {
                    DateTime d;
                    if (DateTime.TryParse(maskedTextBox2.Text, out d))
                    {
                        if (d.CompareTo(DateTime.Now) >= 0)
                        {
                            int numeroSemana = Int32.Parse(comboBox3.SelectedItem.ToString().GetCharsBefore(" - "));
                            if (st.EstaLibre(numeroSemana, (int)comboBox2.SelectedItem, true))
                            {
                                if (Semanizador.LunesDeSemana((int)comboBox2.SelectedItem, numeroSemana).CompareTo(DateTime.Parse(maskedTextBox2.Text).AddDays(7)) > 0)
                                {
                                    HotSale nuevoHotSale = new HotSale(d, d.AddDays(7), maskedTextBox1.AccessibilityObject.Value, numeroSemana, (int)comboBox2.SelectedItem, st);

                                    st.HotSales.Add(nuevoHotSale);

                                    nuevoHotSale.guardarEnBD();

                                    this.inicializar();
                                    MessageBox.Show("Se creó el hotsale con éxito");
                                }
                                else
                                {
                                    MessageBox.Show("Debe existir al menos 7 días de diferencia entre la fecha de inicio y la semana elegida");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("La fecha de inicio es incorrecta");
                        }
                    }
                    else
                    {
                        MessageBox.Show("No es una fecha valida");
                    }
                }
                else
                {
                    MessageBox.Show("La propiedad elegida es errónea");
                }
            }
        }
Exemplo n.º 6
0
        private void button2_Click(object sender, EventArgs e)
        {
            Propiedad st = encontrarCual(comboBox1.AccessibilityObject.Value);

            if (st != null)
            {
                DateTime d;
                //DialogResult m = MessageBox.Show("Desea crear la subasta?","Crear Subasta", MessageBoxButtons.YesNo);
                if (DateTime.TryParse(maskedTextBox2.AccessibilityObject.Value, out d))
                {
                    if (d.CompareTo(DateTime.Now) >= 0)
                    {
                        //toDo: verificar si funciona sin estoint numeroSemana = Int32.Parse(comboBox3.SelectedText.GetCharsBefore(" - "));
                        int numeroSemana = Int32.Parse(comboBox3.Text.GetCharsBefore(" - "));
                        if (st.EstaLibre(numeroSemana, (int)comboBox2.SelectedItem, true))
                        {
                            if (Semanizador.LunesDeSemana((int)comboBox2.SelectedItem, numeroSemana).CompareTo(DateTime.Parse(maskedTextBox2.Text).AddMonths(6)) >= 0)
                            {
                                subasta nuevaSubasta = new subasta((int)comboBox2.SelectedItem, numeroSemana, maskedTextBox1.AccessibilityObject.Value, d, st.id);

                                st.subastas.Add(nuevaSubasta);

                                //ToDo: No se puede guardar la propiedad con la subasta adentro, ver de dar de alta solo la subasta
                                nuevaSubasta.guardarEnBD();

                                this.inicializar();
                                MessageBox.Show("Se creó la subasta con éxito");
                            }
                            else
                            {
                                MessageBox.Show("La semana elegida debe superar en 6 meses la fecha de inicio");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("La fecha de inicio es incorrecta");
                    }
                }
                else
                {
                    MessageBox.Show("La fecha es invalida");
                }
            }
            else
            {
                MessageBox.Show("La propiedad elegida es errónea");
            }
        }
Exemplo n.º 7
0
 private void llenarConSubastas(object sender, EventArgs e)
 {
     semanas.Clear();
     for (int i = 1; i <= 52; i++)
     {
         if (Semanizador.LunesDeSemana((int)comboBox2.SelectedItem, i).CompareTo(DateTime.Today) <= 0)
         {
             continue;
         }
         semanas.Add(string.Concat(i.ToString(), Semanizador.LunesDeSemana((int)comboBox2.SelectedItem, i).ToString(" - (dd/MM/yyyy)")));
     }
     comboBox3.DataSource    = null;
     comboBox3.DataSource    = semanas;
     comboBox3.SelectedIndex = 0;
 }
Exemplo n.º 8
0
 public void inicializar(HotSale hots, Propiedad prop)
 {
     if (Sesion.user != null)
     {
         simpleButton1.Visible = true;
     }
     else
     {
         simpleButton1.Visible = false;
     }
     hot = hots;
     nombreLabel.Text    = prop.nombre;
     ciudadLabel.Text    = prop.ciudad;
     ubicacionLabel.Text = prop.ubicaciòn;
     provinciaLabel.Text = prop.provincia;
     paisLabel.Text      = prop.pais;
     fechaLabel.Text     = Semanizador.LunesDeSemana(hot.añoReservado, hot.semanaReservada).Date.ToShortDateString();
     montoLabel.Text     = hot.monto.ToString();
 }
Exemplo n.º 9
0
        internal bool EstaLibre(int semana, int año, bool saltarMensajes)
        {
            Propiedad propDeDb;

            using (ContextoEntity conec = new ContextoEntity())
            {
                propDeDb = conec.Propiedads
                           .Include(a => a.ReservaDirectas)
                           .Include(a => a.HotSales)
                           .Include(a => a.subastas)
                           .Where(p => p.id == this.id).FirstOrDefault();
            }
            DateTime diaParaCheckear = Semanizador.LunesDeSemana(año, semana);

            if (propDeDb.ReservaDirectas.Any(p => p.semanaReservada == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya está reservada para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una reserva");
                }
                return(false);
            }
            else if (propDeDb.subastas.Any(p => p.semana_de_subasta == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya tiene una subasta para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una subasta");
                }
                return(false);
            }
            else if (propDeDb.HotSales.Any(p => p.semanaReservada == semana && p.añoReservado == año))
            {
                if (saltarMensajes)
                {
                    MessageBox.Show(String.Format("La propiedad ya tiene un HotSale reservado para la semana {0} del año {1}", semana, año), "La propiedad ya tiene una reserva");
                }
                return(false);
            }

            return(true);
        }
 public void cancelarGanador(xucReservasFuturas UcQueLoLlama)
 {
     try
     {
         using (ContextoEntity conec = new ContextoEntity())
         {
             if (Semanizador.LunesDeSemana(this.subasta.añoReservado, this.subasta.semana_de_subasta) >= DateTime.Now.AddMonths(6))
             {
                 this.usuario.agregarCredito();
                 conec.Entry(this.usuario).State = System.Data.Entity.EntityState.Modified;
             }
             conec.ganadorDeSubastas.Remove(this);
             conec.SaveChanges();
             UcQueLoLlama.inicializar();
             MessageBox.Show("Se canceló la reserva con éxito");
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 11
0
        private void reservaDirectaButton_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Quiere confirmar la reserva?", "Reserva", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                if (Sesion.user.token > 0)
                {
                    DateTime semanaAReservar = DateTime.Parse(reservaDirectaComboBox.SelectedItem.ToString());
                    if (this.propi.EstaLibre(Semanizador.getSemanaDelAño(semanaAReservar), semanaAReservar.Year, true))
                    {
                        using (ContextoEntity conec = new ContextoEntity())
                        {
                            ReservaDirecta re = new ReservaDirecta(this.propi.id, Sesion.user.mail, this.propi.montoReserva, Semanizador.getSemanaDelAño(semanaAReservar), semanaAReservar.Year);
                            conec.ReservaDirectas.Add(re);
                            conec.SaveChanges();
                            Sesion.user.restarCredito();
                        }
                        MessageBox.Show(string.Format("Se adjudico la reserva para la fecha {0}", semanaAReservar.ToString("dd/MM/yyyy")));
                        this.inicializar(this.propi);
                    }
                }
                else
                {
                    MessageBox.Show("No tiene suficientes creditos");
                }
            }
            else
            {
                DialogResult resul = MessageBox.Show("Quiere cancelar la operacion?", "Reserva", MessageBoxButtons.OKCancel);
                if (resul == DialogResult.OK)
                {
                    MessageBox.Show("No se realizo la operacion de reserva");
                }
            }
        }
Exemplo n.º 12
0
 public bool esFutura()
 {
     if (this.añoReservado > DateTime.Today.Year)
     {
         return(true);
     }
     else if (this.añoReservado == DateTime.Today.Year && this.semanaReservada > Semanizador.getSemanaDelAño(DateTime.Today))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 13
0
        public void inicializar(Propiedad pro)
        {
            this.propi = pro;
            if (Sesion.user.premium)
            {
                reservaDirectaButton.Visible      = true;
                reservaDirectaComboBox.Visible    = true;
                reservaDirectaLabel.Visible       = true;
                reservaDirectaButton.Enabled      = true;
                reservaDirectaComboBox.DataSource = pro.semanasDisponibles();
                precioReservaDirectaLabel.Enabled = true;
                montoReservaDirectaLabel.Enabled  = true;
                montoReservaDirectaLabel.Text     = pro.montoReserva.ToString();
            }
            else
            {
                reservaDirectaButton.Visible      = false;
                reservaDirectaComboBox.Visible    = false;
                reservaDirectaLabel.Visible       = false;
                reservaDirectaButton.Enabled      = false;
                precioReservaDirectaLabel.Visible = false;
                montoReservaDirectaLabel.Visible  = false;
            }
            var sub = subasta.llenarConSubasta(pro.id);

            if (sub != null)
            {
                List <string> subastasActivas = new List <string>();
                foreach (subasta s in sub)
                {
                    if (s.estaActiva())
                    {
                        subastasActivas.Add(string.Format(Semanizador.LunesDeSemana(Semanizador.semanaSegunFechaInicio(s.fecha_inicio, s.semana_de_subasta).Year, s.semana_de_subasta).ToString("dd/MM/yyyy")));
                        subActivas.Add(s);
                    }
                }
                subastasActivasListBox.DataSource = subastasActivas;
                if (subastasActivasListBox.ItemCount < 1)
                {
                    subastasActivasListBox.Text = "No hay subastas activas";
                }
            }
            else
            {
                subastasActivasListBox.Text = "No hay subastas activas";
            }

            var hot = HotSale.traerDeDB(pro.id);

            if (hot != null)
            {
                List <string> hotsaleActivos = new List <string>();
                foreach (HotSale h in hot)
                {
                    if (h.fechaInicio <= DateTime.Now && h.fechaFin >= DateTime.Now)
                    {
                        hotsaleActivos.Add(string.Format(Semanizador.LunesDeSemana(h.añoReservado, h.semanaReservada).ToString("dd/MM/yyyy")));
                        hotActivos.Add(h);
                    }
                }
                hotsaleBox.DataSource = hotsaleActivos;
                if (hotsaleBox.ItemCount < 1)
                {
                    hotsaleBox.Text = "No hay hotsales activos";
                }
            }
            else
            {
                hotsaleBox.Text = "No hay hotsales activos";
            }
        }