using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
///
/// 数据访问类:nr_z_hbscd_xm
///
public partial class nr_z_hbscd_xm
{
public nr_z_hbscd_xm()
{}
#region BasicMethod
///
/// 得到最大ID
///
public int GetMaxId()
{
return DbHelperSQL.GetMaxID("id", "nr_z_hbscd_xm");
}
///
/// 是否存在该记录
///
public bool Exists(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) from nr_z_hbscd_xm");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(),parameters);
}
///
/// 增加一条数据
///
public int Add(Maticsoft.Model.nr_z_hbscd_xm model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into nr_z_hbscd_xm(");
strSql.Append("xiangmu,wlbh,czks,czcc,pinshu,zhengse,fanse,taoshu,ysfs,banshu,xzs,ysjf,zdjf,hjxz,dzs,ysjt,bz,scd_id,ps,ddmxid)");
strSql.Append(" values (");
strSql.Append("@xiangmu,@wlbh,@czks,@czcc,@pinshu,@zhengse,@fanse,@taoshu,@ysfs,@banshu,@xzs,@ysjf,@zdjf,@hjxz,@dzs,@ysjt,@bz,@scd_id,@ps,@ddmxid)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@xiangmu", SqlDbType.VarChar,500),
new SqlParameter("@wlbh", SqlDbType.VarChar,500),
new SqlParameter("@czks", SqlDbType.VarChar,50),
new SqlParameter("@czcc", SqlDbType.VarChar,50),
new SqlParameter("@pinshu", SqlDbType.Decimal,9),
new SqlParameter("@zhengse", SqlDbType.VarChar,50),
new SqlParameter("@fanse", SqlDbType.VarChar,50),
new SqlParameter("@taoshu", SqlDbType.Decimal,9),
new SqlParameter("@ysfs", SqlDbType.VarChar,50),
new SqlParameter("@banshu", SqlDbType.Decimal,9),
new SqlParameter("@xzs", SqlDbType.Decimal,9),
new SqlParameter("@ysjf", SqlDbType.Decimal,9),
new SqlParameter("@zdjf", SqlDbType.Decimal,9),
new SqlParameter("@hjxz", SqlDbType.Decimal,9),
new SqlParameter("@dzs", SqlDbType.Decimal,9),
new SqlParameter("@ysjt", SqlDbType.VarChar,50),
new SqlParameter("@bz", SqlDbType.VarChar,1000),
new SqlParameter("@scd_id", SqlDbType.Int,4),
new SqlParameter("@ps", SqlDbType.Int,4),
new SqlParameter("@ddmxid", SqlDbType.Int,4)};
parameters[0].Value = model.xiangmu;
parameters[1].Value = model.wlbh;
parameters[2].Value = model.czks;
parameters[3].Value = model.czcc;
parameters[4].Value = model.pinshu;
parameters[5].Value = model.zhengse;
parameters[6].Value = model.fanse;
parameters[7].Value = model.taoshu;
parameters[8].Value = model.ysfs;
parameters[9].Value = model.banshu;
parameters[10].Value = model.xzs;
parameters[11].Value = model.ysjf;
parameters[12].Value = model.zdjf;
parameters[13].Value = model.hjxz;
parameters[14].Value = model.dzs;
parameters[15].Value = model.ysjt;
parameters[16].Value = model.bz;
parameters[17].Value = model.scd_id;
parameters[18].Value = model.ps;
parameters[19].Value = model.ddmxid;
object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 更新一条数据
///
public bool Update(Maticsoft.Model.nr_z_hbscd_xm model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update nr_z_hbscd_xm set ");
strSql.Append("xiangmu=@xiangmu,");
strSql.Append("wlbh=@wlbh,");
strSql.Append("czks=@czks,");
strSql.Append("czcc=@czcc,");
strSql.Append("pinshu=@pinshu,");
strSql.Append("zhengse=@zhengse,");
strSql.Append("fanse=@fanse,");
strSql.Append("taoshu=@taoshu,");
strSql.Append("ysfs=@ysfs,");
strSql.Append("banshu=@banshu,");
strSql.Append("xzs=@xzs,");
strSql.Append("ysjf=@ysjf,");
strSql.Append("zdjf=@zdjf,");
strSql.Append("hjxz=@hjxz,");
strSql.Append("dzs=@dzs,");
strSql.Append("ysjt=@ysjt,");
strSql.Append("bz=@bz,");
strSql.Append("scd_id=@scd_id,");
strSql.Append("ps=@ps,");
strSql.Append("ddmxid=@ddmxid");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@xiangmu", SqlDbType.VarChar,500),
new SqlParameter("@wlbh", SqlDbType.VarChar,500),
new SqlParameter("@czks", SqlDbType.VarChar,50),
new SqlParameter("@czcc", SqlDbType.VarChar,50),
new SqlParameter("@pinshu", SqlDbType.Decimal,9),
new SqlParameter("@zhengse", SqlDbType.VarChar,50),
new SqlParameter("@fanse", SqlDbType.VarChar,50),
new SqlParameter("@taoshu", SqlDbType.Decimal,9),
new SqlParameter("@ysfs", SqlDbType.VarChar,50),
new SqlParameter("@banshu", SqlDbType.Decimal,9),
new SqlParameter("@xzs", SqlDbType.Decimal,9),
new SqlParameter("@ysjf", SqlDbType.Decimal,9),
new SqlParameter("@zdjf", SqlDbType.Decimal,9),
new SqlParameter("@hjxz", SqlDbType.Decimal,9),
new SqlParameter("@dzs", SqlDbType.Decimal,9),
new SqlParameter("@ysjt", SqlDbType.VarChar,50),
new SqlParameter("@bz", SqlDbType.VarChar,1000),
new SqlParameter("@scd_id", SqlDbType.Int,4),
new SqlParameter("@ps", SqlDbType.Int,4),
new SqlParameter("@ddmxid", SqlDbType.Int,4),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.xiangmu;
parameters[1].Value = model.wlbh;
parameters[2].Value = model.czks;
parameters[3].Value = model.czcc;
parameters[4].Value = model.pinshu;
parameters[5].Value = model.zhengse;
parameters[6].Value = model.fanse;
parameters[7].Value = model.taoshu;
parameters[8].Value = model.ysfs;
parameters[9].Value = model.banshu;
parameters[10].Value = model.xzs;
parameters[11].Value = model.ysjf;
parameters[12].Value = model.zdjf;
parameters[13].Value = model.hjxz;
parameters[14].Value = model.dzs;
parameters[15].Value = model.ysjt;
parameters[16].Value = model.bz;
parameters[17].Value = model.scd_id;
parameters[18].Value = model.ps;
parameters[19].Value = model.ddmxid;
parameters[20].Value = model.id;
int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 删除一条数据
///
public bool Delete(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from nr_z_hbscd_xm ");
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;
}
}
///
/// 批量删除数据
///
public bool DeleteList(string idlist )
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from nr_z_hbscd_xm ");
strSql.Append(" where id in ("+idlist + ") ");
int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 得到一个对象实体
///
public Maticsoft.Model.nr_z_hbscd_xm GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,xiangmu,wlbh,czks,czcc,pinshu,zhengse,fanse,taoshu,ysfs,banshu,xzs,ysjf,zdjf,hjxz,dzs,ysjt,bz,scd_id,ps,ddmxid from nr_z_hbscd_xm ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)
};
parameters[0].Value = id;
Maticsoft.Model.nr_z_hbscd_xm model=new Maticsoft.Model.nr_z_hbscd_xm();
DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
if(ds.Tables[0].Rows.Count>0)
{
return DataRowToModel(ds.Tables[0].Rows[0]);
}
else
{
return null;
}
}
///
/// 得到一个对象实体
///
public Maticsoft.Model.nr_z_hbscd_xm DataRowToModel(DataRow row)
{
Maticsoft.Model.nr_z_hbscd_xm model=new Maticsoft.Model.nr_z_hbscd_xm();
if (row != null)
{
if(row["id"]!=null && row["id"].ToString()!="")
{
model.id=int.Parse(row["id"].ToString());
}
if(row["xiangmu"]!=null)
{
model.xiangmu=row["xiangmu"].ToString();
}
if(row["wlbh"]!=null)
{
model.wlbh=row["wlbh"].ToString();
}
if(row["czks"]!=null)
{
model.czks=row["czks"].ToString();
}
if(row["czcc"]!=null)
{
model.czcc=row["czcc"].ToString();
}
if(row["pinshu"]!=null && row["pinshu"].ToString()!="")
{
model.pinshu=decimal.Parse(row["pinshu"].ToString());
}
if(row["zhengse"]!=null)
{
model.zhengse=row["zhengse"].ToString();
}
if(row["fanse"]!=null)
{
model.fanse=row["fanse"].ToString();
}
if(row["taoshu"]!=null && row["taoshu"].ToString()!="")
{
model.taoshu=decimal.Parse(row["taoshu"].ToString());
}
if(row["ysfs"]!=null)
{
model.ysfs=row["ysfs"].ToString();
}
if(row["banshu"]!=null && row["banshu"].ToString()!="")
{
model.banshu=decimal.Parse(row["banshu"].ToString());
}
if(row["xzs"]!=null && row["xzs"].ToString()!="")
{
model.xzs=decimal.Parse(row["xzs"].ToString());
}
if(row["ysjf"]!=null && row["ysjf"].ToString()!="")
{
model.ysjf=decimal.Parse(row["ysjf"].ToString());
}
if(row["zdjf"]!=null && row["zdjf"].ToString()!="")
{
model.zdjf=decimal.Parse(row["zdjf"].ToString());
}
if(row["hjxz"]!=null && row["hjxz"].ToString()!="")
{
model.hjxz=decimal.Parse(row["hjxz"].ToString());
}
if(row["dzs"]!=null && row["dzs"].ToString()!="")
{
model.dzs=decimal.Parse(row["dzs"].ToString());
}
if(row["ysjt"]!=null)
{
model.ysjt=row["ysjt"].ToString();
}
if(row["bz"]!=null)
{
model.bz=row["bz"].ToString();
}
if(row["scd_id"]!=null && row["scd_id"].ToString()!="")
{
model.scd_id=int.Parse(row["scd_id"].ToString());
}
if(row["ps"]!=null && row["ps"].ToString()!="")
{
model.ps=int.Parse(row["ps"].ToString());
}
if(row["ddmxid"]!=null && row["ddmxid"].ToString()!="")
{
model.ddmxid=int.Parse(row["ddmxid"].ToString());
}
}
return model;
}
///
/// 获得数据列表
///
public DataSet GetList(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select id,xiangmu,wlbh,czks,czcc,pinshu,zhengse,fanse,taoshu,ysfs,banshu,xzs,ysjf,zdjf,hjxz,dzs,ysjt,bz,scd_id,ps,ddmxid ");
strSql.Append(" FROM nr_z_hbscd_xm ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获得前几行数据
///
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,xiangmu,wlbh,czks,czcc,pinshu,zhengse,fanse,taoshu,ysfs,banshu,xzs,ysjf,zdjf,hjxz,dzs,ysjt,bz,scd_id,ps,ddmxid ");
strSql.Append(" FROM nr_z_hbscd_xm ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
///
/// 获取记录总数
///
public int GetRecordCount(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) FROM nr_z_hbscd_xm ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
object obj = DbHelperSQL.GetSingle(strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
///
/// 分页获取数据列表
///
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby );
}
else
{
strSql.Append("order by T.id desc");
}
strSql.Append(")AS Row, T.* from nr_z_hbscd_xm T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return DbHelperSQL.Query(strSql.ToString());
}
/*
///
/// 分页获取数据列表
///
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "nr_z_hbscd_xm";
parameters[1].Value = "id";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
}*/
#endregion BasicMethod
#region ExtensionMethod
#endregion ExtensionMethod
}
}