第二层数据访问层,对底层的数据库访问作一些包装供业务层调用生成的代码如下:
代码中主要生成了针对每个数据库表的inf类了对这些表中的记录管理的基类Manager_Base类
代码中主要生成了针对每个数据库表的inf类了对这些表中的记录管理的基类Manager_Base类
using System;
using System.Data;
using Keyss.Framework;
namespace Keyss.Framework
{
ArticleClassInf#region ArticleClassInf
public class ArticleClassInf
{
protected fields#region protected fields
protected Guid _iD = Guid.Empty;
protected Guid _parentID = Guid.Empty;
protected string _name = String.Empty;
protected string _description = String.Empty;
protected int _orderBy;
protected string _imgUrl = String.Empty;
protected string _iconUrl = String.Empty;
#endregion
public properties#region public properties
public Guid ID
{
get {return _iD;}
set {_iD = value;}
}
public Guid ParentID
{
get {return _parentID;}
set {_parentID = value;}
}
public string Name
{
get {return _name;}
set {_name = value;}
}
public string Description
{
get {return _description;}
set {_description = value;}
}
public int OrderBy
{
get {return _orderBy;}
set {_orderBy = value;}
}
public string ImgUrl
{
get {return _imgUrl;}
set {_imgUrl = value;}
}
public string IconUrl
{
get {return _iconUrl;}
set {_iconUrl = value;}
}
#endregion
public methods#region public methods
public virtual void Populate(System.Data.SqlClient.SqlDataReader reader)
{
try
{
_iD = reader.GetGuid(0);
if (!reader.IsDBNull(1))
_parentID = reader.GetGuid(1);
else
_parentID = Guid.Empty;
_name = reader.GetString(2);
_description = reader.GetString(3);
_orderBy = reader.GetInt32(4);
_imgUrl = reader.GetString(5);
_iconUrl = reader.GetString(6);
}
catch
{
throw new FormatException("DataReader format error!");
}
}
public virtual void Populate(DataRow row)
{
try
{
_iD = (Guid)row[0];
if(!(row[1] is DBNull))
_parentID = (Guid)row[1];
else
_parentID = Guid.Empty;
_name = (string)row[2];
_description = (string)row[3];
_orderBy = (int)row[4];
_imgUrl = (string)row[5];
_iconUrl = (string)row[6];
}
catch
{
throw new FormatException("DataRow format error!");
}
}
#endregion
}
#endregion
ArticleClassManager_Base#region ArticleClassManager_Base
public class ArticleClassManager_Base
{
Insert Update Delete#region Insert Update Delete
public static void Insert(ArticleClassInf articleClassInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[9];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleClassInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ParentID",System.Data.SqlDbType.UniqueIdentifier);
if(articleClassInf.ParentID == Guid.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = articleClassInf.ParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Name",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.Name;
para.Size = 128;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Description",System.Data.SqlDbType.NText);
para.Value = articleClassInf.Description;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleClassInf.OrderBy;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.ImgUrl;
para.Size = 128;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@IconUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.IconUrl;
para.Size = 128;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 0;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[8] = para;
helper.Open();
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
SqlHelper.ThrowSQLError((int)paras[8].Value);
throw new Exception("The inserted record in the table 'A_ArticleClass' can't been selected! ");
}
articleClassInf.Populate(RD);
RD.Close();
helper.Close();
}
public static void Delete(Guid iD)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 1;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static void Update(ArticleClassInf articleClassInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[9];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleClassInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ParentID",System.Data.SqlDbType.UniqueIdentifier);
if(articleClassInf.ParentID == Guid.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = articleClassInf.ParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Name",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.Name;
para.Size = 128;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Description",System.Data.SqlDbType.NText);
para.Value = articleClassInf.Description;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleClassInf.OrderBy;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.ImgUrl;
para.Size = 128;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@IconUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.IconUrl;
para.Size = 128;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 2;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[8] = para;
helper.ExecuteNonQuery("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[8].Value);
}
#endregion
Select#region Select
public static bool CheckByID(Guid iD)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleClassInf GetByID(Guid iD)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static bool CheckByParentIDAndName(Guid parentID,string name)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
if(parentID==Guid.Empty)
whereSql += "ParentID is Null";
else
whereSql += string.Format("ParentID = '{0}'",parentID);
whereSql += " AND " + string.Format("Name = '{0}'",name);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleClassInf GetByParentIDAndName(Guid parentID,string name)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
if(parentID==Guid.Empty)
whereSql += "ParentID is Null";
else
whereSql += string.Format("ParentID = '{0}'",parentID);
whereSql += " AND " + string.Format("Name = '{0}'",name);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetAll(string fieldsName, string whereSql, string orderBy)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
helper.Close();
return result;
}
public static DataTable GetPageData(string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[6];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
string[] newfieldnames = fieldsName.ToUpper().Split(',');
fieldsName = "";
for(int i=0;i<newfieldnames.Length;i++)
{
if(!newfieldnames[i].Trim().StartsWith("A."))
fieldsName += "A.";
fieldsName += newfieldnames[i];
if(i!=newfieldnames.Length -1)
fieldsName += ", ";
}
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@RecordCount",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.Output;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@PageIndex",System.Data.SqlDbType.Int);
para.Value = pageIndex;
para.Direction = System.Data.ParameterDirection.InputOutput;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@PageSize",System.Data.SqlDbType.Int);
para.Value = pageSize;
paras[5] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetPageData",System.Data.CommandType.StoredProcedure,paras);
pageIndex = (int)paras[4].Value;
recordCount = (int)paras[3].Value;
helper.Close();
return result;
}
public static DataTable GetAllByParentID(Guid parentID, string fieldsName, string whereSql, string orderBy)
{
string whereSql1 = "";
if(parentID==Guid.Empty)
whereSql1 += "ParentID is Null";
else
whereSql1 += string.Format("ParentID = '{0}'",parentID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetAll(fieldsName, whereSql1, orderBy);
}
public static DataTable GetPageDataByParentID(Guid parentID, string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
string whereSql1 = "";
if(parentID==Guid.Empty)
whereSql1 += "ParentID is Null";
else
whereSql1 += string.Format("ParentID = '{0}'",parentID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetPageData(fieldsName, whereSql1, orderBy,out recordCount, ref pageIndex, pageSize);
}
#endregion
Other method#region Other method
public static int GetRecordNumber(string whereSql)
{
int result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "Count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
result =(int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return result;
}
#endregion
tree related methods#region tree related methods
public static void AddRoot(ArticleClassInf node)
{
node.ParentID = Guid.Empty;
ArticleClassManager_Base.Insert(node);
}
public static ArticleClassInf GetByFullName( string fullName)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += "[dbo].A_ArticleClass_GetFullName(";
whereSql += "ID";
whereSql += string.Format(")='{0}'",fullName);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static ArticleClassInf GetByFullID( string fullID)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += "[dbo].A_ArticleClass_GetFullID(";
whereSql += "ID";
whereSql += string.Format(")='{0}'",fullID);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetRoots()
{
DataTable result;
SqlHelper helper = KeyssConfig.DatabaseHelper;
string SelectSql = "Select * from A_ArticleClass where ParentID is null";
result =helper.ExecuteQuery(SelectSql);
return result;
}
public static int GetMaxLevel()
{
int result;
string paraStr = "Select [dbo].A_ArticleClass_GetMaxLevel(";
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(int)helper.ExecuteScalar(paraStr);
return result;
}
public static void CopyChildren(Guid iD,Guid fromID)
{
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@FromID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = fromID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_CopyChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static DataTable GetChildren(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static DataTable GetNonChildren(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetNonChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static DataTable GetParents(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetParents",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static void MoveTo(Guid iD,Guid newParentID)
{
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@NewParentID",System.Data.SqlDbType.UniqueIdentifier);
if(newParentID==Guid.Empty)
{
para.Value = System.DBNull.Value;
}else
{
para.Value = newParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_MoveTo",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
#endregion
}
#endregion
ArticleInf#region ArticleInf
public class ArticleInf
{
protected fields#region protected fields
protected Guid _iD = Guid.Empty;
protected Guid _articleClassID = Guid.Empty;
protected string _title = String.Empty;
protected string _content = String.Empty;
protected bool _isNew;
protected bool _isTop;
protected int _orderBy;
protected string _imgUrl = String.Empty;
protected DateTime _createTime;
protected string _userName = String.Empty;
protected string _author = String.Empty;
protected string _keywords = String.Empty;
#endregion
public properties#region public properties
public Guid ID
{
get {return _iD;}
set {_iD = value;}
}
public Guid ArticleClassID
{
get {return _articleClassID;}
set {_articleClassID = value;}
}
public string Title
{
get {return _title;}
set {_title = value;}
}
public string Content
{
get {return _content;}
set {_content = value;}
}
public bool IsNew
{
get {return _isNew;}
set {_isNew = value;}
}
public bool IsTop
{
get {return _isTop;}
set {_isTop = value;}
}
public int OrderBy
{
get {return _orderBy;}
set {_orderBy = value;}
}
public string ImgUrl
{
get {return _imgUrl;}
set {_imgUrl = value;}
}
public DateTime CreateTime
{
get {return _createTime;}
set {_createTime = value;}
}
public string UserName
{
get {return _userName;}
set {_userName = value;}
}
public string Author
{
get {return _author;}
set {_author = value;}
}
public string Keywords
{
get {return _keywords;}
set {_keywords = value;}
}
#endregion
public methods#region public methods
public virtual void Populate(System.Data.SqlClient.SqlDataReader reader)
{
try
{
_iD = reader.GetGuid(0);
_articleClassID = reader.GetGuid(1);
_title = reader.GetString(2);
_content = reader.GetString(3);
_isNew = reader.GetBoolean(4);
_isTop = reader.GetBoolean(5);
_orderBy = reader.GetInt32(6);
_imgUrl = reader.GetString(7);
_createTime = reader.GetDateTime(8);
_userName = reader.GetString(9);
_author = reader.GetString(10);
_keywords = reader.GetString(11);
}
catch
{
throw new FormatException("DataReader format error!");
}
}
public virtual void Populate(DataRow row)
{
try
{
_iD = (Guid)row[0];
_articleClassID = (Guid)row[1];
_title = (string)row[2];
_content = (string)row[3];
_isNew = (bool)row[4];
_isTop = (bool)row[5];
_orderBy = (int)row[6];
_imgUrl = (string)row[7];
_createTime = (DateTime)row[8];
_userName = (string)row[9];
_author = (string)row[10];
_keywords = (string)row[11];
}
catch
{
throw new FormatException("DataRow format error!");
}
}
#endregion
}
#endregion
ArticleManager_Base#region ArticleManager_Base
public class ArticleManager_Base
{
Insert Update Delete#region Insert Update Delete
public static void Insert(ArticleInf articleInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[14];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ArticleClassID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ArticleClassID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Title",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Title;
para.Size = 256;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Content",System.Data.SqlDbType.NText);
para.Value = articleInf.Content;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@IsNew",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsNew;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@IsTop",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsTop;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleInf.OrderBy;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.ImgUrl;
para.Size = 128;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@CreateTime",System.Data.SqlDbType.DateTime);
para.Value = articleInf.CreateTime;
paras[8] = para;
para = new System.Data.SqlClient.SqlParameter("@UserName",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.UserName;
para.Size = 64;
paras[9] = para;
para = new System.Data.SqlClient.SqlParameter("@Author",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Author;
para.Size = 16;
paras[10] = para;
para = new System.Data.SqlClient.SqlParameter("@Keywords",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Keywords;
para.Size = 256;
paras[11] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 0;
paras[12] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[13] = para;
helper.Open();
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
SqlHelper.ThrowSQLError((int)paras[13].Value);
throw new Exception("The inserted record in the table 'A_Article' can't been selected! ");
}
articleInf.Populate(RD);
RD.Close();
helper.Close();
}
public static void Delete(Guid iD)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 1;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static void Update(ArticleInf articleInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[14];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ArticleClassID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ArticleClassID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Title",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Title;
para.Size = 256;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Content",System.Data.SqlDbType.NText);
para.Value = articleInf.Content;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@IsNew",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsNew;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@IsTop",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsTop;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleInf.OrderBy;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.ImgUrl;
para.Size = 128;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@CreateTime",System.Data.SqlDbType.DateTime);
para.Value = articleInf.CreateTime;
paras[8] = para;
para = new System.Data.SqlClient.SqlParameter("@UserName",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.UserName;
para.Size = 64;
paras[9] = para;
para = new System.Data.SqlClient.SqlParameter("@Author",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Author;
para.Size = 16;
paras[10] = para;
para = new System.Data.SqlClient.SqlParameter("@Keywords",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Keywords;
para.Size = 256;
paras[11] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 2;
paras[12] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[13] = para;
helper.ExecuteNonQuery("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[13].Value);
}
#endregion
Select#region Select
public static bool CheckByID(Guid iD)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleInf GetByID(Guid iD)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_Article' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static bool CheckByArticleClassIDAndTitle(Guid articleClassID,string title)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ArticleClassID = '{0}'",articleClassID);
whereSql += " AND " + string.Format("Title = '{0}'",title);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleInf GetByArticleClassIDAndTitle(Guid articleClassID,string title)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ArticleClassID = '{0}'",articleClassID);
whereSql += " AND " + string.Format("Title = '{0}'",title);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_Article' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetAll(string fieldsName, string whereSql, string orderBy)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
result =helper.ExecuteQuery("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
helper.Close();
return result;
}
public static DataTable GetPageData(string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[6];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
string[] newfieldnames = fieldsName.ToUpper().Split(',');
fieldsName = "";
for(int i=0;i<newfieldnames.Length;i++)
{
if(!newfieldnames[i].Trim().StartsWith("A."))
fieldsName += "A.";
fieldsName += newfieldnames[i];
if(i!=newfieldnames.Length -1)
fieldsName += ", ";
}
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@RecordCount",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.Output;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@PageIndex",System.Data.SqlDbType.Int);
para.Value = pageIndex;
para.Direction = System.Data.ParameterDirection.InputOutput;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@PageSize",System.Data.SqlDbType.Int);
para.Value = pageSize;
paras[5] = para;
result =helper.ExecuteQuery("A_Article_GetPageData",System.Data.CommandType.StoredProcedure,paras);
pageIndex = (int)paras[4].Value;
recordCount = (int)paras[3].Value;
helper.Close();
return result;
}
public static DataTable GetAllByArticleClassID(Guid articleClassID, string fieldsName, string whereSql, string orderBy)
{
string whereSql1 = "";
whereSql1 += string.Format("ArticleClassID = '{0}'",articleClassID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetAll(fieldsName, whereSql1, orderBy);
}
public static DataTable GetPageDataByArticleClassID(Guid articleClassID, string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
string whereSql1 = "";
whereSql1 += string.Format("ArticleClassID = '{0}'",articleClassID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetPageData(fieldsName, whereSql1, orderBy,out recordCount, ref pageIndex, pageSize);
}
#endregion
Other method#region Other method
public static int GetRecordNumber(string whereSql)
{
int result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "Count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
result =(int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return result;
}
#endregion
}
#endregion
}
using System.Data;
using Keyss.Framework;
namespace Keyss.Framework
{
ArticleClassInf#region ArticleClassInf
public class ArticleClassInf
{
protected fields#region protected fields
protected Guid _iD = Guid.Empty;
protected Guid _parentID = Guid.Empty;
protected string _name = String.Empty;
protected string _description = String.Empty;
protected int _orderBy;
protected string _imgUrl = String.Empty;
protected string _iconUrl = String.Empty;
#endregion
public properties#region public properties
public Guid ID
{
get {return _iD;}
set {_iD = value;}
}
public Guid ParentID
{
get {return _parentID;}
set {_parentID = value;}
}
public string Name
{
get {return _name;}
set {_name = value;}
}
public string Description
{
get {return _description;}
set {_description = value;}
}
public int OrderBy
{
get {return _orderBy;}
set {_orderBy = value;}
}
public string ImgUrl
{
get {return _imgUrl;}
set {_imgUrl = value;}
}
public string IconUrl
{
get {return _iconUrl;}
set {_iconUrl = value;}
}
#endregion
public methods#region public methods
public virtual void Populate(System.Data.SqlClient.SqlDataReader reader)
{
try
{
_iD = reader.GetGuid(0);
if (!reader.IsDBNull(1))
_parentID = reader.GetGuid(1);
else
_parentID = Guid.Empty;
_name = reader.GetString(2);
_description = reader.GetString(3);
_orderBy = reader.GetInt32(4);
_imgUrl = reader.GetString(5);
_iconUrl = reader.GetString(6);
}
catch
{
throw new FormatException("DataReader format error!");
}
}
public virtual void Populate(DataRow row)
{
try
{
_iD = (Guid)row[0];
if(!(row[1] is DBNull))
_parentID = (Guid)row[1];
else
_parentID = Guid.Empty;
_name = (string)row[2];
_description = (string)row[3];
_orderBy = (int)row[4];
_imgUrl = (string)row[5];
_iconUrl = (string)row[6];
}
catch
{
throw new FormatException("DataRow format error!");
}
}
#endregion
}
#endregion
ArticleClassManager_Base#region ArticleClassManager_Base
public class ArticleClassManager_Base
{
Insert Update Delete#region Insert Update Delete
public static void Insert(ArticleClassInf articleClassInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[9];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleClassInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ParentID",System.Data.SqlDbType.UniqueIdentifier);
if(articleClassInf.ParentID == Guid.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = articleClassInf.ParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Name",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.Name;
para.Size = 128;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Description",System.Data.SqlDbType.NText);
para.Value = articleClassInf.Description;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleClassInf.OrderBy;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.ImgUrl;
para.Size = 128;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@IconUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.IconUrl;
para.Size = 128;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 0;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[8] = para;
helper.Open();
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
SqlHelper.ThrowSQLError((int)paras[8].Value);
throw new Exception("The inserted record in the table 'A_ArticleClass' can't been selected! ");
}
articleClassInf.Populate(RD);
RD.Close();
helper.Close();
}
public static void Delete(Guid iD)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 1;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static void Update(ArticleClassInf articleClassInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[9];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleClassInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ParentID",System.Data.SqlDbType.UniqueIdentifier);
if(articleClassInf.ParentID == Guid.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = articleClassInf.ParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Name",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.Name;
para.Size = 128;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Description",System.Data.SqlDbType.NText);
para.Value = articleClassInf.Description;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleClassInf.OrderBy;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.ImgUrl;
para.Size = 128;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@IconUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleClassInf.IconUrl;
para.Size = 128;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 2;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[8] = para;
helper.ExecuteNonQuery("A_ArticleClass_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[8].Value);
}
#endregion
Select#region Select
public static bool CheckByID(Guid iD)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleClassInf GetByID(Guid iD)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static bool CheckByParentIDAndName(Guid parentID,string name)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
if(parentID==Guid.Empty)
whereSql += "ParentID is Null";
else
whereSql += string.Format("ParentID = '{0}'",parentID);
whereSql += " AND " + string.Format("Name = '{0}'",name);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleClassInf GetByParentIDAndName(Guid parentID,string name)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
if(parentID==Guid.Empty)
whereSql += "ParentID is Null";
else
whereSql += string.Format("ParentID = '{0}'",parentID);
whereSql += " AND " + string.Format("Name = '{0}'",name);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetAll(string fieldsName, string whereSql, string orderBy)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
helper.Close();
return result;
}
public static DataTable GetPageData(string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[6];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
string[] newfieldnames = fieldsName.ToUpper().Split(',');
fieldsName = "";
for(int i=0;i<newfieldnames.Length;i++)
{
if(!newfieldnames[i].Trim().StartsWith("A."))
fieldsName += "A.";
fieldsName += newfieldnames[i];
if(i!=newfieldnames.Length -1)
fieldsName += ", ";
}
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@RecordCount",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.Output;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@PageIndex",System.Data.SqlDbType.Int);
para.Value = pageIndex;
para.Direction = System.Data.ParameterDirection.InputOutput;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@PageSize",System.Data.SqlDbType.Int);
para.Value = pageSize;
paras[5] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetPageData",System.Data.CommandType.StoredProcedure,paras);
pageIndex = (int)paras[4].Value;
recordCount = (int)paras[3].Value;
helper.Close();
return result;
}
public static DataTable GetAllByParentID(Guid parentID, string fieldsName, string whereSql, string orderBy)
{
string whereSql1 = "";
if(parentID==Guid.Empty)
whereSql1 += "ParentID is Null";
else
whereSql1 += string.Format("ParentID = '{0}'",parentID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetAll(fieldsName, whereSql1, orderBy);
}
public static DataTable GetPageDataByParentID(Guid parentID, string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
string whereSql1 = "";
if(parentID==Guid.Empty)
whereSql1 += "ParentID is Null";
else
whereSql1 += string.Format("ParentID = '{0}'",parentID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetPageData(fieldsName, whereSql1, orderBy,out recordCount, ref pageIndex, pageSize);
}
#endregion
Other method#region Other method
public static int GetRecordNumber(string whereSql)
{
int result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "Count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
result =(int)helper.ExecuteScalar("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
return result;
}
#endregion
tree related methods#region tree related methods
public static void AddRoot(ArticleClassInf node)
{
node.ParentID = Guid.Empty;
ArticleClassManager_Base.Insert(node);
}
public static ArticleClassInf GetByFullName( string fullName)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += "[dbo].A_ArticleClass_GetFullName(";
whereSql += "ID";
whereSql += string.Format(")='{0}'",fullName);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static ArticleClassInf GetByFullID( string fullID)
{
ArticleClassInf result = new ArticleClassInf();
string whereSql = "";
whereSql += "[dbo].A_ArticleClass_GetFullID(";
whereSql += "ID";
whereSql += string.Format(")='{0}'",fullID);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_ArticleClass_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_ArticleClass' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetRoots()
{
DataTable result;
SqlHelper helper = KeyssConfig.DatabaseHelper;
string SelectSql = "Select * from A_ArticleClass where ParentID is null";
result =helper.ExecuteQuery(SelectSql);
return result;
}
public static int GetMaxLevel()
{
int result;
string paraStr = "Select [dbo].A_ArticleClass_GetMaxLevel(";
paraStr += ")";
SqlHelper helper = KeyssConfig.DatabaseHelper;
result =(int)helper.ExecuteScalar(paraStr);
return result;
}
public static void CopyChildren(Guid iD,Guid fromID)
{
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@FromID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = fromID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_CopyChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static DataTable GetChildren(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static DataTable GetNonChildren(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetNonChildren",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static DataTable GetParents(Guid iD)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[1] = para;
result =helper.ExecuteQuery("A_ArticleClass_GetParents",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[1].Value);
return result;
}
public static void MoveTo(Guid iD,Guid newParentID)
{
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@NewParentID",System.Data.SqlDbType.UniqueIdentifier);
if(newParentID==Guid.Empty)
{
para.Value = System.DBNull.Value;
}else
{
para.Value = newParentID;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_ArticleClass_MoveTo",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
#endregion
}
#endregion
ArticleInf#region ArticleInf
public class ArticleInf
{
protected fields#region protected fields
protected Guid _iD = Guid.Empty;
protected Guid _articleClassID = Guid.Empty;
protected string _title = String.Empty;
protected string _content = String.Empty;
protected bool _isNew;
protected bool _isTop;
protected int _orderBy;
protected string _imgUrl = String.Empty;
protected DateTime _createTime;
protected string _userName = String.Empty;
protected string _author = String.Empty;
protected string _keywords = String.Empty;
#endregion
public properties#region public properties
public Guid ID
{
get {return _iD;}
set {_iD = value;}
}
public Guid ArticleClassID
{
get {return _articleClassID;}
set {_articleClassID = value;}
}
public string Title
{
get {return _title;}
set {_title = value;}
}
public string Content
{
get {return _content;}
set {_content = value;}
}
public bool IsNew
{
get {return _isNew;}
set {_isNew = value;}
}
public bool IsTop
{
get {return _isTop;}
set {_isTop = value;}
}
public int OrderBy
{
get {return _orderBy;}
set {_orderBy = value;}
}
public string ImgUrl
{
get {return _imgUrl;}
set {_imgUrl = value;}
}
public DateTime CreateTime
{
get {return _createTime;}
set {_createTime = value;}
}
public string UserName
{
get {return _userName;}
set {_userName = value;}
}
public string Author
{
get {return _author;}
set {_author = value;}
}
public string Keywords
{
get {return _keywords;}
set {_keywords = value;}
}
#endregion
public methods#region public methods
public virtual void Populate(System.Data.SqlClient.SqlDataReader reader)
{
try
{
_iD = reader.GetGuid(0);
_articleClassID = reader.GetGuid(1);
_title = reader.GetString(2);
_content = reader.GetString(3);
_isNew = reader.GetBoolean(4);
_isTop = reader.GetBoolean(5);
_orderBy = reader.GetInt32(6);
_imgUrl = reader.GetString(7);
_createTime = reader.GetDateTime(8);
_userName = reader.GetString(9);
_author = reader.GetString(10);
_keywords = reader.GetString(11);
}
catch
{
throw new FormatException("DataReader format error!");
}
}
public virtual void Populate(DataRow row)
{
try
{
_iD = (Guid)row[0];
_articleClassID = (Guid)row[1];
_title = (string)row[2];
_content = (string)row[3];
_isNew = (bool)row[4];
_isTop = (bool)row[5];
_orderBy = (int)row[6];
_imgUrl = (string)row[7];
_createTime = (DateTime)row[8];
_userName = (string)row[9];
_author = (string)row[10];
_keywords = (string)row[11];
}
catch
{
throw new FormatException("DataRow format error!");
}
}
#endregion
}
#endregion
ArticleManager_Base#region ArticleManager_Base
public class ArticleManager_Base
{
Insert Update Delete#region Insert Update Delete
public static void Insert(ArticleInf articleInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[14];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ArticleClassID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ArticleClassID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Title",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Title;
para.Size = 256;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Content",System.Data.SqlDbType.NText);
para.Value = articleInf.Content;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@IsNew",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsNew;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@IsTop",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsTop;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleInf.OrderBy;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.ImgUrl;
para.Size = 128;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@CreateTime",System.Data.SqlDbType.DateTime);
para.Value = articleInf.CreateTime;
paras[8] = para;
para = new System.Data.SqlClient.SqlParameter("@UserName",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.UserName;
para.Size = 64;
paras[9] = para;
para = new System.Data.SqlClient.SqlParameter("@Author",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Author;
para.Size = 16;
paras[10] = para;
para = new System.Data.SqlClient.SqlParameter("@Keywords",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Keywords;
para.Size = 256;
paras[11] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 0;
paras[12] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[13] = para;
helper.Open();
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
SqlHelper.ThrowSQLError((int)paras[13].Value);
throw new Exception("The inserted record in the table 'A_Article' can't been selected! ");
}
articleInf.Populate(RD);
RD.Close();
helper.Close();
}
public static void Delete(Guid iD)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = iD;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 1;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[2] = para;
helper.ExecuteNonQuery("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[2].Value);
}
public static void Update(ArticleInf articleInf)
{
SqlHelper helper = KeyssConfig.DatabaseHelper;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[14];
System.Data.SqlClient.SqlParameter para;
para = new System.Data.SqlClient.SqlParameter("@ID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ID;
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@ArticleClassID",System.Data.SqlDbType.UniqueIdentifier);
para.Value = articleInf.ArticleClassID;
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@Title",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Title;
para.Size = 256;
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@Content",System.Data.SqlDbType.NText);
para.Value = articleInf.Content;
para.Size = 1073741823;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@IsNew",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsNew;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@IsTop",System.Data.SqlDbType.Bit);
para.Value = articleInf.IsTop;
paras[5] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.Int);
para.Value = articleInf.OrderBy;
paras[6] = para;
para = new System.Data.SqlClient.SqlParameter("@ImgUrl",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.ImgUrl;
para.Size = 128;
paras[7] = para;
para = new System.Data.SqlClient.SqlParameter("@CreateTime",System.Data.SqlDbType.DateTime);
para.Value = articleInf.CreateTime;
paras[8] = para;
para = new System.Data.SqlClient.SqlParameter("@UserName",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.UserName;
para.Size = 64;
paras[9] = para;
para = new System.Data.SqlClient.SqlParameter("@Author",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Author;
para.Size = 16;
paras[10] = para;
para = new System.Data.SqlClient.SqlParameter("@Keywords",System.Data.SqlDbType.NVarChar);
para.Value = articleInf.Keywords;
para.Size = 256;
paras[11] = para;
para = new System.Data.SqlClient.SqlParameter("@Action",System.Data.SqlDbType.Int);
para.Value = 2;
paras[12] = para;
para = new System.Data.SqlClient.SqlParameter("@ReturnValue",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.ReturnValue;
paras[13] = para;
helper.ExecuteNonQuery("A_Article_InsertDeleteUpdate",System.Data.CommandType.StoredProcedure,paras);
SqlHelper.ThrowSQLError((int)paras[13].Value);
}
#endregion
Select#region Select
public static bool CheckByID(Guid iD)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleInf GetByID(Guid iD)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ID = '{0}'",iD);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_Article' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static bool CheckByArticleClassIDAndTitle(Guid articleClassID,string title)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ArticleClassID = '{0}'",articleClassID);
whereSql += " AND " + string.Format("Title = '{0}'",title);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
int foundNumber = (int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return (foundNumber==1)?true:false;
}
public static ArticleInf GetByArticleClassIDAndTitle(Guid articleClassID,string title)
{
ArticleInf result = new ArticleInf();
string whereSql = "";
whereSql += string.Format("ArticleClassID = '{0}'",articleClassID);
whereSql += " AND " + string.Format("Title = '{0}'",title);
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[1];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[0] = para;
System.Data.SqlClient.SqlDataReader RD
= helper.ExecuteReader("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
if(!RD.Read())
{
throw new Exception("The record in the table 'A_Article' doesn't exist! ");
}
result.Populate(RD);
RD.Close();
helper.Close();
return result;
}
public static DataTable GetAll(string fieldsName, string whereSql, string orderBy)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[3];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
result =helper.ExecuteQuery("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
helper.Close();
return result;
}
public static DataTable GetPageData(string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
DataTable result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[6];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
helper.Open();
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
if((fieldsName==null)||fieldsName.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
string[] newfieldnames = fieldsName.ToUpper().Split(',');
fieldsName = "";
for(int i=0;i<newfieldnames.Length;i++)
{
if(!newfieldnames[i].Trim().StartsWith("A."))
fieldsName += "A.";
fieldsName += newfieldnames[i];
if(i!=newfieldnames.Length -1)
fieldsName += ", ";
}
para.Value = fieldsName;
}
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
if((whereSql==null)||whereSql.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = whereSql;
}
paras[1] = para;
para = new System.Data.SqlClient.SqlParameter("@OrderBy",System.Data.SqlDbType.NVarChar,128);
if((orderBy==null)||orderBy.Trim()==string.Empty)
{
para.Value = System.DBNull.Value;
}
else
{
para.Value = orderBy;
}
paras[2] = para;
para = new System.Data.SqlClient.SqlParameter("@RecordCount",System.Data.SqlDbType.Int);
para.Direction = System.Data.ParameterDirection.Output;
paras[3] = para;
para = new System.Data.SqlClient.SqlParameter("@PageIndex",System.Data.SqlDbType.Int);
para.Value = pageIndex;
para.Direction = System.Data.ParameterDirection.InputOutput;
paras[4] = para;
para = new System.Data.SqlClient.SqlParameter("@PageSize",System.Data.SqlDbType.Int);
para.Value = pageSize;
paras[5] = para;
result =helper.ExecuteQuery("A_Article_GetPageData",System.Data.CommandType.StoredProcedure,paras);
pageIndex = (int)paras[4].Value;
recordCount = (int)paras[3].Value;
helper.Close();
return result;
}
public static DataTable GetAllByArticleClassID(Guid articleClassID, string fieldsName, string whereSql, string orderBy)
{
string whereSql1 = "";
whereSql1 += string.Format("ArticleClassID = '{0}'",articleClassID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetAll(fieldsName, whereSql1, orderBy);
}
public static DataTable GetPageDataByArticleClassID(Guid articleClassID, string fieldsName, string whereSql, string orderBy,out int recordCount, ref int pageIndex, int pageSize)
{
string whereSql1 = "";
whereSql1 += string.Format("ArticleClassID = '{0}'",articleClassID);
if(!((whereSql==null)||whereSql.Trim()==string.Empty))
{
whereSql1 += " AND (" + whereSql + ")";
}
return GetPageData(fieldsName, whereSql1, orderBy,out recordCount, ref pageIndex, pageSize);
}
#endregion
Other method#region Other method
public static int GetRecordNumber(string whereSql)
{
int result;
System.Data.SqlClient.SqlParameter[] paras = new System.Data.SqlClient.SqlParameter[2];
System.Data.SqlClient.SqlParameter para;
SqlHelper helper = KeyssConfig.DatabaseHelper;
para = new System.Data.SqlClient.SqlParameter("@FieldsName",System.Data.SqlDbType.NVarChar,512);
para.Value = "Count(*) as foundNumber";
paras[0] = para;
para = new System.Data.SqlClient.SqlParameter("@Where",System.Data.SqlDbType.NVarChar,512);
para.Value = whereSql;
paras[1] = para;
result =(int)helper.ExecuteScalar("A_Article_GetAll",System.Data.CommandType.StoredProcedure,paras);
return result;
}
#endregion
}
#endregion
}