using System;
using System.Collections.Generic;
using System.Web;
using TopWinCMS.Common;
using System.IO;

namespace TopWinCMS.Install
{
    public class InitData
    {

        public void BuildObject()
        {
             
            string sql;
            string sqlPath = HttpContext.Current.Server.MapPath(@"~\Install\1_数据库对象.sql");
            if (File.Exists(sqlPath))
            {
                sql = File.ReadAllText(sqlPath);
            }
            else
            {
                sql = ResHelper.GetResourceContents("TopWinCMS.Install", "TopWinCMS.Install.1_数据库对象.sql");
            }

            using (SQLBase MyBase = new SQLBase())
            {
                List<string> list = SQLBase.SqlText2SqlList(sql);
                MyBase.ExecuteNonQuery(list);
            }

        }

        public void InsertMustData( )
        {
            string sql;
            string sqlPath = HttpContext.Current.Server.MapPath(@"~\Install\2_初始化基础数据.sql");
            if (File.Exists(sqlPath))
            {
                sql = File.ReadAllText(sqlPath);
            }
            else
            {
                sql = ResHelper.GetResourceContents("TopWinCMS.Install", "TopWinCMS.Install.2_初始化基础数据.sql");
            }

            using (SQLBase MyBase = new SQLBase())
            {

                MyBase.ExecuteNonQuery(sql.Trim());
            }
        }

    }
}
