管理软件coolite开发之登录
开发环境:VS2008、SQL Server2005、Coolite Toolkit
界面
UI代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="e_HR.login" %> <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %> <!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>e-HR Login</title> <style type="text/css"> .user{ background:url(images/user.gif) no-repeat 1px 2px; } .key{ background:url(images/key.gif) no-repeat 1px 2px; } .key,.user{ background-color:#FFFFFF; padding-left:20px; font-weight:bold; color:#000033; } </style> </head> <body> <form id="form1" runat="server"> <ext:scriptmanager runat="server"/> <ext:Window ID="WinLogin" runat="server" Collapsible="true" Height="200px" Icon="Application" Title="Login From" Width="350px" Closable="False"> <Body> <ext:FormLayout ID="FormLayout1" runat="server"> <Anchors> <ext:Anchor Horizontal="100%"> <ext:TextField runat="server" FieldLabel="User Name" ID="tbxUserID" EmptyText="请输入用户名:" AllowBlank="False" TabIndex="1" FieldClass="user" /> </ext:Anchor> <ext:Anchor Horizontal="100%"> <ext:TextField runat="server" AllowBlank="False" ID="tbxPSW" EmptyText="请输入密码" FieldLabel="Pass Word" InputType="Password" TabIndex="2" FieldClass="key" /> </ext:Anchor> <ext:Anchor Horizontal="100%"> <ext:TextField runat="server" AllowBlank="False" ID="tbxCaptcha" EmptyText="请输入验证码" FieldLabel="Validate Code" TabIndex="3" /> </ext:Anchor> <ext:Anchor Horizontal="100%"> <ext:Image ID="imgCaptcha" runat="server" ImageUrl="~/basic/captcha/captcha.ashx?w=207&h=30" /> </ext:Anchor> </Anchors> </ext:FormLayout> </Body> <Buttons> <ext:Button ID="btnLogin" runat="server" Text="登录" Icon="Accept" Pressed="true" TabIndex="4"> <Listeners> <Click Handler=" if(!#{tbxUserID}.validate() || !#{tbxPSW}.validate()|| !#{tbxCaptcha}.validate()) { Ext.Msg.alert('警告','用户名或密码或验证码不能为空!'); // return false to prevent the btnLogin_Click Ajax Click event from firing. return false; }" /> </Listeners> <AjaxEvents> <Click OnEvent="btnLogin_Click"> <EventMask ShowMask="true" Msg="数据验证中..." MinDelay="50" /> </Click> </AjaxEvents> </ext:Button> <%-- <ext:Button ID="btnReset" runat="server" Text="重置" Type="Reset" Icon="ArrowRefreshSmall"> <Listeners> <Click Handler="login.getForm().reset();" /> </Listeners> </ext:Button>--%> <ext:Button ID="btnCancel" runat="server" Text="退出" Icon="Cancel" OnClientClick="javascript:window.close();" TabIndex="5" StyleSpec="margin-right:50;margin-left:25;float:right;"> </ext:Button> </Buttons> </ext:Window> </form> </body> </html>
C#代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Coolite; using Coolite.Ext; using Coolite.Ext.Web; using Coolite.Utilities; using Sys_Business; namespace e_HR { public partial class login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadData(); } } // For generating random numbers. private Random random = new Random(); private void LoadData() { // Create a random code and store it in the Session object. Session["CaptchaImageText"] = GenerateRandomCode(); } private string GenerateRandomCode() { string s = ""; for (int i = 0; i < 6; i++) s = String.Concat(s, random.Next(10).ToString()); return s; } protected void btnLogin_Click(object sender, AjaxEventArgs e) { //if (tbxCaptcha.Text != Session["CaptchaImageText"].ToString()) //{ // Alert.ShowInParent("Error Validate Code!"); // return; //} string msg = Sys_Business.Systeminfo.Winlogin(tbxUserID.Text, tbxPSW.Text).ToString(); //if (tbxUserName.Text == "admin" && tbxPassword.Text == "admin") if (msg == "") { Session["User_ID"] = tbxUserID.Text; Response.Redirect("main.aspx"); } else { //Alert.ShowInParent("Login Failed!"); //Alert.ShowInParent(msg); //LoadData(); Ext.Msg.Show(new MessageBox.Config { Title = "错误", Message = msg, Icon = (MessageBox.Icon)Enum.Parse(typeof(MessageBox.Icon), "ERROR") }); } } } }