Display automatic date sequence

Asked

Viewed 42 times

0

I have a question about Datagridview:

I’m making a payroll system, in that system I have to bring the first day of release and the final day. The problem is that, for example, I need to make a system where every time he presses the "record" button he takes the starting date and every new line he manages the next day:

Example

linha[0] = 10/03/2018

linha[1] = 11/03/2018

linha[n] = ...

It is possible to do this automatically?

Following image below:

O preenchimento automático é abaixo da data

Please ignore input fields and checkboxes.

Grateful from now on

1 answer

0

Guys I managed to solve, I’ll leave the code here in case it’s useful to someone:

    private void Gravar_Click(object sender, EventArgs e)
        {

   //evento para inserir a data no datagridview
   //ao inves de pegar a data atual ele pega o valor do datetime picker

            var culture = new CultureInfo("pt-BR"); //setar culture em portugues para traduzir dia da semana

            DateTime dataAtual = DateTime.Now;//pega data atual

            string diaDaSemanaAtual = culture.DateTimeFormat.GetDayName(dataAtual.DayOfWeek).ToString();
            string somenteDataTexto = dataAtual.ToShortDateString();//pega somente a parte da data para ser mostrada

            //se possui itens no grid, atualiza a "dataAtual"
            if (DataGridColaboradores.Rows.Count > 0)
            {
                var ultimaLinha = DataGridColaboradores.Rows[DataGridColaboradores.Rows.Count - 1].Cells[0].Value.ToString();
                dataAtual = Convert.ToDateTime(ultimaLinha);
                DateTime dataMaisUm = dataAtual.AddDays(1);
                diaDaSemanaAtual = culture.DateTimeFormat.GetDayName(dataMaisUm.DayOfWeek).ToString();
                somenteDataTexto = dataMaisUm.ToShortDateString();
            }


            DataGridColaboradores.Rows.Add(
                somenteDataTexto,
                diaDaSemanaAtual,
                textBoxEntrada.Text,
                textBoxSaida.Text,
                textBoxEntrada2.Text,
                textBoxSaida2.Text
            );
}

Browser other questions tagged

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