private void button2_Click(object sender, EventArgs e)
{
Boolean huboError = this.hacerValidacionesDeTipo();
if (!encontroCliente)
{
if (txtDni.Text.Length > 0 && txtApe.Text.Length > 0)
{
SqlDataReader varCli = this.tieneDocumento(txtDni.Text);
varCli.Read();
if (varCli.HasRows)
{
MessageBox.Show("Dni inválido. Ya existe un Cliente con ese DNI", "Error cliente", MessageBoxButtons.OK);
huboError = true;
}
}
}
if (dp.Value.CompareTo(Program.fechaHoy()) > 0)
{
huboError = true;
MessageBox.Show("La Fecha de Nacimiento debe ser anterior a la fecha actual", "Error en los datos", MessageBoxButtons.OK);
}
if (dgButacas.CurrentCell == null)
{
huboError = true;
MessageBox.Show("No ha seleccionado ninguna butaca disponible", "Error en los datos", MessageBoxButtons.OK);
}
else
{
if (dgButacas.SelectedRows[0].Cells["N° Butaca"].Style.BackColor == Color.Gray)
{
huboError = true;
MessageBox.Show("La butaca seleccionada ya se encuentra ocupada", "Error en los datos", MessageBoxButtons.OK);
}
}
string viaje_cod = (((this.anterior as Compra.Form4).anterior as Compra.Form3).anterior as Compra.Form1).viaje;
if (encontroCliente)
{
string fechaSalida = (((this.anterior as Compra.Form4).anterior as Compra.Form3).anterior as Compra.Form1).fechaSalida;
string fechaLlegada = (((this.anterior as Compra.Form4).anterior as Compra.Form3).anterior as Compra.Form1).fechaLlegada;
string cli_cod = dgCliente.Rows[0].Cells["CLI_COD"].Value.ToString();
SQLManager.ejecutarQuery("select * from [ABSTRACCIONX4].pasajero_disponible('" + cli_cod + "', '" + fechaSalida + "', '" + fechaLlegada + "')", dgCliente);
if (dgCliente.RowCount == 0)
{
MessageBox.Show("El cliente no puede realizar un viaje porque ya tiene programado otro viaje en ese periodo", "Error en los datos", MessageBoxButtons.OK);
huboError = true;
this.inicio();
}
}
if ((this.anterior as Compra.Form4).seRegistroPasajeDelCliente(txtDni.Text, txtApe.Text))
{
MessageBox.Show("Ya se selecciono un pasaje para el cliente en este vuelo", "Error en los datos", MessageBoxButtons.OK);
huboError = true;
}
if(!huboError)
{
MessageBox.Show("Se ha guardado el pasaje", "Pasaje confirmado", MessageBoxButtons.OK);
string matricula = (((this.anterior as Compra.Form4).anterior as Compra.Form3).anterior as Compra.Form1).matricula;
if (!this.encontroCliente)
{
dgCliente2.ColumnCount = 13;
this.agregarCampos(dgCliente2);
dgCliente2.Rows.Add("0", txtDni.Text, txtNom.Text, txtApe.Text, txtDire.Text, txtTel.Text,
txtMail.Text, dp.Value.ToString());
}
dgButacas.SelectedRows[0].Cells["N° Butaca"].Style.BackColor = Color.Gray;
dgButacas.SelectedRows[0].Cells["Tipo"].Style.BackColor = Color.Gray;
if (this.encontroCliente)
{
if (this.actualizarTabla)
{
(this.anterior as Compra.Form4).agregarPasaje(dgCliente.Rows[0].Cells["CLI_COD"].Value.ToString(), txtDni.Text, txtNom.Text, txtApe.Text, txtDire.Text, txtTel.Text, txtMail.Text, dp.Text, dgButacas.SelectedRows[0].Cells["N° Butaca"].Value.ToString(), dgButacas.SelectedRows[0].Cells["Tipo"].Value.ToString(), this.calcularImporte(), actualizarTabla, encontroCliente, viaje_cod, matricula);
}
else
{
(this.anterior as Compra.Form4).agregarPasaje(dgCliente.Rows[0], dgButacas.SelectedRows[0].Cells["N° Butaca"].Value.ToString(), dgButacas.SelectedRows[0].Cells["Tipo"].Value.ToString(), this.calcularImporte(), actualizarTabla, encontroCliente, viaje_cod, matricula);
}
}
else
{
(this.anterior as Compra.Form4).agregarPasaje(dgCliente2.Rows[0], dgButacas.SelectedRows[0].Cells["N° Butaca"].Value.ToString(), dgButacas.SelectedRows[0].Cells["Tipo"].Value.ToString(), this.calcularImporte(), actualizarTabla, encontroCliente, viaje_cod, matricula);
}
this.cantidadButacas -= 1;
/*this.inicio();
if ((anterior as Form4).butacasRestantes() == 0)*/
this.cambiarVisibilidades(this.anterior);
}
}