MODE 层 代码
namespace MODEL
{
public class Article
{
int _ID=0;
int _CID=0;//类别ID
string _Title="";//标题
DateTime _AddDate=DateTime.Now;//添加日期
string _Content="";//内容
int _Hits=0;//点击次数
int _Count=0;//评论次数
public Article()
{
}
//数据库记录实例化为 Article,这个地方 从数据库 读出一条记录后 可以 直接实例化 MODEL,不需要 在 一个个去写
public Article(DataRow dataRow)
{
DataColumnCollection DCC = dataRow.Table.Columns;
if (DCC.Contains("id"))
{
_ID = DataHelper.Int(dataRow["id"]);
}
if (DCC.Contains("cid"))
{
_CID = DataHelper.Int(dataRow["cid"]);
}
if (DCC.Contains("hits"))
{
_Hits = DataHelper.Int(dataRow["hits"]);
}
if (DCC.Contains("count"))
{
_Count = DataHelper.Int(dataRow["count"]);
}
if (DCC.Contains("adddate"))
{
_AddDate = DataHelper.dateTime(dataRow["adddate"]);
}
if (DCC.Contains("title"))
{
_Title = DataHelper.String(dataRow["title"] );
}
if (DCC.Contains("content"))
{
_Content =DataHelper.String( dataRow["content"] );
}
}
//外部接受过来的数据实例化类 使用 hashTable 构造 类
public Article(Hashtable hashtable)
{
if (hashtable.Contains("id"))
{
_ID = DataHelper.Int(hashtable["id"]);
}
if (hashtable.Contains("cid"))
{
_CID = DataHelper.Int(hashtable["cid"]);
}
if (hashtable.Contains("hits"))
{
_Hits = DataHelper.Int(hashtable["hits"]);
}
if (hashtable.Contains("count"))
{
_Count = DataHelper.Int(hashtable["count"]);
}
if (hashtable.Contains("adddate"))
{
_AddDate = DataHelper.dateTime(hashtable["adddate"]);
}
if (hashtable.Contains("title"))
{
_Title = DataHelper.String(hashtable["title"] );
}
if (hashtable.Contains("content"))
{
_Content = DataHelper.String(hashtable["content"] );
}
}
public Article(int id,int cid,string title,DateTime addDate,string content,int hits,int count)
{
_ID = id;
_CID = cid;
_Title = title;
_AddDate = addDate;
_Content = content;
_Hits = hits;
_Count = count;
}
public Article(int cid, string title, DateTime addDate, string content, int hits, int count)
{
_CID = cid;
_Title = title;
_AddDate = addDate;
_Content = content;
_Hits = hits;
_Count = count;
}
public Article( int cid, string title, string content)
{
_CID = cid;
_Title = title;
_Content = content;
}
public Article(int id, int cid, string title, string content)
{
_ID = id;
_CID = cid;
_Title = title;
_Content = content;
}
public int ID
{
get { return _ID; }
set { _ID = value; }
}
public int CID
{
get { return _CID; }
set { _CID = value; }
}
public string Title
{
get { return _Title; }
set { _Title = value; }
}
public DateTime AddDate
{
get { return _AddDate; }
set { _AddDate = value; }
}
public string Content
{
get { return _Content; }
set { _Content = value; }
}
public int Hits
{
get { return _Hits; }
set { _Hits = value; }
}
public int Count
{
get { return _Count; }
set { _Count = value; }
}
}
}
RequestData 类:代替 Request.Form; 上面用到的,作用是 把 Request.Form;里面的 name value 保存到一个 hashTable 里面
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
/// <summary>
///RequestData 的摘要说明
/// </summary>
public class RequestData
{
public RequestData()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
public static Hashtable Get()
{
Hashtable _Hashtable = new Hashtable();
NameValueCollection NVC = HttpContext.Current.Request.Form;
for (int i = 0; i < NVC.Count; i++)
{
_Hashtable.Add(NVC.Keys[i].ToString().ToLower(), NVC[NVC.Keys[i]]);
}
return _Hashtable;
}
}
UI:
ArticleAdd.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="?action=save" method="post">
标题:<input type="text" value="134" name="Title" /><br />
内容:<input type="text" value="134" name="Content" /><br />
日期:<input type="text" value="1989 07 18" name="AddDate" /><br />
类别ID:<input type="text" value="134" name="CID" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>
ArticleAdd.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using MODEL;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Hashtable Has = RequestData.Get();
Article ArticleMOD=new Article(Has); //实例化 MODEL
}
}
慕森卡
largeQ
白猪掌柜的
函数式编程
蝴蝶刀刀
眼眸繁星
至尊宝的传说