|
|
- using System;
- using System.Data;
- using System.Text;
- using System.Data.SqlClient;
-
- namespace Basic.DAL
- {
- /// <summary>
- /// ���ݷ��ʲ�
- /// </summary>
- public partial class freight
- {
- #region �˴����ɹ�������
-
- /// <summary>
- /// ����һ������
- /// </summary>
- public int Add(Basic.Model.freight model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("insert into tb_freight(");
- strSql.Append("title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time)");
- strSql.Append(" values (");
- strSql.Append("@title,@gudingyf,@yuanmian,@yuanjifei,@jianmian,@jianjifei,@content,@paixu,@state,@add_time)");
- strSql.Append(";select @@IDENTITY");
-
- SqlParameter[] parameters = {
- new SqlParameter("@title", SqlDbType.NVarChar,100),
- new SqlParameter("@gudingyf", SqlDbType.NVarChar,255),
- new SqlParameter("@yuanmian", SqlDbType.NVarChar,255),
- new SqlParameter("@yuanjifei", SqlDbType.NVarChar,255),
- new SqlParameter("@jianmian", SqlDbType.NVarChar,255),
- new SqlParameter("@jianjifei", SqlDbType.NVarChar,255),
- new SqlParameter("@content", SqlDbType.NVarChar,255),
- new SqlParameter("@paixu", SqlDbType.Int,10),
- new SqlParameter("@state", SqlDbType.Int,10),
- new SqlParameter("@add_time", SqlDbType.DateTime,23)};
- parameters[0].Value = model.title;
- parameters[1].Value = model.gudingyf;
- parameters[2].Value = model.yuanmian;
- parameters[3].Value = model.yuanjifei;
- parameters[4].Value = model.jianmian;
- parameters[5].Value = model.jianjifei;
- parameters[6].Value = model.content;
- parameters[7].Value = model.paixu;
- parameters[8].Value = model.state;
- parameters[9].Value = model.add_time;
-
- object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
- if (obj == null)
- {
- return 0;
- }
- else
- {
- return Convert.ToInt32(obj);
- }
- }
-
- /// <summary>
- /// ����һ������
- /// </summary>
- public bool Update(Basic.Model.freight model)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update tb_freight set ");
- strSql.Append("title=@title,");
- strSql.Append("gudingyf=@gudingyf,");
- strSql.Append("yuanmian=@yuanmian,");
- strSql.Append("yuanjifei=@yuanjifei,");
- strSql.Append("jianmian=@jianmian,");
- strSql.Append("jianjifei=@jianjifei,");
- strSql.Append("content=@content,");
- strSql.Append("paixu=@paixu,");
- strSql.Append("state=@state,");
- strSql.Append("add_time=@add_time");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@title", SqlDbType.NVarChar,100),
- new SqlParameter("@gudingyf", SqlDbType.NVarChar,255),
- new SqlParameter("@yuanmian", SqlDbType.NVarChar,255),
- new SqlParameter("@yuanjifei", SqlDbType.NVarChar,255),
- new SqlParameter("@jianmian", SqlDbType.NVarChar,255),
- new SqlParameter("@jianjifei", SqlDbType.NVarChar,255),
- new SqlParameter("@content", SqlDbType.NVarChar,255),
- new SqlParameter("@paixu", SqlDbType.Int,10),
- new SqlParameter("@state", SqlDbType.Int,10),
- new SqlParameter("@add_time", SqlDbType.DateTime,23),
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = model.title;
- parameters[1].Value = model.gudingyf;
- parameters[2].Value = model.yuanmian;
- parameters[3].Value = model.yuanjifei;
- parameters[4].Value = model.jianmian;
- parameters[5].Value = model.jianjifei;
- parameters[6].Value = model.content;
- parameters[7].Value = model.paixu;
- parameters[8].Value = model.state;
- parameters[9].Value = model.add_time;
- parameters[10].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_freight");
- 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 Basic.Model.freight GetModel(int id)
- {
- StringBuilder strSql=new StringBuilder();
- strSql.Append("select top 1 id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
- strSql.Append(" where id=@id");
- SqlParameter[] parameters = {
- new SqlParameter("@id", SqlDbType.Int,4)};
- parameters[0].Value = id;
- Basic.Model.freight model = new Basic.Model.freight();
- 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]["title"].ToString()))
- {
- model.title = ds.Tables[0].Rows[0]["title"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gudingyf"].ToString()))
- {
- model.gudingyf = ds.Tables[0].Rows[0]["gudingyf"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanmian"].ToString()))
- {
- model.yuanmian = ds.Tables[0].Rows[0]["yuanmian"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanjifei"].ToString()))
- {
- model.yuanjifei = ds.Tables[0].Rows[0]["yuanjifei"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianmian"].ToString()))
- {
- model.jianmian = ds.Tables[0].Rows[0]["jianmian"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianjifei"].ToString()))
- {
- model.jianjifei = ds.Tables[0].Rows[0]["jianjifei"].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]["state"].ToString()))
- {
- model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
- {
- model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
- }
- return model;
- }
- else
- {
- return null;
- }
- }
-
- /// <summary>
- /// �õ�һ������ʵ��
- /// </summary>
- public Basic.Model.freight GetModelByState()
- {
- StringBuilder strSql=new StringBuilder();
- strSql.Append("select top 1 id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
- strSql.Append(" where state=@state");
- SqlParameter[] parameters =
- {
- new SqlParameter("@state", SqlDbType.Int,4)};
- parameters[0].Value = 0;
- Basic.Model.freight model = new Basic.Model.freight();
- 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]["title"].ToString()))
- {
- model.title = ds.Tables[0].Rows[0]["title"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gudingyf"].ToString()))
- {
- model.gudingyf = ds.Tables[0].Rows[0]["gudingyf"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanmian"].ToString()))
- {
- model.yuanmian = ds.Tables[0].Rows[0]["yuanmian"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanjifei"].ToString()))
- {
- model.yuanjifei = ds.Tables[0].Rows[0]["yuanjifei"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianmian"].ToString()))
- {
- model.jianmian = ds.Tables[0].Rows[0]["jianmian"].ToString();
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianjifei"].ToString()))
- {
- model.jianjifei = ds.Tables[0].Rows[0]["jianjifei"].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]["state"].ToString()))
- {
- model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
- }
- if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
- {
- model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
- }
- return model;
- }
- else
- {
- return null;
- }
- }
-
- /// <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,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time");
- strSql.Append(" from tb_freight");
- if (strWhere.Trim() != "")
- {
- strSql.Append(" where " + strWhere);
- }
- strSql.Append(" order by " + filedOrder);
- return DbHelperSQL.Query(strSql.ToString());
- }
-
-
- /// <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 + " id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
- 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_freight ");
- 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_freight", 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_freight where " + strSql);
- if (myread.Read())
- {
- intTotal = Convert.ToInt32(myread["CountId"].ToString());
- }
- myread.Close();
- return intTotal;
- }
-
- /// <summary>
- /// �Ƿ����ڸü�¼
- /// </summary>
- public bool Exists(int id)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("select count(1) from tb_freight");
- 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 void UpdateField(int id, string strValue)
- {
- StringBuilder strSql = new StringBuilder();
- strSql.Append("update tb_freight set " + strValue);
- strSql.Append(" where id=" + id);
- DbHelperSQL.ExecuteSql(strSql.ToString());
- }
-
- #endregion
- }
- }
-
|