private void textBox2_KeyDown(object sender, KeyEventArgs e) { VentasDAO ventasDao = new VentasDAO(); if (e.KeyCode == Keys.Enter) { e.Handled = true; if (textBox2.Text.Trim().Equals("")) { //insertar nuevo folio textBox2.Text = ventasDao.nuevoFolio().ToString(); //Moverse al sector siguiente limpiarPantalla(); textBox8.Text = "Nota Pendiente"; textBox3.Text = "Contado"; cargarNota.IdCliente = 1; cargarNota.Adeudo = 0; cargarNota.Subtotal = 0; cargarNota.Total = 0; dataGridView1.Enabled = true; dataGridView1.Focus(); dataGridView1.Rows[0].Cells[0].Selected = true; textBox2.Enabled = false; checkBox1.Enabled = true; checkBox1.Checked = true; checkBox2.Enabled = false; checkBox2.Checked = false; } else { //buscar folio VentaNota ventaBuscar = null; //------------cargarNota = null; //Validar numeros try { ventaBuscar = ventasDao.buscarFolio(Convert.ToInt32(textBox2.Text)); } catch (Exception error) { textBox2.Clear(); MessageBox.Show("SoloNumeros"); return; } if (ventaBuscar == null) { MessageBox.Show("No existe la Nota"); textBox2.Clear(); } else { cargarNota = ventaBuscar; //Mostrar Descripcion Nota limpiarPantalla(); textBox7.Text = cargarNota.Adeudo.ToString(); textBox1.Text = cargarNota.Subtotal.ToString(); textBox5.Text = cargarNota.Iva.ToString(); textBox6.Text = cargarNota.Total.ToString(); checkBox1.Checked = cargarNota.Liquidada; if (cargarNota.IdCliente == 1) { textBox3.Text = "Contado"; } else { textBox3.Text = ventasDao.nombreCliente(cargarNota.IdCliente); } switch (cargarNota.Estado) { case 1: textBox8.Text = "Nota Impresa"; dataGridView1.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = true; break; case 2: textBox8.Text = "Nota Pendiente"; dataGridView1.Enabled = true; dataGridView1.Focus(); dataGridView1.Rows[0].Cells[0].Selected = true; textBox2.Enabled = false; checkBox1.Enabled = true; checkBox1.Checked = true; checkBox2.Enabled = false; checkBox2.Checked = false; break; case 3: textBox8.Text = "Nota Facturada"; checkBox2.Enabled = false; dataGridView1.Enabled = false; break; case 4: textBox8.Text = "Nota Cancelada"; dataGridView1.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = false; break; } int i = 0; OrdenNota[] ordenNota = null; ordenNota = ventasDao.cargarNota(cargarNota.IdNota); while (ordenNota[i] != null) { DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone(); row.Cells[0].Value = ordenNota[i].IdProducto; row.Cells[1].Value = ventasDao.nombreProducto(ordenNota[i].IdProducto); row.Cells[2].Value = ordenNota[i].Cantidad; row.Cells[3].Value = ordenNota[i].PrecioVenta; row.Cells[4].Value = ordenNota[i].Importe; dataGridView1.Rows.Add(row); i++; } } } } if (e.KeyCode == Keys.F9) //CANCELAR NOTA { if (!textBox2.Text.Trim().Equals("")) { if (cargarNota.Estado == 1) { var result = MessageBox.Show("Cancelar", "Desea Cancelar la Nota", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { cargarNota.Estado = 4; Boolean actualizar = ventasDao.updateVenta(cargarNota); limpiarPantalla(); } } } } }