Example #1
0
        public void OrderProductModify(int id, OrderProduct orp)
        {
            DataTable dt = new DataTable();
            dt = db.execQuery("Sp_OrderProductSelById", new Object[] { id, orp.product_id });
            if (dt.Rows.Count > 0)
            {

                int qtt_product_master = Convert.ToInt32(dt.Rows[0]["qty"]);
                if (orp.qty != Convert.ToInt16(dt.Rows[0]["qty"]))
                {
                    if (orp.qty > Convert.ToInt16(dt.Rows[0]["qty"])) // berarti penambahan stok
                    {
                        int qtt_update = orp.qty - qtt_product_master;

                        db.execUpdate("sp_ProductStockPlus", new object[] { orp.product_id, qtt_update });
                        db.execUpdate("Sp_OrderProductModify", new object[] { id, orp.product_id, orp.qty, orp.product_price });
                    }
                    else //berarti pengurangan stok
                    {
                        DataTable dt_prod = new DataTable();
                        dt_prod = db.execQuery("Sp_ProductSelById", new Object[] { orp.product_id });
                        if (Convert.ToInt16(dt.Rows[0]["qty_stock"].ToString()) >= orp.qty)
                        {
                            db.execUpdate("sp_ProductStockMinus", new object[] { orp.product_id, orp.qty });
                        }
                        else
                        {
                            // jika stok pada data produk tidak mencukupi maka tidak proses tidak dilakukan
                            throw (new MyException.OutOfStock(orp.product_id + ": Out Of Stock"));
                        }

                    }
                }
            }
            else
            {
                db.execUpdate("Sp_OrderProductAdd", new object[] { id, orp.product_id, orp.qty, orp.product_price });
                db.execUpdate("sp_ProductStockPlus", new object[] { orp.product_id, orp.qty });
            }
        }
Example #2
0
 public void OrderProductAdd(int id, OrderProduct orp)
 {
     db.execUpdate("Sp_OrderProductAdd", new object[] { id, orp.product_id, orp.qty, orp.product_price });
     db.execUpdate("sp_ProductStockPlus", new object[] { orp.product_id, orp.qty });
 }