private void Save() { if (_currentEntity != null) { ConfigureModel Model = new ConfigureModel(); if (cbtemplate.SelectedIndex == -1) { _currentEntity.ConnectionName = this.tbConnectionname.Text; Connections.Add(_currentEntity); } Model.Save(Connections, Configure.DEFAULT_CONNECTION_CONFIG_NAME); ConfigureModel.ClearCache(); this.Close(); } }
private void Save() { ConfigureModel Model = new ConfigureModel(); if (cbtemplate.SelectedIndex == 0)//add { if (Connections.All(p => p.ConnectionName != this.tbConnectionname.Text)) { var newData = new ConnectionEntity(); newData.ConnectionName = this.tbConnectionname.Text; newData.ServerName = this.tbservername.Text; newData.WindowsAuthentication = cbAuthmode.SelectedIndex == 0; newData.UserId = tbusername.Text; newData.Password = tbpwd.Text; Connections.Add(newData); Model.Save(Connections, Configure.DEFAULT_CONNECTION_CONFIG_NAME); ConfigureModel.ClearCache(); } else { MessageBox.Show("This connection name has exists.", "Warning"); } } else //edit { var data = Connections.FirstOrDefault(p => p.ConnectionName == cbtemplate.SelectedValue.ToString()); if (data != null) { data.ConnectionName = this.tbConnectionname.Text; data.ServerName = this.tbservername.Text; data.WindowsAuthentication = cbAuthmode.SelectedIndex == 0; data.UserId = tbusername.Text; data.Password = tbpwd.Text; Model.Save(Connections, Configure.DEFAULT_CONNECTION_CONFIG_NAME); } else { MessageBox.Show("oops! ", "Warning"); } } }