Exemplo n.º 1
0
        /// <summary>
        /// 保存账户操作人
        /// </summary>
        private bool SaveAccountOperators()
        {
            try
            {
                if (this.clbOperator.Items.Count == 0)
                {
                    return(true);
                }

                //添加账户的场合
                if (!this._isEdit)
                {
                    var checkedOperators = new List <AccountOperator>();

                    foreach (CheckedListBoxItem item in this.clbOperator.CheckedItems)
                    {
                        checkedOperators.Add(new AccountOperator {
                            AccountId = this._accountId, OperatorId = int.Parse(item.Value.ToString())
                        });
                    }

                    _accountService.AddAccountOperator(checkedOperators);
                }
                //修改账户的场合
                else
                {
                    foreach (CheckedListBoxItem item in this.clbOperator.Items)
                    {
                        var info = _accountService.GetAccountOperatorByAccountIdAndOperatorId(this._accountId, int.Parse(item.Value.ToString()));

                        // 添加操作人员
                        if (info == null && item.CheckState == CheckState.Checked)
                        {
                            _accountService.AddAccountOperator(new AccountOperator {
                                AccountId = this._accountId, OperatorId = int.Parse(item.Value.ToString())
                            });
                        }
                        // 删除操作人员
                        if (info != null && item.CheckState == CheckState.Unchecked)
                        {
                            _accountService.DeleteAccountOperator(info);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DXMessage.ShowError(ex.Message);
                return(false);
            }
            return(true);
        }