public void DeleteDevice(int id) { TableOperations <Device> deviceTable = DataContext.Table <Device>(); deviceTable.DeleteRecordWhere("ParentID = {0}", id); deviceTable.DeleteRecord(id); }
public void DeleteDevice(int id) { // TODO: Delete associated custom action adapters (generated by tag templates) TableOperations <Device> deviceTable = DataContext.Table <Device>(); deviceTable.DeleteRecordWhere("ParentID = {0}", id); deviceTable.DeleteRecord(id); }
public static void DeleteChildDeviceByIDCode(this Device[] devices, TableOperations <Device> deviceTable, int parentID, ushort idCode) { Device device = devices.FindChildDeviceByIDCode(parentID, idCode); if (device is not null) { deviceTable?.DeleteRecord(device); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (!m_formLoaded || m_formClosing) { return; } if (MessageBox.Show(this, $"Are you sure you want to delete {m_actionAdapters.Count(adapter => adapter.Enabled):N0} selected devices?", "Delete Devices", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } buttonDelete.Enabled = false; buttonDelete.Text = "Working..."; UseWaitCursor = true; ThreadPool.QueueUserWorkItem(_ => { try { SyncDataSource(); lock (m_actionAdapterTable) { foreach (CustomActionAdapter actionAdapter in m_actionAdapters) { if (actionAdapter.Enabled) { m_actionAdapterTable.DeleteRecord(actionAdapter); } } } ReloadConfig(); } catch (Exception ex) { BeginInvoke(new Action(() => MessageBox.Show(this, $"Error deleting calculations: {ex.Message}", "Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Error))); } finally { RefreshActionAdapters(); BeginInvoke(new Action(() => { UseWaitCursor = false; buttonDelete.Text = buttonDelete.Tag.ToString(); if (!m_reconnecting) { buttonDelete.Enabled = true; } })); } }); }
private void UpdateUserAccountAssetGroup(ConfirmableUserAccount userAccount, UpdateSettingModel formData) { using (DataContext dataContext = new DataContext("dbOpenXDA")) { // update link to asset group TableOperations <UserAccountAssetGroup> userAccountAssetGroupTable = dataContext.Table <UserAccountAssetGroup>(); IEnumerable <UserAccountAssetGroup> userAccountAssetGroups = userAccountAssetGroupTable.QueryRecordsWhere("UserAccountID = {0}", userAccount.ID); IEnumerable <int> assetGroups = userAccountAssetGroups.Select(x => x.AssetGroupID); // formData will come back as null instead of empty array .... if (formData.region == null) { formData.region = new List <int>(); } // First pass. Add Link in database if the link does not exist. foreach (int id in formData.region) { if (!assetGroups.Contains(id)) { UserAccountAssetGroup userAccountAssetGroup = new UserAccountAssetGroup(); userAccountAssetGroup.UserAccountID = userAccount.ID; userAccountAssetGroup.AssetGroupID = id; userAccountAssetGroup.Dashboard = true; userAccountAssetGroup.Email = true; userAccountAssetGroupTable.AddNewRecord(userAccountAssetGroup); } else { UserAccountAssetGroup userAccountAssetGroup = userAccountAssetGroups.Where(x => x.AssetGroupID == id).First(); if (!userAccountAssetGroup.Dashboard || !userAccountAssetGroup.Email) { userAccountAssetGroup.Dashboard = true; userAccountAssetGroup.Email = true; userAccountAssetGroupTable.UpdateRecord(userAccountAssetGroup); } } } userAccountAssetGroups = userAccountAssetGroupTable.QueryRecordsWhere("UserAccountID = {0}", userAccount.ID); // Second pass. Remove Link if the link does not exist in data from form. foreach (UserAccountAssetGroup link in userAccountAssetGroups) { if (!formData.region.Contains(link.AssetGroupID)) { userAccountAssetGroupTable.DeleteRecord(link); } } } }
public void DeleteMeasurement(long id) { long pointID = id; using (AdoDataConnection connection = CreateDbConnection()) { TableOperations <ImportedMeasurement> importedMeasurementTable = new TableOperations <ImportedMeasurement>(connection); RecordRestriction recordRestriction = new RecordRestriction("NodeID = {0}", NodeID) & new RecordRestriction("Source = {0}", Source) & new RecordRestriction("PointID = {0}", pointID); importedMeasurementTable.DeleteRecord(recordRestriction); } }
/// <summary> /// Save All changes. /// </summary> public void Save() { if (!Changed) { return; } if (m_removed) { m_analytics.ToList().ForEach(a => a.Save()); } using (AdoDataConnection connection = new AdoDataConnection(ConnectionString, DataProviderString)) { TableOperations <TemplateSection> templateTbl = new TableOperations <TemplateSection>(connection); if (m_section.ID <= 0 && !m_removed) { int templateId = new TableOperations <Template>(connection).QueryRecordWhere("Name = {0}", TemplateViewModel.Name).Id; templateTbl.AddNewRecord(new TemplateSection() { Name = m_section.Name, AnalyticTypeID = m_section.AnalyticTypeID, Order = m_section.Order, TemplateID = templateId }); } else if (!m_removed) { templateTbl.UpdateRecord(m_section); } else { templateTbl.DeleteRecord(m_section); } if (!m_removed) { m_analytics.ToList().ForEach(a => a.Save()); } } }