📄 dictionarydal.cs
字号:
//------------------------------------*/
//版权所有:杭州商易信息技术有限公司
//功能描述:参数管理
// 作者:沈伟
// 日期:2008/08/25
//------------------------------------*/
using System;
using System.Data;
using System.Text;
using SystemFrameworks;
namespace Itsv.DAL.SystemManage
{
public class dictionaryDAL
{
public dictionaryDAL()
{ }
#region 成员方法
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int dict_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from dictionary where dict_id=" + dict_id + "");
object obj = DbHelperSQL.GetSingle(strSql.ToString());
int cmdresult;
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
{
cmdresult = 0;
}
else
{
cmdresult = int.Parse(obj.ToString());
}
if (cmdresult == 0)
{
return false;
}
else
{
return true;
}
}
public bool Exists(string dict_code)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from dictionary where dict_code='" + dict_code + "'");
object obj = DbHelperSQL.GetSingle(strSql.ToString());
int cmdresult;
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
{
cmdresult = 0;
}
else
{
cmdresult = int.Parse(obj.ToString());
}
if (cmdresult == 0)
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public void Add(Itsv.Model.dictionary model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("declare @a varchar(20)");
strSql.Append("select @a='" + model.dict_code + "'+convert(char(3),right((1000+isnull(max(right(dict_code,3)),0)+1),3)) from dictionary where parent_id=" + model.parent_id);
strSql.Append("insert into dictionary(");
strSql.Append("dict_name,dict_code,dict_order,parent_id,dict_inuse");
strSql.Append(")");
strSql.Append(" values (");
strSql.Append("'" + model.dict_name + "',");
strSql.Append("@a,");
strSql.Append("" + model.dict_order + ",");
strSql.Append("" + model.parent_id + ",");
if (model.dict_inuse)
strSql.Append("1 ");
else
strSql.Append("0 ");
strSql.Append(")");
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 更新一条数据
/// </summary>
public void Update(Itsv.Model.dictionary model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update dictionary set ");
strSql.Append("dict_name='" + model.dict_name + "',");
strSql.Append("dict_code='" + model.dict_code + "',");
strSql.Append("dict_order=" + model.dict_order + ",");
strSql.Append("parent_id=" + model.parent_id + ",");
strSql.Append("dict_inuse= ");
if (model.dict_inuse)
strSql.Append("1 ");
else
strSql.Append("0 ");
strSql.Append(" where dict_id=" + model.dict_id + "");
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 删除一条数据
/// </summary>
public void Delete(int dict_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete dictionary ");
strSql.Append(" where dict_id=" + dict_id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Itsv.Model.dictionary GetModel(string dict_code)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from dictionary ");
strSql.Append(" where dict_code= '" + dict_code + "'");
Itsv.Model.dictionary model = new Itsv.Model.dictionary();
DataSet ds = DbHelperSQL.Query(strSql.ToString());
model.dict_code = dict_code;
if (ds.Tables[0].Rows.Count > 0)
{
model.dict_id = int.Parse(ds.Tables[0].Rows[0]["dict_id"].ToString());
model.dict_name = ds.Tables[0].Rows[0]["dict_name"].ToString();
if (ds.Tables[0].Rows[0]["dict_order"].ToString() != "")
{
model.dict_order = int.Parse(ds.Tables[0].Rows[0]["dict_order"].ToString());
}
if (ds.Tables[0].Rows[0]["parent_id"].ToString() != "")
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (ds.Tables[0].Rows[0]["dict_inuse"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["dict_inuse"].ToString() == "1") || (ds.Tables[0].Rows[0]["dict_inuse"].ToString().ToLower() == "true"))
{
model.dict_inuse = true;
}
else
{
model.dict_inuse = false;
}
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Itsv.Model.dictionary GetModel(int dict_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from dictionary ");
strSql.Append(" where dict_id=" + dict_id);
Itsv.Model.dictionary model = new Itsv.Model.dictionary();
DataSet ds = DbHelperSQL.Query(strSql.ToString());
model.dict_id = dict_id;
if (ds.Tables[0].Rows.Count > 0)
{
model.dict_name = ds.Tables[0].Rows[0]["dict_name"].ToString();
model.dict_code = ds.Tables[0].Rows[0]["dict_code"].ToString();
if (ds.Tables[0].Rows[0]["dict_order"].ToString() != "")
{
model.dict_order = int.Parse(ds.Tables[0].Rows[0]["dict_order"].ToString());
}
if (ds.Tables[0].Rows[0]["parent_id"].ToString() != "")
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (ds.Tables[0].Rows[0]["dict_inuse"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["dict_inuse"].ToString() == "1") || (ds.Tables[0].Rows[0]["dict_inuse"].ToString().ToLower() == "true"))
{
model.dict_inuse = true;
}
else
{
model.dict_inuse = false;
}
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from dictionary ");
strSql.Append(" where dict_inuse = 1 and " + strWhere);
strSql.Append(" order by dict_id desc");
return DbHelperSQL.Query(strSql.ToString());
}
#endregion 成员方法
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -