void SaveHistorian(Historian historian, bool isNew)
        {
            try
            {
                bool continueSave = true;

                if (!isNew)
                {
                    if ((m_typeName == "HistorianAdapters.LocalOutputAdapter" && historian.TypeName != m_typeName) ||
                        (m_isLocal && !historian.IsLocal))
                    {
                        SystemMessages sm = new SystemMessages(new Message() { UserMessage = "You are changing your historian type.", SystemMessage = "You are changing your historian type from an in-process local historian to another historian provider. Please note that once the changes are applied, any customizations you may have made to the in-process local historian in the openPDC configuration file will be lost." + Environment.NewLine + "Do you want to continue?", UserMessageType = MessageType.Confirmation }, ButtonType.YesNo);
                        sm.Closed += new EventHandler(delegate(object popupWindow, EventArgs eargs)
                        {
                            if ((bool)sm.DialogResult)
                                continueSave = true;
                            else
                                continueSave = false;
                        });
                        sm.Owner = Window.GetWindow(this);
                        sm.ShowPopup();
                    }
                }

                if (continueSave)
                {
                    string result = CommonFunctions.SaveHistorian(null, historian, isNew);
                    SystemMessages sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success },
                            ButtonType.OkOnly);
                    sm.Owner = Window.GetWindow(this);
                    sm.ShowPopup();
                    GetHistorians();
                    //make this newly added or updated item as default selected. So user can click initialize right away.
                    ListBoxHistorianList.SelectedItem = ((List<Historian>)ListBoxHistorianList.ItemsSource).Find(c => c.Acronym == historian.Acronym);
                }
            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveHistorian", ex);
                SystemMessages sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Historian Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                        ButtonType.OkOnly);
                sm.Owner = Window.GetWindow(this);
                sm.ShowPopup();
            }
        }
        void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            #if SILVERLIGHT
            System.Windows.Media.Animation.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())
            {
                Historian historian = new Historian();
                historian.NodeID = ((KeyValuePair<string, string>)ComboBoxNode.SelectedItem).Key;
                historian.Acronym = TextBoxAcronym.Text;
                historian.Name = TextBoxName.Text;
                historian.AssemblyName = TextBoxAssemblyName.Text;
                historian.TypeName = TextBoxTypeName.Text;
                historian.ConnectionString = TextBoxConnectionString.Text;
                historian.IsLocal = (bool)CheckboxIsLocal.IsChecked;
                historian.Description = TextBoxDescription.Text;
                historian.LoadOrder = TextBoxLoadOrder.Text.ToInteger();
                historian.MeasurementReportingInterval = TextBoxMeasurementReportingInterval.Text.ToInteger();
                historian.Enabled = (bool)CheckboxEnabled.IsChecked;

                if (m_inEditMode == true && m_historianID > 0)
                {
                    historian.ID = m_historianID;
                    SaveHistorian(historian, false);
                }
                else
                    SaveHistorian(historian, true);
            }
        }
Beispiel #3
0
        public static string SaveHistorian(DataConnection connection, Historian historian, bool isNew)
        {
            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 Historian (NodeID, Acronym, Name, AssemblyName, TypeName, ConnectionString, IsLocal, MeasurementReportingInterval, Description, LoadOrder, Enabled, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) Values " +
                        "(@nodeID, @acronym, @name, @assemblyName, @typeName, @connectionString, @isLocal, @measurementReportingInterval, @description, @loadOrder, @enabled, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update Historian Set NodeID = @nodeID, Acronym = @acronym, Name = @name, AssemblyName = @assemblyName, TypeName = @typeName, " +
                        "ConnectionString = @connectionString, IsLocal = @isLocal, MeasurementReportingInterval = @measurementReportingInterval, Description = @description, LoadOrder = @loadOrder, Enabled = @enabled, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

                command.Parameters.Add(AddWithValue(command, "@nodeID", historian.NodeID));
                command.Parameters.Add(AddWithValue(command, "@acronym", historian.Acronym.Replace(" ", "").ToUpper()));
                command.Parameters.Add(AddWithValue(command, "@name", historian.Name));
                command.Parameters.Add(AddWithValue(command, "@assemblyName", historian.AssemblyName));
                command.Parameters.Add(AddWithValue(command, "@typeName", historian.TypeName));
                command.Parameters.Add(AddWithValue(command, "@connectionString", historian.ConnectionString));
                command.Parameters.Add(AddWithValue(command, "@isLocal", historian.IsLocal));
                command.Parameters.Add(AddWithValue(command, "@measurementReportingInterval", historian.MeasurementReportingInterval));
                command.Parameters.Add(AddWithValue(command, "@description", historian.Description));
                command.Parameters.Add(AddWithValue(command, "@loadOrder", historian.LoadOrder));
                command.Parameters.Add(AddWithValue(command, "@enabled", historian.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", historian.ID));

                command.ExecuteNonQuery();
                return "Historian Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }