ERP登录(八)

网友投稿 956 2022-08-31

ERP登录(八)

登录的存储过程:

ALTER PROCEDURE [dbo].[UserLogin] @userid int output, @LoginName nvarchar(50), @Password nvarchar(50) ASBEGIN SET NOCOUNT ON; DECLARE @count int --查询指定表,返回符合条件的个数 SELECT @count=count(*) FROM UserManager WHERE LoginName=@LoginName AND Password=@Password -- PRINT '行数:'+convert(varchar(10),@count) --判断是否有用户,如果有则返回用户ID,否则返回0 IF (@count!=0) begin select @userid=UserId FROM UserManager WHERE LoginName=@LoginName AND Password=@Password END ELSE BEGIN SET @userid=0 END END

业务层的代码:

///

/// 用户登录,返回符合登录名和密码的用户的条数 /// /// 登录名 /// 登录密码 /// int public int UserLogin(string LoginName, string Pwd) { SqlParameter []pars = new SqlParameter[]{ new SqlParameter("@userid",SqlDbType.Int), new SqlParameter("@LoginName",LoginName), new SqlParameter("@Password",Pwd) }; //指定为输出参数 pars[0].Direction = ParameterDirection.Output; DataBaseHelper.SelectSQLReturnObject("UserLogin", CommandType.StoredProcedure, pars); //object count = DataBaseHelper.SelectSQLReturnObject("UserLogin", CommandType.StoredProcedure, pars); //if (count != null) //{ // return int.Parse(count.ToString()); //} //return 0; if (pars[0].Value.ToString() != "0") { return int.Parse(pars[0].Value.ToString()); } else { return 0; } }

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UserLogin.aspx.cs" Inherits="BioErpWeb.Web.UserLogin" %>

用户:
密码:
验证码:
成都Bio公司ERP系统.版权所有 2011-2012
请使用IE6.0 SP1以上浏览器,最佳显示分辨率1024×768

验证码的流程图:

验证码的代码:

public partial class ViewImg : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string chcode = ""; //颜色列表,用于验证码,噪线,躁点的绘制 Color[] colors = { Color.Black, Color.Red, Color.Green, Color.Orange, Color.Yellow, Color.DarkBlue }; //字体列表,用于验证码 string[] font = { "Times New Roman", "MS MinCho", "Book Antiqua", "Gungsuh", "PMingLiU", "Impact" }; //验证码的字符集,去掉容易混淆的字符 char[] Character = { '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' }; Random random = new Random(); //随机生成验证码 for (int i = 0; i < 4; i++) { chcode += Character[random.Next(Character.Length)]; } //保存验证码 Cookie HttpCookie anycookie = new HttpCookie("ValidateCookie"); anycookie.Values.Add("Chcode", chcode); HttpContext.Current.Response.Cookies["ValidateCookie"].Values["Chcode"] = chcode; Bitmap bmp = new Bitmap(150, 30); Graphics g = Graphics.FromImage(bmp); //清空内容 g.Clear(Color.White); //画噪音线 for (int i = 0; i < 5; i++) { int x1 = random.Next(150); int y1 = random.Next(30); int x2 = random.Next(150); int y2 = random.Next(30); Color clr = colors[random.Next(colors.Length)]; g.DrawLine(new Pen(clr), x1, y1, x2, y2); } //画验证码字符串 for (int i = 0; i < chcode.Length; i++) { string fontsytle = font[random.Next(font.Length)]; Font fnt = new Font(fontsytle, 16); Color fcolor = colors[random.Next(colors.Length)]; g.DrawString(chcode[i].ToString(), fnt, new SolidBrush(fcolor), i * 20 + 20, 6); } //画噪点 for (int i = 0; i < 100; i++) { int x = random.Next(bmp.Width); int y = random.Next(bmp.Height); Color fcolor = colors[random.Next(colors.Length)]; bmp.SetPixel(x, y, fcolor); } //清除该页输出缓存,设置该页无缓存 Response.Buffer = true; Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0); Response.Expires = 0; Response.CacheControl = "no-cache"; Response.AppendHeader("Pragma", "No-Cache"); //把验证码图片写入到内存中,并以图片格式输出("imgae/png"); MemoryStream stream = new MemoryStream(); try { bmp.Save(stream, ImageFormat.Png); Response.ClearContent(); Response.ContentType = "Image/png"; Response.BinaryWrite(stream.ToArray()); } finally { bmp.Dispose(); g.Dispose(); } } }

登录的代码:

用户权限绑定菜单:设计方案:

-- Description: 根据权限id获取权限信息-- =============================================ALTER PROCEDURE [dbo].[getRightById] @id int ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT ID, RightName, ReMark FROM tbRight WHERE ID=@idEND

BLL层:

///

/// 根据指定ID返回其对象 /// /// userid /// UserManager public UserManager getuserbyId(string id) { UserManager user = new UserManager(); SqlParameter[] pars = new SqlParameter[]{ new SqlParameter("@userid",id) }; SqlDataReader reader = DataBaseHelper.SelectSQLReturnReader("getUserByid", CommandType.StoredProcedure, pars); while (reader.Read()) { user.LoginName = reader["LoginName"].ToString(); user.UserName = reader["UserName"].ToString(); user.DepartmentId =int.Parse(reader["DepartmentId"].ToString()); user.RoleId = int.Parse(reader["RoleId"].ToString()); user.Birthday =Convert.ToDateTime(reader["Birthday"].ToString()); user.Mobile = reader["Mobile"].ToString(); user.Email = reader["Email"].ToString(); user.Photo = reader["Photo"].ToString(); user.Address = reader["Address"].ToString(); user.LastLoginDate = Convert.ToDateTime(reader["LastLoginDate"].ToString()); user.Sex = reader["Sex"].ToString() == "True" ? true : false; user.DisplayOrder =int.Parse( reader["DisplayOrder"].ToString()); user.Sate = reader["Sate"].ToString() == "True" ? true : false; } reader.Close(); return user; }

创建菜单的时候进行权限的筛选:

protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CreateTreeVeiw(); TreeView1.NodeStyle.Font.Size = FontUnit.Parse("13px"); } } DataSet ds; DataTable dt; private void CreateTreeVeiw() { UserRightMangerBLL userrightbll=new UserRightMangerBLL(); DataTable RightList=userrightbll.getUserRightListByUserID(Session["Userid"].ToString()); string UserRightList=""; for(int i=0;i0) { CreateSubTreeView(n, dv); } } }

先加载Index页面:

protected void Page_Load(object sender, EventArgs e) { if (Session["Userid"] == null) { Server.Transfer("UserLogin.aspx"); return; } }

创建外键约束的方法:

.

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ERP员工入登记查询(六)
下一篇:为什么要内存对齐?Go 语言有时也需要考虑对齐的问题(内存对齐和字节对齐是一回事吗)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~