コード例 #1
0
        //删除账户信息
        private void menuDeletedOperator_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("确认删除此账户的数据吗?", "提醒", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                bool isAddBalanceSuccess;
                bool isOperatorSuccess;
                using (TransactionScope ts = new TransactionScope())
                {
                    isAddBalanceSuccess = new BalanceBLL().DeleteByOperatorId(LoginWindow.GetOperatorId());
                    isOperatorSuccess   = new OperatorBLL().DeleteOperator(LoginWindow.GetOperatorId());
                    ts.Complete();
                }

                if (isOperatorSuccess && isAddBalanceSuccess)
                {
                    MessageBox.Show("用户删除成功!");
                    this.Close();
                    //注销重启
                    Application.Current.Shutdown();
                    System.Reflection.Assembly.GetEntryAssembly();
                    string startpath = System.IO.Directory.GetCurrentDirectory();
                    System.Diagnostics.Process.Start(startpath + "/PAMSystem.UI.exe");
                }
                else
                {
                    MessageBox.Show("用户删除失败!");
                }
            }
        }
コード例 #2
0
        private bool DoLogin(string logName, string pwd)
        {
            SaveConnectString();

            if (UpGradeDataBase())
            {//升级数据库
                AppSettings.Current.DatabaseNeedUpgrade = false;
            }

            OperatorBLL authen = new OperatorBLL(AppSettings.Current.ConnStr);

            if (authen.Authentication(logName, pwd))
            {
                this.DialogResult = DialogResult.OK;
                if (AppSettings.Current.RememberLogID)
                {
                    SaveHistoryOperators();
                }
                this.Close();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Operator operators = new OperatorBLL().GetOperatorById(LoginWindow.GetOperatorId());

            //绑定数据源
            columnOperator.ItemsSource = new OperatorBLL().ListAll();
            gridShowLog.ItemsSource    = new OperationLogBLL().Search(LoginWindow.GetOperatorId());
        }
コード例 #4
0
 //窗口加载时
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (IsInsert)
     {
     }
     else
     {
         //修改密码时 动态为tbName 的Text属性赋值
         tbName.Text            = "您要修改的用户";
         txtUserName.IsReadOnly = true;
         //把当前用户名填到txtUsername中
         EditingId = LoginWindow.GetOperatorId();
         Operator op = new OperatorBLL().GetOperatorById(EditingId);
         txtUserName.Text = op.UserName;
     }
 }
コード例 #5
0
 private bool DoLogin(string logName, string pwd)
 {
     SaveConnectString();
     UpgradeLocalDB(); //升级本地数据库
     OperatorBLL authen = new OperatorBLL(AppSettings.Current.ConnStr);
     if (authen.Authentication(logName, pwd))
     {
         this.DialogResult = DialogResult.OK;
         if (AppSettings.Current.RememberLogID) SaveHistoryOperators();
         this.Close();
         return true;
     }
     else
     {
         return false;
     }
 }
コード例 #6
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     if (CheckInput())
     {
         OperatorBLL bll = new OperatorBLL(AppSettings.Current.ConnStr);
         Operator.Password = txtNewPwd.Text;
         CommandResult result = bll.Update(Operator);
         if (result.Result == ResultCode.Successful)
         {
             this.Close();
         }
         else
         {
             Operator.Password = txtOldPwd.Text;
             MessageBox.Show(result.Message);
         }
     }
 }
コード例 #7
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     if (CheckInput())
     {
         OperatorBLL bll = new OperatorBLL(AppSettings.Current.ConnStr);
         Operator.Password = txtNewPwd.Text;
         CommandResult result=bll.Update (Operator );
         if (result.Result == ResultCode.Successful)
         {
             this.Close();
         }
         else
         {
             Operator.Password = txtOldPwd.Text;
             MessageBox.Show(result.Message);
         }
     }
 }
