首页 > 代码库 > 20161014001 DataGridView 单元格内容 自动计算

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 = "http://www.mamicode.com/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 = "http://www.mamicode.com/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 = "http://www.mamicode.com/1";
                        }

                        T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFManufacturingCost"].Value =http://www.mamicode.com/
                        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 = "http://www.mamicode.com/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 = "http://www.mamicode.com/1";
                        }

                        T_Form_CY_CBD_D.Rows[e.RowIndex].Cells["DFWasteCost"].Value =http://www.mamicode.com/
                        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 单元格内容 自动计算