<%@ page language="C#" autoeventwireup="true" inherits="go_setup_Default, App_Web_goexsoip" %>

<!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 runat="server">
    <title>工资查查安装程序</title>
    <script type="text/javascript" src="../../js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="../../js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/font-awesome.css" />
    <script type="text/javascript" src="../js/mytools.js"></script>
    <style type="text/css">
        span[status='0']
        {
            color: #CCC;
        }
        span[status='1']
        {
            color: #3a3;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>
            欢迎进入工资查查安装程序</h1>
			<div style="box-sizing:border-box; padding:1rem">				<a href='http://wpa.qq.com/msgrd?V=1&uin=2636689020' class='fa fa-qq' style='color:#3a3; text-align:right; display:block; width:100%' target="_blank"> 安装有问题，点击QQ技术支持</a><br /></div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第一步</span> 安装前准备
            </div>
            <div class="panel-body">
                <ul>
                    <li>你应该使用最新版的浏览器查看本页，推荐chrome、firefox、ie9浏览器</li>
                    <li>服务器操作系统win2008及以上版本</li>
                    <li>iis7.0及以上版本</li>
                    <li>准备sqlserver，要求sqlserver2005或以上版本</li>
                    <li>准备数据库在服务器上存放的目录，如e:\db</li>
                    <li>安装时需要使用脚本创建数据库，准备有数据库创建权限的数据库帐户，如sa帐户(sqlserver的超级管理员)</li>
                    <li>系统安装和运行时需要在工资查查目录中进行写操作，因此请将工资查查安装目录设置everyone或web用户可写权限</li>
                    <li>系统使用手机号作为用户名，请确保手机号真实有效</li>
                    <li>您的服务器需要有外网访问能力</li>
                </ul>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第二步</span> 系统检查</div>
            <div class="panel-body">
                <div id="systeminfo" class="panel panel-default">
                </div>
                <button class="btn btn-success" onclick="getsysinfo()">
                    系统检查</button>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第三步</span> 软件注册（免费）<span class="label label-warning" style="float:right; display:none" id="regnotice">已经注册</span></div>
            <div class="panel-body">


                        <label>注册人(公司名或机构名)，不可修改，请慎重填写</label>
						<br />
<input type="text"	name="regname" id="regname" value="" placeholder="公司名|机构名" class="form-control"	maxlength="50">
                    <br />
					
                    <label>Email，不可修改，请慎重填写</label>
					<input type="text" name="email" id="email" value="" placeholder="注册人email，用于接收注册信息" class="form-control">
                   <br />
				   
				    <label>联系人手机号</label>
					<input type="text" name="mob" id="mob" value="" placeholder="" class="form-control">
                   <br />

                    <button type="button" bttype="submitsoftregbt" id="submitsoftregbt" class="btn btn-success" onclick="submitsoftreg()">提交注册</button>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第三步</span> 数据库配置</div>
            <div class="panel-body">
                <div>
                    <div class="radio" style="font-size: 18px">
                        <label>
                            <input type="radio" id="dbmode0" name="dbmode" value="script" onclick="selectdbmode('script')" />使用脚本创建数据库(需要web服务器与数据库服务器是同一台服务器)</label><br />
                        <label>
                            <input type="radio" id="dbmode1" name="dbmode" value="attach" onclick="selectdbmode('attach')" />附加数据库,请点击<a
                                href='gzccdb.zip' target="_blank">下载数据库</a>到数据库服务器进行附加</label>
                    </div>
                    <div id="dbmode_script_box" style="display: none">
                        <div>
                            <label>
                                数据库验证类型</label><br />
                            <label>
                                <input type="radio" name="Integrated_Security" id="Integrated_Security0" value="False"
                                    checked="checked" />混合验证</label><br />
                            <label>
                                <input type="radio" name="Integrated_Security" id="Integrated_Security1" value="True" />集成Windows验证</label>
                        </div>
                        <br />
                        <label>
                            数据库服务器ip地址，如127.0.0.1、localhost、192.168.0.1</label>
                        <input type="text" id="serverip" class="form-control" />
                        <br />
                        <label>
                            数据库帐户名,如sa</label>
                        <input type="text" id="dbusername" class="form-control" />
                        <br />
                        <label>
                            数据库帐户密码</label>
                        <input type="text" id="dbpwd" class="form-control" />
                        <br />
                        <label>
                            数据库名,如gzcc</label>
                        <input type="text" id="dbname" class="form-control" />
                        <br />
                        <label>
                            数据库文件在服务器上的存放路径,如e:\db</label>
                        <input type="text" id="dbpath" class="form-control" /><br />
                        <button class="btn btn-success" onclick="createdb()" id="createdbbt">创建数据库</button>
                    </div>
                    <div id="dbmode_attach_box" style="display: none">
                        <div class="alert alert-info">
                            <span class='fa fa-info'>注意：请确保已经附加了数据库</span></div>
                        <div>
                            <label>
                                数据库验证类型</label><br />
                            <label>
                                <input type="radio" name="Integrated_Security_attach" id="Integrated_Security0_attach"
                                    value="False" checked="checked" />混合验证</label><br />
                            <label>
                                <input type="radio" name="Integrated_Security_attach" id="Integrated_Security1_attach"
                                    value="True" />集成Windows验证</label>
                        </div>
                        <br />
                        <label>
                            数据库服务器ip地址，如127.0.0.1、localhost、192.168.0.1</label>
                        <input type="text" id="serverip_attach" class="form-control" />
                        <br />
                        <label>
                            数据库帐户名,如sa</label>
                        <input type="text" id="dbusername_attach" class="form-control" />
                        <br />
                        <label>
                            数据库帐户密码</label>
                        <input type="text" id="dbpwd_attach" class="form-control" />
                        <br />
                        <label>
                            附加数据库后的数据库名</label>
                        <input type="text" id="dbname_attach" class="form-control" />
                        <br />
                        <button class="btn btn-success" onclick="createconn()" id="createconnbt">保存设置</button>
                    </div>
                    <div class="alert alert-warning" id="sqlerrbox" style="display: none">
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第四步</span> 设置系统管理员帐号</div>
            <div class="panel-body">
                <label>
                    系统管理的手机号</label>
                <input type="text" id="admin" class="form-control" value="" /><br />
                <label>
                    密码，牢记您的密码</label>
                <input type="password" id="adminpwd" class="form-control" value="" /><br />
                <button class="btn btn-success" onclick="createadmin()" id="createadminbt">创建</button>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <span class="badge">第五步</span> 安装完成</div>
            <div class="panel-body">
                <span class="label label-default" id="setupresult0">安装尚未完成</span> <a href='../default.aspx'
                    id="setupresult1" style="display: none">安装完成，点击进入首页</a>
            </div>
        </div>       
		
		<div style="text-align:center; padding:1rem; box-sizing:border-box">北京亦卓科技有限公司</div>
    </div>
</body>
</html>

<script>
var $reg = 0;
<%=js%>
</script>
<script>
$(document).ready(function(e) {
	createMask("mymask");
	init($reg);
});

function init(v){
	if(v==0){
		$("#createadminbt").attr("disabled","disabled");
		$("#createdbbt").attr("disabled","disabled");
		$("#createconnbt").attr("disabled","disabled");
		$("#submitsoftregbt").removeAttr("disabled");
		$("#regnotice").css("display","none");
		$("#mob").removeAttr("disabled");
		$("#regname").removeAttr("disabled");
		$("#email").removeAttr("disabled");
	}
	else{
		$("#createadminbt").removeAttr("disabled");
		$("#createdbbt").removeAttr("disabled");
		$("#createconnbt").removeAttr("disabled");
		$("#submitsoftregbt").attr("disabled","disabled");
		$("#regname").attr("disabled","disabled");
		$("#email").attr("disabled","disabled");
		$("#mob").attr("disabled","disabled");
		$("#regnotice").css("display","");
	}
}
 function submitsoftreg() {
        var o = {};
        o.regname = $("#regname").val();
        o.email = $("#email").val();
        o.mob = $("#mob").val();
        o.regmodeinfo = "";
        o.regmode = "";

        if (o.regname == "") {
            msgbox("请输入注册人", "warning");
            $("#regname").focus();
            return;
        }

        if (o.email == "") {
            msgbox("请输入注册人email", "warning");
            $("#email").focus();
            return;
        }
		
        if (o.mob == "") {
            msgbox("请输入注册人手机号", "warning");
            $("#mob").focus();
            return;
        }
		
        if (!o.mob._Mob_New()) {
            msgbox("手机号格式错误", "warning");
            $("#mob").focus();
            return;
        }

        $("#mymask").modal("show");
        $.get("../submitsoftreg.aspx", o, function (d) {
            $("#mymask").modal("hide");
            if (d.result == "ok") {
                msgbox("注册成功", "success");
				init(1);
            }
            else if (d.result == "reged") {
                msgbox("已经注册过", "warning");
            }
            else {
                msgbox("注册失败，错误消息:" + d.result, "warning");
            }
        }, "json");
    }
	
	
	
    function createadmin() {
        var o = {};
        o.un = $("#admin").val();
        o.pwd = $("#adminpwd").val();
		console.log(o);
//		return;
        if (o.un == "") {
            msgbox("请输入管理员手机号", "warning");
            $("#admin").focus();
            return;
        }

        if (o.un._Mob_New() == "") {
            msgbox("手机号格式错误", "warning");
            $("#admin").focus();
            return;
        }

        if (o.pwd == "") {
            msgbox("请输入密码", "warning");
            $("#adminpwd").focus();
            return;
        }
        if (o.pwd.length < 6) {
            msgbox("密码至少6位", "warning");
            $("#adminpwd").focus();
            return;
        }

        if (!confirm("确定吗创建管理员吗？")) {
            return;
        }
        $("#mymask").modal("show");
        $.post("createadmin.aspx", o, function (d) {
            $("#mymask").modal("hide");
            if (d.result == "ok") {
                msgbox("创建管理员完成", "success");
                $("#setupresult0").css("display", "none");
                $("#setupresult1").css("display", "block");
				alert("安装完成");
            }
			else if (d.result == "notreg") {
                msgbox("系统尚未注册", "warning");
            }
            else if (d.result == "repeat") {
                msgbox("手机号已经被占用", "warning");
            }
            else if (d.result == "usernumover") {
                msgbox("用户数溢出", "warning");
            }
            else if (d.result == "setuped") {
                msgbox("系统已经安装完成，操作未执行", "warning");
            }
            else {
                msgbox("创建管理员错误，代码:" + d.result, "warning");
            }
        }, "json");

    }

    function selectdbmode(v) {
        if (v == "script") {
            $("#dbmode_attach_box").fadeOut(500);
            $("#dbmode_script_box").fadeIn(500);
        }
        else {
            $("#dbmode_attach_box").fadeIn(500);
            $("#dbmode_script_box").fadeOut(500);
        }
    }


    function createconn() {


        var o = {};
        o.serverip = $("#serverip_attach").val();
        o.dbusername = $("#dbusername_attach").val();
        o.dbpwd = $("#dbpwd_attach").val();
        o.dbname = $("#dbname_attach").val();
        o.Integrated_Security = $("#Integrated_Security0_attach").get(0).checked ? "False" : "True";
        o.dbmode = "attach";
        if (o.serverip == "") {
            msgbox("请输入数据库服务器的ip或机器名", "warning");
            $("#serverip_attach").focus();
            return;
        }

        if (o.dbusername == "") {
            msgbox("请输入数据库帐户名", "warning");
            $("#dbusername_attach").focus();
            return;
        }

        if (o.dbname == "") {
            msgbox("请输入数据库名", "warning");
            $("#dbname_attach").focus();
            return;
        }




        if (!confirm("确定吗？")) {
            return;
        }

        $("#sqlerrbox").html("");
        $("#sqlerrbox").css("display", "none");
        $("#mymask").modal("show");
        $.post("createdb.aspx", o, function (d) {
            $("#mymask").modal("hide");
            switch (d.result) {
                case "ok":
                    msgbox("设置保存完成", "success");
                    break;
                case "err":
                    msgbox("设置数据库连接时发生错误", "warning");
                    $("#sqlerrbox").html(d.msg);
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "connerr":
                    msgbox("数据库连接错误", "warning");
                    $("#sqlerrbox").html(d.msg);
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "setuped":
                    msgbox("系统已经安装完成，操作未执行", "warning");
                    break;
				case "notreg":
					msgbox("系统尚未注册", "warning");
					break;

            }
        }, "json");
    }

    function createdb() {


        var o = {};
        o.serverip = $("#serverip").val();
        o.dbusername = $("#dbusername").val();
        o.dbpwd = $("#dbpwd").val();
        o.dbpath = $("#dbpath").val();
        o.dbname = $("#dbname").val();
        o.Integrated_Security = $("#Integrated_Security0").get(0).checked ? "False" : "True";
        o.dbmode = "script";
        if (o.serverip == "") {
            msgbox("请输入数据库服务器的ip或机器名", "warning");
            $("#serverip").focus();
            return;
        }

        if (o.dbusername == "") {
            msgbox("请输入数据库帐户名", "warning");
            $("#dbusername").focus();
            return;
        }

        if (o.dbname == "") {
            msgbox("请输入数据库名", "warning");
            $("#dbname").focus();
            return;
        }

        if (o.dbpath == "") {
            msgbox("请输入数据库存放的路径", "warning");
            $("#dbpath").focus();
            return;
        }


        if (!confirm("确定吗？")) {
            return;
        }

        $("#sqlerrbox").html("");
        $("#sqlerrbox").css("display", "none");
        $("#mymask").modal("show");
        $.post("createdb.aspx", o, function (d) {
            $("#mymask").modal("hide");
            switch (d.result) {
                case "ok":
                    msgbox("数据库创建完成", "success");
                    break;
                case "dbnamerepeat":
                    msgbox("数据库名重复", "warning");
                    $("#sqlerrbox").html("数据库名重复");
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "err":
                    msgbox("数据库创建时发生错误", "warning");
                    $("#sqlerrbox").html(d.msg);
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "connerr":
                    msgbox("数据库连接错误", "warning");
                    $("#sqlerrbox").html(d.msg);
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "createtableerr":
                    msgbox("数据库创建成功，但创建数据表发生错误", "warning");
                    $("#sqlerrbox").html(d.msg);
                    $("#sqlerrbox").css("display", "block");
                    break;
                case "setuped":
                    msgbox("系统已经安装完成，操作未执行", "warning");
                    break;
				case "notreg":
					msgbox("系统尚未注册", "warning");
					break;
            }
        }, "json");
    }

    function nextstep(v) {

    }

    function getsysinfo() {
        $("#mymask").modal("show");
        $.get("systemcheck.aspx?r=" + Math.random(), function (d) {
            $("#mymask").modal("hide");
            if (d.result == "setuped") {

                msgbox("系统已经安装完成，操作未执行", "warning");
                return;

            }
            var a = [];
            a.push("<table class='table'>");
            a.push("<tr><td>OS</td><td>" + d.os + "</td></tr>");
            a.push("<tr><td>.Net版本</td><td>" + d.net + "</td></tr>");
            a.push("<tr><td>OS位数</td><td>" + d.is64 + "</td></tr>");
            a.push("<tr><td>cpu核心数</td><td>" + d.cpunum + "</td></tr>");
            a.push("<tr><td>安装目录</td><td>" + d.dir + "</td></tr>");
            a.push("<tr><td>网站根目录</td><td>" + d.urldir + "</td></tr>");
            a.push("<tr><td>iis版本</td><td>" + d.iis + "</td></tr>");
            a.push("<tr><td>目录写权限</td><td>" + (d.filewrite == 1 ? "<span class='fa fa-check' style='color:#3a3'> 有</span>" : "<span class='label label-danger'>没有目录写权限,不能安装</span>") + "</td></tr>");
            a.push("<tr><td>首页地址</td><td>" + d.url + "</td></tr>");
            a.push("<tr><td>当前工资查查版本</td><td>" + d.version + "," + (d.hasnew == 0 ? "已是最新版" : "有新版本<a target='_blank' href='" + d.newversion.newversiondownaddr + "'>下载最新版本</a>") + "</td></tr>");
            a.push("<tr><td>最新工资查查版本</td><td>" + d.newversion.version + "</td></tr>");
            a.push("<tr><td>连接工资查查更新服务器</td><td>" + (d.accupdateserver == "ok" ? "<span class='fa fa-check' style='color:#3a3'> 成功</span>" : "<span class='label label-danger'>不能连接工资查查更新服务器，不能安装</span>") + "</td></tr>");
            a.push("</table>");
            $("#systeminfo").html(a.join(""));
			if(d.filewrite!=1){
				msgbox("没有目录写权限","danger");	
			}
			
			if(d.accupdateserver!="ok"){
				msgbox("不能连接工资查查更新服务器","danger");	
			}


        }, "json");
    }

</script>
