2017-04-03 4 views
0

私は在庫アプリケーション内にGridViewを持っています...私は製品のグリッドビューを使用しています...それはうまく動作していますが、同じベンダーの同じ製品がグリッドビューで複数回選択された場合、写真のように数量を合計して在庫よりも少ないことを確認します。 enter image description here重複DropDownListの行の合計値gridview内の選択された項目

例えばコンピュータ...すべてのヘルプは高く評価されるだろう ..量の値が追加され、その株式と比較されますが、それだけでその証券とそれを比較します単一の製品のためではなく、すべての重複した製品については ゾーンのキーボードが2回選択され、15の在庫があります... 10 + 7 = 17の数量を合計し、その在庫が15より大きい場合はメッセージをスローします。それ以外の場合は行として保存します... コンピュータゾーンのペンが2回選択されている(3回以上可能)50の在庫があります。数量10 + 60 = 70で、在庫が50より大きい場合はメッセージをスローします。

答えて

0

あなたはRoでこれを行うことができますグリッドビューのwDataBoundは簡単です。

数量、在庫、製品、およびベンダーを取得するだけで済みます。しかし、あなたはまた、以下の関数でこれを行うことができます、それはあなたに何か重複している場合はレコードを与えるでしょうgridview。

public void HighlightDuplicate(GridView gridview) 
{ 
    for(int currentRow = 0; currentRow < gridview.Rows.Count - 1; currentRow++) 
    { 
     GridViewRow rowToCompare = gridview.Rows[currentRow]; 
     for (int otherRow = currentRow + 1; otherRow < gridview.Rows.Count; otherRow++) 
     { 
      GridViewRow row = gridview.Rows[otherRow]; 
      bool duplicateRow = true; 
      //example: check Duplicate on column vendor(cell#0) and product(cell#1) 
      if ((rowToCompare.Cells[0].Text) != (row.Cells[0].Text) && (rowToCompare.Cells[1].Text) != (row.Cells[1].Text)) 
      { 
       duplicateRow = false; 
      } 
      else if (duplicateRow) 
      { 
       rowToCompare.Cells[1].Text = Convert.ToInt32(row.Cells[1].Text) + Convert.ToInt32(rowToCompare.Cells[1].Text); 
row.Visible=false; 
      } 
     } 
    } 
} 

この機能では、セルを持つ行と内部を比較してセルの値をチェックしていることを確認できます。

if ((rowToCompare.Cells[0].Text) != (row.Cells[0].Text) && (rowToCompare.Cells[1].Text) != (row.Cells[1].Text)) 
     { 
      duplicateRow = false; 
     } 
     else if (duplicateRow) 
     { 
      rowToCompare.Cells[1].Text = Convert.ToInt32(row.Cells[1].Text) + Convert.ToInt32(rowToCompare.Cells[1].Text); 
row.Visible=false; 
     } 

セルインデックス0と1を比較します。同じ場合はベンダーと製品が同じであることを意味します。ベンダーと製品が同じであれば、その値と設定を1つの行と2つ目の行に結合しています。表示可能なfalseを設定します。必要に応じて他の操作を実行できます。それに応じて任意の操作を行うことができます。 この関数は、DataBind()の後に呼び出すことができます。例えばGridViewのIDは、その後Gridview1の場合:

HighlightDuplicate(this.GridView1); 
1

あなたは、この製品の利用可能在庫と比較し、同一製品の総量を計算するためにJavaScriptやjQueryのを使用することができます。次のサンプルではjQueryを使用しました。

まず、グリッド内のすべてのアイテムに名前またはクラスを割り当てる必要があります。サンプル行は次のようになります。

<tr> 
    <td class="no">XX</td> 
    <td><select class="vendor" >... </select></td> 
    <td><select class="product" >...</select></td> 
    <td><input class="stock" value="YY" readonly="true"></td> 
    <td><input class="quantity" value="ZZ"></td> 
</tr> 

その後、項目の変更イベントのためのハンドラを追加数量

$('.quantity').change(function(e){ 
    var quantity = $(this); 
    var row = quantity.closest("tr"); 
    var selectedVendor = $(".vendor option:selected", row).val(); 
    var selectedProduct = $(".product option:selected", row).val(); 

    // Get all row that have the same vendor and product 
    var sameRows = $(".product option:selected[value='" + selectedProduct + "']", $(".vendor option:selected[value='" + selectedVendor + "']").closest("tr")).closest("tr"); 

    // Calculate total quantity of same product 
    var total = 0; 
    sameRows.each(function() { 
     total += parseInt($(".quantity", this).val()); 
    }); 

    // Compare total quantity and stock 
    var stock = parseInt($(".stock", row).val()); 
    if (total > stock) { 
     alert("Quantity access available stock"); 
     quantity.focus(); 
    } 
}); 

また、ドロップダウンベンダー製品について同様のハンドラを追加することを検討すべきです。

デモhereを作成しました。確認できました。

関連する問題