您目前尚未登陆,请选择【登陆】或【注册
首页->新闻文章->明博静态新闻文章发布系统源码>>Admin/FileSubmit.aspx.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:明博静态新闻文章发布系统源码
当前文件:文件类型 MinbelNews/Admin/FileSubmit.aspx.cs打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Collections; 5using System.Web; 6using System.Web.Security; 7using System.Web.UI; 8using System.Web.UI.WebControls; 9using System.Web.UI.WebControls.WebParts; 10using System.Web.UI.HtmlControls; 11using System.IO; 12using System.Text; 13using System.Data.OleDb; 14public partial class Admin_FileSubmit : System.Web.UI.Page 15{ 16 CsharpBean cb = new CsharpBean(); 17 protected void Page_Load(object sender, EventArgs e) 18 { 19 if (!Page.IsPostBack) 20 { 21 22 } 23 } 24 protected void btnAdd_Click(object sender, EventArgs e) 25 { 26 string strTitle = txtTitle.Text.Trim(); 27 28 string strProfile = txtProfile.Text.Trim(); 29 string strInputTime = txtInputTime.Text.Trim(); 30 string strLimit = ddlLimit.SelectedValue.ToString(); 31 Int32 iTypeID = Int32.Parse(ddlTypeID.SelectedValue.ToString()); 32 Int32 iExampleID = Int32.Parse(ddlExampleID.SelectedValue.ToString()); 33 string strEditor = txtEditor.Text.Trim(); 34 string strAuthor = txtAuthor.Text.Trim(); 35 string strKeyWords = txtKeyWords.Text.Trim(); 36 37 38 if (strTitle == "" || strProfile=="") 39 { 40 Response.Write(@"<script language='javascript'>window.alert('标题和内容不能为空!');</script>"); 41 return; 42 } 43 // 44 45 46 //strProfile = strProfile.Replace(vbCrLf,"<br>"); 47 strProfile = strProfile.Replace("'","''"); 48 strProfile = FormatStr(strProfile); 49 //根据iExampleID,取出摸板 50 OleDbConnection ConnAcc = new OleDbConnection(cb.MyConn); //OleDb链接类的实例化 51 ConnAcc.Open();//打开数据库 52 string strSQL = "SELECT E_Memo FROM FileExample WHERE ID=" + iExampleID; 53 OleDbCommand cmd = new OleDbCommand(strSQL, ConnAcc);//创建Command命令对象 54 string strMemo = (string)cmd.ExecuteScalar(); 55 ConnAcc.Close();//关闭数据库 56 //Response.Write(strMemo); 57 //替换,给摸板加内容 58 strMemo = strMemo.Replace("T_TITLE", strTitle);//页面标题=文章标题 59 strMemo = strMemo.Replace("T_TIME", strInputTime); 60 strMemo = strMemo.Replace("T_KeyWords", strKeyWords); 61 strMemo = strMemo.Replace("T_Author", strAuthor); 62 strMemo = strMemo.Replace("T_Editor", strEditor); 63 strMemo = strMemo.Replace("T_CONTENT", strProfile); 64 strMemo = strMemo.Replace("T_TYPEID", iExampleID.ToString()); 65 66 //生成HTML文件 67 string Path = HttpContext.Current.Server.MapPath("~/Files/");//存放路径 68 string FileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";//生成文件名 69 Encoding code = Encoding.GetEncoding("gb2312"); 70 StreamWriter sw = null; 71 try 72 { 73 sw = new StreamWriter(Path + FileName, false, code); 74 sw.Write(strMemo); 75 sw.Flush(); 76 } 77 78 catch (Exception ex) 79 { 80 HttpContext.Current.Response.Write(ex.Message); 81 HttpContext.Current.Response.End(); 82 } 83 84 finally 85 { 86 sw.Close(); 87 } 88 //###############把基本信息插入数据库########################################## 89 try 90 { 91 //string strUrl = Path + FileName; 92 string strUrl = FileName; 93 OleDbConnection myConn = new OleDbConnection(cb.MyConn); 94 //queryStr书写向表插入记录的SQL命令;建立Adapter对象执行SQL命令 95 string queryStr = "insert into FileList(TypeID,Title,Url,Limit,InputTime,Author,Editor,KeyWords) values (" + iTypeID + ",'" + strTitle + "','" + strUrl + "','" + strLimit + "','" + DateTime.Parse(strInputTime) + "','" + strAuthor + "','" + strEditor + "','" + strKeyWords + "')"; 96 OleDbCommand cmd2 = new OleDbCommand(queryStr, myConn); 97 cmd2.Connection.Open();//打开数据库连接; 98 cmd2.ExecuteNonQuery();//执行SQL命令到数据库; 99 cmd2.Connection.Close();//关闭数据库连接 100 } 101 catch (Exception ex) 102 { 103 Response.Write("错误,错误原因:" + ex.Message); 104 Response.End(); 105 } 106 107 //############################################################ 108 109 } 110 111 //格式化HTML 112 private string FormatStr(string str) 113 { 114 string strContent = str.Replace("<", "&lt;"); 115 strContent = strContent.Replace(">","&gt;"); 116 //strContent = strContent.Replace(chr(13),"<br>"); 117 strContent = strContent.Replace("\r", "<br>"); 118 strContent = strContent.Replace(" ","&nbsp;"); 119 120 strContent = strContent.Replace("[isOK]","<img src="); 121 strContent = strContent.Replace("[b]","<b>"); 122 strContent = strContent.Replace("[red]","<font color=CC0000>"); 123 strContent = strContent.Replace("[big]","<font size=7>"); 124 strContent = strContent.Replace("[/isOK]","></img>"); 125 strContent = strContent.Replace("[/b]","</b>"); 126 strContent = strContent.Replace("[/red]","</font>"); 127 strContent = strContent.Replace("[/big]","</font>"); 128 return strContent; 129 } 130 131} 132
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:明博静态新闻文章发布系统源码
51Aspx.com 版权所有 CopyRight © 2000-2008. 京ICP备06046876号