Example #1
0
        public void LoadSysData()
        {
            //如果没有admin用户,添加该用户

            myEFContext db = new myEFContext();

            //检查系统设置

            int n = db.sysInfo.Count();

            if (n == 1)
            {
                sysInfo sysInfo = db.sysInfo.First();

                SysSec.companyName = sysInfo.companyName;
                SysSec.sysName     = sysInfo.sysName;
            }

            n = db.Users.Where(t => t.UserLoginName.ToLower() == "admin").Count();
            if (n == 0)
            {
                User adminUser = new User
                {
                    UserLoginName  = "admin",
                    UserPassword   = SysSec.StringSec("admin"),
                    UserName       = "******",
                    Level          = 0,
                    Enable         = true,
                    remark         = "系统内置管理员,不能删除",
                    UserCreateTime = DateTime.Now,
                    LastLoginTime  = null
                };

                db.Users.Add(adminUser);
                db.SaveChanges();

                //自动打开系统配置界面
                MessageBox.Show("第一次登录使用系统,请设置系统数据");
                Form dbset = new sys.SysSet();

                dbset.ShowDialog();
            }
        }
Example #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            //检查登录
            string yhm  = TextBox1.Text;
            string mima = TextBox4.Text;

            if (string.IsNullOrEmpty(yhm) | string.IsNullOrEmpty(mima))
            {
                MessageBox.Show(this, "用户名或者密码为空,请检查。系统不允许用户使用空密码。",
                                "用户名或密码不能为空", MessageBoxButtons.OK);
                return;
            }

            //检查用户名
            myEFContext db = new myEFContext();

            User user = db.Users.FirstOrDefault(t => t.UserLoginName.ToUpper() == yhm.ToUpper());

            if (user == null)
            {
                MessageBox.Show(this, "未找到用户名,请检查。用户名一般为姓名全拼,请联系管理员添加。",
                                "用户名不存在", MessageBoxButtons.OK);
                return;
            }
            //检查用户密码
            if (user.UserPassword != sys.SysSec.StringSec(mima))
            {
                MessageBox.Show(this, "用户密码不配对。",
                                "密码错误", MessageBoxButtons.OK);
                return;
            }

            if (user.Enable == false)
            {
                MessageBox.Show(this, "用户已经被禁止登录,请联系管理员", "警告", MessageBoxButtons.OK);
                return;
            }


            //更新登录信息

            user.LastLoginTime = DateTime.Now;
            db.SaveChanges();

            PublicVar.UserLoginName = user.UserLoginName;
            PublicVar.UserName      = user.UserName;

            //记住用户
            if (CheckBox1.Checked == true)
            {
                PublicVar.SetUserName(yhm);
            }
            else
            {
                PublicVar.SetUserName("");
            }
            this.Visible = false;

            if (user.Level == 0)
            {
                Form SysSet = new sys.SysSet();
                SysSet.ShowDialog();
                this.Close();
            }
            else
            {
                Thread th = new Thread(new ThreadStart(StartMainForm));
                th.Start();
                this.Close();
            }
        }