XX管理系统案例

一.登录界面
建立登录文件夹Login,在此目录下面建立如下文件:
Index.htm:登录页面
ValidateCode.cs:生成验证码
ProcessVerification.ashx:处理验证码
CommonHelper.cs:帮助处理类
Login.ashx:处理登录

Index.htm:登录页面

<!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>
    <title>XX后台管理系统登录</title>
    <link href="../css/StyleHouTai.css" rel="stylesheet" />
    <script type="text/javascript">
        if (window.parent.window != window) {
            window.top.location.href = "/Home/CheckLogin";
        }
    </script>
    <script src="../script/jquery-1.8.3.js" type="text/javascript"></script>
    <script src="../script/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function changeCheckCode() {
            $("#img").attr("src",$("#img").attr("src")+1);
        }
        function afterLogin(data) {
            var serverData = data.split(‘:‘);
            if (serverData[0] == "ok") {
                window.location.href = "/Home/Index";
            } else if (serverData[0] == "no") {
                $("#errorMsg").text(serverData[1]);
                changeCheckCode();
            } else {
                $("#errorMsg").text("系统繁忙");
            }
        }

        function blurCode(id,idErr,errCode) {
            $(id).blur(function () {
                var loginCode = $(id).val();
                //因js不支持trim()函数,需要使用此函数时添加以下语句
                //String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); }
                //if (loginCode.trim().length <= 0) {
                if ($.trim(loginCode).length <= 0) {
                    $(idErr).text(errCode);
                    return;
                }
                else {
                    $(idErr).text("");
                }
            });
        }

        $(function () {
            blurCode(‘#LoginCode‘, ‘#LoginCodeErr‘, ‘请输入账号‘);
            blurCode(‘#LoginPwd‘, ‘#LoginPwdErr‘, ‘请输入密码‘);
            blurCode(‘#code‘, ‘#codeErr‘, ‘请输入验证码‘);
        });

//            $(‘#btnLogin‘).click(function () {
//                var loginCode = $("#LoginCode").val();
//                var loginPwd = $("#LoginPwd").val();
//                if (loginCode.length <= 0) {
//                    alert("请输入账号");
//                }

//                $("#errorMsg").text("登录失败");
//                changeCheckCode();
//            });

        /*
        $(function () {
            $(‘#LoginCode‘).blur(function () {
                var loginCode = $("#LoginCode").val();
                if (loginCode.trim().length <= 0) {
                    $("#LoginCodeErr").text("请输入账号");
                }
                else {
                    $("#LoginCodeErr").text("");
                }
            });
            $(‘#LoginPwd‘).blur(function () {
                var loginPwd = $("#LoginPwd").val();
                if (loginPwd.trim().length <= 0) {
                    $("#LoginPwdErr").text("请输入密码");
                }
                else {
                    $("#LoginPwdErr").text("");
                }
            });
            $(‘#code‘).blur(function () {
                var code = $("#code").val();
                if (code.trim().length <= 0) {
                    $("#codeErr").text("请输入验证码");
                }
                else {
                    $("#codeErr").text("");
                }
            });
        });*/

    </script>

</head>
<body style="padding: 10px">

    <div id="login">
        <div id="loginlogo">
        </div>
        <div id="loginpanel">
            <div class="panel-h">
            </div>
            <div class="panel-c">
                <div class="panel-c-l">
                    <form action="Login.ashx" method="post">

                    <table cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td align="left" colspan="2">
                                    <h3>请使用XX系统账号登录</h3>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">账号:</td>
                                <td align="left">
                                    <input type="text" style="width:150px" name="LoginCode" id="LoginCode" class="login-text" />
                                    <span id="LoginCodeErr" style="color:Red"></span>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    密码:
                                </td>
                                <td align="left">
                                    <input type="password" style="width:150px" name="LoginPwd" id="LoginPwd" value="" class="login-text" />
                                    <span id="LoginPwdErr" style="color:Red"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    验证码:
                                </td>
                                <td align="left">
                                    <input type="text" style="width:150px" class="login-text" id="code" name="vCode" value="" />
                                    <span id="codeErr" style="color:Red"></span>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <img id="img" src="ProcessVerification.ashx?id=1" style="float: left; height: 24px;" />

                                    <div style="float: left; margin-left: 5px; margin-top: 10px;">
                                        <a href="javascript:void(0)" onclick="changeCheckCode();return false;">看不清,换一张</a>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <input type="submit" name="btnLogin" id="btnLogin" value="登录" class="login-btn" />
                                    <span id="errorMsg"></span>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>

                </div>
                <div class="panel-c-r">
                    <p>
                        请从左侧输入登录账号和密码登录</p>
                    <p>
                        如果遇到系统问题,请联系网络管理员。</p>
                    <p>
                        如果没有账号,请联系网站管理员。
                    </p>
                    <p>
                        ......</p>
                </div>
            </div>
            <div class="panel-f">
            </div>
        </div>
        <div id="logincopyright">
            Copyright 2015 www.syfpc.com
        </div>
    </div>
</body>
</html>

ValidateCode.cs:生成验证码

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;

namespace modelInput
{
   public class ValidateCode
    {
        public ValidateCode()
        {
        }
        /// <summary>
        /// 验证码的最大长度
        /// </summary>
        public int MaxLength
        {
            get { return 10; }
        }
        /// <summary>
        /// 验证码的最小长度
        /// </summary>
        public int MinLength
        {
            get { return 1; }
        }
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="length">指定验证码的长度</param>
        /// <returns></returns>
        public string CreateValidateCode(int length)
        {
            int[] randMembers = new int[length];
            int[] validateNums = new int[length];
            string validateNumberStr = "";
            //生成起始序列值
            int seekSeek = unchecked((int)DateTime.Now.Ticks);
            Random seekRand = new Random(seekSeek);
            int beginSeek = (int)seekRand.Next(0, Int32.MaxValue - length * 10000);
            int[] seeks = new int[length];
            for (int i = 0; i < length; i++)
            {
                beginSeek += 10000;
                seeks[i] = beginSeek;
            }
            //生成随机数字
            for (int i = 0; i < length; i++)
            {
                Random rand = new Random(seeks[i]);
                int pownum = 1 * (int)Math.Pow(10, length);
                randMembers[i] = rand.Next(pownum, Int32.MaxValue);
            }
            //抽取随机数字
            for (int i = 0; i < length; i++)
            {
                string numStr = randMembers[i].ToString();
                int numLength = numStr.Length;
                Random rand = new Random();
                int numPosition = rand.Next(0, numLength - 1);
                validateNums[i] = Int32.Parse(numStr.Substring(numPosition, 1));
            }
            //生成验证码
            for (int i = 0; i < length; i++)
            {
                validateNumberStr += validateNums[i].ToString();
            }
            return validateNumberStr;
        }
        /// <summary>
        /// 创建验证码的图片
        /// </summary>
        /// <param name="context">要输出到的page对象</param>
        /// <param name="validateNum">验证码</param>
        public void CreateValidateGraphic(string validateCode, HttpContext context)
        {
            Bitmap image = new Bitmap((int)Math.Ceiling(validateCode.Length * 12.0), 22);
            Graphics g = Graphics.FromImage(image);
            try
            {
                //生成随机生成器
                Random random = new Random();
                //清空图片背景色
                g.Clear(Color.White);
                //画图片的干扰线
                for (int i = 0; i < 25; i++)
                {
                    int x1 = random.Next(image.Width);
                    int x2 = random.Next(image.Width);
                    int y1 = random.Next(image.Height);
                    int y2 = random.Next(image.Height);
                    g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
                }
                Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle.Italic));
                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),
                 Color.Blue, Color.DarkRed, 1.2f, true);
                g.DrawString(validateCode, font, brush, 3, 2);
                //画图片的前景干扰点
                for (int i = 0; i < 100; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);
                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }
                //画图片的边框线
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                //保存图片数据
                MemoryStream stream = new MemoryStream();
                image.Save(stream, ImageFormat.Jpeg);
                //输出图片流
                context.Response.Clear();
                context.Response.ContentType = "image/jpeg";
                context.Response.BinaryWrite(stream.ToArray());
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }
        /// <summary>
        /// 得到验证码图片的长度
        /// </summary>
        /// <param name="validateNumLength">验证码的长度</param>
        /// <returns></returns>
        public static int GetImageWidth(int validateNumLength)
        {
            return (int)(validateNumLength * 12.0);
        }
        /// <summary>
        /// 得到验证码的高度
        /// </summary>
        /// <returns></returns>
        public static double GetImageHeight()
        {
            return 22.5;
        }

        //C# MVC 升级版
        /// <summary>
        /// 创建验证码的图片
        /// </summary>
        /// <param name="containsPage">要输出到的page对象</param>
        /// <param name="validateNum">验证码</param>
        public byte[] CreateValidateGraphic(string validateCode)
        {
            Bitmap image = new Bitmap((int)Math.Ceiling(validateCode.Length * 12.0), 22);
            Graphics g = Graphics.FromImage(image);
            try
            {
                //生成随机生成器
                Random random = new Random();
                //清空图片背景色
                g.Clear(Color.White);
                //画图片的干扰线
                for (int i = 0; i < 25; i++)
                {
                    int x1 = random.Next(image.Width);
                    int x2 = random.Next(image.Width);
                    int y1 = random.Next(image.Height);
                    int y2 = random.Next(image.Height);
                    g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
                }
                Font font = new Font("Arial", 12, (FontStyle.Bold | FontStyle.Italic));
                LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height),
                 Color.Blue, Color.DarkRed, 1.2f, true);
                g.DrawString(validateCode, font, brush, 3, 2);
                //画图片的前景干扰点
                for (int i = 0; i < 100; i++)
                {
                    int x = random.Next(image.Width);
                    int y = random.Next(image.Height);
                    image.SetPixel(x, y, Color.FromArgb(random.Next()));
                }
                //画图片的边框线
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
                //保存图片数据
                MemoryStream stream = new MemoryStream();
                image.Save(stream, ImageFormat.Jpeg);
                //输出图片流
                return stream.ToArray();
            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }
    }
}

ProcessVerification.ashx:处理验证码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using modelInput;
using System.Drawing;
using System.Drawing.Imaging;

namespace XX管理系统.Login
{
    /// <summary>
    /// ProcessVerification 的摘要说明
    /// </summary>
    public class ProcessVerification : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";
            ValidateCode validateCode = new ValidateCode();
            string code = validateCode.CreateValidateCode(4);
            //创建cookie对象
            HttpCookie cookie = new HttpCookie("vCode");
            //将cookie值等于自动生成的验证码
            cookie.Value = code;
            //更新cookie值
            context.Response.SetCookie(cookie);
            using (Bitmap bmp = new Bitmap(100, 50))//创建一个尺寸为500*500的内存图片
            using (Graphics g = Graphics.FromImage(bmp))//得到图片的画布
            {
                g.DrawString(code, new Font(FontFamily.GenericSerif, 30), Brushes.Red, 0, 0);//Font应该被释放
                bmp.Save(context.Response.OutputStream, ImageFormat.Jpeg);//图片保存到输出流
            }
        }

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

CommonHelper.cs:帮助处理类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;

namespace XX管理系统
{
    public class CommonHelper
    {
        /// <summary>
        /// 返回HTML文件内容
        /// </summary>
        /// <param name="fileName">HTML文件</param>
        /// <returns></returns>
        public static string ReadHtml(string fileName)
        {
            HttpContext context = HttpContext.Current;
            string fullpath = context.Server.MapPath(fileName);
            string html = File.ReadAllText(fullpath);
            return html;
        }
    }
}

Login.ashx:处理登录

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "text/html";
    //LoginCode,LoginPwd,
    string loginCode = context.Request["LoginCode"];//用户名
    string loginPwd = context.Request["LoginPwd"];//密码
    string vCode = context.Request["vCode"];//验证码
    //获取客户端的cookie值
    HttpCookie cookie = context.Request.Cookies["vCode"];
    if (cookie == null)
    {
        context.Response.Write("找不到系统生成的验证码");
        context.Response.Redirect("Index.htm");
        return;
    }
    if (vCode != cookie.Value)
    {
        context.Response.Write("验证码错误");
        context.Response.Redirect("Index.htm");
        return;
    }
    int r = (int)SQLHelper.ExecuteScalar("select count(*) from Users where [email protected] and [email protected]",
        new SqlParameter { ParameterName = "@loginCode", Value = loginCode },
        new SqlParameter { ParameterName = "@loginPwd",Value=loginPwd });
    if (r == 1)
    {
        context.Response.Redirect("../Home.htm");
    }

}
时间: 2024-08-24 11:34:19

XX管理系统案例的相关文章

C07 模块化开发信息管理系统案例

目录 需求分析 问题分析 开发阶段 需求分析 总体需求 学员信息管理系统支持以下功能 增加学员信息功能 删除学员信息功能 查询学员信息功能 修改学员信息功能 输出所有学员信息功能 退出系统 其他需求 学员信息需求 学号4位数字 姓名不能超过20个字符 地址不能超过30个字符 手机号码必须为11位数字 成绩在0-100之间 初始状态系统保持2名学员信息 必要的信息提示 例如:姓名长度不正确.手机号码长度不正确等. 问题分析 全局变量 Char  students[50][200];  //存储50

