<?php include_once 'init-lite.php';?>
<?php
echo '*';
if (!isset($_REQUEST['oid'])) die('xxx');
	$HaveOrderID=$_REQUEST['oid'];
 	$sql_Update="Update Orders set ShipCity='' where Orders.OrderID=".$HaveOrderID;
	$orders->query($sql_Update); 

	//********如果有菜单号，调入资料  Start
	//echo "<hr>".$_REQUEST['UserCode']."<hr>".$_REQUEST['ProductName']."<hr>";
	if (isset($_REQUEST['UserCode'])) {
		$SQL_OrderID=$HaveOrderID;
		$SQL_UserCode=$_REQUEST['UserCode'];
		$SQL_ProductName=$_REQUEST['ProductName'];
		$SQL_UnitPrice=$_REQUEST['UnitPrice'];
		$SQL_Discount='0';
		$SQL_Quantity=$_REQUEST['Quantity'];;
		
		
		$is_existProduct=0;
		$query_RecordsetProduct = "SELECT ID, Quantity FROM [Order Details] where OrderID=".$HaveOrderID." and  UserCode = '".$SQL_UserCode."' ";
		
		//echo $query_RecordsetProduct;
		$values = $orders->query($query_RecordsetProduct);
if (is_iterable($values)){
  foreach ($values as $row_RecordsetProduct)
		{ 
			$is_existProduct=1;

			$IDProduct= $row_RecordsetProduct['ID'];
			//$Quantity= $row_RecordsetProduct['Quantity'];
			//$Quantity= $Quantity+$SQL_Quantity;
			$updateSQL = sprintf("UPDATE [Order Details] SET Quantity=%s WHERE UserCode=%s",
						   GetSQLValueStringGBK($SQL_Quantity, "double"),
						  GetSQLValueStringGBK($SQL_UserCode, "text")
						   );
			$orders->query($updateSQL);
			echo "改菜 " ;//.$SQL_Quantity." x ".$SQL_ProductName;
		}
}
		 //echo "is_exist: ".$is_exist;
		if (!$is_existProduct) {
 			//$sn=md5(microtime());
			$insertSQL = sprintf("INSERT INTO [Order Details] ([OrderID],  [UserCode], [ProductName],[UnitPrice], [Discount],[Quantity]) VALUES  (%s, %s, %s, %s,%s, %s)",
				GetSQLValueStringGBK($SQL_OrderID,"long"),
				GetSQLValueStringGBK($SQL_UserCode,"text"),			
				GetSQLValueStringGBK($SQL_ProductName,"text"),			
				GetSQLValueStringGBK($SQL_UnitPrice,"double"),			
				GetSQLValueStringGBK($SQL_Discount,"int"),
				GetSQLValueStringGBK($SQL_Quantity, "double")
	);		
		$orders->query($insertSQL);
		//$insertok="[添加".$GUID."成功]  ";
		//echo "<hr>$insertSQL<hr>";
		echo "加菜 ";//.$SQL_Quantity." x ".$SQL_ProductName;
}
		
		
		
	}
	//********如果有菜单号，调入资料  END   

 
	
	?>