404 lines
16 KiB
C#
404 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
|
|
namespace VEPROMS
|
|
{
|
|
public partial class frmBatchRefresh : Form
|
|
{
|
|
private SessionInfo _MySessionInfo;
|
|
public SessionInfo MySessionInfo
|
|
{
|
|
get { return _MySessionInfo; }
|
|
set { _MySessionInfo = value; }
|
|
}
|
|
public frmBatchRefresh()
|
|
{
|
|
InitializeComponent();
|
|
SetUpBalloons();
|
|
}
|
|
|
|
private void SetUpBalloons()
|
|
{
|
|
btBatch.SetBalloonCaption(rbTransition, "Transitions Only Guidance");
|
|
btBatch.SetBalloonText(rbTransition, "Occasionally, transitions do not get updated." + Environment.NewLine + Environment.NewLine + "This function will refresh transitions in all procedures selected below whether they were selected individually or as a group via a procedure set.");
|
|
btBatch.SetBalloonCaption(rbRefObj, "Referenced Objects Only Guidance");
|
|
btBatch.SetBalloonText(rbRefObj, "Occasionally, referenced objects do not get updated. One cause of this is a failure to allow the RO update to complete." + Environment.NewLine + Environment.NewLine + "This function will refresh referenced objects (based on the current ROFst) in all procedures selected below whether they were selected individually or as a group via a procedure set.");
|
|
btBatch.SetBalloonCaption(rbBoth, "Transitions and Referenced Objects Guidance");
|
|
btBatch.SetBalloonText(rbBoth, "Occasionally, transitions and referenced objects do not get updated." + Environment.NewLine + Environment.NewLine + "This function will refresh transitions and referenced objects (based on the current ROFst) in all procedures selected below whether they were selected individually or as a group via a procedure set.");
|
|
btBatch.SetBalloonCaption(rbNow, "Process Now Guidance");
|
|
btBatch.SetBalloonText(rbNow, "When the button below is pressed the process option selected (as indicated the the title of the button below) will be performed immediately. If during the process a procedure selected to be processed is checked out to a user, you will be notified." + Environment.NewLine + Environment.NewLine + "You will then be given the option of terminating the process without processing the procedures checked out or contacting the appropriate users to check in the procedures and then continue the process to completion.");
|
|
btBatch.SetBalloonCaption(rbLater, "Process Later Guidance");
|
|
btBatch.SetBalloonText(rbLater, "NOTE: It is highly recommended that this function be used on off hours" + Environment.NewLine + Environment.NewLine + "When the button below is pressed the process option selected (as indicated the the title of the button below) will be performed when the date and time set has arrived." + Environment.NewLine + Environment.NewLine + "If during the process a procedure selected to be processed is checked out to a user, the procedures will be forced checked in and the process will be allowed to complete.");
|
|
}
|
|
//private DocVersionInfoList myDVIL;
|
|
private Dictionary<TreeNode, ProcedureInfo> myProcedures = new Dictionary<TreeNode, ProcedureInfo>();
|
|
private void frmBatchRefresh_Load(object sender, EventArgs e)
|
|
{
|
|
Options_Changed(rbTransition, e);
|
|
ResetTV();
|
|
}
|
|
private void ResetTV()
|
|
{
|
|
myTV.Nodes.Clear();
|
|
FolderInfo fi = FolderInfo.GetTop();
|
|
TreeNode tn = myTV.Nodes.Add(fi.Name);
|
|
tn.Tag = fi;
|
|
if (fi.ChildFolderCount > 0)
|
|
LoadChildFolders(fi, tn);
|
|
if (myTV.SelectedNode != null)
|
|
myTV.SelectedNode.Expand();
|
|
}
|
|
private void LoadChildFolders(FolderInfo fi, TreeNode tn)
|
|
{
|
|
foreach (FolderInfo fic in fi.ChildFolders)
|
|
{
|
|
TreeNode tnc = tn.Nodes.Add(fic.Name);
|
|
tnc.Tag = fic;
|
|
if (fic.ChildFolderCount > 0)
|
|
LoadChildFolders(fic, tnc);
|
|
if (fic.FolderDocVersionCount > 0)
|
|
LoadDocVersions(fic, tnc);
|
|
}
|
|
}
|
|
private void LoadDocVersions(FolderInfo fic, TreeNode tnc)
|
|
{
|
|
foreach (DocVersionInfo dvi in fic.FolderDocVersions)
|
|
{
|
|
tnc.Tag = dvi;
|
|
|
|
if (dvi.Procedures.Count > 0)
|
|
LoadProcedures(dvi, tnc);
|
|
}
|
|
}
|
|
private void LoadProcedures(DocVersionInfo dvi, TreeNode tnc)
|
|
{
|
|
foreach (ProcedureInfo pi in dvi.Procedures)
|
|
{
|
|
TreeNode tn = tnc.Nodes.Add(string.Format("{0} {1}", pi.DisplayNumber, pi.DisplayText));
|
|
myProcedures.Add(tn, pi);
|
|
tn.Tag = pi;
|
|
}
|
|
}
|
|
private void LoadFolderInfo(FolderInfo f)
|
|
{
|
|
TreeNode tn = myTV.Nodes.Add(f.Name);
|
|
tn.Tag = f;
|
|
if (f.ChildFolderCount > 0)
|
|
foreach (FolderInfo cf in f.ChildFolders)
|
|
LoadFolderInfo(cf);
|
|
}
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
this.Cursor = Cursors.WaitCursor;
|
|
if (rbNow.Checked)
|
|
{
|
|
#region now
|
|
List<ProcedureInfo> pil = new List<ProcedureInfo>();
|
|
foreach (TreeNode tn in myProcedures.Keys)
|
|
if (tn.Checked)
|
|
pil.Add(myProcedures[tn]);
|
|
PopulateTransitionInfoLists(pil);
|
|
DateTime pStart = DateTime.Now;
|
|
txtProcess.AppendText(pStart.ToString("MM/dd/yyyy @ HH:mm"));
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
Application.DoEvents();
|
|
pbProcess.Minimum = 0;
|
|
pbProcess.Maximum = pil.Count;
|
|
pbProcess.Step = 1;
|
|
while (pil.Count > 0)
|
|
{
|
|
ContentInfo.StaticContentInfoChange += new StaticContentInfoEvent(ContentInfo_StaticContentInfoChange);
|
|
StringBuilder sbProcs = new StringBuilder();
|
|
Queue<ProcedureInfo> piq = new Queue<ProcedureInfo>();
|
|
foreach (ProcedureInfo pi in pil)
|
|
piq.Enqueue(pi);
|
|
pil.Clear();
|
|
while (piq.Count > 0)
|
|
{
|
|
string msg = string.Empty;
|
|
ProcedureInfo pq = piq.Dequeue();
|
|
if (!MySessionInfo.CanCheckOutItem(pq.ItemID, CheckOutType.Procedure, ref msg))
|
|
{
|
|
pil.Add(pq);
|
|
sbProcs.AppendLine(msg);
|
|
}
|
|
else
|
|
{
|
|
if (rbTransition.Checked)
|
|
{
|
|
RefreshProcedureTransitions(pq);
|
|
}
|
|
else if (rbRefObj.Checked)
|
|
{
|
|
RefreshProcedureReferencedObjects(pq);
|
|
}
|
|
else
|
|
{
|
|
RefreshProcedureTransitions(pq);
|
|
RefreshProcedureReferencedObjects(pq);
|
|
}
|
|
pbProcess.PerformStep();
|
|
Application.DoEvents();
|
|
}
|
|
}
|
|
ContentInfo.StaticContentInfoChange -= new StaticContentInfoEvent(ContentInfo_StaticContentInfoChange);
|
|
DateTime pEnd = DateTime.Now;
|
|
txtProcess.AppendText(pEnd.ToString("mm/dd/yyyy @ HH:mm"));
|
|
Application.DoEvents();
|
|
if (pil.Count > 0)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("The batch refresh process was not usccessful for all procedures selected.");
|
|
sb.AppendLine("The following procedures were not able to be refreshed...");
|
|
sb.AppendLine();
|
|
sb.AppendLine(sbProcs.ToString());
|
|
sb.AppendLine();
|
|
sb.AppendLine("If you want to refresh these prcoedures, please contact the respective users and have them close the procedures.");
|
|
sb.AppendLine("Once this is complete you can continue the process otherwise you may terminate the process immediately.");
|
|
sb.AppendLine();
|
|
sb.AppendLine("Have you requested the users to close the procedures and do you want to continue the process?");
|
|
frmBatchRefreshCheckedOut frmCO = new frmBatchRefreshCheckedOut();
|
|
frmCO.MySessionInfo = MySessionInfo;
|
|
frmCO.CheckedOutProcedures = pil;
|
|
frmCO.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - frmCO.Width, Screen.PrimaryScreen.WorkingArea.Height - frmCO.Height);
|
|
frmCO.Show(this);
|
|
while (!this.Visible)
|
|
Application.DoEvents();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
else
|
|
{
|
|
#region later
|
|
long later = long.Parse(dtpDate.Value.ToString("yyyyMMdd") + dtpTime.Value.ToString("HHmm"));
|
|
long now = long.Parse(DateTime.Now.ToString("yyyyMMddHHmm"));
|
|
while (now < later)
|
|
{
|
|
txtProcess.Clear();
|
|
txtProcess.AppendText("Waiting...");
|
|
System.Threading.Thread.Sleep(60000);
|
|
now = long.Parse(DateTime.Now.ToString("yyyyMMddHHmm"));
|
|
}
|
|
List<ProcedureInfo> pil = new List<ProcedureInfo>();
|
|
foreach (TreeNode tn in myProcedures.Keys)
|
|
if (tn.Checked)
|
|
pil.Add(myProcedures[tn]);
|
|
DateTime pStart = DateTime.Now;
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
txtProcess.AppendText(pStart.ToString("mm/dd/yyyy @ HH:mm"));
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
Application.DoEvents();
|
|
pbProcess.Minimum = 0;
|
|
pbProcess.Maximum = pil.Count;
|
|
pbProcess.Step = 1;
|
|
while (pil.Count > 0)
|
|
{
|
|
ContentInfo.StaticContentInfoChange += new StaticContentInfoEvent(ContentInfo_StaticContentInfoChange);
|
|
StringBuilder sbProcs = new StringBuilder();
|
|
Queue<ProcedureInfo> piq = new Queue<ProcedureInfo>();
|
|
foreach (ProcedureInfo pi in pil)
|
|
piq.Enqueue(pi);
|
|
pil.Clear();
|
|
while (piq.Count > 0)
|
|
{
|
|
string msg = string.Empty;
|
|
ProcedureInfo pq = piq.Dequeue();
|
|
if (!MySessionInfo.CanCheckOutItem(pq.ItemID, CheckOutType.Procedure, ref msg))
|
|
{
|
|
pil.Add(pq);
|
|
sbProcs.AppendLine(msg);
|
|
}
|
|
else
|
|
{
|
|
if (rbTransition.Checked)
|
|
{
|
|
RefreshProcedureTransitions(pq);
|
|
}
|
|
else if (rbRefObj.Checked)
|
|
{
|
|
RefreshProcedureReferencedObjects(pq);
|
|
}
|
|
else
|
|
{
|
|
RefreshProcedureTransitions(pq);
|
|
RefreshProcedureReferencedObjects(pq);
|
|
}
|
|
pbProcess.PerformStep();
|
|
Application.DoEvents();
|
|
}
|
|
}
|
|
ContentInfo.StaticContentInfoChange -= new StaticContentInfoEvent(ContentInfo_StaticContentInfoChange);
|
|
DateTime pEnd = DateTime.Now;
|
|
txtProcess.AppendText(pEnd.ToString("mm/dd/yyyy @ HH:mm"));
|
|
Application.DoEvents();
|
|
if (pil.Count > 0)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine("The batch refresh process was not usccessful for all procedures selected.");
|
|
sb.AppendLine("The following procedures were not able to be refreshed...");
|
|
sb.AppendLine();
|
|
sb.AppendLine(sbProcs.ToString());
|
|
sb.AppendLine();
|
|
sb.AppendLine("These procedures were forced checked in and the process was allowed to complete.");
|
|
foreach (ProcedureInfo pi in pil)
|
|
{
|
|
OwnerInfo oi = OwnerInfo.GetByItemID(pi.ItemID, CheckOutType.Procedure);
|
|
MySessionInfo.CheckInItem(oi.OwnerID);
|
|
}
|
|
txtProcess.AppendText(sb.ToString());
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
Application.DoEvents();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
this.Cursor = Cursors.Default;
|
|
MessageBox.Show("Batch Refresh Process Completed", "Batch Refresh Complete");
|
|
}
|
|
|
|
private void RefreshProcedureReferencedObjects(ProcedureInfo pq)
|
|
{
|
|
DateTime start = DateTime.Now;
|
|
myFixes = new StringBuilder();
|
|
ProcedureInfo.ResetROCounters();
|
|
ProcedureInfo.RefreshReferenceObjects(pq);
|
|
TimeSpan ts = DateTime.Now - start;
|
|
txtProcess.AppendText(string.Format("Procedure: {1}{0}, Checked {2} Referenced Objects{0}, Fixed {3} Referenced Objects{0}, Elapsed Seconds:{4}{0}", Environment.NewLine, pq.DisplayNumber, ProcedureInfo.ROCheckCount, ProcedureInfo.ROFixCount, ts.TotalSeconds));
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
txtResults.AppendText(myFixes.ToString());
|
|
txtResults.AppendText(Environment.NewLine);
|
|
}
|
|
private TransitionInfoList transitionsToDisconnected;
|
|
private TransitionInfoList transitionsToNonEditable;
|
|
private void RefreshProcedureTransitions(ProcedureInfo pq)
|
|
{
|
|
DateTime start = DateTime.Now;
|
|
myFixes = new StringBuilder();
|
|
ProcedureInfo.ResetTranCounters();
|
|
ProcedureInfo.RefreshTransitions(pq, transitionsToDisconnected, transitionsToNonEditable);
|
|
TimeSpan ts = DateTime.Now - start;
|
|
txtProcess.AppendText(string.Format("Procedure: {1}{0}Checked {2} Transitions{0}Fixed {3} Transitions{0}Elapsed Seconds:{4}{0}", Environment.NewLine, pq.DisplayNumber, ProcedureInfo.TranCheckCount, ProcedureInfo.TranFixCount, ts.TotalSeconds));
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
txtResults.AppendText(myFixes.ToString());
|
|
txtResults.AppendText(Environment.NewLine);
|
|
}
|
|
|
|
private void PopulateTransitionInfoLists(List<ProcedureInfo> pil)
|
|
{
|
|
Dictionary<int, int> dic = new Dictionary<int, int>();
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (ProcedureInfo pi in pil)
|
|
if (!dic.ContainsKey(pi.MyDocVersion.VersionID))
|
|
{
|
|
dic.Add(pi.MyDocVersion.VersionID, pi.MyDocVersion.VersionID);
|
|
sb.Append(sb.Length == 0 ? pi.MyDocVersion.VersionID.ToString() : "," + pi.MyDocVersion.VersionID.ToString());
|
|
}
|
|
txtProcess.AppendText("Preparing to process...");
|
|
txtProcess.AppendText(Environment.NewLine);
|
|
Application.DoEvents();
|
|
//transitionsToDisconnected = TransitionInfoList.GetTransitionsToDisconnected(sb.ToString());
|
|
transitionsToNonEditable = TransitionInfoList.GetTransitionsToNonEditable(sb.ToString());
|
|
}
|
|
private void ProgressBarShowText()
|
|
{
|
|
pbProcess.Refresh();
|
|
int percent = (int)(((double)(pbProcess.Value - pbProcess.Minimum) /
|
|
(double)(pbProcess.Maximum - pbProcess.Minimum)) * 100);
|
|
using (Graphics gr = pbProcess.CreateGraphics())
|
|
{
|
|
gr.DrawString(percent.ToString() + "%",
|
|
SystemFonts.DefaultFont,
|
|
Brushes.Black,
|
|
new PointF(pbProcess.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
|
|
SystemFonts.DefaultFont).Width / 2.0F),
|
|
pbProcess.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
|
|
SystemFonts.DefaultFont).Height / 2.0F)));
|
|
}
|
|
Application.DoEvents();
|
|
}
|
|
StringBuilder myFixes;
|
|
void ContentInfo_StaticContentInfoChange(object sender, StaticContentInfoEventArgs args)
|
|
{
|
|
if(args.Type == "TX")
|
|
myFixes.AppendLine(string.Format("Fixed Transition for {1}{0}Old Text: {2}{0}New Text: {3}{0}", Environment.NewLine, (sender as ItemInfo).ShortPath, args.OldValue, args.NewValue));
|
|
else if(args.Type == "RO")
|
|
myFixes.AppendLine(string.Format("Fixed Referenced Object for {1}{0}Old Text: {2}{0}New Text: {3}{0}", Environment.NewLine, (sender as ItemInfo).ShortPath, args.OldValue, args.NewValue));
|
|
}
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
txtResults.Clear();
|
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
SaveFileDialog sfd = new SaveFileDialog();
|
|
sfd.DefaultExt = "txt";
|
|
sfd.AddExtension = true;
|
|
sfd.Filter = "Text Files (*.txt)|*.txt";
|
|
sfd.FileName = string.Format("BatchRefreshResults_{0}", DateTime.Now.ToString("yyyyMMdd_HHmm"));
|
|
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\VEPROMS";
|
|
DialogResult dr = sfd.ShowDialog();
|
|
if (dr == DialogResult.OK)
|
|
{
|
|
System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName);
|
|
sw.Write(txtResults.Text);
|
|
sw.Close();
|
|
}
|
|
}
|
|
private void Options_Changed(object sender, EventArgs e)
|
|
{
|
|
if ((sender as RadioButton).Checked)
|
|
btnRefresh.Text = string.Format("Refresh {0}", (sender as RadioButton).Text);
|
|
}
|
|
private void myTV_AfterCheck(object sender, TreeViewEventArgs e)
|
|
{
|
|
if (e.Action != TreeViewAction.Unknown)
|
|
if(e.Node.Nodes.Count > 0)
|
|
CheckChildNodes(e.Node, e.Node.Checked);
|
|
}
|
|
private void CheckChildNodes(TreeNode treeNode, bool ischecked)
|
|
{
|
|
foreach (TreeNode tn in treeNode.Nodes)
|
|
{
|
|
tn.Checked = ischecked;
|
|
if (tn.Nodes.Count > 0)
|
|
CheckChildNodes(tn, ischecked);
|
|
}
|
|
}
|
|
|
|
private void schedule_Click(object sender, EventArgs e)
|
|
{
|
|
pnlLater.Enabled = rbLater.Checked;
|
|
}
|
|
|
|
private void btBatch_BalloonDisplaying(object sender, EventArgs e)
|
|
{
|
|
Point p = Control.MousePosition;
|
|
p.Offset(-btBatch.BalloonControl.TipOffset, btBatch.BalloonControl.TipLength + 4);
|
|
btBatch.BalloonControl.Location = p;
|
|
if (btBatch.BalloonTriggerControl == rbTransition)
|
|
{
|
|
}
|
|
else if (btBatch.BalloonTriggerControl == rbRefObj)
|
|
{
|
|
}
|
|
else if (btBatch.BalloonTriggerControl == rbBoth)
|
|
{
|
|
}
|
|
else if (btBatch.BalloonTriggerControl == rbNow)
|
|
{
|
|
}
|
|
else if (btBatch.BalloonTriggerControl == rbLater)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
} |