public QPS.NEW.Model.Trends GetModel(int Id) { QPS.NEW.Model.Trends trends = null; DataTable dt = sqlHelper_.GetDataTable( "select * from Trends where Id=@id", CommandType.Text, new System.Data.SqlClient.SqlParameter[] { new System.Data.SqlClient.SqlParameter("@id", Id) } ); if (dt != null && dt.Rows.Count > 0) { trends = new Model.Trends(); trends.Id = Convert.ToInt32(dt.Rows[0]["Id"]); trends.Title = dt.Rows[0]["Title"].ToString(); trends.Content = dt.Rows[0]["Content"].ToString(); trends.Time = dt.Rows[0]["Time"].ToString(); } return(trends); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string ID = Convert.ToString(Request["id"]); NEW.Model.Trends ts = new QPS.NEW.Model.Trends(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); ts = Bts.GetModel(Convert.ToInt32(ID)); this.txtTitle.Text = ts.Title; this.Content.Text = ts.Content; } }
protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { string ID = Convert.ToString(Request["id"]); NEW.Model.Trends ts = new QPS.NEW.Model.Trends(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); ts = Bts.GetModel(Convert.ToInt32(ID)); this.txtTitle.Text =ts.Title; this.Content.Text=ts.Content; } }
//修改 protected void bntUpdate_Click(object sender, EventArgs e) { string id = Request["ID"].ToString(); string title = this.txtTitle.Text; string con = this.Content.Text; NEW.Model.Trends Mts = new QPS.NEW.Model.Trends(); Mts.Id = Convert.ToInt32(id); Mts.Title = title; Mts.Content = con; Mts.Time = DateTime.Now.ToString(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); if (Bts.Update(Mts)) { Response.Write("<script>alert('修改成功!!');window.location.href = 'TrendsList.aspx';</script>"); } else { Response.Write("<script>alert('修改失败!!');</script>"); } }
//添加 protected void bntInsert_Click(object sender, EventArgs e) { string title = this.txtTitle.Text; string con = this.Content.Text; NEW.Model.Trends Mts = new QPS.NEW.Model.Trends(); Mts.Title = title; Mts.Content = con; Mts.Time = DateTime.Now.ToString(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); int i = Bts.Add(Mts); if (i > 0) { Response.Write("<script>alert('添加成功!!');window.location.href = 'TrendsList.aspx';</script>"); } else { Response.Write("<script>alert('添加失败!!');</script>"); } }
//修改 protected void bntUpdate_Click(object sender, EventArgs e) { string id = Request["ID"].ToString(); string title = this.txtTitle.Text; string con = this.Content.Text; NEW.Model.Trends Mts = new QPS.NEW.Model.Trends(); Mts.Id = Convert.ToInt32(id); Mts.Title=title; Mts.Content = con; Mts.Time = DateTime.Now.ToString(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); if (Bts.Update(Mts)) { Response.Write("<script>alert('修改成功!!');window.location.href = 'TrendsList.aspx';</script>"); } else { Response.Write("<script>alert('修改失败!!');</script>"); } }
//添加 protected void bntInsert_Click(object sender, EventArgs e) { string title = this.txtTitle.Text; string con = this.Content.Text; NEW.Model.Trends Mts = new QPS.NEW.Model.Trends(); Mts.Title = title; Mts.Content = con; Mts.Time = DateTime.Now.ToString(); QPS.NEW.BLL.Trends Bts = new QPS.NEW.BLL.Trends(); int i = Bts.Add(Mts); if (i > 0) { Response.Write("<script>alert('添加成功!!');window.location.href = 'TrendsList.aspx';</script>"); } else { Response.Write("<script>alert('添加失败!!');</script>"); } }
public int Add(QPS.NEW.Model.Trends model) { string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Title != null) { filedName[Count] = "Title"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Title); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.Time != null) { filedName[Count] = "time"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Time); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Trends("); for (int i = 0; i < Count; i++) { strSql.Append(filedName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")values("); for (int i = 0; i < Count; i++) { strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(")"); int res = -1; res = sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams ); if (res != 1) { return(0); } return(1); }
public bool Update(QPS.NEW.Model.Trends model) { bool res = false; string[] filedName = new string[50]; string[] paramName = new string[50]; SqlParameter[] sqlParams = new SqlParameter[50]; int Count = 0; if (model.Id == -999) { return(false); } if (model.Id != -999) { filedName[Count] = "Id"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Id); Count++; } if (model.Title != null) { filedName[Count] = "Title"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Title); Count++; } if (model.Content != null) { filedName[Count] = "Content"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Content); Count++; } if (model.Time != null) { filedName[Count] = "time"; paramName[Count] = "@" + filedName[Count]; sqlParams[Count] = new SqlParameter(paramName[Count], model.Time); Count++; } StringBuilder strSql = new StringBuilder(); strSql.Append("update Trends set "); for (int i = 1; i < Count; i++) { strSql.Append(filedName[i]); strSql.Append("="); strSql.Append(paramName[i]); if (i != Count - 1) { strSql.Append(","); } } strSql.Append(" where "); strSql.Append(filedName[0] + "=" + paramName[0]); int num = Convert.ToInt32(sqlHelper_.ExecuteCommand( strSql.ToString(), CommandType.Text, sqlParams )); if (num != 1) { res = false; } else { res = true; } return(res); }