Пример #1
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 SaveOutputStreamDeviceAnalog(OutputStreamDeviceAnalog outputStreamDeviceAnalog, bool isNew)
        {
            SystemMessages sm;
            try
            {
                string result = CommonFunctions.SaveOutputStreamDeviceAnalog(null, outputStreamDeviceAnalog, isNew);
                sm = new SystemMessages(new Message() { UserMessage = result, SystemMessage = string.Empty, UserMessageType = MessageType.Success },
                        ButtonType.OkOnly);
                GetOutputStreamDeviceAnalogList();
                //ClearForm();
                //make this newly added or updated item as default selected. So user can click initialize right away.
                ListBoxOutputStreamDeviceAnalogList.SelectedItem = ((List<OutputStreamDeviceAnalog>)ListBoxOutputStreamDeviceAnalogList.ItemsSource).Find(c => c.Label == outputStreamDeviceAnalog.Label);

            }
            catch (Exception ex)
            {
                CommonFunctions.LogException(null, "WPF.SaveOutputStreamDeviceAnalog", ex);
                sm = new SystemMessages(new Message() { UserMessage = "Failed to Save Output Stream Device Analog Information", SystemMessage = ex.Message, UserMessageType = MessageType.Error },
                        ButtonType.OkOnly);
            }
            sm.Owner = Window.GetWindow(this);
            sm.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            sm.ShowPopup();
        }
Пример #3
0
        public static string SaveOutputStreamDeviceAnalog(DataConnection connection, OutputStreamDeviceAnalog outputStreamDeviceAnalog, 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 OutputStreamDeviceAnalog (NodeID, OutputStreamDeviceID, Label, Type, LoadOrder, ScalingValue, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                        "Values (@nodeID, @outputStreamDeviceID, @label, @type, @loadOrder, @scalingValue, @updatedBy, @updatedOn, @createdBy, @createdOn)";
                else
                    command.CommandText = "Update OutputStreamDeviceAnalog Set NodeID = @nodeID, OutputStreamDeviceID = @outputStreamDeviceID, Label = @label, " +
                        "Type = @type, LoadOrder = @loadOrder, ScalingValue = @scalingValue, UpdatedBy = @updatedBy, UpdatedOn = @updatedOn Where ID = @id";

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

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