简阳人论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 1039|回复: 0

网上购物车简单代码5

[复制链接]
发表于 2009-1-6 23:18:16 | 显示全部楼层 |阅读模式 来自 中国北京
</html>


Global.asax
<%@ Application Language="C#" %>

<script runat="server">

    void Application_Start(object sender, EventArgs e)
    {
        // 在应用程序启动时运行的代码

    }
   
    void Application_End(object sender, EventArgs e)
    {
        //  在应用程序关闭时运行的代码

    }
        
    void Application_Error(object sender, EventArgs e)
    {
        // 在出现未处理的错误时运行的代码

    }

    void Session_Start(object sender, EventArgs e)
    {
        // 在新会话启动时运行的代码
        Hashtable ht = new Hashtable(1000);
        Session["shopping"] = ht;
        Session.Timeout = 60;
    }

    void Session_End(object sender, EventArgs e)
    {
        //Session.Clear();//清空所有的键值对,但session对象存在。
        Session.Abandon(); //对session对象进行销毁。
        // 在会话结束时运行的代码。
        // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
        // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
        // 或 SQLServer,则不会引发该事件。
        

    }
      
</script>
shouyin.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="shouyin.aspx.cs" Inherits="shouyin" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>收银台</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <%
            Hashtable ht = (Hashtable)Session["shopping"];
            if (ht == null)
            {
                throw new Exception("程序有问题,请联系管理员");
            }
            else {
                if (ht.Count == 0)
                {
                    Response.Redirect("Default.aspx");
                }
                else {
                    Application.Lock();
                    string strconn = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
                    SqlConnection conn = new SqlConnection(strconn);
                    conn.Open();
                    SqlCommand command = conn.CreateCommand();
                    string fu_type = "现金";
                    string so_type = "送货上门";
                    int userid = 1;
                    command.CommandText = "exec ordercreate '"+DateTime.Now.ToLocalTime().ToString()+"','"+fu_type+"','"+so_type+"',"+userid;
                    int o_id=(int)command.ExecuteScalar();
                  %>
                  <table><tr><td>编号</td><td>商品名</td><td>商品单价</td><td>购物数量</td><td>总价</td></tr>
                  <%
                      ICollection ic= ht.Keys;
                      double alltotal = 0;
                      foreach (int key in ic)
                      {
                          购物商品 s=(购物商品)ht[key];
                          double stotal = s.getTotalPrice();
                          alltotal += stotal;
                          command.CommandText = "exec gouwuproc "+o_id+","+s.Id+",'"+s.Name+"',"+s.Price+","+s.Snum;
                          command.ExecuteNonQuery();
                          %>
                          <tr><td><%=s.Id %></td><td><%=s.Name %></td><td><%=s.Price %></td><td><%=s.Snum %></td><td><%=stotal %></td></tr>
                          <%
                      }
                  %>
                  <tr><td colspan="5" align="right">总计:<%=alltotal %></td></tr>
                  </table>
                  <%
                      //ht.Clear();
                      //Session["shopping"] = ht;
                      conn.Close();
                      Application.UnLock();
                }
            }
         %>
    </div>
    </form>
</body>
</html>
shouyin.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class shouyin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
Web.Config
<?xml version="1.0"?>
<!--
    注意: 除了手动编辑此文件以外,您还可以使用
    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
     “网站”->“Asp.Net 配置”选项。
    设置和注释的完整列表在
    machine.config.comments 中,该文件通常位于
    \Windows\Microsoft.Net\Framework\v2.x\Config 中
-->
<configuration>
         <appSettings>
    <add key="pagecount" value="6"/>
  </appSettings>
  <connectionStrings>
    <add connectionString="server=.;database=shopping;integrated security=true" name="sql"/>
  </connectionStrings>
        <system.web>
                <!--
            设置 compilation debug="true" 将调试符号插入
            已编译的页面中。但由于这会
            影响性能,因此只在开发过程中将此值
            设置为 true。
        -->
                <compilation debug="true"/>
                <!--
            通过 <authentication> 节可以配置 ASP.NET 使用的
            安全身份验证模式,
            以标识传入的用户。
        -->
                <!--
            如果在执行请求的过程中出现未处理的错误,
            则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
            开发人员通过该节可以配置
            要显示的 html 错误页
            以代替错误堆栈跟踪。

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
        </system.web>
