<%@ Page Language="C#" AutoEventWireup="true" Codebehind="install_step3.aspx.cs" Inherits="MyITJob.install_step3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>
        <%=Maticsoft.Common.install.title %>
    </title>
    <link href="images/install.css" type="text/css" rel="stylesheet" />
    <script src="Scripts/Prototype.js" type="text/javascript"></script>
</head>
<body onload="SelectChange('SqlServer')">
    <div class="setindexstyle" id="getLoading" style="display: none;" runat="server">
        <div style="font-family: Arial; line-height: 22px; text-align: left; font-size: 12px;
            font-weight: normal; color: red; padding: 30px 30px 10px 30px; border: 3px #000 solid;
            background-color: #DFE7ED; margin: auto 10px auto 10px; width: 400px; height: 100px;"
            id="MessageID">
        </div>
    </div>
    <form id="form1" name="form1" runat="server" method="post">
        <table width="700" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#666666">
            <tr>
                <td bgcolor="#ffffff">
                    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                        <tr>
                            <td colspan="2" bgcolor="#333333">
                                <table width="100%" border="0" cellspacing="0" cellpadding="8">
                                    <tr>
                                        <td background="image/01.jpg">
                                            <font color="#ffffff">创建数据库 </font>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td width="180" valign="top">
                                <img src="images/install/install_logo.jpg" />
                            </td>
                            <td width="520" valign="top">
                                <br />
                                <br />
                                <table cellspacing="0" cellpadding="8" width="100%" border="0">
                                    <tr>
                                        <td width="30%" style="background-color: #f5f5f5">
                                            数据库类型:</td>
                                        <td style="background-color: #f5f5f5; width: 352px">
                                            <asp:DropDownList ID="DbType" runat="server" onchange="javascript:SelectChange(this.value);"
                                                Width="155px">
                                                <asp:ListItem Value="SqlServer" Selected="True">MSSQL2000/2008</asp:ListItem>
                                                <asp:ListItem Value="SqlServer2005">MSSQL2005</asp:ListItem>
                                            </asp:DropDownList>*<span id="msgDbType"></span>
                                        </td>
                                    </tr>
                                    <tr id="tr1" style="display: none;">
                                        <td style="background-color: #f5f5f5">
                                            服务器名或IP地址:</td>
                                        <td style="background-color: #f5f5f5; width: 352px;">
                                            <asp:TextBox ID="datasource" runat="server" Text="localhost" Width="150" Enabled="true"></asp:TextBox>*<span
                                                id="msg1"></span></td>
                                    </tr>
                                    <tr id="tr2" style="display: none">
                                        <td style="background-color: #f5f5f5">
                                            数据库名称:</td>
                                        <td style="background-color: #f5f5f5; width: 352px;">
                                            <asp:TextBox ID="database" runat="server" Text="WorkYi" Width="150" Enabled="true"></asp:TextBox>*<span
                                                id="msg2"></span></td>
                                    </tr>
                                    <tr id="tr3" style="display: none">
                                        <td style="background-color: #f5f5f5">
                                            数据库用户名称:</td>
                                        <td style="background-color: #f5f5f5; width: 352px;">
                                            <asp:TextBox ID="userid" runat="server" Width="150" Text="sa" Enabled="true"></asp:TextBox>*<span
                                                id="msg3"></span></td>
                                    </tr>
                                    <tr id="tr4" style="display: none">
                                        <td style="background-color: #f5f5f5">
                                            数据库用户口令:</td>
                                        <td style="background-color: #f5f5f5; width: 352px;">
                                            <asp:TextBox ID="password" runat="server" Width="150" Enabled="true" TextMode="Password"
                                                onblur="validate();"></asp:TextBox>*<span id="msg4"></span></td>
                                    </tr>
                                    <tr id="tr5" style="display: none">
                                        <td style="background-color: #f5f5f5">
                                            数据库地址:
                                        </td>
                                        <td style="background-color: #f5f5f5; width: 352px;">
                                            <asp:TextBox ID="FoosunPath" runat="server" Text="/App_Data/HnITJob_NT.mdb" Width="250"
                                                Enabled="true" MaxLength="30"></asp:TextBox>*<span id="msg5"></span></td>
                                    </tr>
                                    <tr id="tr7" style="display: none">
                                        <td>
                                            <input onclick="javascript:expandoptions();" type="button" value="扩展设置>>" /></td>
                                        <td style="width: 352px">
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;</td>
                            <td>
                                <table width="90%" border="0" cellspacing="0" cellpadding="8">
                                    <tr>
                                        <td align="right">
                                            <input type="button" id="cID" value="创建数据库" onclick="showLoading();" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
    <%=Maticsoft.Common.install.copyright%>
