Exemple #1
0
        static void Main(string[] args)
        {
            try
            {
                using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                {
                    GSF.Data.Model.TableOperations <PQds.Model.Setting> tableOperations = new GSF.Data.Model.TableOperations <PQds.Model.Setting>(connection);

                    Setting company = tableOperations.QueryRecordWhere("Name = {0}", "contact.utility");
                    Setting email   = tableOperations.QueryRecordWhere("Name = {0}", "contact.email");

                    int n = args.Count();

                    company.value = String.Join(" ", args.Take(n - 1));
                    email.value   = args[n - 1];

                    tableOperations.UpdateRecord(company);
                    tableOperations.UpdateRecord(email);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.InnerException.Message);
            }
        }
Exemple #2
0
        public PQdsEvent(int id)
        {
            string localAppData = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}{Path.DirectorySeparatorChar}PQio{Path.DirectorySeparatorChar}DataBase.db";

            connectionstring = $"Data Source={localAppData}; Version=3; Foreign Keys=True; FailIfMissing=True";


            if (id == -1)
            {
                //This means the GUID needs to be generated

                m_Event = new PQio.Model.Event()
                {
                    GUID = System.Guid.NewGuid().ToString()
                };
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider))
                {
                    GSF.Data.Model.TableOperations <PQio.Model.Event> evtTable = new GSF.Data.Model.TableOperations <PQio.Model.Event>(connection);
                    m_Event = evtTable.QueryRecordWhere("ID = {0}", id);
                }
            }


            InitializeComponent();
        }
Exemple #3
0
        public PQdsAsset(int id)
        {
            if (id == -1)
            {
                m_Asset = new PQds.Model.Asset();
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                {
                    GSF.Data.Model.TableOperations <PQds.Model.Asset> assetTable = new GSF.Data.Model.TableOperations <PQds.Model.Asset>(connection);
                    m_Asset = assetTable.QueryRecordWhere("ID = {0}", id);
                }
            }

            InitializeComponent();
        }
Exemple #4
0
        public PQdsDevice(int id)
        {
            if (id == -1)
            {
                m_device = new PQds.Model.Meter();
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                {
                    GSF.Data.Model.TableOperations <PQds.Model.Meter> deviceTable = new GSF.Data.Model.TableOperations <PQds.Model.Meter>(connection);
                    m_device  = deviceTable.QueryRecordWhere("ID = {0}", id);
                    this.Text = string.Format("PQds {0} MetaData", m_device.DeviceAlias);
                }
            }

            InitializeComponent();
        }
        public PQdsAsset(int id)
        {
            string localAppData = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}{Path.DirectorySeparatorChar}PQio{Path.DirectorySeparatorChar}DataBase.db";

            connectionstring = $"Data Source={localAppData}; Version=3; Foreign Keys=True; FailIfMissing=True";

            if (id == -1)
            {
                m_Asset = new PQio.Model.Asset();
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider))
                {
                    GSF.Data.Model.TableOperations <PQio.Model.Asset> assetTable = new GSF.Data.Model.TableOperations <PQio.Model.Asset>(connection);
                    m_Asset = assetTable.QueryRecordWhere("ID = {0}", id);
                }
            }

            InitializeComponent();
        }
Exemple #6
0
        public PQdsDevice(int id)
        {
            string localAppData = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}{Path.DirectorySeparatorChar}PQio{Path.DirectorySeparatorChar}DataBase.db";

            connectionstring = $"Data Source={localAppData}; Version=3; Foreign Keys=True; FailIfMissing=True";

            if (id == -1)
            {
                m_device = new PQio.Model.Meter();
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider))
                {
                    GSF.Data.Model.TableOperations <PQio.Model.Meter> deviceTable = new GSF.Data.Model.TableOperations <PQio.Model.Meter>(connection);
                    m_device  = deviceTable.QueryRecordWhere("ID = {0}", id);
                    this.Text = string.Format("PQds {0} MetaData", m_device.DeviceAlias);
                }
            }

            InitializeComponent();
        }
Exemple #7
0
        public PQdsEvent(int id)
        {
            if (id == -1)
            {
                //This means the GUID needs to be generated

                m_Event = new PQds.Model.Event()
                {
                    GUID = System.Guid.NewGuid().ToString()
                };
            }
            else
            {
                using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                {
                    GSF.Data.Model.TableOperations <PQds.Model.Event> evtTable = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection);
                    m_Event = evtTable.QueryRecordWhere("ID = {0}", id);
                }
            }


            InitializeComponent();
        }
Exemple #8
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 #9
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 #10
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 #11
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();
        }
Exemple #12
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();
        }