用xml实现购物车

cyy1981 2006-07-16 10:45:39
有一个xsd文件,把购物车中选购的物品存储到xml中,然后把这个xml文件同定单一起插入数据库
order 表
orderid
product(存放xml)

应该如河实现呢?
有代码的贴一下


写过的指点一下方法。。。。。
...全文
464 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
广州人 2007-04-08
  • 打赏
  • 举报
回复
呵呵,看钻石来滴
ztwz 2007-04-08
  • 打赏
  • 举报
回复
瞎子点灯白费油!
偶来看钻石的!
sunxw18 2007-04-08
  • 打赏
  • 举报
回复
UP~
sujo 2007-04-08
  • 打赏
  • 举报
回复
用数据库就好了
cyy1981 2007-03-16
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;


///////////////////////////////////////////////////////////////////////////////


// This class exists to provide a bit more type-safety and
// code maintainability when using EventSet
public sealed class EventKey : Object {
}


///////////////////////////////////////////////////////////////////////////////


public sealed class EventSet {
// The private dictionary used to maintain EventKey -> Delegate mappings
private Dictionary<EventKey, Delegate> m_events =
new Dictionary<EventKey, Delegate>();

// Adds an EventKey -> Delegate mapping if it doesn't exist or
// combines a delegate to an existing EventKey
public void Add(EventKey eventKey, Delegate handler) {
lock (m_events) {
Delegate d;
m_events.TryGetValue(eventKey, out d);
m_events[eventKey] = Delegate.Combine(d, handler);
}
}

// Removes a delegate from an EventKey (if it exists) and
// removes the EventKey -> Delegate mapping the last delegate is removed
public void Remove(EventKey eventKey, Delegate handler) {
lock (m_events) {
// Do not throw an exception if attempting to remove
// a delegate from an EventKey not in the set
Delegate d;
if (m_events.TryGetValue(eventKey, out d)) {
d = Delegate.Remove(d, handler);

// If a delegate remains, set the new head else remove the EventKey
if (d != null) m_events[eventKey] = d;
else m_events.Remove(eventKey);
}
}
}

// Raies the event for the indicated EventKey
public void Raise(EventKey eventKey, Object sender, EventArgs e) {
// Don't throw an exception if the EventKey is not in the set
Delegate d;
lock (m_events) { m_events.TryGetValue(eventKey, out d); }
if (d != null) {
// Because the dictionary can contain several different delegate types,
// it is impossible to construct a type-safe call to the delegate at
// compile time. So, I call the System.Delegate type抯 DynamicInvoke
// method, passing it the callback method抯 parameters as an array of
// objects. Internally, DynamicInvoke will check the type safety of the
// parameters with the callback method being called and call the method.
// If there is a type mismatch, then DynamicInvoke will throw an exception.
d.DynamicInvoke(new Object[] { sender, e });
}
}
}


//////////////////////////////// End of File //////////////////////////////////
cyy1981 2006-11-26
  • 打赏
  • 举报
回复
function returnDate() //根据日期格式等返回用户选定的日期
{
if(WebCalendar.objExport)
{
var returnValue;
var a = (arguments.length==0) ? WebCalendar.day[this.id.substr(8)].split("/") : arguments[0].split("/");
var d = WebCalendar.format.match(/^(\w{4})(-|\/)(\w{1,2})\2(\w{1,2})$/);
if(d==null){alert("你设定的日期输出格式不对!\r\n\r\n请重新定义 WebCalendar.format !"); return false;}
var flag = d[3].length==2 || d[4].length==2; //判断返回的日期格式是否要补零
returnValue = flag ? a[2] +d[2]+ appendZero(a[1]) +d[2]+ appendZero(a[0]) : a[2] +d[2]+ a[1] +d[2]+ a[0];
if(WebCalendar.timeShow)
{
var h = new Date().getHours(), m = new Date().getMinutes(), s = new Date().getSeconds();
returnValue += flag ? " "+ appendZero(h) +":"+ appendZero(m) +":"+ appendZero(s) : " "+ h +":"+ m +":"+ s;
}
WebCalendar.objExport.value = returnValue;
hiddenCalendar();
}
}
function document.onclick()
{
if(WebCalendar.eventSrc != window.event.srcElement) hiddenCalendar();
}
//--></script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<p>
开始时间<
<input type="text" id="txtStart" onfocus="calendar()"/>结束时间
<asp:textbox id="txtEnd" onfocus="calendar()" runat="server"></asp:textbox>
<asp:button id="btnOk" runat="server" text="确认" width="96px" OnClick="btnOk_Click"></asp:button></p>
<p>
 </p>
