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