|
|
- using System;
- using System.Data;
- using System.Text;
- using System.Data.SqlClient;
-
- namespace Basic.DAL
- {
- /// <summary>
- /// ����ֵ
- /// </summary>
- public partial class attribute_value
- {
- /// <summary>
- /// ����һ������
- /// </summary>
- public int Add(Basic.Model.attribute_value model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("insert into tb_attribute_value(");
- strSql.Append("class_id,parent_id,guid,title,path,content,paixu,status)");
- strSql.Append(" values (");
- strSql.Append("@class_id,@parent_id,@guid,@title,@path,@content,@paixu,@status)");
- strSql.Append(";select @@IDENTITY");
-
- SqlParameter[] parameters = {
- new SqlParameter("@class_id", SqlDbType.Int,10),
- new SqlParameter("@parent_id", SqlDbType.Int,10),
- new SqlParameter("@guid", SqlDbType.NVarChar,50),
- new SqlParameter("@title", SqlDbType.NVarChar,100),
- new SqlParameter("@path", SqlDbType.NVarChar,255),
- new SqlParameter("@content", SqlDbType.NVarChar,255),
- new SqlParameter("@paixu", SqlDbType.Int,10),
- new SqlParameter("@status", SqlDbType.Int,10)};
- parameters[0].Value = model.class_id;
- parameters[1].Value = model.parent_id;
- parameters[2].Value = model.guid;
- parameters[3].Value = model.title;
- parameters[4].Value = model.path;
- parameters[5].Value = model.content;
- parameters[6].Value = model.paixu;
- parameters[7].Value = model.status;
-
- object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
- if (obj == null)
- {
- return 0;
- }
- else
- {
- return Convert.ToInt32(obj);
- }
- }
-
- /// <summary>
- /// ����һ������
- /// </summary>
- public bool Update(Basic.Model.attribute_value model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update tb_attribute_value set ");
- strSql.Append("class_id=@class_id,");
- strSql.Append("parent_id=@parent_id,");
- strSql.Append("guid=@guid,");
- strSql.Append("title=@title,");
- strSql.Append("path=@path,");
- strSql.Append("content=@content,");
- strSql.Append("paixu=@paixu,");
- strSql.Append("status=@status");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@class_id", SqlDbType.Int,10),
- new SqlParameter("@parent_id", SqlDbType.Int,10),
- new SqlParameter("@guid", SqlDbType.NVarChar,50),
- new SqlParameter("@title", SqlDbType.NVarChar,100),
- new SqlParameter("@path", SqlDbType.NVarChar,255),
- new SqlParameter("@content", SqlDbType.NVarChar,255),
- new SqlParameter("@paixu", SqlDbType.Int,10),
- new SqlParameter("@status", SqlDbType.Int,10),
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = model.class_id;
- parameters[1].Value = model.parent_id;
- parameters[2].Value = model.guid;
- parameters[3].Value = model.title;
- parameters[4].Value = model.path;
- parameters[5].Value = model.content;
- parameters[6].Value = model.paixu;
- parameters[7].Value = model.status;
- parameters[8].Value = model.id;
- int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
- if (rows > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
-
- /// <summary>
- /// ɾ��һ������
- /// </summary>
- public bool Delete(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("delete from tb_attribute_value");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
- int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
- if (rows > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// ɾ��һ������
- /// </summary>
- public bool DeleteByClassId(int class_id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("delete from tb_attribute_value");
- strSql.Append(" where class_id=@class_id");
- SqlParameter[] parameters = {
- new SqlParameter("@class_id", SqlDbType.Int,4)};
- parameters[0].Value = class_id;
- int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
- if (rows > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// �õ�һ������ʵ��
- /// </summary>
- public Basic.Model.attribute_value GetModel(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select top 1 id,class_id,parent_id,guid,title,path,content,paixu,status from tb_attribute_value");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
- Basic.Model.attribute_value model = new Basic.Model.attribute_value();
- DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
- if (ds.Tables[0].Rows.Count > 0)
- {
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
- {
- model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
- {
- model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
- {
- model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
- {
- model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
- {
- model.title = ds.Tables[0].Rows[0]["title"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
- {
- model.path = ds.Tables[0].Rows[0]["path"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
- {
- model.content = ds.Tables[0].Rows[0]["content"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
- {
- model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
- {
- model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
- }
- return model;
- }
- else
- {
- return null;
- }
- }
-
- /// <summary>
- /// �Ƿ����ڸü�¼
- /// </summary>
- public bool Exists(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select count(1) from tb_attribute_value");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
-
- return DbHelperSQL.Exists(strSql.ToString(), parameters);
- }
- /// <summary>
- /// ���ò�ѯ��ҳ����
- /// </summary>
- public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
- {
- BasicPage bp = new BasicPage();
- StringBuilder str_Sql = new StringBuilder();
- str_Sql.Append("select top " + _pageSize + " * from tb_attribute_value");
- str_Sql.Append(" where ");
- str_Sql.Append(_strWhere);
- str_Sql.Append(" and id not in ");
- str_Sql.Append(" ( ");
- str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_attribute_value ");
- str_Sql.Append(" where ");
- str_Sql.Append(_strWhere);
- str_Sql.Append(" order by ");
- str_Sql.Append(_orderby);
- str_Sql.Append(" ) ");
- str_Sql.Append(" order by ");
- str_Sql.Append(_orderby);
- DataSet dst = bp.SelectDataBase("tb_attribute_value", str_Sql.ToString());
- //
- recordCount = totlePage(showTotal(_strWhere), _pageSize);
- return dst;
- }
-
- //��ҳ��
- public int totlePage(int Total, int PageSize)
- {
- if (Total % PageSize == 0)
- {
- return Total / PageSize;
- }
- else
- {
- return Total / PageSize + 1;
- }
- }
-
- //������
- protected int showTotal(string strSql)
- {
- BasicPage bp = new BasicPage();
- int intTotal = 0;
- SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_attribute_value where " + strSql);
- if (myread.Read())
- {
- intTotal = Convert.ToInt32(myread["CountId"].ToString());
- }
- myread.Close();
- return intTotal;
- }
- /// <summary>
- /// ��һ������
- /// </summary>
- public void UpdateField(int id, string strValue)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update tb_attribute_value set " + strValue);
- strSql.Append(" where id=" + id);
- DbHelperSQL.ExecuteSql(strSql.ToString());
- }
- /// <summary>
- /// ����ǰ��������
- /// </summary>
- public DataSet GetList(int Top, string strWhere, string filedOrder)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select ");
- if (Top > 0)
- {
- strSql.Append(" top " + Top.ToString());
- }
- strSql.Append("id,class_id,parent_id,guid,title,path,content,paixu,status");
- strSql.Append(" from tb_attribute_value");
- if (strWhere.Trim() != "")
- {
- strSql.Append(" where " + strWhere);
- }
- strSql.Append(" order by " + filedOrder);
- return DbHelperSQL.Query(strSql.ToString());
- }
-
- }
- }
-
|