I have 2 DataGridview
that load information from a database in MySQL, in the dataA
I have schedules, with a column time and a data type: 09:30 ( String
) and in dataB
I have the data of the appointments assigned for the day with its hour column ( String
) and the same format of the grid bull (since when booking the time, it is done with the data of that grid) .
What I have to do is a comparison between the columns hora
of both grid, and in this way, block in the gridA
(that of the hours) the row with the time that is already occupied (which would come being the time that appears in gridB
).
The code I use to make a comparison is the following:
//COMAPRAR SI EL CLICK VIENE DESDE EL METODO DE EDICION
if (variable == "prueba")
{
//MessageBox.Show("DESHABILITA LA COMPARACION POR HORA");
this.txtHorarioCita.Text = Convert.ToString(this.dgvHorarios.CurrentRow.Cells["hora"].Value);
this.lblIDHora.Text = Convert.ToString(this.dgvHorarios.CurrentRow.Cells["idHora"].Value);
}
else
{
this.txtHorarioCita.Text = Convert.ToString(this.dgvHorarios.CurrentRow.Cells["hora"].Value);
this.lblIDHora.Text = Convert.ToString(this.dgvHorarios.CurrentRow.Cells["idHora"].Value);
this.verificarHora();
}
and the verificarHora
method I have it like this:
private void verificarHora()
{
foreach (DataGridViewRow row in dgvConsultasDia.Rows) //dgvConsultasDia.Rows
{
string horaAtencion = Convert.ToString(row.Cells["hora"].Value);
if (horaAtencion == this.txtHorarioCita.Text)
{
MessageBox.Show("LA HORA SELECCIONADA ESTA OCUPADA", "CENTRO MEDICO CHILHUE", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
hora = "";
//this.label18.Visible = true;
//this.label1.Visible = false;
this.groupBox1.Enabled = false;
this.groupBox2.Enabled = false;
return;
}
else
{
//MessageBox.Show("la hora sel", "CENTRO MEDICO CHILHUE", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
//this.habilitarControles(true);
//this.groupBox1.Enabled = true;
this.groupBox2.Enabled = true;
this.btnGuardar.Enabled = true;
this.txtRutPaciente.Enabled = true;
//this.label1.Visible = true;
//this.label18.Visible = false;
break;
}
}
}
The variable prueba
comes from an edit button, and it works, but only once, if I repeat the process after a repeated record is found, it no longer works and it gives me the pass at insert
with the existing time.
Greetings to all, I appreciate from now on any example or guidance.