private void tbNroHab_KeyPress(object sender, KeyPressEventArgs e) { string msj; 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); dgvOpcionesElegidas.Rows[0].Cells[0].Value = dgvOpcionesElegidas.Rows[0].Cells[0].Value.ToString() + " " + nroHab; dgvOpcionesElegidas.ClearSelection(); foreach (DataRow dr in Articulo.obtenerConsumos(nroHab).Rows) { DictConsumos.Add(Convert.ToInt32(dr[0]), new Articulo(Convert.ToInt32(dr[0]), dr[2].ToString(), Convert.ToDecimal(dr[3]),Convert.ToInt32(dr[1]))); dgvOpcionesElegidas.Rows.Add(dr[1].ToString() + " " + dr[2].ToString(),String.Format("{0:C}",decimal.Parse(dr[3].ToString()))); } labelNroHab.Text = "Ingresar Nro.Art "; tbNroHab.Text = "0"; pasoAsignacion = "articulo"; break; case "articulo": msj = validarArticulo(tbNroHab); if (msj != string.Empty) { labelMensaje.Visible = true; labelMensaje.Text = msj; return; } if (tbNroHab.Text == "0") //Esto significa que no quiere mas articulos. { labelNroHab.Text = "Confirma anulación ?"; tbNroHab.Text = "1"; tbNroHab.Visible = false; /*--- 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(3); dgvPromos.Columns.RemoveAt(2); dgvPromos.Columns.RemoveAt(0); dgvPromos.Rows.Add("Esc - Cancelar"); dgvPromos.Rows.Add("Enter - Confirmar"); dgvPromos.ClearSelection(); panelPromos.Visible = true; /*-----------------------------------------------*/ break; } labelMensaje.Visible = false; nroArtElegido = int.Parse(tbNroHab.Text); dgvOpcionesElegidas.Rows.Add(DictArticulos[nroArtElegido].nombre); int ultFila = dgvOpcionesElegidas.Rows.GetLastRow(DataGridViewElementStates.None); dgvOpcionesElegidas.Rows[ultFila].DefaultCellStyle.ForeColor = Color.Red; dgvOpcionesElegidas.FirstDisplayedScrollingRowIndex = ultFila; dgvOpcionesElegidas.ClearSelection(); this.artElegido = DictArticulos[nroArtElegido]; pasoAsignacion = "cantidad"; tbNroHab.Text = "0"; labelNroHab.Text = "Ingresar Cantidad de Articulos "; break; case "cantidad": if (tbNroHab.Text == "" || (cantidad = int.Parse(tbNroHab.Text))== 0) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; } if (cantidad > DictConsumos[nroArtElegido].cantidadConsumida) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad no puede ser mayor a la consumida *"; return; } labelMensaje.Visible = false; if (!DictArticulosAnulados.ContainsKey(nroArtElegido)) DictArticulosAnulados.Add(nroArtElegido, cantidad); else { // si la clave ya existe verifico que no se supere la cantidad if (DictArticulosAnulados[nroArtElegido] + cantidad > DictConsumos[nroArtElegido].cantidadConsumida) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad no puede ser mayor a la consumida *"; return; } DictArticulosAnulados[nroArtElegido] += cantidad; } int indice = dgvOpcionesElegidas.Rows.GetLastRow(DataGridViewElementStates.None);// [[3].Cells[1].Value = dgvOpcionesElegidas.Rows[3].Cells[1].Value.ToString() + " " + socio.puntaje; dgvOpcionesElegidas.Rows[indice].Cells[0].Value = cantidad + " " + dgvOpcionesElegidas.Rows[indice].Cells[0].Value; dgvOpcionesElegidas.Rows[indice].Cells[1].Value = String.Format("{0:C}", DictArticulos[nroArtElegido].precio * cantidad); dgvOpcionesElegidas.ClearSelection(); labelNroHab.Text = "Ingresar Nro.Art "; tbNroHab.Text = "0"; pasoAsignacion = "articulo"; break; case "confirmar": if (tbNroHab.Text == "") { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; } labelMensaje.Visible = false; if(int.Parse(tbNroHab.Text) == 1) { try { Articulo.anularPedidoBar((fPrincipal2)this.Owner, DictArticulosAnulados, nroHab); LoggerProxy.Info(string.Format("Ejecuto Anular Pedido Bar - Hab:{0}",nroHab)); volverFormPrincipal(); return; // y mandar a imprimir ticket a la cocina. } catch (Exception ex) { if (ex.Message.Contains("articulo"))// cantidad de articulos incorrecta { labelMensaje.Text = ex.Message; pasoAsignacion = "cantidad"; tbNroHab.Text = cantidad.ToString(); labelNroHab.Text = "Ingresar Cantidad de Articulos "; } else labelMensaje.Text = "Ha ocurrido un error.Revisar los Logs."; labelMensaje.Visible = true; LoggerProxy.Error("Error al generar pedido de Bar - " + ex.Message + " " + ex.StackTrace); } } if (int.Parse(tbNroHab.Text) == 0) { volverFormPrincipal(); return; } break; default: break; } tbNroHab.Select(0, 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; } }
private void tbNroHab_KeyPress(object sender, KeyPressEventArgs e) { string msj; 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); dgvOpcionesElegidas.Rows[0].Cells[0].Value = dgvOpcionesElegidas.Rows[0].Cells[0].Value.ToString() + " " + nroHab; dgvOpcionesElegidas.ClearSelection(); foreach (DataRow dr in Articulo.obtenerConsumos(nroHab).Rows) { dgvOpcionesElegidas.Rows.Add(dr[1].ToString() + " " + dr[2].ToString(), String.Format("{0:C}", decimal.Parse(dr[3].ToString()))); } labelNroHab.Text = "Ingresar Nro.Art "; tbNroHab.Text = "0"; pasoAsignacion = "articulo"; break; case "articulo": msj = validarArticulo(tbNroHab); if (msj != string.Empty) { labelMensaje.Visible = true; labelMensaje.Text = msj; return; } if (tbNroHab.Text == "0") //Esto significa que no quiere mas articulos. { labelNroHab.Text = "¿ Confirma pedido ?"; tbNroHab.Text = "1"; tbNroHab.Visible = false; /*--- 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(3); dgvPromos.Columns.RemoveAt(2); dgvPromos.Columns.RemoveAt(0); dgvPromos.Rows.Add("Esc - Cancelar"); dgvPromos.Rows.Add("Enter - Confirmar"); dgvPromos.ClearSelection(); /*-----------------------------------------------*/ break; } labelMensaje.Visible = false; nroArtElegido = int.Parse(tbNroHab.Text); dgvOpcionesElegidas.Rows.Add(DictArticulos[nroArtElegido].nombre); int ultFila = dgvOpcionesElegidas.Rows.GetLastRow(DataGridViewElementStates.None); dgvOpcionesElegidas.Rows[ultFila].DefaultCellStyle.ForeColor = Color.Red; dgvOpcionesElegidas.FirstDisplayedScrollingRowIndex = ultFila; dgvOpcionesElegidas.ClearSelection(); this.artElegido = DictArticulos[nroArtElegido]; pasoAsignacion = "cantidad"; tbNroHab.Text = "1"; labelNroHab.Text = "Ingresar Cantidad de Articulos "; break; case "cantidad": int cantidad; if (tbNroHab.Text == "" || (cantidad = int.Parse(tbNroHab.Text)) == 0) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; } labelMensaje.Visible = false; if (DictArticulosPedidos.ContainsKey(nroArtElegido)) DictArticulosPedidos[nroArtElegido] += cantidad; else DictArticulosPedidos.Add(nroArtElegido, cantidad); int indice = dgvOpcionesElegidas.Rows.GetLastRow(DataGridViewElementStates.None);// [[3].Cells[1].Value = dgvOpcionesElegidas.Rows[3].Cells[1].Value.ToString() + " " + socio.puntaje; dgvOpcionesElegidas.Rows[indice].Cells[0].Value = cantidad + " " + dgvOpcionesElegidas.Rows[indice].Cells[0].Value; dgvOpcionesElegidas.Rows[indice].Cells[1].Value = String.Format("{0:C}", DictArticulos[nroArtElegido].precio * cantidad); dgvOpcionesElegidas.ClearSelection(); labelNroHab.Text = "Ingresar Nro.Art "; tbNroHab.Text = "0"; pasoAsignacion = "articulo"; break; case "confirmar": if (tbNroHab.Text == "") { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; } labelMensaje.Visible = false; if (int.Parse(tbNroHab.Text) == 1) { try { Articulo.generarPedidoBar((fPrincipal2)this.Owner, DictArticulosPedidos, nroHab); LoggerProxy.Info(string.Format("Ejecuto Pedido Bar - Hab:{0}", nroHab)); if (tools.obtenerParametroString("emisionPedidos") != "No") { /*ParameterizedThreadStart pth = new ParameterizedThreadStart(imprimirPedido); Thread th = new Thread(pth); th.Start(new pedidoAux(DictArticulosPedidos, nroHab, labelMensaje));*/ imprimirPedido(new pedidoAux(DictArticulosPedidos, nroHab, labelMensaje)); } List<string> sonido = new List<string>(); sonido.Add("pedido de bar.wav"); sonido.Add("habitacion numero.wav"); sonido.Add(nroHab.ToString()+".wav"); Audio.PlayList(sonido); volverFormPrincipal(); } catch (Exception ex) { labelMensaje.Text = "Ha ocurrido un error.Revisar los Logs."; labelMensaje.Visible = true; LoggerProxy.Error("Error al generar pedido de Bar - " + ex.Message + " " + ex.StackTrace); } return; } if (int.Parse(tbNroHab.Text) == 0) { volverFormPrincipal(); return; } break; default: break; } tbNroHab.Select(0, 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; } }
private void tbNroHab_KeyPress(object sender, KeyPressEventArgs e) { string msj; if ((char)Keys.Enter == e.KeyChar) { e.Handled = true; switch (pasoAsignacion) { case "articulo": msj = validarArticulo(tbNroHab); if (msj != string.Empty) { labelMensaje.Visible = true; labelMensaje.Text = msj; return; } labelMensaje.Visible = false; nroArtElegido = int.Parse(tbNroHab.Text); this.artElegido = DictArticulos[nroArtElegido]; pasoAsignacion = "fecha"; tbNroHab.Text = DateTime.Now.ToString("yyyyMMdd"); labelNroHab.Text = "Ingresar Fecha(AAAAMMDD)"; break; case "fecha": if (!DateTime.TryParseExact(tbNroHab.Text, "yyyyMMdd", CultureInfo.CurrentCulture, DateTimeStyles.None, out fecha)) { labelMensaje.Visible = true; labelMensaje.Text = "* La fecha es incorrecta *"; return; } labelMensaje.Visible = false; /* if (DictArticulosPedidos.ContainsKey(nroArtElegido)) DictArticulosPedidos[nroArtElegido] += cantidad; else DictArticulosPedidos.Add(nroArtElegido, cantidad); */ labelNroHab.Text = "Ingresar Compra "; tbNroHab.Text = "0"; pasoAsignacion = "compra"; break; case "compra": cantCompras = int.Parse(tbNroHab.Text); /* if (tbNroHab.Text == "" || (cantCompra = int.Parse(tbNroHab.Text)) == 0) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; }*/ labelMensaje.Visible = false; labelNroHab.Text = "Ingresar Reposición "; tbNroHab.Text = "0"; pasoAsignacion = "reposicion"; break; case "reposicion": cantReposicion = int.Parse(tbNroHab.Text); /* if (tbNroHab.Text == "" || (cantReposicion = int.Parse(tbNroHab.Text)) == 0) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; }*/ labelMensaje.Visible = false; labelNroHab.Text = "Ingresar P.Unitario "; tbNroHab.Text = "0"; pasoAsignacion = "punitario"; break; case "punitario": punitario = decimal.Parse(tbNroHab.Text.Replace('.', ',')); /* if (tbNroHab.Text == "" || (punitario = decimal.Parse(tbNroHab.Text.Replace('.',','))) == 0) { labelMensaje.Visible = true; labelMensaje.Text = "* La cantidad debe ser un numero mayor a 0 *"; return; }*/ labelMensaje.Visible = false; labelNroHab.Text = "Confirma Compra? "; 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"); dgvPromos.ClearSelection(); /*-----------------------------------------------*/ break; case "confirmar": labelMensaje.Visible = false; try { insertarCompras(); LoggerProxy.Info(string.Format("Ejecuto Compras")); volverFormPrincipal(); } catch (Exception ex) { labelMensaje.Text = "Ha ocurrido un error.Revisar los Logs."; labelMensaje.Visible = true; LoggerProxy.Error("Error al generar pedido de Bar - " + ex.Message + " " + ex.StackTrace); } return; default: break; } tbNroHab.Select(0, 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; } }