?? pie_orders.aspx.cs
字號:
/*
C#發(fā)現(xiàn)之旅系列教程配套演示代碼
本代碼僅供學習和參考使用
編制 袁永福 2008-5-15
MSN yyf9989@hotmail.com
QQ 28348092
作者博客 http://xdesigner.cnblogs.com/
使用者請作者的尊重知識產權。
*/
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 System.Data.OleDb ;
namespace cs_discovery
{
/// <summary>
/// pie_orders 的摘要說明。
/// </summary>
public class pie_orders : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Label lblResult;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
private void Page_Load(object sender, System.EventArgs e)
{
string customerid = this.Request.QueryString["customerid"] ;
if( customerid == null || customerid.Length == 0 )
return ;
// 連接數(shù)據(jù)庫
using( OleDbConnection conn = new OleDbConnection())
{
conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ this.Server.MapPath("demomdb.mdb");
conn.Open();
// 查詢數(shù)據(jù)庫
using( OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = @"
SELECT OrderDate AS 訂購時間,
shipname AS 運輸人,
shipaddress AS 地點,
( select
sum( round( unitprice * quantity * ( 1 - discount) , 3 ) )
from orderdetails
where orderdetails.orderid = orders.orderid
) AS 總金額
FROM orders
WHERE customerid ='" + customerid + "'" ;
OleDbDataReader reader = cmd.ExecuteReader();
// 創(chuàng)建餅圖對象
PieShape pie = new PieShape();
pie.Width = 400 ;
pie.Height = 300 ;
System.IO.StringWriter writer = new System.IO.StringWriter();
while( reader.Read())
{
double Value = Convert.ToDouble( reader.GetValue( 3 ));
string Text = "時間:" + reader.GetValue( 0 )
+ "\r\n人員:" + reader.GetValue( 1 )
+ "\r\n地點:" + reader.GetValue( 2 )
+ "\r\n金額:" + reader.GetValue( 3 );
string Link = "#" ;
pie.Add( Value , Text , Link );
}//while
reader.Close();
pie.RefreshState();
this.Session["customerid"] = pie ;
this.lblResult.Text = pie.GetHtmlString("pieimage.aspx?name=customerid");
this.DataGrid1.DataSource = pie ;
this.DataGrid1.DataBind();
}
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -