62,266
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace EVS.Web.Controls
{
public partial class AdminLogin_NewsAdd : System.Web.UI.Page
{
public string ContentEdit = ""; //文本编辑器
public string NewsHot;
protected void Page_Load(object sender, EventArgs e)
{
if (null == Session["AdminNick"])
{
Response.Redirect("login.aspx");
}
if (!IsPostBack)
{
//显示自己的部门
if (null != Session["DepName"])
{
this.TextBox1.Text = Session["DepName"] as string;
}
if (null != Session["DepId"])
{
this.HiddenField1.Value = Session["DepId"] as string;
}
//取出栏目
string ColumnSql = " select menuname,menuid from menumanagement where depid= " + HiddenField1.Value + " and menutype='文字列表类' and delsign=1";
DataSet ColumnDs = manager.connstr.DataAdapter(ColumnSql);
if (ColumnDs.Tables[0].Rows.Count >= 0)
{
this.DropDownList1.DataSource = ColumnDs;
this.DropDownList1.DataTextField = "MenuName";
this.DropDownList1.DataValueField = "MenuId";
this.DropDownList1.DataBind();
}
//取出候选的用户组
string AuthoritySql = " select usergroupname,groupid from UserGroup where delsign=1";
DataSet AuthorityDS = manager.connstr.DataAdapter(AuthoritySql);
if (AuthorityDS.Tables[0].Rows.Count >= 0)
{
this.CheckBoxList1.DataSource = AuthorityDS;
this.CheckBoxList1.DataTextField = "UserGroupName";
this.CheckBoxList1.DataValueField = "GroupID";
this.CheckBoxList1.DataBind();
}
}
}
public void Button1_Click(object sender, EventArgs e)
{
//获取信息插入数据库
string NewsTitle = TextBox2.Text.ToString().Trim();
string NewsContent = Request.Params["textarea1"];
if (CheckBox1.Checked == true)
{
NewsHot = "1";
}
else
{
NewsHot = "0";
}
//bool NewsHot = CheckBox1.Checked;
string Sequence = TextBox3.Text.ToString();
string DepId = HiddenField1.Value;
string MenuId = DropDownList1.SelectedValue.ToString();
string strCollected = string.Empty;
//获取已选的checklistbox的值,并组成字符串
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
if (strCollected == string.Empty)
{
strCollected = CheckBoxList1.Items[i].Value;
}
else
{
strCollected = strCollected + "-" + CheckBoxList1.Items[i].Value;
}
}
}
string UserAuthor = strCollected;
//DateTime Time= DateTime.Now;
//bool DelSign = true;
string InsertSql = "insert into NewsList (newstitle,newscontent,newshot,sequence,depid,menuid,userauthor) values('" +
NewsTitle + "', '" + NewsContent + "', " + NewsHot + ", '" + Sequence + "', '" + DepId + "', '" + MenuId + "', '" + UserAuthor + "')";
ShowMessage.ShowAlert(InsertSql);
int SaveSign = manager.connstr.exccute_del(InsertSql);
if (SaveSign > 0)
{
ShowMessage.ShowAlert("保存成功");
}
else
{
ShowMessage.ShowAlert("很遗憾,保存出错,麻烦你重新输入一遍");
}
}
}
}