/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.NewsInfo GetModel(int newsId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 NewsId,Title,Author,ClassId,Content,Click,IsLock,IsTop,PubTime from NewsInfo "); strSql.Append(" where NewsID=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = newsId; Cms.Model.NewsInfo model = new Cms.Model.NewsInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["NewsID"] != null && ds.Tables[0].Rows[0]["NewsID"].ToString() != "") { model.NewsID = int.Parse(ds.Tables[0].Rows[0]["NewsID"].ToString()); } if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "") { model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); } if (ds.Tables[0].Rows[0]["Author"] != null && ds.Tables[0].Rows[0]["Author"].ToString() != "") { model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); } if (ds.Tables[0].Rows[0]["ClassId"] != null && ds.Tables[0].Rows[0]["ClassId"].ToString() != "") { model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString()); } if (ds.Tables[0].Rows[0]["Content"] != null && ds.Tables[0].Rows[0]["Content"].ToString() != "") { model.Content = ds.Tables[0].Rows[0]["Content"].ToString(); } if (ds.Tables[0].Rows[0]["Click"] != null && ds.Tables[0].Rows[0]["Click"].ToString() != "") { model.Click = int.Parse(ds.Tables[0].Rows[0]["Click"].ToString()); } if (ds.Tables[0].Rows[0]["IsLock"] != null && ds.Tables[0].Rows[0]["IsLock"].ToString() != "") { model.IsLock = int.Parse(ds.Tables[0].Rows[0]["IsLock"].ToString()); } if (ds.Tables[0].Rows[0]["IsTop"] != null && ds.Tables[0].Rows[0]["IsTop"].ToString() != "") { model.IsTop = int.Parse(ds.Tables[0].Rows[0]["IsTop"].ToString()); } if (ds.Tables[0].Rows[0]["PubTime"] != null && ds.Tables[0].Rows[0]["PubTime"].ToString() != "") { model.PubTime = DateTime.Parse(ds.Tables[0].Rows[0]["PubTime"].ToString()); } return(model); } else { return(null); } }
protected void btnSave_Click(object sender, EventArgs e) { Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); Cms.Model.NewsInfo model = new Cms.Model.NewsInfo(); model.NewsID = Id; model.Title = txtTitle.Text.Trim(); model.Author = txtAuthor.Text.Trim(); model.ClassId = int.Parse(ddlClassId.SelectedValue); model.Content = Cms.Common.Utils.ToHtml(NewsContent.Text); model.PubTime = DateTime.Parse(txtPubTime.Text); model.Click = int.Parse(txtClick.Text.Trim()); model.IsTop = 0; if (cblItem.Items[0].Selected == true) { model.IsTop = 1; } model.IsLock = 0; if (cblItem.Items[1].Selected == true) { model.IsLock = 1; } dal.Update(model); //保存日志 MessageBox.Show(this, "新闻编辑成功!"); }
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e) { int id = Convert.ToInt32(((Label)e.Item.FindControl("lb_id")).Text); Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); Cms.Model.NewsInfo model = dal.GetModel(id); switch (e.CommandName.ToLower()) { case "ibtnlock": if (model.IsLock == 1) { dal.UpdateField(id, "IsLock=0"); } else { dal.UpdateField(id, "IsLock=1"); } break; case "ibtntop": if (model.IsTop == 1) { dal.UpdateField(id, "IsTop=0"); } else { dal.UpdateField(id, "IsTop=1"); } break; } RptBind(); }
protected void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtTitle.Text.Trim().Length == 0) { strErr += "新闻标题不能为空!\\n"; } if (this.txtAuthor.Text.Trim().Length == 0) { strErr += "发布人不能为空!\\n"; } if (this.NewsContent.Text.Trim().Length == 0) { strErr += "新闻内容不能为空!\\n"; } if (!PageValidate.IsNumber(txtClick.Text)) { strErr += "点击次数格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } Cms.Model.NewsInfo model = new Cms.Model.NewsInfo(); model.Title = this.txtTitle.Text; model.Author = this.txtAuthor.Text; model.ClassId = int.Parse(ddlClassId.SelectedValue); model.Content = Cms.Common.Utils.ToHtml(this.NewsContent.Text); model.Click = int.Parse(this.txtClick.Text); model.IsTop = 0; if (cblItem.Items[0].Selected == true) { model.IsTop = 1; } model.IsLock = 0; if (cblItem.Items[1].Selected == true) { model.IsLock = 1; } model.PubTime = DateTime.Parse(DateTime.Now.ToString()); Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); int ReId = dal.Add(model); if (ReId > 0) { //保存日志 MessageBox.Show(this, "新闻发布成功!"); } else { MessageBox.Show(this, "发布过程中发生错误!"); //Coolite.Ext.Web.Ext.MessageBox.Alert("提示", "发布过程中发生错误").Show(); } }
//赋值 private void ShowInfo(int Id) { Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); Cms.Model.NewsInfo model = dal.GetModel(Id); this.lblId.Text = model.NewsID.ToString(); this.lblTitle.Text = model.Title; this.lblAuthor.Text = model.Author; this.lblClassId.Text = model.ClassId.ToString(); this.lblContent.Text = Cms.Common.Utils.ToTxt(model.Content); this.lblClick.Text = model.Click.ToString(); this.lblIsLock.Text = model.IsLock.ToString(); this.lblIsTop.Text = model.IsTop.ToString(); this.lblPubTime.Text = model.PubTime.ToString(); }
private void ShowInfo(int _id) { Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); Cms.Model.NewsInfo model = dal.GetModel(_id); txtTitle.Text = model.Title; txtAuthor.Text = model.Author; ddlClassId.SelectedValue = model.ClassId.ToString(); NewsContent.Text = Cms.Common.Utils.ToTxt(model.Content); txtPubTime.Text = model.PubTime.ToString("yyyy-MM-dd HH:mm:ss"); txtClick.Text = model.Click.ToString(); cblItem.Items[0].Selected = model.IsTop > 0; cblItem.Items[1].Selected = model.IsLock > 0; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Cms.Model.NewsInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update NewsInfo set "); strSql.Append("Title=@Title,"); strSql.Append("Author=@Author,"); strSql.Append("ClassId=@ClassId,"); strSql.Append("Content=@Content,"); strSql.Append("Click=@Click,"); strSql.Append("IsLock=@IsLock,"); strSql.Append("IsTop=@IsTop,"); strSql.Append("PubTime=@PubTime"); strSql.Append(" where NewsId=@NewsId"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Author", SqlDbType.NVarChar, 50), new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@Content", SqlDbType.NText), new SqlParameter("@Click", SqlDbType.Int, 4), new SqlParameter("@IsLock", SqlDbType.Int, 4), new SqlParameter("@IsTop", SqlDbType.Int, 4), new SqlParameter("@PubTime", SqlDbType.DateTime), new SqlParameter("@NewsId", SqlDbType.Int, 4) }; parameters[0].Value = model.Title; parameters[1].Value = model.Author; parameters[2].Value = model.ClassId; parameters[3].Value = model.Content; parameters[4].Value = model.Click; parameters[5].Value = model.IsLock; parameters[6].Value = model.IsTop; parameters[7].Value = model.PubTime; parameters[8].Value = model.NewsID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { if (!int.TryParse(Request.Params["newsID"] as string, out this.newsId)) { Response.Write("<script>alert('您要查看的信息参数不正确或不存在!'),location.href='News.aspx';</script>"); return; } Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); model = dal.GetModel(this.newsId);//获得Id if (model == null) { Response.Write("<script>alert('您要查看的信息参数不正确或不存在!'),location.href='News.aspx';</script>"); return; } ////浏览数+1 dal.UpdateField(this.newsId, "Click=Click+1"); ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>menuEnable(4);</script>"); }
protected int newsId; //全局变量Id #endregion Fields #region Methods protected void Page_Load(object sender, EventArgs e) { if (!int.TryParse(Request.Params["newsID"] as string, out this.newsId)) { Response.Write("<script>alert('您要查看的信息参数不正确或不存在!'),location.href='News.aspx';</script>"); return; } Cms.DAL.NewsInfo dal = new Cms.DAL.NewsInfo(); model = dal.GetModel(this.newsId);//获得Id if (model == null) { Response.Write("<script>alert('您要查看的信息参数不正确或不存在!'),location.href='News.aspx';</script>"); return; } ////浏览数+1 dal.UpdateField(this.newsId, "Click=Click+1"); ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>menuEnable(4);</script>"); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Cms.Model.NewsInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into NewsInfo("); strSql.Append("Title,Author,ClassId,Content,Click,IsLock,IsTop,PubTime)"); strSql.Append(" values ("); strSql.Append("@Title,@Author,@ClassId,@Content,@Click,@IsLock,@IsTop,@PubTime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Title", SqlDbType.NVarChar, 100), new SqlParameter("@Author", SqlDbType.NVarChar, 50), new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@Content", SqlDbType.NText), new SqlParameter("@Click", SqlDbType.Int, 4), new SqlParameter("@IsLock", SqlDbType.Int, 4), new SqlParameter("@IsTop", SqlDbType.Int, 4), new SqlParameter("@PubTime", SqlDbType.DateTime) }; parameters[0].Value = model.Title; parameters[1].Value = model.Author; parameters[2].Value = model.ClassId; parameters[3].Value = model.Content; parameters[4].Value = model.Click; parameters[5].Value = model.IsLock; parameters[6].Value = model.IsTop; parameters[7].Value = model.PubTime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Cms.Model.NewsInfo GetModel(int newsId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 NewsId,Title,Author,ClassId,Content,Click,IsLock,IsTop,PubTime from NewsInfo "); strSql.Append(" where NewsID=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = newsId; Cms.Model.NewsInfo model = new Cms.Model.NewsInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["NewsID"] != null && ds.Tables[0].Rows[0]["NewsID"].ToString() != "") { model.NewsID = int.Parse(ds.Tables[0].Rows[0]["NewsID"].ToString()); } if (ds.Tables[0].Rows[0]["Title"] != null && ds.Tables[0].Rows[0]["Title"].ToString() != "") { model.Title = ds.Tables[0].Rows[0]["Title"].ToString(); } if (ds.Tables[0].Rows[0]["Author"] != null && ds.Tables[0].Rows[0]["Author"].ToString() != "") { model.Author = ds.Tables[0].Rows[0]["Author"].ToString(); } if (ds.Tables[0].Rows[0]["ClassId"] != null && ds.Tables[0].Rows[0]["ClassId"].ToString() != "") { model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString()); } if (ds.Tables[0].Rows[0]["Content"] != null && ds.Tables[0].Rows[0]["Content"].ToString() != "") { model.Content = ds.Tables[0].Rows[0]["Content"].ToString(); } if (ds.Tables[0].Rows[0]["Click"] != null && ds.Tables[0].Rows[0]["Click"].ToString() != "") { model.Click = int.Parse(ds.Tables[0].Rows[0]["Click"].ToString()); } if (ds.Tables[0].Rows[0]["IsLock"] != null && ds.Tables[0].Rows[0]["IsLock"].ToString() != "") { model.IsLock = int.Parse(ds.Tables[0].Rows[0]["IsLock"].ToString()); } if (ds.Tables[0].Rows[0]["IsTop"] != null && ds.Tables[0].Rows[0]["IsTop"].ToString() != "") { model.IsTop = int.Parse(ds.Tables[0].Rows[0]["IsTop"].ToString()); } if (ds.Tables[0].Rows[0]["PubTime"] != null && ds.Tables[0].Rows[0]["PubTime"].ToString() != "") { model.PubTime = DateTime.Parse(ds.Tables[0].Rows[0]["PubTime"].ToString()); } return model; } else { return null; } }