📄 order.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
namespace PetShop.Components {
/// <summary>
/// Online orders transactions.
/// </summary>
public class Order {
/// <summary>
/// Adds a new order to the database.
/// </summary>
/// <param name="xml">The order xml doc.</param>
/// <returns>The new order id.</returns>
public int Add(string xml) {
try {
// create data object and params
Database data = new Database();
SqlParameter[] prams = { data.MakeInParam("@xml", SqlDbType.VarChar, 8000, xml) };
// run the stored procedure
return data.RunProc("upOrdersAdd", prams);
}
catch (Exception ex) {
Error.Log(ex.ToString());
return 0;
}
}
/// <summary>
/// Gets the list of orders for a specified user.
/// </summary>
/// <param name="userid">The customer's user id.</param>
/// <returns>A SQL Data Reader containing the list of orders.</returns>
public SqlDataReader GetOrder(string userid) {
// create data object and params
SqlDataReader dataReader = null;
Database data = new Database();
SqlParameter[] prams = { data.MakeInParam("@userid", SqlDbType.VarChar, 80, userid) };
try {
// run the stored procedure
data.RunProc("upOrdersGet", prams, out dataReader);
return dataReader;
}
catch (Exception ex) {
Error.Log(ex.ToString());
return null;
}
}
public SqlDataReader GetOrderList(DateTime orderdate,int ordernumber,string orderstatus)
{
SqlDataReader datareader=null;
Database data=new Database();
SqlParameter[] prams={
data.MakeInParam("@orderdate",SqlDbType.DateTime,8,orderdate),
data.MakeInParam("@ordernumber",SqlDbType.Int,4,ordernumber),
data.MakeInParam("@orderstatus",SqlDbType.Char,2,orderstatus)
};
try
{
data.RunProc("upGetOrderList",prams,out datareader);
return datareader;
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return null;
}
}
public string GetDeliveryMethodName(int OrderID)
{
Database data=new Database();
try
{
SqlParameter[] prams={
data.MakeInParam("@orderid",SqlDbType.Int,4,OrderID),
data.MakeOutParam("@DeliveryMethodName",SqlDbType.VarChar,50)
};
data.RunProc("upGetDeliveryNameAll",prams);
return Convert.ToString(prams[1].Value);
}
catch(Exception ex)
{
PetShop.Components.Error.Log(ex.ToString());
return null;
}
}
public int GetPaymentType(int OrderID)
{
Database data=new Database();
try
{
SqlParameter[] prams={
data.MakeInParam("@orderid",SqlDbType.Int,4,OrderID),
data.MakeOutParam("@PaymentType",SqlDbType.Int,4)
};
data.RunProc("upGetPayment",prams);
return Convert.ToInt32(prams[1].Value);
}
catch(Exception ex)
{
PetShop.Components.Error.Log(ex.ToString());
return 0;
}
}
/// <summary>
/// Returns the order status for the given order number.
/// </summary>
/// <param name="orderid">The customer's order number.</param>
/// <returns>If the order status is valid a string with the order
/// status is returned, otherwise null is returned.</returns>
public string GetOrderStatus(string orderid) {
string orderStatus;
// create data object and params
Database data = new Database();
SqlParameter[] prams = {
data.MakeInParam("@orderid", SqlDbType.VarChar, 80, orderid),
data.MakeOutParam("@OrderStatus", SqlDbType.Char, 2)
};
try {
data.RunProc("upOrderStatusGet", prams); // run the stored procedure
orderStatus = (string) prams[1].Value; // get the output param value
// if the order status is an empty string, then the lookup failed
if (orderStatus == string.Empty)
return null;
else
return orderStatus;
}
catch (Exception ex) {
Error.Log(ex.ToString());
return null;
}
}
public string GetPetStore(int orderID)
{
string strPetStore;
Database db=new Database();
try
{
SqlParameter[] prams=new SqlParameter[]{db.MakeInParam("@orderid",SqlDbType.Int,4,orderID),
db.MakeOutParam("@StoreName",SqlDbType.VarChar,20)};
db.RunProc("GetPetStoreByOrderID",prams);
strPetStore=prams[1].Value.ToString();
return strPetStore;
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return null;
}
}
public bool UpdateOrder(int orderid,string shipaddr1,string shipaddr2,string shipcity,string shipstate,
string shipzip,string shipcountry,string billaddr1,string billaddr2,string billcity,string billstate,
string billzip,string billcountry,string courier,decimal totalprice,string billtofirstname,
string billtolastname,string shiptofirstname,string shiptolastname,string creditcard,
string exprdate,string cardtype,string locale,int PaymentType,int DeliveryMethodID,
decimal AdditionalCharge,string CheckNumber,string StoreName)
{
Database data=new Database();
try
{
SqlParameter[] prams={
data.MakeInParam("@orderid",SqlDbType.Int,10,orderid),
data.MakeInParam("@shipaddr1",SqlDbType.VarChar,80,shipaddr1),
data.MakeInParam("@shipaddr2",SqlDbType.VarChar,80,shipaddr2),
data.MakeInParam("@shipcity",SqlDbType.VarChar,80,shipcity),
data.MakeInParam("@shipstate",SqlDbType.VarChar,80,shipstate),
data.MakeInParam("@shipzip",SqlDbType.VarChar,80,shipzip),
data.MakeInParam("@shipcountry",SqlDbType.VarChar,80,shipcountry),
data.MakeInParam("@billaddr1",SqlDbType.VarChar,80,billaddr1),
data.MakeInParam("@billaddr2",SqlDbType.VarChar,80,billaddr2),
data.MakeInParam("@billcity",SqlDbType.VarChar,80,billcity),
data.MakeInParam("@billstate",SqlDbType.VarChar,80,billstate),
data.MakeInParam("@billzip",SqlDbType.VarChar,80,billzip),
data.MakeInParam("@billcountry",SqlDbType.VarChar,80,billcountry),
data.MakeInParam("@courier",SqlDbType.VarChar,80,courier),
data.MakeInParam("@totalprice",SqlDbType.Decimal,10,totalprice),
data.MakeInParam("@billtofirstname",SqlDbType.VarChar,80,billtofirstname),
data.MakeInParam("@billtolastname",SqlDbType.VarChar,80,billtolastname),
data.MakeInParam("@shiptofirstname",SqlDbType.VarChar,80,shiptofirstname),
data.MakeInParam("@shiptolastname",SqlDbType.VarChar,80,shiptolastname),
data.MakeInParam("@creditcard",SqlDbType.VarChar,80,creditcard),
data.MakeInParam("@exprdate",SqlDbType.VarChar,80,exprdate),
data.MakeInParam("@cardtype",SqlDbType.VarChar,80,cardtype),
data.MakeInParam("@locale",SqlDbType.VarChar,80,locale),
data.MakeInParam("@PaymentType",SqlDbType.Int,4,PaymentType),
data.MakeInParam("@DeliveryMethodID",SqlDbType.Int,10,DeliveryMethodID),
data.MakeInParam("@AdditionalCharge",SqlDbType.Decimal,9,AdditionalCharge),
data.MakeInParam("@CheckNumber",SqlDbType.Int,4,CheckNumber),
data.MakeInParam("@StoreName",SqlDbType.VarChar,20,StoreName)
};
data.RunProc("upOrderUpdate",prams);
return true;
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return false;
}
}
public void UpdateQtyInLineItem(int qty,int iOrderID,string itemID)
{
try
{
Database db=new Database();
SqlParameter[] prams=new SqlParameter[]{ db.MakeInParam("@qty",SqlDbType.Int,4,qty),
db.MakeInParam("@orderID",SqlDbType.Int,4,iOrderID),
db.MakeInParam("@itemID",SqlDbType.Char,10,itemID)};
db.RunProc("upQuantityInLineItemUpdate",prams);
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return ;
}
}
public SqlDataReader GetLineItem(int iOrderID)
{
SqlDataReader dr;
try
{
Database db=new Database();
SqlParameter[] prams=new SqlParameter[]{db.MakeInParam("@orderID",SqlDbType.Int,4,iOrderID)};
db.RunProc("upGetLineItemByOrderID",prams,out dr);
return dr;
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return null;
}
}
public void DelALineItem(int iOrderID,string itemID)
{
Database db=new Database();
try
{
SqlParameter[] prams=new SqlParameter[]{db.MakeInParam("@orderID",SqlDbType.Int,4,iOrderID),
db.MakeInParam("@itemID",SqlDbType.Char,10,itemID)};
db.RunProc("upDelALineItem",prams);
}
catch(Exception ex)
{
Error.Log(ex.ToString());
return ;
}
}
public void GetOrderDetils(int orderid,out string userid,out string StoreName,out string shiptofirstname,out string shiptolastname,out string shipaddr1,out string shipaddr2,out string shipcity,out string shipstate,out string shippostalcode,out string billtofirstname,
out string billtolastname,out string billaddr1,out string billaddr2,out string billcity,out string billstate,out string billpstalcode,out string cardType,
out string cardnumber,out string carddate,out string CheckNumber,out decimal totalPrice)
{
Database db=new Database();
SqlParameter[] prams=new SqlParameter[]
{
db.MakeInParam ("@Orderid",SqlDbType.VarChar ,80,orderid),
db.MakeOutParam ("@Userid",SqlDbType.VarChar ,80),
db.MakeOutParam ("@StoreName",SqlDbType.VarChar ,20),
db.MakeOutParam ("@Shiptofirstname",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shiptolastname",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shipaddr1",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shipaddr2",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shipcity",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shipstate",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Shippostalcode",SqlDbType.VarChar ,20),
db.MakeOutParam ("@Billtofirstname",SqlDbType.VarChar,80),
db.MakeOutParam ("@Billtolastname",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Billaddr1",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Billaddr2",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Billcity",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Billstate",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Billpstalcode",SqlDbType.VarChar ,20),
db.MakeOutParam ("@CardType",SqlDbType.VarChar ,80),
db.MakeOutParam ("@Cardnumber",SqlDbType.VarChar ,80),
db.MakeOutParam ("@CardDate",SqlDbType.VarChar ,7),
db.MakeOutParam("@CheckNumber",SqlDbType.VarChar,50),
db.MakeOutParam("@totalPrice",SqlDbType.Decimal,9)
};
db.RunProc ("upGetOrderDetials", prams);
userid=prams[1].Value .ToString ();
StoreName=prams[2].Value .ToString ();
shiptofirstname=prams[3].Value .ToString ();
shiptolastname=prams[4].Value .ToString ();
shipaddr1=prams[5].Value .ToString ();
shipaddr2=prams[6].Value .ToString ();
shipcity=prams[7].Value .ToString ();
shipstate=prams[8].Value .ToString ();
shippostalcode=prams[9].Value .ToString ();
billtofirstname=prams[10].Value .ToString ();
billtolastname=prams[11].Value .ToString ();
billaddr1=prams[12].Value .ToString ();
billaddr2=prams[13].Value .ToString ();
billcity=prams[14].Value .ToString ();
billstate=prams[15].Value .ToString ();
billpstalcode=prams[16].Value .ToString ();
cardType=prams[17].Value .ToString ();
cardnumber=prams[18].Value .ToString ();
carddate=prams[19].Value .ToString ();
CheckNumber=prams[20].Value.ToString();
totalPrice=Convert.ToDecimal(prams[21].Value);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -