/// <summary> /// 得到一个对象实体 /// </summary> public DTcms.Model.Card GetModel(int CardId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select CardId, CardCategoryId, Code, CreateDate, StartDate, EndDate "); strSql.Append(" from " + databaseprefix + "Card "); strSql.Append(" where CardId=@CardId"); SqlParameter[] parameters = { new SqlParameter("@CardId", SqlDbType.Int, 4) }; parameters[0].Value = CardId; DTcms.Model.Card model = new DTcms.Model.Card(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CardId"].ToString() != "") { model.CardId = int.Parse(ds.Tables[0].Rows[0]["CardId"].ToString()); } if (ds.Tables[0].Rows[0]["CardCategoryId"].ToString() != "") { model.CardCategoryId = int.Parse(ds.Tables[0].Rows[0]["CardCategoryId"].ToString()); } model.Code = ds.Tables[0].Rows[0]["Code"].ToString(); if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString()); } if (ds.Tables[0].Rows[0]["StartDate"].ToString() != "") { model.StartDate = DateTime.Parse(ds.Tables[0].Rows[0]["StartDate"].ToString()); } if (ds.Tables[0].Rows[0]["EndDate"].ToString() != "") { model.EndDate = DateTime.Parse(ds.Tables[0].Rows[0]["EndDate"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 获得数据列表 /// </summary> public List <DTcms.Model.Card> DataTableToList(DataTable dt) { List <DTcms.Model.Card> modelList = new List <DTcms.Model.Card>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DTcms.Model.Card model; for (int n = 0; n < rowsCount; n++) { model = new DTcms.Model.Card(); if (dt.Rows[n]["CardId"].ToString() != "") { model.CardId = int.Parse(dt.Rows[n]["CardId"].ToString()); } if (dt.Rows[n]["CardCategoryId"].ToString() != "") { model.CardCategoryId = int.Parse(dt.Rows[n]["CardCategoryId"].ToString()); } model.Code = dt.Rows[n]["Code"].ToString(); if (dt.Rows[n]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString()); } if (dt.Rows[n]["StartDate"].ToString() != "") { model.StartDate = DateTime.Parse(dt.Rows[n]["StartDate"].ToString()); } if (dt.Rows[n]["EndDate"].ToString() != "") { model.EndDate = DateTime.Parse(dt.Rows[n]["EndDate"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.Card model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "Card set "); strSql.Append(" CardCategoryId = @CardCategoryId , "); strSql.Append(" Code = @Code , "); strSql.Append(" CreateDate = @CreateDate , "); strSql.Append(" StartDate = @StartDate , "); strSql.Append(" EndDate = @EndDate "); strSql.Append(" where CardId=@CardId "); SqlParameter[] parameters = { new SqlParameter("@CardId", SqlDbType.Int, 4), new SqlParameter("@CardCategoryId", SqlDbType.Int, 4), new SqlParameter("@Code", SqlDbType.VarChar, 50), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@StartDate", SqlDbType.DateTime), new SqlParameter("@EndDate", SqlDbType.DateTime) }; parameters[0].Value = model.CardId; parameters[1].Value = model.CardCategoryId; parameters[2].Value = model.Code; parameters[3].Value = model.CreateDate; parameters[4].Value = model.StartDate; parameters[5].Value = model.EndDate; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.Card model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "Card("); strSql.Append("CardCategoryId,Code,CreateDate,StartDate,EndDate"); strSql.Append(") values ("); strSql.Append("@CardCategoryId,@Code,@CreateDate,@StartDate,@EndDate"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CardCategoryId", SqlDbType.Int, 4), new SqlParameter("@Code", SqlDbType.VarChar, 50), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@StartDate", SqlDbType.DateTime), new SqlParameter("@EndDate", SqlDbType.DateTime) }; parameters[0].Value = model.CardCategoryId; parameters[1].Value = model.Code; parameters[2].Value = model.CreateDate; parameters[3].Value = model.StartDate; parameters[4].Value = model.EndDate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.Card model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.Card model) { return(dal.Add(model)); }