時間を入力するデータ グリッド ビューがあり、その下には dataGridview 列の各列の最後にあるフッターのラベルがあり、|Mon| のようなアクティビティの毎日の合計時間を計算します。火| 結婚した
|1 | 2 | 3
|2 | 3 | 4
合計 3 5 6
通常のエントリでは正常に動作していますが、最初の行の月曜日の時刻を 1 から 5 に変更している場合は、その行の合計のみが表示されます
この場合、合計は 5 2 3 になります
次の行は、合計で計算する際に考慮されていません
どこが間違っているのか教えてください。
public void calcdaywisetotal()
{
try
{
if (dgvTimeReport.RowCount > 1)
{
decimal montot = 0, tuetot = 0, wedtot = 0, thutot = 0, fritot = 0, sattot = 0, suntot = 0, tottot = 0;
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
//decimal MonTotal = decimal.Parse(lblMonTotal.Text);
montot = montot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Monday"].Value);
lblMonTotal.Text = montot.ToString();
//monday
if (lblMonTotal.Text != null)
{
string[] strmontot = new string[2];
if (lblMonTotal.Text.Contains(","))
{
strmontot = lblMonTotal.Text.Split(',');
}
if (lblMonTotal.Text.Contains("."))
{
strmontot = lblMonTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strmontot[0]);
int min = Convert.ToInt32(strmontot[1]);
if (min < 60)
{
if (min >= 10)
{
lblMonTotal.Text = hr + "." + min;
}
else
{
lblMonTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblMonTotal.Text = hr + "." + min;
}
else
{
lblMonTotal.Text = hr + ".0" + min;
}
}
montot = Convert.ToDecimal(lblMonTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
tuetot = tuetot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Tuesday"].Value);
lblTueTotal.Text = tuetot.ToString();
//tuesday
if (lblTueTotal.Text != null)
{
string[] strtuetot = new string[2];
if (lblTueTotal.Text.Contains(","))
{
strtuetot = lblTueTotal.Text.Split(',');
}
if (lblTueTotal.Text.Contains("."))
{
strtuetot = lblTueTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strtuetot[0]);
int min = Convert.ToInt32(strtuetot[1]);
if (min < 60)
{
if (min >= 10)
{
lblTueTotal.Text = hr + "." + min;
}
else
{
lblTueTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblTueTotal.Text = hr + "." + min;
}
else
{
lblTueTotal.Text = hr + ".0" + min;
}
}
tuetot = Convert.ToDecimal(lblTueTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
wedtot = wedtot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Wednesday"].Value);
lblWedTotal.Text = wedtot.ToString();
//Wednesday
if (lblWedTotal.Text != null)
{
string[] strwedtot = new string[2];
if (lblWedTotal.Text.Contains(","))
{
strwedtot = lblWedTotal.Text.Split(',');
}
if (lblWedTotal.Text.Contains("."))
{
strwedtot = lblWedTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strwedtot[0]);
int min = Convert.ToInt32(strwedtot[1]);
if (min < 60)
{
if (min >= 10)
{
lblWedTotal.Text = hr + "." + min;
}
else
{
lblWedTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblWedTotal.Text = hr + "." + min;
}
else
{
lblWedTotal.Text = hr + ".0" + min;
}
}
wedtot = Convert.ToDecimal(lblWedTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
thutot = thutot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Thursday"].Value);
lblThuTotal.Text = thutot.ToString();
//Thursday
if (lblThuTotal.Text != null)
{
string[] strthutot = new string[2];
if (lblThuTotal.Text.Contains(","))
{
strthutot = lblThuTotal.Text.Split(',');
}
if (lblThuTotal.Text.Contains("."))
{
strthutot = lblThuTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strthutot[0]);
int min = Convert.ToInt32(strthutot[1]);
if (min < 60)
{
if (min >= 10)
{
lblThuTotal.Text = hr + "." + min;
}
else
{
lblThuTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblThuTotal.Text = hr + "." + min;
}
else
{
lblThuTotal.Text = hr + ".0" + min;
}
}
thutot = Convert.ToDecimal(lblThuTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
fritot = fritot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Friday"].Value);
lblFriTotal.Text = fritot.ToString();
//Friday
if (lblFriTotal.Text != null)
{
string[] strfritot = new string[2];
if (lblFriTotal.Text.Contains(","))
{
strfritot = lblFriTotal.Text.Split(',');
}
if (lblFriTotal.Text.Contains("."))
{
strfritot = lblFriTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strfritot[0]);
int min = Convert.ToInt32(strfritot[1]);
if (min < 60)
{
if (min >= 10)
{
lblFriTotal.Text = hr + "." + min;
}
else
{
lblFriTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblFriTotal.Text = hr + "." + min;
}
else
{
lblFriTotal.Text = hr + ".0" + min;
}
}
fritot = Convert.ToDecimal(lblFriTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
sattot = sattot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Saturday"].Value);
lblSatTotal.Text = sattot.ToString();
//Saturday
if (lblSatTotal.Text != null)
{
string[] strsattot = new string[2];
if (lblSatTotal.Text.Contains(","))
{
strsattot = lblSatTotal.Text.Split(',');
}
if (lblSatTotal.Text.Contains("."))
{
strsattot = lblSatTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strsattot[0]);
int min = Convert.ToInt32(strsattot[1]);
if (min < 60)
{
if (min >= 10)
{
lblSatTotal.Text = hr + "." + min;
}
else
{
lblSatTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblSatTotal.Text = hr + "." + min;
}
else
{
lblSatTotal.Text = hr + ".0" + min;
}
}
sattot = Convert.ToDecimal(lblSatTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
suntot = suntot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Sunday"].Value);
lblSunTotal.Text = suntot.ToString();
//Sunday
if (lblSunTotal.Text != null)
{
string[] strsuntot = new string[2];
if (lblSunTotal.Text.Contains(","))
{
strsuntot = lblSunTotal.Text.Split(',');
}
if (lblSunTotal.Text.Contains("."))
{
strsuntot = lblSunTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strsuntot[0]);
int min = Convert.ToInt32(strsuntot[1]);
if (min < 60)
{
if (min >= 10)
{
lblSunTotal.Text = hr + "." + min;
}
else
{
lblSunTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblSunTotal.Text = hr + "." + min;
}
else
{
lblSunTotal.Text = hr + ".0" + min;
}
}
suntot = Convert.ToDecimal(lblSunTotal.Text);
}
}
for (int i = 0; i < dgvTimeReport.RowCount; i++)
{
tottot = tottot + Convert.ToDecimal(dgvTimeReport.Rows[i].Cells["Total1"].Value);
lblTotTotal.Text = tottot.ToString();
//Total
if (lblTotTotal.Text != null)
{
string[] strtottot = new string[2];
if (lblTotTotal.Text.Contains(","))
{
strtottot = lblTotTotal.Text.Split(',');
}
if (lblTotTotal.Text.Contains("."))
{
strtottot = lblTotTotal.Text.Split('.');
}
int hr = Convert.ToInt32(strtottot[0]);
int min = Convert.ToInt32(strtottot[1]);
if (min < 60)
{
if (min >= 10)
{
lblTotTotal.Text = hr + "." + min;
}
else
{
lblTotTotal.Text = hr + ".0" + min;
}
}
else
{
hr = hr + 1;
min = min - 60;
if (min >= 10)
{
lblTotTotal.Text = hr + "." + min;
}
else
{
lblTotTotal.Text = hr + ".0" + min;
}
}
}
tottot = Convert.ToDecimal(lblTotTotal.Text);
}
}
else
{
lblMonTotal.Text = "0.00";
lblTueTotal.Text = "0.00";
lblWedTotal.Text = "0.00";
lblThuTotal.Text = "0.00";
lblFriTotal.Text = "0.00";
lblSatTotal.Text = "0.00";
lblSunTotal.Text = "0.00";
lblTotTotal.Text = "0.00";
}
}
catch (Exception Excp)
{
MessageBox.Show(Excp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
log.Fatal("Exception -" + Excp.Message);
return;
}
}