Ejemplo n.º 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("用户删除失败!");
                }
            }
        }
Ejemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            IdNameBLL idnamebll = new IdNameBLL();
            Account   account   = new Account();

            //获得用户的Id
            account.OperatorId = LoginWindow.GetOperatorId();


            // MessageBox.Show("执行了!");
            //添加
            if (IsAddNew)
            {
                //设置默认值
                account.Date                = DateTime.Now;
                account.Money               = 0;
                account.Remarks             = "无";
                gridEditAccount.DataContext = account;
                cbType.ItemsSource          = idnamebll.GetByCategory("收支类型");
                //cbType.SelectedIndex = 0;
            }
            //编辑
            else
            {
                //拿出要编辑的对象的值
                account = new AccountBLL().GetById(EditingId);
                gridEditAccount.DataContext = account;
                cbType.ItemsSource          = idnamebll.GetByCategory("收支类型");
            }
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 4
0
        //载入数据都DataGrid
        public void LoadData()
        {
            Operator op = new Operator();

            // columnOperator.ItemsSource = new OperatorBLL().ListAll();
            columnItem.ItemsSource     = new IdNameBLL().ListAll();
            columnCostType.ItemsSource = new IdNameBLL().GetByCategory("收支类型");
            dataGridShow.ItemsSource   = new AccountBLL().GetByOperatorId(LoginWindow.GetOperatorId());
        }
Ejemplo n.º 5
0
        //查看支出
        private void menuShowExpense_Click(object sender, RoutedEventArgs e)
        {
            dataGridShow.ItemsSource = null;
            //获得操作用户的Id
            Guid operatorId = LoginWindow.GetOperatorId();
            //查询收入的Id,并赋值
            IdName idname = new IdNameBLL().GetByName("支出");

            new AccountBLL().GetByOperatorIdAndCostType(operatorId, idname.Id);
            columnCostType.ItemsSource = new IdNameBLL().GetByCategory("收支类型");
            //根据 登录的ID 和收的Id查询 操作者的支出
            dataGridShow.ItemsSource = new AccountBLL().GetByOperatorIdAndCostType(operatorId, idname.Id);
        }
Ejemplo n.º 6
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;
     }
 }
Ejemplo n.º 7
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (IsShowBalance)
     {
         txtBalance.IsReadOnly = true;                                         //查询时txtBalance为只读
         Balance b = new BalanceBLL().GetBalance(LoginWindow.GetOperatorId()); //根据用户Id查询余额
         txtBalance.Text   = b.Balances.ToString();
         btnYes.Visibility = Visibility.Collapsed;                             //隐藏“确定”按钮
         if (b.Balances < 0)
         {
             MessageBox.Show("你已经入不敷出了,快点赚钱吧!");
         }
     }
     else
     {
         tbBalanceText.Text = "添加余额";
     }
 }
Ejemplo n.º 8
0
 //添加余额
 private void btnYes_Click(object sender, RoutedEventArgs e)
 {
     if (!IsShowBalance)
     {
         Balance balance = new Balance();
         balance.Balances = decimal.Parse(txtBalance.Text);    //把string类型转为decimal
         bool i = new BalanceBLL().Update(LoginWindow.GetOperatorId(), balance.Balances);
         if (i)
         {
             new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "添加余额成功!");
             MessageBox.Show("添加数据成功!");
             this.Close();
         }
         else
         {
             new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "添加余额失败!");
             MessageBox.Show("添加数据错误!");
             this.Close();
         }
     }
 }
Ejemplo n.º 9
0
        //点击保存按钮的
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Account    account    = (Account)gridEditAccount.DataContext;
            AccountBLL accountBll = new AccountBLL();

            //判断金额大于0
            if (cbType.SelectedIndex > -1)
            {
                if (account.Money <= 0)
                {
                    MessageBox.Show("你输入的收入金额不合法,请重新输入!");
                    return;
                }
            }
            if (cbType.SelectedIndex < 0)
            {
                MessageBox.Show("请选择收支!");
                return;
            }
            else if (cbItem.SelectedIndex < 0)
            {
                MessageBox.Show("请选择项目!");
                return;
            }
            //有问题
            else
            {
                //获得名字为收入的Id值
                IdName  idname  = new IdNameBLL().GetByName("收入");
                Balance balance = new Balance();
                #region 添加收支
                //添加收支
                if (IsAddNew)
                {
                    int i;
                    //分布式事务处理收支和余额,可实现回滚
                    using (TransactionScope ts = new TransactionScope())
                    {
                        i = accountBll.AddNew(account);
                        //判断是否为收入,收入为正的,支出为负数
                        if (account.CostType == idname.Id)    //收入
                        {
                            balance.Balances = (decimal)account.Money;
                        }
                        else //支出
                        {
                            balance.Balances = (decimal)(-account.Money);
                        }

                        new BalanceBLL().Update(account.OperatorId, balance.Balances);
                        ts.Complete();//表示已完成
                    }
                    //严谨点Update也应该返回true or false
                    if (i < 0)
                    {
                        new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "添加收支,更新余额失败!");
                        MessageBox.Show("添加错误!");
                    }
                    else if (i > 1)
                    {
                        new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "添加收支时错误!");
                        throw new Exception("数据发生错误!");
                    }
                    else
                    {
                        new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "添加收支,更新余额成功!");//日志
                        MessageBox.Show("添加成功!");
                        this.Close();
                    }
                }
                #endregion

                #region 编辑收支
                //编辑收支
                else
                {
                    bool i;               //插入余额是否成功
                    bool isAddbalanceSuc; //插入余额是否成功
                    //分布式处理
                    using (TransactionScope ts = new TransactionScope())
                    {
                        //更新收支
                        i = accountBll.Update(account);

                        //更新前的数据类型是否为收入,并计算出差额,
                        if (BeforeCostType == idname.Id)
                        {
                            //收入改为收入 只是金额的更改
                            if (account.CostType == idname.Id)                                      //更改后收支类型,为收入
                            {
                                if ((decimal)account.Money != BeforeEditingMoney)                   //更新后的钱不等更新前的前
                                {
                                    balance.Balances = (decimal)account.Money - BeforeEditingMoney; //加上前后的差额(后大于前取+,否则为—)
                                }
                                else
                                {
                                    balance.Balances = 0;
                                }
                            }
                            //收入改为支出,前为收,后为支
                            else
                            {
                                // 先减去更新前的收入,再减去更新后的支出金额
                                balance.Balances = -BeforeEditingMoney - (decimal)account.Money;
                            }
                        }
                        //若更新前为支出,计算出差额
                        else
                        {
                            //判断更新后的类型
                            if (account.CostType == idname.Id)                                  //更新后的类型为收入,更新前为支出
                            {
                                balance.Balances = BeforeEditingMoney + (decimal)account.Money; //先加上更新前的支出,再加上更新后的收入
                            }
                            //更新后为支出,更新前为支出
                            else
                            {
                                if (BeforeEditingMoney != (decimal)account.Money)                   //更新前的钱不等于更新后的钱,求钱差额
                                {
                                    balance.Balances = BeforeEditingMoney - (decimal)account.Money; //更新前 减去更新后  若更新前大,那就加上差额
                                }
                                else
                                {
                                    balance.Balances = 0;
                                }
                            }
                        }
                        isAddbalanceSuc = new BalanceBLL().Update(account.OperatorId, balance.Balances);
                        ts.Complete();
                    }
                    if (i && isAddbalanceSuc)
                    {
                        new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "编辑收支成功!");
                        MessageBox.Show("更改成功!");
                        this.Close();
                    }
                    else
                    {
                        new OperationLogBLL().Insert(LoginWindow.GetOperatorId(), "编辑收支失败!");
                        MessageBox.Show("更新失败!");
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 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("修改出错");
                    }
                }
            }
        }