Consider an informed date on a form. Build a function that checks whether the date is correct (considering leap year, April 31, etc). You need to pass the date entered on the form as a parameter.
If the date is correct, build another function that will count the days from the beginning of the year to the date entered. Again passing the date as parameter. For example, how many days is 9/29/2015? Answer 258.
The rest I did, I just can not do this count of days.
This is all being done in C # with Windows Forms:
private void btnVerificar_Click(object sender, EventArgs e)
{
int iDia = Convert.ToInt32(txtDia.Text);
int iMes = Convert.ToInt32(txtMes.Text);
int iAno = Convert.ToInt32(txtAno.Text);
VerificaAno(iAno);
int iData = Convert.ToInt32(DateTime.Now.Year);
VerificaData(iDia, iMes, iAno);
int iTotalDias = Convert.ToInt32(DateTime.Now.Year);
ContarDias(iDia, iMes, iAno, iData);
}
private void VerificaData(int iDia, int iMes, int iAno)
{
int iData = DateTime.DaysInMonth(iAno, iMes);
if (iDia > iData || iDia < 1)
{
lblData.Text = "DATA INVÁLIDA";
lblData.ForeColor = System.Drawing.Color.Red;
}
else
{
lblData.Text = "DATA VÁLIDA";
lblData.ForeColor = System.Drawing.Color.Blue;
}
}
private void ContarDias(int iDia, int iMes, int iAno, int iData)
{
#####NO CASO SERIA AQUI QUE EU IRIA FAZER O MEU CÓDIGO#####
}
private void VerificaAno(int iAno)
{
if (((iAno % 400) == 0) || (iAno % 4 == 0 && iAno % 100 != 0))
{
lblAnoBissexto.Text = "ANO BISSEXTO";
}
else
{
lblAnoBissexto.Text = "ANO NÃO BISSEXTO";
}
}