437 lines
14 KiB
C#
437 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using VEPROMS.CSLA.Library;
|
|
using JR.Utils.GUI.Forms;
|
|
|
|
namespace Volian.Controls.Library
|
|
{
|
|
public partial class DisplayApplicability : UserControl
|
|
{
|
|
public delegate void DisplayApplicabilityEvent(object sender, EventArgs args);
|
|
public event DisplayApplicabilityEvent ApplicabilityViewModeChanged;
|
|
private void OnApplicabilityViewModeChanged()
|
|
{
|
|
if (ApplicabilityViewModeChanged != null)
|
|
ApplicabilityViewModeChanged(this, new EventArgs());
|
|
}
|
|
private DisplayTabItem _MyDisplayTabItem = null;
|
|
public DisplayTabItem MyDisplayTabItem
|
|
{
|
|
get { return _MyDisplayTabItem; }
|
|
set
|
|
{
|
|
if (DesignMode) return; // B2019-043 need to check if we are just saving changes to the user interface
|
|
_MyDisplayTabItem = value;
|
|
gpMode.Controls.Clear();
|
|
gpItem.Controls.Clear();
|
|
MyCheckBoxes.Clear();
|
|
if (_MyDisplayTabItem != null)
|
|
{
|
|
DocVersionConfig dcfg = _MyDisplayTabItem.MyItemInfo.MyDocVersion.MyConfig as DocVersionConfig;
|
|
List<string> names = new List<string>();
|
|
for (int n = 1; n <= dcfg.Unit_Count; n++)
|
|
{
|
|
dcfg.SelectedSlave = n;
|
|
names.Add(dcfg.Unit_Name);
|
|
}
|
|
dcfg.SelectedSlave = 0;
|
|
// string[] names = dcfg.Unit_Name.Split(',');
|
|
int apple = -1;
|
|
if(_MyDisplayTabItem.MyStepTabPanel != null)
|
|
apple = _MyDisplayTabItem.MyStepTabPanel.MyStepPanel.ApplDisplayMode;
|
|
AddViewMode("Master", "-1", apple == -1);
|
|
int i = 0;
|
|
foreach (string name in names)
|
|
{
|
|
i++;
|
|
AddViewMode(name.Trim(), i.ToString(), apple == i);
|
|
}
|
|
AddItemMode("All", "-1");
|
|
i = 0;
|
|
foreach (string name in names)
|
|
AddItemMode(name.Trim(), (++i).ToString());
|
|
AddItemMode("None", "0");
|
|
if (_MyDisplayTabItem.MyStepTabPanel != null)
|
|
MyItemInfo = _MyDisplayTabItem.MyStepTabPanel.MyStepPanel.SelectedItemInfo;
|
|
else
|
|
MyItemInfo = _MyDisplayTabItem.MyItemInfo;
|
|
}
|
|
}
|
|
}
|
|
public int ViewMode
|
|
{
|
|
get
|
|
{
|
|
foreach (Control c in gpMode.Controls)
|
|
{
|
|
RadioButton rb = c as RadioButton;
|
|
if (rb.Checked)
|
|
return int.Parse(rb.Tag.ToString());
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
private Dictionary<int, CheckBox> MyCheckBoxes = new Dictionary<int, CheckBox>();
|
|
private string _MyApplicability = string.Empty;
|
|
public string MyApplicability
|
|
{
|
|
get { return _MyApplicability; }
|
|
set { _MyApplicability = value; }
|
|
}
|
|
|
|
//private ProcedureInfo _MyProcedureInfo;
|
|
//public ProcedureInfo MyProcedureInfo
|
|
//{
|
|
//get { return _MyProcedureInfo; }
|
|
//set
|
|
//{
|
|
// _MyProcedureInfo = value;
|
|
// if (_MyProcedureInfo != null && _MyProcedureInfo.IsProcedure)
|
|
// {
|
|
// DocVersionConfig cfg = new DocVersionConfig(_MyProcedureInfo.MyDocVersion);
|
|
// if (cfg.Unit_Name == string.Empty)
|
|
// this.Visible = false;
|
|
// else
|
|
// {
|
|
// string[] names = cfg.Unit_Name.Split(',');
|
|
// gpMode.Controls.Clear();
|
|
// gpItem.Controls.Clear();
|
|
// MyCheckBoxes.Clear();
|
|
// AddViewMode("Master", "-1", true);
|
|
// int i = 0;
|
|
// foreach (string name in names)
|
|
// {
|
|
// AddViewMode(name.Trim(), (++i).ToString());
|
|
// }
|
|
// AddItemMode("All", "-1");
|
|
// i = 0;
|
|
// foreach (string name in names)
|
|
// AddItemMode(name.Trim(), (++i).ToString());
|
|
// AddItemMode("None", "0");
|
|
// //if(!this.Visible)
|
|
// // this.Visible = true;
|
|
// }
|
|
// }
|
|
//}
|
|
//}
|
|
private void AddItemMode(string name, string value)
|
|
{
|
|
CheckBox cb = new CheckBox();
|
|
cb.BackColor = Color.Transparent;
|
|
cb.Text = name;
|
|
cb.Tag = value;
|
|
cb.Dock = DockStyle.Top;
|
|
gpItem.Controls.Add(cb);
|
|
cb.BringToFront();
|
|
cb.CheckedChanged += new EventHandler(cb_CheckedChanged);
|
|
MyCheckBoxes.Add(value == null ? -1 : int.Parse(value), cb);
|
|
}
|
|
private void cb_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
UnwireCheckboxes(false);
|
|
CheckBox cb = sender as CheckBox;
|
|
CheckState cs = cb.CheckState;
|
|
switch (cb.Tag.ToString())
|
|
{
|
|
case "-1":
|
|
if (cs == CheckState.Checked)
|
|
{
|
|
SetCheckboxes(CheckState.Checked);
|
|
MyCheckBoxes[0].CheckState = CheckState.Unchecked;
|
|
}
|
|
else
|
|
{
|
|
SetCheckboxes(CheckState.Unchecked);
|
|
MyCheckBoxes[0].CheckState = CheckState.Checked;
|
|
}
|
|
break;
|
|
case "0":
|
|
if (cs == CheckState.Unchecked)
|
|
SetCheckboxes(CheckState.Checked);
|
|
else
|
|
SetCheckboxes(CheckState.Unchecked);
|
|
cb.CheckState = cs;
|
|
break;
|
|
default:
|
|
if (AllNumbered(CheckState.Checked))
|
|
{
|
|
MyCheckBoxes[-1].CheckState = CheckState.Checked;
|
|
MyCheckBoxes[0].CheckState = CheckState.Unchecked;
|
|
}
|
|
else if (AllNumbered(CheckState.Unchecked))
|
|
{
|
|
MyCheckBoxes[-1].CheckState = CheckState.Unchecked;
|
|
MyCheckBoxes[0].CheckState = CheckState.Checked;
|
|
}
|
|
else
|
|
{
|
|
MyCheckBoxes[-1].CheckState = CheckState.Unchecked;
|
|
MyCheckBoxes[0].CheckState = CheckState.Unchecked;
|
|
}
|
|
break;
|
|
}
|
|
WireCheckboxes();
|
|
MyApplicability = string.Empty;
|
|
string sep = string.Empty;
|
|
foreach (int i in MyCheckBoxes.Keys)
|
|
{
|
|
if (i < 0 && MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability = i.ToString();
|
|
break;
|
|
}
|
|
else if (i == 0 && MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability = i.ToString();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability += sep + i.ToString();
|
|
sep = ",";
|
|
}
|
|
}
|
|
}
|
|
//IItemConfig cfg = MyItemInfo.MyConfig as IItemConfig;
|
|
//cfg.MasterSlave_Applicability.SetFlags(MyApplicability);
|
|
//Content c = Content.Get(MyItemInfo.MyContent.ContentID);
|
|
//c.Save();
|
|
//foreach (TransitionInfo ti in MyItemInfo.ItemTransitions_ToID)
|
|
//{
|
|
// if (!ti.MyItemToID.IsApplicable(MyApplicability))
|
|
// {
|
|
// MessageBox.Show("you can't do this");
|
|
// return;
|
|
// }
|
|
//}
|
|
List<InvalidTransition> invalidTrans = WillTransitionsBeValidCommand.Execute(MyItemInfo.ItemID, MyApplicability);
|
|
// B2021-149: for Procedure level PC/PC, continue processing if all 'invalid' transitions are internal (query used
|
|
// return internal and external for the procedure level)
|
|
if ((!MyItemInfo.IsProcedure && invalidTrans.Count == 0) || IsProcWithNoExternalTrans(MyItemInfo, invalidTrans))
|
|
{
|
|
// C2021 - 027: Procedure level PC/PC
|
|
if (MyItemInfo.IsProcedure && MyItemInfo.ActiveFormat.PlantFormat.FormatData.ProcData.ProcAppl)
|
|
{
|
|
ProcedureConfig sc = MyItemInfo.MyConfig as ProcedureConfig;
|
|
sc.MasterSlave_Applicability = Volian.Base.Library.BigNum.MakeBigNum(MyApplicability);
|
|
}
|
|
else if (MyItemInfo.IsSection)
|
|
{
|
|
SectionConfig sc = MyItemInfo.MyConfig as SectionConfig;
|
|
sc.MasterSlave_Applicability = Volian.Base.Library.BigNum.MakeBigNum(MyApplicability);
|
|
}
|
|
else
|
|
{
|
|
StepConfig sc = MyItemInfo.MyConfig as StepConfig;
|
|
sc.MasterSlave_Applicability = Volian.Base.Library.BigNum.MakeBigNum(MyApplicability);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
string tmpwrd = MyItemInfo.IsSection ? "section" : "step";
|
|
sb.AppendLine($"The applicability for this {tmpwrd} cannot be changed due to transition links.");
|
|
sb.AppendLine("Applicability settings will return to original settings when OK is selected.");
|
|
sb.AppendLine($"Changing the applicability for this {tmpwrd} will invalidate a transition in the following steps...");
|
|
|
|
sb.AppendLine();
|
|
// B2021-149: if step, put out line for every invalidTrans, if procedure only put out those that are external
|
|
// determine this by looking strings for source and target (to), if procedure level and internal the target starts
|
|
// with the src, i.e. procedure.
|
|
foreach (InvalidTransition inv in invalidTrans)
|
|
if (!MyItemInfo.IsProcedure || !inv.TgtStep.StartsWith(inv.SrcStep))sb.AppendLine(string.Format("From {0} to {1}",inv.TgtStep, inv.SrcStep));
|
|
// MessageBox.Show(sb.ToString());
|
|
// B2013-185 use FlexibleMessageBox to display a long list with a scroll bar
|
|
FlexibleMessageBox.Show(sb.ToString(), "Transitions Affected By Applicability Change");
|
|
MyItemInfo = MyItemInfo;
|
|
}
|
|
// C2021 - 027: Procedure level PC/PC - checkbox for applicability changed, fix ribbon's menus
|
|
if (MyItemInfo.IsProcedure) _MyDisplayTabItem.MyStepTabPanel.MyStepTabRibbon.SetParentChildCreatePDFButton(MyItemInfo.MyDocVersion.UnitNames, MyItemInfo);
|
|
|
|
//using (Content cnt = Content.Get(MyItemInfo.MyContent.ContentID))
|
|
//{
|
|
// cnt.DTS = DateTime.Now;
|
|
// cnt.UserID = Volian.Base.Library.VlnSettings.UserID;
|
|
// //cnt.Save();
|
|
//}
|
|
|
|
//using (Step s = Step.Get(MyItemInfo.ItemID))
|
|
//{
|
|
// IItemConfig cfg = new StepConfig(s);
|
|
// cfg.MasterSlave_Applicability = new Volian.Base.Library.BigNum(MyApplicability);
|
|
// s.MyContent.Config = cfg.ToString();
|
|
// s.Save();
|
|
//}
|
|
}
|
|
// B2021-149: for procedure, only consider external transitions as invalid
|
|
private bool IsProcWithNoExternalTrans(ItemInfo ii, List<InvalidTransition> invalidTrans)
|
|
{
|
|
if (invalidTrans.Count == 0) return true;
|
|
foreach (InvalidTransition iT in invalidTrans)
|
|
{
|
|
// if target (to location) does not start with source location (procedure) then this is external
|
|
// i.e. from a different procedure
|
|
if (!iT.TgtStep.StartsWith(iT.SrcStep)) return false;
|
|
}
|
|
return true;
|
|
}
|
|
private bool AllNumbered(CheckState checkState)
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
if (int.Parse(cb.Tag.ToString()) > 0 && cb.CheckState != checkState)
|
|
return false;
|
|
return true;
|
|
}
|
|
private void SetCheckboxes(CheckState cs)
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
cb.CheckState = cs;
|
|
}
|
|
private ItemInfo _MyItemInfo;
|
|
public ItemInfo MyItemInfo
|
|
{
|
|
get { return _MyItemInfo; }
|
|
set
|
|
{
|
|
if (DesignMode) return; // B2019-043 need to check if we are just saving changes to the user interface
|
|
if (_MyItemInfo != null)
|
|
{
|
|
MyApplicability = string.Empty;
|
|
string sep = string.Empty;
|
|
foreach (int i in MyCheckBoxes.Keys)
|
|
{
|
|
if (i < 0 && MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability = i.ToString();
|
|
break;
|
|
}
|
|
else if (i == 0 && MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability = i.ToString();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (MyCheckBoxes[i].CheckState == CheckState.Checked)
|
|
{
|
|
MyApplicability += sep + i.ToString();
|
|
sep = ",";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_MyItemInfo = value;
|
|
if (_MyItemInfo != null)
|
|
{
|
|
if (this.Visible == false) return;
|
|
IItemConfig cfg = _MyItemInfo.MyConfig as IItemConfig;
|
|
List<int> apples = cfg.MasterSlave_Applicability.GetFlags();
|
|
UnwireCheckboxes(true);
|
|
if (apples.Count == 0)
|
|
{
|
|
SetCheckboxes(CheckState.Checked);
|
|
MyCheckBoxes[0].CheckState = CheckState.Unchecked;
|
|
}
|
|
else
|
|
{
|
|
foreach (int apple in apples)
|
|
{
|
|
if(apple < MyCheckBoxes.Count)
|
|
MyCheckBoxes[apple].CheckState = CheckState.Checked;
|
|
}
|
|
}
|
|
WireCheckboxes();
|
|
}
|
|
}
|
|
}
|
|
private void WireCheckboxes()
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
cb.CheckedChanged += new EventHandler(cb_CheckedChanged);
|
|
}
|
|
private void UnwireCheckboxes(bool reset)
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
{
|
|
cb.CheckedChanged -= new EventHandler(cb_CheckedChanged);
|
|
if(reset)
|
|
cb.CheckState = CheckState.Unchecked;
|
|
}
|
|
}
|
|
private void DisableCheckboxes()
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
cb.Enabled = false;
|
|
}
|
|
private void EnableCheckboxes()
|
|
{
|
|
foreach (CheckBox cb in MyCheckBoxes.Values)
|
|
cb.Enabled = true;
|
|
}
|
|
private void AddViewMode(string name, string value)
|
|
{
|
|
AddViewMode(name, value, false);
|
|
}
|
|
private void AddViewMode(string name, string value, bool selected)
|
|
{
|
|
RadioButton rb = new RadioButton();
|
|
rb.BackColor = Color.Transparent;
|
|
rb.Text = name;
|
|
rb.Tag = value;
|
|
rb.Dock = DockStyle.Top;
|
|
gpMode.Controls.Add(rb);
|
|
rb.BringToFront();
|
|
rb.Checked = selected;
|
|
rb.CheckedChanged += new EventHandler(rb_CheckedChanged);
|
|
}
|
|
private void rb_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
RadioButton rb = sender as RadioButton;
|
|
if (rb.Checked)
|
|
{
|
|
if (int.Parse(rb.Tag.ToString()) > 0)
|
|
{
|
|
DisableCheckboxes();
|
|
MyCheckBoxes[int.Parse(rb.Tag.ToString())].Enabled = true;
|
|
}
|
|
else
|
|
EnableCheckboxes();
|
|
OnApplicabilityViewModeChanged();
|
|
EditItem ei = MyDisplayTabItem.MyStepTabPanel.SelectedEditItem;
|
|
while (ei!=null && ei.Enabled == false)
|
|
ei = ei.MyParentEditItem ?? ei.MyPreviousEditItem;
|
|
// C2021 - 027: Procedure level PC/PC - handle procedure level too for viewing in editor
|
|
if (MyDisplayTabItem.MyStepTabPanel.SelectedItemInfo != null && MyDisplayTabItem.MyStepTabPanel.SelectedItemInfo.IsProcedure)
|
|
ei = MyDisplayTabItem.MyStepTabPanel.SelectedEditItem;
|
|
if (ei != null) ei.MyStepRTB.Focus();
|
|
}
|
|
}
|
|
|
|
private static UserInfo _MyUserInfo = null;
|
|
public static UserInfo MyUserInfo
|
|
{
|
|
get { return _MyUserInfo; }
|
|
set { _MyUserInfo = value; }
|
|
}
|
|
|
|
public DisplayApplicability()
|
|
{
|
|
InitializeComponent();
|
|
this.VisibleChanged += new EventHandler(DisplayApplicability_VisibleChanged);
|
|
}
|
|
|
|
void DisplayApplicability_VisibleChanged(object sender, EventArgs e)
|
|
{
|
|
MyItemInfo = MyItemInfo;
|
|
gpItem.Enabled = UserInfo.CanEdit(MyUserInfo,(MyItemInfo == null) ? null : MyItemInfo.MyDocVersion); //Can Change Applicability
|
|
}
|
|
}
|
|
}
|