Exemple #1
0
        private void SaveField()
        {
            if (this.alreadySavedFlag)
            {
                return;
            }

            this.alreadySavedFlag = true;
            string activeTab = tabControl1.SelectedTab.Text;

            Control[] ctrls = tabControl1.SelectedTab.Controls.Find("listView1-" + activeTab, false);
            ListView  list  = (ListView)ctrls[0];

            ctrls = tabControl1.SelectedTab.Controls.Find("editkey", false);
            TextBox txtkey = (TextBox)ctrls[0];

            ctrls = tabControl1.SelectedTab.Controls.Find("editvalue", false);
            TextBox txtvalue = (TextBox)ctrls[0];

            ctrls = tabControl1.SelectedTab.Controls.Find("editType", false);
            ComboBox txtType = (ComboBox)ctrls[0];

            int index = (int)list.SelectedItems[0].Tag;

            using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider))
            {
                GSF.Data.Model.TableOperations <PQio.Model.CustomField> customFldTbl = new GSF.Data.Model.TableOperations <PQio.Model.CustomField>(connection);
                PQio.Model.CustomField fld;

                if (index == -1)
                {
                    fld         = new Model.CustomField();
                    fld.domain  = activeTab;
                    fld.AssetID = (int)this.m_channel.AssetID;
                    fld.EventID = (int)this.m_evt.ID;
                }
                else
                {
                    fld = customFldTbl.QueryRecordWhere("ID = {0}", index);
                }


                if (txtvalue.Text == "" && index != -1)
                {
                    DialogResult confirm = System.Windows.Forms.MessageBox.Show("This will delete the MetaDataTag " + fld.key, "Warning",
                                                                                System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning);
                    if (confirm == DialogResult.OK)
                    {
                        customFldTbl.DeleteRecord(fld);
                        HideTextEditor();
                        this.UpdateCustomFields();
                        return;
                    }
                }

                fld.key   = txtkey.Text;
                fld.Value = txtvalue.Text;
                fld.Type  = TextToType(txtType.Text);

                customFldTbl.AddNewOrUpdateRecord(fld);
                HideTextEditor();
                this.UpdateCustomFields();
            }
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            m_Asset.AssetKey = AssetNameTxtBox.Text;

            if (NomfTxtBox.Text.Trim() != "")
            {
                try
                {
                    if (!(Convert.ToDouble(NomfTxtBox.Text) == 0))
                    {
                        if (Convert.ToDouble(NomfTxtBox.Text) > 0)
                        {
                            m_Asset.NominalFrequency = Convert.ToDouble(NomfTxtBox.Text);
                        }
                        else
                        {
                            throw new ArgumentOutOfRangeException();
                        }
                    }
                }
                catch { MessageBox.Show("Nominal Frequency has to be a positive number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            }

            if (NomVTxtBox.Text.Trim() != "")
            {
                try
                {
                    if (!(Convert.ToDouble(NomVTxtBox.Text) == 0))
                    {
                        m_Asset.NominalVoltage = Convert.ToDouble(NomVTxtBox.Text);
                    }
                }
                catch { MessageBox.Show("Nominal Voltage has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            }


            if (lenTxtBox.Text.Trim() != "")
            {
                try
                {
                    if (!(Convert.ToDouble(lenTxtBox.Text) == 0))
                    {
                        m_Asset.Length = Convert.ToDouble(lenTxtBox.Text);
                    }
                }
                catch { MessageBox.Show("Length has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            }

            if (XFTxtBox.Text.Trim() != "")
            {
                try
                {
                    if (!(Convert.ToDouble(XFTxtBox.Text) == 0))
                    {
                        m_Asset.UpstreamXFMR = Convert.ToDouble(XFTxtBox.Text);
                    }
                }
                catch { MessageBox.Show("Upstream XF Size has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
            }


            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.Asset> assetTable = new GSF.Data.Model.TableOperations <PQds.Model.Asset>(connection);
                assetTable.AddNewOrUpdateRecord(m_Asset);
            }
            this.Close();
        }
Exemple #3
0
        private void UpdateCustomFields()
        {
            tabControl1.TabPages.Clear();

            using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider))
            {
                GSF.Data.Model.TableOperations <PQio.Model.CustomField> customFldTbl = new GSF.Data.Model.TableOperations <PQio.Model.CustomField>(connection);
                List <string> HeaderFlds;


                HeaderFlds = customFldTbl.QueryRecordsWhere("AssetID = {0} AND EventID = {1} ", m_channel.AssetID, m_evt.ID).Select(item => item.domain).Distinct().ToList();


                foreach (string domainName in HeaderFlds)
                {
                    TabPage myTabPage = new TabPage(domainName);


                    ListView data = new ListView();
                    data.HideSelection = false;
                    data.Location      = new System.Drawing.Point(9, 4);
                    data.Name          = "listView1-" + domainName;
                    data.Size          = new System.Drawing.Size(623, 223);
                    data.TabIndex      = 0;
                    data.UseCompatibleStateImageBehavior = false;
                    data.FullRowSelect = true;

                    data.View = View.Details;
                    // Add a column with width 20 and left alignment.
                    data.Columns.Add("key", "Key", 100, HorizontalAlignment.Left, 0);
                    data.Columns.Add("value", "Value", 75, HorizontalAlignment.Left, 0);
                    data.Columns.Add("type", "Type", 75, HorizontalAlignment.Left, 0);

                    data.Items.AddRange(customFldTbl.QueryRecordsWhere("domain = {0}", domainName).Select(item =>
                    {
                        ListViewItem listItem = new ListViewItem(new string[] { item.key, item.Value, TypeToText(item.Type) });
                        listItem.Tag          = item.ID;
                        return(listItem);
                    }).ToArray());

                    ListViewItem newItem = new ListViewItem(new string[] { "*", "*", "*" });
                    newItem.Tag = -1;

                    data.Items.Add(newItem);
                    data.SelectedIndexChanged += new EventHandler(this.SelectedIndexChanged);
                    myTabPage.Controls.Add(data);

                    //Add textbox and ComboBox to create new Custom Fields and edit them
                    TextBox txtKey = new TextBox();
                    txtKey.Visible = false;
                    txtKey.Name    = "editkey";
                    txtKey.KeyUp  += new KeyEventHandler(this.TxtEdit_KeyUp);
                    txtKey.Leave  += new EventHandler(this.TxtEdit_Leave);

                    TextBox txtValue = new TextBox();
                    txtValue.Visible = false;
                    txtValue.Name    = "editvalue";
                    txtValue.KeyUp  += new KeyEventHandler(this.TxtEdit_KeyUp);
                    txtValue.Leave  += new EventHandler(this.TxtEdit_Leave);

                    ComboBox txtType = new ComboBox();
                    txtType.Visible = false;

                    txtType.Items.Add("Text");
                    txtType.Items.Add("Numeric");

                    txtType.Name          = "editType";
                    txtType.KeyUp        += new KeyEventHandler(this.TxtEdit_KeyUp);
                    txtType.Leave        += new EventHandler(this.TxtEdit_Leave);
                    txtType.DropDownStyle = ComboBoxStyle.DropDownList;

                    myTabPage.Controls.Add(txtKey);
                    myTabPage.Controls.Add(txtValue);
                    myTabPage.Controls.Add(txtType);
                    tabControl1.TabPages.Add(myTabPage);
                }


                TabPage newTabbPage = new TabPage("Add New");
                tabControl1.TabPages.Add(newTabbPage);
                tabControl1.Selected += new System.Windows.Forms.TabControlEventHandler(this.CreateNewTab);

                if (HeaderFlds.Count == 0)
                {
                    this.tabControl1.Enabled = false;
                }
                else
                {
                    this.tabControl1.Enabled = true;
                }
            }

            this.alreadySavedFlag = false;
        }
Exemple #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            //Create a List of Tuples we will have to deal with....
            List <Tuple <PQds.Model.Event, PQds.Model.Asset> > files = new List <Tuple <Model.Event, Model.Asset> >();

            List <int> selectedEvtIDs   = this.chLstBoxEvt.CheckedItems.OfType <Model.Event>().Select(item => item.ID).ToList();
            List <int> selectedAssetIDs = this.chLstBoxAsset.CheckedItems.OfType <Model.Asset>().Select(item => item.ID).ToList();

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.AssetToEvent> assetToEventTable = new GSF.Data.Model.TableOperations <PQds.Model.AssetToEvent>(connection);
                GSF.Data.Model.TableOperations <PQds.Model.Asset>        assetTable        = new GSF.Data.Model.TableOperations <PQds.Model.Asset>(connection);
                GSF.Data.Model.TableOperations <PQds.Model.Event>        eventTable        = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection);

                foreach (int assetID in selectedAssetIDs)
                {
                    List <int> associatedEvents = assetToEventTable.QueryRecordsWhere("AssetID = {0}", assetID).Select(item => item.EventID).ToList();
                    foreach (int eventID in selectedEvtIDs)
                    {
                        if (associatedEvents.Contains(eventID))
                        {
                            files.Add(new Tuple <Model.Event, Model.Asset>(eventTable.QueryRecordWhere("ID = {0}", eventID), assetTable.QueryRecordWhere("ID = {0}", assetID)));
                        }
                    }
                }
            }


            if (files.Count() == 0)
            {
                MessageBox.Show("The selected assets and events do not contain any data. To export every asset from an event select all assets!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (files.Count() == 1)
            {
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();
                saveFileDialog1.RestoreDirectory = true;
                saveFileDialog1.Filter           = "PQDS file (*.csv)|*.csv";
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    WritePQDSFile(files, new List <string>()
                    {
                        saveFileDialog1.FileName
                    });
                }
            }
            else
            {
                DialogResult msg = MessageBox.Show("The selected assets and events will result in multiple PQDS files", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (msg == DialogResult.OK)
                {
                    FolderBrowserDialog saveFileDialog1 = new FolderBrowserDialog();
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        List <string> fileName = files.Select((item, index) => saveFileDialog1.SelectedPath + String.Format("/PQDS_{0}.csv", index)).ToList();
                        WritePQDSFile(files, fileName);
                    }
                }
            }

            this.Close();
        }
Exemple #5
0
        private void PQioChannel_Load(object sender, EventArgs e)
        {
            // Populate Combo Boxes
            comboBox1.Items.AddRange(Model.SignalType.DisplayOptions());
            comboBox2.Items.AddRange(Model.MeasurementType.DisplayOptions());
            comboBox3.Items.AddRange(Model.DataSensitivityCode.DisplayOptions());


            if (m_channel.SignalType != null)
            {
                comboBox1.SelectedIndex = Array.FindIndex(Model.SignalType.DisplayOptions(),
                                                          item => item == Model.SignalType.ToDisplay((int)m_channel.SignalType));
            }
            else
            {
                comboBox1.SelectedIndex = Array.FindIndex(Model.SignalType.DisplayOptions(),
                                                          item => item == Model.SignalType.ToDisplay(-1));
            }

            if (m_channel.MeasurementType != null)
            {
                comboBox2.SelectedIndex = Array.FindIndex(Model.MeasurementType.DisplayOptions(),
                                                          item => item == Model.MeasurementType.ToDisplay(m_channel.MeasurementType));
            }
            else
            {
                comboBox2.SelectedIndex = Array.FindIndex(Model.MeasurementType.DisplayOptions(),
                                                          item => item == Model.MeasurementType.ToDisplay(""));
            }

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.DataSensitivity> dataSensitivityTbl = new GSF.Data.Model.TableOperations <PQds.Model.DataSensitivity>(connection);
                GSF.Data.Model.TableOperations <PQds.Model.Meter>           deviceTbl          = new GSF.Data.Model.TableOperations <PQds.Model.Meter>(connection);


                if (this.m_channel.AssetID != null)
                {
                    // Make sure we check if there is any Data Sensitivity associated with this event

                    if (dataSensitivityTbl.QueryRecordCountWhere("Event = {0} AND Asset = {1}", this.m_evt.ID, this.m_channel.AssetID) > 0)
                    {
                        PQds.Model.DataSensitivity dataSensitivity = dataSensitivityTbl.QueryRecordsWhere("Event = {0} AND Asset = {1}", this.m_evt.ID, this.m_channel.AssetID).First();


                        comboBox3.SelectedIndex = Array.FindIndex(Model.DataSensitivityCode.DisplayOptions(),
                                                                  item => item == Model.DataSensitivityCode.ToDisplay((int)dataSensitivity.DataSensitivityCode));

                        DataSensitivityNoteText.Text = dataSensitivity.Note;
                    }
                    else
                    {
                        comboBox3.SelectedIndex = Array.FindIndex(Model.DataSensitivityCode.DisplayOptions(),
                                                                  item => item == Model.DataSensitivityCode.ToDisplay(-1));
                        DataSensitivityNoteText.Text = "";
                    }
                }
                else
                {
                    comboBox3.Enabled       = false;
                    comboBox3.SelectedIndex = Array.FindIndex(Model.DataSensitivityCode.DisplayOptions(),
                                                              item => item == Model.DataSensitivityCode.ToDisplay(-1));
                }

                comboDevice.DisplayMember = "Text";
                comboDevice.ValueMember   = "Value";

                PQds.Model.Meter[] meters = deviceTbl.QueryRecords("").ToArray();

                comboDevice.Items.AddRange(meters.Select(item => new { Text = item.DeviceName, Value = item.ID }).ToArray());
                comboDevice.SelectedIndex = Array.FindIndex(meters, item => item.ID == this.m_channel.MeterID);
            }
            if (this.m_evt != null)
            {
                UpdateCustomFields();
            }
            else
            {
                this.tabControl1.Enabled = false;
            }

            this.MouseDown += new MouseEventHandler(OnClick);
        }
Exemple #6
0
        private async void WritePQDSFile(List <Tuple <PQds.Model.Event, PQds.Model.Asset> > data, List <string> fileName)
        {
            string logfileName;

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.Setting> settingTbl = new GSF.Data.Model.TableOperations <PQds.Model.Setting>(connection);
                logfileName = settingTbl.QueryRecordWhere("Name = {0}", "logfile.name").value;
            }

            FileParser.PQDSParser parser = new FileParser.PQDSParser(logfileName);

            PQdsProgress progressWindow = new PQdsProgress(fileName.Count() * 100);

            progressWindow.updateText(String.Format("Exporting file {0} out of {1}...", new object[2] {
                "{0}", fileName.Count()
            }));
            progressWindow.Show();

            if (fileName.Count() == 1)
            {
                if (radioButton1.Checked)
                {
                    await parser.WritePQDSFile(new Progress <int>(progressWindow.updateProgress), data[0].Item2, data[0].Item1, fileName[0], includeAuthorMetaData : chkAuthor.Checked, includeGUID : chkGUID.Checked);

                    progressWindow.Close();
                    return;
                }

                if (checkBox2.Checked)
                {
                    await parser.WritePQDSFile(new Progress <int>(progressWindow.updateProgress), data[0].Item2, data[0].Item1, fileName[0],
                                               chkDeviceMD.Checked, chkAssetMD.Checked, chkTimeMD.Checked, chkEvtMD.Checked, chkWaveForm.Checked, CustomMetaData.Checked, chkAuthor.Checked, chkGUID.Checked, dateTimePicker1.Value);
                }
                else
                {
                    await parser.WritePQDSFile(new Progress <int>(progressWindow.updateProgress), data[0].Item2, data[0].Item1, fileName[0],
                                               chkDeviceMD.Checked, chkAssetMD.Checked, chkTimeMD.Checked, chkEvtMD.Checked, chkWaveForm.Checked, CustomMetaData.Checked, chkAuthor.Checked, chkGUID.Checked);
                }
            }
            else
            {
                if (radioButton1.Checked)
                {
                    await parser.WritePQDSFiles(new Progress <int>(progressWindow.updateProgress), data.Select(item => item.Item2).ToList(), data.Select(item => item.Item1).ToList(), fileName, includeAuthorMetaData : chkAuthor.Checked, includeGUID : chkGUID.Checked);

                    progressWindow.Close();
                    return;
                }

                if (checkBox2.Checked)
                {
                    await parser.WritePQDSFiles(new Progress <int>(progressWindow.updateProgress), data.Select(item => item.Item2).ToList(), data.Select(item => item.Item1).ToList(), fileName,
                                                chkDeviceMD.Checked, chkAssetMD.Checked, chkTimeMD.Checked, chkEvtMD.Checked, chkWaveForm.Checked, CustomMetaData.Checked, chkAuthor.Checked, chkGUID.Checked, dateTimePicker1.Value);
                }
                else
                {
                    await parser.WritePQDSFiles(new Progress <int>(progressWindow.updateProgress), data.Select(item => item.Item2).ToList(), data.Select(item => item.Item1).ToList(), fileName,
                                                chkDeviceMD.Checked, chkAssetMD.Checked, chkTimeMD.Checked, chkEvtMD.Checked, chkWaveForm.Checked, CustomMetaData.Checked, chkAuthor.Checked, chkGUID.Checked);
                }
            }
            progressWindow.Close();
        }
Exemple #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.Event> evtTable = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection);
                PQds.Model.Event evt = evtTable.QueryRecordWhere("ID =  {0}", m_Event.ID);

                evt.Name      = faultIDTxtBox.Text;
                evt.EventTime = timeTxtBox.Value;

                if (peakITxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(peakITxtBox.Text) == 0))
                        {
                            evt.PeakCurrent = Convert.ToDouble(peakITxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Peak Current has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (peakVTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(peakVTxtBox.Text) == 0))
                        {
                            evt.PeakVoltage = Convert.ToDouble(peakVTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Peak Voltage has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (preITxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(preITxtBox.Text) == 0))
                        {
                            evt.PreEventCurrent = Convert.ToDouble(preITxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Pre-Event Current has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (preVTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(preVTxtBox.Text) == 0))
                        {
                            evt.PreEventVoltage = Convert.ToDouble(preVTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Pre-Event Voltage has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (I2tTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(I2tTxtBox.Text) == 0))
                        {
                            evt.FaultI2T = Convert.ToDouble(I2tTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Fault I2(t) has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }


                if (maxVaTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxVaTxtBox.Text) == 0))
                        {
                            evt.MaxVA = Convert.ToDouble(maxVaTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase A Voltage Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (maxVbTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxVbTxtBox.Text) == 0))
                        {
                            evt.MaxVB = Convert.ToDouble(maxVbTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase B Voltage Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (maxVcTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxVcTxtBox.Text) == 0))
                        {
                            evt.MaxVC = Convert.ToDouble(maxVcTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase C Voltage Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (minVaTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(minVaTxtBox.Text) == 0))
                        {
                            evt.MinVA = Convert.ToDouble(minVaTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase A Voltage Minimum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (minVbTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(minVbTxtBox.Text) == 0))
                        {
                            evt.MinVB = Convert.ToDouble(minVbTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase B Voltage Minimum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (minVcTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(minVcTxtBox.Text) == 0))
                        {
                            evt.MinVC = Convert.ToDouble(minVcTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase C Voltage Minimum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (maxIaTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxIaTxtBox.Text) == 0))
                        {
                            evt.MaxIA = Convert.ToDouble(maxIaTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase A Current Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (maxIbTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxIbTxtBox.Text) == 0))
                        {
                            evt.MaxIB = Convert.ToDouble(maxIbTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase B Current Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }
                if (maxIcTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(maxIcTxtBox.Text) == 0))
                        {
                            evt.MaxIC = Convert.ToDouble(maxIcTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Phase C Current Maximum has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }


                if (durationTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(durationTxtBox.Text) == 0))
                        {
                            evt.Duration = Convert.ToDouble(durationTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Event duration has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }



                if (distanceTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(distanceTxtBox.Text) == 0))
                        {
                            evt.DistanceToFault = Convert.ToDouble(distanceTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Distance to Fault has to be a Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }



                // Update Data from Comboboxes
                if ((string)FltTypeCombo.SelectedItem == "")
                {
                    evt.FaultType = null;
                }
                else
                {
                    evt.FaultType = Model.FaultType.ToValue((string)FltTypeCombo.SelectedItem);
                }

                if ((string)evtTypeCombo.SelectedItem == "")
                {
                    evt.EventType = null;
                }
                else
                {
                    evt.EventType = Model.EventType.ToValue((string)evtTypeCombo.SelectedItem);
                }


                if ((string)evtCauseCombo.SelectedItem == "")
                {
                    evt.FaultCause = null;
                }
                else
                {
                    evt.FaultCause = Model.FaultCause.ToValue((string)evtCauseCombo.SelectedItem);
                }

                evtTable.AddNewOrUpdateRecord(evt);
            }
            this.Close();
        }
        private Channel ParseChannel(Meter meter, GSF.PQDIF.Logical.ChannelDefinition channeldef, AdoDataConnection connection)
        {
            Channel channel = new Channel();

            channel.MeterID = meter.ID;
            channel.Name    = channeldef.ChannelName;

            GSF.PQDIF.Logical.QuantityMeasured quantity = channeldef.QuantityMeasured;
            Guid quantityType = channeldef.QuantityTypeID;

            GSF.PQDIF.Logical.Phase phase = channeldef.Phase;

            if (isRMS(quantityType))
            {
                channel.SignalType = SignalType.RMS;
            }
            else if (isPOW(quantityType))
            {
                channel.SignalType = SignalType.PointOnWave;
            }
            else
            {
                channel.SignalType = SignalType.other;
            }

            Boolean isV = quantity == QuantityMeasured.Voltage;
            Boolean isI = quantity == QuantityMeasured.Current;

            Boolean isA = (phase == Phase.AN) || (phase == Phase.AB);
            Boolean isB = (phase == Phase.BN) || (phase == Phase.BC);
            Boolean isC = (phase == Phase.CN) || (phase == Phase.CA);
            Boolean isN = phase == Phase.Residual;



            string measurementname = MeasurementType.other;

            if (isV && isA)
            {
                measurementname = MeasurementType.VoltageA;
            }
            else if (isV && isB)
            {
                measurementname = MeasurementType.VoltageB;
            }
            else if (isV && isC)
            {
                measurementname = MeasurementType.VoltageC;
            }
            else if (isI && isA)
            {
                measurementname = MeasurementType.CurrentA;
            }
            else if (isI && isB)
            {
                measurementname = MeasurementType.CurrentB;
            }
            else if (isI && isC)
            {
                measurementname = MeasurementType.CurrentC;
            }
            else if (isV && isN)
            {
                measurementname = MeasurementType.other;
            }
            else if (isI && isN)
            {
                measurementname = MeasurementType.other;
            }

            GSF.Data.Model.TableOperations <Channel> channelTable = new GSF.Data.Model.TableOperations <Channel>(connection);

            channel.MeasurementType = measurementname;

            channelTable.AddNewRecord(channel);
            channel.ID = ModelID.GetID <Channel>(connection);


            return(channel);
        }
        private void Parse(string filename)
        {
            List <ObservationRecord> observationRecords;
            List <DataSourceRecord>  dataSourceRecords;

            using (LogicalParser logicalParser = new LogicalParser(filename))
            {
                observationRecords = new List <ObservationRecord>();
                logicalParser.Open();

                while (logicalParser.HasNextObservationRecord())
                {
                    observationRecords.Add(logicalParser.NextObservationRecord());
                }

                dataSourceRecords = logicalParser.DataSourceRecords;
            }

            this.m_previousProgress = this.m_previousProgress + 50;
            this.mProgress.Report(this.m_previousProgress);

            if (observationRecords.Count == 0)
            {
                return;
            }
            if (dataSourceRecords.Count != 1)
            {
                return;
            }

            //create Meter Definition
            //For now assume a single meter
            Meter meter = new Meter();

            meter.DeviceName     = dataSourceRecords[0].DataSourceName;
            meter.Owner          = dataSourceRecords[0].DataSourceOwner;
            meter.DeviceAlias    = GSF.PQDIF.Logical.Equipment.ToString(dataSourceRecords[0].EquipmentID);
            meter.DeviceLocation = dataSourceRecords[0].DataSourceLocation;
            if (dataSourceRecords[0].Latitude < uint.MaxValue)
            {
                meter.Latitude = dataSourceRecords[0].Latitude;
            }
            if (dataSourceRecords[0].Longitude < uint.MaxValue)
            {
                meter.Longitude = dataSourceRecords[0].Longitude;
            }

            meter.AccountName = GSF.PQDIF.Logical.Vendor.ToString(dataSourceRecords[0].VendorID);

            using (TransactionScope scope = new TransactionScope())
            {
                AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider);

                GSF.Data.Model.TableOperations <Meter> meterTable = new GSF.Data.Model.TableOperations <Meter>(connection);

                meterTable.AddNewRecord(meter);
                meter.ID = ModelID.GetID <Meter>(connection);


                //create Channel Definitions
                List <PQio.Model.Channel> channels = dataSourceRecords[0].ChannelDefinitions.Select(channel => ParseChannel(meter, channel, connection)).ToList();
                List <PQio.Model.Event>   events   = new List <Event>();
                //create Event Definitions
                foreach (ObservationRecord record in observationRecords)
                {
                    //Create Event
                    Event evt = ParseObservationRecord(record, connection);

                    //create DataSeries objects
                    foreach (ChannelInstance channelInstance in record.ChannelInstances)
                    {
                        ParseSeries(channelInstance, channels[(int)channelInstance.ChannelDefinitionIndex], evt, connection);
                    }
                    events.Add(evt);
                }

                // Remove Channels whithout data
                channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList();
                events   = events.FindAll(item => RemoveEmptyEvents(item, connection)).ToList();

                // Remove Channels whithout data
                channels = channels.FindAll(item => RemoveEmptyChannel(item, connection)).ToList();

                // If only one set of data it's easy to keep only single line
                int nVa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageA);
                int nVb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageB);
                int nVc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.VoltageC);
                int nIa = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentA);
                int nIb = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentB);
                int nIc = channels.Count(channel => channel.MeasurementType.ToLower() == MeasurementType.CurrentC);

                if (nVa == 1 && nVb == 1 && nVc == 1)
                {
                    //Create new asset
                    Asset asset = new Asset()
                    {
                        AssetKey = String.Format("Asset 1 ({0})", meter.AccountName)
                    };


                    GSF.Data.Model.TableOperations <Asset> assetTable = new GSF.Data.Model.TableOperations <Asset>(connection);
                    assetTable.AddNewRecord(asset);
                    asset.ID = ModelID.GetID <Asset>(connection);

                    GSF.Data.Model.TableOperations <Channel> channelTable = new GSF.Data.Model.TableOperations <Channel>(connection);

                    Channel Va = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageA);
                    Channel Vb = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageB);
                    Channel Vc = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.VoltageC);

                    Va.AssetID = asset.ID;
                    Vb.AssetID = asset.ID;
                    Vc.AssetID = asset.ID;

                    channelTable.UpdateRecord(Va);
                    channelTable.UpdateRecord(Vb);
                    channelTable.UpdateRecord(Vc);

                    if (nIa == 1 && nIb == 1 && nIc == 1)
                    {
                        Channel Ia = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentA);
                        Channel Ib = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentB);
                        Channel Ic = channels.Find(item => item.MeasurementType.ToLower() == MeasurementType.CurrentC);

                        Ia.AssetID = asset.ID;
                        Ib.AssetID = asset.ID;
                        Ic.AssetID = asset.ID;

                        channelTable.UpdateRecord(Ia);
                        channelTable.UpdateRecord(Ib);
                        channelTable.UpdateRecord(Ic);
                    }
                }

                scope.Complete();
            }
            this.m_previousProgress = this.m_previousProgress + 50;
            this.mProgress.Report(this.m_previousProgress);
        }
