码迷,mamicode.com
首页 > Web开发 > 详细

ASP.Net Cookie

时间:2020-07-10 09:46:03      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:ted   file   size   tofixed   ring   getc   txt   desc   rip   

技术图片
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>协同办公云平台-登录</title>
    <link href="~/Content/Login.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script>
        //获取cookie cname代表你的key比如存储的是code就是用code获取值,ysid=ssss;code=值 GetCookie(code)
        //yjs_id=fDE1NzEwMzk0Mzg2NzI; code1=1IVJAM;dept=;
        function GetCookie(cname) {
            var strCookie = document.cookie;
            //没有找到
            if (strCookie.indexOf(";") != 0) {
                strCookie = strCookie + ";";
            }
            var c = document.cookie.split(";");//数组包含yjs_id=fDE1NzEwMzk0Mzg2NzI和 code=1IVJAM
             var name = cname + "=";
            for (var i = 0; i < c.length; i++) {
                var ca = c[i].trim();//去掉空格
                if (ca.indexOf(name) == 0) {//查找是否存在,如果存在返回0不存在返回-1
                    return ca.substring(name.length, ca.length);//sumString(开始查找的位置,查找的长度是多少)
                }

            }
            return "";
        }



        $(function () {
            $("#login").click(function () {
                var code = $("#VCode").val();
                //获取用户名
                var account = $("#Account").val();
                //获取密码
                var password = $("#Password").val();

                //用户名和密码的判断
                if (account.trim() == "")
                {
                    alert("请输入您的用户名");
                    return;
                }
                else if (password.trim() == "")
                {
                    alert("请输入您的密码");
                    return;
                }

               else if (GetCookie("code") == "" || code == "") {
                    alert("请输入您的验证码");
                    return;
                }
                else if (code != GetCookie("code")) {
                    alert("您输入的验证码不正确");
                      return;
                }

                $.ajax({
                    url: "http://localhost:56848/api/Validate",
                    type: "get",
                    data: { account: account, password: password },
                    dataType: "json",
                    success: function (result) {
                        if (result == "") {
                            alert("用户名或者密码错误,请重新输入");
                        }
                        else {
                            alert("登录成功");
                            //设置cookie
                            document.cookie = "displayName=" + result.DisplayName;
                            document.cookie = "account=" + result.Account;
                            document.cookie = "sex=" + result.Sex;
                            document.cookie = "DeptName=" + result.DeptName;
                        }
                    }

                });

            

            });
            
        });

    </script>
</head>
<body>
    <div id="content">
        <div id="box">
            <div class="title">协同办公云平台</div>
            <div class="input">
                <input type="text" placeholder="请输入用户名" id="Account" />
                <br />
                <input type="password" placeholder="请输入密码" id="Password" />
                <br />
                <input type="text" placeholder="请输入验证码" id="VCode" style="text-align:left;width:50%; float:left; margin-left:53px" maxlength="6" />
                <img src="~/Handler/VerificationHanlder.ashx" onclick="this.src = this.src + ‘?‘ + Math.random()"  style="padding-top:5px;cursor:pointer" />
                <br />
                <button type="button" id="login">登录</button>
            </div>
        </div>
    </div>
</body>
</html>
<script>
    alert(document.cookie);