</form>
<p><input id="txtTemp" style="DISPLAY: none" type="text" size="20" name="txtTemp" runat="server"></p>
<script language="javascript">
if(document.all("txtTemp").value!="")
{
alert(document.all("txtTemp").value);
}
</script>
</body>
</html>
cyy1981 2006-11-26
  • 打赏
  • 举报
回复
function funMonthSelect() //月份的下拉框
{
var m = isNaN(parseInt(WebCalendar.thisMonth, 10)) ? new Date().getMonth() + 1 : parseInt(WebCalendar.thisMonth);
var e = WebCalendar.iframe.document.forms[0].tmpMonthSelect;
for (var i=1; i<13; i++) e.options.add(new Option(i +"月", i));
e.style.display = ""; e.value = m; e.focus(); window.status = e.style.top;
}
function funYearSelect() //年份的下拉框
{
var n = WebCalendar.yearFall;
var e = WebCalendar.iframe.document.forms[0].tmpYearSelect;
var y = isNaN(parseInt(WebCalendar.thisYear, 10)) ? new Date().getFullYear() : parseInt(WebCalendar.thisYear);
y = (y <= 1000)? 1000 : ((y >= 9999)? 9999 : y);
var min = (y - n >= 1000) ? y - n : 1000;
var max = (y + n <= 9999) ? y + n : 9999;
min = (max == 9999) ? max-n*2 : min;
max = (min == 1000) ? min+n*2 : max;
for (var i=min; i<=max; i++) e.options.add(new Option(i +"年", i));
e.style.display = ""; e.value = y; e.focus();
}
function prevM() //往前翻月份
{
WebCalendar.thisDay = 1;
if (WebCalendar.thisMonth==1)
{
WebCalendar.thisYear--;
WebCalendar.thisMonth=13;
}
WebCalendar.thisMonth--; writeCalendar();
}
function nextM() //往后翻月份
{
WebCalendar.thisDay = 1;
if (WebCalendar.thisMonth==12)
{
WebCalendar.thisYear++;
WebCalendar.thisMonth=0;
}
WebCalendar.thisMonth++; writeCalendar();
}
function prevY(){WebCalendar.thisDay = 1; WebCalendar.thisYear--; writeCalendar();}//往前翻 Year
function nextY(){WebCalendar.thisDay = 1; WebCalendar.thisYear++; writeCalendar();}//往后翻 Year
function hiddenSelect(e){for(var i=e.options.length; i>-1; i--)e.options.remove(i); e.style.display="none";}
function getObjectById(id){ if(document.all) return(eval("document.all."+ id)); return(eval(id)); }
function hiddenCalendar(){getObjectById("meizzCalendarLayer").style.display = "none";};
function appendZero(n){return(("00"+ n).substr(("00"+ n).length-2));}//日期自动补零程序
function String.prototype.trim(){return this.replace(/(^\s*)|(\s*$)/g,"");}
function dayMouseOver()
{
this.className = "over";
this.style.backgroundColor = WebCalendar.darkColor;
if(WebCalendar.day[this.id.substr(8)].split("/")[1] == WebCalendar.thisMonth)
this.style.color = WebCalendar.lightColor;
}
function dayMouseOut()
{
this.className = "out"; var d = WebCalendar.day[this.id.substr(8)], a = d.split("/");
this.style.removeAttribute('backgroundColor');
if(a[1] == WebCalendar.thisMonth && d != WebCalendar.today)
{
if(WebCalendar.dateStyle && a[0] == parseInt(WebCalendar.dateStyle[4], 10))
this.style.color = WebCalendar.lightColor;
this.style.color = WebCalendar.wordColor;
}
}
function writeCalendar() //对日历显示的数据的处理程序
{
var y = WebCalendar.thisYear;
var m = WebCalendar.thisMonth;
var d = WebCalendar.thisDay;
WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28;
if (!(y<=9999 && y >= 1000 && parseInt(m, 10)>0 && parseInt(m, 10)<13 && parseInt(d, 10)>0)){
alert("对不起,你输入了错误的日期!");
WebCalendar.thisYear = new Date().getFullYear();
WebCalendar.thisMonth = new Date().getMonth()+ 1;
WebCalendar.thisDay = new Date().getDate(); }
y = WebCalendar.thisYear;
m = WebCalendar.thisMonth;
d = WebCalendar.thisDay;
WebCalendar.iframe.meizzYearHead.innerText = y +" 年";
WebCalendar.iframe.meizzYearMonth.innerText = parseInt(m, 10) +" 月";
WebCalendar.daysMonth[1] = (0==y%4 && (y%100!=0 || y%400==0)) ? 29 : 28; //闰年二月为29天
var w = new Date(y, m-1, 1).getDay();
var prevDays = m==1 ? WebCalendar.daysMonth[11] : WebCalendar.daysMonth[m-2];
for(var i=(w-1); i>=0; i--) //这三个 for 循环为日历赋数据源(数组 WebCalendar.day)格式是 d/m/yyyy
{
WebCalendar.day[i] = prevDays +"/"+ (parseInt(m, 10)-1) +"/"+ y;
if(m==1) WebCalendar.day[i] = prevDays +"/"+ 12 +"/"+ (parseInt(y, 10)-1);
prevDays--;
}
for(var i=1; i<=WebCalendar.daysMonth[m-1]; i++) WebCalendar.day[i+w-1] = i +"/"+ m +"/"+ y;
for(var i=1; i<39-w-WebCalendar.daysMonth[m-1]+1; i++)
{
WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ (parseInt(m, 10)+1) +"/"+ y;
if(m==12) WebCalendar.day[WebCalendar.daysMonth[m-1]+w-1+i] = i +"/"+ 1 +"/"+ (parseInt(y, 10)+1);
}
for(var i=0; i<39; i++) //这个循环是根据源数组写到日历里显示
{
var a = WebCalendar.day[i].split("/");
WebCalendar.dayObj[i].innerText = a[0];
WebCalendar.dayObj[i].title = a[2] +"-"+ appendZero(a[1]) +"-"+ appendZero(a[0]);
WebCalendar.dayObj[i].bgColor = WebCalendar.dayBgColor;
WebCalendar.dayObj[i].style.color = WebCalendar.wordColor;
if ((i<10 && parseInt(WebCalendar.day[i], 10)>20) || (i>27 && parseInt(WebCalendar.day[i], 10)<12))
WebCalendar.dayObj[i].style.color = WebCalendar.wordDark;
if (WebCalendar.inputDate==WebCalendar.day[i]) //设置输入框里的日期在日历上的颜色
{WebCalendar.dayObj[i].bgColor = WebCalendar.darkColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}
if (WebCalendar.day[i] == WebCalendar.today) //设置今天在日历上反应出来的颜色
{WebCalendar.dayObj[i].bgColor = WebCalendar.todayColor; WebCalendar.dayObj[i].style.color = WebCalendar.lightColor;}
}
}
fttcccc 2006-09-01
  • 打赏
  • 举报
