public IngresosCPRegistrados() { InitializeComponent(); lista = new List <Ingresocp>(); objigresosp = new Ingresocp(); try { cbxLugar.DataSource = objlugar.Ver(); cbxLugar.DisplayMember = "Nombre"; cbxLugar.ValueMember = "Nombre"; cbxLugar.SelectedItem = null; lista = objigresosp.Ver(); dgvISP.DataSource = lista; } catch (Exception error) { MessageBox.Show("Error al intentar conectarse con la base de datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnIngresarcp_Click(object sender, EventArgs e) { if (cbxIngresocp.SelectedValue == null) { MessageBox.Show("Es obligatorio seleccionar un LUGAR de ingreso.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtDPIngresocp.Text)) { MessageBox.Show("Es obligatorio llenar el campo DPI del cliente.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtEntregacp.Text)) { MessageBox.Show("Es obligatorio llenar el campo QUIÉN ENTREGA.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtPBcp.Text)) { MessageBox.Show("Es obligatorio llenar el campo PESO BRUTO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtTaracp.Text)) { MessageBox.Show("Es obligatorio llenar el campo TARA.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(lblPesoNeto.Text)) { MessageBox.Show("Debe hacer clic en el campo PESO NETO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtQ.Text)) { MessageBox.Show("Es obligatorio llenar el campo QUETZALES.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.IsNullOrEmpty(txtCtv.Text)) { MessageBox.Show("Es obligatorio llenar el campo CENTAVOS.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (int.Parse(txtQ.Text) >= 10 || int.Parse(txtQ.Text) <= 0) { MessageBox.Show("Debe pedir autorización para ingresar este precio.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (int.Parse(txtCtv.Text) > 99 || int.Parse(txtCtv.Text) < 10) { MessageBox.Show("Debe ingresar una cifra de 2 digitos en el campo CENTAVOS.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { int pb = int.Parse(txtPBcp.Text); int pn = pb - int.Parse(txtTaracp.Text); if (pn != int.Parse(lblPesoNeto.Text)) { MessageBox.Show("El peso neto no coincide con la diferencia entre el peso bruto y la tara.", "Alto", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { if (cbxFormaPago.SelectedItem == null) { MessageBox.Show("Debe seleccionar una FORMA DE PAGO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (cbxFormaPago.Text != "EFECTIVO" && cbxBanco.SelectedItem == null) { MessageBox.Show("Debe seleccionar un BANCO.", "Importante", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { try { string dpi = txtDPIngresocp.Text; while (dpi.Contains(" ")) { dpi = dpi.Replace(" ", ""); } SqlConnection conect = new SqlConnection("server = MBETANCOURT; database = cafedb; integrated security = true"); conect.Open(); string select = "select * from cliente where dpi = '" + dpi + "';"; SqlCommand comando = new SqlCommand(select, conect); SqlDataReader buscar = comando.ExecuteReader(); string idLugar = cbxIngresocp.SelectedValue.ToString(); string idFormaPago = cbxFormaPago.SelectedValue.ToString(); string cuenta; if (cbxBanco.SelectedValue == null) { cuenta = ""; } else { cuenta = cbxBanco.SelectedValue.ToString(); } if (buscar.Read()) { Ingresocp objingreso = new Ingresocp(txtDPIngresocp.Text, idLugar, txtEntregacp.Text.ToUpper(), txtPBcp.Text, txtTaracp.Text, lblPesoNeto.Text, txtQ.Text + "." + txtCtv.Text, idFormaPago, cuenta, usuario); objingreso.Agregar(); MessageBox.Show("Nuevo ingreso AGREGADO con éxito.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); cbxIngresocp.SelectedItem = null; txtDPIngresocp.Clear(); txtEntregacp.Clear(); txtPBcp.Clear(); txtTaracp.Clear(); txtQ.Clear(); txtCtv.Clear(); lblPesoNeto.Text = null; lblTotal.Text = "0.00"; cbxFormaPago.SelectedItem = null; cbxBanco.DataSource = null; } else { MessageBox.Show("El cliente ingresado no aparece registrado.", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information); } conect.Close(); } catch (Exception error) { MessageBox.Show("Error al intentar conectarse con la base de datos", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } } } } } } } } } } }