From 50c04033acffd85950107fe5e32baf0d699acd34 Mon Sep 17 00:00:00 2001 From: Rich Date: Tue, 4 Dec 2012 23:10:38 +0000 Subject: [PATCH] Added DisplayApplicability class to display applicability of individual items of a procedure in step properties panel --- .../DisplayApplicability.Designer.cs | 144 +++++++ .../DisplayApplicability.cs | 380 ++++++++++++++++++ .../DisplayApplicability.resx | 120 ++++++ 3 files changed, 644 insertions(+) create mode 100644 PROMS/Volian.Controls.Library/DisplayApplicability.Designer.cs create mode 100644 PROMS/Volian.Controls.Library/DisplayApplicability.cs create mode 100644 PROMS/Volian.Controls.Library/DisplayApplicability.resx diff --git a/PROMS/Volian.Controls.Library/DisplayApplicability.Designer.cs b/PROMS/Volian.Controls.Library/DisplayApplicability.Designer.cs new file mode 100644 index 00000000..9a7f4920 --- /dev/null +++ b/PROMS/Volian.Controls.Library/DisplayApplicability.Designer.cs @@ -0,0 +1,144 @@ +namespace Volian.Controls.Library +{ + partial class DisplayApplicability + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.gpMode = new DevComponents.DotNetBar.Controls.GroupPanel(); + this.gpItem = new DevComponents.DotNetBar.Controls.GroupPanel(); + this.SuspendLayout(); + // + // gpMode + // + this.gpMode.AutoSize = true; + this.gpMode.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.gpMode.CanvasColor = System.Drawing.SystemColors.Control; + this.gpMode.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; + this.gpMode.Dock = System.Windows.Forms.DockStyle.Top; + this.gpMode.Location = new System.Drawing.Point(0, 0); + this.gpMode.Name = "gpMode"; + this.gpMode.Padding = new System.Windows.Forms.Padding(10, 10, 10, 30); + this.gpMode.Size = new System.Drawing.Size(324, 40); + // + // + // + this.gpMode.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; + this.gpMode.Style.BackColorGradientAngle = 90; + this.gpMode.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; + this.gpMode.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpMode.Style.BorderBottomWidth = 1; + this.gpMode.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.gpMode.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpMode.Style.BorderLeftWidth = 1; + this.gpMode.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpMode.Style.BorderRightWidth = 1; + this.gpMode.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpMode.Style.BorderTopWidth = 1; + this.gpMode.Style.Class = ""; + this.gpMode.Style.CornerDiameter = 4; + this.gpMode.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; + this.gpMode.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; + this.gpMode.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; + this.gpMode.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; + // + // + // + this.gpMode.StyleMouseDown.Class = ""; + this.gpMode.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square; + // + // + // + this.gpMode.StyleMouseOver.Class = ""; + this.gpMode.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.gpMode.TabIndex = 0; + this.gpMode.Text = "Viewing Mode"; + // + // gpItem + // + this.gpItem.AutoSize = true; + this.gpItem.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.gpItem.CanvasColor = System.Drawing.SystemColors.Control; + this.gpItem.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.Office2007; + this.gpItem.Dock = System.Windows.Forms.DockStyle.Top; + this.gpItem.Location = new System.Drawing.Point(0, 40); + this.gpItem.Name = "gpItem"; + this.gpItem.Padding = new System.Windows.Forms.Padding(10, 10, 10, 30); + this.gpItem.Size = new System.Drawing.Size(324, 40); + // + // + // + this.gpItem.Style.BackColor2SchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground2; + this.gpItem.Style.BackColorGradientAngle = 90; + this.gpItem.Style.BackColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBackground; + this.gpItem.Style.BorderBottom = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpItem.Style.BorderBottomWidth = 1; + this.gpItem.Style.BorderColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.gpItem.Style.BorderLeft = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpItem.Style.BorderLeftWidth = 1; + this.gpItem.Style.BorderRight = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpItem.Style.BorderRightWidth = 1; + this.gpItem.Style.BorderTop = DevComponents.DotNetBar.eStyleBorderType.Solid; + this.gpItem.Style.BorderTopWidth = 1; + this.gpItem.Style.Class = ""; + this.gpItem.Style.CornerDiameter = 4; + this.gpItem.Style.CornerType = DevComponents.DotNetBar.eCornerType.Rounded; + this.gpItem.Style.TextAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Center; + this.gpItem.Style.TextColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelText; + this.gpItem.Style.TextLineAlignment = DevComponents.DotNetBar.eStyleTextAlignment.Near; + // + // + // + this.gpItem.StyleMouseDown.Class = ""; + this.gpItem.StyleMouseDown.CornerType = DevComponents.DotNetBar.eCornerType.Square; + // + // + // + this.gpItem.StyleMouseOver.Class = ""; + this.gpItem.StyleMouseOver.CornerType = DevComponents.DotNetBar.eCornerType.Square; + this.gpItem.TabIndex = 1; + this.gpItem.Text = "Item Mode"; + // + // DisplayApplicability + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.gpItem); + this.Controls.Add(this.gpMode); + this.Name = "DisplayApplicability"; + this.Size = new System.Drawing.Size(324, 656); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DevComponents.DotNetBar.Controls.GroupPanel gpMode; + private DevComponents.DotNetBar.Controls.GroupPanel gpItem; + + } +} diff --git a/PROMS/Volian.Controls.Library/DisplayApplicability.cs b/PROMS/Volian.Controls.Library/DisplayApplicability.cs new file mode 100644 index 00000000..d7d8fbae --- /dev/null +++ b/PROMS/Volian.Controls.Library/DisplayApplicability.cs @@ -0,0 +1,380 @@ +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; + +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 + { + _MyDisplayTabItem = value; + gpMode.Controls.Clear(); + gpItem.Controls.Clear(); + MyCheckBoxes.Clear(); + if (_MyDisplayTabItem != null) + { + DocVersionConfig dcfg = _MyDisplayTabItem.MyItemInfo.MyDocVersion.MyConfig as DocVersionConfig; + List names = new List(); + for (int n = 1; n <= dcfg.Unit_Count; n++) + { + dcfg.SelectedSlave = n; + names.Add(dcfg.Unit_Name); + } +// 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 MyCheckBoxes = new Dictionary(); + 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 invalidTrans = WillTransitionsBeValidCommand.Execute(MyItemInfo.ItemID, MyApplicability); + if (invalidTrans.Count == 0) + { + StepConfig sc = MyItemInfo.MyConfig as StepConfig; + sc.MasterSlave_Applicability = Volian.Base.Library.BigNum.MakeBigNum(MyApplicability); + } + else + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("Changing the applicability for this step will invalidate a transition in the following steps..."); + sb.AppendLine(); + foreach (InvalidTransition inv in invalidTrans) + sb.AppendLine(string.Format("From {0} to {1}", inv.SrcStep, inv.TgtStep)); + MessageBox.Show(sb.ToString()); + MyItemInfo = 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(); + //} + } + 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 (_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 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.Enabled == false) + ei = ei.MyParentEditItem ?? ei.MyPreviousEditItem; + ei.MyStepRTB.Focus(); + } + } + public DisplayApplicability() + { + InitializeComponent(); + this.VisibleChanged += new EventHandler(DisplayApplicability_VisibleChanged); + } + + void DisplayApplicability_VisibleChanged(object sender, EventArgs e) + { + MyItemInfo = MyItemInfo; + } + } +} diff --git a/PROMS/Volian.Controls.Library/DisplayApplicability.resx b/PROMS/Volian.Controls.Library/DisplayApplicability.resx new file mode 100644 index 00000000..19dc0dd8 --- /dev/null +++ b/PROMS/Volian.Controls.Library/DisplayApplicability.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file