回复
不管是在客户端还是服务器端,直接XML都很快,顶一下
myminimouse 2006-08-12
  • 打赏
  • 举报
回复
up
可爱的排骨 2006-08-11
  • 打赏
  • 举报
回复
杀鸡用牛刀而已

把XSD和XML数据放进DATASET里,再用DATASET更新数据库
cyy1981 2006-08-11
  • 打赏
  • 举报
回复
using System;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.IO;
using System.Collections;

namespace KellysEZControls
{

/// <summary>
/// Textbox control that has autocomplete
/// </summary>
public class SenseControl2 : TextBox
{
/// <summary>
/// Raised when the user saves the text in the textbox.
/// </summary>
/// <remarks>This can be used to inform other controls
/// that are using the same list to reload.</remarks>
public event EventHandler ChoicesSaved;

/// <summary>
/// Raises the Choices Saved event when the user saves an item to the list.
/// </summary>
/// <param name="e"></param>
[Description("Raises the Choices Saved event when the user saves an item to the list.")]
protected virtual void OnChoicesSaved(System.EventArgs e)
{
if(ChoicesSaved != null)
ChoicesSaved(this, e);
}


#region "Variables"
private ArrayList _values = new ArrayList(); //List that holds the choices.
private bool _update = false; //Flag used to tell the keypress handler if it should autocomplete
private string _choiceFile = ""; //The filename of the file that the list is read from and saved to.
private bool _init = false; //Set to true when the _values is loaded.
#endregion

#region "Constructors"
/// <summary>
/// Constructor
/// </summary>
/// <remarks>Loads the contex menu.</remarks>
public SenseControl2()
{
AddContextMenu();
}
#endregion

#region "Properties"

/// <summary>
/// Sets the list of choices directly
/// </summary>
[Description("Sets the list of choices")]
public string[] Choices
{
get
{
return (string[])_values.ToArray(typeof(string));
}
set
{
_values = new ArrayList(value);
}
}

/// <summary>
/// The filename of the file to get the choices from
/// </summary>
[Description("The filename of the file to get the choices from.")]
public string ChoiceFile
{
get{return _choiceFile;}
set{ _choiceFile = value;}
}

#endregion

#region "Methods"
/// <summary>
/// Causes the control to reload the choice file.
/// </summary>
/// <remarks>This can be used to keep two controls using the same list in sync</remarks>
[Description("Causes the control to reload the choice file.")]
public void ReloadChoices()
{
Reload();
}

#endregion

#region "Private Functions"
/// <summary>
/// Adds the Save context menu
/// </summary>
private void AddContextMenu()
{
ContextMenu saveContextMenu = new ContextMenu();
this.ContextMenu = saveContextMenu;
MenuItem mnuItemNew = new MenuItem("Save",new System.EventHandler(this.Saved_OnClick));
saveContextMenu.MenuItems.Add(mnuItemNew);
}

/// <summary>
/// Searches the list for a match
/// </summary>
/// <returns>True if there is a match in the list</returns>
private bool AlreadyListed()
{
IEnumerator itext = _values.GetEnumerator();
string test = this.Text.ToUpper();
while(itext.MoveNext())
{
string text = (string)itext.Current;
if(text.ToUpper().IndexOf(test) == 0)
return true;
}
return false;
}
/// <summary>
/// Saves the text in the textbox into the file.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <remarks>If the file does not exist, it will be created</remarks>
protected void Saved_OnClick(System.Object sender, System.EventArgs e)
{
string text;
FileStream fs;
StreamWriter sw;

if(this.Text.Trim() == "") return; //Don't save empty strings
bool found = AlreadyListed();
if(File.Exists(_choiceFile)) //if the file already exists add to it.
//we do not want to recreate it in case another control is using it
{
if(found) return; //no sense adding it
try
{
_values.Add(this.Text);
fs = new FileStream(_choiceFile, FileMode.Append);
sw = new StreamWriter(fs);
sw.WriteLine(this.Text);
sw.Close();
fs.Close();
OnChoicesSaved(new System.EventArgs());
}
catch(Exception ee)
{
Debug.WriteLine(ee.Message);
Debug.Assert(false);
throw new Exception("Could not save the value: " + this.Text + " in the control: " + this.Name ,ee);
}
}
else //the file was not found, so create it. Any other control will find this one.
{
if(!found)
_values.Add(this.Text);
try
{
IEnumerator itext = _values.GetEnumerator();
fs = new FileStream(_choiceFile, FileMode.Create);
sw = new StreamWriter(fs);
while(itext.MoveNext())
{
text = (string)itext.Current;
sw.WriteLine(text);
}
sw.Close();
fs.Close();
}
catch(Exception ee)
{
Debug.WriteLine(ee.Message);
Debug.Assert(false);
throw new Exception("Could not save the list to file: " + _choiceFile + " in the control: " + this.Name ,ee);
}
}
}

/// <summary>
/// Reloads the list from the file. If there is no filename, create the default one.
/// </summary>
/// <remarks>The default filename will be the control name wit '.txt' appended.</remarks>
private void Reload()
{
try
{
if(_choiceFile == "")
_choiceFile = this.Name + ".txt";

_values = new ArrayList();
FileStream fs = new FileStream(_choiceFile, FileMode.OpenOrCreate,FileAccess.ReadWrite);
StreamReader sr = new StreamReader(fs);
while(sr.Peek() != -1)
_values.Add(sr.ReadLine());
sr.Close();
fs.Close();
_init = true;
}
catch(Exception ee)
{
Debug.WriteLine(ee.Message);
Debug.Assert(false);
throw new Exception("Could not open the value file for the control: " + this.Name ,ee);
}
}
#endregion

/// <summary>
/// Raises the System.Windows.Forms.Control.TextChanged event.
/// </summary>
/// <param name="e">An System.EventArgs that contains the event data.</param>
protected override void OnTextChanged(EventArgs e)
{
if(_values.Count == 0 && !_init) //Load the values from the file.
{
Reload();
}
string test = this.Text.ToUpper();
if((test == "") || _update)
{
base.OnTextChanged (e);
}
else
{
IEnumerator itext = _values.GetEnumerator();
bool found = false;
while((itext.MoveNext()) && (!found))
{
string text = (string)itext.Current;
if(text.ToUpper().IndexOf(test) == 0)
{
_update = true;
this.Text = text;
this.SelectionStart = test.Length;
this.SelectionLength = text.Length - test.Length;
found = true;
_update = false;
}
}
base.OnTextChanged (e);
}
}


/// <summary>
/// Raises the System.Windows.Forms.Control.KeyDown event.
/// </summary>
/// <param name="e">A System.Windows.Forms.KeyEventArgs that contains the event data.</param>
protected override void OnKeyDown(KeyEventArgs e)
{
if(e.KeyValue == 8 || e.KeyValue == 46)
_update = true;
base.OnKeyDown (e);
}

/// <summary>
/// Raises the System.Windows.Forms.Control.KeyUp event.
/// </summary>
/// <param name="e">A System.Windows.Forms.KeyEventArgs that contains the event data.</param>
protected override void OnKeyUp(KeyEventArgs e)
{
if(e.KeyValue == 8 || e.KeyValue == 46)
_update = false;
base.OnKeyUp (e);
}
}
}
cyy1981 2006-08-06
  • 打赏
  • 举报
