<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!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>License</title>
	<link href="/Styles/login.css" rel="stylesheet" type="text/css" />
	<link href="/Styles/filebox.css" rel="stylesheet" type="text/css" />
	<link href="/Styles/button.css" rel="stylesheet" type="text/css" />
	<script src="/easyui-1.4.2/jquery.min.js" type="text/javascript"></script>
	<script src="/Scripts/ajaxfileupload.js" type="text/javascript"></script>
    <% switch ((int)Session["isCN"]){case 1: %>
    <script type="text/javascript" src="/Scripts/en-US.js"></script>
    <% break; case 2: %>
    <script type="text/javascript" src="/Scripts/zh-TW.js"></script>
    <% break;default: %>
    <script type="text/javascript" src="/Scripts/zh-CN.js"></script>
    <% break; } %>
	<script type="text/javascript">

		function upload() {

			var filename = $("#file").val();
			if (filename == "") {
			    $("#msg").html(lang.PleaseSelectALicenseFile);
				return;
			}

			$.ajaxFileUpload({
				url: "/Home/UploadLicense/",
				type: "POST",
				secureuri: false,
				fileElementId: "file",
				dataType: "json",
				success: function (data, status) {
					if (status == "success" && typeof (data) == "object") {
						if (data.IsSuccess) {
							location.reload();
						} else {
							$("#msg").html(data.Message);
						}
					}
				},
				error: function (data, status, e) {
					$("#msg").html(e);
				}
			});
		}

		$(function () {
		    $("input[type=file]").change(function () {
		        var file = $(this).val();

		        var mime = file.toLowerCase().substr(file.lastIndexOf("."));

		        if (mime !== ".lic") {
		            $("#msg").html(lang.CUOLLFF);
		            return;
		        }

		        $(this).parents(".uploader").find(".filename").val(file);
		    });
		    $("input[type=file]").each(function () {
		        if ($(this).val() == "") { $(this).parents(".uploader").find(".filename").val(lang.PleaseSelectALicenseFile); }
		    });
		    $.ajax({
		        type: "POST",
		        url: "/Home/GetMachineCode/",
		        success: function (msg) {
		            if (msg) {
		                if (msg.IsSuccess) {
		                    $("#txtMachineCode").val(msg.Message);
		                }
		                else {
		                    $("#txtMachineCode").val("获取机器码失败");
		                }
		            }
		            else {
		                $("#txtMachineCode").val("获取机器码失败");
		            }
		        }
		    });
		});
	</script>
</head>
<body>
   <div class="container" style="background:transparent;">
		<div id="licensebox">
			<form id="uploadForm" method="post" action="#" enctype="application/x-www-form-urlencoded">
			<table>
                <tr>
					<td style="height:25%;">
						<div>
							机器码：<input type="text" id="txtMachineCode" disabled="disabled" style="width:180px; height:28px; font-weight:bold;" />
						</div>
					</td>                    
                </tr>
				<tr>
					<td style="height:25%;">
						<div class="uploader blue">
							<input type="text" class="filename" readonly="readonly" />
							<input type="button" class="button" value='<%: Html.Language("Browse")%>'/>
							<input type="file" id="file" name="file" size="30"/>
						</div>
					</td>
				</tr>
				<tr>
					<td style="height:25%;background:#;">
						<input type="button" value='<%: Html.Language("Upload")%>' class="button blue" style="width:100px;" onclick="upload();" />
					</td>
				</tr>
				<tr>
					<td style="height:25%;background:#;">
						<span id="msg" style="color:#f00;"><%: ViewData["Msg"] %></span>
					</td>
				</tr>
			</table>
			</form>
		</div>
	</div>
</body>
</html>
