예제 #1
0
        public void AddInstrument()
        {
            if (App.CurrentStrategy == null || string.IsNullOrEmpty(Cn))
            {
                return;
            }

            // Save to DB
            using (var context = new QTSDbContext())
            {
                var strategy = context.Strategies.FirstOrDefault(s => s.Id == App.CurrentStrategy.Id);

                var instrument = new Instrument();
                instrument.Cn       = Cn;
                instrument.Name     = Name2;
                instrument.Exchange = Exchange;
                if (strategy.Instruments == null)
                {
                    strategy.Instruments = new List <Instrument>();
                }
                strategy.Instruments.Add(instrument);
                context.SaveChanges();

                InstrumentCollection.Add(instrument);
                _events.PublishOnUIThread(new ModelEvents(new List <object>(new
                                                                            object[] { "Add instrument to Current Strategy: name = " + Name2 })));
            }
        }
예제 #2
0
        public AddStrategyViewModel(IEventAggregator events)
        {
            this._events = events;
            DisplayName  = "01. 添加策略";

            StrategyCollection   = new BindableCollection <EntityFramework.Strategy>();
            InstrumentCollection = new BindableCollection <Instrument>();

            using (var context = new QTSDbContext())
            {
                StrategyCollection.AddRange(context.Strategies.Include(s => s.Instruments).ToList());
            }
        }
예제 #3
0
        public void AddStrategy()
        {
            if (string.IsNullOrEmpty(Name))
            {
                return;
            }

            // Save to DB
            using (var context = new QTSDbContext())
            {
                var strategy = new EntityFramework.Strategy();
                strategy.Name = Name;
                strategy.Type = Type;
                context.Strategies.Add(strategy);
                context.SaveChanges();

                StrategyCollection.Add(strategy);
                _events.PublishOnUIThread(new ModelEvents(new List <object>(new
                                                                            object[] { "Add strategy to DB: name = " + Name })));
            }
        }