private void SaveLastConnection( long groupId, long templateId ) { ConnectionType cnnType = SelectedConnectionType; if (cnnType != null) { string machineName = Environment.MachineName; LastConnectionProtocolRow lastConnectionProt = new LastConnectionProtocolRow { GroupId = groupId, TemplateId = templateId, MachineName = machineName, DbType = cnnType.Id }; long?lastConnectionId = this._storage.LastConnectionProtocolTable .SaveLastConnection(lastConnectionProt); if (lastConnectionId != null) { LastConnectionRow lastConnectionRow = new LastConnectionRow { MachineName = machineName, LastConnectionProtocolId = lastConnectionId.Value }; this._storage.LastConnectionTable .SaveLastConnection(lastConnectionRow); } } }
private void InitializeBindings() { // set data source type bindings List <BindingWrapper <ConnectionType> > connectionTypes = this._model.ConnectionTypes; this._lastConnections = ReadLastConnections(connectionTypes.Select(bw => bw.Item).ToList()); // retrieve last connection group LastConnectionRow lastConnectionRow = this._storage.LastConnectionTable.GetLastConnection(Environment.MachineName); ConnectionInfo lastConnection = null; if (lastConnectionRow != null) { lastConnection = this._lastConnections.Values .FirstOrDefault(lc => lastConnectionRow.LastConnectionProtocolId == lc.ConnectionId); } this.bsConnectionType.DataSource = connectionTypes; this.bsConnectionType.DataMember = "Item"; this.cmbDataBaseType.DataSource = bsConnectionType.DataSource; // select data source type used in previous session if (this.cmbDataBaseType.Items.Count > 0) { this.cmbDataBaseType.SelectedItem = 0; if (lastConnection != null) { BindingWrapper <ConnectionType> selItem = connectionTypes.FirstOrDefault( ct => ct.Item.Id == lastConnection.ConnectionType); if (selItem != null) { this.cmbDataBaseType.SelectedItem = selItem; } } // set module type bindings BindModuleType(lastConnection); } // load external templates paths from sqlite db cmbPathToFile.Items.Clear(); List <TemplateRow> externalTemplates = this._storage.TemplateDirectory.GetExternalTemplates(); foreach (TemplateRow externalTemplate in externalTemplates) { string path = Path.Combine(externalTemplate.Directory, externalTemplate.Id); cmbPathToFile.Items.Add(path); } UpdateConnections(lastConnection); BindTemplate(lastConnection); UpdateControlsState(); }