/// <summary> /// 根据桌号查询出订单号 /// </summary> /// <param name="tableId"></param> /// <returns></returns> public int GetOrderIdByTableId(int tableId) { string sql = "SELECT OId FROM OrderInfo " + " WHERE TableId=@TableId AND IsPay=0 ORDER BY OId DESC LIMIT 1"; MySqlParameter p = new MySqlParameter("@TableId", tableId); return(Convert.ToInt32(MysqlHelper.ExecuteScalar(sql, p))); }
/// <summary> /// 判断订单中这个菜是否已经存在 /// </summary> /// <param name="orderId"></param> /// <param name="dishId"></param> /// <returns></returns> public bool HasCai(int orderId, int dishId) { string sql = "SELECT COUNT(*) FROM OrderDetailInfo WHERE OrderId=@OrderId AND DishId=@DishId"; MySqlParameter[] ps = { new MySqlParameter("@OrderId", orderId), new MySqlParameter("@DishId", dishId), }; return(Convert.ToInt32(MysqlHelper.ExecuteScalar(sql, ps)) > 0); }
/// <summary> /// 根据订单,计算订单总金额 /// </summary> /// <param name="orderId"></param> /// <returns></returns> public decimal GetTotalMoneyByOrderId(int orderId) { string sql = "SELECT SUM(di.DPrice*odi.Count) FROM OrderDetailInfo AS odi " + " INNER JOIN DishInfo AS di " + " ON odi.DishId=di.DId " + " WHERE odi.OrderId=@OrderId"; MySqlParameter p = new MySqlParameter("@OrderId", orderId); var result = MysqlHelper.ExecuteScalar(sql, p); if (result != DBNull.Value) { return(Convert.ToDecimal(result)); } return(0); }