using System; using System.Collections.Generic; using System.Windows.Forms; using VEPROMS.CSLA.Library; namespace VEPROMS { public partial class frmAnnotationsCleanup : Form { string procList = ""; string docvList = ""; int AnnotationTyp; string AnnotationName = ""; string totalDeleteCnt = ""; [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] List pil2 = new List(); [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] List dvil2 = new List(); private readonly frmBatchRefresh mainForm = null; // frmAnnotationsCleanup constructor passes users procedure and docversion selections from frmBatchRefresh public frmAnnotationsCleanup(Form callingForm, List pil, List dvil) { // Set up link back to parent form. mainForm = callingForm as frmBatchRefresh; InitializeComponent(); pil2 = pil; dvil2 = dvil; // Get list of annotation types for plant. myAnnotationTypeInfoList = AnnotationTypeInfoList.Get(); lbAnnotationTypes.DataSource = myLocalAnnotationTypeInfoList = new LocalAnnotationTypeInfoList(myAnnotationTypeInfoList); Dictionary AnnotationsList = new Dictionary(); // Add name and type ID to form. foreach (LocalAnnotationTypeInfo lati in myLocalAnnotationTypeInfoList) { AnnotationsList.Add(lati.TypeID.ToString(), lati.Name); } lbAnnotationTypes.DataSource = new BindingSource(AnnotationsList, null); lbAnnotationTypes.DisplayMember = "Value"; lbAnnotationTypes.ValueMember = "Key"; lbAnnotationTypes.SelectedIndexChanged += lbAnnotationTypes_SelectedIndexChanged; lbAnnotationTypes.ClearSelected(); } // create comma delimited string of procedures selected by user. private string getAnnotationProcItems(List pil2) { procList = ""; foreach (var p in pil2) { if (p.IsProcedure) { if (procList == "") { procList += p.ItemID.ToString(); } else { procList = $"{procList},{p.ItemID}"; } } } return procList; } // create comma delimited string of doc versions selected by user. private string getAnnotationDocvItems(List dvil2) { docvList = ""; foreach (var d in dvil2) { if (d.IsDocVersion) { if (docvList == "") { docvList += d.VersionID.ToString(); } else { docvList = $"{docvList},{d.VersionID}"; } } } return docvList; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private AnnotationTypeInfoList myAnnotationTypeInfoList = null; [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")] private LocalAnnotationTypeInfoList myLocalAnnotationTypeInfoList = null; // Process used to cleanup annotations "(Proceed?" button) private void button1_Click(object sender, EventArgs e) { if (lbAnnotationTypes.SelectedIndex > -1) { TextBox frm2 = mainForm.GettxtProcess(); TextBox frm3 = mainForm.GettxtResults(); AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); AnnotationName = System.Convert.ToString(((KeyValuePair)lbAnnotationTypes.SelectedItem).Value); frm3.AppendText($"Deleting Annotations: Annotation Type: \"{AnnotationName}\""); frm3.AppendText($"{Environment.NewLine}P = Procedure, F = Folder{Environment.NewLine}"); foreach (var p in pil2) { if (p.IsProcedure) { int deletecountProc = Annotation.getAnnotationProcCnt(AnnotationTyp, p.ItemID.ToString()); frm2.AppendText($"{Environment.NewLine}{p.DisplayNumber} {p.DisplayText}"); frm3.AppendText($"{Environment.NewLine}P: {p.DisplayNumber}\"{p.DisplayText}\" Delete count: {deletecountProc}"); Annotation.DeleteAnnotationProcByType(AnnotationTyp, p.ItemID.ToString()); lblCountNumber.Text = "0"; } } foreach (var d in dvil2) { if (d.IsDocVersion) { int deletecountDocv = Annotation.getAnnotationCountDocv(AnnotationTyp, d.VersionID.ToString()); frm2.AppendText(Environment.NewLine + d.ActiveParent.ToString()); frm3.AppendText($"{Environment.NewLine}F: \"{d.ActiveParent.ToString()}\" Delete count: {deletecountDocv}"); AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); Annotation.DeleteAnnotationDocvByType(AnnotationTyp, d.VersionID.ToString()); lblCountNumber.Text = "0"; } } frm3.AppendText($"{Environment.NewLine}{Environment.NewLine}Total Annotations Deleted: {totalDeleteCnt}{Environment.NewLine}{Environment.NewLine}"); } } // Retrieve number of annotations that will be deleted. private void lbAnnotationTypes_SelectedIndexChanged(object sender, EventArgs e) { if (lbAnnotationTypes.SelectedIndex > -1) { btnClean.Enabled = false; lblCountNumber.Text = ""; int deletecountProc = 0; int deletecountDocv = 0; if (pil2.Count > 0) { AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); deletecountProc = Annotation.getAnnotationProcCnt(AnnotationTyp, getAnnotationProcItems(pil2)); } if (dvil2.Count > 0) { AnnotationTyp = System.Convert.ToInt32(((KeyValuePair)lbAnnotationTypes.SelectedItem).Key); deletecountDocv = Annotation.getAnnotationCountDocv(AnnotationTyp, getAnnotationDocvItems(dvil2)); } lblCountNumber.Text = (deletecountProc + deletecountDocv).ToString(); totalDeleteCnt = (deletecountProc + deletecountDocv).ToString(); btnClean.Enabled = true; } } // Close form. private void btnClose_Click(object sender, EventArgs e) => Close(); } }