自动补全+汉字拼音双查(4)---添加文章功能
界面AddArticle.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddArticle.aspx.cs" Inherits="AddArticle" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="LB_Title" runat="server" Text="标题:"></asp:Label> <asp:TextBox ID="TB_Title" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="LB_Keyword" runat="server" Text="关键字:"></asp:Label> <asp:TextBox ID="TB_Keyword" runat="server"></asp:TextBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="内容:"></asp:Label> <br /> <asp:TextBox ID="TB_Content" runat="server" Height="107px" TextMode="MultiLine" Width="250px"></asp:TextBox> <br /> <br /> <br /> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="提交" /> </div> </form> </body> </html>
后台处理程序AddArticle.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using DB; using System.Data; using System.Data.SqlClient; public partial class AddArticle : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string titleyuanwen = TB_Title.Text; string titleshouzimu = NPinyin.Pinyin.GetInitials(titleyuanwen).ToUpper().Replace(" ", ""); string titlequanpin = NPinyin.Pinyin.GetPinyin(titleyuanwen).ToUpper().Replace(" ", ""); string keywordyuanwen = TB_Keyword.Text; string keywordshouzimu = NPinyin.Pinyin.GetInitials(keywordyuanwen).ToUpper().Replace(" ", ""); string keywordquanpin = NPinyin.Pinyin.GetPinyin(keywordyuanwen).ToUpper().Replace(" ", ""); string content = TB_Content.Text; addArticle(titleyuanwen, titleshouzimu, titlequanpin, keywordyuanwen, keywordshouzimu, keywordquanpin, content); } private void addArticle(string titleyuanwen, string titleshouzimu, string titlequanpin, string keywordyuanwen, string keywordshouzimu, string keywordquanpin, string content ) { DbHelper db = DbHelper.Instance(); SqlParameter[] sps = new SqlParameter[7]; sps[0] = new SqlParameter("@title", SqlDbType.NVarChar); sps[0].Value = titleyuanwen; sps[1] = new SqlParameter("@tshouzimu", SqlDbType.NVarChar); sps[1].Value = titleshouzimu; sps[2] = new SqlParameter("@tquanpin", SqlDbType.NVarChar); sps[2].Value = titlequanpin; sps[3] = new SqlParameter("@keyword", SqlDbType.NVarChar); sps[3].Value = keywordyuanwen; sps[4] = new SqlParameter("@kshouzimu", SqlDbType.NVarChar); sps[4].Value = keywordshouzimu; sps[5] = new SqlParameter("@kquanpin", SqlDbType.NVarChar); sps[5].Value = keywordquanpin; sps[6] = new SqlParameter("@content", SqlDbType.Text); sps[6].Value = content; db.ExecProc("AddArticle", sps); } }