<%@ 페이지 언어="c#" Codebehind="shoppingcart.aspx.cs" AutoEventWireup="false" Inherits="myshop.shoppingcart" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional// EN" ><HTML> <HEAD>
<제목>장바구니
</제목>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312"> <LINK href="mycss.css" type="text/css" rel="stylesheet">
<메타 이름="vs_defaultClientScript" 콘텐츠="JavaScript">
<meta name="vs_targetSchema" content=" http://schemas.microsoft.com/intellisense/ie5 "> </HEAD>
<바디> <중앙>
<form id="Form1" runat="server"> <table width="500" border="0"cellspacing="0" cellpadding="0"> <tr> <td>
<asp:DataGrid id="ShoppingCartDlt" runat="server" Width="500" BackColor="white" BorderColor="black" ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana " Font-Size="8pt" HeaderStyle-BackColor="#cecfd6" AutoGenerateColumns="false" MaintenanceState="true"> <열>
<asp:TemplateColumn HeaderText="删除">
<아이템템플릿> <가운데>
<asp:CheckBox id="chkProductID" runat="server" /> </center>
</ItemTemplate> </asp:TemplateColumn>
<asp:BoundColumn DataField="ProdID" HeaderText="ID" />
<asp:BoundColumn DataField="ProName" HeaderText="商productname称" />
<asp:BoundColumn DataField="UnitPrice" HeaderText="单价" />
<asp:TemplateColumn HeaderText="数용량">
<아이템템플릿>
<asp:TextBox id="CountTb" runat="server" Text='<%#DataBinder.Eval( Container.DataItem,"ProdCount" )%>'> </asp:TextBox>
</ItemTemplate> </asp:TemplateColumn>
<asp:BoundColumn DataField="TotalPrice" HeaderText="小计( 元 )" /> </Columns> </asp:DataGrid></td> </tr> <//table> <br> <table width=" 500" border="0" cellpacing="0" cellpadding="0"> <tr> <td>
<asp:Button id="update" runat="server" Text="更新我的购물车" CssClass="button2" /></td> <td>
<asp:Button id="CheckOut" runat="server" Text="结算" CssClass="button5" />
<input type="button" name="close2" value="继续购물" onClick="window.close ( );
거짓을 반환;
" class="button2"></td> <td align="right"><br>
<asp:Label id="label" runat="server" Width="100px" Visible="True" ForeColor="#FF8080" Height="18px"></asp:Label></td> </tr> </테이블>
</form> </center>
</body></HTML>========================================= ===================================================================================================================================
================================================= ========================================
시스템 사용;
System.Collections 사용;
System.ComponentModel 사용;
System.Web.SessionState 사용;
System.Web 사용;
System.Web.UI 사용;
System.Web.UI.HtmlControls 사용;
System.Web.UI.WebControls 사용;
System.Data 사용;
System.Data.OleDb 사용;
System.Configuration 사용;
네임스페이스 myshop
{
/// <요약> /// shoppingcart 的摘要说明. /// </summary> 공개 클래스 shoppingcart : System.Web.UI.Page
{
보호된 System.Web.UI.WebControls.DataGrid ShoppingCartDlt;
보호된 System.Web.UI.WebControls.Button 업데이트;
보호된 System.Web.UI.WebControls.Button CheckOut;
보호된 System.Web.UI.HtmlControls.HtmlForm Form1;
보호된 System.Web.UI.WebControls.Label 레이블;
보호된 System.Web.UI.WebControls.CheckBox chkProductID;
보호된 System.Web.UI.WebControls.TextBox txtCount;
보호된 System.Web.UI.WebControls.TextBox CountTb;
문자열 AddProID;
개인 무효 Page_Load(개체 전송자, System.EventArgs e)
{
노력하다
{
if ( 세션["logon"]!="yes" 세션["username"]==null )
{
Response.Redirect( "error.htm" ) ;
}
}
잡다
{
Response.Redirect( "error.htm" ) ;
}
/////////////查看用户是否已经登陆.
if( !IsPostBack )
{
if( Request.Params["mode"]=="view" ) //检测是否为直接查看购物车.
{
ViewShoppingCart( );
계산기( );
}
if( Request.Params["productID"]!=null Request.Params["productID"]!="" )
{
AddProID=요청["제품ID"];
UpdateShoppingCart( );
계산기( );
}
}
// 此处放置用户代码以初始化页면
}
공공 무효 CreateCartTable() //创建购물车
{
DataSet ds = new DataSet( );
DataTable newDT=새 DataTable( "CartTable" );
ds.Tables.Add( newDT );
DataColumn newDC;
newDC=new DataColumn( "ProdID",System.Type.GetType( "System.Int32" ) );
ds.Tables["CartTable"].Columns.Add( newDC );
newDC=new DataColumn( "ProdCount",System.Type.GetType( "System.Int32" ) );
newDC.DefaultValue=1;
ds.Tables["CartTable"].Columns.Add( newDC );
newDC=new DataColumn( "ProName",System.Type.GetType( "System.String" ) );
ds.Tables["CartTable"].Columns.Add( newDC );
newDC=new DataColumn( "UnitPrice",System.Type.GetType( "System.Double" ) );
ds.Tables["CartTable"].Columns.Add( newDC );
newDC=new DataColumn( "TotalPrice",System.Type.GetType( "System.Double" ) );
ds.Tables["CartTable"].Columns.Add( newDC );
newDC=new DataColumn( "IsDeleted",System.Type.GetType( "System.Int32" ) );
newDC.DefaultValue=0;
// 공개 무효 WriteShoppingCart( ) 中 newDR[5]="0";
行,已被注销, ds.Tables["CartTable"].Columns.Add( newDC );
세션["myCartTable"]=newDT;
ShoppingCartDlt.DataSource=ds.Tables["CartTable"].DefaultView;
ShoppingCartDlt.DataBind( );
}
공개 무효 UpdateShoppingCart( )
{
if( 세션["myCartTable"]==null )//세션["myCartTable"]==null
{
CreateCartTable( );
//사용용函数CreateCartTable( ) 새로운建一个DataTable WriteShoppingCart( );
}
또 다른
{
//如果购物蓝中已有商product,则需要对购物信息表DataTable进行更新,并将其棒定到ShoppingCartDlt WriteShoppingCart( );
}
}
public void ViewShoppingCart( ) //查看购물车
{
if( 세션["myCartTable"]!=null )
{
DataTable viewTable=new DataTable( "nowCartTable" );
viewTable=( DataTable ) 세션["myCartTable"];
ShoppingCartDlt.DataSource = viewTable.DefaultView;
//쇼핑카트Dlt ShoppingCartDlt.DataBind( );
}
}
공공 무효 WriteShoppingCart()
{
if( Request.Params["mode"]!="view" ) //检查是否是直接查看购물车,如果直接查看,就不再写MYCARTTABLE
{
DataTable nowTable=new DataTable( "nowCartTable" );
nowTable=( DataTable ) 세션["myCartTable"];
int pn=nowTable.Rows.Count;
int i=0;
bool hasone=false;
int nowProdID;
while( i<pn && !hasone )
{
nowProdID=Int32.Parse( nowTable.Rows[i][0].ToString( ) );
if( nowProdID==Int32.Parse( AddProID ) ) //判断购物信息表中,是否存有当前放入商product. if( nowProdID==Int32.Parse( AddProID ) )
{
해손=true;
}
또 다른
{
나++;
}
}
if( hasone )
{
//如果已有该商품,则 hasone=true,更改该数据行 DataRow oldDR;
oldDR=nowTable.Rows[i];
oldDR["ProdCount"]=Int32.Parse( oldDR["ProdCount"].ToString( ) )+1;
oldDR["TotalPrice"]=Int32.Parse( oldDR["ProdCount"].ToString( ) )*Double.Parse( oldDR["UnitPrice"].ToString( ) );
}
또 다른
{
//如果没有该商제품, 表中新加如一行. DataRow newDR;
이중 단위p;
문자열 strcon="provider=Microsoft.jet.OLEDB.4.0;
data Source="+Server.MapPath( ConfigurationSettings.AppSettings["MDBpath2"] )+";
";
OleDbConnection myConnection = new OleDbConnection( strcon );
string strSQL= "pro에서 * 선택 product_id="+AddProID+"";
OleDbDataAdapter myCommand = new OleDbDataAdapter( strSQL, myConnection );
DataSet ds = new DataSet( );
myCommand.Fill( ds, "AddP" );
newDR=nowTable.NewRow( );
newDR[0]=ProID 추가;
newDR[2]=ds.Tables["Addp"].Rows[0]["product_name"].ToString( );
unitp=Double.Parse( ds.Tables["AddP"].Rows[0]["product_memprice"].ToString( ) );
//会员价 newDR[3]=unitp;
newDR[4]=유닛p;
//모든 것이 중요합니다. //newDR[5]="0";
nowTable.Rows.Add( newDR );
myConnection.Close( );
}
ShoppingCartDlt.DataSource = nowTable.DefaultView;
//새로운 DataTable은 ShoppingCartDlt ShoppingCartDlt.DataBind( );
세션["myCartTable"] = nowTable;
// 새로운 DataTable을 새로 추가했습니다.
}
}
공공 무효 Caculator( )
{
if( Session["myCartTable"]!=null ) //쇼핑몰
{
int h;
이중 TotalPri;
총합=0;
DataTable nowTable3=새 DataTable( "nowCartTable3" );
nowTable3=( DataTable ) 세션["myCartTable"];
if( nowTable3.Rows.Count>0 ) //返回购식물车中是否유유식물
{
for(h=0;
h<=nowTable3.Rows.Count-1;
하++ )
{
TotalPri=TotalPri+Int32.Parse( nowTable3.Rows[h][4].ToString( ) );
//Double.Parse( ( 문자열 )TotalText.Text );
}
label.Text="总计: "+TotalPri.ToString( )+" 원" ;
}
}
}
공개 무효 업데이트( )
{
나는 int;
int j;
정수 k;
ArrayList deleteItem = new ArrayList( 10 );
DataGridItem _item ;
j=0;
int deleteid;
k=0;
DataTable nowTable2=새 DataTable( "nowCartTable2" );
nowTable2=( DataTable ) 세션["myCartTable"];
for(i=0;
i<=this.ShoppingCartDlt.Items.Count-1;
나++ )
{
_item = this.ShoppingCartDlt.Items[i];
TextBox CountText=( TextBox )this.ShoppingCartDlt.Items[i].Cells[4].FindControl( "CountTb" );
//컨트롤[1];
//_item.FindControl( "CountTb" );
CheckBox ProductIDCheck =( CheckBox ) _item.FindControl( "chkProductID" );
nowTable2.Rows[i][1] = Int32.Parse( CountText.Text.ToString( ) );
nowTable2.Rows[i][4] = Int32.Parse( nowTable2.Rows[i][1].ToString( ) ) * Double.Parse( nowTable2.Rows[i][3].ToString( ) );
if( ProductIDCheck.Checked )
{
nowTable2.Rows[i][5] = 1;
//添加删除标记1 j=j+1;
}
}
문자열 strExpr="IsDeleted>0";
//http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfSystemDataDataTableClassSelectTopic.asp DataRow[]foundRows = nowTable2.Select( strExpr );
for( int m = 0;
m <foundRows.Length;
m ++ )
{
//Console.WriteLine(foundRows[i][0] );
foundRows[m].Delete( );
}
ShoppingCartDlt.DataSource = nowTable2.DefaultView;
ShoppingCartDlt.DataBind( );
세션["myCartTable"] = nowTable2;
계산기( );
}
#region Web 窗体设计器生成的代码 override protected void OnInit( EventArgs e )
{
// // CODEGEN: 该调用是 asp.NET Web 窗体设计器所必需的. // 초기화구성요소( );
base.OnInit( e );
}
/// <요약> /// 设计器支持所需적방법 - 不要使用代码编辑器修改 /// 此方法的内容. /// </summary> private void 초기화컴포넌트( )
{
this.update.Click += new System.EventHandler( this.update_Click );
this.CheckOut.Click += new System.EventHandler( this.CheckOut_Click );
this.Load += new System.EventHandler( this.Page_Load );
}
#endregion
개인 무효 update_Click(개체 보낸 사람, System.EventArgs e)
{
업데이트( );
}
개인 무효 CheckOut_Click( 개체 보낸 사람, System.EventArgs e )
{
업데이트( );
Response.Redirect( "checkout.aspx" );
}
}
}
http://www.cnblogs.com/boundless/archive/2007/01/16/621553.html