我在计算小时数时出错。您在下面看到的值取自数据库,我使用 C# 的任务是计算小时数的总和。
我列出了下面的问题:
1) 总错误时间,
2) 正如您在数据网格视图中看到的,有一个时间为 9.7 小时,但不可能一个小时有 70 分钟!我把C#代码和相关数据网格视图放在下面,你能帮我解决吗?
数据网格视图值:
24-07-2018 9:7 08:30
25-07-2018 0:0 08:30
26-07-2018 9:42 08:30
Final sum-> 18:49 1:30
C# 代码:
private void buttonCarica_Click(object sender, EventArgs e)
{
dataGridViewPrincipale.Hide();
dataGridViewSecondario.Hide();
resetDataGrid();
string StartDate = dateTimePickerInizio.Value.Date.ToString("dd-MM-yy");
string EndData = dateTimePickerFine.Value.Date.ToString("dd-MM-yy");
Utente utemp = new Utente(comboBoxUtenti.Text);
timemanager tm = new timemanager(utemp);
PeopleController r = new PeopleController(utemp);
DataTable dt = tm.CaricaDataeTotaleHour(StartDate, EndData);
if (dt.Rows.Count == 0)
{
reset();
MessageBox.Show("\n ATTENZIONE: " + comboBoxUtenti.Text + " in questo range di tempo non ha effettuato marcature");
}
else
{
labelTotaleHourWork.Show();
labelTotaleHourWorkMod.Show();
labelTotaleHourtimemanagerMod.Show();
labelTotaletimemanager.Show();
dataGridViewPrincipale.Show();
TimeSpan tempoSpanTotaleHourWork = TimeSpan.Zero;
foreach (DataRow dr in dt.Rows)
{
String TotaleHourWork = r.CaricaHourGiornaliere(dr["Data"].ToString());
if (TotaleHour.Equals("0") == false)
{
TotaleHourWork = TotaleHourWork.Replace(",", ":");
tempoSpanTotaleHourWork = SommaHour(TotaleHourWork, tempoSpanTotaleHourWork);
}
if (tempoSpanTotaleHourWork == TimeSpan.Zero)
{
TotaleHourWork = "0";
}
函数 CheckValue.ConversioneTimeSpantoString :
public static String ConversioneTimeSpantoString(TimeSpan tm)
{
return "" + tm.Hours.ToString().Replace("-", "").ToString() + ":" + tm.Minutes.ToString().Replace("-", "").ToString();
}
鸿蒙传说
温温酱
相关分类