⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orders.cs

📁 网上购物系统源代码加毕业设计论文
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;

namespace eshop.BLL
{
	public class OrderDetails 
	{

		public DateTime  OrderDate;
		public decimal   OrderTotal;
		public DataSet   OrderItems;

	}
	/// <summary>
	/// Orders 的摘要说明。
	/// </summary>
	public class Orders
	{
		public Orders()
		{
		
		}

		public SqlDataReader GetOrderList(string userId)
		{
			SqlParameter[] para = {
									  new SqlParameter("@userId", userId)
								  };

			return DAL.SQLHelper.ExecuteReader(DAL.SQLHelper.CONN_STRING, CommandType.StoredProcedure,
				"GetOrdersList", para);
		}

		public OrderDetails GetOrderDetails(int orderId, string userId)
		{
			// Create Instance of Connection and Command Object
			SqlConnection myConnection = new SqlConnection(DAL.SQLHelper.CONN_STRING);
			SqlDataAdapter myCommand = new SqlDataAdapter("GetOrdersDetail", myConnection);

			// Mark the Command as a SPROC
			myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;

			// Add Parameters to SPROC
			SqlParameter parameterOrderID = new SqlParameter("@OrderID", SqlDbType.Int, 4);
			parameterOrderID.Value = orderId;
			myCommand.SelectCommand.Parameters.Add(parameterOrderID);

			SqlParameter parameterCustomerID = new SqlParameter("@userID", SqlDbType.Int, 4);
			parameterCustomerID.Value = Int32.Parse(userId);
			myCommand.SelectCommand.Parameters.Add(parameterCustomerID);

			SqlParameter parameterOrderDate = new SqlParameter("@OrderDate", SqlDbType.DateTime, 8);
			parameterOrderDate.Direction = ParameterDirection.Output;
			myCommand.SelectCommand.Parameters.Add(parameterOrderDate);

			

			SqlParameter parameterOrderTotal = new SqlParameter("@OrderTotal", SqlDbType.Money, 8);
			parameterOrderTotal.Direction = ParameterDirection.Output;
			myCommand.SelectCommand.Parameters.Add(parameterOrderTotal);

			// Create and Fill the DataSet
			DataSet myDataSet = new DataSet();
			myCommand.Fill(myDataSet, "OrderItems");
            

			// Create and Populate OrderDetails Struct using
			// Output Params from the SPROC, as well as the
			// populated dataset from the SqlDataAdapter

			OrderDetails myOrderDetails = new OrderDetails();

			myOrderDetails.OrderDate= (DateTime)parameterOrderDate.Value;
				
			myOrderDetails.OrderTotal = (decimal)parameterOrderTotal.Value;
			myOrderDetails.OrderItems = myDataSet;

			// Return the DataSet
			return myOrderDetails;
		}

		public int PlaceOrder(string userId, string cartId)
		{
			object m_DBNull = Convert.DBNull;

			SqlParameter[] para = {
									  new SqlParameter("@userId", userId),
									  new SqlParameter("@cartId", cartId),
									  new SqlParameter("@orderDate", System.DateTime.Now),
									  new SqlParameter("@orderId", SqlDbType.Int, 4, ParameterDirection.Output,
									  true, 0, 0, "", DataRowVersion.Default, m_DBNull)
								  };
			try
			{
				DAL.SQLHelper.ExecuteNonQuery(DAL.SQLHelper.CONN_STRING, CommandType.StoredProcedure, "OrdersAdd",
					para);
			}
			catch
			{
				throw;
			}

			return Convert.ToInt32(para[3].Value);
		}


		public int PayOrder(string userId, decimal totalcost)
		{
			object m_DBNull = Convert.DBNull;

			SqlParameter[] para = {
									  new SqlParameter("@userId", userId),
									  new SqlParameter("@totalcost", totalcost),
									  new SqlParameter("@result", SqlDbType.Int, 4, ParameterDirection.Output,
									  true, 0, 0, "", DataRowVersion.Default, m_DBNull)
								  };
			try
			{
				DAL.SQLHelper.ExecuteNonQuery(DAL.SQLHelper.CONN_STRING, CommandType.StoredProcedure, "PayOrder",
					para);
			}
			catch
			{
				throw;
			}

			return Convert.ToInt32(para[2].Value);
		}


	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -