• 登陆,激活,权限


    连接数据库

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 登陆_激活_权限.Model
    {
        public class Login
        {
            public string Username { get; set; }
            public string Password { get; set; }
            public bool State { get; set; }
            public string Permissions { get; set; }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using 登陆_激活_权限.Model;
    using System.Data.SqlClient;
    
    namespace 登陆_激活_权限.DataOperation
    {
        public class LoginData
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            public LoginData()
            {
                conn = new SqlConnection("server=.;database=Data0425;user=sa;pwd=123;");
                cmd = conn.CreateCommand();
            }
    
            public Login SelectUser(string Uname, string Pwd)
            {
                Login log = null;
                cmd.CommandText = "select *from [Login] where Username=@u and Password = @p";
                cmd.Parameters.Clear();
                cmd.Parameters.Add("@u", Uname);
                cmd.Parameters.Add("@p", Pwd);
    
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    log = new Login();
                    dr.Read();
                    log.Username = dr["Username"].ToString();
                    log.Password = dr["Password"].ToString();
                    log.State = Convert.ToBoolean(dr["State"]);
                    log.Permissions = dr["Permissions"].ToString();
                }
    
                conn.Close();
                return log;
            }
    
    
        }
    }

    表单设置

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using 登陆_激活_权限.DataOperation;
    using 登陆_激活_权限.Model;
    
    namespace 登陆_激活_权限
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //1、验证用户名
                string name = textBox1.Text;
                string pwd = textBox2.Text;
    
                Login loo = new LoginData().SelectUser(name, pwd);
                if (loo == null)
                {
                    MessageBox.Show("账户不存在!");
                }
                else
                { 
                    //1、判断账户是否激活
                    if (loo.State)
                    {
                        Form2 f2 = new Form2(this,loo);
                        f2.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("账户未激活!无法登陆!");
                    }
                }
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using 登陆_激活_权限.Model;
    
    namespace 登陆_激活_权限
    {
        public partial class Form2 : Form
        {
            Form1 F1 = null;
            public Form2(Form1 f1,Login looo)
            {
                InitializeComponent();
                F1 = f1;
                string[] aaa = looo.Permissions.Split(',');
    
                if (aaa.Contains("101"))
                {
                    button1.Visible = true;
                }
                if (aaa.Contains("102"))
                {
                    button2.Visible = true;
                }
                if (aaa.Contains("103"))
                {
                    button3.Visible = true;
                }
                
                
    
            }
        }
    }
  • 相关阅读:
    mysql 5.6
    mysql5.7 二进制包安装
    centos 6 编译安装httpd-2.4
    mysql 5.5源码包安装
    BZOJ4945 & 洛谷3825 & UOJ317:[NOI2017]游戏——题解
    BZOJ4943 & 洛谷3823 & UOJ315:[NOI2017]蚯蚓排队——题解
    BZOJ3435 & 洛谷3920 & UOJ55:[WC2014]紫荆花之恋
    BZOJ5343 & 洛谷4602 & LOJ2555:[CTSC2018]混合果汁——题解
    真·APIO2018滚粗记
    BZOJ4518:[SDOI2016]征途——题解
  • 原文地址:https://www.cnblogs.com/zhangdemin/p/5681618.html
Copyright © 2020-2023  润新知