📄 districtaccess.cs
字号:
using System;
using System.Collections;using Stella.Model;using Stella.Utility;using System.Data;using System.Data.SqlClient;
namespace Stella.SQLServerDAL
{
/// <summary>
/// 执行和区域设置有关的操作
/// </summary>
public class DistrictAccess
{
private string connString=ConfigHelper.ConnString;
#region Remove
/// <summary>
/// 删除区域
/// </summary>
/// <param name="id">该区域的id</param> public void Remove(int id) { SqlParameter[] parms=new SqlParameter[]{ new SqlParameter("@did",SqlDbType.Int,0) }; parms[0].Value=id; SQLHelper.ExecuteNonQuery(connString,CommandType.StoredProcedure,"districts_DeleteBydid",parms); }
#endregion
#region Update
/// <summary>
/// 更新区域的资料
/// </summary>
/// <param name="district">要更新的区域</param> public void Update(District district) { SqlParameter[] parms=this.getUpdateParms(); this.setUpdateParms(parms,district); SQLHelper.ExecuteNonQuery(connString,CommandType.StoredProcedure,"districts_Update",parms); }
private SqlParameter[] getUpdateParms()
{
SqlParameter[] parms=SQLHelper.GetCachedParameters("UpdateDistrict");
if(parms==null)
{
parms=new SqlParameter[]{
new SqlParameter("@did",SqlDbType.Int,0),
new SqlParameter("@dname",SqlDbType.VarChar,20),
new SqlParameter("@comment",SqlDbType.VarChar,100),
new SqlParameter("@lv",SqlDbType.SmallInt,0)
};
SQLHelper.CacheParameters("UpdateDistrict",parms);
}
return parms;
}
private void setUpdateParms(SqlParameter[] parms,District di)
{
parms[0].Value=di.Did;
parms[1].Value=di.Dname;
parms[2].Value=di.Comment;
parms[3].Value=di.Lv;
}
#endregion
#region Create
/// <summary>
/// 创建新区域
/// </summary>
/// <param name="forum">乘有待添加的区域集合</param> public void Create(Forum forum) { SqlParameter[] parms=this.getCreateParms(); using(SqlConnection conn=new SqlConnection(connString)) { foreach(District district in forum.Districts) { this.setCreateParms(parms,district); SQLHelper.ExecuteNonQuery(conn,CommandType.StoredProcedure,"districts_Create",parms); } } }
private SqlParameter[] getCreateParms()
{
SqlParameter[] parms=SQLHelper.GetCachedParameters("CreateDistrict");
if(parms==null)
{
parms=new SqlParameter[]{
new SqlParameter("@dname",SqlDbType.VarChar,20),
new SqlParameter("@comment",SqlDbType.VarChar,100),
new SqlParameter("@lv",SqlDbType.SmallInt,0)
};
SQLHelper.CacheParameters("CreateDistrict",parms);
}
return parms;
}
private void setCreateParms(SqlParameter[] parms,District di)
{
parms[0].Value=di.Dname;
parms[1].Value=di.Comment;
parms[2].Value=di.Lv;
}
#endregion
#region FillWithThemes
/// <summary>
/// 使用版块填充区域
/// </summary>
/// <param name="district">要填充的区域</param>
public void FillWithThemes(District district)
{
SqlParameter[] parms=new SqlParameter[]{ new SqlParameter("@did",SqlDbType.Int,0) }; parms[0].Value=district.Did;
using(SqlDataReader sdr=SQLHelper.ExecuteReader(connString,CommandType.StoredProcedure,"themes_SelectInfoByDid",parms))
{
Theme theme;
while(sdr.Read())
{
theme=new Theme();
theme.Tid=sdr.GetInt32(0);
theme.Tname=sdr.GetString(1);
theme.Comment=sdr.GetString(2);
theme.District=sdr.GetInt32(3);
theme.Lv=sdr.GetInt16(4);
district.AddTheme(theme);
}
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -