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 name=@loginCode and password=@loginPwd",
        new SqlParameter { ParameterName = "@loginCode", Value = loginCode },
        new SqlParameter { ParameterName = "@loginPwd",Value=loginPwd });
    if (r == 1)
    {
        context.Response.Redirect("../Home.htm");
    }

}

 

转载于:https://www.cnblogs.com/genesis/p/4674104.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
项目名称: XX物业后台管理系统 项目描述: XX物业后台管理系统是一个为物业管理公司打造的全面管理解决方案。该系统旨在提供一个高效、智能、集成化的平台,以简化和优化物业管理公司的日常运营和管理流程。 主要功能和特点包括: 1. 物业管理: 包括楼宇信息管理、房屋信息管理、租赁信息管理、租户信息管理等功能。管理员可以轻松管理和更新物业相关信息,如楼宇维护、房屋出租情况等。 2. 人员管理: 提供员工信息管理模块,包括员工档案、考勤记录、薪资管理等功能。管理员可以方便地管理员工的基本信息和薪资发放情况。 3. 收费管理: 实现费用管理模块,包括物业费用、水电费用、维修费用等。管理员可以通过系统自动生成账单,并进行费用的收取和统计。 4. 报修管理: 提供在线报修功能,租户可以通过系统提交报修请求,并及时收到处理进度和结果的通知。管理员可以有效地安排维修人员,跟踪和处理报修事务。 5. 投诉管理: 提供投诉处理功能,租户可以通过系统提交投诉,并及时获得处理进度和结果。管理员可以快速响应和解决投诉事宜,提升租户满意度。 6. 统计分析: 提供数据统计和分析功能,管理员可以通过系统生成各类报表和图表,了解物业运营情况、租赁情况、费用情况等,为决策提供参考依据。 7. 消息通知: 实现系统内部的消息通知机制,管理员可以通过系统向租户发送通知、提醒和公告,方便及时沟通和信息传递。 8. 安全管理: 通过权限控制、数据加密等手段,保障系统的安全性和数据的保密性,防止信息泄露和非法访问。 该系统的设计理念是用户友好、功能强大、易于扩展。它将提高物业管理公司的工作效率,减少人力和时间成本,并提供更好的服务质量和租户满意度。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值