Easyui登陆页面制作

2018-06-17 20:21:10来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

一、登陆页面HTML

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.EasyUITest.WebForm1" %>

<!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>Login</title>
    <script src="../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="../Scripts/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $("#win").window({
                title: "Login",
                width: 300,
                height: 200,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                closable: false,
                closed: false,
                draggable: false,
                resizable: false,
                modal: true
            });
        });
        function login() {
            var name = $("#txt_name").val();
            var psd = $("#txt_psd").val();

            $.ajax({
                type: "POST",
                dataType: "json",
                url: "Service/login.ashx",
                data: { Method: "Login" },
                success: function (data) {
                    $.messager.alert("消息", data, "info");
                },
                error: function () {
                    $.messager.alert("消息", "错误!", "info");
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="win" class="easyui-window">
        <table>
            <tr>
                <td>
                    Name:
                </td>
                <td>
                    <input id="txt_name" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>
                <td>
                    <input id="txt_psd" type="text" />
                </td>
            </tr>
            <tr>
                <td>
                    <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="login()">Login</a>
                </td>
                <td>
                    <a href="#" class="easyui-linkbutton" iconcls="icon-cancel">Cancel</a>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

二、一般处理程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Reflection;
using System.Web.SessionState;
using Newtonsoft.Json;

namespace WebApplication1.EasyUITest.Service
{
    /// <summary>
    /// login 的摘要说明
    /// </summary>
    public class login : IHttpHandler, IRequiresSessionState
    {
        HttpRequest Request;
        HttpResponse Response;
        HttpSessionState Session;
        HttpServerUtility Server;
        //HttpCookie Cookie;

        public void ProcessRequest(HttpContext context)
        {
            //不让浏览器缓存
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";

            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
            Server = context.Server;

            string method = Request["Method"].ToString();
            MethodInfo methodInfo = this.GetType().GetMethod(method);
            methodInfo.Invoke(this, null);
        }

        public void Login()
        {
            Response.Write(JsonConvert.SerializeObject(DateTime.Now.ToString()));
        }

        [Serializable]
        public class Infomation
        {
            public string id { get; set; }
            public string msg { get; set; }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

三、Index页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="WebApplication1.EasyUITest.index" %>

<!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 src="../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.easyui.min.js" type="text/javascript"></script>
    <link href="../Scripts/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/themes/icon.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $("#tt").tree({
                checkbox: false,
                url: "Service/index.ashx?Method=GetTreeData&id=0",
                onBeforeExpand: function (node, param) {
                    $(this).tree("options").url = "Service/index.ashx?Method=GetTreeData&id=" + node.id;
                },
                onClick: function (node) {
                    $("#contentPage").attr("src", node.attributes);
                }
            });
        });
        function Open() {
            $("#contentPage").attr("src", "WebForm1.aspx");
        }
    </script>
</head>
<body class="easyui-layout">
    <div region="north" style="height: 100px;">
    </div>
    <div region="west" style="width: 200px;" title="west" split="true">
        <ul id="tt">
        </ul>
    </div>
    <div id="divCenter" region="center" title="center" style="padding: 5px; background: #eee;">
        <iframe id="contentPage" width="100%" height="100%" frameborder="0" marginheight="0"
            marginwidth="0"></iframe>
    </div>
</body>
</html>

四、Index一般处理程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Reflection;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Text;

namespace WebApplication1.EasyUITest.Service
{
    /// <summary>
    /// index 的摘要说明
    /// </summary>
    public class index : IHttpHandler
    {
        HttpRequest Request;
        HttpResponse Response;
        HttpServerUtility Server;
        HttpSessionState Session;
        public readonly string connectionString = ConfigurationManager.ConnectionStrings["BookConnectionString"].ToString();

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Buffer = true;
            context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";
            context.Response.ContentType = "text/plain";

            Request = context.Request;
            Response = context.Response;
            Session = context.Session;
            Server = context.Server;

            string method = Request["Method"].ToString();
            MethodInfo methodInfo = this.GetType().GetMethod(method);
            methodInfo.Invoke(this, null);
        }

        public void GetTreeData()
        {
            string id = Request.QueryString["id"].ToString();
            string sqlStr = "SELECT * FROM dbo.tree where parentid=" + id;
            DataSet ds = new DataSet();
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(sqlStr, conn))
                {
                    da.Fill(ds);
                }
            }
            StringBuilder sb = new StringBuilder();
            sb.Append("[");
            foreach (DataRow r in ds.Tables[0].Rows)
            {
                sb.Append("{");
                sb.AppendFormat("\"id\": \"{0}\", \"text\": \"{1}\", \"state\": \"closed\",\"attributes\":\"{2}\"", r["id"], r["name"], r["url"]);
                sb.Append("},");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            sb.Append("]");
            Response.Write(sb.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:【中英对照】【EntLib6】【Unity】实验1:使用一个Unity容器

下一篇:C#操作Excel(2)-- 打开-读取Excel文档