コード例 #1
0
        private void btnupdate_Click(object sender, RoutedEventArgs e)
        {
            UserVM UserVMd = new UserVM();
            int    id      = 0;

            try
            {
                id = Int16.Parse(tb_id.Text);
            }
            catch
            {
                MessageBox.Show("User ID is unacceptable");
            }

            User user = new User
            {
                Id       = id,
                Name     = tb_name.Text,
                Email    = tb_email.Text,
                Phone    = tb_phone.Text,
                Password = UserVM.GetMD5Hash(tb_password.Password),
                Admin    = tb_admin.Text
            };

            if (UserVMd.UpdateUser(user))
            {
                MessageBox.Show("Update Success");
                loaddatagrid();
            }
            else
            {
                MessageBox.Show("Update failed");
            }
        }
コード例 #2
0
        private void btninsert_Click(object sender, RoutedEventArgs e)
        {
            UserVM UserVMd = new UserVM();
            User   user    = new User
            {
                Name     = tb_name.Text,
                Email    = tb_email.Text,
                Phone    = tb_phone.Text,
                Password = UserVM.GetMD5Hash(tb_password.Password),
                Admin    = tb_admin.Text
            };

            if (UserVMd.InsertUser(user))
            {
                MessageBox.Show("Insert Success");
                loaddatagrid();
            }
            else
            {
                MessageBox.Show("Insert failed");
            }
        }