Exemple #10
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.Meter> deviceTable = new GSF.Data.Model.TableOperations <PQds.Model.Meter>(connection);
                PQds.Model.Meter device = deviceTable.QueryRecordWhere("ID = {0}", m_device.ID);
                if (device is null)
                {
                    device = new PQds.Model.Meter();
                }

                device.DeviceName = NameTxtBox.Text;

                device.DeviceAlias = AliasTxtBox.Text;


                device.DeviceLocation      = LocationTxtBox.Text;
                device.DeviceLocationAlias = LocationAliasTxtBox.Text;


                if (LatTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(LatTxtBox.Text) == 0))
                        {
                            device.Latitude = Convert.ToDouble(LatTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Latitude has to be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                if (LongTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(LongTxtBox.Text) == 0))
                        {
                            device.Longitude = Convert.ToDouble(LongTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Longitude has to be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }

                device.AccountAlias = ActAliasTxtBox.Text;
                device.AccountName  = ActTxtBox.Text;

                device.Owner = OwnerTxtBox.Text;

                if (XFRTxtBox.Text != "")
                {
                    try
                    {
                        if (!(Convert.ToDouble(XFRTxtBox.Text) == 0))
                        {
                            device.DistanceToXFR = Convert.ToDouble(XFRTxtBox.Text);
                        }
                    }
                    catch { MessageBox.Show("Distance to XFMR has to be a number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
                }


                if ((string)connBox.SelectedItem == "")
                {
                    device.ConnectionType = null;
                }
                else
                {
                    device.ConnectionType = Model.ConnectionType.ToValue((string)connBox.SelectedItem);
                }

                deviceTable.AddNewOrUpdateRecord(device);
            }
            this.Close();
        }