using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;

public partial class Step1Class : Page
    {
		MysqlHelp mh = null;
		string createTableSQL = "";
			
		protected void Page_Load(object sender, EventArgs e)
        {
		
        }
		
		protected void btnCreateTables_Click(object sender, EventArgs e)
		{
			mh = new MysqlHelp();
			///用户数据表
			createTableSQL = "create table if not exists Users4DeepSoon(id int(4) not null primary key auto_increment,name char(20) not null,pwd char(32) not null,class char(20) default 'super',area char(20) )";
			mh.Runsql(createTableSQL);
			
			///站点配置表
			createTableSQL = "create table if not exists Preference4DeepSoon(id int(4) not null primary key auto_increment,siteName char(20) not null,siteTitle char(40) not null,siteKeywords char(140) not null,siteDescribe char(200) not null,siteMain char(50) not null,siteLogoAddr char(200) not null,htmlDir char(100) not null,uploadFileDir char(200) not null,siteCopyRight Text,WatermarkLogo char(200) not null,urlRule char(200) not null)";
			mh.Runsql(createTableSQL);
			
			///操作日志表
			createTableSQL = "create table if not exists Log4DeepSoon(ID int(8) not null primary key auto_increment,Name char(20) not null,EventStr char(40) not null,IPStr char(20) not null,DateStr  timestamp DEFAULT now() )";
			mh.Runsql(createTableSQL);
			
			///目录树表
			createTableSQL = "create table if not exists Class4DeepSoon(ID int(4) not null primary key auto_increment,Name char(20) not null,FatherID char(20) not null,ChildID char(250),OutLinkHref char(150) not null,isHidden bool default false,ThemeFile char(250) not null default 'T_list.html',openArea  char(20) default 'all',linkTarget char(20) default '_self')";
			mh.Runsql(createTableSQL);
			
			///文章表
			createTableSQL = "create table if not exists Article4DeepSoon(ID int(8) not null primary key auto_increment,Title char(50) not null,Source char(20) not null,Author char(20) not null,ClassID char(20) not null,Article Text ,TitleColor char(20) ,setTop bool default false ,DateStr  timestamp DEFAULT now(),isDelete bool default false ,BriefInfor char(150) not null,thumbnailImage Text,ReadCount int(8)  DEFAULT 0,isSetIndexPic bool default false,isPass bool default false)";
			mh.Runsql(createTableSQL);
			
			///头版头条表
			createTableSQL = "create table if not exists HeadTitle4DeepSoon(ID int(4) not null primary key auto_increment,ArticleID int(8) not null)";
			mh.Runsql(createTableSQL);
			
			///友情链接表
			createTableSQL = "create table if not exists Links4DeepSoon(ID int(4) not null primary key auto_increment,LinkName char(50) not null,LinkHref char(150) not null)";
			mh.Runsql(createTableSQL);
			///插入地平线官网的友情链接：
			string insertDeepSoonLinkSQL = "insert into Links4DeepSoon(LinkName,LinkHref) Values('地平线官网','http://www.deepsoon.com')";
			mh.Runsql(insertDeepSoonLinkSQL);
			
			///广告表
			createTableSQL = "create table if not exists AdList4DeepSoon(ID int(4) not null primary key auto_increment,AdContent Text,AdPos char(100))";
			mh.Runsql(createTableSQL);
			///广告表插入初始化数据：
			string insertTopSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<a href=\"http://www.deepsoon.com\" target=\"_blank\"><img src=\"System_Img/allAd.jpg\" title=\"全站顶部广告\"></a>','allTop')";
			mh.Runsql(insertTopSQLStr);
			string insertIndexSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<a href=\"http://www.deepsoon.com\" target=\"_blank\"><img src=\"System_Img/indexAd.jpg\" title=\"首页广告\"></a>','indexLeft')";
			mh.Runsql(insertIndexSQLStr);
			string insertViewSQLStr = "insert into AdList4DeepSoon(AdContent,AdPos) Values('<a href=\"http://www.deepsoon.com\" target=\"_blank\"><img src=\"System_Img/viewAd.jpg\" title=\"正文广告\"></a>','viewRight')";
			mh.Runsql(insertViewSQLStr);
			
			///主题风格表
			createTableSQL = "create table if not exists Theme4DeepSoon(ID int(4) not null primary key auto_increment,ThemeName char(100) not null)";
			mh.Runsql(createTableSQL);
			///插入默认主题风格
			string insertThemeSQLStr = "insert into Theme4DeepSoon(ThemeName) Values('Default')";
			mh.Runsql(insertThemeSQLStr);
			
			///说说表
			string feedBackSQL = "create table FeedBack4DeepSoon(ID int(4) not null primary key auto_increment,Content Text not null,Author char(20),IPAddress char(50),DateStr  timestamp DEFAULT now(),FatherID char(20) not null,isPass bool default false)";
			mh.Runsql(feedBackSQL);
			///说说配置表
			string feedBackSettingSQL = "create table FeedBackSetting4DeepSoon(ID int(4) not null primary key auto_increment,setTitle char(20),setContent Text,setButtonName char(20),setOpen  bool default true,setPass bool default false,setSize int(8) default 200)";
			mh.Runsql(feedBackSettingSQL);
			string insertFeedBackSettingStr = "insert into FeedBackSetting4DeepSoon(setTitle,setContent,setButtonName) values ('说说','既然来了，给我们说说吧!','发表')";
			mh.Runsql(insertFeedBackSettingStr);
			
			///邮箱配置表
			string MailSettingSQL = "create table MailSetting4DeepSoon(ID int(4) not null primary key auto_increment,setTitle char(20),setContent Text,setButtonName char(20),setOpen  bool default true,Host Text,Account Text,PWD Text,FromMail Text,ToMail Text)";
			mh.Runsql(MailSettingSQL);
			string insertMailSettingStr = "insert into MailSetting4DeepSoon(setTitle,setContent,setButtonName,Host,FromMail,ToMail) values ('电子邮件','欢迎给我们发送电子邮件，您提交的信息将直接发送到我们的邮箱!','发送','smtp.126.com','XXX@126.com','XXX@qq.com')";
			mh.Runsql(insertMailSettingStr);
			
			///文章评论表
			string commentSQL = "create table Comment4DeepSoon(ID int(8) not null primary key auto_increment,Content Text not null,Author char(20),IPAddress char(50),DateStr  timestamp DEFAULT now(),FatherID char(20) not null,isPass bool default false,ArticleID int(8) not null)";
			mh.Runsql(commentSQL);
			///文章评论配置表
			string commentSettingSQL = "create table CommentSetting4DeepSoon(ID int(4) not null primary key auto_increment,setOpen  bool default true,setPass bool default false,setSize int(8) default 200,openArea  char(20) default 'all')";
			mh.Runsql(commentSettingSQL);
			string insertCommentSettingStr = "insert into CommentSetting4DeepSoon(setSize) values ('200')";
			mh.Runsql(insertCommentSettingStr);
			
			///所有数据表创建成功，跳转到下一步：
			Response.Redirect("step2.aspx");
		}
    }