private void InitializeCustomComponents()
        {
            dataGridFunds = FormUtility.CreateDataGridView(typeof(Fund), 80, 580);
            ToolStripMenuItem itemDelete   = FormUtility.CreateContextMenuItem("Löschen", DeleteFundClick);
            ToolStripMenuItem itemEditFund = FormUtility.CreateContextMenuItem("Fonds bearbeiten", EditFundClick);

            FormUtility.AddContextMenu(dataGridFunds, itemDelete, itemEditFund);
            FormUtility.GetBindingSource(dataGridFunds).Clear();
            FormUtility.AddValidation(buttonSubmit, textBoxCurrency, () =>
            {
                TableUtility tableUtility  = new TableUtility();
                List <Range> currencyRange = tableUtility.ReadTableRow(Currency.GetDefaultValue(), new Dictionary <string, string>
                {
                    { "IsoCode", textBoxCurrency.Text.ToUpper() }
                }, QueryOperator.OR);

                if (currencyRange.Count == 0 || currencyRange.Count > 1)
                {
                    return(false);
                }
                Currency currency = tableUtility.ConvertRangesToObjects <Currency>(currencyRange)[0];
                Fund newFund      = new Fund(textBoxFundName.Text, textBoxIsin.Text, textBoxCustodyNr.Text, currency);
                tableUtility.InsertTableRow(newFund);
                FormUtility.GetBindingSource(dataGridFunds).Add(newFund);
                return(true);
            });
            FormUtility.AddControlsToForm(this, dataGridFunds);
        }
        private void LoadRatings(int index)
        {
            if (index < 0)
            {
                FormUtility.GetBindingSource(dataGridViewRatingCodes).Clear();
                return;
            }
            FormUtility.GetBindingSource(dataGridViewRatingCodes).Clear();
            if (currentRatingAgency == null)
            {
                return;
            }
            TableUtility tableUtility = new TableUtility();

            List <Range> agencyRanges = tableUtility.ReadTableRow(Rating.GetDefaultValue(), new Dictionary <string, string>
            {
                { "Agency", currentRatingAgency.GetIndex().ToString() }
            }, QueryOperator.OR);

            if (agencyRanges.Count == 0)
            {
                return;
            }

            List <Rating> ratings = tableUtility.ConvertRangesToObjects <Rating>(agencyRanges);

            foreach (Rating rating in ratings)
            {
                FormUtility.GetBindingSource(dataGridViewRatingCodes).Add(rating);
            }
        }
        private bool MergeFundProperties()
        {
            TableUtility tableUtility = new TableUtility();
            Fund         newFund      = new Fund
            {
                Index = fund.Index,
                Name  = textBoxFundName.Text,
                CustodyAccountNumber = textBoxCustodyNr.Text,
                Isin = textBoxIsin.Text
            };
            List <Range> currencyRange = tableUtility.ReadTableRow(Currency.GetDefaultValue(), new Dictionary <string, string>
            {
                { "IsoCode", textBoxCurrency.Text.ToUpper() }
            }, QueryOperator.OR);

            if (currencyRange.Count != 0)
            {
                Currency currency = tableUtility.ConvertRangesToObjects <Currency>(currencyRange)[0];
                newFund.Currency = currency;
            }
            else
            {
                newFund.Currency = fund.Currency;
            }

            if (!fund.Equals(newFund))
            {
                tableUtility.MergeTableRow(newFund);
                return(true);
            }
            return(true);
        }
        private void InitializeCustomComponents()
        {
            tableLayoutPanelAA = FormUtility.CreateTableLayoutPanel(1000, 200);
            FormUtility.AddValidation(buttonSubmit, textBoxCurrency, () =>
            {
                TableUtility tableUtility  = new TableUtility();
                List <Range> currencyRange = tableUtility.ReadTableRow(Currency.GetDefaultValue(), new Dictionary <string, string>
                {
                    { "IsoCode", textBoxCurrency.Text.ToUpper() }
                }, QueryOperator.OR);

                if (currencyRange.Count == 0 || currencyRange.Count > 1)
                {
                    textBoxCurrency.BackColor = Color.Red;
                    return(false);
                }
                if (MergeFundProperties() && MergeAssetAllocation())
                {
                    passedForm.OnSubmit();
                    Close();
                }
                return(true);
            });
            FormUtility.AddControlsToForm(this, tableLayoutPanelAA);
        }
        private void DeleteRatingAgencyClick(object sender, EventArgs e)
        {
            TableUtility  tableUtility         = new TableUtility();
            RatingAgency  ratingAgencyToDelete = dataGridViewRatingAgencies.Rows[ratingAgenciesRowIndex].DataBoundItem as RatingAgency;
            List <Rating> ratingsToDelete      = tableUtility.ConvertRangesToObjects <Rating>(tableUtility.ReadTableRow(Rating.GetDefaultValue(), new Dictionary <string, string>
            {
                { "Agency", ratingAgencyToDelete.GetIndex().ToString() }
            }, QueryOperator.OR));

            foreach (Rating rating in ratingsToDelete)
            {
                tableUtility.DeleteTableRow(rating);
            }
            tableUtility.DeleteTableRow(ratingAgencyToDelete);
            FormUtility.GetBindingSource(dataGridViewRatingAgencies).RemoveAt(ratingAgenciesRowIndex);
            LoadRatings(ratingAgenciesRowIndex);
            if (FormUtility.GetBindingSource(dataGridViewRatingAgencies).Count == 0)
            {
                currentRatingAgency = null;
            }
        }