</script>
View Code
技术图片
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>LeaveForm</title>
    <style>
    </style>

    <link href="~/Content/upload.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.1.10.2.min.js"></script>
    <script src="/scripts/jquery/jquery.iframe-transport.js"></script>
    <script src="/scripts/jquery/jquery.ui.widget.js"></script>
    <script src="/scripts/jquery/jquery.xdr-transport.js"></script>
    <script src="/scripts/jquery/jquery.fileupload.js"></script>
    <script>
        function GetCookie(cname) {
            var strCookie = document.cookie;
            //没有找到
            if (strCookie.indexOf(";") != 0) {
                strCookie = strCookie + ";";
            }
            var c = document.cookie.split(";");//数组包含yjs_id=fDE1NzEwMzk0Mzg2NzI;code=1IVJAM
            var name = cname + "=";
            for (var i = 0; i < c.length; i++) {
                var ca = c[i].trim();//去掉空格
                if (ca.indexOf(name) == 0) {//查找是否存在,如果存在返回0不存在返回-1
                    return ca.substring(name.length, ca.length);//sumString(开始查找的位置,查找的长度是多少)
                }

            }
            return "";
        }
        $(function () {

            //获取cookie中的显示用户名
            $("#txtDisplayName").val(GetCookie("displayName"));
            $("#txtAccount").val(GetCookie("account"));
            var date = new Date();
            $("#txtDeptName").val(GetCookie("DeptName"));
            $("#txtDate").val(date.getFullYear() + "-" + date.getMonth() + "-" + date.getDate());



            $("input[type=file]").fileupload({
                done: function (e, result) {
                    //done方法就是上传完毕的回调函数,其他回调函数可以自行查看api
                    //注意result要和jquery的ajax的data参数区分,这个对象包含了整个请求信息
                    //返回的数据在result.result中,假设我们服务器返回了一个json对象
                    //json对象{"newName": "sss", "oldName": "sdf"}

                    var resultJson = $.parseJSON(result.result)
                    $(e.target).attr("value", resultJson.newName);
                    var uploadDiv = $(e.target).parent().parent().parent();
                    uploadDiv.find(".filestate").show().text(resultJson.oldName);
                },
                progressall: function (e, data) {
                    var maxWidth = 200;
                    var percent = (data.loaded / data.total * 100).toFixed(2);
                    var progress = parseInt(data.loaded / data.total * maxWidth, 10);
                    var uploadDiv = $(e.target).parent().parent().parent();
                    uploadDiv.find(".progress").show();
                    uploadDiv.find(".bar").css("width", progress);
                    uploadDiv.find(".progresspercent").show().text(percent + "%");

                }
            });

        });




        //计算天数
        function DateDiff(sDate1, sDate2) {
            var oDate1, oDate2, iDays
            oDate1 = new Date(sDate1);
            oDate2 = new Date(sDate2);
            console.log(sDate1);
            console.log(sDate2)
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24);
            return iDays;
        }
        function CalcDay() {
            var txtBeginDdate = $("#txtBeginDdate").val();
            var txtEndDate = $("#txtEndDate").val();

            $("#txtDay").val(DateDiff(txtBeginDdate, txtEndDate) + 1);
        }

        function LeaveSubmit() {
            var txtAccount = $("#txtAccount").val();
            var txtDisplayName = $("#txtDisplayName").val();
            var txtDeptName = $("#txtDeptName").val();
            var approveAccount = "tianyou.xiang";
            var approveName = "项天佑";
            var txtBeginDdate = $("#txtBeginDdate").val();
            var txtEndDate = $("#txtEndDate").val();
            var txtDay = $("#txtDay").val();
            var txtDesc = $("#txtDesc").val();
            var dropType = $("#dropType").val();
            $.ajax({
                url: "http://localhost:56848/api/LeaveSubmit",
                data: { AppAccount: txtAccount, AppName: txtDisplayName, AppDetp: txtDeptName, ApproveAccount: approveAccount, ApproveName: approveName, StartDate: txtBeginDdate, EndDate: txtEndDate, day: txtDay, _Desc: txtDesc, LeaveType: dropType },
                type: "post",
                dataType: "text",
                success: function (result) {

                }
            });
        }
     
    </script>
</head>
<body>
    <div style="margin:0">
        <div align="center" style="font-size:20px">请假申请流程</div>
        <div class="upload clearfix">
            <div class="uploadbtnBox clearfix">
                <a href="javascript:;" class="a-upload">
                    <input type="file" data-url="/Handler/upload.ashx" name="files" value="" id="file1"
                           />点击上传
                </a>
            </div>
            <div class="filestate">
                文件名
            </div>
            <div class="progresspercent">
            </div>
            <div class="progress">
                <div class="bar" style="width: 0%;">
                </div>
            </div>
        </div>

        <div align="center" style="width:auto">
            <table border="1px" cellpadding="0" cellspacing="0">
                <tr><td colspan="4" style="font-weight:100">基本信息</td></tr>
                <tr>
                    <td>申请单号:</td>
                    <td><input type="text" id="txtLeaveNumber" value="---申请单号自动生成----" disabled /></td>
                    <td>申请人:</td>
                    <td>
                        <input type="text" id="txtDisplayName" disabled />
                        <input type="hidden" id="txtAccount" />
                    </td>
                </tr>
                <tr>
                    <td>所在部门:</td>
                    <td><input type="text" id="txtDeptName" disabled /></td>
                    <td>申请日期:</td>
                    <td>
                        <input type="text" id="txtDate" disabled />
                    </td>
                </tr>
                <tr><td colspan="4" style="font-weight:100">申请信息</td></tr>
                <tr>
                    <td>假期类型:</td>
                    <td colspan="3">
                        <select id="dropType">
                            <option value="年假">年假</option>
                            <option value="事假">事假</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>请假开始日期:</td>
                    <td>
                        <input type="date" id="txtBeginDdate" onclick="CalcDay()">
                    </td>
                    <td>请假结束日期</td>
                    <td><input id="txtEndDate" type="date" onclick="CalcDay()" /></td>
                </tr>
                <tr>
                    <td>请假天数:</td>
                    <td colspan="3"><input type="text" disabled id="txtDay" /></td>
                </tr>
                <tr>
                    <td>描述:</td>
                    <td colspan="3"><textarea rows="5" id="txtDesc" cols="20"></textarea></td>
                </tr>
            </table>
        </div>
        <div align="left" style="margin-left:500px">
            <input type="button" onclick="LeaveSubmit()" value="提交表单" />
        </div>
    </div>
</body>
</html>
View Code

 

ASP.Net Cookie

标签:ted   file   size   tofixed   ring   getc   txt   desc   rip   

原文地址:https://www.cnblogs.com/XJNB/p/13277414.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!