回复
好久不来了,公司不能发帖子。这是我们的一个traning project,requiement就是这样要求的
teacher1998 2006-07-17
  • 打赏
  • 举报
回复
看到了3颗钻.我也来冒泡!
saucer 2006-07-17
  • 打赏
  • 举报
回复
but if you insist, see

Building an ASP.NET Shopping Cart Using DataTables
http://www.sitepoint.com/article/net-shopping-cart-datatables

when you are ready to save, convert DataTable/DataSet into xml and save the xml string in the database
winner2050 2006-07-17
  • 打赏
  • 举报
回复
这种使用XML有点脱裤子放屁
yilan505 2006-07-17
  • 打赏
  • 举报
回复
不为别的. 我看到"思归" 特地回一个.
saucer 2006-07-17
  • 打赏
  • 举报
回复
既然用数据库,又为什么要把购物篮持久化为XML,然后存入数据库呢?如果不用SQL SERVER 2005 的话,你无法检索购物篮的东西啊
gngnandgngn 2006-07-17
  • 打赏
  • 举报
回复
楼主的设计讲的不清楚啊, 你那个xml是在客户端的还是服务端的??
如果是服务端的, 那一点意义都没有, 直接插入到数据库里去不就行了??
如果是在客户端的, 那还有点意思, 购物的时候读写本地的文件当然快很多, 但似乎权限不够啊。。。
myminimouse 2006-07-17
  • 打赏
  • 举报
回复
up

62,254

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