/// <summary>
/// 数据访问类:hi_test
/// </summary>
public partial class TestDA
{
public TestDA()
{}
#region Method /// <summary>
/// 增加一条数据
/// </summary>
public bool Add(TestEN model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into hi_test(");
strSql.Append("name,showpage,status,create_time)");
strSql.Append(" values (");
strSql.Append("?name,?showpage,?status,?create_time)");
MySqlParameter[] parameters = {
new MySqlParameter("?name", model.Name),
new MySqlParameter("?showpage", model.ShowPage),
new MySqlParameter("?status", model.Status),
new MySqlParameter("?create_time", model.CreateTime)}; int rows = MySqlHelper.ExecuteNonQuery(ConnStrs.AndroidConnStrForWrite, strSql.ToString(), parameters);
if (rows > )
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(TestEN model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update hi_test set ");
strSql.Append("name=?name,");
strSql.Append("showpage=?showpage,");
strSql.Append("status=?status");
strSql.Append("create_time=?create_time");
strSql.Append(" where id=?id");
MySqlParameter[] parameters = {
new MySqlParameter("?name", model.Name),
new MySqlParameter("?showpage",model.ShowPage),
new MySqlParameter("?status", model.Status),
new MySqlParameter("?create_time",model.CreateTime),
new MySqlParameter("?id",model.Id)}; int rows = MySqlHelper.ExecuteNonQuery(ConnStrs.AndroidConnStrForWrite, strSql.ToString(), parameters);
if (rows > )
{
return true;
}
else
{
return false;
}
} /// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int Id)
{ StringBuilder strSql=new StringBuilder();
strSql.Append("delete from hi_test ");
strSql.Append(" where id=?id");
MySqlParameter[] parameters = {
new MySqlParameter("?id",Id)
}; int rows = MySqlHelper.ExecuteNonQuery(ConnStrs.AndroidConnStrForWrite, strSql.ToString(), parameters);
if (rows > )
{
return true;
}
else
{
return false;
}
} public IList<TestEN> Find(int pageIndex, int pageSize, TestEN condition, ref int totalCount)
{
string dataTableKey = "hi_test";
string dataCodeKey = "id";
string selectColumn = " id,name,showpage,status,create_time "; string sortString = " create_time desc "; string searchCondition = " 1=1 ";
if (condition != null)
{
searchCondition += !string.IsNullOrEmpty(condition.Name) ? string.Format(" AND name like ?name escape '^' ") : string.Empty;//模糊匹配
//searchCondition += !string.IsNullOrEmpty(condition.Name) ? string.Format(" AND name=?name ") : string.Empty;//精确匹配
searchCondition += condition.ShowPage != - ? string.Format(" AND showpage={0} ", condition.ShowPage) : string.Empty;
searchCondition += condition.Status != - ? string.Format(" AND status={0} ", condition.Status) : string.Empty;
// searchCondition += condition.CreateTime != -1 ? string.Format(" AND create_time={0} ", condition.CreateTime) : string.Empty;
}
try
{
List<MySqlParameter> parameters = new List<MySqlParameter>();
parameters.Add(new MySqlParameter("name", string.IsNullOrEmpty(condition.Name) ? string.Empty : "%" + condition.Name.Replace("%", "^%").Replace("_", "^_") + "%"));
//parameters.Add(new MySqlParameter("name", string.IsNullOrEmpty(condition.Name) ? string.Empty : condition.Name));
parameters.Add(new MySqlParameter("showpage", condition.ShowPage != - ? condition.ShowPage.ToString() : string.Empty));
parameters.Add(new MySqlParameter("status", condition.Status != - ? condition.Status.ToString() : string.Empty));
// parameters.Add(new MySqlParameter("create_time", condition.CreateTime != -1 ? condition.ShowPage.ToString() : string.Empty));
totalCount = PageAccess.GetItemCount(ConnStrs.AndroidConnStrForWrite, dataTableKey, searchCondition, parameters.ToArray());
if (totalCount > )
{
DataTable dt = PageAccess.GetDataSetByPage(ConnStrs.AndroidConnStrForWrite, pageIndex, pageSize, dataTableKey, selectColumn, dataCodeKey, searchCondition, sortString, parameters.ToArray()).Tables[];
return DataTableToList(dt);
}
}
catch (Exception e)
{
throw e;
}
return null;
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<TestEN> DataTableToList(DataTable dt)
{
List<TestEN> modelList = new List<TestEN>();
int rowsCount = dt.Rows.Count;
if (rowsCount > )
{
TestEN model;
for (int n = ; n < rowsCount; n++)
{
model = BuildEntity(dt.Rows[n]);
modelList.Add(model);
}
}
return modelList;
}
public TestEN BuildEntity(DataRow dr)
{
TestEN model = new TestEN();
if (dr["id"] != null && dr["id"].ToString() != "")
{
model.Id = int.Parse(dr["id"].ToString());
}
if (dr["name"] != null && dr["name"].ToString() != "")
{
model.Name = dr["name"].ToString();
}
if (dr["showpage"] != null && dr["showpage"].ToString() != "")
{
model.ShowPage = int.Parse(dr["showpage"].ToString());
}
if (dr["status"] != null && dr["status"].ToString() != "")
{
model.Status = int.Parse(dr["status"].ToString());
}
if (dr["create_time"] != null && dr["create_time"].ToString() != "")
{
model.CreateTime = int.Parse(dr["create_time"].ToString());
}
return model;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public TestEN GetModel(int Id)
{ StringBuilder strSql=new StringBuilder();
strSql.Append("select id,name,showpage,status,create_time from hi_test ");
strSql.Append(" where id=?id");
MySqlParameter[] parameters = {
new MySqlParameter("?id", Id)
}; TestEN model = new TestEN();
DataSet ds = MySqlHelper.ExecuteDataSet(ConnStrs.AndroidConnStrForWrite, strSql.ToString(), parameters);
if(ds.Tables[].Rows.Count>)
{
model = BuildEntity(ds.Tables[].Rows[]);
return model;
}
else
{
return null;
}
}
#endregion Method
}