How to check if you are registered through Monthecalendar ? C#

Asked

Viewed 163 times

0

Talk good morning guys!

I’m having a little difficulty regarding use of Monthecalendar...

I have a scheduling system by DATA, which after registering the given event, it is presented in DATAGRIDVIEW,with the following code

`public void GetData()
        {
            try
            {
                cg.con = new SqlConnection(cn.DBconn);
                cg.con.Open();
                cg.cmd = new SqlCommand("SELECT RTRIM(Id),RTRIM(Nome) ,RTRIM(Endereco), RTRIM(Quadra), RTRIM(Lote), RTRIM(Telefone), RTRIM(Celular),(Data), RTRIM(Hora), RTRIM(Email), RTRIM(Observacao), RTRIM(Locacao), RTRIM(Evento),  RTRIM(Estado) from Eventos order by Data", cg.con);
                cg.rdr = cg.cmd.ExecuteReader(CommandBehavior.CloseConnection);
                DGW_Agenda.Rows.Clear();


                while (cg.rdr.Read() == true)
                {
                    DGW_Agenda.Rows.Add(cg.rdr[0], cg.rdr[1], cg.rdr[2], cg.rdr[3], cg.rdr[4], cg.rdr[5], cg.rdr[6], cg.rdr[7], cg.rdr[8], cg.rdr[9], cg.rdr[10], cg.rdr[11], cg.rdr[12], cg.rdr[13]);
                }

                cg.con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }`

What I would like is that when I clicked on some date in the monthercalendar it checked my datagridview in the column 'SCHEDULING DATE' if the date is scheduled, or available date for registration.

Follow the system screen print for better understanding. inserir a descrição da imagem aqui

  • 1

    And the code where it is? You can’t check on DataSource, Do you want when selecting a date it tells you it is not available or disable the unavailable dates in the selection? Will the system be used by multiple users? Are you doing some consistency control? Elaborate further your question by presenting a [MCVE]

  • Hello @Leandroangelo I can not check it in my datasource, I researched some foruns how to do this check, but I’m a little lost. The idea is only to check if the date is registered according to the registered event! doing the check in the datasource column.

  • I don’t understand why you can’t consult the datasource... but anyway if you present the code, there’s no way to help

1 answer

0

Without presenting your code and structure not how to detail more, but see the example below of an approach that can help you...

Hypothetical model structure for scheduling:

public class Agendamento
{
    public string Local { get; set; }
    public DateTime DataAgendamento { get; set; }
}

Structure of the form popuplando a DataGridView and already with the selection event bind to the MonthCalendar, sharing the same source for validation...

public partial class Main : Form
{

    private List<Agendamento> agendamentosDataSource { get; set; } = new List<Agendamento>();

    public Main()
    {
        InitializeComponent();

    }

    private void Main_Load(object sender, EventArgs e)
    {
        //Simulando uma consulta para popular a lista de agendamentos
        agendamentosDataSource.AddRange(
            new List<Agendamento>() {
                new Agendamento{ Local = "Teste 1", DataAgendamento = DateTime.Parse("18/04/2019") },
                new Agendamento{ Local = "Teste 2", DataAgendamento = DateTime.Parse("19/04/2019") },
            });

        //Apontando o DataSource da Grid para a lista
        grdPessoas.DataSource = agendamentosDataSource;

    }

    private void mcSelecionaData_DateChanged(object sender, DateRangeEventArgs e)
    {
        var dataSelecionada = (sender as MonthCalendar).SelectionStart;

        //Utilizando a mesma lista do DataSource da Grid para recuperar as datas reservadas.          
        var datasReservadas = agendamentosDataSource.Select(x => x.DataAgendamento);

        //Validação e feedback simples para o usuário...
        if (datasReservadas.Contains(dataSelecionada))
            MessageBox.Show("Essa Data já foi reservada");

    }
  • This is Leandro Angelo Thank you for your help, I reformulated the question to better understand the problem srsrs. I already have the form of data presentation of datagridview only do not know how to make this check by monthercalendar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.