A. 求一个购物车项目设计源代码
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;using System.Collections;public partial class AddCar : System.Web.UI.Page{ DataAccess db = new DataAccess(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request.QueryString["id"].ToString(); if (Session["car"] != null) { Hashtable hash = Session["car"] as Hashtable; if (!hash.ContainsKey(id)) { hash.Add(id, 1); } else { hash[id] = int.Parse(hash[id].ToString()) + 1; } Session["car"] = hash; } else { Hashtable hash = new Hashtable(); hash.Add(id, 1); Session["car"] = hash; } Hashtable k = Session["car"] as Hashtable; DataColumn dc0 = new DataColumn("id", typeof(string)); DataColumn dc1 = new DataColumn("商品名", typeof(string)); DataColumn dc2 = new DataColumn("价格", typeof(float)); DataColumn dc3 = new DataColumn("数量", typeof(int)); DataColumn dc4 = new DataColumn("总价格", typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+" "+i.Value+"<br>"); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet("select * from proct where p_id=" + i.Key); dr["id"] = ds.Tables[0].Rows[0]["p_id"].ToString(); dr["商品名"] = ds.Tables[0].Rows[0]["p_name"].ToString(); dr["价格"] = ds.Tables[0].Rows[0]["p_price"].ToString(); dr["数量"] = int.Parse(k[i.Key].ToString()); dr["总价格"] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0]["p_price"].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("default2.aspx"); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); Hashtable k = Session["car"] as Hashtable; Session["car"] = k; k.Remove(id); DataColumn dc0 = new DataColumn("id", typeof(string)); DataColumn dc1 = new DataColumn("商品名", typeof(string)); DataColumn dc2 = new DataColumn("价格", typeof(float)); DataColumn dc3 = new DataColumn("数量", typeof(int)); DataColumn dc4 = new DataColumn("总价格", typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+" "+i.Value+"<br>"); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet("select * from proct where p_id=" + i.Key); dr["id"] = ds.Tables[0].Rows[0]["p_id"].ToString(); dr["商品名"] = ds.Tables[0].Rows[0]["p_name"].ToString(); dr["价格"] = ds.Tables[0].Rows[0]["p_price"].ToString(); dr["数量"] = int.Parse(k[i.Key].ToString()); dr["总价格"] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0]["p_price"].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } protected void Button2_Click(object sender, EventArgs e) { Hashtable k = Session["car"] as Hashtable; string code = DateTime.Now.Ticks.ToString() + new Random().Next(); db.ExecuteNonQuery("insert into OrderList values('"+code+"')"); foreach(DictionaryEntry i in k) { db.ExecuteNonQuery("insert into DetailsList values('"+code+"',"+Session["u_id"].ToString()+","+i.Key+","+i.Value+")"); } }}自己慢慢领悟把%D%A
B. 用dreamweaver怎么制作购物车
制作购物车属于编写动态程序,首先要选择用哪一种程序来制作,比如php,jsp等等;dreamweaver可以利用内置的可视化动态程序制作功能生成程序,不过也要了解动态程序的一些基础知识,比如安装网络服务器以便测试编写的网页,安装数据库、建立站点等等,如果对动态程序的代码一点不了解,也不能够修改出现的错误、丰富网页的功能。
像购物车这样的程序,仅仅用dreamweaver生成的程序来制作效果会非常简陋,很不专业,制作功能完善的程序还是需要学习代码,手写编程。
C. 购物车的java代码
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;public class ShoppingCartManager {
HashMap<String, String> hm=new HashMap<String, String>();
float totlePrice=0;
//添加book到购物车
public void addBook(String bookId,String bookQuantity){
if(hm.containsKey(bookId)){
int value=Integer.parseInt(hm.get(bookId));
value+=Integer.parseInt(bookQuantity);
hm.put(bookId, value+"");
}else{
hm.put(bookId, bookQuantity);
}
}
//修改数量
public void updateQuantity(String bookId,String bookQuantity){
hm.put(bookId, bookQuantity);
}
//获取购物车的所有信息 并计算总价
public ArrayList<BookBean> getShoppingCart(){
ArrayList<BookBean> al=new ArrayList<BookBean>();
Iterator<String> i=hm.keySet().iterator();
String ids="";
BookTableManager btm=new BookTableManager();
while(i.hasNext()){
ids=ids+","+i.next();
}
al= btm.selectByBookIds(ids);
totlePrice=0; //清空总价,防止无限累计
for(int j=0;j<al.size();j++){
BookBean bb=al.get(j);
totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));
}
return al;
}
//获取总价
public float getTotlePrice(){
return totlePrice;
}
//根据ID获取数量
public String getQuantityById(String id){
String quantity=hm.get(id);
return quantity;
}
//清空购物车
public void clear(){
hm.clear();
}
//删除购物车中的一本书
public void deleteById(String id){
hm.remove(id);
}
}
D. JAVA 购物车示例代码
import java.awt.*;
import java.awt.event.*;
class ShopFrame extends Frame implements ActionListener
{ Label label1,label2,label3,label4;
Button button1,button2,button3,button4,button5;
TextArea text;
Panel panel1,panel2;
static float sum=0.0f;
ShopFrame(String s)
{ super(s);
setLayout(new BorderLayout());
label1=new Label("面纸:3元",Label.LEFT);
label2=new Label("钢笔:5元",Label.LEFT);
label3=new Label("书:10元",Label.LEFT);
label4=new Label("袜子:8元",Label.LEFT);
button1=new Button("加入购物车");
button2=new Button("加入购物车");
button3=new Button("加入购物车");
button4=new Button("加入购物车");
button5=new Button("查看购物车");
text=new TextArea("商品有:"+"\n",5,10);
text.setEditable(false);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
}
);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
panel1=new Panel();
panel2=new Panel();
panel1.add(label1);
panel1.add(button1);
panel1.add(label2);
panel1.add(button2);
panel1.add(label3);
panel1.add(button3);
panel1.add(label4);
panel1.add(button4);
panel2.setLayout(new BorderLayout());
panel2.add(button5,BorderLayout.NORTH);
panel2.add(text,BorderLayout.SOUTH);
this.add(panel1,BorderLayout.CENTER);
this.add(panel2,BorderLayout.SOUTH);
setBounds(100,100,350,250);
setVisible(true);
validate();
}
public void actionPerformed(ActionEvent e)
{ if(e.getSource()==button1)
{ text.append("一个面纸、");
sum=sum+3;
}
else if(e.getSource()==button2)
{ text.append("一只钢笔、");
sum=sum+5;
}
else if(e.getSource()==button3)
{ text.append("一本书、");
sum=sum+10;
}
else if(e.getSource()==button4)
{ text.append("一双袜子、");
sum=sum+8;
}
else if(e.getSource()==button5)
{
text.append("\n"+"总价为:"+"\n"+sum);
}
}
}
public class Shopping {
public static void main(String[] args) {
new ShopFrame("购物车");
}
}
我没用Swing可能显示不出来你的效果。不满意得话我在给你编一个。