コード例 #1
0
ファイル: UsersForm.cs プロジェクト: obourgain/maksudproject
        private void clUpdate_Click(object sender, System.EventArgs e)
        {
            User u = (from user in _entities.Users
                      where user.Username == textUsername.Text
                      select user).FirstOrDefault();

            if (u == null)
            {
                u = new User {
                    Username = textUsername.Text, Password = textPassword.Text
                };
                _entities.AddToUsers(u);

                dataListView1.DataSource = _entities.Users;
            }
            else
            {
                u.Username = textUsername.Text;
                u.Password = textPassword.Text;
            }
            _entities.SaveChanges();


            dataListView1.Enabled = true;
            textUsername.ReadOnly = true;
            textPassword.ReadOnly = true;
        }
コード例 #2
0
ファイル: LoginForm.cs プロジェクト: obourgain/maksudproject
        private void clLogin_Click(object sender, EventArgs e)
        {
            if (textUsername.Text.Trim().Length == 0)
            {
                return;
            }
            if (textPassword.Text.Trim().Length == 0)
            {
                return;
            }



            var user = db.Users.Where(o => o.Username == textUsername.Text).FirstOrDefault();

            if (user == null)
            {
                user = new User {
                    Username = textUsername.Text, Password = textPassword.Text
                };

                db.AddToUsers(user);
                db.SaveChanges();


                _args = new TextEventArgs("Success")
                {
                    Data = user
                };
                this.Hide();
            }
            else if (user.Password != textPassword.Text)
            {
                _args = new TextEventArgs("Fail")
                {
                    Data = null
                };
                MessageBox.Show(this, @"Username/Password does not match!");
            }
            else
            {
                _args = new TextEventArgs("Success")
                {
                    Data = user
                };
                this.Hide();
            }
        }