390 lines
		
	
	
		
			11 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			390 lines
		
	
	
		
			11 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;
 | 
						|
 | 
						|
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<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);
 | 
						|
			if (invalidTrans.Count == 0)
 | 
						|
			{
 | 
						|
				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();
 | 
						|
				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<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.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;
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |