public void SaveToDB() { DB_ModelContainer db = new DB_ModelContainer(); foreach (SettingsList.Keys key in Enum.GetValues(typeof(Keys))) { if (IsValueChanged(key) == true) { Setting set = db.Settings.FirstOrDefault(s => s.Key == key.ToString()); if (set == null) { set = new Setting(key.ToString(), valuesList[key.ToString()]); db.Settings.Add(set); } else { set.Value = valuesList[key.ToString()]; db.Settings.Update(set); } } } if (db.ChangeTracker.HasChanges() == true) { db.SaveChanges(); } }
// // Called from AddSymbol_ViewModel when a contract was selected from list, will add it to the listview // then will subscribe to receive TWS real time (5s) data. // private async void AddSymbol_VM_ContractSelected_Event(object sender, ContractDetailsRecv_EventArgs e) { ContractData cd = new ContractData(e.ContractDetails.Contract); Start(cd); DB_ModelContainer db = new DB_ModelContainer(); db.DisplayedContracts.Add(cd); await db.SaveChangesAsync(); }
public MainWindow() { InitializeComponent(); DB_ModelContainer db = new DB_ModelContainer(); db.Database.Migrate(); mainViewModel = new Main_ViewModel(); DataContext = mainViewModel; Workspace_ViewModel.SetFullScreen_Event += VmFullScreen_SetFullScreen_Event; }
public async Task DeleteFromDB() { DB_ModelContainer db = new DB_ModelContainer(); ContractData cData = db.DisplayedContracts.FirstOrDefault(c => c.Symbol == ContractDetails.Contract.Symbol && c.SecType == ContractDetails.Contract.SecType); if (cData != null) { db.DisplayedContracts.Remove(cData); await db.SaveChangesAsync(); ContractRemoved_Event?.Invoke(this, EventArgs.Empty); } }
public async void SaveToDB() { DB_ModelContainer db = new DB_ModelContainer(); ContractData cData = db.DisplayedContracts.FirstOrDefault(c => c.Symbol == ContractDetails.Contract.Symbol && c.SecType == ContractDetails.Contract.SecType); if (cData == null) { ContractData cd = new ContractData(ContractDetails.Contract); db.DisplayedContracts.Add(cd); await db.SaveChangesAsync(); } }
public async void Start(ContractData cd = null) { List <ContractData> cDataList; Task rtTask; if (cd == null) { DB_ModelContainer db = new DB_ModelContainer(); cDataList = db.DisplayedContracts.ToList(); // Create Real Time queue only once, rtTask = Task.Factory.StartNew(StartRealTime); } else { // Got only one contract data to add a symbol, // possible source is AddSymbol_ViewModel: cDataList = new List <ContractData>(); cDataList.Add(cd); } pipelineStartup.QuoteAdded += PipelineStartup_AddQuote; pipelineStartup.QuoteRemoved += PipelineStartup_QuoteRemoved; pipelineStartup.QuotesRealTimeStarted += PipelineStartup_QuotesRealTimeStarted; await pipelineStartup.Run(cDataList); ChangeDimensions(height, width); pipelineStartup.QuoteAdded -= PipelineStartup_AddQuote; pipelineStartup.QuoteRemoved -= PipelineStartup_QuoteRemoved; pipelineStartup.QuotesRealTimeStarted -= PipelineStartup_QuotesRealTimeStarted; //if (cd == null) //{ // System.Timers.Timer timer = new System.Timers.Timer(); // timer.Elapsed += async (sender, e) => await TickTimer(); // timer.AutoReset = true; // timer.Interval = 5000; // timer.Start(); //} }
public bool LoadSettingsFromDB() { bool settingsOK = true; DB_ModelContainer db = new DB_ModelContainer(); valuesList = db.Settings.ToDictionary(s => s.Key, s => s.Value); preValuesList = new Dictionary <string, string>(valuesList); foreach (SettingsList.Keys key in Enum.GetValues(typeof(Keys))) { if (valuesList.Keys.Contains(key.ToString()) == false) { settingsOK = false; valuesList[key.ToString()] = DefaultValues[(int)key]; } } return(settingsOK); }
private void button2_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); var path = openFileDialog1.FileName; System.Data.SQLite.SQLiteConnectionStringBuilder connect = new SQLiteConnectionStringBuilder("Data Source=" + path); System.Data.EntityClient.EntityConnectionStringBuilder entity_connect = new System.Data.EntityClient.EntityConnectionStringBuilder(); entity_connect.Provider = @"System.Data.SQLite"; entity_connect.ProviderConnectionString = connect.ConnectionString; entity_connect.Metadata = @"res://*/DB_Model.csdl|res://*/DB_Model.ssdl|res://*/DB_Model.msl"; data_source = new DB_ModelContainer(entity_connect.ConnectionString); dataGridView1.DataSource = data_source.Ciphers_Table; MessageBox.Show("База удачно подключена"); }