怎么实现。NET三层架构(要例子)
怎么实现ASP。NET三层架构。。
要有实倒。。不要只解释名词。
不胜感激。。
------解决方案--------------------可以看petshop的分解~~
刚开始接触看petshop3就够用了~~
你可以下载微软苏鹏讲的petshop 与 n层架构~~
可以在csdn上下载:最新三层构架网站 OA设计4大示例
------解决方案--------------------DAL ----1 FILE
----------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration ;
using System.Collections;
using System.Xml;
using System.Xml.XPath;
using IDAL;
using Model;
namespace DAL
{
class xml:Iguestbook
{
string xmlGuestBookPath = System.Web.HttpContext.Current.Server.MapPath("../App_Data/") + ConfigurationSettings.AppSettings["xmlConnectionString"];
//得到所有留言
public guestbook[] getListGuestBook()
{
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load(xmlGuestBookPath);//打开留言本xml文档
XmlNodeList xnl = xmlDoc.SelectSingleNode("guestBooks").ChildNodes;//读取所有结点
XmlElement xe ;//声明一个元素
ArrayList guest = new ArrayList();
foreach (XmlNode xn in xnl)
{
guestbook gb = new guestbook();
xe = (XmlElement)xn;//转换这个节点为一个元素
gb.Time = DateTime.Parse(xe.GetAttribute("time"));//得到留言时间
XmlNodeList xnlChild = xn.ChildNodes ;
gb.Id = gb.Time.ToString();//以时间为主键
gb.Name = xn.ChildNodes[0].InnerText;
gb.Ip = xn.ChildNodes[1].InnerText;
gb.Content = xn.ChildNodes[2].InnerText;
gb.Recontent = xn.ChildNodes[3].InnerText;
gb.Pic = xn.ChildNodes[4].InnerText;
gb.Email = xn.ChildNodes[5].InnerText;
guest.Add(gb);
}
guest.Reverse();//数组反转,最后一条留言在第一位显示
return (guestbook[])guest.ToArray(typeof(guestbook));
}
//得到一条留言
public guestbook[] getOnly(string id)
{
guestbook gb = new guestbook();
ArrayList guest = new ArrayList();
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load(xmlGuestBookPath);
XmlNodeList xnl = xmlDoc.SelectSingleNode("guestBooks").ChildNodes;
XmlElement xe;
foreach (XmlNode xn in xnl)
{
xe = (XmlElement)xn;
gb.Time = DateTime.Parse (xe.GetAttribute("time"));
gb.Id = gb.Time.ToString();//以时间为主键
if (xe.GetAttribute("time") == id)
{
XmlNodeList xnlChild = xn.ChildNodes;
gb.Name = xn.ChildNodes[0].InnerText;
gb.Ip = xn.ChildNodes[1].InnerText;
gb.Content = xn.ChildNodes[2].InnerText;
gb.Recontent = xn.ChildNodes[3].InnerText;
gb.Pic = xn.ChildNodes[4].InnerText;
gb.Email = xn.ChildNodes[5].InnerText;
guest.Add(gb);
}
}
return (guestbook[])guest.ToArray(typeof(guestbook));
}
//添加留言内容
public void setGuestBook(guestbook gb)
{
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load(this.xmlGuestBookPath);
//选择根结点
XmlNode root = xmlDoc.SelectSingleNode("guestBooks");
XmlElement xe = xmlDoc.CreateElement("guestBook");//添加