Tengo 2 DataGridview
que cargan información desde una base de datos en MySQL, en el dataA
tengo horarios, con una columna hora y un dato del tipo: 09:30 (String
) y en el dataB
tengo los datos de las citas asignadas para el día con su columna hora (String
) y el mismo formato del toro grid (ya que al reservar la hora, se hace con los datos de ese grid).
Lo que tengo que hacer es una comparación entre las columnas hora
de ambos grid, y de esta manera, bloquear en el gridA
(el de las horas) la fila con la hora que ya esta ocupada (que vendría siendo la hora que aparezca en el gridB
).
El código que uso para hacer una comparación es el siguiente:
//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();
}
y el método verificarHora
lo tengo así:
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;
}
}
}
La variable prueba
viene desde un botón de edición, y funciona, pero una sola vez, si vuelvo a repetir el proceso luego que se encuentra un registro repetido, ya no funciona y me da el pase al insert
con la hora ya existente.
Saludos a todos, agradezco desde ya cualquier ejemplo u orientación.