20161014001 DataGridView 单元格内容 自动计算

Posted 我的梦会回来

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了20161014001 DataGridView 单元格内容 自动计算相关的知识,希望对你有一定的参考价值。

private void T_Form_CY_CBD_D_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (T_Form_CY_CBD_D.Rows.Count > 0 && e.RowIndex >= 0)
            {

                // 计算制造成本的公式依据:工费率/产能/直通率.
                if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "DFWorkRate" || T_Form_CY_CBD_D.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "DFCapacity" || T_Form_CY_CBD_D.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "DFFPY")
                {
                    try
                    {
                        T_Form_CY_CBD_D.Columns["DFManufacturingCost"].ReadOnly = true;

                        if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFWorkRate"].Value.ToString().Trim() == "")
                        {
                            T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFWorkRate"].Value = "1";
                        }
                        if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFCapacity"].Value.ToString().Trim() == "")
                        {
                            T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFCapacity"].Value = "1";
                        }
                        if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFFPY"].Value.ToString().Trim() == "")
                        {
                            T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFFPY"].Value = "1";
                        }

                        T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFManufacturingCost"].Value =
                        System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFWorkRate"].Value) /
                        System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFCapacity"].Value) /
                        System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFFPY"].Value);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }

                // 计算浪费成本的公式依据: (制造成本)*(1-效率)/ 效率)
                if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "DFManufacturingCost"
                    || T_Form_CY_CBD_D.Rows[e.RowIndex].Cells[e.ColumnIndex].OwningColumn.Name == "DFEfficiency")
                {
                    try
                    {
                        T_Form_CY_CBD_D.Columns["DFWasteCost"].ReadOnly = true;

                        if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFManufacturingCost"].Value.ToString().Trim() == "")
                        {
                            T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFManufacturingCost"].Value = "0.00";
                        }
                        if (T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFEfficiency"].Value.ToString().Trim() == "")
                        {
                            T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFEfficiency"].Value = "1";
                        }

                        T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFWasteCost"].Value =
                        System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFManufacturingCost"].Value) *
                        (1 - System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFEfficiency"].Value)) /
                        System.Convert.ToDecimal(T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFEfficiency"].Value);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }

                //

            }
        }

以上是关于20161014001 DataGridView 单元格内容 自动计算的主要内容,如果未能解决你的问题,请参考以下文章

c#设置datagridview行标题

VB.net datagridview 折叠展开

怎么插入datagridview的行

datagridview怎么把一行数据复制到另一个datagridview [C# VS2005]

c#怎么把datagridview给填满

C#datagridview怎么设置行标题的文字?