Display Automatic Date Sequence

0

I have a question regarding Datagridview:

I'm doing a payroll system, in this system I have to bring the first day of the release and the final day. The problem is that, for example, I need to make a system in which every time he press the "record" button he takes the start date and every new line he manages the next day:

Example

linha[0] = 10/03/2018

linha[1] = 11/03/2018

linha[n] = ...

Is it possible to do this automatically?

Below is the image below:

Please ignore input fields and checkboxes.

Thank you in advance

    
asked by anonymous 11.03.2018 / 21:33

1 answer

0

I have solved the problem, I will leave the code here if it is useful for 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
            );
}
    
12.03.2018 / 12:00