</body>
</html>

<script language="javascript" type="text/javascript">
var gDbType=document.getElementById("DbType");
var gdatasource=document.getElementById("datasource");
var gdatabase=document.getElementById("database");
var guserid=document.getElementById("userid");
var gpassword =document.getElementById("password");

function SelectChange(value)
{
    if(value=="SqlServer")
    {
        document.getElementById("tr1").style.display='';
        document.getElementById("tr2").style.display='';
        document.getElementById("tr3").style.display='';
        document.getElementById("tr4").style.display='';
        document.getElementById("tr5").style.display='none';
        document.getElementById("tr7").style.display='none';//block
        document.getElementById("datasource").value='localhost';
    }
    else
    {
        document.getElementById("tr1").style.display='';
        document.getElementById("tr2").style.display='';
        document.getElementById("tr3").style.display='';
        document.getElementById("tr4").style.display='';
        document.getElementById("tr5").style.display='none';
        document.getElementById("tr7").style.display='none';//block
        document.getElementById("datasource").value='localhost,端口';
    }
}
function validate()
{
    // Ajax验证
    if(gpassword.value == '')
    {
        msg4.style.color = '#F00';
        msg4.innerHTML = '数据库用户密码不能为空!';
    }
}
function showLoading()
{
    //SqlServer选项
    if(gDbType.value == 'SqlServer' || gDbType.value == 'SqlServer2005')
    {
        if (gdatasource.value == "")
        {
            alert('服务器名或IP地址不能为空!');
            gdatasource.focus();
            return false;
        }
        if (gdatabase.value == "")
        {
            alert('数据库名称不能为空!');
            ginitialcatalog.focus();
            return false;
        }
        if (guserid.value == "")
        {
            alert('数据库用户名称不能为空!');
            guserid.focus();
            return false;
        }
        if (gpassword.value == "")
        {
            msg4.style.color = '#F00';
            msg4.innerHTML = '数据库用户密码不能为空!';
            gpassword.focus();
            return false;
        }
        
        document.getElementById("getLoading").style.display="block";
        document.getElementById("MessageID").innerHTML="正在检测系统，并执行SQL语句进行数据库创建...请耐心等待。<br /><br />根据您的网络,这可能要几十秒或者几分钟。";
        document.getElementById("cID").disabled=true;
        document.getElementById("cID").value="正在创建数据库....";
        var Action='type=sqlserver&datasource='+gdatasource.value+'&database='+gdatabase.value+'&userid='+guserid.value+'&password='+gpassword.value;
        var options={
            method:'get', parameters:Action, onComplete:function(changeHTML) 
            { 
                      var returnvalue=changeHTML.responseText; 
                      if (returnvalue.indexOf("??")>-1) 
                          document.getElementById("MessageID").innerHTML='发生错误'; 
                      else 
                         document.getElementById("MessageID").innerHTML=returnvalue;
            } 
        };
        new Ajax.Request('install_step3.aspx?cache='+Math.random(),options);
    }
    
    //Access选项
    if(gDbType.value == 'Access')
    {
        alert('Access暂时不可用，请选择SqlServer进行数据库配置。');
        gDbType.value = 'SqlServer';
        SelectChange('SqlServer');
    }
}
function closediv()
{
    document.getElementById("getLoading").style.display="none";
    document.getElementById("cID").disabled=false; 
    document.getElementById("cID").value="创建数据库";
}
function showDivID(Err)
{
    document.getElementById("cID").disabled=false;
    document.getElementById("cID").value="创建数据库";
    document.getElementById("getLoading").style.display="block";
   document.getElementById("MessageID").innerHTML=""+Err+""; 
}
</script>

