private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!fEditMode)
                {
                    BankingAccount _banking = new BankingAccount();
                    _banking.name   = txtName.Text;
                    _banking.iban   = txtIBAN.Text;
                    _banking.amount = 0;
                    _banking.FK_BankingAccounts_Funds      = manager.Selected;
                    _banking.FK_BankingAccounts_Banks      = Convert.ToInt32(cbBank.SelectedValue);
                    _banking.FK_BankingAccounts_Currencies = Convert.ToInt32(cbCurrency.SelectedValue);
                    _banking.number = txtNumber.Text;

                    manager.My_db.BankingAccounts.Add(_banking);
                    manager.My_db.SaveChanges();
                }
                else
                {
                    int _id = (int)dataGridView1.Rows[fEditIndex].Cells[0].Value;

                    BankingAccount _selecteItem = manager.My_db.BankingAccounts.FirstOrDefault(x => x.Id == _id);

                    if (_selecteItem != null)
                    {
                        _selecteItem.name = txtName.Text;
                        _selecteItem.iban = txtIBAN.Text;
                        _selecteItem.FK_BankingAccounts_Banks      = Convert.ToInt32(cbBank.SelectedValue);
                        _selecteItem.FK_BankingAccounts_Currencies = Convert.ToInt32(cbCurrency.SelectedValue);
                        _selecteItem.number = txtNumber.Text;

                        manager.My_db.SaveChanges();
                    }
                }

                this.bAccountsWithBanksCurrenciesTableAdapter.FillByFund(this.fundsDBDataSet.BAccountsWithBanksCurrencies, manager.Selected);
                this.bAccountsWithBanksCurrenciesTableAdapter.FillByFund(this.fundsDBDataSet1.BAccountsWithBanksCurrencies, manager.Selected);

                cmdCancel_Click(null, null);
            }
            catch (Exception _ex)
            {
                ErrorMessage.showErrorMessage(_ex);
            }
        }
示例#2
0
        private void loadMovementsInListView()
        {
            listView1.Items.Clear();

            total_credit = 0;
            total_debit  = 0;

            foreach (Movement _movement in movements)
            {
                _movement.SubAccountBalance = 0;
                _movement.AccountBalance    = 0;
            }

            foreach (Movement _movement in movements)
            {
                total_credit += _movement.Credit;
                total_debit  += _movement.Debit;

                Account    _account    = manager.My_db.Accounts.FirstOrDefault(x => x.Id == _movement.Account);
                Subaccount _subAccount = manager.My_db.Subaccounts.FirstOrDefault(x => x.Id == _movement.Subaccount);

                String detailText = "";

                switch (_movement.Detail_type)
                {
                case 1:
                    Client client = manager.My_db.Clients.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (client != null)
                    {
                        detailText = client.name;
                    }
                    break;

                case 2:
                    BankingAccount baccount = manager.My_db.BankingAccounts.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (baccount != null)
                    {
                        detailText = baccount.name;
                    }
                    break;

                case 3:
                    Employee employee = manager.My_db.Employees.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (employee != null)
                    {
                        detailText = employee.name;
                    }
                    break;

                case 4:
                    Creditor creditor = manager.My_db.Creditors.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (creditor != null)
                    {
                        detailText = creditor.name;
                    }
                    break;

                case 5:
                    OtherDetail detail = manager.My_db.OtherDetails.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (detail != null)
                    {
                        detailText = detail.name;
                    }
                    break;

                case 6:
                    Shareholder holder = manager.My_db.Shareholders.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (holder != null)
                    {
                        detailText = holder.name;
                    }
                    break;

                case 7:
                    ServiceSupplier supplier = manager.My_db.ServiceSuppliers.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (supplier != null)
                    {
                        detailText = supplier.name;
                    }
                    break;

                //case 8:
                //    Creditor lender = manager.My_db.Creditors.FirstOrDefault(x => x.Id == _movement.Detail);
                //    if (lender != null)
                //    {
                //        detailText = lender.name;
                //    }
                //    break;
                case 9:
                    BondsTFAM bond = manager.My_db.BondsTFAMs.FirstOrDefault(x => x.Id == _movement.Detail);
                    if (bond != null)
                    {
                        detailText = bond.number;
                    }
                    break;
                }

                int _creditFactor = 1;
                int _debitFactor  = -1;

                if (Account.leftAccountingIncrement(_account.type))
                {
                    _creditFactor = -1;
                    _debitFactor  = 1;
                }

                decimal _amountShift = _debitFactor * _movement.Debit + _creditFactor * _movement.Credit;

                string[]     row     = { _account.name, _subAccount != null ? _subAccount.name : "", detailText, String.Format("{0:n}", _movement.Debit), String.Format("{0:n}", _movement.Credit) };
                ListViewItem my_item = new ListViewItem(row);

                listView1.Items.Add(my_item);
            }

            if (total_credit > 0 || total_debit > 0)
            {
                string[] totales           = { "", "", "Total", String.Format("{0:n}", total_debit), String.Format("{0:n}", total_credit) };
                var      listViewItemTotal = new ListViewItem(totales);

                if (total_credit == total_debit || AvoidAccountBalanceValidation)
                {
                    _color          = Color.FromName("Green");
                    button2.Enabled = true;
                }
                else
                {
                    _color          = Color.FromName("Red");
                    button2.Enabled = false;
                }

                listViewItemTotal.ForeColor = _color;
                listView1.Items.Add(listViewItemTotal);
            }

            checkForContractVisibility();
        }