shell脚本自动化部署XX的案例(附数组使用)

#!/bin/sh #Auto Make install MFS Files # cat <<EOF ++++++++++++++++Welcome To Use Auto Install MFS Scripts ++++++++++++++++++ +++++++++++++++++++++This MFS Install Version 1.6.27++++++++++++++++++++++ +++++++++++++++++++++++++2013-12-04 Author wugk

客户管理系统 详细流程(不用三大框架)

客户管理系统的详细编写流程 一.系统设计 1.需求分析 (系统中包含哪些数据模型.数据模型存在怎样的关系 E-R图.UML(用例图)) 2.制作页面Demo (和真实系统效果一样,给客户确认需求) 3.技术选型(环境搭建) 软件建模工具:IBM RSA.Rational Rose.Jude(日本研发 纯java编写,小巧.在此次编写中使用) 技术选型:DHTML+JSP+Servlet+C3P0+DBUtils+MySQL(MVC模式,DAO模型)+Tomcat6+Windows 4.数据库设计

python继承关系及DVD案例

1.模块.getrefcount--查看引用个数,如果没有引用,则抛异常: 2.继承:简化代码.生成子类时,先初始化父类 继承属性--①self.属性=当前属性 ②父类.属性=当前属性 ③父类._init_()方法 ④super(子类,self)._init_()方法 3.构造方法(必须有返回值)优先于初始化方法 类名.mso用于调用父类的位置 def _new_(cls,*,**): print() return object._new_(cls) 4.类方法:@classmethod需要参数

如何自学成为一个WEB前端

WEB前端是做什么的? 那些什么高大上的介绍作者就略过了,简单来说就是做网页的,我们上网浏览的网站界面就是WEB前端工程师做的. 在互联网迅速发展的近几年,你上网冲浪的时候是不是感觉WEB网站越来越漂亮酷炫,功能越来越多,越来越复杂?各种类似桌面软件的Web应用大量出现,没错,WEB前端在其中有着很大的功劳. 发展方向 WEB前端的发展迅速导致其细分出了很多细分职业,我先来说一下我了解的WEB前端的分支,欢迎各位前辈补充: 1.网页设计方向(移动和PC):主要偏向html.css.js主要是做一

JAVA相关的视频学习视频,内容较多

开源项目: Jeecg(Java快速开发平台)  http://git.oschina.net/jeecg/jeecg Jeewx(微信开发平台) http://git.oschina.net/jeecg/jeewx Minidao(持久层)  http://git.oschina.net/jeecg/minidao Jeewx-API(微信接口API) http://git.oschina.net/jeecg/jeewx-api P3-Weixin(Saas插件开发框架)http://git.

第8天 Java基础语法

第8天 Java基础语法 今日内容介绍 Eclipse开发工具 超市库存管理系统 Eclipse开发工具 Eclipse是功能强大Java集成开发工具.它可以极大地提升我们的开发效率.可以自动编译,检查错误.在公司中,使用的就是Eclipse进行开发. Eclipse的下载.安装.卸载 下载 http://www.eclipse.org 安装 (只需要解压后就能使用) 卸载(只需要将文件夹删除就可以了) 注意: 开发软件的安装目录中,尽量不要出现空格与中文 Eclipse的使用 在当前阶段,我们

如何从菜鸟到伪高手

如何从菜鸟程序员成长为(伪)高手 目录 [显示] 1.摘要 最近有一些毕业不久的同事问我:"你工作的时候有没有什么窍门?怎么才能快速成为高手?" 想起当初刚入职,新人培训的时候,也跟其他同事讨论过这个问题:如何才能成为业界大牛?当时自己只是觉得兴趣是最好的老师,思路方法什么的没有多想. 加入微博平台架构部的时间也不短了,趁着快过春节总结了一下自己入职微博以来的工作情况,从互联网开发的半个门外汉,到如今能设计一些架构.排查一 些问题.分享一些经验,收获颇多,感想颇多,也逐渐意识到思路和方

500 G JAVA视频网盘分享(JEECG开源社区)

[涵盖从java入门到深入架构,Linux.云计算.分布式.大数据Hadoop.ios.Android.互联网技术应有尽有] [转载:http://blog.csdn.net/zhangdaiscott/article/details/18220411] JEECG开源社区秉承开源宗旨,分享社区Java架构视频,更多资料点击: www.jeecg.org JAVA架构QQ技术群: 39596137 Jeecg开设师徒架构学习班(师傅带徒弟模式),有兴趣的可以参加学习 => 开源社区师徒架构班 1