I'm trying to print a subtraction of dates using C # with WebForms, but I'm not sure how to correctly enter the attributes in the methods or how to print the method.
I'm converting the subtraction of the dates into days because I do not know how to work right with DateTime
, I do not know if I can do this directly.
After converting the difference between the least date and the largest date into days I enter those days into a new DateTime
which I called the total. So I have to print the total in days, months and years separately. But when I call in the Print method, which is called ImprimirExperiênciasTravalho()
, the IDE complains that this operation is not allowed.
The result I expected from this class would be the impression of the company, the position, the description of the obligations of the person in the company and when the person enters the date of entry into the company and exit, this impression would show the total time the person worked in this company.
The error you are giving is this one:
Operator '+' can not be applied to operand od type 'strig' and 'method group'
The following is the C # code:
public class Experiencias_Trabalho
{
private string nomeEmpresa, cargo, descricaoFuncao;
private DateTime dataInicio = new DateTime();
private DateTime dataSaida = new DateTime();
public Experiencias_Trabalho(string nomeEmpresa, string cargo, string descricaoFuncao, DateTime dataInicio, DateTime dataSaida)
{
this.nomeEmpresa = nomeEmpresa;
this.cargo = cargo;
this.descricaoFuncao = descricaoFuncao;
this.DataInicio = dataInicio;
this.DataSaida = dataSaida;
}
public string NomeEmpresa
{
get
{
return nomeEmpresa;
}
set
{
nomeEmpresa = value;
}
}
public string Cargo
{
get
{
return cargo;
}
set
{
cargo = value;
}
}
public string DescricaoFuncao
{
get
{
return descricaoFuncao;
}
set
{
descricaoFuncao = value;
}
}
public DateTime DataInicio
{
get
{
return dataInicio;
}
set
{
dataInicio = value;
}
}
public DateTime DataSaida
{
get
{
return dataSaida;
}
set
{
dataSaida = value;
}
}
public static string TempoTotal(DateTime DataInicio, DateTime DataSaida)
{
System.TimeSpan diff = DataSaida - DataInicio;
int diasTotais = Convert.ToInt32(diff.TotalDays);
DateTime total = new DateTime().AddDays(diasTotais);
return (total.Year - 1) + " anos, " + (total.Month % 12) + " meses " + (total.Day % 365) + " dias.";
}
public string Imprimir_Experiencias_Trabalho()
{
return "<tr>"
+ "<td>" + NomeEmpresa + "</td>"
+ "<td>" + Cargo + "</td>"
+ "<td>" + DescricaoFuncao + "</td>"
+ "<td>" + TempoTotal + "</td>"
+ "<td>" + "<i class='fa fa-edit'></i> <i class='fa fa-trash'></i>" + "</td>"
+ "</tr";
}
}