</configuration>
数据库.txt
create database shopping

use shopping
create table userinfo(id int not null primary key identity(1,1),
name varchar(50) not null,pwd varchar(50) not null)
insert into userinfo values('song','123')

create table kucun(id int not null primary key identity(1,1),
name varchar(50),price decimal(9,2),amount bigint,imgurl varchar(50))

insert into kucun values('袜子',100.02,1000,'image/1.gif')
insert into kucun values('衣服',100.02,1000,'image/2.gif')
insert into kucun values('帽子',100.02,1000,'image/3.gif')
insert into kucun values('眼镜',100.02,1000,'image/4.gif')
insert into kucun values('领带1',100.02,1000,'image/5.gif')
insert into kucun values('领带2',100.02,1000,'image/5.gif')
insert into kucun values('领带3',100.02,1000,'image/5.gif')
insert into kucun values('领带4',100.02,1000,'image/5.gif')
insert into kucun values('领带5',100.02,1000,'image/5.gif')
insert into kucun values('领带6',100.02,1000,'image/5.gif')
insert into kucun values('领带7',100.02,1000,'image/5.gif')
insert into kucun values('领带9',100.02,1000,'image/5.gif')
insert into kucun values('领带9',10,10890,'image/9.gif')


select * from kucun

create table order1
(id int not null primary key identity(1,1),dt varchar(200),
fu_type varchar(50),so_type varchar(50),b_id int not null
foreign key references userinfo(id))


create table order_detail
(id int not null primary key identity(1,1),
o_id int not null foreign key references order1(id),
name varchar(50) not null,price decimal(9,2) not null,amount int not null)

select * from kucun

userinfofenye 2,3
create proc propro
(@page int,@count int) --page为显示几页,@count为一页显示多少数据
as
declare @start int
set @start=(@page-1)*@count+1
declare @end int
set @end=@start+@count-1 --获取从第一行到显示网页的最后一行数据行
create table  #temp(bian int identity(1,1),id int,name varchar(50),price decimal(9,2),amount int ,imgurl varchar(50))
insert into #temp exec('select top '+@end+' * from kucun')
select id,name,price,amount,imgurl from #temp where bian>=@start and bian<=@end





select * from order1

select * from order_detail

select * from userinfo

insert into order1 values('2008-11-27 10:29:30',
'现金','送货上门',1)

select * from order1
select max(id) from order1
select top 1 id from order1 order by id desc

declare @num int
set @num=(select ident_current('order1'))
select @num
1.一个表只有一个标识列
2. ident_current('表名') 返回最近插入的标识列的数据

insert into order_detail
values(ident_current('order1'),'袜子',30.5,10)
select * from order_detail

select * from kucun
select convert(varchar(50),getdate())
declare @temp varchar(50)
set @temp=convert(varchar(50),getdate())
--select @temp
exec ordercreate @temp,'现金','送货上门',1

exec gouwuproc 4,1,'袜子',100.02,200

alter proc ordercreate
(@dt varchar(50),@fu_type varchar(50),@so_type varchar(50),
@b_id int)
as
insert into order1 values(@dt,@fu_type,@so_type,@b_id)
select convert(int,ident_current('order1'))

alter proc gouwuproc
(@o_id int,@sid int,@sname varchar(50),@price decimal(9,2),
@amount int)
as
insert into order_detail
values(@o_id,@sname,@price,@amount)
update kucun set amount=amount-@amount where id=@sid


select * from order1
select * from order_detail
select * from kucun
*滑块验证:
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|小黑屋|手机版|Archiver|简阳人论坛 ( 蜀ICP备07502275号-3 )

川公网安备 51200002000214号

GMT+8, 2024-5-14 09:27 , Processed in 0.331489 second(s), 9 queries , Gzip On, File On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表