code to support CPS Editor
This commit is contained in:
parent
9931c454f3
commit
b695681aba
@ -7,17 +7,143 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using Volian.Base.Library;
|
||||
using Volian.Pipe.Library;
|
||||
using System.Xml;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Volian.Controls.Library
|
||||
{
|
||||
public delegate void NewMessageDelegate(string NewMessage);
|
||||
public partial class AnnotationDetails : UserControl
|
||||
{
|
||||
private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||
#region Properties
|
||||
private bool _LoadingAnnotation = false;
|
||||
private bool _LoadingGrid = false;
|
||||
private XmlDocument _ProcList;
|
||||
private ItemInfo _ProcItem = null;
|
||||
public ItemInfo ProcItem
|
||||
{
|
||||
get { return _ProcItem; }
|
||||
set
|
||||
{
|
||||
if (_ProcItem == value) return;
|
||||
_ProcItem = value;
|
||||
CreateProcList();
|
||||
}
|
||||
}
|
||||
|
||||
private ItemInfo _CurrentItem = null;
|
||||
private void CreateProcList()
|
||||
{
|
||||
_ProcList = null;
|
||||
if (_ProcItem == null) return;
|
||||
_ProcList = new XmlDocument();
|
||||
_ProcList.LoadXml("<ProcSteps/>");
|
||||
AddItem(0,ProcItem);
|
||||
//Console.WriteLine(_ProcList.OuterXml);
|
||||
}
|
||||
private void AddItem(int parentID, ItemInfo myItemInfo)
|
||||
{
|
||||
if (myItemInfo.IsProcedure || myItemInfo.IsSection || myItemInfo.IsHigh ||
|
||||
myItemInfo.IsRNOPart || myItemInfo.IsSequential || myItemInfo.IsNote ||
|
||||
myItemInfo.IsCaution)
|
||||
{
|
||||
XmlElement xe = _ProcList.CreateElement(TypeName(myItemInfo));
|
||||
AddAttribute(xe, "ItemID", myItemInfo.ItemID);
|
||||
AddAttribute(xe, "ParentID", parentID);
|
||||
if (myItemInfo.IsProcedure || myItemInfo.IsSection)
|
||||
AddAttribute(xe, "Number", myItemInfo.DisplayNumber);
|
||||
else
|
||||
AddAttribute(xe, "Number", myItemInfo.MyTab.CleanText);
|
||||
AddAttribute(xe, "Text", myItemInfo.DisplayText);
|
||||
_ProcList.DocumentElement.AppendChild(xe);
|
||||
|
||||
if (myItemInfo.Cautions != null) foreach (StepInfo caui in myItemInfo.Cautions) AddItem(myItemInfo.ItemID, caui);
|
||||
if (myItemInfo.Notes != null) foreach (StepInfo noti in myItemInfo.Notes) AddItem(myItemInfo.ItemID, noti);
|
||||
if (myItemInfo.RNOs != null) foreach (StepInfo rnoi in myItemInfo.RNOs) AddItem(myItemInfo.ItemID, rnoi);
|
||||
if (myItemInfo.Sections != null) foreach (SectionInfo seci in myItemInfo.Sections) AddItem(myItemInfo.ItemID, seci);
|
||||
if (myItemInfo.Steps != null)
|
||||
{
|
||||
if(myItemInfo.IsSection || (myItemInfo.IsHigh && SubStepHasRNOs(myItemInfo.Steps)))
|
||||
foreach (StepInfo stpi in myItemInfo.Steps) AddItem(myItemInfo.ItemID, stpi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string TypeName(ItemInfo myItemInfo)
|
||||
{
|
||||
if (myItemInfo.IsProcedure) return "Procedure";
|
||||
if (myItemInfo.IsSection) return "Section";
|
||||
if (myItemInfo.IsHigh) return "Step";
|
||||
if (myItemInfo.IsRNOPart) return "RNO";
|
||||
if (myItemInfo.IsCaution) return "Caution";
|
||||
if (myItemInfo.IsNote) return "Note";
|
||||
return "Substep";
|
||||
}
|
||||
private bool SubStepHasRNOs(ItemInfoList substeps)
|
||||
{
|
||||
foreach (ItemInfo ii in substeps)
|
||||
if (ii.RNOs != null) return true;
|
||||
return false;
|
||||
}
|
||||
private ItemInfo _CurrentItem = null;
|
||||
public ItemInfo CurrentItem
|
||||
{
|
||||
get { return _CurrentItem; }
|
||||
set
|
||||
{
|
||||
_CurrentItem = value;
|
||||
SetupCurrentItemValues();
|
||||
SetupConfigEdit();
|
||||
if (_ExeType > 0) SendPromsAnnotationData();
|
||||
}
|
||||
}
|
||||
private int _FromType;
|
||||
private string _ROPath;
|
||||
private void SetupCurrentItemValues()
|
||||
{
|
||||
_FromType = 0;
|
||||
if (CurrentItem.FirstSibling.ItemPartCount > 0)
|
||||
_FromType = CurrentItem.FirstSibling.ItemParts[0].FromType;
|
||||
_ROPath = "";
|
||||
if (CurrentItem.MyDocVersion != null)
|
||||
if (CurrentItem.MyDocVersion.DocVersionAssociationCount > 0)
|
||||
_ROPath = CurrentItem.MyDocVersion.DocVersionAssociations[0].MyROFst.MyRODb.FolderPath;
|
||||
ProcItem = CurrentItem.MyProcedure;
|
||||
}
|
||||
public AnnotationInfo FirstExeAnnotation(ItemInfo ii)
|
||||
{
|
||||
if (ii == null) return null;
|
||||
if (ii.ItemAnnotationCount == 0) return null;
|
||||
foreach (AnnotationInfo ai in ii.ItemAnnotations)
|
||||
if (ai.TypeID == _ExeType) return ai;
|
||||
return null;
|
||||
}
|
||||
private void SetupConfigEdit()
|
||||
{
|
||||
if (_ExeType == 0)
|
||||
{
|
||||
_ExeType = -1;
|
||||
foreach (AnnotationTypeInfo ati in AnnotationTypeInfoList.Get())
|
||||
{
|
||||
if ((ati.Config ?? "") != "")
|
||||
{
|
||||
_ExePath = ati.AnnotationTypeConfig.Integration_Executable;
|
||||
_PipeIn = ati.AnnotationTypeConfig.Integration_PipeIn;
|
||||
_PipeOut = ati.AnnotationTypeConfig.Integration_PipeOut;
|
||||
if (_ExePath != "" && _PipeIn != "" && _PipeOut != "")
|
||||
{
|
||||
_ExeType = ati.TypeID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private string _ExePath;
|
||||
private string _PipeOut;
|
||||
private string _PipeIn;
|
||||
private int _ExeType=0;
|
||||
private DisplaySearch _AnnotationSearch;
|
||||
|
||||
private AnnotationInfoList _Annotations;
|
||||
@ -216,6 +342,8 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
_LoadingAnnotation = false;
|
||||
AnnotationDirty = false;
|
||||
if (!rtxbComment.Visible)
|
||||
rtxbComment.Visible = true;
|
||||
if (!_LoadingGrid)
|
||||
rtxbComment.Focus(); // Set the focus to the comment text
|
||||
if (CurrentAnnotation != null && MyUserInfo.IsReviewer(CurrentAnnotation.MyItem.MyDocVersion ) && CurrentAnnotation.UserID != MyUserInfo.UserID)
|
||||
@ -232,8 +360,171 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
private void CheckClientProcess()
|
||||
{
|
||||
if (ClientProcess.HasExited)
|
||||
{
|
||||
ClientProcess = null;
|
||||
StartClientProcess();
|
||||
}
|
||||
}
|
||||
void ClientProcess_Exited(object sender, EventArgs e)
|
||||
{
|
||||
ClientProcess = null;
|
||||
}
|
||||
private Process _ClientProcess;
|
||||
|
||||
public Process ClientProcess
|
||||
{
|
||||
get {
|
||||
if (_ClientProcess == null)
|
||||
{
|
||||
StartClientProcess();
|
||||
}
|
||||
return _ClientProcess;
|
||||
}
|
||||
set { _ClientProcess = value; }
|
||||
}
|
||||
|
||||
private void StartClientProcess()
|
||||
{
|
||||
_ClientProcess = Process.Start(_ExePath);
|
||||
_ClientProcess.WaitForInputIdle();
|
||||
_ClientProcess.Exited += ClientProcess_Exited;
|
||||
}
|
||||
private void SendPromsAnnotationData()
|
||||
{
|
||||
Console.WriteLine("Send {0}", CurrentItem);
|
||||
XmlDocument xdMessage = new XmlDocument();
|
||||
xdMessage.LoadXml("<PromsToClient Mode='AnnotationSetup'><PromsAnnotationConfig/></PromsToClient>");
|
||||
// Add Steps Data
|
||||
if(_ProcList != null)
|
||||
{
|
||||
xdMessage.DocumentElement.AppendChild(xdMessage.ImportNode(_ProcList.DocumentElement, true));
|
||||
_ProcList = null;
|
||||
}
|
||||
// Add Config Data
|
||||
AnnotationInfo ai = FirstExeAnnotation(CurrentItem);
|
||||
if (ai != null)
|
||||
{
|
||||
XmlDocument xdConfig = new XmlDocument();
|
||||
xdConfig.LoadXml(ai.Config);
|
||||
ProcedureInfo currentProc = CurrentItem.MyProcedure;
|
||||
XmlNode nd = xdMessage.DocumentElement.SelectSingleNode("//PromsAnnotationConfig");
|
||||
nd.AppendChild(xdMessage.ImportNode(xdConfig.DocumentElement, true));
|
||||
}
|
||||
// Add Local Info
|
||||
AddAttribute(xdMessage.DocumentElement, "ItemID", CurrentItem.ItemID);
|
||||
AddAttribute(xdMessage.DocumentElement, "ROPath", _ROPath);
|
||||
AddAttribute(xdMessage.DocumentElement, "FromType", _FromType);
|
||||
AddAttribute(xdMessage.DocumentElement, "Type", CurrentItem.MyContent.Type);
|
||||
PipeToClient.Send(xdMessage.OuterXml);
|
||||
PipeFromClient.Listen();
|
||||
}
|
||||
private void AddAttribute(XmlElement xe, string name, object value)
|
||||
{
|
||||
XmlAttribute xa = xe.OwnerDocument.CreateAttribute(name);
|
||||
xa.Value= value.ToString();
|
||||
xe.Attributes.Append(xa);
|
||||
}
|
||||
private PipeClient _PipeToClient;
|
||||
public PipeClient PipeToClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PipeToClient == null)
|
||||
_PipeToClient = new PipeClient(_PipeOut);
|
||||
return _PipeToClient;
|
||||
}
|
||||
}
|
||||
private PipeServer _PipeFromClient;
|
||||
public PipeServer PipeFromClient
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_PipeFromClient == null)
|
||||
{
|
||||
_PipeFromClient = new PipeServer(_PipeIn);
|
||||
_PipeFromClient.PipeMessage += PipesMessageHandler;
|
||||
}
|
||||
return _PipeFromClient;
|
||||
}
|
||||
}
|
||||
void PipesMessageHandler(string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new NewMessageDelegate(PipesMessageHandler), message);
|
||||
}
|
||||
else
|
||||
{
|
||||
ProcessMessage(message);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PipesMessageHandler(string.Format("{0} - {1}", ex.GetType().FullName, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private void ProcessMessage(string message)
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
XmlDocument xd = new XmlDocument();
|
||||
xd.LoadXml(message);
|
||||
string Mode = GetAttribute(xd, "ClientToProms", "Mode");
|
||||
switch (Mode)
|
||||
{
|
||||
case "SaveAnnotationConfig":
|
||||
// Get the AnnotationID
|
||||
int itemID = GetAttributeInt(xd,"ClientToProms","ItemID");
|
||||
// Get the Config
|
||||
string config = GetNode(xd,"PromsAnnotationConfig").InnerXml;
|
||||
// Save updated Config Value
|
||||
AnnotationInfo ai = FirstExeAnnotation(ItemInfo.Get(itemID));
|
||||
if(ai != null) // Update existing Annotation
|
||||
using(Annotation aa = Annotation.Get(ai.AnnotationID))
|
||||
{
|
||||
aa.Config=config;
|
||||
aa.DTS=DateTime.Now;
|
||||
aa.UserID = Volian.Base.Library.VlnSettings.UserID;
|
||||
aa.Save();
|
||||
AnnotationInfo.Refresh(aa);
|
||||
}
|
||||
else // Add a new Annotation
|
||||
{
|
||||
using(Item myItem = Item.Get(itemID ))
|
||||
{
|
||||
using (AnnotationType myType = AnnotationType.Get(_ExeType))
|
||||
{
|
||||
using (Annotation annotation = Annotation.MakeAnnotation(myItem, myType,null, "New",config))
|
||||
{
|
||||
annotation.Save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Unknown Message Type {0}", Mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
private XmlNode GetNode(XmlDocument xd, string nodeName)
|
||||
{
|
||||
return xd.DocumentElement.SelectSingleNode("//" + nodeName);
|
||||
}
|
||||
private string GetAttribute(XmlDocument xd, string nodeName, string attrName)
|
||||
{
|
||||
return GetNode(xd,nodeName).Attributes[attrName].Value;
|
||||
}
|
||||
private int GetAttributeInt(XmlDocument xd, string nodeName, string attrName)
|
||||
{
|
||||
return int.Parse(GetAttribute(xd, nodeName, attrName));
|
||||
}
|
||||
#endregion
|
||||
#region VariousSupportMethods
|
||||
|
||||
/// <summary>
|
||||
@ -243,7 +534,7 @@ namespace Volian.Controls.Library
|
||||
/// <param name="currentitem"></param>
|
||||
public void UpdateAnnotationGrid(ItemInfo currentitem)
|
||||
{
|
||||
_CurrentItem = currentitem;
|
||||
CurrentItem = currentitem;
|
||||
UpdateAnnotationGrid();
|
||||
}
|
||||
|
||||
@ -251,16 +542,16 @@ namespace Volian.Controls.Library
|
||||
{
|
||||
_LoadingGrid = true;
|
||||
|
||||
if (_CurrentItem == null)
|
||||
if (CurrentItem == null)
|
||||
_Annotations= null;
|
||||
else
|
||||
{
|
||||
_CurrentItem.RefreshItemAnnotations();
|
||||
_Annotations = _CurrentItem.ItemAnnotations;
|
||||
CurrentItem.RefreshItemAnnotations();
|
||||
_Annotations = CurrentItem.ItemAnnotations;
|
||||
}
|
||||
itemAnnotationsBindingSource.DataSource = _Annotations;
|
||||
dgAnnotations.Refresh();
|
||||
if ((CurrentAnnotation == null || (_CurrentItem.ItemID != CurrentAnnotation.ItemID)))
|
||||
if ((CurrentAnnotation == null || (CurrentItem.ItemID != CurrentAnnotation.ItemID)))
|
||||
{
|
||||
if (_Annotations != null && _Annotations.Count > 0)
|
||||
CurrentAnnotation = _Annotations[0];
|
||||
@ -314,7 +605,7 @@ namespace Volian.Controls.Library
|
||||
if (_AddingAnnotation)
|
||||
{
|
||||
_AddingAnnotation = false;
|
||||
using (Item myItem = _CurrentItem.Get())
|
||||
using (Item myItem = CurrentItem.Get())
|
||||
{
|
||||
using (Annotation annotation = Annotation.MakeAnnotation(myItem, annotationType, rtxbComment.Rtf, rtxbComment.Text, ""))
|
||||
{
|
||||
@ -342,10 +633,5 @@ namespace Volian.Controls.Library
|
||||
}
|
||||
#endregion
|
||||
|
||||
//private void AnnotationDetails_Resize(object sender, EventArgs e)
|
||||
//{
|
||||
// vlnStackTrace.ShowStackLocal(string.Format("Resize - Height = {0}", Height), 3, 4);
|
||||
// //vlnStackTrace.ShowStack(string.Format("Resize - Height = {0}", Height));
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user