protected void btnSave_Click(object sender, EventArgs e) { string strErr=""; if(this.txtnewsTitle.Text.Trim().Length==0) { strErr+="标题不能为空!\\n"; } if(this.txtContent.Text.Trim().Length==0) { strErr+="新闻内容不能为空!\\n"; } if (this.ddrCat.SelectedValue == "0") { strErr += "请选择所属分类!\\n"; } if(strErr!="") { MessageBox.Show(this,strErr); return; } int catId = int.Parse(this.ddrCat.SelectedValue); string catName = this.ddrCat.Items[ddrCat.SelectedIndex].Text; int userId=int.Parse(Common.Cookie.GetValue(StatusHelpercs.Cookie_Admin_UserId)); string userName = Common.Cookie.GetValue(StatusHelpercs.Cookie_Admin_UserName); int deptId = 1; string newsTitle=this.txtnewsTitle.Text; string summary=""; string newsContent = this.txtContent.Text; string contentSource=""; string author=""; DateTime addTime = DateTime.Now; DateTime modifyTime = DateTime.Now; int status=1; int isHomePage=0; int isSlide=0; hm.Model.news model=new hm.Model.news(); model.catId=catId; model.catName=catName; model.userId=userId; model.userName=userName; model.deptId=deptId; model.newsTitle=newsTitle; model.summary=summary; model.newsContent=newsContent; model.contentSource=contentSource; model.author=author; model.addTime=addTime; model.modifyTime=modifyTime; model.status=status; model.isHomePage=isHomePage; model.isSlide=isSlide; hm.BLL.news bll=new hm.BLL.news(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
private void ShowInfo(int newsId) { hm.BLL.news bll = new hm.BLL.news(); hm.Model.news model = bll.GetModel(newsId); this.lblNewsId.Text = model.newsId.ToString(); this.txtnewsTitle.Text = model.newsTitle; this.txtContent.Text = model.newsContent; Model.ed_node modelNode = nBll.GetModel(model.catId.Value); litId.Text = modelNode.ID.ToString(); litName.Text = modelNode.title; }
private void ShowInfo(int newsId) { hm.BLL.news bll = new hm.BLL.news(); hm.Model.news model = bll.GetModel(newsId); this.lblnewsId.Text = model.newsId.ToString(); this.lbluserName.Text = model.userName; this.lblnewsTitle.Text = model.newsTitle; this.lblnewsContent.Text = model.newsContent; this.lbladdTime.Text = model.addTime.ToString(); this.lblmodifyTime.Text = model.modifyTime.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public hm.Model.news GetModel(int newsId) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 newsId,catId,catName,userId,userName,deptId,newsTitle,summary,newsContent,picUrl,videoUrl,contentSource,author,addTime,modifyTime,status,isHomePage,isSlide,isTop,fileUrl1,fileUrl2,fileUrl3 from news "); strSql.Append(" where newsId=@newsId"); SqlParameter[] parameters = { new SqlParameter("@newsId", SqlDbType.Int,4) }; parameters[0].Value = newsId; hm.Model.news model=new hm.Model.news(); 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]["catId"]!=null && ds.Tables[0].Rows[0]["catId"].ToString()!="") { model.catId=int.Parse(ds.Tables[0].Rows[0]["catId"].ToString()); } if(ds.Tables[0].Rows[0]["catName"]!=null && ds.Tables[0].Rows[0]["catName"].ToString()!="") { model.catName=ds.Tables[0].Rows[0]["catName"].ToString(); } if(ds.Tables[0].Rows[0]["userId"]!=null && ds.Tables[0].Rows[0]["userId"].ToString()!="") { model.userId=int.Parse(ds.Tables[0].Rows[0]["userId"].ToString()); } if(ds.Tables[0].Rows[0]["userName"]!=null && ds.Tables[0].Rows[0]["userName"].ToString()!="") { model.userName=ds.Tables[0].Rows[0]["userName"].ToString(); } if(ds.Tables[0].Rows[0]["deptId"]!=null && ds.Tables[0].Rows[0]["deptId"].ToString()!="") { model.deptId=int.Parse(ds.Tables[0].Rows[0]["deptId"].ToString()); } if(ds.Tables[0].Rows[0]["newsTitle"]!=null && ds.Tables[0].Rows[0]["newsTitle"].ToString()!="") { model.newsTitle=ds.Tables[0].Rows[0]["newsTitle"].ToString(); } if(ds.Tables[0].Rows[0]["summary"]!=null && ds.Tables[0].Rows[0]["summary"].ToString()!="") { model.summary=ds.Tables[0].Rows[0]["summary"].ToString(); } if(ds.Tables[0].Rows[0]["newsContent"]!=null && ds.Tables[0].Rows[0]["newsContent"].ToString()!="") { model.newsContent=ds.Tables[0].Rows[0]["newsContent"].ToString(); } if(ds.Tables[0].Rows[0]["picUrl"]!=null && ds.Tables[0].Rows[0]["picUrl"].ToString()!="") { model.picUrl=ds.Tables[0].Rows[0]["picUrl"].ToString(); } if(ds.Tables[0].Rows[0]["videoUrl"]!=null && ds.Tables[0].Rows[0]["videoUrl"].ToString()!="") { model.videoUrl=ds.Tables[0].Rows[0]["videoUrl"].ToString(); } if(ds.Tables[0].Rows[0]["contentSource"]!=null && ds.Tables[0].Rows[0]["contentSource"].ToString()!="") { model.contentSource=ds.Tables[0].Rows[0]["contentSource"].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]["addTime"]!=null && ds.Tables[0].Rows[0]["addTime"].ToString()!="") { model.addTime=DateTime.Parse(ds.Tables[0].Rows[0]["addTime"].ToString()); } if(ds.Tables[0].Rows[0]["modifyTime"]!=null && ds.Tables[0].Rows[0]["modifyTime"].ToString()!="") { model.modifyTime=DateTime.Parse(ds.Tables[0].Rows[0]["modifyTime"].ToString()); } if(ds.Tables[0].Rows[0]["status"]!=null && ds.Tables[0].Rows[0]["status"].ToString()!="") { model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if(ds.Tables[0].Rows[0]["isHomePage"]!=null && ds.Tables[0].Rows[0]["isHomePage"].ToString()!="") { model.isHomePage=int.Parse(ds.Tables[0].Rows[0]["isHomePage"].ToString()); } if(ds.Tables[0].Rows[0]["isSlide"]!=null && ds.Tables[0].Rows[0]["isSlide"].ToString()!="") { model.isSlide=int.Parse(ds.Tables[0].Rows[0]["isSlide"].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]["fileUrl1"]!=null && ds.Tables[0].Rows[0]["fileUrl1"].ToString()!="") { model.fileUrl1=ds.Tables[0].Rows[0]["fileUrl1"].ToString(); } if(ds.Tables[0].Rows[0]["fileUrl2"]!=null && ds.Tables[0].Rows[0]["fileUrl2"].ToString()!="") { model.fileUrl2=ds.Tables[0].Rows[0]["fileUrl2"].ToString(); } if(ds.Tables[0].Rows[0]["fileUrl3"]!=null && ds.Tables[0].Rows[0]["fileUrl3"].ToString()!="") { model.fileUrl3=ds.Tables[0].Rows[0]["fileUrl3"].ToString(); } return model; } else { return null; } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(hm.Model.news model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into news("); strSql.Append("catId,catName,userId,userName,deptId,newsTitle,summary,newsContent,picUrl,videoUrl,contentSource,author,addTime,modifyTime,status,isHomePage,isSlide,isTop,fileUrl1,fileUrl2,fileUrl3)"); strSql.Append(" values ("); strSql.Append("@catId,@catName,@userId,@userName,@deptId,@newsTitle,@summary,@newsContent,@picUrl,@videoUrl,@contentSource,@author,@addTime,@modifyTime,@status,@isHomePage,@isSlide,@isTop,@fileUrl1,@fileUrl2,@fileUrl3)"); OleDbParameter[] parameters = { new OleDbParameter("@catId", OleDbType.Integer, 4), new OleDbParameter("@catName", OleDbType.VarChar, 0), new OleDbParameter("@userId", OleDbType.Integer, 4), new OleDbParameter("@userName", OleDbType.VarChar, 0), new OleDbParameter("@deptId", OleDbType.Integer, 4), new OleDbParameter("@newsTitle", OleDbType.VarChar, 0), new OleDbParameter("@summary", OleDbType.VarChar, 0), new OleDbParameter("@newsContent", OleDbType.VarChar, 0), new OleDbParameter("@picUrl", OleDbType.VarChar, 0), new OleDbParameter("@videoUrl", OleDbType.VarChar, 0), new OleDbParameter("@contentSource", OleDbType.VarChar, 0), new OleDbParameter("@author", OleDbType.VarChar, 0), new OleDbParameter("@addTime", OleDbType.Date), new OleDbParameter("@modifyTime", OleDbType.Date), new OleDbParameter("@status", OleDbType.Integer, 4), new OleDbParameter("@isHomePage", OleDbType.Integer, 4), new OleDbParameter("@isSlide", OleDbType.Integer, 4), new OleDbParameter("@isTop", OleDbType.Integer, 4), new OleDbParameter("@fileUrl1", OleDbType.VarChar, 0), new OleDbParameter("@fileUrl2", OleDbType.VarChar, 0), new OleDbParameter("@fileUrl3", OleDbType.VarChar, 0) }; parameters[0].Value = model.catId; parameters[1].Value = model.catName; parameters[2].Value = model.userId; parameters[3].Value = model.userName; parameters[4].Value = model.deptId; parameters[5].Value = model.newsTitle; parameters[6].Value = model.summary; parameters[7].Value = model.newsContent; parameters[8].Value = model.picUrl; parameters[9].Value = model.videoUrl; parameters[10].Value = model.contentSource; parameters[11].Value = model.author; parameters[12].Value = model.addTime; parameters[13].Value = model.modifyTime; parameters[14].Value = model.status; parameters[15].Value = model.isHomePage; parameters[16].Value = model.isSlide; parameters[17].Value = model.isTop; parameters[18].Value = model.fileUrl1; parameters[19].Value = model.fileUrl2; parameters[20].Value = model.fileUrl3; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public hm.Model.news GetModel(int newsId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select newsId,catId,catName,userId,userName,deptId,newsTitle,summary,newsContent,picUrl,videoUrl,contentSource,author,addTime,modifyTime,status,isHomePage,isSlide,isTop,fileUrl1,fileUrl2,fileUrl3 from news "); strSql.Append(" where newsId=@newsId"); OleDbParameter[] parameters = { new OleDbParameter("@newsId", OleDbType.Integer, 4) }; parameters[0].Value = newsId; hm.Model.news model = new hm.Model.news(); DataSet ds = DbHelperOleDb.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]["catId"] != null && ds.Tables[0].Rows[0]["catId"].ToString() != "") { model.catId = int.Parse(ds.Tables[0].Rows[0]["catId"].ToString()); } if (ds.Tables[0].Rows[0]["catName"] != null && ds.Tables[0].Rows[0]["catName"].ToString() != "") { model.catName = ds.Tables[0].Rows[0]["catName"].ToString(); } if (ds.Tables[0].Rows[0]["userId"] != null && ds.Tables[0].Rows[0]["userId"].ToString() != "") { model.userId = int.Parse(ds.Tables[0].Rows[0]["userId"].ToString()); } if (ds.Tables[0].Rows[0]["userName"] != null && ds.Tables[0].Rows[0]["userName"].ToString() != "") { model.userName = ds.Tables[0].Rows[0]["userName"].ToString(); } if (ds.Tables[0].Rows[0]["deptId"] != null && ds.Tables[0].Rows[0]["deptId"].ToString() != "") { model.deptId = int.Parse(ds.Tables[0].Rows[0]["deptId"].ToString()); } if (ds.Tables[0].Rows[0]["newsTitle"] != null && ds.Tables[0].Rows[0]["newsTitle"].ToString() != "") { model.newsTitle = ds.Tables[0].Rows[0]["newsTitle"].ToString(); } if (ds.Tables[0].Rows[0]["summary"] != null && ds.Tables[0].Rows[0]["summary"].ToString() != "") { model.summary = ds.Tables[0].Rows[0]["summary"].ToString(); } if (ds.Tables[0].Rows[0]["newsContent"] != null && ds.Tables[0].Rows[0]["newsContent"].ToString() != "") { model.newsContent = ds.Tables[0].Rows[0]["newsContent"].ToString(); } if (ds.Tables[0].Rows[0]["picUrl"] != null && ds.Tables[0].Rows[0]["picUrl"].ToString() != "") { model.picUrl = ds.Tables[0].Rows[0]["picUrl"].ToString(); } if (ds.Tables[0].Rows[0]["videoUrl"] != null && ds.Tables[0].Rows[0]["videoUrl"].ToString() != "") { model.videoUrl = ds.Tables[0].Rows[0]["videoUrl"].ToString(); } if (ds.Tables[0].Rows[0]["contentSource"] != null && ds.Tables[0].Rows[0]["contentSource"].ToString() != "") { model.contentSource = ds.Tables[0].Rows[0]["contentSource"].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]["addTime"] != null && ds.Tables[0].Rows[0]["addTime"].ToString() != "") { model.addTime = DateTime.Parse(ds.Tables[0].Rows[0]["addTime"].ToString()); } if (ds.Tables[0].Rows[0]["modifyTime"] != null && ds.Tables[0].Rows[0]["modifyTime"].ToString() != "") { model.modifyTime = DateTime.Parse(ds.Tables[0].Rows[0]["modifyTime"].ToString()); } if (ds.Tables[0].Rows[0]["status"] != null && ds.Tables[0].Rows[0]["status"].ToString() != "") { model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (ds.Tables[0].Rows[0]["isHomePage"] != null && ds.Tables[0].Rows[0]["isHomePage"].ToString() != "") { model.isHomePage = int.Parse(ds.Tables[0].Rows[0]["isHomePage"].ToString()); } if (ds.Tables[0].Rows[0]["isSlide"] != null && ds.Tables[0].Rows[0]["isSlide"].ToString() != "") { model.isSlide = int.Parse(ds.Tables[0].Rows[0]["isSlide"].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]["fileUrl1"] != null && ds.Tables[0].Rows[0]["fileUrl1"].ToString() != "") { model.fileUrl1 = ds.Tables[0].Rows[0]["fileUrl1"].ToString(); } if (ds.Tables[0].Rows[0]["fileUrl2"] != null && ds.Tables[0].Rows[0]["fileUrl2"].ToString() != "") { model.fileUrl2 = ds.Tables[0].Rows[0]["fileUrl2"].ToString(); } if (ds.Tables[0].Rows[0]["fileUrl3"] != null && ds.Tables[0].Rows[0]["fileUrl3"].ToString() != "") { model.fileUrl3 = ds.Tables[0].Rows[0]["fileUrl3"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(hm.Model.news model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update news set "); strSql.Append("catId=@catId,"); strSql.Append("catName=@catName,"); strSql.Append("userId=@userId,"); strSql.Append("userName=@userName,"); strSql.Append("deptId=@deptId,"); strSql.Append("newsTitle=@newsTitle,"); strSql.Append("summary=@summary,"); strSql.Append("newsContent=@newsContent,"); strSql.Append("picUrl=@picUrl,"); strSql.Append("videoUrl=@videoUrl,"); strSql.Append("contentSource=@contentSource,"); strSql.Append("author=@author,"); strSql.Append("addTime=@addTime,"); strSql.Append("modifyTime=@modifyTime,"); strSql.Append("status=@status,"); strSql.Append("isHomePage=@isHomePage,"); strSql.Append("isSlide=@isSlide,"); strSql.Append("isTop=@isTop,"); strSql.Append("fileUrl1=@fileUrl1,"); strSql.Append("fileUrl2=@fileUrl2,"); strSql.Append("fileUrl3=@fileUrl3"); strSql.Append(" where newsId=@newsId"); OleDbParameter[] parameters = { new OleDbParameter("@catId", OleDbType.Integer, 4), new OleDbParameter("@catName", OleDbType.VarChar, 0), new OleDbParameter("@userId", OleDbType.Integer, 4), new OleDbParameter("@userName", OleDbType.VarChar, 0), new OleDbParameter("@deptId", OleDbType.Integer, 4), new OleDbParameter("@newsTitle", OleDbType.VarChar, 0), new OleDbParameter("@summary", OleDbType.VarChar, 0), new OleDbParameter("@newsContent", OleDbType.VarChar, 0), new OleDbParameter("@picUrl", OleDbType.VarChar, 0), new OleDbParameter("@videoUrl", OleDbType.VarChar, 0), new OleDbParameter("@contentSource", OleDbType.VarChar, 0), new OleDbParameter("@author", OleDbType.VarChar, 0), new OleDbParameter("@addTime", OleDbType.Date), new OleDbParameter("@modifyTime", OleDbType.Date), new OleDbParameter("@status", OleDbType.Integer, 4), new OleDbParameter("@isHomePage", OleDbType.Integer, 4), new OleDbParameter("@isSlide", OleDbType.Integer, 4), new OleDbParameter("@isTop", OleDbType.Integer, 4), new OleDbParameter("@fileUrl1", OleDbType.VarChar, 0), new OleDbParameter("@fileUrl2", OleDbType.VarChar, 0), new OleDbParameter("@fileUrl3", OleDbType.VarChar, 0), new OleDbParameter("@newsId", OleDbType.Integer, 4) }; parameters[0].Value = model.catId; parameters[1].Value = model.catName; parameters[2].Value = model.userId; parameters[3].Value = model.userName; parameters[4].Value = model.deptId; parameters[5].Value = model.newsTitle; parameters[6].Value = model.summary; parameters[7].Value = model.newsContent; parameters[8].Value = model.picUrl; parameters[9].Value = model.videoUrl; parameters[10].Value = model.contentSource; parameters[11].Value = model.author; parameters[12].Value = model.addTime; parameters[13].Value = model.modifyTime; parameters[14].Value = model.status; parameters[15].Value = model.isHomePage; parameters[16].Value = model.isSlide; parameters[17].Value = model.isTop; parameters[18].Value = model.fileUrl1; parameters[19].Value = model.fileUrl2; parameters[20].Value = model.fileUrl3; parameters[21].Value = model.newsId; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtnewsTitle.Text.Trim().Length == 0) { strErr += "标题不能为空!\\n"; } if (this.txtContent.Text.Trim().Length == 0) { strErr += "新闻内容不能为空!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int newsId = int.Parse(this.lblNewsId.Text); int catId = int.Parse(litId.Text); string catName = litName.Text; int userId = int.Parse(Request.Cookies["userId"].Value); string userName = Request.Cookies["userName"].Value; int deptId = int.Parse(Request.Cookies["deptId"].Value); string newsTitle = this.txtnewsTitle.Text; string summary = ""; string newsContent = this.txtContent.Text; string contentSource = ""; string author = ""; DateTime addTime = DateTime.Now; DateTime modifyTime = DateTime.Now; int isHomePage = 0; int isSlide = 0; isHomePage = 0; hm.BLL.news bll = new hm.BLL.news(); hm.Model.news model = bll.GetModel(newsId); model.newsId = newsId; model.catId = catId; model.catName = catName; model.userId = userId; model.userName = userName; model.deptId = deptId; model.newsTitle = newsTitle; model.summary = summary; model.newsContent = newsContent; model.contentSource = contentSource; model.author = author; model.addTime = addTime; model.modifyTime = modifyTime; model.isHomePage = isHomePage; model.isSlide = isSlide; model.picUrl = ""; model.videoUrl = ""; model.isTop = 0; model.fileUrl1 = ""; model.fileUrl2 = ""; model.fileUrl3 = ""; bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "../media/list.aspx?id=" + model.catId); }