<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Avicap.aspx.cs" Inherits="SWTraining.Tools.Avicap"
    Title="照相机" %>

<%@ Register Src="../UserCol/PrintControl.ascx" TagName="PrintControl" TagPrefix="uc1" %>
<%@ Import Namespace="SWTraining" %>
<!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">
    <link id="linkStyle" runat="server" rel="stylesheet" type="text/css" />
    <base target="_self" />
</head>
<body onkeydown="if (event.keyCode==116){reload.click()};" style="background-color: ButtonFace">
    <a id="reload" href="Avicap.aspx" style="display: none">reload...</a>
    <div align="center">
        <form id="form1" runat="server" defaultfocus="btnPost">
        <fieldset style="width: auto; margin: 10px; height: 100%; padding-bottom: 5px">
            <legend>监视器</legend>
            <div style="width: 250px; height: 200px; background-color: Black; padding: 1px">
                <uc1:PrintControl ID="Avicap1" runat="server" Height="200" Width="250" Mode="Avicap"
                    AutoPlay="true" />
            </div>
        </fieldset>

        <script type="text/javascript">

            function IsStudentRegPage() {
                var obj = window.dialogArguments;
                if (obj.parent.window.right.document.getElementById("imgPhoto") == null || obj.parent.window.right.document.getElementById("imgByteString") == null) {
                    return false;
                }
                else {
                    return true;
                }
            }

            function SetByteString(PhotoByteString, LocalPicPath) {
                var obj = window.dialogArguments;
                if (obj.parent.window.right.document.getElementById("imgByteString") != null) {
                    obj.parent.window.right.document.getElementById("imgByteString").value = PhotoByteString;

                    obj.parent.window.right.document.getElementById("imgPhoto").src = "../images/pic.gif";
                    obj.parent.window.right.document.getElementById("imgUrl").value = "../images/pic.gif";

                    obj.parent.window.right.document.getElementById("imgPhoto").src = LocalPicPath;
                    obj.parent.window.right.document.getElementById("imgUrl").value = LocalPicPath;
                }
            }

            function Avicap() {
                if (IsStudentRegPage()) {
                    var av = document.getElementById("Avicap1");
                    if (av.GrabImage()) {
                        var s = av.GetBase64String();
                        SetByteString(s, av.LocalPicPath);
                    }
                    else {
                        alert('拍照失败！');
                    }
                }
                else {
                    alert('未找到合适的对象，请转到特定页面。');
                }
            }

            function hotkey() {
                var a = window.event.keyCode;
                if (a == 13) {
                    document.getElementById("btnPost").click();
                }
            }

            document.onkeydown = hotkey;

            DetectControl("Avicap1");
        </script>

        <fieldset style="width: auto; margin: 10px; height: 100%; padding-bottom: 5px">
            <legend>控制面板</legend>
            <input id="btnPost" type="button" value="拍照(Enter)" runat="server" onclick="Avicap()" />
            <input id="btnClose" type="button" value="关闭" runat="server" onclick="window.close()" />
        </fieldset>
        </form>
    </div>
</body>
</html>
