private bool CheckStockControl() { CCategory3DAO cCategory3Dao = new CCategory3DAO(); COrderManager tempOrderManager = new COrderManager(); List<COrderDetails> tempOrderDetailsList = new List<COrderDetails>(); CResult oResult = tempOrderManager.OrderDetailsByOrderID(orderID); if (oResult.IsSuccess && oResult.Data != null) tempOrderDetailsList = (List<COrderDetails>)oResult.Data; string stockMessage = "Stock is unavailable "; bool isStockAvailable = true; foreach (COrderDetails orderDetail in tempOrderDetailsList) { CCategory3 cCategory3 = cCategory3Dao.GetAllCategory3ByCategory3ID(Convert.ToInt32(orderDetail.ProductID)); if ((orderDetail.OrderQuantity - orderDetail.KitchenQuantity) > cCategory3.MUnitsInStock && cCategory3.MNonStockable) { //stockMessage += "\n " + orderDetail.Product_Name + " " + (orderDetail.OrderQuantity - cCategory3.MUnitsInStock); stockMessage += "\n " + cCategory3.Category3Name + ": Needed: " + (orderDetail.OrderQuantity - orderDetail.KitchenQuantity) + " But Have " + (cCategory3.MUnitsInStock); isStockAvailable = false; } } if (!isStockAvailable) { CUserInfoDAO aUserInfoDao = new CUserInfoDAO(); CUserInfo aUserInfo = new CUserInfo(); aUserInfo = aUserInfoDao.GetUserInfoByUsername(RMSGlobal.LoginUserName); if (aUserInfo.Type == 0) { DialogResult dialogResult = MessageBox.Show("Do You Proceed", "Stock Alert", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { isStockAvailable = true; } else if (dialogResult == DialogResult.No) { } } } if (!isStockAvailable || !CheckRawProduct(tempOrderDetailsList)) { CMessageBox cMessageBox = new CMessageBox("Finished Product", stockMessage); cMessageBox.ShowDialog(); //MessageBox.Show(stockMessage); return false; } else { foreach (COrderDetails orderDetails in tempOrderDetailsList) { CCategory3 cCategory3 = cCategory3Dao.GetAllCategory3ByCategory3ID(Convert.ToInt32(orderDetails.ProductID)); if (!cCategory3.MNonStockable) { cCategory3Dao.UpdateStock(Convert.ToInt32(orderDetails.ProductID), orderDetails.OrderQuantity - orderDetails.KitchenQuantity); COrderDetailsDAO cOrderDetailsDao = new COrderDetailsDAO(); cOrderDetailsDao.UpdateKitchenQuantity(orderDetails); } } } // parrentForm.scre return true; }
private bool CheckRawProduct(List<COrderDetails> tempOrderDetailsList) { CCategory3DAO cCategory3Dao = new CCategory3DAO(); FinishedRawProductListDAO finishedRawProductListDao = new FinishedRawProductListDAO(); string stockMessage = "Stock is unavailable "; bool isStockAvailable = true; KitchenStockDAO aKitchenStockDao = new KitchenStockDAO(); foreach (COrderDetails orderDetail in tempOrderDetailsList) { List<CFinishedRawProductList> finishedRawProductList = finishedRawProductListDao.GetFinishedRawProductListByProductID(Convert.ToInt32(orderDetail.ProductID)); foreach (CFinishedRawProductList finishedRawProduct in finishedRawProductList) { // CCategory3 cCategory3 = cCategory3Dao.GetAllCategory3ByCategory3ID(Convert.ToInt32(finishedRawProduct.RawProductID)); KitchenStock aKitchenStock = new KitchenStock(); // KitchenStockDAO aKitchenStockDao=new KitchenStockDAO(); aKitchenStock = aKitchenStockDao.GetStockByItemidFrominventory_kitchen_stock((int)finishedRawProduct.RawProductID); //List<CCategory3> aList = cCategory3Dao.GetAllCategory3(); //var temp = from acategory in aList where acategory.Category2ID == cCategory3.Category2ID select acategory; if (finishedRawProduct.Qnty * (orderDetail.OrderQuantity - orderDetail.KitchenQuantity) > aKitchenStock.Stocks) { stockMessage += "\n " + finishedRawProduct.RawProductName + ": Needed: " + finishedRawProduct.Qnty * (orderDetail.OrderQuantity - orderDetail.KitchenQuantity) + "\n " + " But Have: " + (aKitchenStock.Stocks); isStockAvailable = false; } } } if(!isStockAvailable) { CUserInfoDAO aUserInfoDao=new CUserInfoDAO(); CUserInfo aUserInfo=new CUserInfo(); aUserInfo = aUserInfoDao.GetUserInfoByUsername(RMSGlobal.LoginUserName); if (aUserInfo.Type == 0) { DialogResult dialogResult = MessageBox.Show("Do You Proceed", "Stock Alert", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { isStockAvailable = true; } else if (dialogResult == DialogResult.No) { } } } if (!isStockAvailable) { CMessageBox cMessageBox = new CMessageBox("Raw Product", stockMessage); cMessageBox.ShowDialog(); return false; } else { foreach (COrderDetails orderDetails in tempOrderDetailsList) { List<CFinishedRawProductList> finishedRawProductList = finishedRawProductListDao.GetFinishedRawProductListByProductID( Convert.ToInt32(orderDetails.ProductID)); foreach (CFinishedRawProductList finishedRawProduct in finishedRawProductList) { aKitchenStockDao.UpdateStock(Convert.ToInt32(finishedRawProduct.RawProductID), finishedRawProduct.Qnty * (orderDetails.OrderQuantity - orderDetails.KitchenQuantity)); } COrderDetailsDAO cOrderDetailsDao = new COrderDetailsDAO(); cOrderDetailsDao.UpdateKitchenQuantity(orderDetails); } } return true; }