AspxBoy.Com开放源码

1 // 2004-03-14,贺落伍者(im286.com)三周岁,
2 // 开放AspxBoy.Com目前源代码,大家相互学习。
3 // 靶子刚开始学.Net编码粗滥,请各位指正,谢谢!
4
5 //+++++++++++++++++++++++++++++++++++++++++++++++++++++
6 //
7 // CopyRight: www.AspxBoy.Com
8 // FileName: AspxBoy.cs
9 // Author Huobazi
10 // CreateDate:
11 // UpdateHistory:
12 //
13 //++++++++++++++++++++++++++++++++++++++++++++++++++++++
14
15 namespace AspxBoy.Com
16{
17 using System;
18 using System.Configuration;
19 using System.Data;
20 using System.Data.OleDb;
21 using System.IO;
22 using System.Text;
23 using System.Text.RegularExpressions;
24 using System.Web;
25 using System.Web.UI;
26 using System.Web.UI.WebControls;
27 using System.Web.UI.HtmlControls;
28 using Wuqi.Webdiyer;
29 /// ///
30 /// <summary>
31 /// 创建AspxBoy.Com命名空间
32 /// </summary>
33 /// ///
34 public class BasePage:Page
35{
36
37 public static string strConn
38{
39get
40{
41StringBuilder strResult = new StringBuilder(ConfigurationSettings.AppSettings[ "Provider"]);
42strResult.Append( "; ");
43strResult.Append( "Data Source = ");
44strResult.Append(HttpContext.Current.Request.PhysicalApplicationPath);
45strResult.Append( "//");
46strResult.Append(ConfigurationSettings.AppSettings[ "DataSource"]);
47 return strResult.ToString();
48}
49}
50 public string strSiteUrl
51{
52get
53{
54 string str = "http://www.AspxBoy.Com";
55 return str;
56}
57}
58 public string TransString( string str, int i)
59{
60 if (str.Length>i)
61{
62 return str.Substring(0,i)+ "...";
63}
64 else
65{
66 return str;
67}
68}
69 protected OleDbConnection Con = new OleDbConnection(strConn);
70 protected OleDbCommand Cmm;
71}
72 public class BaseControl : UserControl
73{
74 /// /
75 /// <summary>
76 /// 创建基类型BasePage
77 /// </summary>
78 /// /
79
80 public string strCopyRight
81{
82get
83{ string str;
84str = "Copyright (c) 2003-";
85str += (System.DateTime.Now.Year + 1).ToString();
86str += " by AspxBoy.Com. All Rights Reserved";
87 return str;
88}
89}
90 public string strSiteUrl
91{
92get
93{
94 string str = "http://www.AspxBoy.Com";
95 return str;
96}
97}
98 public string strSiteTitle
99{
100get
101{
102 string str= "--| .Net男孩社区 |--| AspxBoy.Com |----|提供大量.Net技术文章//.NET技术讨论区//大量Asp.Net//C#//VB.NET//WEB SERVICES//网站设计//平面设计//软件开发//教程//~~~Powered by Huo ba zi-----------------";
103 return str;
104}
105}
106 public string strMailWebmaster
107{
108get
109{
110 string str = "Webmaster@Aspxboy.com";
111 return str;
112}
113}
114 public static string strConn
115{
116get
117{
118StringBuilder strResult = new StringBuilder(ConfigurationSettings.AppSettings[ "Provider"]);
119strResult.Append( "; ");
120strResult.Append( "Data Source = ");
121strResult.Append(HttpContext.Current.Request.PhysicalApplicationPath);
122strResult.Append( "//");
123strResult.Append(ConfigurationSettings.AppSettings[ "DataSource"]);
124 return strResult.ToString();
125}
126
127}
128 public string strVersion
129{
130get
131{ string str = "1.0";
132 return str;
133}
134}
135 public string TransString( string str, int i)
136{
137 if (str.Length>i)
138{
139 return str.Substring(0,i)+ "...";
140}
141 else
142{
143 return str;
144}
145}
146 protected OleDbConnection Conn = new OleDbConnection(strConn);
147 protected OleDbCommand Cmd;
148}
149
150 public class Module : BasePage
151{
152 /// /
153 /// <summary>
154 /// Module类,实现动态添加Module控件
155 /// </summary>
156 ///
157 protected HtmlForm MyForm= new HtmlForm();
158 public string GetModuleName()
159{
160 string strM;
161 if (Request.QueryString[ "module"] == null || Request.QueryString[ "module"] == "")
162strM = "index";
163 else
164strM=Request.QueryString[ "module"];
165 return strM;
166}
167 public string GetModuleSkinPath( string ModulName)
168{
169 string strResult = null;
170StringBuilder strSkinFile = new StringBuilder(HttpContext.Current.Server.MapPath( "."));
171strSkinFile.Append( "//Module//");
172strSkinFile.Append(ModulName);
173strSkinFile.Append( "//");
174strSkinFile.Append(ModulName);
175strSkinFile.Append( ".ascx");
176 if (!File.Exists(strSkinFile.ToString()))
177strResult= "err";
178 else strResult = strSkinFile.ToString();
179 return strResult.Replace(HttpContext.Current.Server.MapPath( "."), ".");
180
181}
182 public void LoadModuleSkin( string strModuleSkinPath)
183{
184Control myCtrl = LoadControl(strModuleSkinPath);
185MyForm.Controls.Add(myCtrl);
186}
187 public void Page_Load( object sender,EventArgs e)
188{
189 string ModuleName = GetModuleName();
190 string ModulePath = GetModuleSkinPath(ModuleName);
191 if (ModulePath == "err")
192Response.Redirect( "./ErrorPages/GeneralError.htm?aspxerrorpath=default.aspx");
193 else
194{
195LoadModuleSkin(ModulePath);
196}
197}
198}
199
200 public class Article : BaseControl
201{
202 /// /
203 /// <summary>
204 /// Article类,实现文章页
205 /// </summary>
206 ///
207
208 protected Repeater repeater,ShowBigClass,ShowSmallClass,Top;
209 protected AspNetPager pager;
210 protected HtmlGenericControl Title = new HtmlGenericControl();
211 protected void InitBigClassShow()
212{
213Conn.Open();
214Cmd= new OleDbCommand( "select ID,BigClassName from RootClass",Conn);
215OleDbDataReader myReader=Cmd.ExecuteReader();
216ShowBigClass.DataSource=myReader;
217ShowBigClass.DataBind();
218myReader.Close();
219Conn.Close();
220}
221 protected void InitSmallClassShow()
222{
223 if((Request.QueryString[ "BigClassID"]!= null) && (Request.QueryString[ "BigClassID"]!= ""))
224{
225 string strsql= "select ID,TypeName from Type where BigID = ";
226strsql+=(Request.QueryString[ "BigClassID"]).ToString();
227Conn.Open();
228Cmd= new OleDbCommand(strsql,Conn);
229OleDbDataReader myReader=Cmd.ExecuteReader();
230ShowSmallClass.DataSource=myReader;
231ShowSmallClass.DataBind();
232myReader.Close();
233Conn.Close();
234}
235}
236 protected void InitTopShow()
237{
238 string strsql= "select Top 10 ArticleID,Title from ";
239strsql+= Where();
240strsql+= " order by Hits desc";
241Cmd= new OleDbCommand(strsql,Conn);
242Conn.Open();
243OleDbDataReader myReader=Cmd.ExecuteReader();
244Top.DataSource=myReader;
245Top.DataBind();
246myReader.Close();
247Conn.Close();
248}
249 protected string Where()
250{
251 string strWhere;
252 if(Request.QueryString[ "SmallClassID"] == null || Request.QueryString[ "SmallClassID"]== "")
253 if(Request.QueryString[ "BigClassID"] == null || Request.QueryString[ "BigClassID"]== "")
254strWhere= " Article ";
255 else
256{
257strWhere= " Article Where BigID = ";
258strWhere+=(Request.QueryString[ "BigClassID"]).ToString();
259}
260 else
261{
262strWhere= " Article Where SmallID = ";
263strWhere+=(Request.QueryString[ "SmallClassID"]).ToString();
264}
265 return strWhere;
266}
267 protected void BindData()
268{
269
270 string strsql= "select ArticleID,Title,AddDate from ";
271strsql+=Where();
272strsql+= " order by ArticleID desc";
273Cmd= new OleDbCommand(strsql,Conn);
274Conn.Open();
275OleDbDataAdapter adapter= new OleDbDataAdapter(Cmd);
276DataSet ds= new DataSet();
277adapter.Fill(ds,pager.PageSize*(pager.CurrentPageIndex-1),pager.PageSize, "Article");
278repeater.DataSource=ds.Tables[ "Article"].DefaultView;
279repeater.DataBind();
280Conn.Close();
281}
282 protected void InitPaging()
283{
284pager.ShowFirstLast= true;
285pager.ShowPrevNext= true;
286pager.ShowPageIndex= true;
287
288
289 //计算总记录数
290 string strsql= "select count(ArticleID) from ";
291strsql+=Where();
292Cmd= new OleDbCommand(strsql,Conn);
293Conn.Open();
294pager.RecordCount=(( int)Cmd.ExecuteScalar()<=0)?1:( int)Cmd.ExecuteScalar();
295Conn.Close();
296 //动态设置用户自定义文本内容
297pager.CustomInfoText= "文章总数:<font color=/"blue/"><b>"+pager.RecordCount.ToString()+ "</b></font>";
298pager.CustomInfoText+= " 总页数:<font color=/"blue/"><b>"+pager.PageCount.ToString()+ "</b></font>";
299pager.CustomInfoText+= " 当前页:<font color=/"red/"><b>"+pager.CurrentPageIndex.ToString()+ "</b></font>";
300}
301 protected void Change_Page( object sender,PageChangedEventArgs e)
302{
303pager.CurrentPageIndex=e.NewPageIndex;
304BindData();
305}
306 protected void Page_Load( object sender,EventArgs e)
307{
308 if(!Page.IsPostBack)
309{
310Title.InnerText=strSiteTitle;
311InitBigClassShow();
312InitSmallClassShow();
313InitTopShow();
314InitPaging();
315BindData();
316}
317}
318}
319 public class HotFile : BaseControl
320{
321 public Repeater Hot;
322 public void Page_Load( object sender,EventArgs e)
323{
324 string strsql= "select Top 15 ArticleID,Title,Hits from Article";
325strsql+= " order by Hits desc";
326Cmd= new OleDbCommand(strsql,Conn);
327Conn.Open();
328OleDbDataReader myReader=Cmd.ExecuteReader();
329Hot.DataSource=myReader;
330Hot.DataBind();
331myReader.Close();
332Conn.Close();
333}
334}
335 public class NewArticle : BaseControl
336{
337 string Repeater RPNewArticle;
338 public void Page_Load( object sender,EventArgs e)
339{
340 string strsql= "select Top 15 ArticleID,Title from Article";
341strsql+= " order by AddDate desc";
342Cmd= new OleDbCommand(strsql,Conn);
343Conn.Open();
344OleDbDataReader myReader=Cmd.ExecuteReader();
345RPNewArticle.DataSource=myReader;
346RPNewArticle.DataBind();
347myReader.Close();
348Conn.Close();
349}
350}
351 public class ShowArticle : BasePage
352{
353 public void Updatehits( string id)
354{
355 string str= "update Article set Hits = Hits+1 Where ArticleID= ";
356str+=id;
357Cmm = new OleDbCommand(str,Con);
358Cmm.ExecuteNonQuery();
359}
360 public void Page_Load( object sender,EventArgs e)
361{
362 string url,strsql;
363 if (!Page.IsPostBack)
364{
365 if((Request.QueryString[ "ID"]== null)||(Request.QueryString[ "ID"]== ""))
366Response.Redirect( "./ErrorPages/GeneralError.htm?aspxerrorpath=ShowArticle.aspx");
367 else
368{
369strsql= "select FileName from Article where ArticleID= ";
370strsql+=(Request.QueryString[ "ID"]).ToString();
371Con.Open();
372Cmm = new OleDbCommand(strsql,Con);
373OleDbDataReader dr = Cmm.ExecuteReader(CommandBehavior.SingleRow);
374 if(dr.Read())
375{ url=strSiteUrl;
376url+=dr[ "FileName"].ToString();
377dr.Close();
378Updatehits((Request.QueryString[ "ID"]).ToString());
379}
380 else url= "./ErrorPages/GeneralError.htm?aspxerrorpath=ShowArticle.aspx";
381Con.Close();
382Response.Redirect(url);
383}
384}
385}
386}
387 public class Admin : Module
388{
389 protected new void Page_Load( object sender,EventArgs e)
390{
391
392 string ModuleName = GetModuleName();
393 string ModulePath = GetModuleSkinPath(ModuleName);
394 if (ModulePath == "err")
395Response.Redirect( "../ErrorPages/GeneralError.htm?aspxerrorpath=AdminCenter/default.aspx");
396 else
397{
398LoadModuleSkin(ModulePath);
399}
400
401
402}
403}
404
405
406 /// 文章分类管理/
407 public class ArticleClass : BaseControl
408{
409 protected TextBox txtBigClassAdd,txtSmallClassAdd,txtBigClassEdit,txtSmallClassEdit;
410 protected Button btnBigClassAdd,btnBigClassEdit,btnBigClassDelete,btnSmallClassAdd,btnSmallClassEdit,btnSmallClassDelete;
411 protected DropDownList BigClassListEdit,SmallClassListEdit,BigClassListDelete,SmallClassListDelete;
412 protected DropDownList BigClassList= new DropDownList();
413 protected void Page_Load(Object sender,EventArgs e)
414{
415 if(Session[ "Admin"] != null)
416{
417BigClassDropDownListInit();
418SmallClassDropDownListInit();
419}
420 else
421Response.Redirect( "Default.aspx?Module=Login");
422}
423 protected void btnBigClassAdd_Click(Object sender,EventArgs e)
424{
425 string strInsert= "insert into RootClass(BigClassName) Values('"+txtBigClassAdd.Text+ "')";
426Conn.Open();
427OleDbCommand commTest= new OleDbCommand( "select count(*) from RootClass where BigClassName='"+txtBigClassAdd.Text+ "'",Conn);
428 int i= int.Parse(commTest.ExecuteScalar().ToString());
429Conn.Close();
430 if(i>0)
431{
432Response.Write( "<script>alert('已有同名主分类存在!');</script>");
433}
434 else
435{
436Conn.Open();
437OleDbCommand commAdd= new OleDbCommand(strInsert,Conn);
438commAdd.ExecuteNonQuery();
439
440 string strSelect= "select ID from RootClass where BigClassName='"+txtBigClassAdd.Text+ "'";
441OleDbCommand commDir= new OleDbCommand(strSelect,Conn);
442 string BigClassDir=commDir.ExecuteScalar().ToString();
443Conn.Close();
444
445Directory.CreateDirectory(HttpContext.Current.Request.PhysicalApplicationPath+ "//Files//"+BigClassDir);
446Response.Write( "<script>alert('主分类添加成功!');</script>");
447
448}
449BigClassDropDownListInit();
450SmallClassDropDownListInit();
451}
452 protected void btnSmallClassAdd_Click(Object sender,EventArgs e)
453{
454Conn.Open();
455 string strInsert= "insert into Type(TypeName,BigClassName,BigID) Values('"+txtSmallClassAdd.Text+ "','"+BigClassList.SelectedItem.Text+ "','"+BigClassList.SelectedItem.Value+ "')";
456OleDbCommand commTest= new OleDbCommand( "select * from Type where TypeName='"+txtSmallClassAdd.Text+ "'",Conn);
457 int i=commTest.ExecuteNonQuery();
458Conn.Close();
459 if(i>0)
460Response.Write( "<script>alert('已有同名二级分类存在!');</script>");
461 else
462{
463Conn.Open();
464OleDbCommand commAdd= new OleDbCommand(strInsert,Conn);
465commAdd.ExecuteNonQuery();
466
467 string strSelect= "select ID from Type Where TypeName='"+txtSmallClassAdd.Text+ "'";
468OleDbCommand commDir= new OleDbCommand(strSelect,Conn);
469 string SmallClassDir=commDir.ExecuteScalar().ToString();
470Conn.Close();
471
472Directory.CreateDirectory(HttpContext.Current.Request.PhysicalApplicationPath+ "//Files//"+ "//"+BigClassList.SelectedItem.Value+ "//"+SmallClassDir);
473Response.Write( "<script>alert('二级分类添加成功!');</script>");
474
475}
476BigClassDropDownListInit();
477SmallClassDropDownListInit();
478}
479
480 protected void btnBigClassEdit_Click(Object sender,EventArgs e)
481{
482 string strUpDate= "update RootClass set BigClassName='"+txtBigClassEdit.Text+ "' where BigClassName='"+BigClassListEdit.SelectedItem.Text+ "'";
483 string strUpDateArticle= "update Article set BigClassName='"+txtBigClassEdit.Text+ "' where BigClassName='"+BigClassListEdit.SelectedItem.Text+ "'";
484OleDbCommand commTest= new OleDbCommand( "select count(*) from RootClass where BigClassName='"+txtBigClassEdit.Text+ "'",Conn);
485Conn.Open();
486 int i= int.Parse(commTest.ExecuteScalar().ToString());
487Conn.Close();
488 if(i>0)
489{
490Response.Write( "<script>alert('已有同名主分类存在!');</script>");
491}
492 else
493{
494OleDbCommand comm= new OleDbCommand(strUpDate,Conn);
495Conn.Open();
496comm.ExecuteNonQuery();
497Conn.Close();
498OleDbCommand comm2= new OleDbCommand(strUpDateArticle,Conn);
499Conn.Open();
500comm2.ExecuteNonQuery();
501Conn.Close();
502Response.Write( "<script>alert('主分类修改成功!');</script>");
503}
504BigClassDropDownListInit();
505}
506 protected void btnSmallClassEdit_Click(Object sender,EventArgs e)
507{
508 string strUpDate= "update Type set TypeName='"+txtSmallClassEdit.Text+ "' where TypeName='"+SmallClassListEdit.SelectedItem.Text+ "'";
509 string strUpDateArticle= "update Article set Type='"+txtSmallClassEdit.Text+ "' where Type='"+SmallClassListEdit.SelectedItem.Text+ "'";
510OleDbCommand commTest= new OleDbCommand( "select count(*) from Type where TypeName='"+txtSmallClassEdit.Text+ "'",Conn);
511Conn.Open();
512 int i= int.Parse(commTest.ExecuteScalar().ToString());
513Conn.Close();
514 if(i>0)
515{
516Response.Write( "<script>alert('已有同名二级分类存在!');</script>");
517}
518 else
519{
520OleDbCommand comm= new OleDbCommand(strUpDate,Conn);
521Conn.Open();
522comm.ExecuteNonQuery();
523Conn.Close();
524
525OleDbCommand comm2= new OleDbCommand(strUpDateArticle,Conn);
526Conn.Open();
527comm2.ExecuteNonQuery();
528Conn.Close();
529Response.Write( "<script>alert('二级分类修改成功!');</script>");
530}
531SmallClassDropDownListInit();
532}
533 protected void btnBigClassDelete_Click(Object sender,EventArgs e)
534{
535 string BigBak=BigClassListDelete.SelectedItem.Text;
536 string BigClassDir=BigClassListDelete.SelectedItem.Value;
537 string strDelete= "delete from RootClass where BigClassName='"+BigBak+ "'";
538Conn.Open();
539OleDbCommand comm= new OleDbCommand(strDelete,Conn);
540comm.ExecuteNonQuery();
541Conn.Close();
542
543Directory.Delete(HttpContext.Current.Request.PhysicalApplicationPath+ "//Files//"+BigClassDir, true);
544
545 string strDeleteArticle= "delete from Article where BigClassName= '"+BigBak+ "'";
546OleDbCommand comm3= new OleDbCommand(strDeleteArticle,Conn);
547Conn.Open();
548comm3.ExecuteNonQuery();
549Conn.Close();
550
551 string strDeleteSmall= "delete from Type where BigClassName='"+BigBak+ "'";
552OleDbCommand comm2= new OleDbCommand(strDeleteSmall,Conn);
553Conn.Open();
554comm2.ExecuteNonQuery();
555Conn.Close();
556
557Response.Write( "<script>alert('所选主分类及其下的二级分类和文章均已删除!');</script>");
558
559BigClassDropDownListInit();
560SmallClassDropDownListInit();
561}
562
563 protected void btnSmallClassDelete_Click(Object sender,EventArgs e)
564{
565 string SmallBak=SmallClassListDelete.SelectedItem.Text;
566 string BigDir;
567
568 string strSelect= "select BigID from Type Where TypeName='"+SmallBak+ "'";
569OleDbCommand comm3= new OleDbCommand(strSelect,Conn);
570Conn.Open();
571OleDbDataReader rd=comm3.ExecuteReader(CommandBehavior.SingleRow);
572 if (rd.Read())
573{
574BigDir=rd[ "BigID"].ToString();
575Directory.Delete(HttpContext.Current.Request.PhysicalApplicationPath+ "//Files//"+BigDir+ "//"+SmallClassListDelete.SelectedItem.Value, true);
576}
577rd.Close();
578Conn.Close();
579
580 string strDelete= "delete from Type where TypeName='"+SmallBak+ "'";
581OleDbCommand comm= new OleDbCommand(strDelete,Conn);
582Conn.Open();
583comm.ExecuteNonQuery();
584Conn.Close();
585
586 string strDeleteArticle= "delete from Article where Type='"+SmallBak+ "'";
587OleDbCommand comm2= new OleDbCommand(strDeleteArticle,Conn);
588Conn.Open();
589comm2.ExecuteNonQuery();
590Conn.Close();
591
592Response.Write( "<script>alert('所选二级分类及其下的文章均已删除!');</script>");
593SmallClassDropDownListInit();
594}
595
596 protected void BigClassDropDownListInit()
597{
598InitList(BigClassList, "select ID,BigClassName from RootClass order by BigClassName", "BigClassName", "ID");
599InitList(BigClassListEdit, "select ID,BigClassName from RootClass order by BigClassName", "BigClassName", "ID");
600InitList(BigClassListDelete, "select ID,BigClassName from RootClass order by BigClassName", "BigClassName", "ID");
601
602}
603 protected void SmallClassDropDownListInit()
604{
605InitList(SmallClassListEdit, "select ID,TypeName from Type order by BigClassName", "TypeName", "ID");
606InitList(SmallClassListDelete, "select ID,TypeName from Type order by BigClassName", "TypeName", "ID");
607
608}
609 protected void InitList(DropDownList list, string strsql, string TextField, string ValueField)
610{
611Conn.Open();
612Cmd = new OleDbCommand(strsql,Conn);
613OleDbDataReader Rd = Cmd.ExecuteReader();
614list.DataSource=Rd;
615list.DataTextField=TextField;
616list.DataValueField=ValueField;
617list.DataBind();
618list.SelectedIndex = 0;
619Rd.Close();
620Conn.Close();
621}
622
623}
624
625 public class AddArticle : BaseControl
626{
627 protected TextBox txtArticleTitle,txtKeyWords,txtAuthorName,txtWhere,txtContent;
628 protected DropDownList BigClassList,SmallClassList,TemplateList;
629 protected Button btnAritcleSubmit,btnReset;
630
631 protected void Page_Load(Object sender,EventArgs e)
632{
633 if(Session[ "Admin"] != null)
634{
635BigClassDropDownListInit();
636SmallClassDropDownListInit();
637TemplateListInit();
638}
639 else
640Response.Redirect( "Default.aspx?Module=Login");
641}
642 protected void BigClassDropDownListInit()
643{
644Conn.Open();
645OleDbCommand commBigClass= new OleDbCommand( "select BigClassName,ID from RootClass order by ID",Conn);
646OleDbDataReader MyReaderBigClass111=commBigClass.ExecuteReader();
647BigClassList.DataSource=MyReaderBigClass111;
648BigClassList.DataTextField= "BigClassName";
649BigClassList.DataValueField= "ID";
650BigClassList.DataBind();
651MyReaderBigClass111.Close();
652Conn.Close();
653}
654
655
656 protected void BigClassList_SelectedIndexChanged(Object sender,System.EventArgs e)
657{
658SmallClassList.Items.Clear();
659SmallClassDropDownListInit();
660}
661 protected void SmallClassDropDownListInit()
662{
663Conn.Open();
664 string strCom= "select TypeName,ID from Type ";
665strCom+= " Where BigClassName ='"+BigClassList.SelectedItem.Text+ "' ";
666strCom+= " order by ID";
667 try
668{
669OleDbCommand commSmallClass= new OleDbCommand(strCom,Conn);
670OleDbDataReader MyReaderSmallClass1=commSmallClass.ExecuteReader();
671SmallClassList.DataSource=MyReaderSmallClass1;
672SmallClassList.DataTextField= "TypeName";
673SmallClassList.DataValueField= "ID";
674SmallClassList.DataBind();
675MyReaderSmallClass1.Close();
676}
677
678 catch
679{
680Response.Write( "<script>alert('异常错误');</script>");
681}
682Conn.Close();
683}
684 protected void TemplateListInit()
685{
686Conn.Open();
687OleDbCommand comm= new OleDbCommand( "select ID,TemplateName from Template order by ID",Conn);
688OleDbDataReader MyReader=comm.ExecuteReader();
689TemplateList.DataSource=MyReader;
690TemplateList.DataTextField= "TemplateName";
691TemplateList.DataValueField= "ID";
692TemplateList.DataBind();
693MyReader.Close();
694Conn.Close();
695}
696 protected void btnArticleSubmit_Click(Object sender,EventArgs e)
697{
698 string Year,Month,Today,Hour,Minute,Secend;
699Year=System.DateTime.Now.Year.ToString();
700Month=System.DateTime.Now.Month.ToString();
701Today=System.DateTime.Today.Day.ToString();
702Hour=System.DateTime.Now.Hour.ToString();
703Minute=System.DateTime.Now.Minute.ToString();
704Secend=System.DateTime.Now.Second.ToString();
705 string FileName= "//Files//"+BigClassList.SelectedItem.Value+ "//"+SmallClassList.SelectedItem.Value+ "//"+Year+Month+Today+Hour+Minute+Secend+ ".htm";
706 string FilePath=HttpContext.Current.Request.PhysicalApplicationPath+FileName;
707
708 //string strInsert="Insert into Article(Title,FileName,BigClassName,BigID,Type,SmallID,Author,WhereFrom,ArticleContent,TemplateName) Values('"+txtArticleTitle.Text+"','"+FileName+"','"+BigClassList.SelectedItem.Text+"','"+BigClassList.SelectedItem.Value+"','"+SmallClassList.SelectedItem.Text+"','"+SmallClassList.SelectedItem.Value+"','"+txtAuthorName.Text+"','"+txtWhere.Text+"','"+txtContent.Text+"','"+TemplateList.SelectedItem.Text+"')";
709 string strInsert= "Insert into Article(Title,FileName,BigClassName,BigID,Type,SmallID,Author,WhereFrom,ArticleContent,TemplateName) Values(@Title,@FileName,@BigClassName,@BigID,@Type,@SmallID,@Author,@WhereFrom,@ArticleContent,@TemplateName)";
710Conn.Open();
711OleDbCommand comm= new OleDbCommand(strInsert,Conn);
712 //添加参数
713comm.Parameters.Add( new OleDbParameter( "@Title",OleDbType.Char));
714comm.Parameters.Add( new OleDbParameter( "@FileName",OleDbType.Char));
715comm.Parameters.Add( new OleDbParameter( "@BigClassName",OleDbType.Char));
716comm.Parameters.Add( new OleDbParameter( "@BigID",OleDbType.Integer));
717comm.Parameters.Add( new OleDbParameter( "@Type",OleDbType.Char));
718comm.Parameters.Add( new OleDbParameter( "@SmallID",OleDbType.Integer));
719comm.Parameters.Add( new OleDbParameter( "@Author",OleDbType.Char));
720comm.Parameters.Add( new OleDbParameter( "@WhereFrom",OleDbType.Char));
721comm.Parameters.Add( new OleDbParameter( "@ArticleContent",OleDbType.VarChar));
722comm.Parameters.Add( new OleDbParameter( "@TemplateName",OleDbType.Char));
723 //参数赋值
724comm.Parameters[ "@Title"].Value=txtArticleTitle.Text;
725comm.Parameters[ "@FileName"].Value=FileName;
726comm.Parameters[ "@BigClassName"].Value=BigClassList.SelectedItem.Text;
727comm.Parameters[ "@BigID"].Value=BigClassList.SelectedItem.Value;
728comm.Parameters[ "@Type"].Value=SmallClassList.SelectedItem.Text;
729comm.Parameters[ "@SmallID"].Value=SmallClassList.SelectedItem.Value;
730comm.Parameters[ "@Author"].Value=txtAuthorName.Text;
731comm.Parameters[ "@WhereFrom"].Value=txtWhere.Text;
732comm.Parameters[ "@ArticleContent"].Value=txtContent.Text;
733comm.Parameters[ "@TemplateName"].Value=TemplateList.SelectedItem.Text;
734 //执行操作
735comm.ExecuteNonQuery();
736
737 //生成HTML文件。。,其他功能为实现
738 string strSelectTemplate= "select TemplateContent from Template Where TemplateName='"+TemplateList.SelectedItem.Text+ "'";
739OleDbCommand commTemplate= new OleDbCommand(strSelectTemplate,Conn);
740 string HtmlContent=( string)commTemplate.ExecuteScalar(); //读取所选模板的内容
741 string InsertContent=txtContent.Text;
742InsertContent=InsertContent.Replace( "<", "<");
743InsertContent=InsertContent.Replace( ">", ">");
744InsertContent=ToUbb(InsertContent);
745InsertContent=InsertContent.Replace( "/r/n", "<br>");
746Conn.Close();
747HtmlContent=HtmlContent.Replace( "Article-RootClass", "<a href=../../../Default.aspx?Module=Article&BigClassID="+BigClassList.SelectedItem.Value+ ">"+BigClassList.SelectedItem.Text+ "</a>");
748HtmlContent=HtmlContent.Replace( "Article-Type", "<a href=../../../Default.aspx?Module=Article&BigClassID="+BigClassList.SelectedItem.Value+ "&SmallClassID="+SmallClassList.SelectedItem.Value+ ">"+SmallClassList.SelectedItem.Text+ "</a>");
749
750HtmlContent=HtmlContent.Replace( "Article-Title", ""+txtArticleTitle.Text+ "");
751HtmlContent=HtmlContent.Replace( "Article-Author", ""+txtAuthorName.Text+ "");
752HtmlContent=HtmlContent.Replace( "Article-WhereFrom", ""+txtWhere.Text+ "");
753HtmlContent=HtmlContent.Replace( "Article-Content", ""+InsertContent+ "");
754FileStream fs= new FileStream(FilePath,FileMode.OpenOrCreate,FileAccess.ReadWrite);
755StreamWriter w= new StreamWriter(fs,System.Text.Encoding.GetEncoding( "GB2312"));
756w.Write(HtmlContent);
757w.Close();
758fs.Close();
759Response.Write( "<script>alert('文章添加成功');</script>");
760 /// 判断是否需要继续添加文章
761}
762
763 protected static string ToUbb( string str) //ubb转换函数
764{
765
766Regex my= new Regex(@ "(/[IMG/])(.[^/[]*)(/[//IMG/])",RegexOptions.IgnoreCase);
767str=my.Replace(str,@ "<a href=" "$2" " target=_blank><IMG SRC=" "$2" " border=0 alt=?????????? οnlοad=" "javascript:if(this.width>screen.width*0.6) {this.resized=true; this.width=screen.width*0.6; this.alt='Click here to open new window';}" " οnmοuseοver=" "if(this.resized) this.style.cursor='hand';" " οnclick=" "if(this.resized) window.open(" "$2" ");" "></a>");
768
769my= new Regex(@ "/[DIR=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//DIR]",RegexOptions.IgnoreCase);
770str=my.Replace(str,@ "<object classid=clsid:166B1BCA-3F9C-11CF-8075-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=7,0,2,0 width=$1 height=$2><param name=src value=$3><embed src=$3 pluginspage=http://www.macromedia.com/shockwave/download/ width=$1 height=$2></embed></object>");
771
772my= new Regex(@ "/[QT=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//QT]",RegexOptions.IgnoreCase);
773str=my.Replace(str,@ "<embed src=$3 width=$1 height=$2 autoplay=true loop=false controller=true playeveryframe=false cache=false scale=TOFIT bgcolor=#000000 kioskmode=false targetcache=false pluginspage=http://www.apple.com/quicktime/>");
774
775
776my= new Regex(@ "/[MP=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//MP]",RegexOptions.IgnoreCase);
777str=my.Replace(str,@ "<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=$1 height=$2 ><param name=ShowStatusBar value=-1><param name=Filename value=$3><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=$3 width=$1 height=$2></embed></object>");
778
779my= new Regex(@ "/[RM=*([0-9]*),*([0-9]*)/](.[^/[]*)/[//RM]",RegexOptions.IgnoreCase);
780str=my.Replace(str,@ "<OBJECT classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA class=OBJECT id=RAOCX width=$1 height=$2><PARAM NAME=SRC VALUE=$3><PARAM NAME=CONSOLE VALUE=Clip1><PARAM NAME=CONTROLS VALUE=imagewindow><PARAM NAME=AUTOSTART VALUE=true></OBJECT><br/><OBJECT classid=CLSID:CFCDAA03-8BE4-11CF-B84B-0020AFBBCCFA height=32 id=video2 width=$1><PARAM NAME=SRC VALUE=$3><PARAM NAME=AUTOSTART VALUE=-1><PARAM NAME=CONTROLS VALUE=controlpanel><PARAM NAME=CONSOLE VALUE=Clip1></OBJECT>");
781
782my= new Regex(@ "(/[FLASH/])(.[^/[]*)(/[//FLASH/])",RegexOptions.IgnoreCase);
783str=my.Replace(str,@ "<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=" "$2" "><PARAM NAME=quality VALUE=high><embed src=" "$2" " quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>$2</embed></OBJECT>");
784
785my= new Regex(@ "(/[ZIP/])(.[^/[]*)(/[//ZIP/])",RegexOptions.IgnoreCase);
786str=my.Replace(str,@ "<br/><IMG SRC=pic/zip.gif border=0> <a href=" "$2" ">???????</a>");
787
788my= new Regex(@ "(/[RAR/])(.[^/[]*)(/[//RAR/])",RegexOptions.IgnoreCase);
789str=my.Replace(str,@ "<br/><IMG SRC=pic/rar.gif border=0> <a href=" "$2" ">???????</a>");
790
791 //my=new Regex(@"(/[UPLOAD=(.[^/[]*)/])(.[^/[]*)(/[//UPLOAD/])",RegexOptions.IgnoreCase);
792 //str=my.Replace(str,@"<br/><IMG SRC=""pic/$2.gif"" border=0>?????????:<br/><A HREF=""$3"" TARGET=_blank><IMG SRC=""$3"" border=0 alt=?????????? οnlοad=""javascript:if(this.width>screen.width-333)this.width=screen.width-333""></A>");
793
794my= new Regex(@ "(/[URL/])(http:.[^/[]*)(/[//URL/])",RegexOptions.IgnoreCase);
795str=my.Replace(str,@ "<A HREF=" "$2" " TARGET=_blank>$2</A>");
796
797my= new Regex(@ "(/[URL/])(.[^/[]*)(/[//URL/])",RegexOptions.IgnoreCase);
798str=my.Replace(str,@ "<A HREF=" "http://$2" " TARGET=_blank>$2</A>");
799
800my= new Regex(@ "(/[URL=(http:.[^/[]*)/])(.[^/[]*)(/[//URL/])",RegexOptions.IgnoreCase);
801str=my.Replace(str,@ "<A HREF=" "$2" " TARGET=_blank>$3</A>");
802
803my= new Regex(@ "(/[URL=(.[^/[]*)/])(.[^/[]*)(/[//URL/])",RegexOptions.IgnoreCase);
804str=my.Replace(str,@ "<A HREF=" "http://$2" " TARGET=_blank>$3</A>");
805
806my= new Regex(@ "(/[EMAIL/])(/S+/@.[^/[]*)(/[//EMAIL/])",RegexOptions.IgnoreCase);
807str=my.Replace(str,@ "<A HREF=" "mailto:$2" ">$2</A>");
808
809my= new Regex(@ "(/[EMAIL=(/S+/@.[^/[]*)/])(.[^/[]*)(/[//EMAIL/])",RegexOptions.IgnoreCase);
810str=my.Replace(str,@ "<A HREF=" "mailto:$2" " TARGET=_blank>$3</A>");
811
812my= new Regex(@ "^(HTTP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
813str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
814
815my= new Regex(@ "(HTTP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
816str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
817
818
819my= new Regex(@ "[^>=" "](HTTP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
820str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
821
822my= new Regex(@ "^(NEWS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
823str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
824
825my= new Regex(@ "(NEWS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
826str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
827
828
829my= new Regex(@ "[^>=" "](NEWS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
830str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
831
832my= new Regex(@ "^(HTTPS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
833str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
834
835my= new Regex(@ "(HTTPS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
836str=my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
837
838
839my= new Regex(@ "[^>=" "](HTTPS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
840str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
841
842my= new Regex(@ "^(FTP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
843str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
844
845my= new Regex(@ "(FTP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
846str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
847
848my= new Regex(@ "[^>=" "](FTP://[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
849str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
850
851my= new Regex(@ "^(RTSP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
852str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
853
854my= new Regex(@ "(RTSP://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
855str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
856
857my= new Regex(@ "[^>=" "](RTSP://[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
858str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
859my= new Regex(@ "^(MMS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
860str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
861
862my= new Regex(@ "(MMS://[A-Za-z0-9/./=/?%/-&_~`@':+!]+)$",RegexOptions.IgnoreCase);
863str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
864
865my= new Regex(@ "[^>=" "](MMS://[A-Za-z0-9/.//=/?%/-&_~`@':+!]+)",RegexOptions.IgnoreCase);
866str = my.Replace(str,@ "<a target=_blank href=$1>$1</a>");
867
868my= new Regex(@ "(/[HTML/])(.[^/[]*)(/[//HTML/])",RegexOptions.IgnoreCase);
869str=my.Replace(str,@ "<table width='100%' border='0' cellspacing='0' cellpadding='6' ><td align='center'><table width=85% border='0' cellspacing='0' bgcolor='#E7E7E7'><td><b>以下内容为HTML代码:</b><br/>$2</td></table></td></table>");
870
871my= new Regex(@ "(/[CODE/])(.[^/[]*)(/[//CODE/])",RegexOptions.IgnoreCase);
872str=my.Replace(str,@ "<table width='100%' border='0' cellspacing='0' cellpadding='6' ><td align='center'><table width=85% border='0' cellspacing='0' bgcolor='#E7E7E7'><td><b>以下内容为程序代码:</b><br/>$2<td></table></td></table>");
873
874my= new Regex(@ "(/[COLOR=(.[^/[]*)/])(.[^/[]*)(/[//COLOR/])",RegexOptions.IgnoreCase);
875str=my.Replace(str,@ "<font COLOR=$2>$3</font>");
876
877my= new Regex(@ "(/[FACE=(.[^/[]*)/])(.[^/[]*)(/[//FACE/])",RegexOptions.IgnoreCase);
878str=my.Replace(str,@ "<font FACE=$2>$3</font>");
879
880my= new Regex(@ "(/[ALIGN=(.[^/[]*)/])(.*)(/[//ALIGN/])",RegexOptions.IgnoreCase);
881str=my.Replace(str,@ "<div ALIGN=$2>$3</div>");
882
883my= new Regex(@ "(/[QUOTE/])(.*)(/[//QUOTE/])",RegexOptions.IgnoreCase);
884str=my.Replace(str,@ "<table cellpadding=0 cellspacing=0 border=0 WIDTH=94% bgcolor=#000000 align=center><tr><td><table width=100% cellpadding=5 cellspacing=1 border=0><TR><TD BGCOLOR=''>$2</table></table><br/>");
885
886my= new Regex(@ "(/[MOVE/])(.*)(/[//MOVE/])",RegexOptions.IgnoreCase);
887str=my.Replace(str,@ "<MARQUEE scrollamount=3>$2</marquee>");
888
889my= new Regex(@ "/[GLOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//GLOW]",RegexOptions.IgnoreCase);
890str=my.Replace(str,@ "<table width=$1 style=" "filter:glow(color=$2, strength=$3)" ">$4</table>");
891
892my= new Regex(@ "/[SHADOW=*([0-9]*),*(#*[a-z0-9]*),*([0-9]*)/](.[^/[]*)/[//SHADOW]",RegexOptions.IgnoreCase);
893str=my.Replace(str,@ "<table width=$1 style=" "filter:shadow(color=$2, strength=$3)" ">$4</table>");
894
895my= new Regex(@ "(/[I/])(.[^/[]*)(/[//I/])",RegexOptions.IgnoreCase);
896str=my.Replace(str,@ "<i>$2</i>");
897
898my= new Regex(@ "(/[B/])(.[^/[]*)(/[//U/])",RegexOptions.IgnoreCase);
899str=my.Replace(str,@ "<u>$2</u>");
900
901my= new Regex(@ "(/[B/])(.[^/[]*)(/[//B/])",RegexOptions.IgnoreCase);
902str=my.Replace(str,@ "<b>$2</b>");
903
904my= new Regex(@ "(/[FLY/])(.[^/[]*)(/[//FLY/])",RegexOptions.IgnoreCase);
905str=my.Replace(str,@ "<marquee>$2</marquee>");
906
907my= new Regex(@ "(/[SIZE=1/])(.[^/[]*)(/[//SIZE/])",RegexOptions.IgnoreCase);
908str=my.Replace(str,@ "<font size=1>$2</font>");
909
910my= new Regex(@ "(/[SIZE=2/])(.[^/[]*)(/[//SIZE/])",RegexOptions.IgnoreCase);
911str=my.Replace(str,@ "<font size=2>$2</font>");
912
913my= new Regex(@ "(/[SIZE=3/])(.[^/[]*)(/[//SIZE/])",RegexOptions.IgnoreCase);
914str=my.Replace(str,@ "<font size=3>$2</font>");
915
916my= new Regex(@ "(/[SIZE=4/])(.[^/[]*)(/[//SIZE/])",RegexOptions.IgnoreCase);
917str=my.Replace(str,@ "<font size=4>$2</font>");
918
919my= new Regex(@ "(/[CENTER/])(.[^/[]*)(/[//CENTER/])",RegexOptions.IgnoreCase);
920str=my.Replace(str,@ "<center>$2</center>");
921
922 return(str);
923}
924
925 protected AddArticle()
926{
927}
928}
929
930 public class EditArticle:Article
931{
932 protected LinkButton btnEdit,btnDelete;
933 protected new void Page_Load( object sender, EventArgs e)
934{
935 if(Session[ "Admin"] != null)
936{
937 if(!Page.IsPostBack)
938{
939Title.InnerText=strSiteTitle;
940InitBigClassShow();
941InitSmallClassShow();
942InitPaging();
943BindData();
944}
945}
946 else
947Response.Redirect( "Default.aspx?Module=Login");
948}
949 protected void AdminButton_Click( object sender, CommandEventArgs e)
950{
951 string strCommand;
952 if(e.CommandName== "Delete")
953{ string strSelect= "select FileName from Article where ArticleID= "+e.CommandArgument;
954strCommand= "delete from Article Where ArticleID= "+e.CommandArgument;
955OleDbCommand comm1= new OleDbCommand(strSelect,Conn);
956Conn.Open();
957OleDbDataReader rd=comm1.ExecuteReader(CommandBehavior.SingleRow);
958
959 if(rd.Read())
960{
961 string FilePath=HttpContext.Current.Request.PhysicalApplicationPath+rd[ "FileName"].ToString();
962 try
963{
964File.Delete(FilePath);
965}
966 catch
967{
968}
969}
970rd.Close();
971OleDbCommand comm2= new OleDbCommand(strCommand,Conn);
972comm2.ExecuteNonQuery();
973Conn.Close();
974Response.Redirect( "Default.aspx?module=EditArticle");
975}
976 if(e.CommandName== "Edit")
977{
978 string url= "Default.aspx?module=UpdateArticle&ID=" +(e.CommandArgument).ToString();
979Response.Write( "<script language='javascript'>window.open('"+url+ "');</script>");
980}
981}
982}
983 public class UpdateArticle:AddArticle
984{
985 protected string ArticleID;
986 protected static string FileName;
987 protected DataRow dr;
988 protected Button btnArticleEdit;
989 protected new void Page_Load(Object sender,EventArgs e)
990{
991 if(Session[ "Admin"] != null)
992{
993BigClassDropDownListInit();
994SmallClassDropDownListInit();
995TemplateListInit();
996ReadAll();
997}
998 else
999Response.Redirect( "Default.aspx?Module=Login");
1000}
1001 protected void ReadAll()
1002{
1003ArticleID=Request.Params[ "ID"];
1004 string strSelect= "Select * From Article Where ArticleID = "+ArticleID;
1005Conn.Open();
1006OleDbDataAdapter myAdapter= new OleDbDataAdapter(strSelect,Conn);
1007DataSet ds = new DataSet();
1008myAdapter.Fill(ds, "Article");
1009dr = ds.Tables[ "Article"].Rows[0];
1010Conn.Close();
1011txtArticleTitle.Text=dr[ "Title"].ToString();
1012 //确定文章的的类别以确定DDL的selectIndex
1013 for ( int i=0;i<BigClassList.Items.Count; i++)
1014{
1015 if (BigClassList.Items[i].Text==dr[ "BigClassName"].ToString())
1016BigClassList.SelectedIndex=i;
1017}
1018 for ( int i=0;i<SmallClassList.Items.Count; i++)
1019{
1020 if (SmallClassList.Items[i].Text==dr[ "Type"].ToString())
1021SmallClassList.SelectedIndex=i;
1022}
1023
1024txtAuthorName.Text=dr[ "Author"].ToString();
1025txtWhere.Text=dr[ "WhereFrom"].ToString();
1026txtContent.Text=dr[ "ArticleContent"].ToString();
1027TemplateList.SelectedItem.Text=dr[ "TemplateName"].ToString();
1028FileName=dr[ "FileName"].ToString();
1029
1030}
1031 protected void btnArticleEdit_Click(Object sender,EventArgs e)
1032{
1033 string FilePath=HttpContext.Current.Request.PhysicalApplicationPath+FileName;
1034ArticleID=Request.Params[ "ID"];
1035 string strUpdate= "Update Article set ";
1036strUpdate+= "Title='"+txtArticleTitle.Text.Replace( "'", "''")+ "'";
1037strUpdate+= ",BigClassName='"+BigClassList.SelectedItem.Text.Replace( "'", "''")+ "'";
1038strUpdate+= ",BigID='"+BigClassList.SelectedItem.Value+ "'";
1039strUpdate+= ",Type='"+SmallClassList.SelectedItem.Text+ "'";
1040strUpdate+= ",SmallID='"+SmallClassList.SelectedItem.Value+ "'";
1041strUpdate+= ",Author='"+txtAuthorName.Text.Replace( "'", "''")+ "'";
1042strUpdate+= ",WhereFrom='"+txtWhere.Text.Replace( "'", "''")+ "'";
1043strUpdate+= ",ArticleContent='"+txtContent.Text.Replace( "'", "''")+ "'";
1044strUpdate+= ",TemplateName='"+TemplateList.SelectedItem.Text+ "' ";
1045strUpdate+= " Where ArticleID =";
1046strUpdate+=ArticleID;
1047OleDbCommand comm= new OleDbCommand(strUpdate,Conn);
1048Conn.Open();
1049comm.ExecuteNonQuery();
1050
1051 //生成HTML文件。。,其他功能为实现
1052 string strSelectTemplate= "select TemplateContent from Template Where TemplateName='"+TemplateList.SelectedItem.Text+ "'";
1053OleDbCommand commTemplate= new OleDbCommand(strSelectTemplate,Conn);
1054 string HtmlContent=( string)commTemplate.ExecuteScalar(); //读取所选模板的内容
1055 string InsertContent=txtContent.Text;
1056InsertContent=InsertContent.Replace( "<", "<");
1057InsertContent=InsertContent.Replace( ">", ">");
1058InsertContent=ToUbb(InsertContent);
1059InsertContent=InsertContent.Replace( "/r/n", "<br>");
1060Conn.Close();
1061
1062HtmlContent=HtmlContent.Replace( "Article-RootClass", "<a href=../../../Default.aspx?Module=Article&BigClassID="+BigClassList.SelectedItem.Value+ ">"+BigClassList.SelectedItem.Text+ "</a>");
1063HtmlContent=HtmlContent.Replace( "Article-Type", "<a href=../../../Default.aspx?Module=Article&BigClassID="+BigClassList.SelectedItem.Value+ "&SmallClassID="+SmallClassList.SelectedItem.Value+ ">"+SmallClassList.SelectedItem.Text+ "</a>");
1064
1065HtmlContent=HtmlContent.Replace( "Article-Title", ""+txtArticleTitle.Text+ "");
1066HtmlContent=HtmlContent.Replace( "Article-Author", ""+txtAuthorName.Text+ "");
1067HtmlContent=HtmlContent.Replace( "Article-WhereFrom", ""+txtWhere.Text+ "");
1068HtmlContent=HtmlContent.Replace( "Article-Content", ""+InsertContent+ "");
1069FileStream fs= new FileStream(FilePath,FileMode.OpenOrCreate,FileAccess.ReadWrite);
1070StreamWriter w= new StreamWriter(fs,System.Text.Encoding.GetEncoding( "GB2312"));
1071w.Write(HtmlContent);
1072w.Close();
1073fs.Close();
1074Response.Write( "<script>alert('文章修改成功');</script>");
1075
1076}
1077}
1078
1079 public class AddTemplate:BaseControl
1080{
1081 protected TextBox txtTemplateContent,txtTemplateName;
1082 protected Button btnAddTemplate;
1083 protected void Page_Load( object sender,EventArgs e)
1084{
1085 if(Session[ "Admin"] == null)
1086Response.Redirect( "Default.aspx?Module=Login");
1087}
1088 protected void btnAddTemplate_Click( object sender,System.EventArgs e)
1089{
1090OleDbCommand commTest= new OleDbCommand( "select count(*) from Template where TemplateName='"+txtTemplateName.Text+ "'",Conn);
1091Conn.Open();
1092 int i= int.Parse(commTest.ExecuteScalar().ToString());
1093Conn.Close();
1094 if(i>0)
1095{
1096Response.Write( "<script>alert('已经有此名称的模板存在');</script>");
1097}
1098 else
1099{
1100GoInsert();
1101}
1102}
1103 protected void GoInsert()
1104{
1105Conn.Open();
1106 string strInsert= "Insert Into Template(TemplateName,TemplateContent) Values('"+txtTemplateName.Text+ "','"+txtTemplateContent.Text+ "')";
1107OleDbCommand comm= new OleDbCommand(strInsert,Conn);
1108comm.ExecuteNonQuery();
1109Conn.Close();
1110Response.Write( "<script>alert('模板添加成功');</script>");
1111}
1112
1113}
1114
1115 public class EditTemplate : BaseControl
1116{
1117 protected DropDownList lstTemplateName;
1118 protected TextBox txtTemplateContent,txtTemplateName;
1119 protected Button btnEditTemplate;
1120 protected DataRow dr;
1121
1122 protected void Page_Load( object sender, EventArgs e)
1123{
1124 if(Session[ "Admin"] == null)
1125Response.Redirect( "Default.aspx?Module=Login");
1126 if(!Page.IsPostBack)
1127InitDDL();
1128
1129}
1130 protected void InitDDL()
1131{
1132 string strSelect= "select TemplateName,ID from Template";
1133OleDbCommand cmm= new OleDbCommand(strSelect,Conn);
1134Conn.Open();
1135OleDbDataReader rd=cmm.ExecuteReader();
1136lstTemplateName.DataSource=rd;
1137lstTemplateName.DataTextField= "TemplateName";
1138lstTemplateName.DataValueField= "ID";
1139lstTemplateName.DataBind();
1140lstTemplateName.Items.Insert(0, "选择模板名");
1141rd.Close();
1142Conn.Close();
1143}
1144 protected void ShowTemplateContent(Object o,System.EventArgs e)
1145{
1146 string strSelect= "select TemplateContent from Template where TemplateName= '"+lstTemplateName.SelectedItem.Text+ "' ";
1147 try
1148{
1149Conn.Open();
1150DataSet ds= new DataSet();
1151OleDbDataAdapter adpt= new OleDbDataAdapter(strSelect,Conn);
1152adpt.Fill(ds, "Template");
1153Conn.Close();
1154dr=ds.Tables[ "Template"].Rows[0];
1155txtTemplateContent.Text=dr[ "TemplateContent"].ToString();
1156}
1157 catch
1158{
1159Response.Write( "<script>alert('加载错误!');</script>");
1160}
1161}
1162 protected void btnEditTemplate_Click( object sender,EventArgs e)
1163{
1164 string strInsert;
1165OleDbCommand commTest= new OleDbCommand( "select count(*) from Template where TemplateName='"+txtTemplateName.Text+ "'",Conn);
1166Conn.Open();
1167 int i= int.Parse(commTest.ExecuteScalar().ToString());
1168Conn.Close();
1169 if(i>0)
1170{
1171Response.Write( "<script>alert('已经有此名称的模板存在');</script>");
1172}
1173 else
1174{
1175 if(txtTemplateName.Text== "")
1176{
1177strInsert= "update Template set TemplateContent= '"+txtTemplateContent.Text+ "' where TemplateName= '"+lstTemplateName.SelectedItem.Text+ "'";
1178}
1179 else
1180{
1181Response.Write( "<script>alert('"+txtTemplateContent.Text+ "');</script>");
1182strInsert= "update Template set TemplateName= '"+txtTemplateName.Text+ "' ,TemplateContent= '"+txtTemplateContent.Text+ "' where TemplateName= '"+lstTemplateName.SelectedItem.Text+ "'";
1183 string strUpdate= "update Article set TemplateName='"+txtTemplateName.Text+ "' where TemplateName='"+lstTemplateName.SelectedItem.Text+ "'";
1184Conn.Open();
1185OleDbCommand comm2= new OleDbCommand(strUpdate,Conn);
1186comm2.ExecuteNonQuery();
1187Conn.Close();
1188}
1189Conn.Open();
1190OleDbCommand comm= new OleDbCommand(strInsert,Conn);
1191comm.ExecuteNonQuery();
1192Conn.Close();
1193Response.Write( "<script>alert('模板修改成功');</script>");
1194}
1195}
1196}
1197 public class HotArticle : BasePage
1198{
1199 public Repeater Hot;
1200 public void Page_Load( object sender,EventArgs e)
1201{
1202 string strsql= "select Top 15 ArticleID,Title from Article";
1203strsql+= " order by Hits desc";
1204Cmm= new OleDbCommand(strsql,Con);
1205Con.Open();
1206OleDbDataReader myReader=Cmm.ExecuteReader();
1207Hot.DataSource=myReader;
1208Hot.DataBind();
1209myReader.Close();
1210Con.Close();
1211}
1212}
1213 public class GuestBook:BaseControl
1214{
1215 protected void Page_Load()
1216{
1217}
1218}
1219 public class AdminLogin:BaseControl
1220{
1221 protected TextBox username,password;
1222 protected void LoginButton_Click( object sender,EventArgs e)
1223{
1224 if((username.Text==ConfigurationSettings.AppSettings[ "UserName"])&&(password.Text==ConfigurationSettings.AppSettings[ "PassWord"]))
1225{
1226Session[ "Admin"] = "admin";
1227Response.Redirect( "Default.aspx?Module=Index");
1228}
1229 else Response.Write( "<center><font color=red>^_^管理员名称或者密码不正确!</font></center>");
1230}
1231 protected void ResetBotton_Click( object sender,EventArgs e)
1232{
1233Response.Redirect( "http://www.AspxBoy.Com");
1234}
1235}
1236}
1237 //================记1237行,ver1.0结束=================
1238
1239 <script language="javascript"> </script> .Net男孩社区,asp.net技术, AspxBoy.Com,活靶子,武眉博,商业建站,域名注册,虚拟主机,整机租用,主机托管,整站代码,源代码下载,教学,文章,教程,soft,bbs,forum,chat,down,download,asp,asp.net,ado.net,php,jsp,C#,VB.Net,提供大量.Net技术文章,.NET技术讨论区,大量Asp.Net,C#,VB.NET,WEB SERVICES,网站设计,平面设计,软件开发,教程~~Powered by Huo ba zi---
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值