orderbook.cs
来自「这是一个编好的网上书店系统」· CS 代码 · 共 158 行
CS
158 行
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using RobertSoft.BookStore.DBClass;
namespace RobertSoft.BookStore
{
/// <summary>
/// OrderBook 的摘要说明。
/// </summary>
public class OrderBook : DBBaseClass,IEnumerator
{
public OrderBook()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region IEnumerator 成员
public void Reset()
{
// TODO: 添加 OrderBook.Reset 实现
}
public object Current
{
get
{
// TODO: 添加 OrderBook.Current getter 实现
return null;
}
}
public bool MoveNext()
{
// TODO: 添加 OrderBook.MoveNext 实现
return false;
}
#endregion
public DataTable OrderDetail(int nUserID)
{
string strSql = "select * from ShoppingCartDetail where UserID=" + nUserID;
DataSet currentDV;
currentDV = ExecuteSQLForDS(strSql);
DataRow currentDR, tempDR;
DataTable currentDT;
string str="";
int nInt=1;
// Add a new table which contains all the shopping cart table will list.
currentDT = new DataTable();
currentDT.Columns.Add(new DataColumn("BookName", str.GetType()));
currentDT.Columns.Add(new DataColumn("Price", str.GetType()));
currentDT.Columns.Add(new DataColumn("DiscountPrice", str.GetType()));
currentDT.Columns.Add(new DataColumn("Quantity", str.GetType()));
currentDT.Columns.Add(new DataColumn("TotalPrice", str.GetType()));
currentDT.Columns.Add(new DataColumn("TotalDiscountPrice", str.GetType()));
currentDT.Columns.Add(new DataColumn("BookID", nInt.GetType()));
for(int i=0; i< currentDV.Tables[0].Rows.Count; i++)
{
tempDR = currentDV.Tables[0].Rows[i];
currentDR = currentDT.NewRow();
currentDR[0] = tempDR["BookName"].ToString();
currentDR[1] = tempDR["Price"].ToString();
// if it is a special price book, all has the same price
int nSpecial = int.Parse(tempDR["SpecialPrice"].ToString());
if( nSpecial == 1)
{
int nDiscount;
float fPrice;
nDiscount = int.Parse(tempDR["Discount"].ToString());
fPrice = float.Parse(tempDR["Price"].ToString());
fPrice = (float)nDiscount*fPrice/100;
int n = (int) (fPrice * 10);
fPrice = (float)n / 10;
currentDR[2] = fPrice.ToString();
}
// otherwise, the book sale price will consider user's level
// 1 star * 0.9
// 2 star * 0.88
// 3 star * 0.85
// 4 star * 0.80
// 5 star * 0.78
else
{
int n = int.Parse(tempDR["UserLevel"].ToString());
if( n == 1)
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.9;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
else if( n == 2)
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.88;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
else if(n == 3)
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.85;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
else if(n == 4)
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.80;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
else if(n == 5)
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.78;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
else
{
float fPrice = float.Parse(tempDR["Price"].ToString()) * (float)0.75;
int nCount = (int) (fPrice * 10);
fPrice = (float)nCount / 10;
currentDR[2] = fPrice.ToString();
}
}
currentDR[3] = tempDR["Quantity"].ToString();
float totalPrice, totalDiscountPrice;
totalPrice = float.Parse(currentDR[1].ToString());
totalPrice *= float.Parse(currentDR[3].ToString());
currentDR[4] = totalPrice.ToString();
totalDiscountPrice = float.Parse(currentDR[2].ToString());
totalDiscountPrice *= float.Parse(currentDR[3].ToString());
currentDR[5] = totalDiscountPrice.ToString();
currentDR[6] = int.Parse(tempDR["BookID"].ToString());
currentDT.Rows.Add(currentDR);
}
return currentDT;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?