void SaveOutputStreamDevicePhasor(OutputStreamDevicePhasor outputStreamDevicePhasor, bool isNew)
        {
            SystemMessages sm;
            try
            {
                string result = CommonFunctions.SaveOutputStreamDevicePhasor(null, outputStreamDevicePhasor, isNew);
                sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success },
                        ButtonType.OkOnly);
                GetOutputStreamDevicePhasorList();
                //ClearForm();

                //make this newly added or updated item as default selected. So user can click initialize right away.
                ListBoxOutputStreamDevicePhasorList.SelectedItem = ((List<OutputStreamDevicePhasor>)ListBoxOutputStreamDevicePhasorList.ItemsSource).Find(c => c.Label == outputStreamDevicePhasor.Label);

            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveOutputStreamDevicePhasor", ex);
                sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Output Stream Device Phasor Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                        ButtonType.OkOnly);
            }
            sm.Owner = Window.GetWindow(this);
            sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            sm.ShowPopup();
        }
Ejemplo n.º 2
0
        public static string SaveOutputStreamDevicePhasor(DataConnection connection, OutputStreamDevicePhasor outputStreamDevicePhasor, bool isNew)
        {
            //DataConnection connection = new DataConnection();
            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 OutputStreamDevicePhasor (NodeID, OutputStreamDeviceID, Label, Type, Phase, LoadOrder, ScalingValue, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                        "Values (@nodeID, @outputStreamDeviceID, @label, @type, @phase, @loadOrder, @scalingValue, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update OutputStreamDevicePhasor Set NodeID = @nodeID, OutputStreamDeviceID = @outputStreamDeviceID, Label = @label, " +
                        "Type = @type, Phase = @phase, LoadOrder = @loadOrder, ScalingValue = @scalingValue, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

                command.Parameters.Add(AddWithValue(command, "@nodeID", outputStreamDevicePhasor.NodeID));
                command.Parameters.Add(AddWithValue(command, "@outputStreamDeviceID", outputStreamDevicePhasor.OutputStreamDeviceID));
                command.Parameters.Add(AddWithValue(command, "@label", outputStreamDevicePhasor.Label));
                command.Parameters.Add(AddWithValue(command, "@type", outputStreamDevicePhasor.Type));
                command.Parameters.Add(AddWithValue(command, "@phase", outputStreamDevicePhasor.Phase));
                command.Parameters.Add(AddWithValue(command, "@loadOrder", outputStreamDevicePhasor.LoadOrder));
                command.Parameters.Add(AddWithValue(command, "@scalingValue", outputStreamDevicePhasor.ScalingValue));
                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", outputStreamDevicePhasor.ID));
                }

                command.ExecuteNonQuery();
                return "Output Stream Device Phasor Information Saved Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }
Ejemplo n.º 3
0
        public static string AddDevices(DataConnection connection, int outputStreamID, Dictionary<int, string> devicesToBeAdded, bool addDigitals, bool addAnalogs)
        {
            bool createdConnection = false;
            try
            {
                if (connection == null)
                {
                    connection = new DataConnection();
                    createdConnection = true;
                }
                foreach (KeyValuePair<int, string> deviceInfo in devicesToBeAdded)	//loop through all the devices that needs to be added.
                {
                    Device device = new Device();
                    device = GetDeviceByDeviceID(connection, deviceInfo.Key);	//Get all the information about the device to be added.
                    OutputStreamDevice outputStreamDevice = new OutputStreamDevice();
                    outputStreamDevice.NodeID = device.NodeID;
                    outputStreamDevice.AdapterID = outputStreamID;
                    outputStreamDevice.Acronym = device.Acronym;
                    outputStreamDevice.BpaAcronym = string.Empty;
                    outputStreamDevice.Name = device.Name;
                    outputStreamDevice.LoadOrder = device.LoadOrder;
                    outputStreamDevice.Enabled = true;
                    outputStreamDevice.PhasorDataFormat = string.Empty;
                    outputStreamDevice.FrequencyDataFormat = string.Empty;
                    outputStreamDevice.AnalogDataFormat = string.Empty;
                    outputStreamDevice.CoordinateFormat = string.Empty;
                    outputStreamDevice.IdCode = device.AccessID;
                    SaveOutputStreamDevice(connection, outputStreamDevice, true, string.Empty);	//save in to OutputStreamDevice Table.

                    int savedOutputStreamDeviceID = GetOutputStreamDevice(connection, outputStreamID, device.Acronym).ID;

                    //********************************************
                    List<Phasor> phasorList = new List<Phasor>();
                    phasorList = GetPhasorList(connection, deviceInfo.Key);			//Get all the phasor information for the device to be added.

                    foreach (Phasor phasor in phasorList)
                    {
                        OutputStreamDevicePhasor outputStreamDevicePhasor = new OutputStreamDevicePhasor(); //Add all phasors one by one into OutputStreamDevicePhasor table.
                        outputStreamDevicePhasor.NodeID = device.NodeID;
                        outputStreamDevicePhasor.OutputStreamDeviceID = savedOutputStreamDeviceID;
                        outputStreamDevicePhasor.Label = phasor.Label;
                        outputStreamDevicePhasor.Type = phasor.Type;
                        outputStreamDevicePhasor.Phase = phasor.Phase;
                        outputStreamDevicePhasor.LoadOrder = phasor.SourceIndex;
                        outputStreamDevicePhasor.ScalingValue = 0;
                        SaveOutputStreamDevicePhasor(connection, outputStreamDevicePhasor, true);
                    }
                    //********************************************

                    //********************************************
                    List<Measurement> measurementList = new List<Measurement>();
                    measurementList = GetMeasurementsByDevice(connection, deviceInfo.Key);

                    int analogIndex = 0;
                    foreach (Measurement measurement in measurementList)
                    {
                        if (measurement.SignalAcronym != "STAT")
                        {
                            OutputStreamMeasurement outputStreamMeasurement = new OutputStreamMeasurement();
                            outputStreamMeasurement.NodeID = device.NodeID;
                            outputStreamMeasurement.AdapterID = outputStreamID;
                            outputStreamMeasurement.HistorianID = measurement.HistorianID;
                            outputStreamMeasurement.PointID = measurement.PointID;
                            outputStreamMeasurement.SignalReference = measurement.SignalReference;

                            if (measurement.SignalAcronym == "ALOG")
                            {
                                if (addAnalogs)
                                {
                                    SaveOutputStreamMeasurement(connection, outputStreamMeasurement, true);

                                    OutputStreamDeviceAnalog outputStreamDeviceAnalog = new OutputStreamDeviceAnalog();
                                    outputStreamDeviceAnalog.NodeID = device.NodeID;
                                    outputStreamDeviceAnalog.OutputStreamDeviceID = savedOutputStreamDeviceID;
                                    outputStreamDeviceAnalog.Label = device.Acronym.Length > 12 ? device.Acronym.Substring(0, 12) + ":A" + analogIndex.ToString() : device.Acronym + ":A" + analogIndex.ToString(); // measurement.PointTag;
                                    outputStreamDeviceAnalog.Type = 0;	//default
                                    outputStreamDeviceAnalog.LoadOrder = Convert.ToInt32(measurement.SignalReference.Substring((measurement.SignalReference.LastIndexOf("-") + 3)));
                                    outputStreamDeviceAnalog.ScalingValue = 0;
                                    SaveOutputStreamDeviceAnalog(connection, outputStreamDeviceAnalog, true);
                                    analogIndex += 1;
                                }
                            }
                            else if (measurement.SignalAcronym == "DIGI")
                            {
                                if (addDigitals)
                                {
                                    SaveOutputStreamMeasurement(connection, outputStreamMeasurement, true);

                                    OutputStreamDeviceDigital outputStreamDeviceDigital = new OutputStreamDeviceDigital();
                                    outputStreamDeviceDigital.NodeID = device.NodeID;
                                    outputStreamDeviceDigital.OutputStreamDeviceID = savedOutputStreamDeviceID;
                                    outputStreamDeviceDigital.Label = digitalLabel;     // measurement.PointTag;
                                    outputStreamDeviceDigital.LoadOrder = Convert.ToInt32(measurement.SignalReference.Substring((measurement.SignalReference.LastIndexOf("-") + 3)));
                                    outputStreamDeviceDigital.MaskValue = 0;
                                    SaveOutputStreamDeviceDigital(connection, outputStreamDeviceDigital, true);
                                }
                            }
                            else
                                SaveOutputStreamMeasurement(connection, outputStreamMeasurement, true);

                        }
                    }
                    //********************************************
                }

                return "Output Stream Device(s) Added Successfully";
            }
            finally
            {
                if (createdConnection && connection != null)
                    connection.Dispose();
            }
        }
        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())
            {
                OutputStreamDevicePhasor outputStreamDevicePhasor = new OutputStreamDevicePhasor();
                App app = (App)Application.Current;
                outputStreamDevicePhasor.NodeID = app.NodeValue;
                outputStreamDevicePhasor.OutputStreamDeviceID = m_sourceOutputStreamDeviceID;
                outputStreamDevicePhasor.Label = TextBoxLabel.Text.CleanText();
                outputStreamDevicePhasor.Type = ((KeyValuePair<string, string>)ComboboxType.SelectedItem).Key;
                outputStreamDevicePhasor.Phase = ((KeyValuePair<string, string>)ComboboxPhase.SelectedItem).Key;
                outputStreamDevicePhasor.LoadOrder = TextBoxLoadOrder.Text.ToInteger();
                outputStreamDevicePhasor.ScalingValue = TextBoxScalingValue.Text.ToInteger();

                if (m_inEditMode == true && m_outputStreamDevicePhasorID > 0)
                {
                    outputStreamDevicePhasor.ID = m_outputStreamDevicePhasorID;
                    SaveOutputStreamDevicePhasor(outputStreamDevicePhasor, false);
                }
                else
                    SaveOutputStreamDevicePhasor(outputStreamDevicePhasor, true);
            }
        }