2016-09-09 44 views
0

任何人都可以幫助我嗎?我已經處理了幾個月,但我似乎無法找到解決方案。檢查庫存中是否有足夠的庫存

正如標題所說,我需要檢查每個餐點是否有足夠的配料,當我點擊POS中的某一餐時。

我有這些表結構在我的數據庫..

enter image description here

enter image description here enter image description here

正如你所看到的,炸雞的每一個服務包括以下成分從我的庫存來了。 假設某種成分沒有足夠的庫存,將出現一個消息框,指出庫存中沒有庫存,否則它將被添加到datagridview中。一旦我點擊我的POS中的炸雞,就會發生這種情況。

這裏是我的代碼:

 cmd = new MySqlCommand("SELECT * FROM tblmenu", dbConn); 
     MySqlDataReader rdr = cmd.ExecuteReader(); 

     while (rdr.Read()) 
     { 
      Button btn = new Button(); 
      btn.Name = rdr["menuID"].ToString(); 
      btn.BackgroundImage = Image.FromStream(ms); 
      btn.BackgroundImageLayout = ImageLayout.Stretch; 

      btn.Width = 120; 
      btn.Height = 100; 

      btn.Click += delegate 
      { 

       MySqlConnection cnn2 = new MySqlConnection(sqlConn.connString); 
       cnn2.Open(); 
       cmd = new MySqlCommand("SELECT menuID, menuName, menuPrice, menuCategory FROM tblmenu WHERE menuID = @id", cnn2); 
       cmd.Parameters.AddWithValue("@id", btn.Name); 
       MySqlDataReader rdr2 = cmd.ExecuteReader(); 

       if (rdr2.Read() == true) 
       { 

        dataGridView1.Rows.Add(rdr2.GetInt32("menuID"), rdr2.GetString("menuName").ToUpper(), 1, rdr2.GetDouble("menuPrice"), rdr2.GetDouble("menuPrice")); 

       } 
      }; 

那麼對於在DataGridView

void quantity_change(object sender, EventArgs e) 
    { 
     var row = dataGridView1.CurrentRow; 

     if (row == null || row.Index < 0) 
      return; 
     var unit = (sender == btnAdd) ? 1 : -1; 

     var quantity = Convert.ToInt32(row.Cells["Quantity"].Value) + unit; 


     row.Cells["Quantity"].Value = quantity; 
     var rate = Convert.ToDouble(row.Cells["Price"].Value); 
     row.Cells["TotalAmount"].Value = quantity * rate; 

    } 

我真的希望有人能幫助我在這裏調整量的功能,因爲這是唯一的事情我需要完成我的項目。

+0

從代碼中獲得的當前輸出是什麼? –

+0

我可以在數據網格中添加菜單/項目,但我真的不知道要使用哪種或哪些方法來檢查庫存中是否仍有足夠的原料。 – LazyPirate

+0

你使用什麼表引擎? InnoDB的? – Shadow

回答

0

btn.Click += delegate你不應該在tblmenu查詢,但從Ingredients表中選擇,並使用在MenuID的哪裏。同時加入庫存,選擇當前庫存值。

喜歡的東西:(未測試,但可能會給出提示)

SELECT menuID, menuName, menuPrice, menuCategory, tblinventory.Quantity AS StockQuantity, tblingredients.Quantity AS IngredientQuantity 
FROM tblingredients 
INNER JOIN tblinventory on tblingredients.InvID == tblinventory.ID 
WHERE menuID = @id 

並比較結果的StockQuantityIngredientQuantity


有一些問題的代碼:

dataGridView1.Rows.Add(rdr2.GetInt32("menuID"), rdr2.GetString("menuName").ToUpper(), 1, rdr2.GetDouble("menuPrice"), rdr2.GetDouble("menuPrice"));

爲什麼要添加菜單價格兩次?


配料菜單中的MenuName是多餘的。你應該刪除它。因爲成分是庫存和菜單之間的交集。你不想來存儲菜單名你不應該使用btn.Name這裏=>cmd.Parameters.AddWithValue("@id", btn.Name);使用btn.Tag,而不是每種成分



如何是units相關。 ingredients的單位與inventory的單位可能有差異。

+0

謝謝你回答,但我應該如何比較兩者? (庫存量和成分量)。我已經提出了你提出的想法。我添加menuPrice兩次,因爲我的dgv中有兩列,即銷售價格和調整數量的價格。 – LazyPirate

+0

a,我的不好。你只是想將菜單添加到網格中,而不是成分。在添加菜單之前,您應該檢查庫存。 (用我給你的查詢)然後用一段時間循環,你應該檢查每種成分的股票。 –

+1

1.可用性應該檢查兩次:生成列表和選擇用餐時間。 2.在第二次檢查時,如果使用select進行檢查,則記錄應該被鎖定,以防其他POS使用相同的成分。 – Shadow

相關問題