2013-06-23 79 views
1

我開發推定的應用程序和我有硬的時刻寫入的公式得到所需結果如下:如下所示如何將datagridview單元格格式化爲%或將公式寫入正確?

    Quantity/Production * Non productive % = Labor Hours 

上述公式應該被數學回答:

    1000 SF/300 SF per hour * @10% Non Productive= 3.6 Labor hours 

我的問題是如何編寫一個公式來正確計算人工小時數?

謝謝

這是我的代碼:

private void dgv1_CellEndEdit(object sender, DataGridViewCellEventArgs e) 

     { 

       double cell2 = Convert.ToSingle(dgv1.CurrentRow.Cells[2].Value); 

       double cell4 = Convert.ToSingle(dgv1.CurrentRow.Cells[4].Value); 

       double cell5 = Convert.ToSingle(dgv1.CurrentRow.Cells[5].Value); 

       double cell6 = Convert.ToSingle(dgv1.CurrentRow.Cells[6].Value); 

       double cell7 = Convert.ToSingle(dgv1.CurrentRow.Cells[7].Value); 

       double cell8 = Convert.ToSingle(dgv1.CurrentRow.Cells[8].Value); 

       double cell9 = Convert.ToSingle(dgv1.CurrentRow.Cells[9].Value); 

       double cell10 = Convert.ToSingle(dgv1.CurrentRow.Cells[10].Value); 

       double cell11 = Convert.ToSingle(dgv1.CurrentRow.Cells[11].Value); 

       double cell12 = Convert.ToSingle(dgv1.CurrentRow.Cells[12].Value); 

       double cell13 = Convert.ToSingle(dgv1.CurrentRow.Cells[13].Value); 

       double cell14 = Convert.ToSingle(dgv1.CurrentRow.Cells[14].Value); 

       double cell15 = Convert.ToSingle(dgv1.CurrentRow.Cells[15].Value); 

       double cell16 = Convert.ToSingle(dgv1.CurrentRow.Cells[16].Value); 

       double cell17 = Convert.ToSingle(dgv1.CurrentRow.Cells[17].Value); 

       if (2.ToString() != "" && cell4.ToString() != "" && cell5.ToString() != "" && cell6.ToString() != "" && cell7.ToString() != "" && cell8.ToString() != "" && cell9.ToString() != "" && cell10.ToString() != "" && cell11.ToString() != "" && cell12.ToString() != "" && cell13.ToString() != "" && cell14.ToString() != "" && cell15.ToString() != "" && cell16.ToString() != "" && cell17.ToString() != "") 
    { 
     dgv1.CurrentRow.Cells[6].Value = cell2/cell4 * cell5; // <------ This is the formula I'm talking about// 

     dgv1.CurrentRow.Cells[10].Value = cell6 * cell7 *cell8 *cell9; 

     dgv1.CurrentRow.Cells[13].Value = cell2/cell11; 

     dgv1.CurrentRow.Cells[17].Value = cell13 * cell14 * cell15 * cell16; 
    } 
} 
+0

,你在哪裏讀作Quantity','Production'並在代碼'非productive',以及如何計算'非productive'百分比是多少?我的意思是它應該分成什麼?總時數?如果是的話,你在哪裏閱讀? – mrz

回答

0

Quantity/(Production * ((Non productive/Total)* 100)) = Labor Hours

從你的代碼我假設cell2是數量,cell4是生產和cell5是非生產性的。

您需要做的第一件事就是找出如何計算非生產性百分比。我認爲(這意味着我不確定)它應該按照(Non productive/Total)* 100來計算,根據我的假設,非生產性的將是cell5,但我不知道總數在哪裏。

那麼你的公式應該是:

cell2/(cell4 * ((cell5/total) * 100))) 
+0

我現在就試試.....謝謝! – user2506869

+0

我似乎無法正確地將其轉換爲您的配方。 dgv1.CurrentRow.Cells [6] .Value = cell2/cell4 * cell5; – user2506869

+0

什麼是'cell2','cell4'和'cell5'? – mrz

相關問題