Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从datagrid视图单元格C的值更新标签文本#_C#_Winforms_Datagrid_Label - Fatal编程技术网

C# 从datagrid视图单元格C的值更新标签文本#

C# 从datagrid视图单元格C的值更新标签文本#,c#,winforms,datagrid,label,C#,Winforms,Datagrid,Label,我有一个数据网格视图,我在其中输入时间小时,在它下面是dataGridview列每列末尾的页脚标签,该标签用于计算活动(如)每天的按天总小时数 |周一|周二|周三 |1 | 2 | 3 |2 | 3 | 4 总数356 对于正常的输入,它工作正常,但如果我在(比如)第一行星期一时间做任何更改,从1改为5,那么只有行总数来了 在这种情况下,总数将达到523 那就是下一行在计算中没有考虑到的总数 请让我知道我错在哪里 public void calcdaywisetotal() {

我有一个数据网格视图,我在其中输入时间小时,在它下面是dataGridview列每列末尾的页脚标签,该标签用于计算活动(如)每天的按天总小时数 |周一|周二|周三

|1 | 2 | 3

|2 | 3 | 4

总数356

对于正常的输入,它工作正常,但如果我在(比如)第一行星期一时间做任何更改,从1改为5,那么只有行总数来了

在这种情况下,总数将达到523

那就是下一行在计算中没有考虑到的总数

请让我知道我错在哪里

 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;
        }
    }
public void calcdaywisetotal()
{
尝试
{
如果(dgvTimeReport.RowCount>1)
{
十进制蒙托=0,图托特=0,韦德托特=0,图托特=0,弗里托=0,萨托特=0,桑托特=0,托托=0;
对于(int i=0;i=10)
{
lblMonTotal.Text=hr+“+min;
}
其他的
{
lblMonTotal.Text=hr+“.0”+分钟;
}
}
其他的
{
hr=hr+1;
min=min-60;
如果(最小值>=10)
{
lblMonTotal.Text=hr+“+min;
}
其他的
{
lblMonTotal.Text=hr+“.0”+分钟;
}
}
montot=Convert.ToDecimal(lblMonTotal.Text);
}
}
对于(int i=0;i=10)
{
lblTueTotal.Text=hr+“+min;
}
其他的
{
lblTueTotal.Text=hr+“.0”+分钟;
}
}
其他的
{
hr=hr+1;
min=min-60;
如果(最小值>=10)
{
lblTueTotal.Text=hr+“+min;
}
其他的
{
lblTueTotal.Text=hr+“.0”+分钟;
}
}
tuetot=Convert.ToDecimal(lblTueTotal.Text);
}
}
对于(int i=0;i=10)
{
lblWedTotal.Text
    if (lblMonTotal.Text.Contains(","))
    {
        strmontot = lblMonTotal.Text.Split(',');
    }
    if (lblMonTotal.Text.Contains("."))
    {
        strmontot = lblMonTotal.Text.Split('.');
    }
    else
    {
        strmontot = new string[2] { montot.ToString(), "0" };
    }


    else if (hr != 0)
    {
        lblMonTotal.Text = hr + ".0" + min;
    }