实现用户管理模块和新闻类别管理模块
2013-03-08 15:37
288 查看
--这是用户管理模块的前台页面
<body>
<form id="form1" runat="server">
<div>
用户姓名:<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
<asp:Button ID="BtnCheck"
runat="server" Text="查询" onclick="BtnCheck_Click" /><a href="用户添加模块.aspx">添加</a>
<div id="divResult" runat="server"></div>
</div>
</form>
</body>
--这是用户管理模块的后台代码
namespace 新闻管理系统
{
public partial class 用户管理模块 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["key"]))
{
TxtRealName.Text = Request.QueryString["key"];
DataLoad();
}
if (Request.QueryString["ispostback"] == "1")
{
DataLoad();
}
}
}
private void DataLoad()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select T_User.Id, T_User.UserId,T_User.UserName,T_User.Password,T_User.RealName,T_User.Mobile,T1.Department_Name FROM T_User INNER JOIN Department T1 ON T_User.Department=T1.Department_Id WHERE T_User.RealName LIKE @name
order by T_User.UserID DESC";
cmd.Parameters.AddWithValue("@name", "%" + TxtRealName.Text + "%");
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Dispose();
StringBuilder sb1 = new StringBuilder();
string userid = string.Empty;
string username = string.Empty;
string password = string.Empty;
string realname = string.Empty;
string moblie = string.Empty;
string department = string.Empty;
sb1.Append("<table border=1>");
foreach (DataRow row in dt.Rows)
{
sb1.Append("<tr>");
userid = row["UserId"].ToString();
username = row["UserName"].ToString();
password = row["Password"].ToString();
realname = row["RealName"].ToString();
moblie = row["Mobile"].ToString();
department = row["Department_Name"].ToString();
sb1.Append("<td>" + userid + "</td>");
sb1.Append("<td>" + username + "</td>");
sb1.Append("<td>" + password + "</td>");
sb1.Append("<td>" + realname + "</td>");
sb1.Append("<td>" + moblie + "</td>");
sb1.Append("<td>" + department + "</td>");
sb1.Append("<td><a href='用户管理更改.aspx?id=" + row["Id"].ToString() + "&key=" + TxtRealName.Text + "'> 更改</a></td>");
sb1.Append("</tr>");
}
sb1.Append("</table>");
divResult.InnerHtml = sb1.ToString();
}
}
}
protected void BtnCheck_Click(object sender, EventArgs e)
{
#region 验证输入是否为空
if (string.IsNullOrEmpty(TxtRealName.Text))
{
TxtRealName.Text = "请输入您要查询的数据";
return;
}
#endregion
DataLoad();
}
}
}
--这是用户管理模块更改的前台
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 85px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">用户编号:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">用户姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">用户密码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtPassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">真实姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">手机号码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtCall" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">所属部门:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="36px" Width="148px">
</asp:DropDownList>
</td>
</tr>
<tr><td></td><td>
<asp:Button ID="BtnSave" runat="server" Text="保存" onclick="BtnSave_Click"
style="height: 21px" /></td></tr>
</table>
</div>
</form>
</body>
--这是用户管理模块更改的后台代码
namespace 新闻管理系统
{
public partial class 用户管理更改 : System.Web.UI.Page
{
string newsname = string.Empty;
string key = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
newsname= Request.QueryString["id"];
key = Request.QueryString["key"];
if (!IsPostBack)
{
Data(newsname);
}
}
private void Data(string newsname)
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select T_User.Id,T_User.UserId,T_User.UserName,T_User.Password,T_User.RealName,T_User.Mobile,T_User.Department,T1.Department_Name FROM T_User INNER JOIN Department T1 ON T_User.Department=T1.Department_Id WHERE T_User.Id=@Id
";
cmd.Parameters.AddWithValue("@Id", newsname);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
foreach (DataRow row in dt.Rows)
{
TxtID.Text = row["UserId"].ToString();
TxtName.Text =row["UserName"].ToString();
TxtPassword.Text = row["Password"].ToString();
TxtRealName.Text =row["RealName"].ToString();
TxtCall.Text = row["Mobile"].ToString();
}
cmd.Parameters.Clear();
cmd.CommandText = "select Department_Id,Department_Name from Department";
DataTable dtname = new DataTable();
adapter.Fill(dtname);
this.DropDownList1.DataSource = dtname;
this.DropDownList1.DataTextField = "Department_Name";
this.DropDownList1.DataValueField = "Department_Id";
this.DropDownList1.DataBind();
DropDownList1.Items.FindByValue(dtname.Rows[0]["Department_Id"].ToString()).Selected = true;
cmd.Dispose();
conn.Dispose();
}
}
}
protected void BtnSave_Click(object sender, EventArgs e)
{
string id = TxtID.Text;
string name = TxtName.Text;
string password = TxtPassword.Text;
string realname = TxtRealName.Text;
string call = TxtCall.Text;
string departmentid = DropDownList1.SelectedItem.Value;
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "UPDATE T_User SET UserId=@id,UserName=@name,Password=@password,RealName=@realname,Mobile=@call,Department=@departmentid where Department=@departmentid ";
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@realname", realname);
cmd.Parameters.AddWithValue("@call", call);
cmd.Parameters.AddWithValue("@departmentid",departmentid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("用户管理模块.aspx?key=" + key);
}
}
}
}
}
}
--这是用户管理模块添加的前台设计
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 87px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">用户编号:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">用户姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">用户密码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtPassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">真实姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">手机号码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtCall" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">所属部门:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="36px" Width="148px">
</asp:DropDownList>
</td>
</tr>
<tr><td class="style1"></td><td>
<asp:Button ID="BtnAdd" runat="server" Text="添加" onclick="BtnAdd_Click"
style="height: 21px" /></td></tr>
</table>
</div>
</form>
</body>
</html>
--这是用户管理模块添加的后台代码
namespace 新闻管理系统
{
public partial class 用户添加模块 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
newsType();
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
string id = TxtID.Text;
string name = TxtName.Text;
string password = TxtPassword.Text;
string realname = TxtRealName.Text;
string call = TxtCall.Text;
string departmentid = DropDownList1.SelectedItem.Value;
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO T_User(UserId,UserName,Password,RealName,Mobile,Department) VALUES(@id,@name,@password,@realname,@call,@departmentid)";
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@realname", realname);
cmd.Parameters.AddWithValue("@call", call);
cmd.Parameters.AddWithValue("@departmentid",departmentid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("用户管理模块.aspx?ispostback=1");
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
private void newsType()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select Department_Id,Department_Name from Department";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataTextField = "Department_Name";
this.DropDownList1.DataValueField = "Department_Id";
this.DropDownList1.DataBind();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
}
--这是新闻类别管理模块的前台页面
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 82px;
}
.style2
{
width: 149px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
新闻类别: <asp:TextBox ID="TxtType" runat="server"></asp:TextBox> <asp:Button ID="BtnCheck" runat="server" Text="查询" onclick="BtnCheck_Click" />
<a href="NewsTypeAdd.aspx">添加</a>
<div id="divResult" runat="server"></div>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeUpdate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["key"]))
{
TxtType.Text = Request.QueryString["key"];
DataLoad();
}
if (Request.QueryString["ispostback"] == "1")
{
DataLoad();
}
}
}
private void DataLoad()
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,T1.NewsContent,T2.Id,T2.ClassName,T3.RealName,T4.Department_Name FROM T_News T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId INNER JOIN Department
T4 ON T3.Department=T4.Department_Id WHERE T2.ClassName LIKE @newstype Order by T1.Id DESC";
cmd.Parameters.AddWithValue("@newstype", "%" + TxtType.Text + "%");
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Dispose();
StringBuilder sb1 = new StringBuilder();
string newstitle = string.Empty;
string newscontent = string.Empty;
string creator = string.Empty;
string department = string.Empty;
sb1.Append("<table border=1>");
foreach (DataRow row in dt.Rows)
{
sb1.Append("<tr>");
newstitle = row["NewsTitle"].ToString();
newscontent = row["NewsContent"].ToString();
creator = row["RealName"].ToString();
department = row["Department_Name"].ToString();
sb1.Append("<td>" + newstitle + "</td>");
sb1.Append("<td>" + newscontent + "</td>");
sb1.Append("<td>" + creator + "</td>");
sb1.Append("<td>" + department + "</td>");
sb1.Append("<td><a href='NewsTypeCheck.aspx?id=" + row["Id"].ToString() + "&key=" +TxtType.Text + "'> 更改</a></td>");
}
sb1.Append("</table>");
divResult.InnerHtml = sb1.ToString();
}
}
}
protected void BtnCheck_Click(object sender, EventArgs e)
{
#region 验证输入是否为空
if (string.IsNullOrEmpty(TxtType.Text))
{
TxtType.Text= "请输入您要查询的数据";
return;
}
#endregion
DataLoad();
}
}
}
--这是新闻类别管理模块更改的前台
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 96px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">新闻标题:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtNewsTitle" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">发表人:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="26px" Width="150px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">新闻类别:</asp:Label>
</td>
<td class="style3">
<asp:DropDownList ID="DropDownList2" runat="server" Height="63px" Width="151px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">新闻内容:</asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TxtContent" runat="server" Height="105px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Button ID="Button1" runat="server" Text="保存" onclick="Button1_Click" />
</td>
<td class="style3">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块更改的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeCheck : System.Web.UI.Page
{
string newsid = string.Empty;
string key= string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
newsid = Request.QueryString["id"];
key = Request.QueryString["key"];
if (!IsPostBack)
{
Data(newsid);
}
}
private void Data(string newsid)
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,T1.NewsContent,T1.ClassId,T2.Id,T2.ClassName,T3.RealName,T3.UserId,T4.Department_Name FROM T_News T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId
INNER JOIN Department T4 ON T3.Department=T4.Department_Id WHERE T1.Id=@id";
cmd.Parameters.AddWithValue("@id",newsid);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
TxtNewsTitle.Text = dt.Rows[0]["NewsTitle"].ToString();
TxtContent.Text = dt.Rows[0]["NewsContent"].ToString();
cmd.Parameters.Clear();
cmd.CommandText = "select UserId,RealName from T_User";
DataTable dtname = new DataTable();
adapter.Fill(dtname);
this.DropDownList1.DataSource = dtname;
this.DropDownList1.DataTextField = "RealName";
this.DropDownList1.DataValueField = "UserId";
this.DropDownList1.DataBind();
DropDownList1.Items.FindByValue(dt.Rows[0]["UserId"].ToString()).Selected=true;
cmd.Parameters.Clear();
cmd.CommandText = "SELECT ClassId,ClassName FROM T_NewsClass";
DataTable dtNewsClass = new DataTable();
adapter.Fill(dtNewsClass);
this.DropDownList2.DataSource = dtNewsClass;
this.DropDownList2.DataTextField = "ClassName";
this.DropDownList2.DataValueField = "ClassId";
this.DropDownList2.DataBind();
DropDownList2.Items.FindByValue(dt.Rows[0]["ClassId"].ToString()).Selected = true;
cmd.Dispose();
conn.Dispose();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string newstitle = TxtNewsTitle.Text;
string newscontent = TxtContent.Text;
string classid = DropDownList2.SelectedItem.Value;
string userid = DropDownList1.SelectedItem.Value;
//建立数据连接,更改数据
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "UPDATE T_News SET NewsTitle=@newstitle,NewsContent=@newscontent,ClassId=@classid,NewsCreator=@newscreator WHERE Id=@id";
cmd.Parameters.AddWithValue("@newstitle", newstitle);
cmd.Parameters.AddWithValue("@newscontent", newscontent);
cmd.Parameters.AddWithValue("@classid", classid);
cmd.Parameters.AddWithValue("@newscreator", userid);
cmd.Parameters.AddWithValue("@id", newsid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("NewsTypeUpdate.aspx?key=" + key);
}
}
}
}
}
}
--这是新闻类别管理模块添加的前台设计
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 93px;
}
.style2
{
width: 93px;
height: 23px;
}
.style3
{
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">新文标题:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtTitle" runat="server"></asp:TextBox>
</td>
</tr>
<%-- <tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="Label">发表时间:</asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TxtTime" runat="server"></asp:TextBox>
</td>
</tr>--%>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">创建人:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="21px" Width="145px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">新闻类别</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="144px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">新闻内容:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtContent" runat="server" Height="95px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr><td></td><td>
<asp:Button ID="btnInsert" runat="server" Text="插入" onclick="btnInsert_Click" /></td></tr>
</table>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块添加的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
author();
newstype();
}
}
private void author()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select UserId,RealName from T_User";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dtauthor = new DataTable();
adapter.Fill(dtauthor); ;
this.DropDownList1.DataSource = dtauthor;
this.DropDownList1.DataTextField = "RealName";
this.DropDownList1.DataValueField = "UserId";
this.DropDownList1.DataBind();
cmd.Dispose();
conn.Dispose();
}
}
}
private void newstype()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select ClassId,ClassName From T_NewsClass";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Close();
conn.Dispose();
this.DropDownList2.DataSource = dt;
this.DropDownList2.DataTextField = "ClassName";
this.DropDownList2.DataValueField = "ClassId";
this.DropDownList2.DataBind();
}
protected void btnInsert_Click(object sender, EventArgs e)
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
string newstitle = TxtTitle.Text;
string newscontent = TxtContent.Text;
string userid = DropDownList1.SelectedItem.Value;
string classid = DropDownList2.SelectedItem.Value;
cmd.CommandText = "insert into T_News(NewsTitle,NewsContent,NewsCreator,CreateTime,ClassId) VALUES(@newstitle,@newscontent,@newscreator,getdate(),@calssid)";
cmd.Parameters.AddWithValue("@newstitle", newstitle);
cmd.Parameters.AddWithValue("@newscontent", newscontent);
cmd.Parameters.AddWithValue("@newscreator", userid);
cmd.Parameters.AddWithValue("@calssid", classid);
if (cmd.ExecuteNonQuery()> 0)
{
Response.Redirect("NewsTypeUpdate.aspx?ispostback=1");
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
}
}
}
<body>
<form id="form1" runat="server">
<div>
用户姓名:<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
<asp:Button ID="BtnCheck"
runat="server" Text="查询" onclick="BtnCheck_Click" /><a href="用户添加模块.aspx">添加</a>
<div id="divResult" runat="server"></div>
</div>
</form>
</body>
--这是用户管理模块的后台代码
namespace 新闻管理系统
{
public partial class 用户管理模块 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["key"]))
{
TxtRealName.Text = Request.QueryString["key"];
DataLoad();
}
if (Request.QueryString["ispostback"] == "1")
{
DataLoad();
}
}
}
private void DataLoad()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select T_User.Id, T_User.UserId,T_User.UserName,T_User.Password,T_User.RealName,T_User.Mobile,T1.Department_Name FROM T_User INNER JOIN Department T1 ON T_User.Department=T1.Department_Id WHERE T_User.RealName LIKE @name
order by T_User.UserID DESC";
cmd.Parameters.AddWithValue("@name", "%" + TxtRealName.Text + "%");
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Dispose();
StringBuilder sb1 = new StringBuilder();
string userid = string.Empty;
string username = string.Empty;
string password = string.Empty;
string realname = string.Empty;
string moblie = string.Empty;
string department = string.Empty;
sb1.Append("<table border=1>");
foreach (DataRow row in dt.Rows)
{
sb1.Append("<tr>");
userid = row["UserId"].ToString();
username = row["UserName"].ToString();
password = row["Password"].ToString();
realname = row["RealName"].ToString();
moblie = row["Mobile"].ToString();
department = row["Department_Name"].ToString();
sb1.Append("<td>" + userid + "</td>");
sb1.Append("<td>" + username + "</td>");
sb1.Append("<td>" + password + "</td>");
sb1.Append("<td>" + realname + "</td>");
sb1.Append("<td>" + moblie + "</td>");
sb1.Append("<td>" + department + "</td>");
sb1.Append("<td><a href='用户管理更改.aspx?id=" + row["Id"].ToString() + "&key=" + TxtRealName.Text + "'> 更改</a></td>");
sb1.Append("</tr>");
}
sb1.Append("</table>");
divResult.InnerHtml = sb1.ToString();
}
}
}
protected void BtnCheck_Click(object sender, EventArgs e)
{
#region 验证输入是否为空
if (string.IsNullOrEmpty(TxtRealName.Text))
{
TxtRealName.Text = "请输入您要查询的数据";
return;
}
#endregion
DataLoad();
}
}
}
--这是用户管理模块更改的前台
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 85px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">用户编号:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">用户姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">用户密码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtPassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">真实姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">手机号码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtCall" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">所属部门:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="36px" Width="148px">
</asp:DropDownList>
</td>
</tr>
<tr><td></td><td>
<asp:Button ID="BtnSave" runat="server" Text="保存" onclick="BtnSave_Click"
style="height: 21px" /></td></tr>
</table>
</div>
</form>
</body>
--这是用户管理模块更改的后台代码
namespace 新闻管理系统
{
public partial class 用户管理更改 : System.Web.UI.Page
{
string newsname = string.Empty;
string key = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
newsname= Request.QueryString["id"];
key = Request.QueryString["key"];
if (!IsPostBack)
{
Data(newsname);
}
}
private void Data(string newsname)
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select T_User.Id,T_User.UserId,T_User.UserName,T_User.Password,T_User.RealName,T_User.Mobile,T_User.Department,T1.Department_Name FROM T_User INNER JOIN Department T1 ON T_User.Department=T1.Department_Id WHERE T_User.Id=@Id
";
cmd.Parameters.AddWithValue("@Id", newsname);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
foreach (DataRow row in dt.Rows)
{
TxtID.Text = row["UserId"].ToString();
TxtName.Text =row["UserName"].ToString();
TxtPassword.Text = row["Password"].ToString();
TxtRealName.Text =row["RealName"].ToString();
TxtCall.Text = row["Mobile"].ToString();
}
cmd.Parameters.Clear();
cmd.CommandText = "select Department_Id,Department_Name from Department";
DataTable dtname = new DataTable();
adapter.Fill(dtname);
this.DropDownList1.DataSource = dtname;
this.DropDownList1.DataTextField = "Department_Name";
this.DropDownList1.DataValueField = "Department_Id";
this.DropDownList1.DataBind();
DropDownList1.Items.FindByValue(dtname.Rows[0]["Department_Id"].ToString()).Selected = true;
cmd.Dispose();
conn.Dispose();
}
}
}
protected void BtnSave_Click(object sender, EventArgs e)
{
string id = TxtID.Text;
string name = TxtName.Text;
string password = TxtPassword.Text;
string realname = TxtRealName.Text;
string call = TxtCall.Text;
string departmentid = DropDownList1.SelectedItem.Value;
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "UPDATE T_User SET UserId=@id,UserName=@name,Password=@password,RealName=@realname,Mobile=@call,Department=@departmentid where Department=@departmentid ";
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@realname", realname);
cmd.Parameters.AddWithValue("@call", call);
cmd.Parameters.AddWithValue("@departmentid",departmentid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("用户管理模块.aspx?key=" + key);
}
}
}
}
}
}
--这是用户管理模块添加的前台设计
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 87px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">用户编号:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">用户姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">用户密码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtPassword" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">真实姓名:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtRealName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">手机号码:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtCall" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">所属部门:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="36px" Width="148px">
</asp:DropDownList>
</td>
</tr>
<tr><td class="style1"></td><td>
<asp:Button ID="BtnAdd" runat="server" Text="添加" onclick="BtnAdd_Click"
style="height: 21px" /></td></tr>
</table>
</div>
</form>
</body>
</html>
--这是用户管理模块添加的后台代码
namespace 新闻管理系统
{
public partial class 用户添加模块 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
newsType();
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
string id = TxtID.Text;
string name = TxtName.Text;
string password = TxtPassword.Text;
string realname = TxtRealName.Text;
string call = TxtCall.Text;
string departmentid = DropDownList1.SelectedItem.Value;
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO T_User(UserId,UserName,Password,RealName,Mobile,Department) VALUES(@id,@name,@password,@realname,@call,@departmentid)";
cmd.Parameters.AddWithValue("@id", id);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@realname", realname);
cmd.Parameters.AddWithValue("@call", call);
cmd.Parameters.AddWithValue("@departmentid",departmentid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("用户管理模块.aspx?ispostback=1");
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
private void newsType()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select Department_Id,Department_Name from Department";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
this.DropDownList1.DataSource = dt;
this.DropDownList1.DataTextField = "Department_Name";
this.DropDownList1.DataValueField = "Department_Id";
this.DropDownList1.DataBind();
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
}
--这是新闻类别管理模块的前台页面
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 82px;
}
.style2
{
width: 149px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
新闻类别: <asp:TextBox ID="TxtType" runat="server"></asp:TextBox> <asp:Button ID="BtnCheck" runat="server" Text="查询" onclick="BtnCheck_Click" />
<a href="NewsTypeAdd.aspx">添加</a>
<div id="divResult" runat="server"></div>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeUpdate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!string.IsNullOrEmpty(Request.QueryString["key"]))
{
TxtType.Text = Request.QueryString["key"];
DataLoad();
}
if (Request.QueryString["ispostback"] == "1")
{
DataLoad();
}
}
}
private void DataLoad()
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,T1.NewsContent,T2.Id,T2.ClassName,T3.RealName,T4.Department_Name FROM T_News T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId INNER JOIN Department
T4 ON T3.Department=T4.Department_Id WHERE T2.ClassName LIKE @newstype Order by T1.Id DESC";
cmd.Parameters.AddWithValue("@newstype", "%" + TxtType.Text + "%");
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Dispose();
StringBuilder sb1 = new StringBuilder();
string newstitle = string.Empty;
string newscontent = string.Empty;
string creator = string.Empty;
string department = string.Empty;
sb1.Append("<table border=1>");
foreach (DataRow row in dt.Rows)
{
sb1.Append("<tr>");
newstitle = row["NewsTitle"].ToString();
newscontent = row["NewsContent"].ToString();
creator = row["RealName"].ToString();
department = row["Department_Name"].ToString();
sb1.Append("<td>" + newstitle + "</td>");
sb1.Append("<td>" + newscontent + "</td>");
sb1.Append("<td>" + creator + "</td>");
sb1.Append("<td>" + department + "</td>");
sb1.Append("<td><a href='NewsTypeCheck.aspx?id=" + row["Id"].ToString() + "&key=" +TxtType.Text + "'> 更改</a></td>");
}
sb1.Append("</table>");
divResult.InnerHtml = sb1.ToString();
}
}
}
protected void BtnCheck_Click(object sender, EventArgs e)
{
#region 验证输入是否为空
if (string.IsNullOrEmpty(TxtType.Text))
{
TxtType.Text= "请输入您要查询的数据";
return;
}
#endregion
DataLoad();
}
}
}
--这是新闻类别管理模块更改的前台
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 96px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">新闻标题:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtNewsTitle" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label6" runat="server" Text="Label">发表人:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="26px" Width="150px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Label">新闻类别:</asp:Label>
</td>
<td class="style3">
<asp:DropDownList ID="DropDownList2" runat="server" Height="63px" Width="151px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">新闻内容:</asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TxtContent" runat="server" Height="105px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style1">
<asp:Button ID="Button1" runat="server" Text="保存" onclick="Button1_Click" />
</td>
<td class="style3">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块更改的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeCheck : System.Web.UI.Page
{
string newsid = string.Empty;
string key= string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
newsid = Request.QueryString["id"];
key = Request.QueryString["key"];
if (!IsPostBack)
{
Data(newsid);
}
}
private void Data(string newsid)
{
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT T1.Id,T1.NewsTitle,T1.NewsContent,T1.ClassId,T2.Id,T2.ClassName,T3.RealName,T3.UserId,T4.Department_Name FROM T_News T1 INNER JOIN T_NewsClass T2 ON T1.ClassId=T2.ClassId INNER JOIN T_User T3 ON T1.NewsCreator=T3.UserId
INNER JOIN Department T4 ON T3.Department=T4.Department_Id WHERE T1.Id=@id";
cmd.Parameters.AddWithValue("@id",newsid);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
TxtNewsTitle.Text = dt.Rows[0]["NewsTitle"].ToString();
TxtContent.Text = dt.Rows[0]["NewsContent"].ToString();
cmd.Parameters.Clear();
cmd.CommandText = "select UserId,RealName from T_User";
DataTable dtname = new DataTable();
adapter.Fill(dtname);
this.DropDownList1.DataSource = dtname;
this.DropDownList1.DataTextField = "RealName";
this.DropDownList1.DataValueField = "UserId";
this.DropDownList1.DataBind();
DropDownList1.Items.FindByValue(dt.Rows[0]["UserId"].ToString()).Selected=true;
cmd.Parameters.Clear();
cmd.CommandText = "SELECT ClassId,ClassName FROM T_NewsClass";
DataTable dtNewsClass = new DataTable();
adapter.Fill(dtNewsClass);
this.DropDownList2.DataSource = dtNewsClass;
this.DropDownList2.DataTextField = "ClassName";
this.DropDownList2.DataValueField = "ClassId";
this.DropDownList2.DataBind();
DropDownList2.Items.FindByValue(dt.Rows[0]["ClassId"].ToString()).Selected = true;
cmd.Dispose();
conn.Dispose();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string newstitle = TxtNewsTitle.Text;
string newscontent = TxtContent.Text;
string classid = DropDownList2.SelectedItem.Value;
string userid = DropDownList1.SelectedItem.Value;
//建立数据连接,更改数据
string Constr = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(Constr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "UPDATE T_News SET NewsTitle=@newstitle,NewsContent=@newscontent,ClassId=@classid,NewsCreator=@newscreator WHERE Id=@id";
cmd.Parameters.AddWithValue("@newstitle", newstitle);
cmd.Parameters.AddWithValue("@newscontent", newscontent);
cmd.Parameters.AddWithValue("@classid", classid);
cmd.Parameters.AddWithValue("@newscreator", userid);
cmd.Parameters.AddWithValue("@id", newsid);
if (cmd.ExecuteNonQuery() > 0)
{
Response.Redirect("NewsTypeUpdate.aspx?key=" + key);
}
}
}
}
}
}
--这是新闻类别管理模块添加的前台设计
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 93px;
}
.style2
{
width: 93px;
height: 23px;
}
.style3
{
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Label">新文标题:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtTitle" runat="server"></asp:TextBox>
</td>
</tr>
<%-- <tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="Label">发表时间:</asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="TxtTime" runat="server"></asp:TextBox>
</td>
</tr>--%>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Label">创建人:</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="21px" Width="145px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label4" runat="server" Text="Label">新闻类别</asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="22px" Width="144px">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label5" runat="server" Text="Label">新闻内容:</asp:Label>
</td>
<td>
<asp:TextBox ID="TxtContent" runat="server" Height="95px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr><td></td><td>
<asp:Button ID="btnInsert" runat="server" Text="插入" onclick="btnInsert_Click" /></td></tr>
</table>
</div>
</form>
</body>
</html>
--这是新闻类别管理模块添加的后台代码
namespace 新闻管理系统
{
public partial class NewsTypeAdd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
author();
newstype();
}
}
private void author()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select UserId,RealName from T_User";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dtauthor = new DataTable();
adapter.Fill(dtauthor); ;
this.DropDownList1.DataSource = dtauthor;
this.DropDownList1.DataTextField = "RealName";
this.DropDownList1.DataValueField = "UserId";
this.DropDownList1.DataBind();
cmd.Dispose();
conn.Dispose();
}
}
}
private void newstype()
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
SqlConnection conn = new SqlConnection(strcon);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select ClassId,ClassName From T_NewsClass";
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
cmd.Dispose();
conn.Close();
conn.Dispose();
this.DropDownList2.DataSource = dt;
this.DropDownList2.DataTextField = "ClassName";
this.DropDownList2.DataValueField = "ClassId";
this.DropDownList2.DataBind();
}
protected void btnInsert_Click(object sender, EventArgs e)
{
string strcon = "data source=LOVE-PC\\SQLEXPRESSPC;initial catalog=News;user id=sa;password=admin";
using (SqlConnection conn = new SqlConnection(strcon))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
string newstitle = TxtTitle.Text;
string newscontent = TxtContent.Text;
string userid = DropDownList1.SelectedItem.Value;
string classid = DropDownList2.SelectedItem.Value;
cmd.CommandText = "insert into T_News(NewsTitle,NewsContent,NewsCreator,CreateTime,ClassId) VALUES(@newstitle,@newscontent,@newscreator,getdate(),@calssid)";
cmd.Parameters.AddWithValue("@newstitle", newstitle);
cmd.Parameters.AddWithValue("@newscontent", newscontent);
cmd.Parameters.AddWithValue("@newscreator", userid);
cmd.Parameters.AddWithValue("@calssid", classid);
if (cmd.ExecuteNonQuery()> 0)
{
Response.Redirect("NewsTypeUpdate.aspx?ispostback=1");
}
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
}
}
}
相关文章推荐
- 实现用户管理模块和新闻类别管理模块
- Servlet+JSP+MySQL实现用户管理模块之一、数据库表设计及创建
- Servlet+JSP+MySQL实现用户管理模块之二、实现用户注册
- Servlet+JSP+MySQL实现用户管理模块之五、实现用户删除与恢复
- 三、基础功能模块,用户类别管理——锁、EF并发处理、领域服务、应用服务的划分
- 权限管理系统(用户信息管理模块业务组件实现代码,带注解)
- Servlet+JSP+MySQL实现用户管理模块之七、实现用户信息更新和重置密码
- Servlet+JSP+MySQL实现用户管理模块之六、实现用户信息显示
- Servlet+JSP+MySQL实现用户管理模块之四、实现用户列表显示
- mysql+pam模块实现vsftp虚拟用户统一管理
- Servlet+JSP+MySQL实现用户管理模块之三、实现用户登录
- Vue + Element UI 实现权限管理系统 前端篇(十二):用户管理模块
- 把Shark的用户管理模块改为Hibernate实现
- 模块管理常规功能自定义系统的设计与实现(06--第一个用户模块)
- 模块管理常规功能自定义系统的设计与实现(37--终级阶段 综合查询[4])
- 信息系统开发平台OpenExpressApp - 使用CSLA类库实现用户管理
- Java Web入门之用Filter实现用户权限的管理
- 模块管理常规功能自定义系统的设计与实现(08--数据新增[一])
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(17)-注册用户功能的细节处理(各种验证)
- eShop电子商城的SSH实现的用户模块(1)登录和注册Bean(Version 1.0)