コード例 #8
0
        private bool DoLogin(string logName, string pwd)
        {
            OperatorBLL authen = new OperatorBLL(AppSettings.Current.ConnStr);

            if (authen.Authentication(logName, pwd))
            {
                this.DialogResult = DialogResult.OK;
                if (AppSettings.Current.RememberLogID)
                {
                    SaveHistoryOperators();
                }
                this.Close();
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #9
0
        //点击登录按钮,实现登录
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (txtUserName.Text.Length <= 0)
            {
                MessageBox.Show("请输入用户名!");
            }
            else if (pwdPassword.Password.Length <= 0)
            {
                MessageBox.Show("请输入密码!");
            }
            else
            {
                Operator op       = new Operator();
                string   userName = txtUserName.Text.Trim();

                Application.Current.Properties["OperatorName"] = userName;

                string password = pwdPassword.Password;
                //OperatorBLL bll = new OperatorBLL();
                LoginResult result = new OperatorBLL().UserLoginResult(userName, password);
                OperatorBLL bll    = new OperatorBLL();
                if (result == LoginResult.ErrorNameOrPwd)
                {
                    op = bll.GetOperatorByUserName(userName);
                    if (op != null)
                    {
                        new OperationLogBLL().Insert(op.Id, "尝试登陆失败!");
                    }
                    MessageBox.Show("用户名或密码错误");
                }
                else
                {
                    //MessageBox.Show("登录成功");
                    //获得登录用户的Id,存到Application.Current.Properties里面的在程序其他地方也可以取
                    op = bll.GetOperatorByUserName(userName);
                    Application.Current.Properties["OperatorId"] = op.Id;
                    new OperationLogBLL().Insert(op.Id, "登陆成功!");
                    //关闭LoginWindow,进入主窗口
                    DialogResult = true;
                }
            }
        }
コード例 #10
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            //判断是插入 还是编辑
            //添加
            if (IsInsert)
            {
                if (txtUserName.Text.Length <= 0)
                {
                    MessageBox.Show("请输入用户名!");
                }
                if (pwdPassword.Password.Length <= 0)
                {
                    MessageBox.Show("请输入密码!");
                }
                else if (pwdRePassword.Password.Length <= 0)
                {
                    MessageBox.Show("请再次输入密码!");
                }
                else if (pwdPassword.Password != pwdRePassword.Password)
                {
                    MessageBox.Show("两次输入密码不一致!");
                }
                else
                {
                    //添加用户
                    string      userName = txtUserName.Text.Trim();
                    string      password = pwdPassword.Password;
                    OperatorBLL bll = new OperatorBLL();
                    int         i = 0, j = 0;
                    //打开Distributed Transaction Coordinator服务
                    // 引用System.Transaction
                    //用分布式事务实现添加新用户的的同时添加改账户的余额
                    using (TransactionScope ts = new TransactionScope())
                    {
                        Operator oper = new OperatorBLL().GetOperatorByUserName(userName);
                        //数据库中是否已有此用户名
                        if (oper == null)    //没有就添加
                        {
                            i = bll.AddOpertator(userName, password);
                            Operator op = bll.GetOperatorByUserName(userName);
                            new BalanceBLL().AddNew(op.Id);
                        }
                        //若有是否已删除
                        else
                        {
                            //恢复已删除用户

                            if (oper.IsDeleted)
                            {
                                new OperatorBLL().ReuseOperator(oper.Id);              //恢复
                                j = new OperatorBLL().EditOperator(oper.Id, password); //更改密码
                                new BalanceBLL().ReuseByOperatorId(oper.Id);           //恢复余额
                                new BalanceBLL().Update(oper.Id, 0);                   //初始化余额为0
                            }
                            else
                            {
                                MessageBox.Show("用户名重复,请更换用户名!");
                            }
                        }

                        ts.Complete();
                    }
                    if (i >= 1 || j > 0)
                    {
                        MessageBox.Show("成功添加用户!");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加用户失败!");
                        this.Close();
                    }
                }
            }
            //编辑
            else
            {
                if (pwdPassword.Password.Length <= 0)
                {
                    MessageBox.Show("请输入密码!");
                }
                else if (pwdRePassword.Password.Length <= 0)
                {
                    MessageBox.Show("请再次输入密码!");
                }
                else if (pwdPassword.Password != pwdRePassword.Password)
                {
                    MessageBox.Show("两次输入密码不一致!");
                }
                else
                {
                    txtUserName.IsReadOnly = true;
                    string pwd        = pwdPassword.Password;
                    Guid   operatorId = LoginWindow.GetOperatorId();
                    int    i          = new OperatorBLL().EditOperator(operatorId, pwd);
                    if (i >= 1)
                    {
                        MessageBox.Show("修改成功");
                        this.Close();
                    }
                    if (i <= 0)
                    {
                        MessageBox.Show("修改出错");
                    }
                }
            }
        }