Csharpsss
2018-06-13 02:23
采纳率: 88.2%
浏览 876

求类似案例源码!!winform用户登陆只能查看自己的信息 并且不可修改

管理员可查看所有人 可以修改指定用户指定权限

满足标题就可以了

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

7条回答 默认 最新

  • dabocaiqq 2018-06-13 03:04
    已采纳
     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;
    
    namespace Q691926
    {
        public partial class LoginDialog : Form
        {
            public LoginDialog()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var db = new Q691926DBClassDataContext();
                if (db.UserInfos.Any(x => x.username == textBox1.Text && x.pwd == textBox2.Text))
                {
                    this.Hide();
                    Session.UserName = textBox1.Text;
                    var f = new MainForm();
                    f.FormClosed += new FormClosedEventHandler(f_FormClosed);
                    f.Show();
                }
                else
                {
                    MessageBox.Show("wrong password!");
                }
            }
    
            void f_FormClosed(object sender, FormClosedEventArgs e)
            {
                this.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;
    
    namespace Q691926
    {
        public partial class MainForm : Form
        {
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void MainForm_Load(object sender, EventArgs e)
            {
                var db = new Q691926DBClassDataContext();
                string query = db.UserInfos.First(x => x.username == Session.UserName).info;
                label1.Text = query;
            }
        }
    }
    
    
    打赏 评论
  • 做好登录,用对象存储用户身份就行了,然后依据身份读取自己的或者所有人的信息

    打赏 评论
  • 你这个应该很简单的。等会登陆你显示用户自己的信息。管理员登陆时,查询所有咯,管理员可以指定用户权限,这个是就相当于修改了。权限字段。
    然后相应功能,sql里条件加权限咯。也可以给你写个简单列子。

    打赏 评论
  • dabocaiqq 2018-06-13 03:06

    图片说明

    打赏 评论
  • dabocaiqq 2018-06-13 03:08

    完整代码:https://download.csdn.net/download/dabocaiqq/10475944
    求采纳,谢谢。

    打赏 评论
  • dabocaiqq 2018-06-13 03:29

    权限也给你做了

    图片说明

    打赏 评论
  • dabocaiqq 2018-06-13 03:32

    下载:https://download.csdn.net/download/dabocaiqq/10476038

     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;
    
    namespace Q691926
    {
        public partial class MainForm : Form
        {
            public MainForm()
            {
                InitializeComponent();
            }
    
            private void MainForm_Load(object sender, EventArgs e)
            {
                var db = new Q691926DBClassDataContext();
                string query = db.UserInfos.First(x => x.username == Session.UserName).info;
                label1.Text = query;
                if (db.UserInfos.First(x => x.username == Session.UserName).isadmin)
                {
                    panel1.Visible = true;
                    comboBox1.Items.Clear();
                    foreach (var item in db.UserInfos)
                    {
                        comboBox1.Items.Add(item.username);
                    }
                    comboBox1.TextChanged += new EventHandler(comboBox1_TextChanged);
                }
                else
                {
                    panel1.Visible = false;
                }
            }
    
            void comboBox1_TextChanged(object sender, EventArgs e)
            {
                var db = new Q691926DBClassDataContext();
                if (db.UserInfos.Any(x => x.username == comboBox1.Text))
                {
                    textBox1.Text = db.UserInfos.First(x => x.username == comboBox1.Text).info;
                }
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                var db = new Q691926DBClassDataContext();
                if (db.UserInfos.Any(x => x.username == comboBox1.Text))
                {
                    var u = db.UserInfos.First(x => x.username == comboBox1.Text);
                    u.info = textBox1.Text;
                    db.SubmitChanges();
                }
            }
        }
    }
    
    
    打赏 评论

相关推荐 更多相似问题