191 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			191 lines
		
	
	
		
			6.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.ComponentModel;
 | |
| using System.Data;
 | |
| using System.Drawing;
 | |
| using System.Linq;
 | |
| using System.Text;
 | |
| using System.Threading.Tasks;
 | |
| using System.Windows.Forms;
 | |
| using VEPROMS.CSLA.Library;
 | |
| using Volian.Base.Library;
 | |
| //using Volian.Pipe.Library;
 | |
| using System.Xml;
 | |
| using System.Diagnostics;
 | |
| using JR.Utils.GUI.Forms;
 | |
| 
 | |
| namespace VEPROMS
 | |
| {
 | |
| 	public partial class frmAnnotationsCleanup : Form
 | |
| 	{
 | |
| 		Label mylab = new Label();
 | |
| 		string procList = "";
 | |
| 		string docvList = "";
 | |
| 		int AnnotationTyp;
 | |
| 		string AnnotationName = "";
 | |
| 		string totalDeleteCnt = "";
 | |
| 		List<ProcedureInfo> pil2 = new List<ProcedureInfo>();
 | |
| 		List<DocVersionInfo> dvil2 = new List<DocVersionInfo>();
 | |
| 		private frmBatchRefresh mainForm = null;
 | |
| 		// frmAnnotationsCleanup constructor passes users procedure and docversion selections from frmBatchRefresh
 | |
| 		public frmAnnotationsCleanup(Form callingForm, List<ProcedureInfo> pil, List<DocVersionInfo> 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<string, string> AnnotationsList = new Dictionary<string, string>();
 | |
| 
 | |
| 				// Add name and type ID to form.
 | |
| 			foreach (LocalAnnotationTypeInfo lati in myLocalAnnotationTypeInfoList)
 | |
| 			{
 | |
| 				AnnotationsList.Add(lati.TypeID.ToString(), lati.Name);
 | |
| 				//cbAnnotationTypes.Items.Add(new { Name = lati.Name, Value = lati.TypeID });
 | |
| 			}
 | |
| 
 | |
| 			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<ProcedureInfo> pil2)
 | |
| 		{
 | |
| 			procList = "";
 | |
| 			foreach (var p in pil2)
 | |
| 			{
 | |
| 				if (p.IsProcedure)
 | |
| 				{
 | |
| 					if (procList == "")
 | |
| 					{
 | |
| 						procList = procList + p.ItemID.ToString();
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						procList = procList + "," + p.ItemID.ToString();
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			return procList;
 | |
| 		}
 | |
| 
 | |
| 			// create comma delimited string of doc versions selected by user.
 | |
| 		private string getAnnotationDocvItems(List<DocVersionInfo> dvil2)
 | |
| 		{
 | |
| 			docvList = "";
 | |
| 			foreach (var d in dvil2)
 | |
| 			{
 | |
| 				if (d.IsDocVersion)
 | |
| 				{
 | |
| 					if (docvList == "")
 | |
| 					{
 | |
| 						docvList = docvList + d.VersionID.ToString();
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						docvList = docvList + "," + d.VersionID.ToString();
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			return docvList;
 | |
| 		}
 | |
| 
 | |
| 		private AnnotationTypeInfoList myAnnotationTypeInfoList = null;
 | |
| 		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<string, string>)lbAnnotationTypes.SelectedItem).Key);
 | |
| 				AnnotationName = System.Convert.ToString(((KeyValuePair<string, string>)lbAnnotationTypes.SelectedItem).Value);
 | |
| 				frm3.AppendText("Deleting Annotations: Annotation Type: " + '"' + AnnotationName + '"');
 | |
| 				frm3.AppendText(Environment.NewLine + "P = Procedure, F = Folder" + Environment.NewLine);
 | |
| 				int deletecountProc = 0;
 | |
| 				int deletecountDocv = 0;
 | |
| 				foreach (var p in pil2)
 | |
| 				{
 | |
| 					if (p.IsProcedure)
 | |
| 					{
 | |
| 						//AnnotationTyp = System.Convert.ToInt32(((KeyValuePair<string, string>)lbAnnotationTypes.SelectedItem).Key);
 | |
| 						//AnnotationName = System.Convert.ToString(((KeyValuePair<string, string>)lbAnnotationTypes.SelectedItem).Value);
 | |
| 						//deletecountProc = Annotation.getAnnotationProcCnt(AnnotationTyp, getAnnotationProcItems(p));
 | |
| 						deletecountProc = Annotation.getAnnotationProcCnt(AnnotationTyp, p.ItemID.ToString());
 | |
| 						frm2.AppendText(Environment.NewLine + p.DisplayNumber + ' ' + p.DisplayText);
 | |
| 						//frm3.AppendText(Environment.NewLine + "P: " + p.DisplayNumber + '"' + p.DisplayText + '"' + " Type: " + '"' + AnnotationName + '"' + " count: " + deletecountProc);
 | |
| 						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)
 | |
| 					{
 | |
| 						//AnnotationTyp = System.Convert.ToInt32(((KeyValuePair<string, string>)lbAnnotationTypes.SelectedItem).Key);
 | |
| 						//AnnotationName = System.Convert.ToString(((KeyValuePair<string, string>)lbAnnotationTypes.SelectedItem).Value);
 | |
| 						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<string, string>)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<string, string>)lbAnnotationTypes.SelectedItem).Key);
 | |
| 					deletecountProc = Annotation.getAnnotationProcCnt(AnnotationTyp, getAnnotationProcItems(pil2));
 | |
| 				}
 | |
| 
 | |
| 				if (dvil2.Count > 0)
 | |
| 				{
 | |
| 					AnnotationTyp = System.Convert.ToInt32(((KeyValuePair<string, string>)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)
 | |
| 		{
 | |
| 			this.Close();
 | |
| 		}
 | |
| 
 | |
| 	}
 | |
| }
 | |
| 
 | |
| 
 |