using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EKETEAM.Data;
using EKETEAM.FrameWork;

public partial class Application_Check_Create : System.Web.UI.Page
{
    public string UserArea = "Application"; //用户登录域-默认值
    public eParentModel model;//取父模块动作及表单数据 
    string ID = "";//父级模块的主键编号
    eUser user;//当前操作用户
    protected void Page_Load(object sender, EventArgs e)
    {
        ID = eParameters.QueryString("id");//获取当前父级模块的主键编号,也可以使用model.ID
        user = new eUser(eBase.getUserArea(UserArea));
        model = new eParentModel();

        if(model.Action.ToLower()=="insert" || 1==1)
        {
            string baseName = eOleDB.getValue("select BaseName from CheckPlans where CheckPlanID='" + ID + "'");

           // CreateTable(baseName);
            //eBase.AppendLog(model.Action.ToLower() + "::" + tablename);
        }

    }
    private void CreateTable(string  baseName)
    {
        //计划采集
        string TableName = "Check_plan_" + baseName;
        string sql = "Create table [" + TableName + "] (";
        sql += "[ID] [int] IDENTITY (1, 1) NOT NULL,";
        sql += "[CheckPlanID] uniqueidentifier NULL,";
        sql += "[Code] nvarchar(50) NULL,";
        sql += "[orgCode] nvarchar(50) NULL,";
        sql += "[SFZH] nvarchar(50) NULL,";
        sql += "[XM] nvarchar(50) NULL,";
        sql += "[CJFS] nvarchar(50) NULL default '点位采集',";//采集方式
        sql += "[result] [int] NULL default 0,"; //默认为0未采集 ,1为已采集
        sql += "[CJSJ] nvarchar(50) NULL,"; //采集时间
        sql += "[Reason] nvarchar(50) NULL,";//未采集原因
        sql += "[addTime] [datetime] NULL default getdate(),";
        sql += "[addUser] nvarchar(36) NULL,";
        sql += "PRIMARY KEY(ID)";
        sql += ") ON [PRIMARY]";
        eOleDB.Execute(sql);
        sql = "CREATE INDEX index_" + TableName + "_sfzh ON [" + TableName + "] ([SFZH])";
        eOleDB.Execute(sql);



        //计划外
        TableName = "Check_other_" + baseName;
        sql = "Create table [" + TableName + "] (";
        sql += "[ID] [int] IDENTITY (1, 1) NOT NULL,";
        sql += "[CheckPlanID] uniqueidentifier NULL,";
        sql += "[Code] nvarchar(50) NULL,";
        sql += "[orgCode] nvarchar(50) NULL,";
        sql += "[SFZH] nvarchar(50) NULL,";
        sql += "[XM] nvarchar(50) NULL,";
        sql += "[CJSJ] nvarchar(50) NULL,"; //采集时间
        sql += "[CJFS] nvarchar(50) NULL,";//采集方式
        sql += "[addTime] [datetime] NULL default getdate(),";
        sql += "[addUser] nvarchar(36) NULL,";
        sql += "PRIMARY KEY(ID)";
        sql += ") ON [PRIMARY]";
        eOleDB.Execute(sql);
        sql = "CREATE INDEX index_" + TableName + "_sfzh ON [" + TableName + "] ([SFZH])";
        eOleDB.Execute(sql);



        //返回结果
        TableName = "Check_result_" + baseName;
        sql = "Create table [" + TableName + "] (";
        sql += "[ID] [int] IDENTITY (1, 1) NOT NULL,";
        sql += "[CheckPlanID] uniqueidentifier NULL,";
        sql += "[SFZH] nvarchar(50) NULL,";
        sql += "[XM] nvarchar(50) NULL,";
        sql += "[addTime] [datetime] NULL default getdate(),";
        sql += "[addUser] nvarchar(36) NULL,";
        sql += "PRIMARY KEY(ID)";
        sql += ") ON [PRIMARY]";
        eOleDB.Execute(sql);
        sql = "CREATE INDEX index_" + TableName + "_sfzh ON [" + TableName + "] ([SFZH])";
        eOleDB.Execute(sql);

        //更新结果
        TableName = "Check_update_" + baseName;
        sql = "Create table [" + TableName + "] (";
        sql += "[ID] [int] IDENTITY (1, 1) NOT NULL,";
        sql += "[CheckPlanID] uniqueidentifier NULL,";
        sql += "[SFZH] nvarchar(50) NULL,";
        sql += "[XM] nvarchar(50) NULL,";
        sql += "[CJSJ] nvarchar(50) NULL,"; //采集时间
        sql += "[CJFS] nvarchar(50) NULL,";//采集方式
        sql += "[addTime] [datetime] NULL default getdate(),";
        sql += "[addUser] nvarchar(36) NULL,";
        sql += "PRIMARY KEY(ID)";
        sql += ") ON [PRIMARY]";
        eOleDB.Execute(sql);
        sql = "CREATE INDEX index_" + TableName + "_sfzh ON [" + TableName + "] ([SFZH])";
        eOleDB.Execute(sql);
    }
}