展开全部
using System;
using System.Data;
using System.Text;
using System.Data.OleDb;
using Maticsoft.IDAL;
using Maticsoft.DBUtility;//请先添加引用
namespace Maticsoft.OleDbDAL
{
///
/// 数据访问类Train。
///
public class Train:ITrain
{
public Train()
{}
#region 成员方法
///
/// 增加一条数据
///
public void Add(Maticsoft.Model.Train model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into Train(");
strSql.Append("ID,P2,P3,P4,Type,Station,S_No,Day,A_Time,D_Time,Distance,P1)");
strSql.Append(" values (");
strSql.Append("@636f707962616964757a686964616f31333238653937ID,@P2,@P3,@P4,@Type,@Station,@S_No,@Day,@A_Time,@D_Time,@Distance,@P1)");
OleDbParameter[] parameters = {
new OleDbParameter("@ID", OleDbType.VarChar,20),
new OleDbParameter("@P2", OleDbType.VarChar,20),
new OleDbParameter("@P3", OleDbType.VarChar,20),
new OleDbParameter("@P4", OleDbType.VarChar,20),
new OleDbParameter("@Type", OleDbType.VarChar,20),
new OleDbParameter("@Station", OleDbType.VarChar,20),
new OleDbParameter("@S_No", OleDbType.VarChar,5),
new OleDbParameter("@Day", OleDbType.VarChar,5),
new OleDbParameter("@A_Time", OleDbType.VarChar,20),
new OleDbParameter("@D_Time", OleDbType.VarChar,20),
new OleDbParameter("@Distance", OleDbType.VarChar,20),
new OleDbParameter("@P1", OleDbType.VarChar,20)};
parameters[0].Value = model.ID;
parameters[1].Value = model.P2;
parameters[2].Value = model.P3;
parameters[3].Value = model.P4;
parameters[4].Value = model.Type;
parameters[5].Value = model.Station;
parameters[6].Value = model.S_No;
parameters[7].Value = model.Day;
parameters[8].Value = model.A_Time;
parameters[9].Value = model.D_Time;
parameters[10].Value = model.Distance;
parameters[11].Value = model.P1;
DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
}
///
/// 更新一条数据
///
public void Update(Maticsoft.Model.Train model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update Train set ");
strSql.Append("ID=@ID,");
strSql.Append("P2=@P2,");
strSql.Append("P3=@P3,");
strSql.Append("P4=@P4,");
strSql.Append("Type=@Type,");
strSql.Append("Station=@Station,");
strSql.Append("S_No=@S_No,");
strSql.Append("Day=@Day,");
strSql.Append("A_Time=@A_Time,");
strSql.Append("D_Time=@D_Time,");
strSql.Append("Distance=@Distance,");
strSql.Append("P1=@P1");
strSql.Append(" where ");
OleDbParameter[] parameters = {
new OleDbParameter("@ID", OleDbType.VarChar,20),
new OleDbParameter("@P2", OleDbType.VarChar,20),
new OleDbParameter("@P3", OleDbType.VarChar,20),
new OleDbParameter("@P4", OleDbType.VarChar,20),
new OleDbParameter("@Type", OleDbType.VarChar,20),
new OleDbParameter("@Station", OleDbType.VarChar,20),
new OleDbParameter("@S_No", OleDbType.VarChar,5),
new OleDbParameter("@Day", OleDbType.VarChar,5),
new OleDbParameter("@A_Time", OleDbType.VarChar,20),
new OleDbParameter("@D_Time", OleDbType.VarChar,20),
new OleDbParameter("@Distance", OleDbType.VarChar,20),
new OleDbParameter("@P1", OleDbType.VarChar,20)};
parameters[0].Value = model.ID;
parameters[1].Value = model.P2;
parameters[2].Value = model.P3;
parameters[3].Value = model.P4;
parameters[4].Value = model.Type;
parameters[5].Value = model.Station;
parameters[6].Value = model.S_No;
parameters[7].Value = model.Day;
parameters[8].Value = model.A_Time;
parameters[9].Value = model.D_Time;
parameters[10].Value = model.Distance;
parameters[11].Value = model.P1;
DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
}
///
/// 删除一条数据
///
public void Delete()
{
//该表无主键信息,请自定义主键/条件字段
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from Train ");
strSql.Append(" where ");
OleDbParameter[] parameters = {
};
DbHelperOleDb.ExecuteSql(strSql.ToString(),parameters);
}
///
/// 得到一个对象实体
///
public Maticsoft.Model.Train GetModel()
{
//该表无主键信息,请自定义主键/条件字段
StringBuilder strSql=new StringBuilder();
strSql.Append("select ID,P2,P3,P4,Type,Station,S_No,Day,A_Time,D_Time,Distance,P1 from Train ");
strSql.Append(" where ");
OleDbParameter[] parameters = {
};
Maticsoft.Model.Train model=new Maticsoft.Model.Train();
DataSet ds=DbHelperOleDb.Query(strSql.ToString(),parameters);
if(ds.Tables[0].Rows.Count>0)
{
model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
model.P2=ds.Tables[0].Rows[0]["P2"].ToString();
model.P3=ds.Tables[0].Rows[0]["P3"].ToString();
model.P4=ds.Tables[0].Rows[0]["P4"].ToString();
model.Type=ds.Tables[0].Rows[0]["Type"].ToString();
model.Station=ds.Tables[0].Rows[0]["Station"].ToString();
model.S_No=ds.Tables[0].Rows[0]["S_No"].ToString();
model.Day=ds.Tables[0].Rows[0]["Day"].ToString();
model.A_Time=ds.Tables[0].Rows[0]["A_Time"].ToString();
model.D_Time=ds.Tables[0].Rows[0]["D_Time"].ToString();
model.Distance=ds.Tables[0].Rows[0]["Distance"].ToString();
model.P1=ds.Tables[0].Rows[0]["P1"].ToString();
return model;
}
else
{
return null;
}
}
///
/// 获得数据列表
///
public DataSet GetList(string strWhere)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select ID,P2,P3,P4,Type,Station,S_No,Day,A_Time,D_Time,Distance,P1 ");
strSql.Append(" FROM Train ");
if(strWhere.Trim()!="")
{
strSql.Append(" where "+strWhere);
}
return DbHelperOleDb.Query(strSql.ToString());
}
/*
///
/// 分页获取数据列表
///
public DataSet GetList(int PageSize,int PageIndex,string strWhere)
{
OleDbParameter[] parameters = {
new OleDbParameter("@tblName", OleDbType.VarChar, 255),
new OleDbParameter("@fldName", OleDbType.VarChar, 255),
new OleDbParameter("@PageSize", OleDbType.Integer),
new OleDbParameter("@PageIndex", OleDbType.Integer),
new OleDbParameter("@IsReCount", OleDbType.Bit),
new OleDbParameter("@OrderType", OleDbType.Bit),
new OleDbParameter("@strWhere", OleDbType.VarChar,1000),
};
parameters[0].Value = "Train";
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 DbHelperOleDb.RunProcedure("UP_GetRecordByPage",parameters,"ds");
}*/
#endregion 成员方法
}
}
已赞过
已踩过<
你对这个回答的评价是?
评论
收起