Exemplo n.º 1
0
        void btn_login_Click(object sender, RoutedEventArgs e)
        {
            Button btn = e.Source as Button;
            int    num = int.Parse(tb_log1.Text.Trim());
            string pwd = tb_log2.Password;

            using (var context = new BankDbEntities2())
            {
                var q = from t in context.Staff
                        where t.员工编号 == num
                        select t;
                foreach (var v in q)
                {
                    if (v.密码 == pwd)
                    {
                        this.NName    = v.姓名;
                        this.Rank     = v.身份;
                        this.UserName = v.员工编号;
                        this.Close();
                        break;
                    }
                    else
                    {
                        MessageBox.Show("密码错误!", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        //MessageBoxResult res = MessageBox.Show("密码错误!", "提示", MessageBoxButton.OK, MessageBoxImage.Error);
                        //if (res == MessageBoxResult.OK)
                        //{
                        //    //this.Close();
                        //    System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
                        //}
                    }
                }
            }
        }
Exemplo n.º 2
0
        void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn  = sender as Button;
            string pwd1 = pb1.Password;
            string pwd2 = pb2.Password;
            string pwd3 = pb3.Password;

            using (var context = new BankDbEntities2())
            {
                var q = from t in context.Staff
                        where t.员工编号 == this.Num
                        select t;
                foreach (var v in q)
                {
                    if (v.密码 == pwd1 && pwd2 == pwd3)
                    {
                        v.密码 = pwd3;
                    }
                    else
                    {
                        MessageBox.Show("密码错误或新密码不一致!");
                    }
                }
                try
                {
                    context.SaveChanges();
                    MessageBox.Show("修改成功!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show("修改失败:" + ex.Message);
                }
            }
        }