Example #1
0
        public static Socio registrarYobtener(int nroSocio)
        {
            Socio socio;
            DataSet ds = new DataSet();
            SqlDataAdapter dataAdapter = new SqlDataAdapter("socios_registrar", fPrincipal2.conn);
            dataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            dataAdapter.SelectCommand.Parameters.AddWithValue("@nroSocio", nroSocio);
            try
            {
                dataAdapter.Fill(ds);
                if (ds.Tables[0].Rows.Count > 0)
                    socio = new Socio(ds.Tables[0].Rows[0]);
                else
                    socio = null;
            }
            catch (Exception ex)
            {
                log.Error("Socio - registrarYobtener = "+ex.Message+ex.StackTrace);
                socio = null;
            }

            return socio;
        }
Example #2
0
        private void tbNroHab_KeyPress(object sender, KeyPressEventArgs e)
        {
            string msj;

            try
            {
                if ((char)Keys.Enter == e.KeyChar)
                {
                    e.Handled = true;

                    switch (pasoAsignacion)
                    {
                        case "nroHabitacion":

                            msj = validarNroHabitacion(tbNroHab);
                            if (msj != string.Empty)
                            {
                                labelMensaje.Text = msj;
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;
                            nroHab = int.Parse(tbNroHab.Text);

                            dgvPromos.Columns[1].HeaderText = "Categorias";
                            dgvOpcionesElegidas.Rows[0].Cells[1].Value = dgvOpcionesElegidas.Rows[0].Cells[1].Value.ToString() + " " + nroHab;

                            dictCategorias = Habitacion.obtenerCategorias(tbNroHab.Text);

                            foreach (int categoria in dictCategorias.Keys)
                            {
                                dgvPromos.Rows.Add(categoria, dictCategorias[categoria]);
                            }

                            panelPromos.Visible = true;
                            labelNroHab.Text = "Ingresar categoria";
                            tbNroHab.Text = dgvPromos.Rows[0].Cells[0].Value.ToString();
                            pasoAsignacion = "categoria";

                            break;

                        case "categoria":

                            msj = validarNroCategoria(tbNroHab);
                            if (msj != string.Empty)
                            {
                                labelMensaje.Text = msj;
                                labelMensaje.Visible = true;
                                return;
                            }

                            nroCategoria = int.Parse(tbNroHab.Text);
                            dgvPromos.Rows.Clear();
                            dgvPromos.Columns[1].HeaderText = "Promociones";

                            int nroPromo = 0;
                            int altoFila;
                            int altoFilaExtra;
                            labelMensaje.Visible = false;

                            DictDescuentos = new Dictionary<int, Descuento>();
                            dgvOpcionesElegidas.Rows[1].Cells[1].Value = dgvOpcionesElegidas.Rows[1].Cells[1].Value.ToString() + " " + dictCategorias[nroCategoria];
                            List<Descuento> lDescuentos = Descuento.obtenerDescuentos(nroCategoria);

                            tools.calcularAlturas(dgvPromos.Height - dgvPromos.ColumnHeadersHeight, lDescuentos.Count > tools.minCantFilas ? lDescuentos.Count : tools.minCantFilas, out altoFila, out altoFilaExtra);
                            dgvPromos.RowTemplate.Height = altoFila;

                            dgvPromos.Rows.Add(nroPromo, "Sin Promoción");
                            DictDescuentos.Add(nroPromo, new Descuento("Sin Promoción"));
                            foreach (Descuento desc in lDescuentos)
                            {
                                nroPromo++;
                                dgvPromos.Rows.Add(nroPromo, desc.nombre);
                                DictDescuentos.Add(nroPromo, desc);
                            }
                            tools.completarDG(dgvPromos, altoFilaExtra);
                            dgvPromos.ClearSelection();

                            panelPromos.Visible = true;
                            labelNroHab.Text = "Ingresar Promoción";
                            tbNroHab.Text = "0";
                            pasoAsignacion = "promocion";

                            break;

                        case "promocion":

                            msj = validarPromocion(tbNroHab);
                            if (msj != string.Empty)
                            {
                                labelMensaje.Visible = true;
                                labelMensaje.Text = msj;
                                return;
                            }
                            nroPromoElegida = int.Parse(tbNroHab.Text);
                            dgvOpcionesElegidas.Rows[2].Cells[1].Value = dgvOpcionesElegidas.Rows[2].Cells[1].Value.ToString() + " " + DictDescuentos[nroPromoElegida].nombre;
                            this.desc = DictDescuentos[nroPromoElegida];
                            if (nroPromoElegida == 0)// sin promocion
                            {
                                pasoAsignacion = "pernocte";
                                labelNroHab.Text = "Pernocte";
                                tbNroHab.Text = "0";
                                labelMensaje.Visible = false;
                                dgvPromos.Visible = false;
                            }
                            else
                            {
                                if (desc.nombre.ToLower().Contains("socio"))// promo socios, pedir tarjeta
                                {
                                    labelNroHab.Text = "Inserte Tarjeta";
                                    dgvPromos.Visible = false;
                                    tbNroHab.Text = "";
                                    tbNroHab.Width += 50;
                                    tbNroHab.MaxLength = 9;
                                    pasoAsignacion = "leerTarjeta";
                                    puntosStr = dgvOpcionesElegidas.Rows[4].Cells[1].Value.ToString();
                                    break;

                                }
                                else // otra promo
                                {
                                    pasoAsignacion = "pernocte";
                                    labelNroHab.Text = "Pernocte";
                                    tbNroHab.Text = "0";
                                    labelMensaje.Visible = false;
                                    dgvPromos.Visible = false;
                                }
                            }
                            panelPromos.Visible = true;
                            dgvPromos.Visible = true;
                            /*--- Modifico el dgv Promos ---*/
                            dgvPromos.Rows.Clear();
                            dgvPromos.Columns[1].HeaderText = " Pernocte ";
                            dgvPromos.Rows.Add(0,"No");
                            dgvPromos.Rows.Add(1,"Si");
                            /*-----------------------------------------------*/

                            break;

                        case "leerTarjeta":
                            int nroHotel = tools.obtenerParametroInt("nroHotelCodBarras");

                            if (tbNroHab.Text.Length > 2 && nroHotel.ToString() == tbNroHab.Text.Substring(0, 2))
                            {
                                socio = Socio.registrarYobtener(int.Parse(tbNroHab.Text.Substring(2)));
                                if (socio == null)
                                {
                                    labelMensaje.Text = "Error al registrar el Socio.";
                                    labelMensaje.Visible = true;
                                    return;
                                }
                                labelMensaje.Visible = false;
                                dgvOpcionesElegidas.Rows[3].Cells[1].Value = dgvOpcionesElegidas.Rows[3].Cells[1].Value.ToString() + " " + socio.nroSocio;
                                dgvOpcionesElegidas.Rows[4].Cells[1].Value = dgvOpcionesElegidas.Rows[4].Cells[1].Value.ToString() + socio.puntaje;
                                tbNroHab.Text = "0";
                                tbNroHab.MaxLength = 7;
                                labelNroHab.Text = "¿Cambiar puntos?";
                                pasoAsignacion = "puntos";
                            }
                            else
                            {
                                labelMensaje.Text = "El numero ingresado no corresponde a ninguna tarjeta valida.";
                                labelMensaje.Visible = true;
                                return;
                            }

                            break;

                        case "puntos":
                            tbNroHab.Text = String.IsNullOrEmpty(tbNroHab.Text) ? "0" : tbNroHab.Text;
                            if (int.Parse(tbNroHab.Text) > socio.puntaje)
                            {
                                labelMensaje.Text = "El cliente no tiene esa cantidad de puntos.";
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;
                            puntosACambiar = int.Parse(tbNroHab.Text);
                            dgvOpcionesElegidas.Rows[4].Cells[1].Value = puntosStr + (socio.puntaje - puntosACambiar);
                            tbNroHab.Text = "0";
                            labelNroHab.Text = "Pernocte";
                            pasoAsignacion = "pernocte";

                            /*--- Modifico el dgv Promos ---*/
                            dgvPromos.Rows.Clear();
                            dgvPromos.Columns[1].HeaderText = " Pernocte ";
                            dgvPromos.Rows.Add(0, "No");
                            dgvPromos.Rows.Add(1, "Si");
                            /*-----------------------------------------------*/
                            dgvPromos.Visible = true;
                            panelPromos.Visible = true;

                            break;

                        case "pernocte":

                            if (tbNroHab.Text != "1" && tbNroHab.Text != "0")
                            {
                                labelMensaje.Visible = true;
                                labelMensaje.Text = " 0 - No es pernocte\r\n 1 - Es pernocte";
                                return;
                            }
                            labelMensaje.Visible = false;
                            int altoFilaExtraMedioPagos;
                            DataSet ds = new DataSet();
                            pernocte = int.Parse(tbNroHab.Text);
                            dgvOpcionesElegidas.Rows[5].Cells[1].Value = pernocteString + (tbNroHab.Text == "1" ? " Si" : " No");

                            montoAPagar = Habitacion.calcularPrecioTurno(pernocte, this.desc.id, puntosACambiar, nroCategoria,out tarifaNoche,out descTotalHabitacion,out totExtra);

                            //decimal precioExtra = montoAPagar - (tarifaNoche == null ? 0 : tarifaNoche.precio);
                            if (montoAPagar == 0)
                            {
                                labelMensaje.Visible = true;
                                labelMensaje.Text = " No hay Tarifas cargadas para este horario y esta categoria ó el precio asignado es cero ";
                                return;
                            }
                            labelMensaje.Visible = true;
                            labelMensaje.Text = String.Format("{0:C}",montoAPagar) ;
                            labelMensaje.Font = new Font("Cooper Std", 38, FontStyle.Bold);
                            labelMensaje.BorderStyle = BorderStyle.FixedSingle;

                            SqlDataAdapter dataAdapter = new SqlDataAdapter("select * from mediosDePago", fPrincipal2.conn);
                            dataAdapter.Fill(ds);
                            dgvPromos.Rows.Clear();

                            tools.calcularAlturas(dgvPromos.Height - dgvPromos.ColumnHeadersHeight, ds.Tables[0].Rows.Count > tools.minCantFilas ? ds.Tables[0].Rows.Count : tools.minCantFilas, out altoFila, out altoFilaExtraMedioPagos);
                            dgvPromos.RowTemplate.Height = altoFila;

                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                dictMediosDePago.Add(int.Parse(dr[0].ToString()), dr[1].ToString());
                                dgvPromos.Rows.Add(dr[0].ToString(), dr[1].ToString());
                            }
                            // ----  Completando la tabla mediosPagos  ----//
                            tools.completarDG(dgvPromos, altoFilaExtraMedioPagos);
                            //---------------------------------------------------------------------------//

                            tbNroHab.Text = "0";
                            dgvPromos.Visible = true;
                            dgvPromos.Columns[1].HeaderText = "Medios de Pago";
                            labelNroHab.Text = "Medio de Pago ";
                            pasoAsignacion = "medioPago";

                            break;

                        case "adelanto":

                            decimal.TryParse(tbNroHab.Text.Replace('.', ','),out montoAdelantar);

                            labelMensaje.Visible = false;

                            panelPromos.Visible = true;
                            dgvOpcionesElegidas.Rows[7].Cells[1].Value = dgvOpcionesElegidas.Rows[7].Cells[1].Value + " " + String.Format("{0:C}", montoAdelantar);

                            labelNroHab.Text = "¿Confirmar?";
                            tbNroHab.Text = "0";
                            pasoAsignacion = "confirmar";

                            /*--- Modifico el dgv Promos ---*/
                            dgvPromos.Rows.Clear();
                            dgvPromos.RowTemplate.Height = 80;
                            dgvPromos.RowTemplate.DefaultCellStyle.Font = tools.fuenteConfirma;
                            dgvPromos.Columns[1].HeaderText = " Opciones ";
                            dgvPromos.Columns.RemoveAt(0);
                            dgvPromos.Rows.Add("Esc - Cancelar");
                            dgvPromos.Rows.Add("Enter - Confirmar");
                            /*-----------------------------------------------*/

                            tbNroHab.Visible = false;

                            break;

                        case "medioPago":

                            medioPago = string.IsNullOrEmpty(tbNroHab.Text) ? 0 : int.Parse(tbNroHab.Text);
                            if (!dictMediosDePago.ContainsKey(medioPago))
                            {
                                labelMensaje.Font = new Font("Microsoft Sans Serif", 15.25f, FontStyle.Bold);
                                labelMensaje.Text = "* El medio de Pago no existe *";
                                labelMensaje.Visible = true;
                                return;
                            }

                            labelMensaje.Text = String.Format("{0:C}", montoAPagar);
                            labelMensaje.Font = new Font("Cooper Std", 38, FontStyle.Bold);

                            dgvOpcionesElegidas.Rows[6].Cells[1].Value = dgvOpcionesElegidas.Rows[6].Cells[1].Value + " " + dictMediosDePago[medioPago];

                            pasoAsignacion = "adelanto";
                            labelNroHab.Text = "Importe a Adelantar  $";
                            tbNroHab.Text = "0";

                            break;

                        case "confirmar":
                            if (Habitacion.Asignar((fPrincipal2)this.Owner, this.desc.id, nroHab, pernocte, nroCategoria, ((fPrincipal2)this.Owner).conserjeActual.usuario, socio.id, puntosACambiar,montoAPagar,tarifaNoche,descTotalHabitacion,totExtra))
                            {
                                if(montoAdelantar > 0)
                                    Habitacion.Adelanto((fPrincipal2)this.Owner, nroHab,montoAdelantar, medioPago);
                                if (socio.id != 0)
                                    socio.descontarPuntos(puntosACambiar);

                                DetallesHabitacion detalle = Habitacion.obtenerDetalles(nroHab);
                                int minArestar;

                                if(detalle.duracion>=100)
                                    minArestar = tools.obtenerParametroInt("minFinTurnoMayor100");
                                else
                                    minArestar = tools.obtenerParametroInt("minFinTurnoMenor100");

                                try
                                {
                                    if(tools.obtenerParametroInt("emisionTicketAsignar")==1)
                                        new Impresora().ImprimirTicketAsignar(nroHab);
                                }
                                catch (Exception ex)
                                {
                                    LoggerProxy.Error("Error en Asignar Habitacion - Imprimir Ticket.\r\n" + ex.Message + "-" + ex.StackTrace);
                                    labelMensaje.Text = "Error, no se pudo imprimir.";
                                    labelMensaje.Visible = true;
                                }
                                Habitacion.agregarAlarma((fPrincipal2)this.Owner, nroHab,int.Parse(detalle.hasta.AddMinutes(-minArestar).ToString("HHmm")), 2);
                                LoggerProxy.Info(string.Format("Ejecuto Asignar Habitación - Nro.Hab:{0}, Categoria:{1}, Conserje:{2}.", nroHab, dictCategorias[nroCategoria], ((fPrincipal2)this.Owner).conserjeActual.nombre));
                                volverFormPrincipal();

                            }
                            else
                            {
                                labelMensaje.Text = "No se puede Asignar la Habitacion, posiblemente falten definir tarifas para la categoria elegida.";
                                labelMensaje.Visible = true;
                            }
                            return;

                        default:
                            break;

                    }

                    tbNroHab.Select(0, tbNroHab.TextLength);
                    dgvPromos.ClearSelection();
                    //tbNroHab.SelectionStart = tbNroHab.TextLength;
                    return;
                }
                if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != (char)Keys.Back)
                {
                    if (e.KeyChar == '+')
                    {
                        e.KeyChar = (char)Keys.Back;
                        tbNroHab_KeyPress(sender, e);
                    }
                    else
                        e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                labelMensaje.Text = ex.Message;
                labelMensaje.Visible = true;
                LoggerProxy.ErrorSinBD(ex.Message + "-" + ex.StackTrace);
            }
        }
Example #3
0
        internal static void AdelantarPuntos(fPrincipal2 fPrincipal, int nroHab, int puntos,ref Socio socio)
        {
            using (SqlConnection conn = new SqlConnection(fPrincipal2.conn.ConnectionString))
            {
                SqlTransaction transaccion = null;
                conn.Open();
                transaccion = conn.BeginTransaction(IsolationLevel.RepeatableRead);
                try
                {
                    SqlCommand comm = new SqlCommand("habitacion_adelantarPuntos", conn);
                    comm.Transaction = transaccion;
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.Parameters.AddWithValue("@nroHab", nroHab);
                    comm.Parameters.AddWithValue("@puntos", puntos);
                    comm.ExecuteNonQuery();

                    socio.descontarPuntos(puntos,transaccion,conn);
                    transaccion.Commit();
                    tools.actualizarListadoTurnos(fPrincipal.dataGridView1, fPrincipal.dataGridView2);
                }
                catch (Exception ex)
                {
                    transaccion.Rollback();
                    LoggerProxy.Error(ex.Message + "-" + ex.StackTrace);
                }
            }
        }
        private void tbNroHab_KeyPress(object sender, KeyPressEventArgs e)
        {
            string msj;
            try
            {
                if ((char)Keys.Enter == e.KeyChar)
                {
                    e.Handled = true;

                    switch (pasoAsignacion)
                    {
                        case "nroHabitacion":

                            msj = validarNroHabitacion(tbNroHab);
                            if (msj != string.Empty)
                            {
                                labelMensaje.Text = msj;
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;

                            nroHab = int.Parse(tbNroHab.Text);
                            detallesHab = Habitacion.obtenerDetalles(nroHab);
                            decimal saldoAfavor = decimal.Parse(detallesHab.ptosCambiados.ToString()) - detallesHab.impHabitacion < 0 ? 0 : decimal.Parse(detallesHab.ptosCambiados.ToString()) - detallesHab.impHabitacion;
                            dgvOpcionesElegidas.Rows[0].Cells[0].Value = dgvOpcionesElegidas.Rows[0].Cells[0].Value.ToString() + "    " + nroHab;
                            decimal importeAux2 = detallesHab.impHabitacion - decimal.Parse(detallesHab.ptosCambiados);
                            importeAux2 = importeAux2 < 0 ? 0 : importeAux2;// Si es negativo ,pongo cero.
                            dgvOpcionesElegidas.Rows[1].Cells[0].Value = dgvOpcionesElegidas.Rows[1].Cells[0].Value.ToString() + "    " + String.Format("{0:C}",importeAux2 );
                            dgvOpcionesElegidas.Rows[2].Cells[0].Value = dgvOpcionesElegidas.Rows[2].Cells[0].Value.ToString() + " " + detallesHab.ptosCambiados;
                            dgvOpcionesElegidas.Rows[3].Cells[0].Value = dgvOpcionesElegidas.Rows[3].Cells[0].Value.ToString() + "     " + String.Format("{0:C}", saldoAfavor); ;

                            labelNroHab.Text = "Medio de Pago ";
                            tbNroHab.Text = "0";
                            pasoAsignacion = "medioPago";
                            panelPromos.Visible = true;
                            dgvMedioPago.ClearSelection();

                            break;

                        case "medioPago":

                            medioPago = string.IsNullOrEmpty(tbNroHab.Text) ? 0 : int.Parse(tbNroHab.Text);
                            if (!dictMediosDePago.ContainsKey(medioPago))
                            {
                                labelMensaje.Text = "* El medio de Pago no existe *";
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;

                            //Agrego el tema de los Puntos

                            if (dictMediosDePago[medioPago].ToLower().Contains("puntos"))
                            {
                                if (string.IsNullOrEmpty(detallesHab.nroSocio))
                                {
                                    labelMensaje.Text = "* El cliente no es socio *";
                                    labelMensaje.Visible = true;
                                    return;
                                }
                                socio = Socio.registrarYobtener(int.Parse(detallesHab.nroSocio));

                                /*--- Modificar panel medios de pago---*/
                                dgvMedioPago.Rows.Clear();
                                dgvMedioPago.Columns[1].HeaderText = "Datos Socio";
                                dgvMedioPago.Rows.Add("","Puntos: "+ socio.puntaje);
                                dgvMedioPago.Rows.Add("", "Vencimiento: " + socio.fechaVencimientoPuntaje.ToString("dd-MM-yyyy"));
                                /*-------------------------------------*/
                                labelNroHab.Text = "Puntos a Cambiar";
                                pasoAsignacion = "puntos";
                            }
                            else
                            {
                                labelNroHab.Text = "Monto a Adelantar $ ";
                                pasoAsignacion = "monto";
                            }
                            dgvOpcionesElegidas.Rows[4].Cells[0].Value = dgvOpcionesElegidas.Rows[4].Cells[0].Value.ToString() + "    " + dictMediosDePago[medioPago];
                            tbNroHab.Text = "0";

                            break;

                        case "monto":

                            if (string.IsNullOrEmpty(tbNroHab.Text) || tbNroHab.Text == "0")
                            {
                                labelMensaje.Text = "* El monto debe ser mayor a cero *";
                                labelMensaje.Visible = true;
                                return;
                            }
                            monto = decimal.Parse(tbNroHab.Text.Replace('.', ','));
                            if (monto > detallesHab.impHabitacion - decimal.Parse(detallesHab.ptosCambiados) )
                            {
                                labelMensaje.Text = "* El monto debe ser inferior o igual al total *";
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;
                            dgvOpcionesElegidas.Rows[5].Cells[0].Value = dgvOpcionesElegidas.Rows[5].Cells[0].Value.ToString() + "  " + String.Format("{0:C}", decimal.Parse(tbNroHab.Text.Replace('.', ',')));

                            pasoAsignacion = "confirmar";
                            labelNroHab.Text = "Confirma Adelanto?";
                            tbNroHab.Visible = false;
                            mostrarOpcionConfirmar();

                            break;

                        case "puntos":

                            if (string.IsNullOrEmpty(tbNroHab.Text) || tbNroHab.Text == "0")
                            {
                                labelMensaje.Text = "* La cantidad de puntos debe ser mayor a cero *";
                                labelMensaje.Visible = true;
                                return;
                            }
                            puntos = int.Parse(tbNroHab.Text);
                            if (puntos > socio.puntaje)
                            {
                                labelMensaje.Text = "* Puntaje insuficiente *";
                                tbNroHab.Clear();
                                labelMensaje.Visible = true;
                                return;
                            }
                            labelMensaje.Visible = false;
                            dgvOpcionesElegidas.Rows[5].Cells[0].Value = dgvOpcionesElegidas.Rows[5].Cells[0].Value.ToString() + " " + puntos.ToString();

                            pasoAsignacion = "confirmar";
                            labelNroHab.Text = "Confirma Adelanto?";
                            tbNroHab.Visible = false;

                            /*--- Modifico el dgv Promos ---*/
                            mostrarOpcionConfirmar();

                            break;

                        case "confirmar":

                            if(puntos == 0)
                                Habitacion.Adelanto((fPrincipal2)this.Owner, nroHab, monto, medioPago);
                            else
                                //adelanto puntos y se los descuento al socio.
                                Habitacion.AdelantarPuntos((fPrincipal2)this.Owner, nroHab, puntos,ref socio);

                            LoggerProxy.Info(string.Format("Ejecuto Adelanto de Dinero - Hab:{0}  Monto:{1}",nroHab,monto));
                            volverFormPrincipal();
                            return;

                        default:
                            break;
                    }
                    tbNroHab.Select(0, tbNroHab.TextLength);
                    dgvMedioPago.ClearSelection();
                    //tbNroHab.SelectionStart = tbNroHab.TextLength;
                    return;
                }
                if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != (char)Keys.Back && e.KeyChar != '.' || (e.KeyChar == '.' && (pasoAsignacion == "nroHabitacion" || tbNroHab.Text.Contains('.'))))
                {
                    if (e.KeyChar == '+')
                    {
                        e.KeyChar = (char)Keys.Back;
                        tbNroHab_KeyPress(sender, e);
                    }
                    else
                        e.Handled = true;
                }
            }
            catch (Exception ex)
            {
                labelMensaje.Text = ex.Message;
                labelMensaje.Visible = true;
                LoggerProxy.Error(ex.Message + " - " + ex.StackTrace);
            }
        }