private void OnRuleAddClick(object sender, EventArgs e) { ListViewItem item = null; List <String> doNotIncludeList = selectedRuleListView.ListView.Items.Cast <ListViewItem>().Select(i => i.Text).ToList(); frmSelectRule frmSelectRuleSet = new frmSelectRule(doNotIncludeList); if (frmSelectRuleSet.ShowDialog() == System.Windows.Forms.DialogResult.OK) { item = new ListViewItem(frmSelectRuleSet.SelectedRule.Name); item.Tag = frmSelectRuleSet.SelectedRule; } if (item == null) { return; } int priority = selectedRuleListView.ListView.Items.Count + 1; item.SubItems.Add(priority.ToString()); selectedRuleListView.ListView.Items.Add(item); SreDataSourceProperty.KeepVersion(this.DataSource.Id); IdpeRuleDataSource idpeRuleDataSource = new IdpeRuleDataSource(); idpeRuleDataSource.DataSourceId = DataSource.Id; idpeRuleDataSource.RuleId = frmSelectRuleSet.SelectedRule.Id; idpeRuleDataSource.Priority = priority; idpeRuleDataSource.RuleSetType = (int)selectedRuleSetType; new DataManager.Manager().Save(idpeRuleDataSource); }
private void DisassociateRuleFromDatabase(ListView listView, bool deleteRule) { SreDataSourceProperty.KeepVersion(this.DataSource.Id); IdpeRule rule = (IdpeRule)listView.SelectedItems[0].Tag; new Manager().DeleteRuleFromDataSource(DataSource.Id, rule.Id, selectedRuleSetType, deleteRule); listView.Items.Remove(listView.SelectedItems[0]); Bind(); }
public void DisassociateAttributeFromDataSource(ListViewControl sreListView1, bool isSystemDataSource = false) { int dataSourceId = isSystemDataSource ? (int)SelectedDataSource.SystemDataSourceId : SelectedDataSource.Id; bool saved = false; Manager manager = new Manager(); SreDataSourceProperty.KeepVersion(dataSourceId); if (sreListView1.ListView.SelectedItems.Count > 0) { if ((sreListView1.ListView.SelectedItems.Count == 1) && (sreListView1.ListView.SelectedItems[0].Text != "IsValid")) { if (MessageBox.Show(string.Format("You are about to disassociate {0} from {1}. Are you sure?", sreListView1.ListView.SelectedItems[0].Text, SelectedDataSource.Name), "Disassociate Attribute", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { return; } if (manager.DisassociateAttributeFromDataSource(dataSourceId, (sreListView1.ListView.SelectedItems[0].Tag as IdpeAttribute).AttributeId) == true) { sreListView1.ListView.Items.Remove(sreListView1.ListView.SelectedItems[0]); saved = true; } } else { foreach (ListViewItem selectedItem in sreListView1.ListView.SelectedItems) { if (selectedItem.Text != "IsValid") { if (manager.DisassociateAttributeFromDataSource(dataSourceId, (selectedItem.Tag as IdpeAttribute).AttributeId) == true) { sreListView1.ListView.Items.Remove(sreListView1.ListView.SelectedItems[0]); } saved = true; } } } } if (saved) { SaveAssociations(sreListView1.ListView, isSystemDataSource, false); } if (ServiceCommunicator.ClearDataSource(SelectedDataSource.Id, string.Empty)) { SetToolStripStatusLabel("Ready"); } else { SetToolStripStatusLabel("Failed to clear cache", true); } }
private void tsbSave_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; switch (tabControl1.SelectedIndex) { case 2: SreDataSourceProperty.KeepVersion(this.DataSource.Id); this.idpeKeys1.Save(); break; case 3: SreDataSourceProperty.KeepVersion(this.DataSource.Id); this.sreEmails1.Save(); break; case 4: SreDataSourceProperty.KeepVersion(this.DataSource.Id); this.sreDatabases1.Save(); break; } if (propertyGrid.SelectedObject is SreAttributeProperty) { SreAttributeProperty aProp = propertyGrid.SelectedObject as SreAttributeProperty; if ((aProp != null) && (aProp.HasChanged == true)) { MainWindow.SetToolStripStatusLabel("Please wait...Saving..."); Application.DoEvents(); aProp.Save(); aProp.HasChanged = false; errorProvider1.Clear(); DockPanelGlobalAttributes.RefreshData(aProp.Attribute.AttributeId); } } else if (propertyGrid.SelectedObject is SreDataSourceProperty) { SreDataSourceProperty dsProp = propertyGrid.SelectedObject as SreDataSourceProperty; if ((dsProp != null) && (dsProp.HasChanged == true)) { string errorMsg = errorProvider1.GetError(picIcon); if ((errorMsg.StartsWith("Property has been changed, will be auto saved")) || (string.IsNullOrEmpty(errorProvider1.GetError(picIcon)))) { MainWindow.SetToolStripStatusLabel("Please wait...Saving..."); Application.DoEvents(); dsProp.Save(); dsProp.HasChanged = false; errorProvider1.Clear(); DockPanelDataSources.RefreshData(dsProp.DataSource.Id); } } } tsbClearCache_Click(sender, e); }
void SaveAssociations(ListView listView, bool isSystemDataSource = false, bool takeCareOfOldVersion = true) { int dataSourceId = isSystemDataSource ? (int)SelectedDataSource.SystemDataSourceId : SelectedDataSource.Id; Manager manager = new Manager(); if (takeCareOfOldVersion) { SreDataSourceProperty.KeepVersion(dataSourceId); } int position = 1; foreach (ListViewItem item in listView.Items) { IdpeAttribute attribute = item.Tag as IdpeAttribute; if (attribute.Name == "IsValid") { continue; } IdpeAttributeDataSource sds = new IdpeAttributeDataSource(); sds.DataSourceId = dataSourceId; sds.IsAcceptable = (bool)attribute.IsAcceptable; sds.AttributeId = attribute.AttributeId; sds.AttributePrintValueType = attribute.AttributePrintValueType; sds.AttributePrintValueCustom = attribute.AttributePrintValueCustom; sds.Position = position; toolStripStatusLabel1.Text = "Please wait...Saving..." + attribute.Name; Application.DoEvents(); try { manager.Save(sds); } catch { MessageBox.Show(string.Format("{0} could not be loaded!", attribute.Name), "Attribute Skipped", MessageBoxButtons.OK, MessageBoxIcon.Information); } position++; } }
void SaveAssociations(ListView listView, bool isSystem) { Manager manager = new Manager(); SreDataSourceProperty.KeepVersion(isSystem ? (int)SelectedDataSource.SystemDataSourceId: SelectedDataSource.Id); int position = 1; foreach (ListViewItem item in listView.Items) { IdpeAttribute attribute = item.Tag as IdpeAttribute; IdpeAttributeDataSource sds = new IdpeAttributeDataSource(); sds.DataSourceId = isSystem ? (int)SelectedDataSource.SystemDataSourceId : SelectedDataSource.Id; sds.AttributeId = attribute.AttributeId; if (isSystem == false) { sds.IsAcceptable = true; } else { sds.IsAcceptable = (bool)attribute.IsAcceptable; } sds.AttributePrintValueType = attribute.AttributePrintValueType; sds.AttributePrintValueCustom = attribute.AttributePrintValueCustom; sds.Position = position; manager.Save(sds); position++; } if (!isSystem) { DockPanelDataSourceAttributes.DataSourceId = SelectedDataSource.Id; } else { DockPanelDataSourceSystemAttributes.SystemDataSourceId = (int)SelectedDataSource.SystemDataSourceId; } }