大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
Enterprise Library: https://msdn.microsoft.com/en-us/library/ff648951.aspx
/// <summary>
/// 是否存在该记录
/// </summary>
/// <param name="ReportID"></param>
/// <returns></returns>
public bool Exists(string ReportID)
{
Database db = DatabaseFactory.CreateDatabase();
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from BookPlaceList where BookPlaceID=@BookPlaceID ");
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "BookPlaceID", DbType.AnsiString, ReportID);
int cmdresult;
object obj = db.ExecuteScalar(dbCommand);
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>
/// <param name="model"></param>
public int Add(BookPlaceListInfo model)
{
int i=0;
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into BookPlaceList(");
strSql.Append("BookPlaceName,BookPlaceCode,BookPlaceParent)");
strSql.Append(" values (");
strSql.Append("@BookPlaceName,@BookPlaceCode,@BookPlaceParent)");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "BookPlaceName", DbType.String, model.BookPlaceName);
db.AddInParameter(dbCommand, "BookPlaceCode", DbType.String, model.BookPlaceCode);
db.AddInParameter(dbCommand, "BookPlaceParent", DbType.Int32, model.BookPlaceParent);
i=db.ExecuteNonQuery(dbCommand);
return i;
}
/// <summary>
/// 更新一条数据
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public int Update(BookPlaceListInfo model)
{
int i = 0;
StringBuilder strSql = new StringBuilder();
strSql.Append("update BookPlaceList set ");
strSql.Append("BookPlaceName=@BookPlaceName,");
strSql.Append("BookPlaceCode=@BookPlaceCode,");
strSql.Append("BookPlaceParent=@BookPlaceParent,");
strSql.Append(" where BookPlaceID=@BookPlaceID ");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "BookPlaceID", DbType.Int32, model.BookPlaceID);
db.AddInParameter(dbCommand, "BookPlaceName", DbType.String, model.BookPlaceName);
db.AddInParameter(dbCommand, "BookPlaceCode", DbType.String, model.BookPlaceCode);
db.AddInParameter(dbCommand, "BookPlaceParent", DbType.Int32, model.BookPlaceParent);
i= db.ExecuteNonQuery(dbCommand);
return i;
}
/// <summary>
///
/// </summary>
/// <param name="ReportID"></param>
/// <returns></returns>
public int Delete(string ReportID)
{
int i = 0;
StringBuilder strSql = new StringBuilder();
strSql.Append("delete BookPlaceList ");
strSql.Append(" where bookPlaceID=@bookPlaceID ");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "bookPlaceID", DbType.AnsiString, ReportID);
i=db.ExecuteNonQuery(dbCommand);
return i;
}
/// <summary>
/// 获得数据列表
/// </summary>
/// <param name="strWhere"></param>
/// <returns></returns>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM BookPlaceList ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
Database db = DatabaseFactory.CreateDatabase();
return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获得数据列表(比DataSet效率高,推荐使用)
/// using Microsoft.Practices.EnterpriseLibrary.Data;
///using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
/// </summary>
/// <param name="strWhere"></param>
/// <returns></returns>
public List<BookPlaceListInfo> GetListArray(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM BookPlaceList ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
List<BookPlaceListInfo> list = new List<BookPlaceListInfo>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (dataReader.Read())
{
list.Add(ReaderBind(dataReader));
}
}
return list;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public BookPlaceListInfo GetModel(string bookPlaceID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from BookPlaceList ");
strSql.Append(" where bookPlaceID=@bookPlaceID ");
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
db.AddInParameter(dbCommand, "bookPlaceID", DbType.AnsiString, bookPlaceID);
BookPlaceListInfo model = null;
using (IDataReader dataReader = db.ExecuteReader(dbCommand))
{
if (dataReader.Read())
{
model = ReaderBind(dataReader);
}
}
return model;
}
/// <summary>
/// 对象实体绑定数据
/// </summary>
/// <param name="dataReader"></param>
/// <returns></returns>
private BookPlaceListInfo ReaderBind(IDataReader dataReader)
{
BookPlaceListInfo bookPlaceList = new BookPlaceListInfo();
//1.
//object ojb;
//ojb = dataReader["BookPlaceID"];
//if (ojb != null && ojb != DBNull.Value)
//{
// bookPlaceList.BookPlaceID = (int)ojb;
//}
//ojb = dataReader["BookPlaceName"];
//if (ojb != null && ojb != DBNull.Value)
//{
// bookPlaceList.BookPlaceName = (string)ojb;
//}
//2.
bookPlaceList.BookPlaceID = (!object.Equals(dataReader["BookPlaceID"], null)) ? (int)dataReader["BookPlaceID"] : 0;
bookPlaceList.BookPlaceName = (!object.Equals(dataReader["BookPlaceName"], null)) ? (string)dataReader["BookPlaceName"] : "";
bookPlaceList.BookPlaceCode = (!object.Equals(dataReader["BookPlaceCode"], null)) ? (string)dataReader["BookPlaceCode"] : "";
bookPlaceList.BookPlaceParent = (!object.Equals(dataReader["BookPlaceParent"], null)) ? (int)dataReader["BookPlaceParent"] : 0;
return bookPlaceList;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/179901.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...