private void save_Click(object sender, EventArgs e) { if (Model.SignalType.ToValue((string)comboBox1.SelectedItem) != -1) { this.m_channel.SignalType = Model.SignalType.ToValue((string)comboBox1.SelectedItem); } else { this.m_channel.SignalType = null; } if (Model.MeasurementType.ToValue((string)comboBox2.SelectedItem) != "") { this.m_channel.MeasurementType = Model.MeasurementType.ToValue((string)comboBox2.SelectedItem); } else { this.m_channel.MeasurementType = ""; } this.m_channel.MeterID = (comboDevice.SelectedItem as dynamic).Value; using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider)) { (new GSF.Data.Model.TableOperations <PQio.Model.Channel>(connection)).UpdateRecord(this.m_channel); GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity> dataSensitivityTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity>(connection); PQio.Model.DataSensitivity dataSensitivity; if (this.m_channel.AssetID != null) { if (dataSensitivityTbl.QueryRecordCountWhere("Event = {0} AND Asset = {1}", this.m_evt.ID, this.m_channel.AssetID) > 0) { dataSensitivity = dataSensitivityTbl.QueryRecordsWhere("Event = {0} AND Asset = {1}", this.m_evt.ID, this.m_channel.AssetID).First(); } else { dataSensitivity = new Model.DataSensitivity() { Event = this.m_evt.ID, Asset = (int)this.m_channel.AssetID } }; dataSensitivity.DataSensitivityCode = Model.DataSensitivityCode.ToValue((string)comboBox3.SelectedItem); dataSensitivity.Note = DataSensitivityNoteText.Text; dataSensitivityTbl.AddNewOrUpdateRecord(dataSensitivity); } } this.Close(); }
private void PQioPQDSexp_Load(object sender, EventArgs e) { //Load All Assets using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.Asset> assetTable = new GSF.Data.Model.TableOperations <PQds.Model.Asset>(connection); List <PQds.Model.Asset> assets = assetTable.QueryRecordsWhere("(SELECT COUNT(DataSeries.ID) FROM DataSeries LEFT OUTER JOIN Channel ON Channel.ID = DataSeries.ChannelID WHERE Channel.AssetID = Asset.ID) > 0 ").ToList(); this.chLstBoxAsset.Items.Clear(); this.chLstBoxAsset.Items.AddRange(assets.ToArray()); } UpdateEvents(); }
private void MetaData_Load(object sender, EventArgs e) { DataSensitivityCombo.Items.AddRange(Model.DataSensitivityCode.DisplayOptions()); using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.DataSensitivity> dataSensitivityTable = new GSF.Data.Model.TableOperations <PQds.Model.DataSensitivity>(connection); if (PQds.Model.DataSensitivity.CodeisGlobal()) { int?dataSensitivity = null; dataSensitivity = dataSensitivityTable.QueryRecords().First().DataSensitivityCode; if (dataSensitivity != null) { DataSensitivityCombo.SelectedIndex = Array.FindIndex(Model.DataSensitivityCode.DisplayOptions(), item => item == Model.DataSensitivityCode.ToDisplay((int)dataSensitivity)); } else { DataSensitivityCombo.SelectedIndex = Array.FindIndex(Model.DataSensitivityCode.DisplayOptions(), item => item == Model.DataSensitivityCode.ToDisplay(-1)); } } else { DataSensitivityCombo.Enabled = false; } if (PQds.Model.DataSensitivity.NoteisGlobal()) { string dataSensitivityNote = null; dataSensitivityNote = dataSensitivityTable.QueryRecordsWhere("Note <> ''").First().Note; DataSensitivityNoteText.Text = dataSensitivityNote; } else { DataSensitivityNoteText.Enabled = false; } } this.MouseDown += new MouseEventHandler(OnClick); }
private void UpdateEvents() { this.chLstBoxEvt.Items.Clear(); 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.Event> evtTable = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection); string sqlQuerry = "((SELECT COUNT(DataSeries.ID) FROM DataSeries WHERE DataSeries.EventID = Event.ID) > 0) " + "AND ({0} IN " + "(SELECT Channel.AssetID FROM Channel LEFT JOIN DataSeries ON Channel.ID = DataSeries.ChannelID " + "WHERE DataSeries.EventID = Event.ID )) "; foreach (int i in selectedAssetIDs) { this.chLstBoxEvt.Items.AddRange(evtTable.QueryRecordsWhere(sqlQuerry, i).ToArray()); } } }
private void GenereateDataSensitivities(string note, int code) { // If we overwrite we need to create a set of Asset and event IDs that need to create a Data Sesitivity Code List <Tuple <int, int> > combinations = new List <Tuple <int, int> >(); using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider)) { GSF.Data.Model.TableOperations <PQio.Model.Channel> channelTbl = new GSF.Data.Model.TableOperations <PQio.Model.Channel>(connection); GSF.Data.Model.TableOperations <PQio.Model.Asset> assetTbl = new GSF.Data.Model.TableOperations <PQio.Model.Asset>(connection); GSF.Data.Model.TableOperations <PQio.Model.DataSeries> seriesTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSeries>(connection); GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity> sensitivityTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity>(connection); foreach (int assetID in assetTbl.QueryRecords().Select(item => item.ID)) { foreach (int channelID in channelTbl.QueryRecordsWhere("AssetID = {0}", assetID).Select(item => item.ID)) { foreach (int evtID in seriesTbl.QueryRecordsWhere("ChannelID = {0}", channelID).Select(item => item.EventID)) { combinations.Add(new Tuple <int, int>(assetID, evtID)); } } } combinations = combinations.Distinct().ToList(); foreach (Tuple <int, int> item in combinations) { if (sensitivityTbl.QueryRecordCountWhere("Event = {0} AND Asset = {1}", item.Item2, item.Item1) == 0) { sensitivityTbl.AddNewRecord(new Model.DataSensitivity() { Asset = item.Item1, Event = item.Item2, DataSensitivityCode = code, Note = note }); } } } }
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(connectionstring, dataprovider)) { GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity> dataSensitivityTbl = new GSF.Data.Model.TableOperations <PQio.Model.DataSensitivity>(connection); GSF.Data.Model.TableOperations <PQio.Model.Meter> deviceTbl = new GSF.Data.Model.TableOperations <PQio.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) { PQio.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)); tabControl1.Enabled = false; } comboDevice.DisplayMember = "Text"; comboDevice.ValueMember = "Value"; PQio.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); }
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; }
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(); }