using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Xml.Serialization;
using Multiplex;

namespace QDART_MFG_CfgEditor;

public class MultiplexPanel : UserControl
{
	public delegate void TargetFileChangedEventHandler(string targetfile);

	private ConfigurationFile ori = new ConfigurationFile();

	private RootConfig rc;

	private string target_file;

	private string routing_txt;

	private string routing_port;

	private string ids_txt;

	private string paths_txt;

	private bool beRefreashUI;

	private InfoItem[] infoItem;

	private bool bSimpleMode = true;

	private bool bNeedUpdateUsingMultiplex = true;

	private SortedList<int, string> slGroup = new SortedList<int, string>();

	private SortedList<int, string> slDut = new SortedList<int, string>();

	private SortedList<int, string> slMultiplexer = new SortedList<int, string>();

	private SortedList<int, string> slPort = new SortedList<int, string>();

	private SortedList<int, int> slGroupMap = new SortedList<int, int>();

	private SortedList<int, SortedList<int, int>> slDutMap = new SortedList<int, SortedList<int, int>>();

	private SortedList<int, int> slMultiplexerMap = new SortedList<int, int>();

	private SortedList<int, int> slDutGroupMap = new SortedList<int, int>();

	private CurrencyManager multiplexCM;

	private CurrencyManager groupCM;

	private CurrencyManager dutCM;

	private CurrencyManager portCM;

	private int currentGroupId;

	private int currentDutId;

	private int currentMultiplexerId;

	private int currentGroupInTabpages;

	private int currentDutInTabpages;

	private int currentMultiplexerInTabpages;

	private TextBox input;

	private BindingSource bsRoot = new BindingSource();

	private BindingSource bsMultiplex = new BindingSource();

	private BindingSource bsGroup = new BindingSource();

	private BindingSource bsDUT = new BindingSource();

	private BindingSource bsMultiDUTSetting = new BindingSource();

	private BindingSource bsMultiplexUpLevel = new BindingSource();

	private BindingSource bsGroupUpLevel = new BindingSource();

	private BindingSource bsPortsUpLevel = new BindingSource();

	private BindingSource bsPorts = new BindingSource();

	private BindingSource bsBands = new BindingSource();

	private List<string> multiplexerIdsSrc = new List<string>();

	private List<string> multiplexerPathSrc = new List<string>();

	private IContainer components;

	private TextBox tbTarget;

	private Panel plGroup;

	private TabPage tabPage1;

	private TabPage tabPage2;

	private Panel plDut;

	private Button btnDelGroup;

	private Button btnAddGroup;

	private Button btnDelDut;

	private Button btnAddDut;

	private Panel plDutCfg;

	private TabControl tbDut;

	private TabPage tabPage3;

	private TabPage tabPage4;

	private Button btnDelMultiplexer;

	private Button btnAddMultiplexer;

	private Panel plMultiplexerCfg;

	private ComboBox cbSimulation;

	private Label label4;

	private Label label5;

	private TabControl tbMultiplexer;

	private TabPage tabPage5;

	private TabPage tabPage6;

	private Panel plMultiplexer;

	private Button btnDll;

	private TextBox tbBusCfg;

	private TextBox tbDll;

	private Label label6;

	private DataGridView dgRouting;

	private Label label7;

	private DataGridViewTextBoxColumn Paths;

	private TabControl tbGroup;

	private Button btnPasteDut;

	private ToolTip toolTip1;

	private Panel panel1;

	private DataGridView dgIdPathPair;

	private DataGridViewComboBoxColumn PAIR_ID;

	private DataGridViewComboBoxColumn PAIR_PATHS;

	private Label lbFile;

	private Button btnDelRC;

	private Button btnEdit;

	private Button btnNewRC;

	private ComboBox cmbPorts;

	private Label PORT;

	private TextBox tbDescription;

	private Label label1;

	private Label lbSrcfile;

	private ComboBox cmbSrcfile;

	private TextBox tbSrcfile;

	private Label lbBand;

	private CheckBox cbUsingMultiplex;

	private TextBox tbBands;

	private CheckBox cbShowDetail;

	public string TargetFile
	{
		get
		{
			return target_file;
		}
		set
		{
			target_file = value;
		}
	}

	public string RoutingPort
	{
		get
		{
			return routing_port;
		}
		set
		{
			routing_port = value;
		}
	}

	public string RoutingTxt
	{
		get
		{
			return routing_txt;
		}
		set
		{
			routing_txt = value;
		}
	}

	public string IdsTxt
	{
		get
		{
			return ids_txt;
		}
		set
		{
			ids_txt = value;
		}
	}

	public string PathsTxt
	{
		get
		{
			return paths_txt;
		}
		set
		{
			paths_txt = value;
		}
	}

	public event TargetFileChangedEventHandler TargetFileChanged;

	public MultiplexPanel(RootConfig cfg)
	{
		InitializeComponent();
		InitVar(cfg);
		rc = cfg;
	}

