Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!fEditMode)
                {
                    Creditor _creditor = new Creditor();
                    _creditor.name = txtName.Text;
                    _creditor.FK_Creditors_Funds = manager.Selected;
                    _creditor.number             = txtNumber.Text;
                    manager.My_db.Creditors.Add(_creditor);
                    manager.My_db.SaveChanges();
                }
                else
                {
                    Creditor _selectedItem = manager.My_db.Creditors.FirstOrDefault(x => x.Id == (int)listBox1.SelectedValue);

                    if (_selectedItem != null)
                    {
                        _selectedItem.name   = txtName.Text;
                        _selectedItem.number = txtNumber.Text;
                        manager.My_db.SaveChanges();
                    }
                }

                this.creditorsTableAdapter.FillByFund(this.fundsDBDataSet.Creditors, manager.Selected);

                cmdCancel_Click(null, null);
            }
            catch (Exception _ex)
            {
                ErrorMessage.showErrorMessage(_ex);
            }
        }
Exemplo n.º 2
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                fEditMode         = true;
                cmdAddOrSave.Text = "Save";

                Creditor _selectedItem = manager.My_db.Creditors.FirstOrDefault(x => x.Id == (int)listBox1.SelectedValue);

                if (_selectedItem != null)
                {
                    txtName.Text   = _selectedItem.name;
                    txtNumber.Text = _selectedItem.number;
                }

                cmdCancel.Visible = true;
            }
            else
            {
                fEditMode         = false;
                cmdAddOrSave.Text = "Add";
                txtName.Text      = "";
                txtNumber.Text    = "";

                cmdCancel.Visible = false;
            }
        }
Exemplo n.º 3
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();
        }