?? orders.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 + -