📄 manageorderdetail.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using OpenSmtp.Mail;
namespace BookStore.Admin
{
/// <summary>
/// ManageOrderDetail 的摘要说明。
/// </summary>
public class ManageOrderDetail : System.Web.UI.Page
{
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.HyperLink HyperLink4;
protected System.Web.UI.WebControls.HyperLink Hyperlink9;
protected System.Web.UI.WebControls.HyperLink HyperLink2;
protected System.Web.UI.WebControls.HyperLink HyperLink3;
protected System.Web.UI.WebControls.HyperLink Hyperlink10;
protected System.Web.UI.WebControls.HyperLink HyperLink5;
protected System.Web.UI.WebControls.HyperLink Hyperlink7;
protected System.Web.UI.WebControls.HyperLink Hyperlink8;
protected System.Web.UI.WebControls.HyperLink HyperLink6;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.Label Label13;
protected System.Web.UI.WebControls.Label Label14;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label lbInfo;
protected Lei.WebControls.PagerDataList pdlOrderDetail;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label lbRealName;
protected System.Web.UI.WebControls.Label lbEmail;
protected System.Web.UI.WebControls.Label lbCall;
protected System.Web.UI.WebControls.Label lbMobile;
protected System.Web.UI.WebControls.Label lbTotalPrice;
protected System.Web.UI.WebControls.Label lbPostcode;
protected System.Web.UI.WebControls.Label lbOrderDate;
protected System.Web.UI.WebControls.Label lbSending;
protected System.Web.UI.WebControls.Label lbPayment;
protected System.Web.UI.WebControls.Label lbIsNeedInvoice;
protected System.Web.UI.WebControls.Label lbAddress;
protected System.Web.UI.WebControls.Label lbUserMemo;
protected System.Web.UI.WebControls.Button btChangeOrderStatus;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.DropDownList ddOrderStatus;
static int nID;
static string strSummary, strEmail, strUserName;
protected System.Web.UI.WebControls.Label lbEmailInfo;
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
if(Object.Equals(Session["UserName"],null))
{
Response.Redirect("../Error.aspx");
}
else
{
if(!RobertSoft.BookStore.User.IsSupervisor(Session["UserName"].ToString()))
{
Response.Redirect("../Default.aspx");
}
else
{
nID = int.Parse(Request["ID"].ToString());
BindData(nID);
}
}
}
}
private void BindData(int nID)
{
string strSql;
strSql = "select * from BookOrderShortDetailView where OrderID=" + nID;
DataSet currentBookDS, UserInfoDS;
currentBookDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
this.pdlOrderDetail.DataSource = currentBookDS.Tables[0].DefaultView;
this.pdlOrderDetail.DataBind();
strSql = "select * from OrderUserDetail where ID=" + nID;
UserInfoDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
DataRow currentBookDR, currentDR;
currentDR = UserInfoDS.Tables[0].Rows[0];
this.lbAddress.Text = currentDR["Address"].ToString();
this.lbCall.Text = currentDR["PhoneNumber"].ToString();
this.lbEmail.Text = currentDR["Email"].ToString();
this.lbMobile.Text = currentDR["MobilePhone"].ToString();
this.lbOrderDate.Text = currentDR["OrderDate"].ToString();
this.lbPostcode.Text = currentDR["PostCode"].ToString();
this.lbRealName.Text = currentDR["ContactName"].ToString();
this.lbTotalPrice.Text = currentDR["TotalDiscountPrice"].ToString();
this.lbUserMemo.Text = currentDR["SendMemo"].ToString();
strEmail = currentDR["Email"].ToString();
strUserName = currentDR["ContactName"].ToString();
strSummary = "您好!" + currentDR["ContactName"].ToString() + " 。\r\n下面是您在BookStore的订购详情:\r\n";
strSummary += "您的订单号是:" + nID.ToString() + "\r\n";
strSummary += "您下订单的日期是:" + currentDR["OrderDate"].ToString() + "\r\n";
// 需要发票 1 需要 0 不需要
if(int.Parse(currentDR["NeedInvoice"].ToString()) == 1)
{
this.lbIsNeedInvoice.Text = "需要";
}
else
{
this.lbIsNeedInvoice.Text = "不需要";
}
// 付款方式 1 货到付款 2 邮局汇款 3 银行转账
if(int.Parse(currentDR["PayMethod"].ToString()) == 1)
{
this.lbPayment.Text = "货到付款";
strSummary += "您选择的支付方式是:货到付款\r\n" ;
}
else if(int.Parse(currentDR["PayMethod"].ToString()) == 2)
{
this.lbPayment.Text = "邮局汇款";
strSummary += "您选择的支付方式是:邮局汇款\r\n" ;
strSummary += "请您将汇款邮寄到以下地址:×××××\r\n";
}
else
{
this.lbPayment.Text = "银行转账";
strSummary += "您选择的支付方式是:银行转账\r\n" ;
strSummary += "请您汇款到以下账号:×××××\r\n";
}
// 送货方式 1 送货 2 上门自取
if(int.Parse(currentDR["SendMethod"].ToString()) == 1)
{
this.lbSending.Text = "送货上门";
strSummary += "您选择的送货方式是:送货上门\r\n" ;
}
else
{
this.lbSending.Text = "上门自取";
strSummary += "您选择的送货方式是:上门自取\r\n" ;
strSummary += "请等待我们的电话或者Email通知您取书的时间和地点。\r\n";
}
if(currentDR["SendMemo"].ToString() != "")
{
strSummary += "您的留言是:" + currentDR["SendMemo"].ToString() + "\r\n" ;
}
strSummary += "您的订单详情为:\r\n";
for(int i=0; i<currentBookDS.Tables[0].Rows.Count; i++)
{
currentBookDR = currentBookDS.Tables[0].Rows[i];
strSummary += "书名:" + currentBookDR["BookName"].ToString() + "; 共" + currentBookDR["Quantity"].ToString() + "本; 单价:" +
currentBookDR["DiscountPrice"].ToString() + "\r\n";
}
strSummary += "您的订单总价为:" + currentDR["TotalDiscountPrice"].ToString() + "\r\n";
strSummary += "感谢您的订购!这是一封确认信,不用回复。请等待我们进一步的服务。";
this.ddOrderStatus.SelectedValue = currentDR["OrderStatus"].ToString();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pdlOrderDetail.PageIndexChanged += new System.EventHandler(this.pdlOrderDetail_PageIndexChanged);
this.btChangeOrderStatus.Click += new System.EventHandler(this.btChangeOrderStatus_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btChangeOrderStatus_Click(object sender, System.EventArgs e)
{
string strSql;
int nStatus;
this.btChangeOrderStatus.Enabled = false;
nStatus = int.Parse(this.ddOrderStatus.SelectedValue.Trim().ToString());
strSql = "Update OrderUserDetail Set OrderStatus=" + nStatus + " where ID=" + nID;
try
{
RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);
this.lbInfo.Text = "状态更改成功";
}
catch
{
this.lbInfo.Text = "状态更改失败!";
return;
}
// 订单状态 1 用户发出订单 2 网站已经确认订单,处理中 3 图书已经送达,订单结束
// 如果订单结束,应该更新书的售出数目
if(nStatus == 2)
{
SendConfirmEmail();
}
if(nStatus == 3)
{
strSql = "select UserID, BookID from OrderBookDetail where OrderID=" + nID;
DataSet currentDS;
DataRow currentDR;
int nBookID;
currentDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
for(int i=0; i < currentDS.Tables[0].Rows.Count; i++)
{
currentDR = currentDS.Tables[0].Rows[i];
nBookID = int.Parse(currentDR["BookID"].ToString());
strSql = "select SoldNumber from BookInfo where ID=" + nBookID;
int nSoldNumber;
nSoldNumber = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForValue(strSql);
nSoldNumber += 1;
strSql = "Update BookInfo Set SoldNumber=" + nSoldNumber + " where ID=" + nBookID;
try
{
RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);
this.lbInfo.Text = "状态更改成功";
}
catch
{
this.lbInfo.Text = "状态更改失败!";
return;
}
}
// Get user's consumption information, then update it.
int nUserID;
double dTotalPrice, dOrignialPrice;
strSql = "select UserID, TotalDiscountPrice from OrderUserDetail where ID=" + nID;
DataSet UserDS;
DataRow UserDR;
UserDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
UserDR = UserDS.Tables[0].Rows[0];
nUserID = int.Parse(UserDR["UserID"].ToString());
dTotalPrice = double.Parse(UserDR["TotalDiscountPrice"].ToString());
strSql = "select TotalConsumption, UserLevel from [User] where ID=" + nUserID;
UserDS = RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLForDS(strSql);
UserDR = UserDS.Tables[0].Rows[0];
dOrignialPrice = double.Parse(UserDR["TotalConsumption"].ToString());
dTotalPrice += dOrignialPrice;
int nLevel = int.Parse(UserDR["UserLevel"].ToString());
// 凡购书满100元的用户,自动成为二星级用户,享受购书88折优惠;
// 300元的用户,自动成为三星级用户,享受购书85折优惠;
// 1000元的用户,自动成为四星级用户,享受购书8折优惠;
// 1800元用户,自动成为5星级用户,享受购书78折优惠;
// 3000元用户,享受钻石级最高级别:享受购书75折优惠。
if( (dTotalPrice>=100) && (dTotalPrice < 300))
{
nLevel = 2;
}
else if((dTotalPrice>=300) && (dTotalPrice < 1000))
{
nLevel = 3;
}
else if((dTotalPrice>=1000) && (dTotalPrice < 1800))
{
nLevel = 4;
}
else if((dTotalPrice>=1800) && (dTotalPrice < 3000))
{
nLevel = 5;
}
else if(dTotalPrice >= 3000)
{
nLevel = 6;
}
strSql = "Update [User] Set UserLevel=" + nLevel + ", TotalConsumption=" + dTotalPrice.ToString() + " where ID=" + nUserID;
try
{
RobertSoft.BookStore.DBClass.DBBaseClass.ExecuteSQLCmd(strSql);
this.lbInfo.Text = "状态更改成功";
}
catch
{
this.lbInfo.Text = "状态更改失败!";
return;
}
}
this.btChangeOrderStatus.Enabled = true;
}
private void SendConfirmEmail()
{
Smtp MySmtp;
MySmtp = new Smtp();
MySmtp.Username = "BookStore163";
MySmtp.Password = "123456";
MySmtp.Port = 25;
MySmtp.Host = "202.108.44.206";
MailMessage msg;
EmailAddress senderAddress;
EmailAddress replyToAddress;
EmailAddress recipientAddress;
senderAddress = new EmailAddress("BookStore163@163.com", "BookStore");
recipientAddress = new EmailAddress(strEmail, strUserName);
replyToAddress = new EmailAddress("BookStore163@163.com", "BookStore");
msg = new MailMessage();
msg.Subject = "您的订单详情--BookStore";
msg.Body = strSummary;
msg.From = senderAddress;
msg.AddRecipient(recipientAddress, AddressType.To);
msg.ReplyTo = replyToAddress;
// msg.AddCustomHeader("X-FakeTestHeader", "Fake Value");
// msg.AddCustomHeader("X-AnotherFakeTestHeader", "Fake Value");
msg.Notification = false;
msg.Charset = "gb2312";
msg.Priority = MailPriority.Normal;
try
{
MySmtp.SendMail(msg);
this.lbEmailInfo.Text = "用户确认信已经正确发出!";
}
catch
{
this.lbEmailInfo.Text = "发送给用户确认信件失败!请再次尝试!";
this.lbEmailInfo.ForeColor = Color.Red;
}
}
private void pdlOrderDetail_PageIndexChanged(object sender, System.EventArgs e)
{
int pageindex = ((DataGridPageChangedEventArgs)e).NewPageIndex;
this.pdlOrderDetail.CurrentPageIndex = pageindex;
BindData(nID);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -