Exemple #1
0
        public MainWindow(DataContainer data, IAppSettings settings, DbContextFactory contextFactory, IDataSourcer dataSourcer)
        {
            /////////////////////////////////////////////////////////
            InitializeComponent();
            /////////////////////////////////////////////////////////

            Settings       = settings;
            ContextFactory = contextFactory;
            DataSourcer    = dataSourcer;

            ViewModel        = new MainViewModel(ContextFactory, DataSourcer, DialogCoordinator.Instance, Settings, data);
            this.DataContext = ViewModel;

            PopulateStatementMenus();

            //Restore column ordering, widths, and sorting
            LoadDataGridLayouts();

            //A hack to force the heavy stuff to load,
            //providing snappier navigation at the expense of longer startup time
#if !DEBUG
            TradesGrid.Measure(new Size(500, 500));

            OrdersGrid.Measure(new Size(500, 500));

            CashTransactionsGrid.Measure(new Size(500, 500)); //todo: remove this stuff?
#endif
            //hiding the tab headers
            Style s = new Style();
            s.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed));
            MainTabCtl.ItemContainerStyle = s;

            //close the slash screen
            //App.Splash.LoadComplete();

            this.Show();

            ShowChangelog();
        }
Exemple #2
0
        private void CashTransactionsGrid_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
        {
            if ((string)e.Column.Header == "Trade")
            {
                var ct = (CashTransaction)CashTransactionsGrid.SelectedItem;
                //if this cash transaction belongs to a closed trade, disallow editing
                if (ct.Trade != null && ct.Trade.Open == false)
                {
                    e.Cancel = true;
                    return;
                }

                //Fill it
                CtGridTradePickerListBox.ItemsSource = Context
                                                       .Trades
                                                       .Where(x => x.Open)
                                                       .OrderBy(x => x.Name)
                                                       .ToList()
                                                       .Select(
                    x => new CheckListItem <Trade>(x))
                                                       .ToList();

                //make sure the currently selected trade is checked
                if (ct.Trade != null)
                {
                    foreach (CheckListItem <Trade> item in CtGridTradePickerListBox.Items)
                    {
                        item.IsChecked = ct.Trade.ID == item.Item.ID;
                    }
                }

                //and open it at the right position
                CashTransactionsGridTradePickerPopup.PlacementTarget = CashTransactionsGrid.GetCell(e.Row.GetIndex(), e.Column.DisplayIndex);
                CashTransactionsGridTradePickerPopup.IsOpen          = true;
            }
        }
Exemple #3
0
        public MainWindow()
        {
            //make sure we have a database connection and stuff, otherwise show the dialog to set db settings
            try
            {
                DBUtils.CheckDBConnection();
            }
            catch
            {
                App.Splash.LoadComplete();
                var dbDetailsWindow = new DBPicker();
                dbDetailsWindow.ShowDialog();
            }

            //initialize logging
            InitializeLogging();

            //Log unhandled exceptions
            AppDomain.CurrentDomain.UnhandledException += AppDomain_CurrentDomain_UnhandledException;

            //set the connection string
            DBUtils.SetConnectionString();

            Context = new DBContext();

            //create db if it doesn't exist
            Context.Database.Initialize(false);

            //check for any currencies, seed the db with initial values if nothing is found
            if (!Context.Currencies.Any())
            {
                Seed.DoSeed();
            }

            //check for empty account fields
            if (Context.EquitySummaries.Any(x => x.AccountID == null))
            {
                App.Splash.LoadComplete();
                var accountMigrationWindow = new AccountMigrationWindow();
                accountMigrationWindow.ShowDialog();
            }

            var qdmsSource = new ExternalDataSources.QDMS();

            Datasourcer = new DataSourcer(Context, qdmsSource);

            TradesRepository = new TradesRepository(Context, Datasourcer);

            IDialogService dialogService = new DialogService(this);

            ViewModel = new MainViewModel(Context, Datasourcer, dialogService);

            /////////////////////////////////////////////////////////
            InitializeComponent();
            /////////////////////////////////////////////////////////

            DataContext = ViewModel;

            //Create the load statement menus using the loaded plugins
            PopulateStatementMenus();

            //Restore column ordering, widths, and sorting
            LoadDataGridLayouts();

            //A hack to force the heavy stuff to load,
            //providing snappier navigation at the expense of longer startup time
#if !DEBUG
            ViewModel.TradesPageViewModel.Refresh();
            TradesGrid.Measure(new Size(500, 500));

            ViewModel.OrdersPageViewModel.Refresh();
            OrdersGrid.Measure(new Size(500, 500));

            ViewModel.CashTransactionsPageViewModel.Refresh();
            CashTransactionsGrid.Measure(new Size(500, 500));
#endif
            //hiding the tab headers
            Style s = new Style();
            s.Setters.Add(new Setter(VisibilityProperty, Visibility.Collapsed));
            MainTabCtl.ItemContainerStyle = s;

            //load the open positions page data
            ViewModel.RefreshCurrentPage();

            //close the slash screen
            App.Splash.LoadComplete();

            ShowChangelog();
        }