/// <summary> /// 更新一条数据 /// </summary> public bool Update(CustomerJPush model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CustomerJPush set "); strSql.Append("CustomerId=@CustomerId,"); strSql.Append("RegId=@RegId,"); strSql.Append("Platform=@Platform,"); strSql.Append("Created=@Created"); strSql.Append(" where Id=@Id"); MySqlParameter[] parameters = { new MySqlParameter("@CustomerId", MySqlDbType.Int32, 11), new MySqlParameter("@RegId", MySqlDbType.VarChar, 200), new MySqlParameter("@Platform", MySqlDbType.VarChar, 2), new MySqlParameter("@Created", MySqlDbType.DateTime), new MySqlParameter("@Id", MySqlDbType.Int32, 11) }; parameters[0].Value = model.CustomerId; parameters[1].Value = model.RegId; parameters[2].Value = model.Platform; parameters[3].Value = model.Created; parameters[4].Value = model.Id; int rows = DbHelperMySql.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(CustomerJPush model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CustomerJPush("); strSql.Append("CustomerId,RegId,Platform,Created)"); strSql.Append(" values ("); strSql.Append("@CustomerId,@RegId,@Platform,@Created)"); MySqlParameter[] parameters = { new MySqlParameter("@CustomerId", MySqlDbType.Int32, 11), new MySqlParameter("@RegId", MySqlDbType.VarChar, 200), new MySqlParameter("@Platform", MySqlDbType.VarChar, 2), new MySqlParameter("@Created", MySqlDbType.DateTime) }; parameters[0].Value = model.CustomerId; parameters[1].Value = model.RegId; parameters[2].Value = model.Platform; parameters[3].Value = model.Created; int rows = DbHelperMySql.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public CustomerJPush DataRowToModel(DataRow row) { CustomerJPush model = new CustomerJPush(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["CustomerId"] != null && row["CustomerId"].ToString() != "") { model.CustomerId = int.Parse(row["CustomerId"].ToString()); } if (row["RegId"] != null) { model.RegId = row["RegId"].ToString(); } if (row["Platform"] != null) { model.Platform = row["Platform"].ToString(); } if (row["Created"] != null && row["Created"].ToString() != "") { model.Created = DateTime.Parse(row["Created"].ToString()); } } return(model); }
/* * /// <summary> * /// 分页获取数据列表 * /// </summary> * public DataSet GetList(int PageSize,int PageIndex,string strWhere) * { * MySqlParameter[] parameters = { * new MySqlParameter("@tblName", MySqlDbType.VarChar, 255), * new MySqlParameter("@fldName", MySqlDbType.VarChar, 255), * new MySqlParameter("@PageSize", MySqlDbType.Int32), * new MySqlParameter("@PageIndex", MySqlDbType.Int32), * new MySqlParameter("@IsReCount", MySqlDbType.Bit), * new MySqlParameter("@OrderType", MySqlDbType.Bit), * new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000), * }; * parameters[0].Value = "CustomerJPush"; * 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 DbHelperMySql.RunProcedure("UP_GetRecordByPage",parameters,"ds"); * }*/ #endregion BasicMethod #region ExtensionMethod public List <CustomerJPush> GetListByCusId(int customerId) { List <CustomerJPush> cjpList = null; string sql = string.Format("SELECT * FROM `CustomerJPush` where CustomerId={0};", customerId); MySqlDataReader reader = null; try { reader = DbHelperMySql.ExecuteReader(sql); if (reader.HasRows) { cjpList = new List <CustomerJPush>(); while (reader.Read()) { CustomerJPush model = new CustomerJPush(); if (reader["Id"] != null && reader["Id"].ToString() != "") { model.Id = int.Parse(reader["Id"].ToString()); } if (reader["CustomerId"] != null && reader["CustomerId"].ToString() != "") { model.CustomerId = int.Parse(reader["CustomerId"].ToString()); } if (reader["RegId"] != null) { model.RegId = reader["RegId"].ToString(); } if (reader["Platform"] != null) { model.Platform = reader["Platform"].ToString(); } if (reader["Created"] != null && reader["Created"].ToString() != "") { model.Created = DateTime.Parse(reader["Created"].ToString()); } cjpList.Add(model); } } } catch (Exception ex) { throw ex; } finally { if (null != reader) { // 关闭reader对象,将自动关闭connection reader.Close(); } } return(cjpList); }