private void button2_Click(object sender, EventArgs e) { string localAppData = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}{Path.DirectorySeparatorChar}PQio{Path.DirectorySeparatorChar}DataBase.db"; string connectionstring = $"Data Source={localAppData}; Version=3; Foreign Keys=True; FailIfMissing=True"; using (AdoDataConnection connection = new AdoDataConnection(connectionstring, dataprovider)) { GSF.Data.Model.TableOperations <PQio.Model.CustomField> customFldTbl = new GSF.Data.Model.TableOperations <PQio.Model.CustomField>(connection); if (this.textBox1.Text.Length < 1) { MessageBox.Show("A Domain name has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (customFldTbl.QueryRecordCountWhere("domain = {0}", this.textBox1.Text) > 0) { MessageBox.Show("This domain already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { PQio.Model.CustomField fld = new Model.CustomField() { EventID = m_eventid, AssetID = m_assetid, key = "Key", Value = "Value", Type = "T", domain = this.textBox1.Text }; customFldTbl.AddNewRecord(fld); } } this.Close(); }
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(); } }