Ejemplo n.º 1
0
        public void InsertOrUpdateSaleRawmaterialsReport(IEnumerable<COrderDetails> check)
        {
            FinishedRawProductListDAO finishedRawProductListDao = new FinishedRawProductListDAO();
             KitchenStockDAO aKitchenStockDao=new KitchenStockDAO();

            try
            {
                this.OpenConnection();
                foreach (COrderDetails cOrderDetailse in check)
                {
                    List<CFinishedRawProductList> finishedRawProductList =
                        finishedRawProductListDao.GetFinishedRawProductListByProductID(
                            Convert.ToInt32(cOrderDetailse.ProductID));
                    //aKitchenStockDao.UpdateStock(Convert.ToInt32(finishedRawProduct.RawProductID),
                    //   finishedRawProduct.Qnty * (orderDetails.OrderQuantity - orderDetails.KitchenQuantity));

                    foreach (CFinishedRawProductList finishedRawProduct in finishedRawProductList)
                    {
                        int flag = 0;
                          KitchenStock aKitchenStock=new KitchenStock();
                          aKitchenStock = aKitchenStockDao.GetStockByItemidFrominventory_kitchen_stock((int)finishedRawProduct.RawProductID);
                        string sqlComm = String.Format(SqlQueries.GetQuery(Query.ExitOrNot), aKitchenStock.ItemId,
                                                       DateTime.Now.Date);
                        IDataReader aReader = this.ExecuteReader(sqlComm);
                        if(aReader!=null)
                        {
                            while(aReader.Read())
                            {
                                flag = Convert.ToInt32(aReader["sale_id"]);
                            }
                            aReader.Close();
                        }
                        if(flag==0)
                        {
                             sqlComm = String.Format(SqlQueries.GetQuery(Query.InsertSalereport), aKitchenStock.ItemId,
                                    cOrderDetailse.OrderQuantity*finishedRawProduct.Qnty,aKitchenStock.UnitPrice*cOrderDetailse.OrderQuantity*finishedRawProduct.Qnty,
                                    DateTime.Now.Date);
                            this.ExecuteNonQuery(sqlComm);
                        }
                        if (flag > 0)
                        {
                            sqlComm = String.Format(SqlQueries.GetQuery(Query.UpdateSalereport),
                                          cOrderDetailse.OrderQuantity * finishedRawProduct.Qnty,
                                          aKitchenStock.UnitPrice * cOrderDetailse.OrderQuantity * finishedRawProduct.Qnty, flag);
                            this.ExecuteNonQuery(sqlComm);
                        }

                    }

                }

            }
            catch (Exception ex)
            {

                throw new Exception("InsertOrUpdateSaleRawmaterialsReport()",ex);
            }
            finally
            {
                this.CloseConnection();
            }
        }
Ejemplo n.º 2
0
        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;
        }