	public bool OpenFile()
	{
		bool result = false;
		try
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "xml(*.xml)|*.xml";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				string fileName = openFileDialog.FileName;
				if (LoadTargetFile(fileName))
				{
					TargetFile = fileName;
					BindingUI();
					InitControls();
					result = true;
				}
				else
				{
					ClearControls();
				}
			}
			return result;
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
			return false;
		}
	}

	private bool LoadTargetFile(string resfile)
	{
		OnFileChange(resfile);
		bool result = false;
		beRefreashUI = false;
		plMultiplexer.Enabled = false;
		plGroup.Enabled = false;
		if (File.Exists(resfile))
		{
			tbTarget.Text = resfile;
			try
			{
				using (FileStream fileStream = new FileStream(resfile, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationFile));
					ori = (ConfigurationFile)xmlSerializer.Deserialize(fileStream);
					fileStream.Close();
				}
				if (PreCheckFile())
				{
					UpdateGroupDutIdMap();
					UpdateMultiplexerIdMap();
					InitGroupTabControl();
					InitMultiplexTabControl();
					plMultiplexer.Enabled = true;
					plGroup.Enabled = true;
					beRefreashUI = true;
					result = true;
				}
			}
			catch (Exception ex)
			{
				if (MessageBox.Show(" Error in file:" + resfile + "\n\n Message:" + ex.Message + "\n\n Select another file now ?", "Error in file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes && OpenFile())
				{
					beRefreashUI = true;
					result = true;
				}
			}
		}
		return result;
	}

	private void BindingUI()
	{
		try
		{
			bsRoot = new BindingSource();
			bsMultiplex = new BindingSource();
			bsGroup = new BindingSource();
			bsDUT = new BindingSource();
			bsMultiDUTSetting = new BindingSource();
			bsMultiplexUpLevel = new BindingSource();
			bsGroupUpLevel = new BindingSource();
			bsPorts = new BindingSource();
			bsBands = new BindingSource();
			tbDescription.DataBindings.Clear();
			tbDll.DataBindings.Clear();
			tbBusCfg.DataBindings.Clear();
			cbSimulation.DataBindings.Clear();
			cmbPorts.DataBindings.Clear();
			tbBands.DataBindings.Clear();
			base.DataBindings.Clear();
			if (ori != null)
			{
				bsRoot.Add(ori);
				bsMultiDUTSetting.DataSource = bsRoot;
				bsMultiDUTSetting.DataMember = "MultiDUTConfigItems";
				bsMultiplexUpLevel.DataSource = bsMultiDUTSetting;
				bsMultiplexUpLevel.DataMember = "MultiplexersSection";
				bsMultiplex.DataSource = bsMultiplexUpLevel;
				bsMultiplex.DataMember = "MultiplexerList";
				multiplexCM = (CurrencyManager)BindingContext[bsMultiplex];
				bsPortsUpLevel.DataSource = bsMultiplex;
				bsPortsUpLevel.DataMember = "RoutingConfigList";
				bsPorts.DataSource = bsMultiplex;
				bsPorts.DataMember = "RoutingConfigList";
				bsBands.DataSource = bsMultiplex;
				bsBands.DataMember = "RoutingConfigList";
				bsGroupUpLevel.DataSource = bsMultiDUTSetting;
				bsGroupUpLevel.DataMember = "GroupsSection";
				bsGroup.DataSource = bsGroupUpLevel;
				bsGroup.DataMember = "GroupList";
				groupCM = (CurrencyManager)BindingContext[bsGroup];
				bsDUT.DataSource = bsGroup;
				bsDUT.DataMember = "DutList";
				dutCM = (CurrencyManager)BindingContext[bsDUT];
				base.DataBindings.Add("IdsTxt", bsDUT, "MultiplexerIDs");
				base.DataBindings.Add("PathsTxt", bsDUT, "MultiplexerPaths");
				tbDescription.DataBindings.Add("Text", bsMultiplex, "Description");
				tbDll.DataBindings.Add("Text", bsMultiplex, "DriverDLL");
				tbBusCfg.DataBindings.Add("Text", bsMultiplex, "BusConfig");
				base.DataBindings.Add("RoutingTxt", bsPorts, "RoutingConfig");
				cbSimulation.DataBindings.Add("Text", bsMultiplex, "SimulationMode");
				cmbPorts.DataSource = bsPorts;
				cmbPorts.DisplayMember = "PORTS";
				cmbPorts.ValueMember = "PORTS";
				tbBands.DataBindings.Add("Text", bsPorts, "BANDS");
				portCM = (CurrencyManager)BindingContext[bsPorts];
				((BindingList<Multiplexer>)bsMultiplex.List).AllowNew = true;
				((BindingList<Multiplexer>)bsMultiplex.List).AllowRemove = true;
				((BindingList<Group>)bsGroup.List).AllowNew = true;
				((BindingList<Group>)bsGroup.List).AllowRemove = true;
				((BindingList<Dut>)bsDUT.List).AllowNew = true;
				((BindingList<Dut>)bsDUT.List).AllowRemove = true;
				((BindingList<Routing_Config>)bsPorts.List).AllowNew = true;
				((BindingList<Routing_Config>)bsPorts.List).AllowRemove = true;
				((BindingList<Routing_Config>)bsPorts.List).AllowEdit = true;
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	public void SaveResult()
	{
		try
		{
			if (!ValidateConfigFileEntries())
			{
				return;
			}
			string targetFile = TargetFile;
			if (File.Exists(targetFile))
			{
				if (File.GetAttributes(targetFile).ToString().IndexOf("ReadOnly") != -1)
				{
					File.SetAttributes(targetFile, FileAttributes.Normal);
				}
				SerialToFile(targetFile);
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	public string GetResultFilePath()
	{
		return TargetFile;
	}

	public void SaveResultAs()
	{
		try
		{
			if (!ValidateConfigFileEntries())
			{
				return;
			}
			string targetFile = TargetFile;
			using SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.Title = "Save file as Diag";
			saveFileDialog.InitialDirectory = Path.GetDirectoryName(targetFile);
			saveFileDialog.FileName = targetFile;
			saveFileDialog.Filter = "xmlfile|*.xml";
			if (saveFileDialog.ShowDialog() == DialogResult.OK)
			{
				targetFile = saveFileDialog.FileName;
				SerialToFile(targetFile);
				tbTarget.Text = targetFile;
				TargetFile = targetFile;
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private bool PreCheckFile()
	{
		string text = "";
		if (ori == null)
		{
			text += "Target file is blank or load fail.";
		}
		if (ori.MultiDUTConfigItems == null)
		{
			text += "MULTI_DUT_CONFIG is null";
		}
		if (ori.MultiDUTConfigItems.GroupsSection == null)
		{
			text += "GROUPS is null";
		}
		if (ori.MultiDUTConfigItems.GroupsSection.GroupList == null)
		{
			text += "GroupList is null";
		}
		if (ori.MultiDUTConfigItems.GroupsSection.GroupList.Count == 0)
		{
			text += "Group count is 0";
		}
		if (ori.MultiDUTConfigItems.MultiplexersSection == null)
		{
			text += "MULTIPLEXERS is null";
		}
		if (ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList == null)
		{
			text += "Multiplexerlist is null";
		}
		if (ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count == 0)
		{
			text += "MULTIPLEXER count is 0";
		}
		int num = 1;
		foreach (Multiplexer multiplexer in ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList)
		{
			string text2 = multiplexer.MultiplexerID;
			if (int.Parse(multiplexer.MultiplexerID) < 1)
			{
				if (int.Parse(multiplexer.MultiplexerID) == -1)
				{
					text2 = "Unknown";
				}
				text = text + " MULTIPLEXER ID = " + text2 + ". Missing or invalid MULTIPLEXER ID. Must be an integer value greater than or equal to 1.\n";
			}
			string text3 = multiplexer.BusConfig.ToUpper().Replace(" ", "");
			for (int i = num; i < ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count; i++)
			{
				if (multiplexer.MultiplexerID == ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].MultiplexerID)
				{
					text = text + " More than one MULTIPLEXER was assigned MULTIPLEXER ID = " + multiplexer.MultiplexerID.ToString() + ". ID must be unique for each MULTIPLEXER.\n";
				}
				string value = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].BusConfig.ToUpper().Replace(" ", "");
				if (text3.Equals(value))
				{
					text = text + " More than one MULTIPLEXER is using BUS_CONFIG = \"" + multiplexer.BusConfig + "\". BUS_CONFIG must be unique for each MULTIPLEXER.\n";
				}
			}
			num++;
		}
		num = 1;
		List<int> list = new List<int>();
		foreach (Group group in ori.MultiDUTConfigItems.GroupsSection.GroupList)
		{
			string text4 = group.GroupID;
			if (int.Parse(group.GroupID) < 1)
			{
				if (int.Parse(group.GroupID) == -1)
				{
					text4 = "Unknown";
				}
				text = text + " GROUP ID = " + text4 + ". Missing or invalid GROUP ID. Must be an integer value greater than or equal to 1.\n";
			}
			if (group.DutList.Count == 0)
			{
				text = text + " No DUT nodes listed for GROUP ID = " + text4 + ".\n";
			}
			else
			{
				foreach (Dut dut in group.DutList)
				{
					string text5 = dut.DutID;
					if (int.Parse(dut.DutID) < 1)
					{
						if (int.Parse(dut.DutID) == -1)
						{
							text5 = "Unknown";
						}
						text = text + " DUT ID = " + text5 + ". Missing or invalid DUT ID. Must be an integer value greater than or equal to 1.\n";
					}
					if (list.Contains(int.Parse(dut.DutID)))
					{
						text = text + " More than one DUT was assigned DUT ID = " + dut.DutID + ". ID must be unique.\n";
					}
					else
					{
						list.Add(int.Parse(dut.DutID));
					}
					if (dut.MultiplexerIDs.Length <= 0 || dut.MultiplexerPaths.Length <= 0)
					{
						continue;
					}
					string[] array = dut.MultiplexerIDs.Split(',');
					string[] array2 = dut.MultiplexerPaths.Split(',');
					if (array.Length != array2.Length)
					{
						text = text + " MULTIPLEXER_IDS and MULTIPLEXER_PATHS for DUT ID = " + text5 + " must contain the same number of entries.\n";
						string text6 = text;
						text = text6 + "\tThey contain " + array.Length + " and " + array2.Length + " entries, respectively.\n";
						continue;
					}
					for (int j = 0; j < array.Length; j++)
					{
						if (Convert.ToInt32(array[j]) != -1 && Convert.ToInt32(array2[j]) <= 0)
						{
							string text7 = text;
							text = text7 + " Invalid entry in MULTIPLEXER_PATHS: " + array2[j] + " for DUT ID = " + text5 + " MULTIPLEXER ID = " + array[j] + ".\n";
						}
					}
				}
			}
			for (int k = num; k < ori.MultiDUTConfigItems.GroupsSection.GroupList.Count; k++)
			{
				if (group.GroupID == ori.MultiDUTConfigItems.GroupsSection.GroupList[k].GroupID)
				{
					text = text + " More than one GROUP was assigned GROUP ID = " + group.GroupID.ToString() + ". ID must be unique for each GROUP.\n";
				}
			}
			num++;
		}
		if (text.Length != 0)
		{
			MessageBox.Show("Error in " + TargetFile + ":\n" + text);
			return false;
		}
		return true;
	}

	private bool ValidateConfigFileEntries()
	{
		string text = "";
		if (ori.MultiDUTConfigItems == null)
		{
			text += " MULTI_DUT_CONFIG node is missing.\n";
		}
		else
		{
			if (ori.MultiDUTConfigItems.MultiplexersSection == null)
			{
				text += " MULTIPLEXERS node is missing.\n";
			}
			else if (ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count == 0)
			{
				text += " No MULTIPLEXER nodes listed.\n";
			}
			else
			{
				int num = 1;
				foreach (Multiplexer multiplexer in ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList)
				{
					string text2 = multiplexer.MultiplexerID;
					if (int.Parse(multiplexer.MultiplexerID) < 1)
					{
						if (int.Parse(multiplexer.MultiplexerID) == -1)
						{
							text2 = "Unknown";
						}
						text = text + " MULTIPLEXER ID = " + text2 + ". Missing or invalid MULTIPLEXER ID. Must be an integer value greater than or equal to 1.\n";
					}
					if (multiplexer.DriverDLL.Replace(" ", "").Length == 0)
					{
						text = text + " DRIVER_DLL was not specified for MULTIPLEXER ID = " + text2 + ".\n";
					}
					if (multiplexer.BusConfig.Replace(" ", "").Length == 0)
					{
						text = text + " BUS_CONFIG was not specified for MULTIPLEXER ID = " + text2 + ".\n";
					}
					if (multiplexer.RoutingConfigList[0].RoutingConfig.Replace(" ", "").Length == 0)
					{
						text = text + " ROUTING_CONFIG was not specified for MULTIPLEXER ID = " + text2 + ".\n";
					}
					string text3 = multiplexer.BusConfig.ToUpper().Replace(" ", "");
					for (int i = num; i < ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count; i++)
					{
						if (multiplexer.MultiplexerID == ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].MultiplexerID)
						{
							text = text + " More than one MULTIPLEXER was assigned MULTIPLEXER ID = " + multiplexer.MultiplexerID.ToString() + ". ID must be unique for each MULTIPLEXER.\n";
						}
						string value = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].BusConfig.ToUpper().Replace(" ", "");
						if (text3.Equals(value))
						{
							text = text + " More than one MULTIPLEXER is using BUS_CONFIG = \"" + multiplexer.BusConfig + "\". BUS_CONFIG must be unique for each MULTIPLEXER.\n";
						}
					}
					num++;
				}
			}
			if (ori.MultiDUTConfigItems.GroupsSection == null)
			{
				text += " GROUPS node is missing.\n";
			}
			else if (ori.MultiDUTConfigItems.GroupsSection.GroupList.Count == 0)
			{
				text += " No GROUP nodes listed.\n";
			}
			else
			{
				int num2 = 1;
				foreach (Group group in ori.MultiDUTConfigItems.GroupsSection.GroupList)
				{
					string text4 = group.GroupID;
					if (int.Parse(group.GroupID) < 1)
					{
						if (int.Parse(group.GroupID) == -1)
						{
							text4 = "Unknown";
						}
						text = text + " GROUP ID = " + text4 + ". Missing or invalid GROUP ID. Must be an integer value greater than or equal to 1.\n";
					}
					if (group.DutList.Count == 0)
					{
						text = text + " No DUT nodes listed for GROUP ID = " + text4 + ".\n";
					}
					else
					{
						foreach (Dut dut in group.DutList)
						{
							string text5 = dut.DutID;
							if (int.Parse(dut.DutID) < 1)
							{
								if (int.Parse(dut.DutID) == -1)
								{
									text5 = "Unknown";
								}
								text = text + " DUT ID = " + text5 + ". Missing or invalid DUT ID. Must be an integer value greater than or equal to 1.\n";
							}
							if (dut.MultiplexerIDs.Length == 0)
							{
								text = text + " Missing MULTIPLEXER_IDS for DUT ID = " + text5 + ".\n";
							}
							if (dut.MultiplexerPaths.Length == 0)
							{
								text = text + " Missing MULTIPLEXER_PATHS for DUT ID = " + text5 + ".\n";
							}
							if (dut.MultiplexerIDs.Length <= 0 || dut.MultiplexerPaths.Length <= 0)
							{
								continue;
							}
							string[] array = dut.MultiplexerIDs.Split(',');
							string[] array2 = dut.MultiplexerPaths.Split(',');
							if (array.Length != array2.Length)
							{
								text = text + " MULTIPLEXER_IDS and MULTIPLEXER_PATHS for DUT ID = " + text5 + " must contain the same number of entries.\n";
								string text6 = text;
								text = text6 + "\tThey contain " + array.Length + " and " + array2.Length + " entries, respectively.\n";
								continue;
							}
							for (int j = 0; j < array.Length; j++)
							{
								if (Convert.ToInt32(array[j]) == -1)
								{
									continue;
								}
								if (Convert.ToInt32(array2[j]) <= 0)
								{
									string text7 = text;
									text = text7 + " Invalid entry in MULTIPLEXER_PATHS: " + array2[j] + " for DUT ID = " + text5 + " MULTIPLEXER ID = " + array[j] + ".\n";
								}
								else if (slMultiplexerMap.Keys.Contains(Convert.ToInt32(array[j])))
								{
									if (SplitRouting(ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[slMultiplexerMap[int.Parse(array[j])]].RoutingConfigList[0].RoutingConfig).Count < Convert.ToInt32(array2[j]))
									{
										string text8 = text;
										text = text8 + " MULTIPLEXER_PATHS: " + array2[j] + " out of range for DUT ID = " + text5 + " MULTIPLEXER ID = " + array[j] + ".\n";
									}
								}
								else
								{
									string text9 = text;
									text = text9 + " MULTIPLEXER ID = " + array[j] + " not exist for DUT ID = " + text5 + ".\n";
								}
							}
						}
					}
					for (int k = num2; k < ori.MultiDUTConfigItems.GroupsSection.GroupList.Count; k++)
					{
						if (group.GroupID == ori.MultiDUTConfigItems.GroupsSection.GroupList[k].GroupID)
						{
							text = text + " More than one GROUP was assigned GROUP ID = " + group.GroupID.ToString() + ". ID must be unique for each GROUP.\n";
						}
					}
					num2++;
				}
			}
		}
		if (text.Length != 0)
		{
			MessageBox.Show("Error in " + TargetFile + ":\n" + text);
			return false;
		}
		return true;
	}

	private void SerialToFile(string fileName)
	{
		try
		{
			XmlSerializer xmlSerializer = new XmlSerializer(typeof(ConfigurationFile));
			using StreamWriter streamWriter = new StreamWriter(fileName);
			currentGroupInTabpages = tbGroup.SelectedIndex;
			currentDutInTabpages = tbDut.SelectedIndex;
			currentMultiplexerInTabpages = tbMultiplexer.SelectedIndex;
			List<Group> list = ori.MultiDUTConfigItems.GroupsSection.GroupList.OrderBy((Group t) => int.Parse(t.GroupID)).ToList();
			ori.MultiDUTConfigItems.GroupsSection.GroupList = new BindingList<Group>(list);
			foreach (Group item in list)
			{
				List<Dut> list2 = item.DutList.OrderBy((Dut t) => int.Parse(t.DutID)).ToList();
				item.DutList = new BindingList<Dut>(list2);
			}
			List<Multiplexer> list3 = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.OrderBy((Multiplexer t) => int.Parse(t.MultiplexerID)).ToList();
			ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList = new BindingList<Multiplexer>(list3);
			foreach (Multiplexer item2 in list3)
			{
				item2.SimulationMode = "NO";
			}
			UpdateGroupDutIdMap();
			UpdateMultiplexerIdMap();
			InitGroupTabControl();
			InitMultiplexTabControl();
			BindingUI();
			InitControls();
			xmlSerializer.Serialize(streamWriter, ori);
			streamWriter.Close();
			tbGroup.SelectedIndex = currentGroupInTabpages;
			tbDut.SelectedIndex = currentDutInTabpages;
			tbMultiplexer.SelectedIndex = currentMultiplexerInTabpages;
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void InitControls()
	{
		cbShowDetail_CheckedChanged(null, null);
		tbGroup_SelectedIndexChanged(null, null);
		tbDut_SelectedIndexChanged(null, null);
		tbMultiplexer_SelectedIndexChanged(null, null);
	}

	private void ClearControls()
	{
		tbGroup.TabPages.Clear();
		tbDut.TabPages.Clear();
		tbMultiplexer.TabPages.Clear();
		dgIdPathPair.Rows.Clear();
		dgRouting.Rows.Clear();
		tbBusCfg.Clear();
		tbDll.Clear();
		cbSimulation.SelectedIndex = -1;
		cmbPorts.SelectedIndex = -1;
		tbBands.Clear();
	}

	private void InitMultiplexTabControl()
	{
		slMultiplexer.Clear();
		for (int i = 0; i < ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count; i++)
		{
			string multiplexerID = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].MultiplexerID;
			slMultiplexer.Add(int.Parse(multiplexerID), multiplexerID);
		}
		if (tbMultiplexer.TabPages != null)
		{
			tbMultiplexer.TabPages.Clear();
		}
		foreach (KeyValuePair<int, string> item in slMultiplexer)
		{
			tbMultiplexer.Controls.Add(new TabPage("MULTIPLEXER " + item.Value));
		}
	}

	private void InitGroupTabControl()
	{
		slGroup.Clear();
		for (int i = 0; i < ori.MultiDUTConfigItems.GroupsSection.GroupList.Count; i++)
		{
			string groupID = ori.MultiDUTConfigItems.GroupsSection.GroupList[i].GroupID;
			slGroup.Add(int.Parse(groupID), groupID);
		}
		if (tbGroup.TabPages != null)
		{
			tbGroup.TabPages.Clear();
		}
		foreach (KeyValuePair<int, string> item in slGroup)
		{
			tbGroup.Controls.Add(new TabPage("GROUP " + item.Value));
		}
	}

	private void InitDutTabControl(int GroupIndex)
	{
		slDut.Clear();
		for (int i = 0; i < ori.MultiDUTConfigItems.GroupsSection.GroupList[GroupIndex].DutList.Count; i++)
		{
			string dutID = ori.MultiDUTConfigItems.GroupsSection.GroupList[GroupIndex].DutList[i].DutID;
			slDut.Add(int.Parse(dutID), dutID);
		}
		if (tbDut.TabPages != null)
		{
			tbDut.TabPages.Clear();
		}
		foreach (KeyValuePair<int, string> item in slDut)
		{
			tbDut.Controls.Add(new TabPage("DUT " + item.Value));
		}
		if (slDutMap[GroupIndex].Keys.Count != 0)
		{
			dutCM.Position = slDutMap[GroupIndex][slDutMap[GroupIndex].Keys[0]];
			UpdateIdPathGrid();
		}
	}

	private void UpdateRoutingGrid()
	{
		List<string> list = new List<string>();
		if (!string.IsNullOrEmpty(RoutingTxt))
		{
			list = SplitRouting(RoutingTxt);
			dgRouting.Rows.Clear();
			dgRouting.AutoGenerateColumns = false;
			foreach (string item in list)
			{
				dgRouting.Rows.Add(item);
			}
			dgRouting.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
		}
		else
		{
			dgRouting.Rows.Clear();
			dgRouting.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
		}
	}

	private void UpdateIdPathGrid()
	{
		List<string> list = new List<string>();
		List<string> list2 = new List<string>();
		if (string.IsNullOrEmpty(IdsTxt) || string.IsNullOrEmpty(PathsTxt))
		{
			return;
		}
		list = SplitIdPaths(IdsTxt);
		list2 = SplitIdPaths(PathsTxt);
		dgIdPathPair.Rows.Clear();
		UpdateMultiplexerIdMap();
		multiplexerIdsSrc.Clear();
		multiplexerIdsSrc.Add("None");
		foreach (int key in slMultiplexerMap.Keys)
		{
			multiplexerIdsSrc.Add(key.ToString());
		}
		PAIR_ID.Items.Clear();
		PAIR_ID.Items.AddRange(multiplexerIdsSrc.ToArray());
		multiplexerPathSrc.Clear();
		multiplexerPathSrc.Add("None");
		foreach (string item in list2)
		{
			multiplexerPathSrc.Add(item);
		}
		PAIR_PATHS.Items.Clear();
		PAIR_PATHS.Items.AddRange(multiplexerPathSrc.ToArray());
		for (int i = 0; i < list.Count; i++)
		{
			string text = list[i];
			string text2 = list2[i];
			if (list[i] == "-1")
			{
				text = "None";
				if (i == 0)
				{
					bNeedUpdateUsingMultiplex = false;
					cbUsingMultiplex.Checked = false;
					bNeedUpdateUsingMultiplex = true;
				}
			}
			else if (i == 0)
			{
				bNeedUpdateUsingMultiplex = false;
				cbUsingMultiplex.Checked = true;
				bNeedUpdateUsingMultiplex = true;
			}
			if (list2[i] == "-1")
			{
				text2 = "None";
			}
			dgIdPathPair.Rows.Add(text, text2);
		}
		dgIdPathPair.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
	}

	private void InitVar(RootConfig cfg)
	{
		RoutingTxt = "";
		infoItem = null;
		RootConfigAllPanel[] panel = cfg.All[0].Panel;
		foreach (RootConfigAllPanel rootConfigAllPanel in panel)
		{
			if (cfg.Station == rootConfigAllPanel.Name)
			{
				if (rootConfigAllPanel.File.Length > 0)
				{
					TargetFile = Common.GetPath(rootConfigAllPanel.File[0].Value);
				}
				if (rootConfigAllPanel.InfoItem.Length != 0)
				{
					infoItem = rootConfigAllPanel.InfoItem;
				}
			}
		}
		DirectoryInfo directoryInfo = new DirectoryInfo(Path.Combine(Application.StartupPath, "..\\Databases"));
		FileInfo[] files = directoryInfo.GetFiles();
		foreach (FileInfo fileInfo in files)
		{
			if (fileInfo.Name.Contains("MultiplexManagerConfigFile"))
			{
				cmbSrcfile.Items.Add(fileInfo.Name);
			}
		}
		if (File.Exists(TargetFile))
		{
			if (LoadTargetFile(TargetFile))
			{
				BindingUI();
				InitControls();
			}
			else
			{
				ClearControls();
			}
		}
		else
		{
			plMultiplexer.Enabled = false;
			plGroup.Enabled = false;
		}
	}

	private List<string> SplitRouting(string strRouting)
	{
		strRouting = strRouting.Replace("\r", "");
		strRouting = strRouting.Replace("\n", "");
		strRouting = strRouting.Replace("\t", "");
		strRouting = strRouting.Replace(" ", "");
		string[] source = strRouting.Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
		return source.ToList();
	}

	private void SaveRouting()
	{
		string text = "";
		for (int i = 0; i < dgRouting.Rows.Count - 1; i++)
		{
			if (dgRouting.Rows[i].Cells[0].Value != null)
			{
				text = text + dgRouting.Rows[i].Cells[0].Value.ToString() + ";";
			}
		}
		if (text != "")
		{
			text = text.Substring(0, text.Length - 1);
		}
		RoutingTxt = text;
		bsPorts.EndEdit();
		bsMultiplex.EndEdit();
	}

	private List<string> SplitIdPaths(string strIdsOrPaths)
	{
		strIdsOrPaths = strIdsOrPaths.Replace("\r", "");
		strIdsOrPaths = strIdsOrPaths.Replace("\n", "");
		strIdsOrPaths = strIdsOrPaths.Replace("\t", "");
		strIdsOrPaths = strIdsOrPaths.Replace(" ", "");
		string[] source = strIdsOrPaths.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
		return source.ToList();
	}

	private void SaveIdPaths()
	{
		string text = "";
		string text2 = "";
		dgIdPathPair.Refresh();
		for (int i = 0; i < dgIdPathPair.Rows.Count - 1; i++)
		{
			string text3 = dgIdPathPair.Rows[i].Cells[0].FormattedValue.ToString();
			if (text3 == "None")
			{
				text3 = "-1";
			}
			text = text + text3 + ",";
			text3 = dgIdPathPair.Rows[i].Cells[1].FormattedValue.ToString();
			if (text3 == "None")
			{
				text3 = "-1";
			}
			text2 = text2 + text3 + ",";
		}
		if (text != "")
		{
			text = text.Substring(0, text.Length - 1);
		}
		if (text2 != "")
		{
			text2 = text2.Substring(0, text2.Length - 1);
		}
		IdsTxt = text;
		PathsTxt = text2;
		bsDUT.EndEdit();
	}

	private void UpdateGroupDutIdMap()
	{
		if (ori.MultiDUTConfigItems == null)
		{
			return;
		}
		slGroupMap.Clear();
		slDutMap.Clear();
		for (int i = 0; i < ori.MultiDUTConfigItems.GroupsSection.GroupList.Count; i++)
		{
			slGroupMap.Add(int.Parse(ori.MultiDUTConfigItems.GroupsSection.GroupList[i].GroupID), i);
			SortedList<int, int> sortedList = new SortedList<int, int>();
			for (int j = 0; j < ori.MultiDUTConfigItems.GroupsSection.GroupList[i].DutList.Count; j++)
			{
				sortedList.Add(int.Parse(ori.MultiDUTConfigItems.GroupsSection.GroupList[i].DutList[j].DutID), j);
			}
			slDutMap.Add(i, sortedList);
		}
	}

	private void UpdateDutGroupMap()
	{
		slDutGroupMap.Clear();
		for (int i = 0; i < slDutMap.Count; i++)
		{
			for (int j = 0; j < slDutMap[i].Count; j++)
			{
				slDutGroupMap.Add(slDutMap[i].Keys[j], i);
			}
		}
	}

	private void UpdateMultiplexerIdMap()
	{
		if (ori.MultiDUTConfigItems != null)
		{
			slMultiplexerMap.Clear();
			for (int i = 0; i < ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count; i++)
			{
				slMultiplexerMap.Add(int.Parse(ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].MultiplexerID), i);
			}
		}
	}

	private bool MultiplexerInUse()
	{
		string text = "";
		string text2 = tbMultiplexer.SelectedTab.Text.Replace("MULTIPLEXER ", "");
		if (ori.MultiDUTConfigItems != null && ori.MultiDUTConfigItems.GroupsSection != null && ori.MultiDUTConfigItems.GroupsSection.GroupList.Count != 0)
		{
			int num = 0;
			int num2 = 0;
			foreach (Group group in ori.MultiDUTConfigItems.GroupsSection.GroupList)
			{
				num2 = 0;
				if (group.DutList.Count != 0)
				{
					foreach (Dut dut in group.DutList)
					{
						if (dut.MultiplexerIDs.Length != 0)
						{
							string[] array = dut.MultiplexerIDs.Split(',');
							for (int i = 0; i < array.Length; i++)
							{
								if (text2 == array[i])
								{
									string text3 = text;
									text = text3 + "MULTIPLEXER " + text2 + " in use : GROUP " + ori.MultiDUTConfigItems.GroupsSection.GroupList[num].GroupID + " DUT " + ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList[num2].DutID + "\n";
									break;
								}
							}
						}
						num2++;
					}
				}
				num++;
			}
		}
		if (text.Length != 0)
		{
			MessageBox.Show(text);
			return true;
		}
		return false;
	}

	private void MultiplexPanel_Load(object sender, EventArgs e)
	{
		if (beRefreashUI)
		{
			InitControls();
		}
	}

	private void btnBrowseDllPath_Click(object sender, EventArgs e)
	{
		try
		{
			OpenFileDialog openFileDialog = new OpenFileDialog();
			openFileDialog.Filter = "dll(*.dll)|*.dll";
			if (openFileDialog.ShowDialog() == DialogResult.OK)
			{
				tbDll.Text = openFileDialog.FileName;
				bsMultiplex.EndEdit();
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void tbGroup_SelectedIndexChanged(object sender, EventArgs e)
	{
		tbDut.SelectedTab = null;
		try
		{
			if (tbGroup.SelectedTab != null)
			{
				dgIdPathPair.Rows.Clear();
				int key = int.Parse(tbGroup.SelectedTab.Text.Replace("GROUP ", ""));
				int num = slGroupMap[key];
				groupCM.Position = num;
				currentGroupId = key;
				InitDutTabControl(num);
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void tbDut_SelectedIndexChanged(object sender, EventArgs e)
	{
		try
		{
			if (tbDut.SelectedTab != null && tbGroup.SelectedTab != null && sender != null)
			{
				int key = int.Parse(tbGroup.SelectedTab.Text.Replace("GROUP ", ""));
				int key2 = slGroupMap[key];
				int key3 = int.Parse(tbDut.SelectedTab.Text.Replace("DUT ", ""));
				dutCM.Position = slDutMap[key2][key3];
				currentDutId = key3;
				UpdateIdPathGrid();
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void tbMultiplexer_SelectedIndexChanged(object sender, EventArgs e)
	{
		try
		{
			if (tbMultiplexer.SelectedTab != null)
			{
				int key = int.Parse(tbMultiplexer.SelectedTab.Text.Replace("MULTIPLEXER ", ""));
				multiplexCM.Position = slMultiplexerMap[key];
				currentMultiplexerId = key;
				UpdateRoutingGrid();
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void dgRouting_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
	{
		dgRouting.TopLeftHeaderCell.Value = "DUT";
		try
		{
			e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, new SolidBrush(Color.CadetBlue), e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
		}
		catch (Exception ex)
		{
			MessageBox.Show("Add Row number fail" + ex.Message, "Operate fail");
		}
	}

	private void btnDelGroup_Click(object sender, EventArgs e)
	{
		if (tbGroup.SelectedTab == null || MessageBox.Show("Delete " + tbGroup.SelectedTab.Text + " ?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
		{
			return;
		}
		int key = int.Parse(tbGroup.SelectedTab.Text.Replace("GROUP ", ""));
		int index = slGroupMap[key];
		ori.MultiDUTConfigItems.GroupsSection.GroupList.RemoveAt(index);
		UpdateGroupDutIdMap();
		foreach (TabPage tabPage in tbGroup.TabPages)
		{
			if (tbGroup.SelectedTab.Text == tabPage.Text)
			{
				dgIdPathPair.Rows.Clear();
				tbDut.TabPages.Clear();
				tbGroup.TabPages.Remove(tabPage);
				break;
			}
		}
	}

	private void btnDelDut_Click(object sender, EventArgs e)
	{
		if (tbDut.SelectedTab == null || MessageBox.Show("Delete " + tbDut.SelectedTab.Text + " ?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
		{
			return;
		}
		int key = int.Parse(tbGroup.SelectedTab.Text.Replace("GROUP ", ""));
		int num = slGroupMap[key];
		int key2 = int.Parse(tbDut.SelectedTab.Text.Replace("DUT ", ""));
		int index = slDutMap[num][key2];
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList.RemoveAt(index);
		UpdateGroupDutIdMap();
		foreach (TabPage tabPage in tbDut.TabPages)
		{
			if (tbDut.SelectedTab.Text == tabPage.Text)
			{
				dgIdPathPair.Rows.Clear();
				tbDut.TabPages.Remove(tabPage);
				break;
			}
		}
	}

	private void btnDelMultiplexer_Click(object sender, EventArgs e)
	{
		if (tbMultiplexer.SelectedTab == null || MultiplexerInUse() || MessageBox.Show("Delete " + tbMultiplexer.SelectedTab.Text + " ?", "Delete Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) != DialogResult.Yes)
		{
			return;
		}
		int key = int.Parse(tbMultiplexer.SelectedTab.Text.Replace("MULTIPLEXER ", ""));
		int index = slMultiplexerMap[key];
		ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.RemoveAt(index);
		UpdateMultiplexerIdMap();
		foreach (TabPage tabPage in tbMultiplexer.TabPages)
		{
			if (tbMultiplexer.SelectedTab.Text == tabPage.Text)
			{
				dgRouting.Rows.Clear();
				tbMultiplexer.TabPages.Remove(tabPage);
				break;
			}
		}
	}

	private void btnAddMultiplexer_Click(object sender, EventArgs e)
	{
		using MultiplexerAddForm multiplexerAddForm = new MultiplexerAddForm(Common.EditTypes.MULTIPLEXER, slMultiplexerMap);
		if (multiplexerAddForm.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		int num = int.Parse(multiplexerAddForm.Tag.ToString());
		ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.AddNew();
		int count = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count;
		ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[count - 1].MultiplexerID = num.ToString();
		ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[count - 1].SimulationMode = "NO";
		UpdateMultiplexerIdMap();
		InitMultiplexTabControl();
		foreach (TabPage tabPage in tbMultiplexer.TabPages)
		{
			if (tabPage.Text == "MULTIPLEXER " + num)
			{
				dgRouting.Rows.Clear();
				tbMultiplexer.SelectedTab = tabPage;
				break;
			}
		}
	}

	private void btnAddDut_Click(object sender, EventArgs e)
	{
		if (tbGroup.SelectedTab == null)
		{
			return;
		}
		int key = int.Parse(tbGroup.SelectedTab.Text.Replace("GROUP ", ""));
		int num = slGroupMap[key];
		UpdateDutGroupMap();
		using MultiplexerAddForm multiplexerAddForm = new MultiplexerAddForm(Common.EditTypes.DUT, slDutGroupMap, slDutMap, slGroupMap);
		if (multiplexerAddForm.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		int key2 = int.Parse(multiplexerAddForm.Tag.ToString());
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList.AddNew();
		int count = ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList.Count;
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList[count - 1].DutID = key2.ToString();
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList[count - 1].MultiplexerIDs = "-1";
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList[count - 1].MultiplexerPaths = "-1";
		UpdateGroupDutIdMap();
		InitDutTabControl(num);
		foreach (TabPage tabPage in tbDut.TabPages)
		{
			if (tabPage.Text == "DUT " + key2)
			{
				dgIdPathPair.Rows.Clear();
				tbDut.SelectedTab = tabPage;
				dutCM.Position = slDutMap[num][key2];
				currentDutId = key2;
				break;
			}
		}
	}

	private void btnPasteDut_Click(object sender, EventArgs e)
	{
		if (ori.MultiDUTConfigItems.GroupsSection.GroupList.Count == 1)
		{
			return;
		}
		using MultiplexerMoveDutForm multiplexerMoveDutForm = new MultiplexerMoveDutForm(slGroupMap, slDutMap, currentGroupId);
		if (multiplexerMoveDutForm.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		dgIdPathPair.Rows.Clear();
		string[] array = multiplexerMoveDutForm.Tag.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
		int key = int.Parse(array[0]);
		int key2 = int.Parse(array[1]);
		int num = slGroupMap[key];
		int index = slDutMap[num][key2];
		int num2 = slGroupMap[currentGroupId];
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num2].DutList.AddNew();
		int count = ori.MultiDUTConfigItems.GroupsSection.GroupList[num2].DutList.Count;
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num2].DutList[count - 1] = ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList[index];
		ori.MultiDUTConfigItems.GroupsSection.GroupList[num].DutList.RemoveAt(index);
		UpdateGroupDutIdMap();
		InitDutTabControl(num2);
		foreach (TabPage tabPage in tbDut.TabPages)
		{
			if (tabPage.Text == "DUT " + key2)
			{
				tbDut.SelectedTab = tabPage;
				dutCM.Position = slDutMap[num2][key2];
				currentDutId = key2;
				break;
			}
		}
	}

	private void btnAddGroup_Click(object sender, EventArgs e)
	{
		using MultiplexerAddForm multiplexerAddForm = new MultiplexerAddForm(Common.EditTypes.GROUP, slGroupMap);
		if (multiplexerAddForm.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		int num = int.Parse(multiplexerAddForm.Tag.ToString());
		ori.MultiDUTConfigItems.GroupsSection.GroupList.AddNew();
		int count = ori.MultiDUTConfigItems.GroupsSection.GroupList.Count;
		ori.MultiDUTConfigItems.GroupsSection.GroupList[count - 1].GroupID = num.ToString();
		UpdateGroupDutIdMap();
		InitGroupTabControl();
		foreach (TabPage tabPage in tbGroup.TabPages)
		{
			if (tabPage.Text == "GROUP " + num)
			{
				dgIdPathPair.Rows.Clear();
				tbGroup.SelectedTab = tabPage;
				break;
			}
		}
		btnAddDut_Click(null, null);
	}

	private void dgRouting_Validated(object sender, EventArgs e)
	{
		SaveRouting();
	}

	private void dgRouting_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
	{
		input = (TextBox)e.Control;
		input.KeyPress += input_KeyPress;
	}

	private void input_KeyPress(object sender, KeyPressEventArgs e)
	{
		if (e.KeyChar == ';')
		{
			e.Handled = true;
		}
	}

	private void dgRouting_CellEndEdit(object sender, DataGridViewCellEventArgs e)
	{
		input.KeyPress -= input_KeyPress;
	}

	private void dgIdPathPair_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
	{
		try
		{
			e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, new SolidBrush(Color.CadetBlue), e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + 5);
		}
		catch (Exception ex)
		{
			MessageBox.Show("Add Row number fail" + ex.Message, "Operate fail");
		}
	}

	private void dgIdPathPair_CellClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex == -1)
		{
			return;
		}
		if (e.ColumnIndex == 0)
		{
			UpdateMultiplexerIdMap();
			multiplexerIdsSrc.Clear();
			multiplexerIdsSrc.Add("None");
			foreach (int key in slMultiplexerMap.Keys)
			{
				multiplexerIdsSrc.Add(key.ToString());
			}
			PAIR_ID.Items.Clear();
			PAIR_ID.Items.AddRange(multiplexerIdsSrc.ToArray());
		}
		else
		{
			if (e.ColumnIndex != 1 || e.RowIndex >= dgIdPathPair.Rows.Count - 1)
			{
				return;
			}
			string text = dgIdPathPair.Rows[e.RowIndex].Cells[0].FormattedValue.ToString();
			if (text == "None")
			{
				multiplexerPathSrc.Clear();
				multiplexerPathSrc.Add("None");
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[e.RowIndex].Cells[1]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[e.RowIndex].Cells[1]).Items.AddRange(multiplexerPathSrc.ToArray());
			}
			else
			{
				if (text == null || ori.MultiDUTConfigItems == null || ori.MultiDUTConfigItems.MultiplexersSection == null)
				{
					return;
				}
				int count = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList.Count;
				if (count <= 0)
				{
					return;
				}
				for (int i = 0; i < count; i++)
				{
					if (!(ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].MultiplexerID == text))
					{
						continue;
					}
					string routingConfig = ori.MultiDUTConfigItems.MultiplexersSection.MultiplexerList[i].RoutingConfigList[0].RoutingConfig;
					if (!string.IsNullOrEmpty(routingConfig))
					{
						int count2 = SplitRouting(routingConfig).Count;
						multiplexerPathSrc.Clear();
						for (int j = 1; j <= count2; j++)
						{
							multiplexerPathSrc.Add(j.ToString());
						}
						((DataGridViewComboBoxCell)dgIdPathPair.Rows[e.RowIndex].Cells[1]).Items.Clear();
						((DataGridViewComboBoxCell)dgIdPathPair.Rows[e.RowIndex].Cells[1]).Items.AddRange(multiplexerPathSrc.ToArray());
						break;
					}
				}
			}
		}
	}

	private void dgIdPathPair_DataError(object sender, DataGridViewDataErrorEventArgs e)
	{
	}

	private void dgIdPathPair_Validated(object sender, EventArgs e)
	{
		SaveIdPaths();
	}

	private void dgIdPathPair_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
	{
		DataGridView dataGridView = (DataGridView)sender;
		ComboBox comboBox = new ComboBox();
		if (dataGridView.CurrentCell.GetType().Name == "DataGridViewComboBoxCell" && dataGridView.CurrentCell.ColumnIndex == 0 && dataGridView.CurrentCell.RowIndex != -1 && e.Control is ComboBox comboBox2)
		{
			try
			{
				comboBox2.SelectedIndexChanged -= comboBox_SelectedIndexChanged;
				comboBox2.SelectedIndexChanged += comboBox_SelectedIndexChanged;
				comboBox2.DropDown -= comboBox_DropDown;
				comboBox2.DropDown += comboBox_DropDown;
			}
			catch
			{
			}
		}
	}

	private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
	{
		if (dgIdPathPair.CurrentCell.ColumnIndex == 0)
		{
			ComboBox comboBox = (ComboBox)sender;
			if (comboBox.Text == "None")
			{
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1]).Items.AddRange("None");
				dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1].Value = "None";
			}
			else
			{
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1]).Items.AddRange("1");
				dgIdPathPair.Rows[dgIdPathPair.CurrentCell.RowIndex].Cells[1].Value = "1";
			}
		}
	}

	private void comboBox_DropDown(object sender, EventArgs e)
	{
		((ComboBox)sender).BackColor = Color.White;
	}

	private void OnFileChange(string resfile)
	{
		if (this.TargetFileChanged != null)
		{
			this.TargetFileChanged(resfile);
		}
	}

	public void TickFileChange()
	{
		OnFileChange(TargetFile);
	}

	private void cmbPorts_SelectedIndexChanged(object sender, EventArgs e)
	{
		try
		{
			if (portCM != null && sender != null)
			{
				int selectedIndex = cmbPorts.SelectedIndex;
				if (portCM.Position != selectedIndex)
				{
					portCM.Position = selectedIndex;
				}
				if ((Routing_Config)bsPorts.Current != null)
				{
					RoutingTxt = ((Routing_Config)bsPorts.Current).RoutingConfig;
				}
				else
				{
					RoutingTxt = "";
				}
				UpdateRoutingGrid();
			}
		}
		catch (Exception ex)
		{
			MessageBox.Show(ex.Message);
		}
	}

	private void btnAddRC_Click(object sender, EventArgs e)
	{
		using RoutingCfgEditPorts routingCfgEditPorts = new RoutingCfgEditPorts("", "", infoItem, bNew: true);
		if (routingCfgEditPorts.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		string text = "";
		string text2 = "";
		string[] array = routingCfgEditPorts.Tag.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
		if (array.Length == 1)
		{
			text = array[0];
			text2 = "";
		}
		else
		{
			if (array.Length != 2)
			{
				return;
			}
			text = array[0];
			text2 = array[1];
		}
		bsPorts.AddNew();
		int count = ((Multiplexer)multiplexCM.Current).RoutingConfigList.Count;
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].PORTS = text;
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].RoutingConfig = "";
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].BANDS = text2;
		tbBands.Text = text2;
		bsPorts.EndEdit();
		portCM.Position = count - 1;
	}

	private void btnDelRC_Click(object sender, EventArgs e)
	{
		if (MessageBox.Show("Delete selected ROUTING_CONFIG ?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
		{
			int count = ((Multiplexer)multiplexCM.Current).RoutingConfigList.Count;
			if (count > 1)
			{
				bsPorts.RemoveCurrent();
				portCM.Position = count - 1;
			}
			else
			{
				MessageBox.Show("Fail to delete. At least 1 ROUTING_CONFIG section!");
			}
		}
	}

	private void btnEdit_Click(object sender, EventArgs e)
	{
		SaveRouting();
		using RoutingCfgEditPorts routingCfgEditPorts = new RoutingCfgEditPorts(cmbPorts.Text, tbBands.Text, infoItem, bNew: false);
		if (routingCfgEditPorts.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		string text = "";
		string text2 = "";
		string text3 = "";
		string[] array = routingCfgEditPorts.Tag.ToString().Split(new char[1] { ';' }, StringSplitOptions.RemoveEmptyEntries);
		if (array.Length == 1)
		{
			text2 = array[0];
			text3 = "";
		}
		else
		{
			if (array.Length != 2)
			{
				return;
			}
			text2 = array[0];
			text3 = array[1];
		}
		if (portCM.Position == -1)
		{
			bsPorts.AddNew();
			int count = ((Multiplexer)multiplexCM.Current).RoutingConfigList.Count;
			((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].PORTS = text2;
			((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].BANDS = text3;
			((Multiplexer)multiplexCM.Current).RoutingConfigList[count - 1].RoutingConfig = "";
			portCM.Position = count - 1;
			return;
		}
		text = ((Routing_Config)portCM.Current).RoutingConfig;
		int position = bsPorts.Position;
		bsPorts.AddNew();
		int count2 = ((Multiplexer)multiplexCM.Current).RoutingConfigList.Count;
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count2 - 1].PORTS = text2;
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count2 - 1].BANDS = text3;
		((Multiplexer)multiplexCM.Current).RoutingConfigList[count2 - 1].RoutingConfig = text;
		RoutingTxt = text;
		if (position != -1)
		{
			bsPorts.RemoveAt(position);
		}
	}

	private void cmbSrcfile_SelectedIndexChanged(object sender, EventArgs e)
	{
		try
		{
			string text = Path.Combine(Application.StartupPath, "..\\Databases", cmbSrcfile.Text);
			tbSrcfile.Text = text.Replace("bin\\..\\", "");
			if (LoadTargetFile(text))
			{
				TargetFile = Path.Combine(Application.StartupPath, "..\\Databases\\MultiplexManagerConfigFile.xml");
				tbTarget.Text = TargetFile.Replace("bin\\..\\", "");
				BindingUI();
				InitControls();
			}
			else
			{
				ClearControls();
			}
		}
		catch
		{
		}
	}

	private void btnBandEdit_Click(object sender, EventArgs e)
	{
	}

	private void btnBandNew_Click(object sender, EventArgs e)
	{
	}

	private void btnBandDelete_Click(object sender, EventArgs e)
	{
	}

	private void cbUsingMultiplex_CheckedChanged(object sender, EventArgs e)
	{
		if (bNeedUpdateUsingMultiplex && bSimpleMode)
		{
			if (cbUsingMultiplex.Checked)
			{
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[0]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[0]).Items.AddRange("1");
				dgIdPathPair.Rows[0].Cells[0].Value = "1";
				string text = tbDut.SelectedTab.Text.Replace("DUT ", "");
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[1]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[1]).Items.AddRange(text);
				dgIdPathPair.Rows[0].Cells[1].Value = text;
				SaveIdPaths();
			}
			else
			{
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[1]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[1]).Items.AddRange("None");
				dgIdPathPair.Rows[0].Cells[1].Value = "None";
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[0]).Items.Clear();
				((DataGridViewComboBoxCell)dgIdPathPair.Rows[0].Cells[0]).Items.AddRange("None");
				dgIdPathPair.Rows[0].Cells[0].Value = "None";
				SaveIdPaths();
			}
		}
	}

	private void cmbBands_SelectedIndexChanged(object sender, EventArgs e)
	{
		dgIdPathPair.Visible = cbShowDetail.Checked;
	}

	private void cbShowDetail_CheckedChanged(object sender, EventArgs e)
	{
		dgIdPathPair.Visible = cbShowDetail.Checked;
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(QDART_MFG_CfgEditor.MultiplexPanel));
		this.tbTarget = new System.Windows.Forms.TextBox();
		this.plGroup = new System.Windows.Forms.Panel();
		this.btnDelGroup = new System.Windows.Forms.Button();
		this.btnAddGroup = new System.Windows.Forms.Button();
		this.plDut = new System.Windows.Forms.Panel();
		this.btnDelDut = new System.Windows.Forms.Button();
		this.btnPasteDut = new System.Windows.Forms.Button();
		this.btnAddDut = new System.Windows.Forms.Button();
		this.plDutCfg = new System.Windows.Forms.Panel();
		this.cbShowDetail = new System.Windows.Forms.CheckBox();
		this.cbUsingMultiplex = new System.Windows.Forms.CheckBox();
		this.dgIdPathPair = new System.Windows.Forms.DataGridView();
		this.PAIR_ID = new System.Windows.Forms.DataGridViewComboBoxColumn();
		this.PAIR_PATHS = new System.Windows.Forms.DataGridViewComboBoxColumn();
		this.tbDut = new System.Windows.Forms.TabControl();
		this.tabPage3 = new System.Windows.Forms.TabPage();
		this.tabPage4 = new System.Windows.Forms.TabPage();
		this.tbGroup = new System.Windows.Forms.TabControl();
		this.tabPage1 = new System.Windows.Forms.TabPage();
		this.tabPage2 = new System.Windows.Forms.TabPage();
		this.btnDelMultiplexer = new System.Windows.Forms.Button();
		this.btnAddMultiplexer = new System.Windows.Forms.Button();
		this.plMultiplexerCfg = new System.Windows.Forms.Panel();
		this.lbBand = new System.Windows.Forms.Label();
		this.tbBands = new System.Windows.Forms.TextBox();
		this.tbDescription = new System.Windows.Forms.TextBox();
		this.PORT = new System.Windows.Forms.Label();
		this.btnDelRC = new System.Windows.Forms.Button();
		this.btnEdit = new System.Windows.Forms.Button();
		this.btnNewRC = new System.Windows.Forms.Button();
		this.cmbPorts = new System.Windows.Forms.ComboBox();
		this.dgRouting = new System.Windows.Forms.DataGridView();
		this.Paths = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.btnDll = new System.Windows.Forms.Button();
		this.tbBusCfg = new System.Windows.Forms.TextBox();
		this.tbDll = new System.Windows.Forms.TextBox();
		this.cbSimulation = new System.Windows.Forms.ComboBox();
		this.label7 = new System.Windows.Forms.Label();
		this.label6 = new System.Windows.Forms.Label();
		this.label4 = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		this.label5 = new System.Windows.Forms.Label();
		this.tbMultiplexer = new System.Windows.Forms.TabControl();
		this.tabPage5 = new System.Windows.Forms.TabPage();
		this.tabPage6 = new System.Windows.Forms.TabPage();
		this.plMultiplexer = new System.Windows.Forms.Panel();
		this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
		this.panel1 = new System.Windows.Forms.Panel();
		this.cmbSrcfile = new System.Windows.Forms.ComboBox();
		this.lbSrcfile = new System.Windows.Forms.Label();
		this.lbFile = new System.Windows.Forms.Label();
		this.tbSrcfile = new System.Windows.Forms.TextBox();
		this.plGroup.SuspendLayout();
		this.plDut.SuspendLayout();
		this.plDutCfg.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgIdPathPair).BeginInit();
		this.tbDut.SuspendLayout();
		this.tbGroup.SuspendLayout();
		this.plMultiplexerCfg.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgRouting).BeginInit();
		this.tbMultiplexer.SuspendLayout();
		this.plMultiplexer.SuspendLayout();
		this.panel1.SuspendLayout();
		base.SuspendLayout();
		this.tbTarget.Cursor = System.Windows.Forms.Cursors.Arrow;
		this.tbTarget.Location = new System.Drawing.Point(7, 22);
		this.tbTarget.Multiline = true;
		this.tbTarget.Name = "tbTarget";
		this.tbTarget.ReadOnly = true;
		this.tbTarget.Size = new System.Drawing.Size(359, 37);
		this.tbTarget.TabIndex = 0;
		this.tbTarget.TabStop = false;
		this.plGroup.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.plGroup.Controls.Add(this.btnDelGroup);
		this.plGroup.Controls.Add(this.btnAddGroup);
		this.plGroup.Controls.Add(this.plDut);
		this.plGroup.Controls.Add(this.tbGroup);
		this.plGroup.Location = new System.Drawing.Point(3, 153);
		this.plGroup.Name = "plGroup";
		this.plGroup.Size = new System.Drawing.Size(387, 324);
		this.plGroup.TabIndex = 3;
		this.btnDelGroup.Location = new System.Drawing.Point(350, 3);
		this.btnDelGroup.Name = "btnDelGroup";
		this.btnDelGroup.Size = new System.Drawing.Size(29, 23);
		this.btnDelGroup.TabIndex = 2;
		this.btnDelGroup.Text = "x";
		this.toolTip1.SetToolTip(this.btnDelGroup, "Delete selected GROUP");
		this.btnDelGroup.UseVisualStyleBackColor = true;
		this.btnDelGroup.Click += new System.EventHandler(btnDelGroup_Click);
		this.btnAddGroup.Location = new System.Drawing.Point(306, 3);
		this.btnAddGroup.Name = "btnAddGroup";
		this.btnAddGroup.Size = new System.Drawing.Size(29, 23);
		this.btnAddGroup.TabIndex = 2;
		this.btnAddGroup.Text = "+";
		this.toolTip1.SetToolTip(this.btnAddGroup, "Add a new GROUP");
		this.btnAddGroup.UseVisualStyleBackColor = true;
		this.btnAddGroup.Click += new System.EventHandler(btnAddGroup_Click);
		this.plDut.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.plDut.Controls.Add(this.btnDelDut);
		this.plDut.Controls.Add(this.btnPasteDut);
		this.plDut.Controls.Add(this.btnAddDut);
		this.plDut.Controls.Add(this.plDutCfg);
		this.plDut.Controls.Add(this.tbDut);
		this.plDut.Location = new System.Drawing.Point(3, 26);
		this.plDut.Name = "plDut";
		this.plDut.Size = new System.Drawing.Size(380, 294);
		this.plDut.TabIndex = 1;
		this.btnDelDut.Location = new System.Drawing.Point(346, 3);
		this.btnDelDut.Name = "btnDelDut";
		this.btnDelDut.Size = new System.Drawing.Size(29, 23);
		this.btnDelDut.TabIndex = 4;
		this.btnDelDut.Text = "x";
		this.toolTip1.SetToolTip(this.btnDelDut, "Delete selected DUT");
		this.btnDelDut.UseVisualStyleBackColor = true;
		this.btnDelDut.Click += new System.EventHandler(btnDelDut_Click);
		this.btnPasteDut.Location = new System.Drawing.Point(257, 3);
		this.btnPasteDut.Name = "btnPasteDut";
		this.btnPasteDut.Size = new System.Drawing.Size(31, 23);
		this.btnPasteDut.TabIndex = 3;
		this.btnPasteDut.Text = "<->";
		this.toolTip1.SetToolTip(this.btnPasteDut, "Move DUT from another GROUP");
		this.btnPasteDut.UseVisualStyleBackColor = true;
		this.btnPasteDut.Click += new System.EventHandler(btnPasteDut_Click);
		this.btnAddDut.Location = new System.Drawing.Point(302, 3);
		this.btnAddDut.Name = "btnAddDut";
		this.btnAddDut.Size = new System.Drawing.Size(29, 23);
		this.btnAddDut.TabIndex = 3;
		this.btnAddDut.Text = "+";
		this.toolTip1.SetToolTip(this.btnAddDut, "Add a new DUT");
		this.btnAddDut.UseVisualStyleBackColor = true;
		this.btnAddDut.Click += new System.EventHandler(btnAddDut_Click);
		this.plDutCfg.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.plDutCfg.Controls.Add(this.cbShowDetail);
		this.plDutCfg.Controls.Add(this.cbUsingMultiplex);
		this.plDutCfg.Controls.Add(this.dgIdPathPair);
		this.plDutCfg.Location = new System.Drawing.Point(13, 26);
		this.plDutCfg.Name = "plDutCfg";
		this.plDutCfg.Size = new System.Drawing.Size(362, 247);
		this.plDutCfg.TabIndex = 1;
		this.cbShowDetail.AutoSize = true;
		this.cbShowDetail.Location = new System.Drawing.Point(15, 63);
		this.cbShowDetail.Name = "cbShowDetail";
		this.cbShowDetail.Size = new System.Drawing.Size(93, 17);
		this.cbShowDetail.TabIndex = 4;
		this.cbShowDetail.Text = "* Show details";
		this.toolTip1.SetToolTip(this.cbShowDetail, "Advanced usage");
		this.cbShowDetail.UseVisualStyleBackColor = true;
		this.cbShowDetail.CheckStateChanged += new System.EventHandler(cbShowDetail_CheckedChanged);
		this.cbUsingMultiplex.AutoSize = true;
		this.cbUsingMultiplex.Location = new System.Drawing.Point(15, 25);
		this.cbUsingMultiplex.Name = "cbUsingMultiplex";
		this.cbUsingMultiplex.Size = new System.Drawing.Size(131, 17);
		this.cbUsingMultiplex.TabIndex = 4;
		this.cbUsingMultiplex.Text = "Using MULTIPLEXER";
		this.toolTip1.SetToolTip(this.cbUsingMultiplex, "Using RF Switch Port Box");
		this.cbUsingMultiplex.UseVisualStyleBackColor = true;
		this.cbUsingMultiplex.CheckedChanged += new System.EventHandler(cbUsingMultiplex_CheckedChanged);
		this.dgIdPathPair.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader;
		this.dgIdPathPair.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgIdPathPair.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgIdPathPair.Columns.AddRange(this.PAIR_ID, this.PAIR_PATHS);
		this.dgIdPathPair.Location = new System.Drawing.Point(15, 88);
		this.dgIdPathPair.Name = "dgIdPathPair";
		this.dgIdPathPair.Size = new System.Drawing.Size(315, 105);
		this.dgIdPathPair.TabIndex = 3;
		this.dgIdPathPair.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgIdPathPair_CellClick);
		this.dgIdPathPair.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(dgIdPathPair_DataError);
		this.dgIdPathPair.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(dgIdPathPair_EditingControlShowing);
		this.dgIdPathPair.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(dgIdPathPair_RowPostPaint);
		this.dgIdPathPair.Validated += new System.EventHandler(dgIdPathPair_Validated);
		this.PAIR_ID.HeaderText = "MULTIPLEXER_IDS";
		this.PAIR_ID.Name = "PAIR_ID";
		this.PAIR_ID.Width = 112;
		this.PAIR_PATHS.HeaderText = "MULTIPLEXER_PATHS";
		this.PAIR_PATHS.Name = "PAIR_PATHS";
		this.PAIR_PATHS.Width = 130;
		this.tbDut.Controls.Add(this.tabPage3);
		this.tbDut.Controls.Add(this.tabPage4);
		this.tbDut.Location = new System.Drawing.Point(13, 6);
		this.tbDut.Name = "tbDut";
		this.tbDut.SelectedIndex = 0;
		this.tbDut.Size = new System.Drawing.Size(242, 20);
		this.tbDut.TabIndex = 0;
		this.tbDut.SelectedIndexChanged += new System.EventHandler(tbDut_SelectedIndexChanged);
		this.tabPage3.Location = new System.Drawing.Point(4, 22);
		this.tabPage3.Name = "tabPage3";
		this.tabPage3.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage3.Size = new System.Drawing.Size(234, 0);
		this.tabPage3.TabIndex = 0;
		this.tabPage3.Text = "DUT 1";
		this.tabPage3.UseVisualStyleBackColor = true;
		this.tabPage4.Location = new System.Drawing.Point(4, 22);
		this.tabPage4.Name = "tabPage4";
		this.tabPage4.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage4.Size = new System.Drawing.Size(234, 0);
		this.tabPage4.TabIndex = 1;
		this.tabPage4.Text = "DUT 2";
		this.tabPage4.UseVisualStyleBackColor = true;
		this.tbGroup.Controls.Add(this.tabPage1);
		this.tbGroup.Controls.Add(this.tabPage2);
		this.tbGroup.Location = new System.Drawing.Point(3, 7);
		this.tbGroup.Name = "tbGroup";
		this.tbGroup.SelectedIndex = 0;
		this.tbGroup.Size = new System.Drawing.Size(480, 19);
		this.tbGroup.TabIndex = 0;
		this.tbGroup.SelectedIndexChanged += new System.EventHandler(tbGroup_SelectedIndexChanged);
		this.tabPage1.Location = new System.Drawing.Point(4, 22);
		this.tabPage1.Name = "tabPage1";
		this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage1.Size = new System.Drawing.Size(472, 0);
		this.tabPage1.TabIndex = 0;
		this.tabPage1.Text = "GROUP 1";
		this.tabPage1.UseVisualStyleBackColor = true;
		this.tabPage2.Location = new System.Drawing.Point(4, 22);
		this.tabPage2.Name = "tabPage2";
		this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage2.Size = new System.Drawing.Size(472, 0);
		this.tabPage2.TabIndex = 1;
		this.tabPage2.Text = "GROUP 2";
		this.tabPage2.UseVisualStyleBackColor = true;
		this.btnDelMultiplexer.Location = new System.Drawing.Point(475, 5);
		this.btnDelMultiplexer.Name = "btnDelMultiplexer";
		this.btnDelMultiplexer.Size = new System.Drawing.Size(29, 23);
		this.btnDelMultiplexer.TabIndex = 8;
		this.btnDelMultiplexer.Text = "x";
		this.toolTip1.SetToolTip(this.btnDelMultiplexer, "Delete selected MULTIPLEXER");
		this.btnDelMultiplexer.UseVisualStyleBackColor = true;
		this.btnDelMultiplexer.Click += new System.EventHandler(btnDelMultiplexer_Click);
		this.btnAddMultiplexer.Location = new System.Drawing.Point(431, 5);
		this.btnAddMultiplexer.Name = "btnAddMultiplexer";
		this.btnAddMultiplexer.Size = new System.Drawing.Size(29, 23);
		this.btnAddMultiplexer.TabIndex = 7;
		this.btnAddMultiplexer.Text = "+";
		this.toolTip1.SetToolTip(this.btnAddMultiplexer, "Add a new MULTIPLEXER");
		this.btnAddMultiplexer.UseVisualStyleBackColor = true;
		this.btnAddMultiplexer.Click += new System.EventHandler(btnAddMultiplexer_Click);
		this.plMultiplexerCfg.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.plMultiplexerCfg.Controls.Add(this.lbBand);
		this.plMultiplexerCfg.Controls.Add(this.tbBands);
		this.plMultiplexerCfg.Controls.Add(this.tbDescription);
		this.plMultiplexerCfg.Controls.Add(this.PORT);
		this.plMultiplexerCfg.Controls.Add(this.btnDelRC);
		this.plMultiplexerCfg.Controls.Add(this.btnEdit);
		this.plMultiplexerCfg.Controls.Add(this.btnNewRC);
		this.plMultiplexerCfg.Controls.Add(this.cmbPorts);
		this.plMultiplexerCfg.Controls.Add(this.dgRouting);
		this.plMultiplexerCfg.Controls.Add(this.btnDll);
		this.plMultiplexerCfg.Controls.Add(this.tbBusCfg);
		this.plMultiplexerCfg.Controls.Add(this.tbDll);
		this.plMultiplexerCfg.Controls.Add(this.cbSimulation);
		this.plMultiplexerCfg.Controls.Add(this.label7);
		this.plMultiplexerCfg.Controls.Add(this.label6);
		this.plMultiplexerCfg.Controls.Add(this.label4);
		this.plMultiplexerCfg.Controls.Add(this.label1);
		this.plMultiplexerCfg.Controls.Add(this.label5);
		this.plMultiplexerCfg.Location = new System.Drawing.Point(3, 29);
		this.plMultiplexerCfg.Name = "plMultiplexerCfg";
		this.plMultiplexerCfg.Size = new System.Drawing.Size(512, 441);
		this.plMultiplexerCfg.TabIndex = 6;
		this.lbBand.AutoSize = true;
		this.lbBand.Location = new System.Drawing.Point(50, 242);
		this.lbBand.Name = "lbBand";
		this.lbBand.Size = new System.Drawing.Size(44, 13);
		this.lbBand.TabIndex = 16;
		this.lbBand.Text = "BANDS";
		this.tbBands.Location = new System.Drawing.Point(94, 237);
		this.tbBands.Multiline = true;
		this.tbBands.Name = "tbBands";
		this.tbBands.ReadOnly = true;
		this.tbBands.Size = new System.Drawing.Size(380, 42);
		this.tbBands.TabIndex = 11;
		this.tbDescription.Location = new System.Drawing.Point(94, 5);
		this.tbDescription.Multiline = true;
		this.tbDescription.Name = "tbDescription";
		this.tbDescription.ReadOnly = true;
		this.tbDescription.Size = new System.Drawing.Size(408, 83);
		this.tbDescription.TabIndex = 11;
		this.PORT.AutoSize = true;
		this.PORT.Location = new System.Drawing.Point(50, 213);
		this.PORT.Name = "PORT";
		this.PORT.Size = new System.Drawing.Size(44, 13);
		this.PORT.TabIndex = 10;
		this.PORT.Text = "PORTS";
		this.toolTip1.SetToolTip(this.PORT, "RF Chains");
		this.btnDelRC.Location = new System.Drawing.Point(445, 208);
		this.btnDelRC.Name = "btnDelRC";
		this.btnDelRC.Size = new System.Drawing.Size(29, 23);
		this.btnDelRC.TabIndex = 9;
		this.btnDelRC.Text = "x";
		this.toolTip1.SetToolTip(this.btnDelRC, "Delete selected ROUTING_CONFIG");
		this.btnDelRC.UseVisualStyleBackColor = true;
		this.btnDelRC.Click += new System.EventHandler(btnDelRC_Click);
		this.btnEdit.Location = new System.Drawing.Point(346, 208);
		this.btnEdit.Name = "btnEdit";
		this.btnEdit.Size = new System.Drawing.Size(41, 23);
		this.btnEdit.TabIndex = 8;
		this.btnEdit.Text = "Edit";
		this.toolTip1.SetToolTip(this.btnEdit, "PORT View and Edit");
		this.btnEdit.UseVisualStyleBackColor = true;
		this.btnEdit.Click += new System.EventHandler(btnEdit_Click);
		this.btnNewRC.Location = new System.Drawing.Point(401, 208);
		this.btnNewRC.Name = "btnNewRC";
		this.btnNewRC.Size = new System.Drawing.Size(29, 23);
		this.btnNewRC.TabIndex = 7;
		this.btnNewRC.Text = "+";
		this.toolTip1.SetToolTip(this.btnNewRC, "Add a new ROUTING_CONFIG");
		this.btnNewRC.UseVisualStyleBackColor = true;
		this.btnNewRC.Click += new System.EventHandler(btnAddRC_Click);
		this.cmbPorts.FormattingEnabled = true;
		this.cmbPorts.Location = new System.Drawing.Point(94, 210);
		this.cmbPorts.Name = "cmbPorts";
		this.cmbPorts.Size = new System.Drawing.Size(233, 21);
		this.cmbPorts.TabIndex = 6;
		this.cmbPorts.SelectedIndexChanged += new System.EventHandler(cmbPorts_SelectedIndexChanged);
		this.dgRouting.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.ColumnHeader;
		this.dgRouting.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgRouting.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgRouting.Columns.AddRange(this.Paths);
		this.dgRouting.Location = new System.Drawing.Point(53, 285);
		this.dgRouting.MultiSelect = false;
		this.dgRouting.Name = "dgRouting";
		this.dgRouting.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
		this.dgRouting.Size = new System.Drawing.Size(421, 135);
		this.dgRouting.TabIndex = 5;
		this.dgRouting.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(dgRouting_CellEndEdit);
		this.dgRouting.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(dgRouting_EditingControlShowing);
		this.dgRouting.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(dgRouting_RowPostPaint);
		this.dgRouting.Validated += new System.EventHandler(dgRouting_Validated);
		this.Paths.HeaderText = "MULTIPLEXER_ROUTING_PATH";
		this.Paths.Name = "Paths";
		this.Paths.Width = 198;
		this.btnDll.Location = new System.Drawing.Point(462, 94);
		this.btnDll.Name = "btnDll";
		this.btnDll.Size = new System.Drawing.Size(40, 23);
		this.btnDll.TabIndex = 4;
		this.btnDll.Text = "...";
		this.btnDll.UseVisualStyleBackColor = true;
		this.btnDll.Click += new System.EventHandler(btnBrowseDllPath_Click);
		this.tbBusCfg.Cursor = System.Windows.Forms.Cursors.Arrow;
		this.tbBusCfg.Location = new System.Drawing.Point(94, 123);
		this.tbBusCfg.Name = "tbBusCfg";
		this.tbBusCfg.Size = new System.Drawing.Size(345, 20);
		this.tbBusCfg.TabIndex = 3;
		this.tbBusCfg.TabStop = false;
		this.tbDll.Cursor = System.Windows.Forms.Cursors.Arrow;
		this.tbDll.Location = new System.Drawing.Point(94, 96);
		this.tbDll.Name = "tbDll";
		this.tbDll.Size = new System.Drawing.Size(346, 20);
		this.tbDll.TabIndex = 3;
		this.cbSimulation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cbSimulation.FormattingEnabled = true;
		this.cbSimulation.Items.AddRange(new object[2] { "YES", "NO" });
		this.cbSimulation.Location = new System.Drawing.Point(136, 149);
		this.cbSimulation.Name = "cbSimulation";
		this.cbSimulation.Size = new System.Drawing.Size(83, 21);
		this.cbSimulation.TabIndex = 2;
		this.label7.AutoSize = true;
		this.label7.Location = new System.Drawing.Point(14, 180);
		this.label7.Name = "label7";
		this.label7.Size = new System.Drawing.Size(103, 13);
		this.label7.TabIndex = 1;
		this.label7.Text = "ROUTING_CONFIG";
		this.toolTip1.SetToolTip(this.label7, resources.GetString("label7.ToolTip"));
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(14, 153);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(115, 13);
		this.label6.TabIndex = 1;
		this.label6.Text = "*SIMULATION_MODE";
		this.toolTip1.SetToolTip(this.label6, resources.GetString("label6.ToolTip"));
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(14, 126);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(75, 13);
		this.label4.TabIndex = 1;
		this.label4.Text = "BUS_CONFIG";
		this.toolTip1.SetToolTip(this.label4, resources.GetString("label4.ToolTip"));
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(14, 5);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(80, 13);
		this.label1.TabIndex = 0;
		this.label1.Text = "DESCRIPTION";
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(14, 99);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(74, 13);
		this.label5.TabIndex = 0;
		this.label5.Text = "DRIVER_DLL";
		this.toolTip1.SetToolTip(this.label5, "Full path and file name of the C# driver DLL to be used to control the multiplexer. \r\nThis DLL must override the abstract methods defined in QC.MultiplexControlInterface.dll");
		this.tbMultiplexer.Controls.Add(this.tabPage5);
		this.tbMultiplexer.Controls.Add(this.tabPage6);
		this.tbMultiplexer.Location = new System.Drawing.Point(3, 9);
		this.tbMultiplexer.Name = "tbMultiplexer";
		this.tbMultiplexer.SelectedIndex = 0;
		this.tbMultiplexer.Size = new System.Drawing.Size(471, 23);
		this.tbMultiplexer.TabIndex = 5;
		this.tbMultiplexer.SelectedIndexChanged += new System.EventHandler(tbMultiplexer_SelectedIndexChanged);
		this.tabPage5.Location = new System.Drawing.Point(4, 22);
		this.tabPage5.Name = "tabPage5";
		this.tabPage5.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage5.Size = new System.Drawing.Size(463, 0);
		this.tabPage5.TabIndex = 0;
		this.tabPage5.Text = "MULTIPLEXER 1";
		this.tabPage5.UseVisualStyleBackColor = true;
		this.tabPage6.Location = new System.Drawing.Point(4, 22);
		this.tabPage6.Name = "tabPage6";
		this.tabPage6.Padding = new System.Windows.Forms.Padding(3);
		this.tabPage6.Size = new System.Drawing.Size(463, 0);
		this.tabPage6.TabIndex = 1;
		this.tabPage6.Text = "MULTIPLEXER 2";
		this.tabPage6.UseVisualStyleBackColor = true;
		this.plMultiplexer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.plMultiplexer.Controls.Add(this.btnDelMultiplexer);
		this.plMultiplexer.Controls.Add(this.btnAddMultiplexer);
		this.plMultiplexer.Controls.Add(this.plMultiplexerCfg);
		this.plMultiplexer.Controls.Add(this.tbMultiplexer);
		this.plMultiplexer.Location = new System.Drawing.Point(405, 3);
		this.plMultiplexer.Name = "plMultiplexer";
		this.plMultiplexer.Size = new System.Drawing.Size(519, 473);
		this.plMultiplexer.TabIndex = 9;
		this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
		this.panel1.Controls.Add(this.cmbSrcfile);
		this.panel1.Controls.Add(this.lbSrcfile);
		this.panel1.Controls.Add(this.lbFile);
		this.panel1.Controls.Add(this.tbSrcfile);
		this.panel1.Controls.Add(this.tbTarget);
		this.panel1.Location = new System.Drawing.Point(4, 3);
		this.panel1.Name = "panel1";
		this.panel1.Size = new System.Drawing.Size(387, 144);
		this.panel1.TabIndex = 11;
		this.cmbSrcfile.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cmbSrcfile.FormattingEnabled = true;
		this.cmbSrcfile.Location = new System.Drawing.Point(61, 71);
		this.cmbSrcfile.Name = "cmbSrcfile";
		this.cmbSrcfile.Size = new System.Drawing.Size(305, 21);
		this.cmbSrcfile.TabIndex = 3;
		this.cmbSrcfile.SelectedIndexChanged += new System.EventHandler(cmbSrcfile_SelectedIndexChanged);
		this.lbSrcfile.AutoSize = true;
		this.lbSrcfile.Location = new System.Drawing.Point(4, 74);
		this.lbSrcfile.Name = "lbSrcfile";
		this.lbSrcfile.Size = new System.Drawing.Size(51, 13);
		this.lbSrcfile.TabIndex = 2;
		this.lbSrcfile.Text = "Soure file";
		this.lbFile.AutoSize = true;
		this.lbFile.Location = new System.Drawing.Point(4, 6);
		this.lbFile.Name = "lbFile";
		this.lbFile.Size = new System.Drawing.Size(54, 13);
		this.lbFile.TabIndex = 1;
		this.lbFile.Text = "Target file";
		this.tbSrcfile.Cursor = System.Windows.Forms.Cursors.Arrow;
		this.tbSrcfile.Location = new System.Drawing.Point(7, 98);
		this.tbSrcfile.Multiline = true;
		this.tbSrcfile.Name = "tbSrcfile";
		this.tbSrcfile.ReadOnly = true;
		this.tbSrcfile.Size = new System.Drawing.Size(359, 37);
		this.tbSrcfile.TabIndex = 0;
		this.tbSrcfile.TabStop = false;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.panel1);
		base.Controls.Add(this.plMultiplexer);
		base.Controls.Add(this.plGroup);
		base.Name = "MultiplexPanel";
		base.Size = new System.Drawing.Size(932, 480);
		base.Load += new System.EventHandler(MultiplexPanel_Load);
		this.plGroup.ResumeLayout(false);
		this.plDut.ResumeLayout(false);
		this.plDutCfg.ResumeLayout(false);
		this.plDutCfg.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.dgIdPathPair).EndInit();
		this.tbDut.ResumeLayout(false);
		this.tbGroup.ResumeLayout(false);
		this.plMultiplexerCfg.ResumeLayout(false);
		this.plMultiplexerCfg.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.dgRouting).EndInit();
		this.tbMultiplexer.ResumeLayout(false);
		this.plMultiplexer.ResumeLayout(false);
		this.panel1.ResumeLayout(false);
		this.panel1.PerformLayout();
		base.ResumeLayout(false);
	}
}
