Пример #1
0
        private void AddAssetClass(string assetClassName)
        {
            TableUtility tableUtility = new TableUtility();

            tableUtility.CreateTable(AssetClass.GetDefaultValue());
            AssetClass assetClass = new AssetClass
            {
                Name = assetClassName
            };

            tableUtility.InsertTableRow(assetClass);
            FormUtility.GetBindingSource(dataGridViewAssetClasses).Add(assetClass);
        }
Пример #2
0
        private void AddAssetClass(string assetClassName)
        {
            TableUtility tableUtility = new TableUtility(Globals.WatchdogAddIn.Application.ActiveWorkbook);

            tableUtility.CreateMissingTable(AssetClass.GetDefaultValue());
            AssetClass assetClass = new AssetClass
            {
                Name = assetClassName
            };

            tableUtility.InsertTableRow(assetClass, new List <string>()
            {
                assetClass.Name
            });
            assetClassBindingSource.Add(assetClass);
        }
Пример #3
0
        private void LoadAssetClasses()
        {
            TableUtility tableUtility = new TableUtility(Globals.WatchdogAddIn.Application.ActiveWorkbook);
            // List<AssetClass> assetClassList = tableUtility.ConvertRangeToAssetClass(tableUtility.ReadAllRows(AssetClass.GetDefaultValue().GetTableName()));
            List <AssetClass> assetClassList = tableUtility.ConvertRangesToObjects <AssetClass>(tableUtility.ReadAllRows(AssetClass.GetDefaultValue().GetTableName()));

            foreach (AssetClass assetClass in assetClassList)
            {
                assetClassBindingSource.Add(assetClass);
            }
        }
Пример #4
0
        private void LoadAssetClasses()
        {
            TableUtility      tableUtility   = new TableUtility();
            List <AssetClass> assetClassList = tableUtility.ConvertRangesToObjects <AssetClass>(tableUtility.ReadAllRows(AssetClass.GetDefaultValue()));

            foreach (AssetClass assetClass in assetClassList)
            {
                FormUtility.GetBindingSource(dataGridViewAssetClasses).Add(assetClass);
            }
        }
Пример #5
0
        private void LoadTable()
        {
            TableUtility      tableUtility = new TableUtility(Globals.WatchdogAddIn.Application.ActiveWorkbook);
            List <AssetClass> assetClasses = tableUtility.ConvertRangesToObjects <AssetClass>(tableUtility.ReadAllRows(AssetClass.GetDefaultValue().GetTableName()));
            List <Currency>   currencies   = tableUtility.ConvertRangesToObjects <Currency>(tableUtility.ReadAllRows(Currency.GetDefaultValue().GetTableName()));
            int numberOfColumns            = assetClasses.Count + 1;
            int numberOfRows = currencies.Count + 1;

            tableLayoutPanel1.ColumnCount = numberOfColumns + 1;
            tableLayoutPanel1.RowCount    = numberOfRows + 1;

            // First cell, should be empty
            tableLayoutPanel1.Controls.Add(GenerateLabel <Persistable>(string.Empty, null), 0, 0);

            Padding padding = Padding.Empty;

            // Add column labels for asset classes
            for (int col = 1; col < numberOfColumns; col++)
            {
                AssetClass assetClass  = assetClasses[col - 1];
                Label      columnLabel = GenerateLabel(assetClass.Name, assetClass);
                tableLayoutPanel1.Controls.Add(columnLabel, col, 0);
            }

            // Add total column
            tableLayoutPanel1.Controls.Add(GenerateLabel <Persistable>("Total", null), numberOfColumns, 0);

            // Add row labels for currencies
            for (int row = 1; row < numberOfRows; row++)
            {
                Currency currency = currencies[row - 1];
                Label    rowLabel = GenerateLabel(currency.IsoCode, currency);
                tableLayoutPanel1.Controls.Add(rowLabel, 0, row);
            }

            // Add total row
            tableLayoutPanel1.Controls.Add(GenerateLabel <Persistable>("Total", null), 0, numberOfRows);

            // Add text boxes
            for (int row = 1; row < numberOfRows; row++)
            {
                for (int col = 1; col < numberOfColumns; col++)
                {
                    TextBox textBox = new TextBox
                    {
                        AutoSize    = false,
                        Width       = 200,
                        Height      = 50,
                        Margin      = new Padding(1, 0, 0, 0),
                        BorderStyle = BorderStyle.None,
                        TextAlign   = HorizontalAlignment.Right
                    };
                    textBox.KeyUp += (tb, keyUp) =>
                    {
                        TableLayoutPanelCellPosition position = tableLayoutPanel1.GetPositionFromControl(tb as TextBox);
                        Label  totalAssetClass = tableLayoutPanel1.GetControlFromPosition(position.Column, numberOfRows) as Label;
                        Label  totalCurrency   = tableLayoutPanel1.GetControlFromPosition(numberOfColumns, position.Row) as Label;
                        Label  total           = tableLayoutPanel1.GetControlFromPosition(numberOfColumns, numberOfRows) as Label;
                        double rowSum          = GetRowSum(position.Row);
                        double columnSum       = GetColumnSum(position.Column);
                        totalCurrency.Text   = rowSum.ToString();
                        totalAssetClass.Text = columnSum.ToString();
                        double totalSum = GetTotalSum();
                        total.Text = totalSum.ToString();
                    };
                    textBox.KeyUp += (tb, keyUp) =>
                    {
                        TextBox t = tb as TextBox;
                        bool    cellContentIsNumber = double.TryParse(t.Text, out _);
                        if (!cellContentIsNumber)
                        {
                            t.Clear();
                        }
                    };
                    tableLayoutPanel1.Controls.Add(textBox);
                }
            }

            // Add total labels in last column
            for (int row = 1; row < numberOfRows + 1; row++)
            {
                tableLayoutPanel1.Controls.Add(GenerateLabel <Persistable>("", null), numberOfColumns, row);
            }

            // Add total labels in last row
            for (int col = 1; col < numberOfColumns; col++)
            {
                tableLayoutPanel1.Controls.Add(GenerateLabel <Persistable>("", null), col, numberOfRows);
            }
        }
        private void LoadAssetAllocationTable()
        {
            TableUtility      tableUtility = new TableUtility();
            List <AssetClass> assetClasses = tableUtility.ConvertRangesToObjects <AssetClass>(tableUtility.ReadAllRows(AssetClass.GetDefaultValue()));
            List <Currency>   currencies   = tableUtility.ConvertRangesToObjects <Currency>(tableUtility.ReadAllRows(Currency.GetDefaultValue()));
            int numberOfColumns            = assetClasses.Count + 1;
            int numberOfRows = currencies.Count + 1;

            tableLayoutPanelAA.ColumnCount = numberOfColumns + 1;
            tableLayoutPanelAA.RowCount    = numberOfRows + 1;

            // First cell, should be empty
            tableLayoutPanelAA.Controls.Add(GenerateLabel(string.Empty, null), 0, 0);

            Padding padding = Padding.Empty;

            // Add column labels for asset classes
            for (int col = 1; col < numberOfColumns; col++)
            {
                AssetClass assetClass  = assetClasses[col - 1];
                Label      columnLabel = GenerateLabel(assetClass.Name, assetClass);
                tableLayoutPanelAA.Controls.Add(columnLabel, col, 0);
            }

            // Add total column
            tableLayoutPanelAA.Controls.Add(GenerateLabel("Total", null), numberOfColumns, 0);

            // Add row labels for currencies
            for (int row = 1; row < numberOfRows; row++)
            {
                Currency currency = currencies[row - 1];
                Label    rowLabel = GenerateLabel(currency.IsoCode, currency);
                tableLayoutPanelAA.Controls.Add(rowLabel, 0, row);
            }

            // Add total row
            tableLayoutPanelAA.Controls.Add(GenerateLabel("Total", null), 0, numberOfRows);

            // Add text boxes
            for (int row = 1; row < numberOfRows; row++)
            {
                for (int col = 1; col < numberOfColumns; col++)
                {
                    AssetClass      assetClass     = tableLayoutPanelAA.GetControlFromPosition(col, 0).DataBindings[0].DataSource as AssetClass;
                    Currency        currency       = tableLayoutPanelAA.GetControlFromPosition(0, row).DataBindings[0].DataSource as Currency;
                    Padding         paddingOneLeft = new Padding(1, 0, 0, 0);
                    FlowLayoutPanel panel          = new FlowLayoutPanel
                    {
                        Margin = paddingOneLeft,
                        Height = 50,
                        Width  = 150,
                    };

                    for (int i = 0; i < 3; i++)
                    {
                        TextBox textBox = new TextBox
                        {
                            AutoSize    = false,
                            Width       = 50,
                            Height      = 50,
                            Margin      = padding,
                            BorderStyle = BorderStyle.FixedSingle,
                            TextAlign   = HorizontalAlignment.Right
                        };
                        textBox.KeyUp += (tb, keyUp) =>
                        {
                            TextBox t = tb as TextBox;
                            bool    cellContentIsNumber = double.TryParse(t.Text, out _);
                            if (!cellContentIsNumber)
                            {
                                t.Clear();
                            }
                        };
                        panel.Controls.Add(textBox);
                    }
                    panel.Controls[1].KeyUp += (tb, keyUp) =>
                    {
                        TextBox         textBox   = tb as TextBox;
                        FlowLayoutPanel flowPanel = ((TextBox)tb).Parent as FlowLayoutPanel;
                        CalcTotals(flowPanel);
                    };

                    AssetAllocationEntry entry = GetAssetAllocationEntry(assetClass, currency);
                    if (entry != null)
                    {
                        panel.Controls[0].Text = entry.StrategicMinValue.ToString();
                        panel.Controls[1].Text = entry.StrategicOptValue.ToString();
                        panel.Controls[2].Text = entry.StrategicMaxValue.ToString();
                        FormUtility.BindObjectToControl(panel, entry);
                    }


                    tableLayoutPanelAA.Controls.Add(panel);
                }
            }

            // Add total labels in last column
            for (int row = 1; row < numberOfRows + 1; row++)
            {
                tableLayoutPanelAA.Controls.Add(GenerateLabel("", null), numberOfColumns, row);
            }

            // Add total labels in last row
            for (int col = 1; col < numberOfColumns; col++)
            {
                tableLayoutPanelAA.Controls.Add(GenerateLabel("", null), col, numberOfRows);
            }
        }