void ButtonSave_Click(object sender, RoutedEventArgs e) { #if SILVERLIGHT Storyboard sb = new Storyboard(); sb = Application.Current.Resources["ButtonPressAnimation"] as Storyboard; sb.Completed += new EventHandler(delegate(object obj, EventArgs es) { sb.Stop(); }); Storyboard.SetTarget(sb, ButtonSaveTransform); sb.Begin(); #endif if (IsValid()) { Adapter adapter = new Adapter(); adapter.adapterType = m_adapterType; adapter.NodeID = ((KeyValuePair<string, string>)ComboboxNode.SelectedItem).Key; adapter.AdapterName = TextBoxAdapterName.Text.CleanText(); adapter.AssemblyName = TextBoxAssemblyName.Text.CleanText(); adapter.TypeName = TextBoxTypeName.Text.CleanText(); adapter.ConnectionString = TextBoxConnectionString.Text.CleanText(); adapter.LoadOrder = TextBoxLoadOrder.Text.ToInteger(); adapter.Enabled = (bool)CheckboxEnabled.IsChecked; if (m_inEditMode == true && m_adapterID > 0) { adapter.ID = m_adapterID; SaveAdapter(adapter, false); } else { SaveAdapter(adapter, true); } } }
void SaveAdapter(Adapter adapter, bool isNew) { SystemMessages sm; try { string result = CommonFunctions.SaveAdapter(null, adapter, isNew); sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.ShowPopup(); GetAdapterList(); //ClearForm(); //make this newly added or updated item as default selected. So user can click initialize right away. ListBoxAdapterList.SelectedItem = ((List<Adapter>)ListBoxAdapterList.ItemsSource).Find(c => c.AdapterName == adapter.AdapterName); // Update Metadata in the openPDC Service. try { if (serviceClient != null && serviceClient.Helper.RemotingClient.CurrentState == TVA.Communication.ClientState.Connected) CommonFunctions.SendCommandToWindowsService(serviceClient, "ReloadConfig"); //we do this to make sure all statistical measurements are in the system. else { sm = new SystemMessages(new openPDCManager.Utilities.Message() { UserMessage = "Failed to Perform Configuration Changes", SystemMessage = "Application is disconnected from the openPDC Service.", UserMessageType = openPDCManager.Utilities.MessageType.Information }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); } } catch (Exception ex) { sm = new SystemMessages(new openPDCManager.Utilities.Message() { UserMessage = "Failed to Perform Configuration Changes", SystemMessage = ex.Message, UserMessageType = openPDCManager.Utilities.MessageType.Information }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.WindowStartupLocation = WindowStartupLocation.CenterOwner; sm.ShowPopup(); CommonFunctions.LogException(null, "SaveAdapter.RefreshMetadata", ex); } } catch (Exception ex) { CommonFunctions.LogException(null, "WPF.SaveAdapter", ex); sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Adapter Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error }, ButtonType.OkOnly); sm.Owner = Window.GetWindow(this); sm.ShowPopup(); } }
public static string SaveAdapter(DataConnection connection, Adapter adapter, bool isNew) { string tableName; AdapterType adapterType = adapter.adapterType; if (adapterType == AdapterType.Input) tableName = "CustomInputAdapter"; else if (adapterType == AdapterType.Action) tableName = "CustomActionAdapter"; else tableName = "CustomOutputAdapter"; bool createdConnection = false; try { if (connection == null) { connection = new DataConnection(); createdConnection = true; } IDbCommand command = connection.Connection.CreateCommand(); command.CommandType = CommandType.Text; if (isNew) command.CommandText = "Insert Into " + tableName + " (NodeID, AdapterName, AssemblyName, TypeName, ConnectionString, LoadOrder, Enabled, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values " + "(@nodeID, @adapterName, @assemblyName, @typeName, @connectionString, @loadOrder, @enabled, @updatedBy, @updatedOn, @createdBy, @createdOn)"; else command.CommandText = "Update " + tableName + " Set NodeID = @nodeID, AdapterName = @adapterName, AssemblyName = @assemblyName, TypeName = @typeName, " + "ConnectionString = @connectionString, LoadOrder = @loadOrder, Enabled = @enabled, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id"; command.Parameters.Add(AddWithValue(command, "@nodeID", adapter.NodeID)); command.Parameters.Add(AddWithValue(command, "@adapterName", adapter.AdapterName)); command.Parameters.Add(AddWithValue(command, "@assemblyName", adapter.AssemblyName)); command.Parameters.Add(AddWithValue(command, "@typeName", adapter.TypeName)); command.Parameters.Add(AddWithValue(command, "@connectionString", adapter.ConnectionString)); command.Parameters.Add(AddWithValue(command, "@loadOrder", adapter.LoadOrder)); command.Parameters.Add(AddWithValue(command, "@enabled", adapter.Enabled)); command.Parameters.Add(AddWithValue(command, "@updatedBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@updatedOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); if (isNew) { command.Parameters.Add(AddWithValue(command, "@createdBy", s_currentUser)); command.Parameters.Add(AddWithValue(command, "@createdOn", command.Connection.ConnectionString.Contains("Microsoft.Jet.OLEDB") ? DateTime.UtcNow.Date : DateTime.UtcNow)); } else command.Parameters.Add(AddWithValue(command, "@id", adapter.ID)); command.ExecuteNonQuery(); return "Adapter Information Saved Successfully"; } finally { if (createdConnection && connection != null) connection.Dispose(); } }