private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { fEditIndex = e.RowIndex; int _id = (int)dataGridView1.Rows[fEditIndex].Cells[0].Value; OtherDetail _selectedDetail = manager.My_db.OtherDetails.FirstOrDefault(x => x.Id == _id); if (_selectedDetail != null) { fEditMode = true; cmdAddOrSave.Text = "Save"; txtName.Text = _selectedDetail.name; txtNumber.Text = _selectedDetail.number; Subaccount _subacct = manager.My_db.Subaccounts.FirstOrDefault(x => x.Id == _selectedDetail.subacct_id); foreach (DataRowView _item in cbSubAccount.Items) { if (_item.Row[0].ToString() == _subacct.Id.ToString()) { cbSubAccount.SelectedItem = _item; break; } } cmdCancel.Visible = true; editModeAccountIndex = cbAccount.SelectedIndex; editModeSubaccountIndex = cbSubAccount.SelectedIndex; } }
private void addDetail() { try { editModeAccountIndex = cbAccount.SelectedIndex; editModeSubaccountIndex = cbSubAccount.SelectedIndex; int subacctId = Convert.ToInt32(cbSubAccount.SelectedValue); if (!fEditMode) { OtherDetail _validationOtherDetail = manager.My_db.OtherDetails.FirstOrDefault(x => x.number == txtNumber.Text && x.subacct_id == subacctId && x.FK_OtherDetails_Funds == manager.Selected); if (_validationOtherDetail != null) { MessageBox.Show("Duplicated number."); return; } OtherDetail _otherdetail = new OtherDetail(); _otherdetail.name = txtName.Text; _otherdetail.subacct_id = Convert.ToInt32(cbSubAccount.SelectedValue); _otherdetail.FK_OtherDetails_Funds = manager.Selected; _otherdetail.number = txtNumber.Text; manager.My_db.OtherDetails.Add(_otherdetail); manager.My_db.SaveChanges(); } else { int _id = (int)dataGridView1.Rows[fEditIndex].Cells[0].Value; OtherDetail _validationOtherDetail = manager.My_db.OtherDetails.FirstOrDefault(x => x.Id != _id && x.number == txtNumber.Text && x.subacct_id == subacctId && x.FK_OtherDetails_Funds == manager.Selected); if (_validationOtherDetail != null) { MessageBox.Show("Duplicated number."); return; } OtherDetail _selectedDetail = manager.My_db.OtherDetails.FirstOrDefault(x => x.Id == _id); if (_selectedDetail != null) { _selectedDetail.name = txtName.Text; _selectedDetail.subacct_id = Convert.ToInt32(cbSubAccount.SelectedValue); _selectedDetail.number = txtNumber.Text; manager.My_db.SaveChanges(); } } cmdCancel_Click(null, null); int subaccountId = int.Parse(cbSubAccount.SelectedValue.ToString()); this.otherDetailsTableAdapter.FillBySubaccount(this.fundsDBDataSet.OtherDetails, subaccountId, manager.Selected); foreach (DataGridViewRow _row in dataGridView1.Rows) { Subaccount _subaccount = new Subaccount(); _subaccount = manager.My_db.Subaccounts.Find(Convert.ToInt32(_row.Cells[4].Value)); _row.Cells[5].Value = _subaccount.name; } } catch (Exception _ex) { ErrorMessage.showErrorMessage(_ex); } }
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(); }