using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;
using QDART_MFG_CfgEditor.Properties;

namespace QDART_MFG_CfgEditor;

public class PathLossEditor : UserControl
{
	public const int NODE_MAIN = 1;

	public const int NODE_CHILD = 2;

	private string target_file;

	private bool isMultiDut;

	private int cur_dut;

	private bool bLoadDefault;

	private bool bOpenByUser;

	private Common.CalTypes m_CalType = Common.CalTypes.QRD;

	private CalibrationData calInfo;

	private PathList qtaCalInfo;

	private string openedFile;

	private bool fileEdited;

	private TreeNode myTreeNode;

	private TreeNode linkedTreeNode;

	private int freqCount;

	private double offset;

	private bool isValidInput;

	private bool isEditing;

	private bool isEmptyLine;

	private string strFreqIndex = string.Empty;

	private int col_index;

	private int row_index;

	private Dictionary<string, string> m_ConfigLinkDetails = new Dictionary<string, string>();

	private OffsetForm m_OffsetForm = new OffsetForm();

	private IContainer components;

	private Panel panelMain;

	private Panel panelTreeView;

	private TreeView treeView1;

	private Panel panelGrid;

	private Label labelLinkFrom;

	private Button btnCancelOffset;

	private Button btnApplyOffset;

	private Label labelOffSet;

	private Button btnSetOffset;

	private TextBox txtOffset;

	private Label labelPathName;

	private TextBox txtError;

	private DataGridView dgvCalLink;

	private DataGridViewTextBoxColumn LinkDest;

	private DataGridViewComboBoxColumn SourcePath;

	private DataGridViewComboBoxColumn SourceLink;

	private DataGridView dgvCalData;

	private DataGridViewTextBoxColumn Frequency;

	private DataGridViewTextBoxColumn Loss;

	private MenuStrip menuStrip1;

	private ToolStripMenuItem menuFile;

	private ToolStripMenuItem menuItemFileOpen;

	private ToolStripMenuItem menuItemFileSave;

	private ToolStripMenuItem menuItemFileSaveAs;

	private ToolStripMenuItem menuEdit;

	private ToolStripMenuItem menuItemEditOffset;

	private ToolStripMenuItem menuHelp;

	private ToolStripMenuItem menuItemHelpAbout;

	private ToolStripMenuItem configFilesEditorHelpToolStripMenuItem;

	public bool FileEdited
	{
		get
		{
			return fileEdited;
		}
		set
		{
			fileEdited = value;
			if (!string.IsNullOrEmpty(openedFile))
			{
				if (FileEdited)
				{
					Text = "QDARTConfigFilesEditor - " + Path.GetFileName(openedFile) + "*";
				}
				else
				{
					Text = "QDARTConfigFilesEditor - " + Path.GetFileName(openedFile);
				}
			}
		}
	}

	public PathLossEditor(RootConfig cfg, int currentDUT)
	{
		InitializeComponent();
		InitVar(cfg, currentDUT);
	}

	public PathLossEditor(RootConfig cfg)
	{
		InitializeComponent();
		InitVar(cfg);
	}

	private void ConfigFilesEditor_Load(object sender, EventArgs e)
	{
		string[] commandLineArgs = Environment.GetCommandLineArgs();
		if (commandLineArgs.Length > 1)
		{
			OpenFile(commandLineArgs[1]);
		}
	}

	private void menuItemEditOffset_Click(object sender, EventArgs e)
	{
		dgvCalData.EndEdit();
		if ((calInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) || (qtaCalInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1))
		{
			m_OffsetForm.ShowDialog();
			if (m_OffsetForm.OffSet != null && m_OffsetForm.OffSet != string.Empty)
			{
				offset = double.Parse(m_OffsetForm.OffSet.ToString());
				PopulateGrid(offset, isOffSet: true);
				FileEdited = true;
				SaveToTemp(myTreeNode);
				TextBox textBox = txtError;
				textBox.Text = textBox.Text + "Loss offset is applied: " + offset + " (dB)";
				TxtAutoScroll();
				m_OffsetForm.OffSet = string.Empty;
			}
		}
		else
		{
			MessageBox.Show("Loss Offset can only be applied to the valid path. Please select a valid path first!");
		}
	}

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

	private void expandAllToolStripMenuItem_Click(object sender, EventArgs e)
	{
		ExpandAllTreeNodes(treeView1.Nodes[0]);
	}

	private void collapseAllToolStripMenuItem_Click(object sender, EventArgs e)
	{
		CollapseAllTreeNodes(treeView1.Nodes[0], collapseAllChildren: false);
	}

	private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
	{
		Console.WriteLine("Afterseelct" + e.Node.Text);
		if (myTreeNode != null)
		{
			Console.WriteLine("My tree node " + myTreeNode.Text);
		}
		if (linkedTreeNode != null)
		{
			linkedTreeNode.BackColor = SystemColors.Window;
			linkedTreeNode = null;
		}
		try
		{
			dgvCalData.Rows.Clear();
		}
		catch (Exception ex)
		{
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Exception " + ex.Message;
			TxtAutoScroll();
		}
		string text = "All Cal Values";
		labelLinkFrom.Text = "";
		if (m_CalType == Common.CalTypes.QRD && e.Node.Level == 2)
		{
			if (e.Node.Tag is CalPathLinkInfo)
			{
				CalPathLinkInfo calPathLinkInfo = (CalPathLinkInfo)e.Node.Tag;
				text = e.Node.Parent.Text + " \\ " + e.Node.Text;
				if (IsLinkedNodePresent(calPathLinkInfo.SrcCalConfig, calPathLinkInfo.SrcPathNumber, showNode: true))
				{
					Label label = labelLinkFrom;
					label.Text = label.Text + "Linked From " + text;
					e.Node.BackColor = Color.Aqua;
					linkedTreeNode = e.Node;
				}
				else
				{
					MessageBox.Show("Invalid Link from " + text);
					labelPathName.Text = "For path: " + text;
				}
			}
			else
			{
				dgvCalData.Enabled = true;
				text = e.Node.Parent.Text + " \\ " + e.Node.Text;
				PopulateGrid(offset, isOffSet: false);
				myTreeNode = treeView1.SelectedNode;
				labelPathName.Text = "For path: " + text;
			}
		}
		else if (m_CalType == Common.CalTypes.QRD && e.Node.Level == 1)
		{
			text = e.Node.Text;
			e.Node.Expand();
			PopulateGrid(((CalConfigInfo)e.Node.Tag).CalPathLink);
			myTreeNode = treeView1.SelectedNode;
			labelPathName.Text = "For path: " + text;
		}
		else
		{
			if (m_CalType == Common.CalTypes.QTA && e.Node.Level == 1)
			{
				dgvCalData.Enabled = true;
				text = e.Node.Text;
				PopulateGrid(offset, isOffSet: false);
				myTreeNode = treeView1.SelectedNode;
				Console.WriteLine("in After select " + myTreeNode.Text);
			}
			else
			{
				dgvCalData.Enabled = false;
			}
			labelPathName.Text = "For path: " + text;
		}
	}

	private void treeView1_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
	{
	}

	private void btnOpenCalFile_Click(object sender, EventArgs e)
	{
		OpenFileDialog openFileDialog = new OpenFileDialog();
		openFileDialog.DefaultExt = "xml";
		if (openFileDialog.ShowDialog() != DialogResult.OK)
		{
			return;
		}
		if (FileEdited)
		{
			switch (MessageBox.Show("Value has been changed. \nDo you want to save the edited values ? \n\t" + openedFile, "Warning", MessageBoxButtons.YesNoCancel))
			{
			case DialogResult.Yes:
				btnSave_Click(null, null);
				break;
			case DialogResult.Cancel:
				return;
			}
		}
		dgvCalData.Rows.Clear();
		treeView1.Nodes.Clear();
		OpenFile(openFileDialog.FileName);
		bOpenByUser = true;
	}

	private void btnSave_Click(object sender, EventArgs e)
	{
		try
		{
			string text = openedFile;
			dgvCalData.EndEdit();
			if (!bOpenByUser)
			{
				string text2 = "";
				text2 = (isMultiDut ? (Path.GetDirectoryName(target_file) + "\\DUT_" + cur_dut + "\\" + Path.GetFileName(target_file)) : target_file);
				if (!File.Exists(text2))
				{
					string directoryName = Path.GetDirectoryName(text2);
					if (!Directory.Exists(directoryName))
					{
						Directory.CreateDirectory(directoryName);
					}
					FileStream fileStream = File.Create(text2);
					fileStream.Close();
				}
				text = text2;
			}
			if (File.GetAttributes(text).ToString().IndexOf("ReadOnly") != -1)
			{
				File.SetAttributes(text, FileAttributes.Normal);
			}
			using (StreamWriter streamWriter = new StreamWriter(text))
			{
				if (m_CalType == Common.CalTypes.QRD)
				{
					XmlSerializer xmlSerializer = new XmlSerializer(typeof(CalibrationData));
					xmlSerializer.Serialize(streamWriter, calInfo);
				}
				else
				{
					XmlSerializer xmlSerializer2 = new XmlSerializer(typeof(PathList));
					xmlSerializer2.Serialize(streamWriter, qtaCalInfo);
				}
				streamWriter.Close();
			}
			Common.FormatXml(text);
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Contents saved in file " + text;
			TxtAutoScroll();
			FileEdited = false;
		}
		catch (Exception ex)
		{
			TextBox textBox2 = txtError;
			textBox2.Text = textBox2.Text + "Exception " + ex.Message;
			TxtAutoScroll();
		}
	}

	private void btnSaveAs_Click(object sender, EventArgs e)
	{
		try
		{
			SaveFileDialog saveFileDialog = new SaveFileDialog();
			saveFileDialog.FileName = openedFile;
			saveFileDialog.Filter = "XML Files | *.xml";
			saveFileDialog.DefaultExt = "xml";
			if (saveFileDialog.ShowDialog() != DialogResult.OK)
			{
				return;
			}
			try
			{
				string fileName = saveFileDialog.FileName;
				using (StreamWriter streamWriter = new StreamWriter(fileName))
				{
					if (m_CalType == Common.CalTypes.QRD)
					{
						XmlSerializer xmlSerializer = new XmlSerializer(typeof(CalibrationData));
						xmlSerializer.Serialize(streamWriter, calInfo);
					}
					else
					{
						XmlSerializer xmlSerializer2 = new XmlSerializer(typeof(PathList));
						xmlSerializer2.Serialize(streamWriter, qtaCalInfo);
					}
					streamWriter.Close();
				}
				Common.FormatXml(fileName);
				openedFile = fileName;
				TextBox textBox = txtError;
				textBox.Text = textBox.Text + "Contents saved in file " + openedFile;
				TxtAutoScroll();
				FileEdited = false;
			}
			catch (Exception ex)
			{
				TextBox textBox2 = txtError;
				textBox2.Text = textBox2.Text + "Exception " + ex.Message;
				TxtAutoScroll();
			}
		}
		catch (Exception ex2)
		{
			TextBox textBox3 = txtError;
			textBox3.Text = textBox3.Text + "Exception " + ex2.Message;
			TxtAutoScroll();
		}
	}

	private void btnCancel_Click(object sender, EventArgs e)
	{
		if (!FileEdited)
		{
			return;
		}
		DialogResult dialogResult = MessageBox.Show("Do you want to save the edited values ? ", "Warning", MessageBoxButtons.YesNoCancel);
		if (dialogResult == DialogResult.Yes)
		{
			switch (MessageBox.Show("Do you want to save to the same file ? \n\t" + openedFile, "Warning", MessageBoxButtons.YesNoCancel))
			{
			case DialogResult.Yes:
				btnSave_Click(null, null);
				break;
			case DialogResult.No:
				btnSaveAs_Click(null, null);
				break;
			}
		}
		else
		{
			_ = 2;
		}
	}

	private void dgvCalData_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
	{
		isValidInput = true;
		isEditing = true;
	}

	private void dgvCalData_CellEndEdit(object sender, DataGridViewCellEventArgs e)
	{
		col_index = e.ColumnIndex;
		row_index = e.RowIndex;
		Validate();
		Console.WriteLine("cell end edit" + myTreeNode.Text);
		if (isValidInput && ValidCellEdit())
		{
			SaveToTemp(myTreeNode);
			Console.WriteLine("cell save" + myTreeNode.Text);
			FileEdited = true;
		}
		else if (isEmptyLine)
		{
			try
			{
				isEmptyLine = false;
				dgvCalData.Rows.RemoveAt(e.RowIndex);
			}
			catch
			{
			}
		}
		dgvCalData.Columns[e.ColumnIndex].HeaderCell.SortGlyphDirection = SortOrder.None;
		isEditing = false;
	}

	private void dgvCalData_UserDeletedRow(object sender, DataGridViewRowEventArgs e)
	{
		FileEdited = true;
		SaveToTemp(myTreeNode);
	}

	private void dgvCalData_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
	{
		if (!isEditing)
		{
			return;
		}
		Console.WriteLine("cell validating" + myTreeNode.Text);
		try
		{
			if ((m_CalType != Common.CalTypes.QRD || treeView1.SelectedNode.Level != 1) && e.FormattedValue.ToString() != "")
			{
				double.Parse(e.FormattedValue.ToString());
			}
		}
		catch (Exception ex)
		{
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Exception " + ex.Message;
			TxtAutoScroll();
			MessageBox.Show("Invalid value entered. Please enter numbers only!", "Warning", MessageBoxButtons.OK);
			dgvCalData.CancelEdit();
			isValidInput = false;
		}
		if (e.FormattedValue == null || e.FormattedValue.ToString() == "")
		{
			if ((e.ColumnIndex == 0 && dgvCalData[1, e.RowIndex].Value == null) || (e.ColumnIndex == 1 && dgvCalData[0, e.RowIndex].Value == null))
			{
				isEmptyLine = true;
				isValidInput = false;
			}
		}
		else
		{
			if (e.ColumnIndex != 0 || (m_CalType == Common.CalTypes.QRD && treeView1.SelectedNode.Level == 1))
			{
				return;
			}
			for (int i = 0; i < dgvCalData.RowCount - 1; i++)
			{
				double num = double.Parse(e.FormattedValue.ToString());
				if (i != e.RowIndex && double.Parse(dgvCalData[0, i].Value.ToString()) == num)
				{
					MessageBox.Show("Duplicate Frequences are found. The duplicate Freq input is canceled.\n\tFreq:\t" + e.FormattedValue.ToString(), "Invalid Value Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
					dgvCalData.CancelEdit();
					isValidInput = false;
					break;
				}
			}
		}
	}

	private void txtOffset_KeyPress(object sender, KeyPressEventArgs e)
	{
		if (e.KeyChar == '\r')
		{
			btnApplyOffset_Click(null, null);
		}
	}

	private void btnSetOffset_Click(object sender, EventArgs e)
	{
		if ((calInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) || (qtaCalInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1))
		{
			if (!txtOffset.Visible)
			{
				txtOffset.Visible = true;
				labelOffSet.Visible = true;
				btnApplyOffset.Visible = true;
				btnCancelOffset.Visible = true;
				btnSetOffset.Visible = false;
			}
		}
		else
		{
			MessageBox.Show("Loss Offset can only be applied to the valid path. Please select a valid path first!");
		}
	}

	private void btnApplyOffset_Click(object sender, EventArgs e)
	{
		dgvCalData.EndEdit();
		if ((calInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) || (qtaCalInfo != null && treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 1))
		{
			if (double.TryParse(txtOffset.Text.ToString(), out offset))
			{
				PopulateGrid(offset, isOffSet: true);
				FileEdited = true;
				SaveToTemp(treeView1.SelectedNode);
				TextBox textBox = txtError;
				textBox.Text = textBox.Text + "Loss offset is applied: " + offset + " (dB)";
				TxtAutoScroll();
				txtOffset.Text = "";
				offset = 0.0;
				txtOffset.Visible = false;
				labelOffSet.Visible = false;
				btnApplyOffset.Visible = false;
				btnCancelOffset.Visible = false;
				btnSetOffset.Visible = true;
			}
			else
			{
				txtError.Text += "Invalid offset value is given";
				TxtAutoScroll();
				txtOffset.Text = "";
			}
		}
		else
		{
			txtError.Text += "Loss Offset can only be applied to the valid path. Please select a valid path first!";
			TxtAutoScroll();
			MessageBox.Show("Loss Offset can only be applied to the valid path. Please select a valid path first!");
		}
	}

	private void btnCancelOffset_Click(object sender, EventArgs e)
	{
		txtOffset.Text = "";
		offset = 0.0;
		txtOffset.Visible = false;
		labelOffSet.Visible = false;
		btnApplyOffset.Visible = false;
		btnCancelOffset.Visible = false;
		btnSetOffset.Visible = true;
	}

	private void ResetVbles()
	{
		txtError.Text = "";
		FileEdited = false;
		dgvCalData.Rows.Clear();
		dgvCalLink.Rows.Clear();
		dgvCalLink.Visible = false;
		dgvCalData.Visible = false;
		myTreeNode = null;
		myTreeNode = null;
		labelLinkFrom.Text = "";
		labelPathName.Text = "";
	}

	private void OpenFile(string fileName)
	{
		ResetVbles();
		string text = fileName + ".bak";
		try
		{
			if (File.Exists(text))
			{
				if (File.GetAttributes(text).ToString().IndexOf("ReadOnly") != -1)
				{
					File.SetAttributes(text, FileAttributes.Normal);
				}
				File.Delete(text);
			}
			File.Copy(fileName, text);
			bool flag = false;
			using (StreamReader streamReader = new StreamReader(fileName))
			{
				while (streamReader.Peek() >= 0)
				{
					string text2 = streamReader.ReadLine();
					if (text2.Contains("PathList"))
					{
						m_CalType = Common.CalTypes.QTA;
						flag = true;
						break;
					}
					if (text2.Contains("CalibrationData"))
					{
						m_CalType = Common.CalTypes.QRD;
						flag = true;
						break;
					}
				}
				streamReader.Close();
				if (!flag)
				{
					MessageBox.Show("Invalid Cal data file");
					TextBox textBox = txtError;
					textBox.Text = textBox.Text + "Invalid Cal data file " + fileName;
					TxtAutoScroll();
					return;
				}
			}
			using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
			{
				if (m_CalType == Common.CalTypes.QRD)
				{
					XmlSerializer xmlSerializer = new XmlSerializer(typeof(CalibrationData));
					calInfo = null;
					calInfo = (CalibrationData)xmlSerializer.Deserialize(fileStream);
					_ = calInfo.CalConfig.Count;
					fileStream.Close();
				}
				else
				{
					XmlSerializer xmlSerializer2 = new XmlSerializer(typeof(PathList));
					qtaCalInfo = (PathList)xmlSerializer2.Deserialize(fileStream);
					_ = qtaCalInfo.QTAPaths.Count;
					fileStream.Close();
				}
			}
			PopulateTree();
			openedFile = fileName;
			FileEdited = false;
			TextBox textBox2 = txtError;
			textBox2.Text = textBox2.Text + "Cal File is loaded: " + fileName;
			TxtAutoScroll();
		}
		catch (Exception ex)
		{
			TextBox textBox3 = txtError;
			textBox3.Text = textBox3.Text + "Exception " + ex.Message;
			TxtAutoScroll();
		}
	}

	private void UpdateConfigLinkDetails()
	{
		m_ConfigLinkDetails.Clear();
		foreach (CalConfigInfo item in calInfo.CalConfig)
		{
			foreach (CalPathInfo item2 in item.CalPath)
			{
				string text = item.Name + "#" + item2.Number + "#" + item2.Number;
				if (m_ConfigLinkDetails.ContainsKey(text))
				{
					TextBox textBox = txtError;
					textBox.Text = textBox.Text + "Same key found. Only first one will load. Key: " + text;
					TxtAutoScroll();
				}
				else
				{
					m_ConfigLinkDetails.Add(text, item2.Name);
				}
			}
		}
	}

	private void PopulateTree()
	{
		try
		{
			if (m_CalType == Common.CalTypes.QRD)
			{
				List<TreeNode> list = new List<TreeNode>();
				foreach (CalConfigInfo item in calInfo.CalConfig)
				{
					List<TreeNode> list2 = new List<TreeNode>();
					foreach (CalPathLinkInfo item2 in item.CalPathLink)
					{
						TreeNode treeNode = new TreeNode(Common.CalPathMappingList[item2.DestPathNumber.ToString()] + " - > " + item2.SrcCalConfig + " - " + Common.CalPathMappingList[item2.SrcPathNumber.ToString()]);
						treeNode.Tag = item2;
						list2.Add(treeNode);
					}
					foreach (CalPathInfo item3 in item.CalPath)
					{
						TreeNode treeNode2 = new TreeNode(item3.Name);
						treeNode2.Name = item3.Name;
						treeNode2.Tag = item3;
						if (Common.CalPathMappingList.ContainsKey(item3.Number.ToString()))
						{
							treeNode2.Text = Common.CalPathMappingList[item3.Number.ToString()];
						}
						else
						{
							treeNode2.Text = item3.Name;
						}
						list2.Add(treeNode2);
					}
					TreeNode treeNode3 = new TreeNode(item.Name, list2.ToArray());
					treeNode3.Name = item.Name;
					treeNode3.Text = item.Name;
					treeNode3.Tag = item;
					list.Add(treeNode3);
				}
				TreeNode treeNode4 = new TreeNode("Cal Values", list.ToArray());
				treeNode4.Name = "Cal Values";
				treeNode4.Text = "Cal Values";
				treeView1.Nodes.AddRange(new TreeNode[1] { treeNode4 });
				treeNode4.Expand();
				SourcePath.DataSource = list;
				SourcePath.DisplayMember = "Text";
				SourcePath.ValueMember = "Text";
				SourceLink.DataSource = Enum.GetNames(typeof(Common.CalPathVbles));
				dgvCalData.Visible = false;
				dgvCalLink.Visible = false;
				return;
			}
			List<TreeNode> list3 = new List<TreeNode>();
			foreach (QTAPathInfo qTAPath in qtaCalInfo.QTAPaths)
			{
				TreeNode treeNode5 = new TreeNode(qTAPath.PathName);
				treeNode5.Name = qTAPath.PathName;
				treeNode5.Text = qTAPath.PathName;
				treeNode5.Tag = qTAPath;
				list3.Add(treeNode5);
			}
			TreeNode treeNode6 = new TreeNode("Cal Values", list3.ToArray());
			treeNode6.Name = "Cal Values";
			treeNode6.Text = "Cal Values";
			treeView1.Nodes.AddRange(new TreeNode[1] { treeNode6 });
			treeNode6.Expand();
		}
		catch (Exception ex)
		{
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Exception " + ex.Message;
			TxtAutoScroll();
		}
	}

	private void PopulateGrid(double offset, bool isOffSet)
	{
		dgvCalLink.Visible = false;
		dgvCalData.Visible = true;
		try
		{
			dgvCalData.Columns[0].HeaderText = "Frequency(MHz)";
			dgvCalData.Columns[1].HeaderText = "Loss(dB)";
			if (m_CalType == Common.CalTypes.QRD)
			{
				if (!isOffSet)
				{
					if (treeView1.SelectedNode.Level == 2)
					{
						double?[] array = new double?[2];
						for (freqCount = 0; freqCount < ((CalPathInfo)treeView1.SelectedNode.Tag).CalPoint.Count; freqCount++)
						{
							int num = 0;
							ref double? reference = ref array[num++];
							reference = double.Parse(((CalPathInfo)treeView1.SelectedNode.Tag).CalPoint[freqCount].Freq.ToString());
							ref double? reference2 = ref array[num++];
							reference2 = double.Parse(((CalPathInfo)treeView1.SelectedNode.Tag).CalPoint[freqCount].Loss.ToString());
							dgvCalData.Rows.Add(Math.Round(array[0].Value, 5), Math.Round(array[1].Value, 5));
						}
						dgvCalData.Sort(Frequency, ListSortDirection.Ascending);
					}
				}
				else
				{
					for (int i = 0; i < dgvCalData.Rows.Count - 1; i++)
					{
						dgvCalData.Rows[i].Cells[1].Value = Math.Round(double.Parse(dgvCalData.Rows[i].Cells[1].Value.ToString()) + offset, 5);
					}
				}
			}
			else if (!isOffSet)
			{
				if (treeView1.SelectedNode.Level == 1)
				{
					double?[] array2 = new double?[2];
					for (freqCount = 0; freqCount < ((QTAPathInfo)treeView1.SelectedNode.Tag).DataList.QTADataList.Count; freqCount++)
					{
						int num2 = 0;
						ref double? reference3 = ref array2[num2++];
						reference3 = double.Parse(((QTAPathInfo)treeView1.SelectedNode.Tag).DataList.QTADataList[freqCount].Frequency.ToString());
						ref double? reference4 = ref array2[num2++];
						reference4 = double.Parse(((QTAPathInfo)treeView1.SelectedNode.Tag).DataList.QTADataList[freqCount].Loss.ToString()) + double.Parse(((QTAPathInfo)treeView1.SelectedNode.Tag).AdditionalLoss.ToString());
						dgvCalData.Rows.Add(Math.Round(array2[0].Value, 5), Math.Round(array2[1].Value, 5));
					}
					dgvCalData.Sort(Frequency, ListSortDirection.Ascending);
				}
			}
			else
			{
				for (int j = 0; j < dgvCalData.Rows.Count - 1; j++)
				{
					dgvCalData.Rows[j].Cells[1].Value = Math.Round(double.Parse(dgvCalData.Rows[j].Cells[1].Value.ToString()) + offset, 5);
				}
			}
		}
		catch (Exception ex)
		{
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Exception " + ex.Message;
			TxtAutoScroll();
		}
	}

	private void PopulateGrid(ArrayList calPathLinkList)
	{
		dgvCalLink.Visible = true;
		dgvCalData.Visible = false;
		dgvCalLink.Rows.Clear();
		foreach (CalPathLinkInfo calPathLink in calPathLinkList)
		{
			dgvCalLink.Rows.Add(Common.CalPathMappingList[calPathLink.DestPathNumber.ToString()], calPathLink.SrcCalConfig, Common.CalPathMappingList[calPathLink.SrcPathNumber.ToString()]);
		}
	}

	private void RefreshTreeNode(TreeNode treeNode)
	{
		foreach (TreeNode node in treeNode.Nodes)
		{
			_ = node;
			treeNode.Nodes.Clear();
		}
		CalConfigInfo calConfigInfo = (CalConfigInfo)treeNode.Tag;
		foreach (CalPathLinkInfo item in calConfigInfo.CalPathLink)
		{
			TreeNode treeNode2 = new TreeNode(Common.CalPathMappingList[item.DestPathNumber.ToString()] + " - > " + item.SrcCalConfig + " - " + Common.CalPathMappingList[item.SrcPathNumber.ToString()]);
			treeNode2.Tag = item;
			treeNode.Nodes.Add(treeNode2);
		}
		foreach (CalPathInfo item2 in calConfigInfo.CalPath)
		{
			TreeNode treeNode3 = new TreeNode(item2.Name);
			treeNode3.Name = item2.Name;
			treeNode3.Tag = item2;
			if (Common.CalPathMappingList.ContainsKey(item2.Number.ToString()))
			{
				treeNode3.Text = Common.CalPathMappingList[item2.Number.ToString()];
			}
			else
			{
				treeNode3.Text = item2.Name;
			}
		}
	}

	private void SaveToTemp(TreeNode editedNode)
	{
		bool flag = false;
		if ((calInfo == null && m_CalType == Common.CalTypes.QRD) || (qtaCalInfo == null && m_CalType == Common.CalTypes.QTA))
		{
			return;
		}
		int num = 0;
		_ = string.Empty;
		Dictionary<double, double> dictionary = new Dictionary<double, double>();
		Dictionary<double, double> dictionary2 = new Dictionary<double, double>();
		List<CalPathLinkInfo> list = new List<CalPathLinkInfo>();
		try
		{
			if (m_CalType == Common.CalTypes.QTA || editedNode.Level == 2)
			{
				for (num = 0; num < dgvCalData.RowCount - 1; num++)
				{
					if (dgvCalData.Rows[num].Cells[1].Value != null)
					{
						dictionary2.Add(double.Parse(dgvCalData.Rows[num].Cells[0].Value.ToString()), double.Parse(dgvCalData.Rows[num].Cells[1].Value.ToString()));
					}
				}
			}
		}
		catch (Exception ex)
		{
			TextBox textBox = txtError;
			textBox.Text = textBox.Text + "Exception " + ex.Message;
			TxtAutoScroll();
			return;
		}
		try
		{
			if (m_CalType == Common.CalTypes.QRD)
			{
				if (editedNode.Level == 1)
				{
					try
					{
						for (int i = 0; i < dgvCalLink.RowCount; i++)
						{
							if (dgvCalLink.Rows[i].Cells[1].Value != null)
							{
								dgvCalLink.Rows[i].Cells[1].Value.ToString().Split('#');
								CalPathLinkInfo calPathLinkInfo = new CalPathLinkInfo();
								Common.CalPathVbles calPathVbles = (Common.CalPathVbles)Enum.Parse(typeof(Common.CalPathVbles), dgvCalLink.Rows[i].Cells[0].Value.ToString());
								int num2 = (int)calPathVbles;
								calPathLinkInfo.DestPathNumber = num2.ToString();
								calPathLinkInfo.SrcCalConfig = dgvCalLink.Rows[i].Cells[1].Value.ToString();
								calPathVbles = (Common.CalPathVbles)Enum.Parse(typeof(Common.CalPathVbles), dgvCalLink.Rows[i].Cells[2].Value.ToString());
								int num3 = (int)calPathVbles;
								calPathLinkInfo.SrcPathNumber = num3.ToString();
								list.Add(calPathLinkInfo);
							}
						}
					}
					catch (Exception ex2)
					{
						TextBox textBox2 = txtError;
						textBox2.Text = textBox2.Text + "Exception " + ex2.Message;
						TxtAutoScroll();
						MessageBox.Show(ex2.Message);
					}
				}
				else if (editedNode.Level == 2)
				{
					foreach (CalPointInfo item2 in ((CalPathInfo)editedNode.Tag).CalPoint)
					{
						_ = item2.Freq;
						dictionary.Add(double.Parse(item2.Freq), double.Parse(item2.Loss));
					}
				}
			}
			else if (editedNode.Tag != null)
			{
				foreach (QTADataInfo qTAData in ((QTAPathInfo)editedNode.Tag).DataList.QTADataList)
				{
					_ = qTAData.Frequency;
					dictionary.Add(double.Parse(qTAData.Frequency), double.Parse(qTAData.Loss));
				}
			}
		}
		catch (Exception ex3)
		{
			TextBox textBox3 = txtError;
			textBox3.Text = textBox3.Text + "Exception " + ex3.Message;
			TxtAutoScroll();
			MessageBox.Show(ex3.Message);
			return;
		}
		if (m_CalType == Common.CalTypes.QTA || editedNode.Level == 2)
		{
			if (!Common.DictionaryCompare(dictionary, dictionary2))
			{
				List<double> list2 = new List<double>();
				new Dictionary<double, double>();
				foreach (double key2 in dictionary2.Keys)
				{
					double item = key2;
					list2.Add(item);
				}
				list2.Sort();
				dictionary.Clear();
				if (m_CalType == Common.CalTypes.QRD)
				{
					((CalPathInfo)editedNode.Tag).CalPoint.Clear();
				}
				else
				{
					((QTAPathInfo)editedNode.Tag).DataList.QTADataList.Clear();
				}
				foreach (double item3 in list2)
				{
					double key = item3;
					if (m_CalType == Common.CalTypes.QRD)
					{
						CalPointInfo calPointInfo = new CalPointInfo();
						calPointInfo.Freq = key.ToString();
						calPointInfo.Loss = dictionary2[key].ToString();
						((CalPathInfo)editedNode.Tag).CalPoint.Add(calPointInfo);
						continue;
					}
					QTADataInfo qTADataInfo = new QTADataInfo();
					qTADataInfo.Frequency = key.ToString();
					qTADataInfo.Loss = dictionary2[key].ToString();
					((QTAPathInfo)editedNode.Tag).DataList.QTADataList.Add(qTADataInfo);
					if (((QTAPathInfo)editedNode.Tag).AdditionalLoss.ToString() != "0")
					{
						((QTAPathInfo)editedNode.Tag).AdditionalLoss = "0";
					}
				}
				flag = true;
			}
		}
		else if (m_CalType == Common.CalTypes.QRD && treeView1.SelectedNode.Level == 1)
		{
			CalConfigInfo calConfigInfo = (CalConfigInfo)editedNode.Tag;
			calConfigInfo.CalPathLink.Clear();
			calConfigInfo.CalPathLink = new ArrayList(list);
			RefreshTreeNode(treeView1.SelectedNode);
			flag = true;
		}
		if (!flag)
		{
			return;
		}
		if (m_CalType == Common.CalTypes.QRD && editedNode.Level == 2)
		{
			string empty = string.Empty;
			empty = DateTime.Now.ToShortDateString().Remove(DateTime.Now.ToShortDateString().Length - 4, 2) + " " + DateTime.Now.ToLongTimeString().Substring(0, DateTime.Now.ToLongTimeString().Length - 3);
			if (empty.IndexOf('/') != 2)
			{
				empty = empty.Insert(0, "0");
			}
			if (empty.IndexOf('/', 3) != 5)
			{
				empty = empty.Insert(3, "0");
			}
			((CalPathInfo)editedNode.Tag).Date = empty;
		}
		else if (m_CalType == Common.CalTypes.QTA)
		{
			((QTAPathInfo)editedNode.Tag).Cal_Date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
		}
	}

	private bool IsLinkedNodePresent(string calConfigName, string calPathNumber, bool showNode)
	{
		TreeNode treeNode = treeView1.Nodes[0];
		foreach (TreeNode node in treeNode.Nodes)
		{
			if (!((CalConfigInfo)node.Tag).Name.Equals(calConfigName))
			{
				continue;
			}
			foreach (TreeNode node2 in node.Nodes)
			{
				if (node2.Tag is CalPathInfo && ((CalPathInfo)node2.Tag).Number.ToString().Equals(calPathNumber))
				{
					if (showNode)
					{
						treeView1.SelectedNode = node2;
						ExpandAllParents(node2);
					}
					return true;
				}
			}
		}
		return false;
	}

	private void ExpandAllParents(TreeNode treeNode)
	{
		if (treeNode.Parent != null)
		{
			ExpandAllParents(treeNode.Parent);
		}
		treeNode.Expand();
	}

	private void ExpandAllTreeNodes(TreeNode treeNode)
	{
		treeNode.ExpandAll();
	}

	private void CollapseAllTreeNodes(TreeNode treeNode, bool collapseAllChildren)
	{
		treeNode.Collapse(collapseAllChildren);
	}

	private bool ValidCellEdit()
	{
		bool result = true;
		if (dgvCalData[0, row_index].Value == null || dgvCalData[1, row_index].Value == null)
		{
			result = false;
		}
		return result;
	}

	private bool ConfigHasValidLink(string calPathLink, int columnIndex, int rowIndex)
	{
		bool flag = false;
		switch (columnIndex)
		{
		case 0:
			return true;
		case 1:
		{
			Common.CalPathVbles calPathVbles2 = (Common.CalPathVbles)Enum.Parse(typeof(Common.CalPathVbles), dgvCalLink.Rows[rowIndex].Cells[2].Value.ToString());
			int num2 = (int)calPathVbles2;
			return IsLinkedNodePresent(calPathLink, num2.ToString(), showNode: false);
		}
		default:
		{
			Common.CalPathVbles calPathVbles = (Common.CalPathVbles)Enum.Parse(typeof(Common.CalPathVbles), calPathLink);
			string calConfigName = dgvCalLink.Rows[rowIndex].Cells[1].Value.ToString();
			int num = (int)calPathVbles;
			return IsLinkedNodePresent(calConfigName, num.ToString(), showNode: false);
		}
		}
	}

	private void TxtAutoScroll()
	{
		TextBox textBox = txtError;
		textBox.Text = textBox.Text + Environment.NewLine + Environment.NewLine;
		txtError.SelectionStart = txtError.Text.Length - 1;
		txtError.ScrollToCaret();
		txtError.Refresh();
	}

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

	private void dgvCalLink_CellEndEdit(object sender, DataGridViewCellEventArgs e)
	{
		if (isValidInput)
		{
			SaveToTemp(myTreeNode);
			FileEdited = true;
		}
		isEditing = false;
	}

	private void dgvCalLink_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
	{
		isValidInput = true;
		isEditing = true;
	}

	private void dgvCalLink_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
	{
		if (!isEditing)
		{
			return;
		}
		try
		{
			if (m_CalType == Common.CalTypes.QRD && treeView1.SelectedNode.Level == 1)
			{
				if (!ConfigHasValidLink(e.FormattedValue.ToString(), e.ColumnIndex, e.RowIndex))
				{
					dgvCalLink.CancelEdit();
					TextBox textBox = txtError;
					textBox.Text = textBox.Text + "Could not find CalPath " + e.FormattedValue.ToString() + " in Config file.";
					MessageBox.Show("Invalid Value entered. CalLink not found", "Warning", MessageBoxButtons.OK);
					TxtAutoScroll();
					isValidInput = false;
				}
				FileEdited = true;
			}
		}
		catch (Exception ex)
		{
			TextBox textBox2 = txtError;
			textBox2.Text = textBox2.Text + "Exception " + ex.Message;
			TxtAutoScroll();
			MessageBox.Show("Invalid value entered.  ", "Warning", MessageBoxButtons.OK);
			dgvCalData.CancelEdit();
			isValidInput = false;
		}
	}

	private void ConfigFilesEditor_FormClosing(object sender, FormClosingEventArgs e)
	{
		if (FileEdited)
		{
			switch (MessageBox.Show("Value has been changed. \nDo you want to save the edited values ? \n\t" + openedFile, "Warning", MessageBoxButtons.YesNoCancel))
			{
			case DialogResult.Yes:
				btnSave_Click(null, null);
				break;
			case DialogResult.Cancel:
				e.Cancel = true;
				break;
			}
		}
	}

	private void InitVar(RootConfig cfg, int currentDUT)
	{
		bOpenByUser = false;
		bool.TryParse(cfg.MultiDUT, out isMultiDut);
		bool.TryParse(cfg.BlankWhenNull, out bLoadDefault);
		cur_dut = currentDUT;
		RootConfigAllPanel[] panel = cfg.All[0].Panel;
		foreach (RootConfigAllPanel rootConfigAllPanel in panel)
		{
			if (cfg.Station == rootConfigAllPanel.Name && rootConfigAllPanel.File.Length > 0)
			{
				target_file = Common.GetPath(rootConfigAllPanel.File[0].Value);
			}
		}
		string text = "";
		if (!isMultiDut)
		{
			text = target_file;
		}
		else
		{
			text = Path.GetDirectoryName(target_file) + "\\DUT_" + cur_dut + "\\" + Path.GetFileName(target_file);
			if (!File.Exists(text) && bLoadDefault)
			{
				text = target_file;
			}
		}
		if (File.Exists(text))
		{
			OpenFile(text);
		}
	}

	private void InitVar(RootConfig cfg)
	{
		bOpenByUser = false;
		isMultiDut = false;
		RootConfigAllPanel[] panel = cfg.All[0].Panel;
		foreach (RootConfigAllPanel rootConfigAllPanel in panel)
		{
			if (cfg.Station == rootConfigAllPanel.Name && rootConfigAllPanel.File.Length > 0)
			{
				target_file = Common.GetPath(rootConfigAllPanel.File[0].Value);
			}
		}
		if (File.Exists(target_file))
		{
			OpenFile(target_file);
		}
	}

	public void SaveResult()
	{
		btnSave_Click(null, null);
	}

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

	private void InitializeComponent()
	{
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
		System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
		this.panelMain = new System.Windows.Forms.Panel();
		this.panelTreeView = new System.Windows.Forms.Panel();
		this.treeView1 = new System.Windows.Forms.TreeView();
		this.panelGrid = new System.Windows.Forms.Panel();
		this.labelLinkFrom = new System.Windows.Forms.Label();
		this.btnCancelOffset = new System.Windows.Forms.Button();
		this.btnApplyOffset = new System.Windows.Forms.Button();
		this.labelOffSet = new System.Windows.Forms.Label();
		this.btnSetOffset = new System.Windows.Forms.Button();
		this.txtOffset = new System.Windows.Forms.TextBox();
		this.labelPathName = new System.Windows.Forms.Label();
		this.txtError = new System.Windows.Forms.TextBox();
		this.dgvCalLink = new System.Windows.Forms.DataGridView();
		this.LinkDest = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.SourcePath = new System.Windows.Forms.DataGridViewComboBoxColumn();
		this.SourceLink = new System.Windows.Forms.DataGridViewComboBoxColumn();
		this.dgvCalData = new System.Windows.Forms.DataGridView();
		this.Frequency = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.Loss = new System.Windows.Forms.DataGridViewTextBoxColumn();
		this.menuStrip1 = new System.Windows.Forms.MenuStrip();
		this.menuFile = new System.Windows.Forms.ToolStripMenuItem();
		this.menuItemFileOpen = new System.Windows.Forms.ToolStripMenuItem();
		this.menuItemFileSave = new System.Windows.Forms.ToolStripMenuItem();
		this.menuItemFileSaveAs = new System.Windows.Forms.ToolStripMenuItem();
		this.menuEdit = new System.Windows.Forms.ToolStripMenuItem();
		this.menuItemEditOffset = new System.Windows.Forms.ToolStripMenuItem();
		this.menuHelp = new System.Windows.Forms.ToolStripMenuItem();
		this.menuItemHelpAbout = new System.Windows.Forms.ToolStripMenuItem();
		this.configFilesEditorHelpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
		this.panelMain.SuspendLayout();
		this.panelTreeView.SuspendLayout();
		this.panelGrid.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgvCalLink).BeginInit();
		((System.ComponentModel.ISupportInitialize)this.dgvCalData).BeginInit();
		this.menuStrip1.SuspendLayout();
		base.SuspendLayout();
		this.panelMain.Controls.Add(this.panelTreeView);
		this.panelMain.Controls.Add(this.panelGrid);
		this.panelMain.Controls.Add(this.menuStrip1);
		this.panelMain.Dock = System.Windows.Forms.DockStyle.Fill;
		this.panelMain.Location = new System.Drawing.Point(0, 0);
		this.panelMain.Name = "panelMain";
		this.panelMain.Size = new System.Drawing.Size(931, 489);
		this.panelMain.TabIndex = 1;
		this.panelTreeView.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
		this.panelTreeView.Controls.Add(this.treeView1);
		this.panelTreeView.Location = new System.Drawing.Point(6, 24);
		this.panelTreeView.Name = "panelTreeView";
		this.panelTreeView.Size = new System.Drawing.Size(419, 462);
		this.panelTreeView.TabIndex = 0;
		this.treeView1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
		this.treeView1.HideSelection = false;
		this.treeView1.Location = new System.Drawing.Point(6, 6);
		this.treeView1.Name = "treeView1";
		this.treeView1.Size = new System.Drawing.Size(410, 453);
		this.treeView1.TabIndex = 0;
		this.treeView1.AfterLabelEdit += new System.Windows.Forms.NodeLabelEditEventHandler(treeView1_AfterLabelEdit);
		this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(treeView1_AfterSelect);
		this.panelGrid.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.panelGrid.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
		this.panelGrid.Controls.Add(this.labelLinkFrom);
		this.panelGrid.Controls.Add(this.btnCancelOffset);
		this.panelGrid.Controls.Add(this.btnApplyOffset);
		this.panelGrid.Controls.Add(this.labelOffSet);
		this.panelGrid.Controls.Add(this.btnSetOffset);
		this.panelGrid.Controls.Add(this.txtOffset);
		this.panelGrid.Controls.Add(this.labelPathName);
		this.panelGrid.Controls.Add(this.txtError);
		this.panelGrid.Controls.Add(this.dgvCalLink);
		this.panelGrid.Controls.Add(this.dgvCalData);
		this.panelGrid.Location = new System.Drawing.Point(428, 24);
		this.panelGrid.Name = "panelGrid";
		this.panelGrid.Size = new System.Drawing.Size(500, 459);
		this.panelGrid.TabIndex = 1;
		this.labelLinkFrom.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.labelLinkFrom.AutoSize = true;
		this.labelLinkFrom.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.labelLinkFrom.Location = new System.Drawing.Point(14, 39);
		this.labelLinkFrom.Name = "labelLinkFrom";
		this.labelLinkFrom.Size = new System.Drawing.Size(0, 16);
		this.labelLinkFrom.TabIndex = 11;
		this.btnCancelOffset.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.btnCancelOffset.Location = new System.Drawing.Point(382, 433);
		this.btnCancelOffset.Name = "btnCancelOffset";
		this.btnCancelOffset.Size = new System.Drawing.Size(105, 23);
		this.btnCancelOffset.TabIndex = 10;
		this.btnCancelOffset.Text = "Cancel Loss Offset";
		this.btnCancelOffset.UseVisualStyleBackColor = true;
		this.btnCancelOffset.Visible = false;
		this.btnCancelOffset.Click += new System.EventHandler(btnCancelOffset_Click);
		this.btnApplyOffset.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.btnApplyOffset.Location = new System.Drawing.Point(382, 404);
		this.btnApplyOffset.Name = "btnApplyOffset";
		this.btnApplyOffset.Size = new System.Drawing.Size(105, 23);
		this.btnApplyOffset.TabIndex = 3;
		this.btnApplyOffset.Text = "Apply Loss Offset";
		this.btnApplyOffset.UseVisualStyleBackColor = true;
		this.btnApplyOffset.Visible = false;
		this.btnApplyOffset.Click += new System.EventHandler(btnApplyOffset_Click);
		this.labelOffSet.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.labelOffSet.AutoSize = true;
		this.labelOffSet.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.labelOffSet.Location = new System.Drawing.Point(460, 384);
		this.labelOffSet.Name = "labelOffSet";
		this.labelOffSet.Size = new System.Drawing.Size(26, 13);
		this.labelOffSet.TabIndex = 8;
		this.labelOffSet.Text = "(dB)";
		this.labelOffSet.Visible = false;
		this.btnSetOffset.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.btnSetOffset.Location = new System.Drawing.Point(381, 433);
		this.btnSetOffset.Name = "btnSetOffset";
		this.btnSetOffset.Size = new System.Drawing.Size(105, 23);
		this.btnSetOffset.TabIndex = 3;
		this.btnSetOffset.Text = "Set Loss Offset";
		this.btnSetOffset.UseVisualStyleBackColor = true;
		this.btnSetOffset.Click += new System.EventHandler(btnSetOffset_Click);
		this.txtOffset.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.txtOffset.BackColor = System.Drawing.SystemColors.ControlLightLight;
		this.txtOffset.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.txtOffset.Location = new System.Drawing.Point(391, 381);
		this.txtOffset.Name = "txtOffset";
		this.txtOffset.Size = new System.Drawing.Size(63, 20);
		this.txtOffset.TabIndex = 4;
		this.txtOffset.Visible = false;
		this.labelPathName.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.labelPathName.AutoSize = true;
		this.labelPathName.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.labelPathName.Location = new System.Drawing.Point(14, 6);
		this.labelPathName.Name = "labelPathName";
		this.labelPathName.Size = new System.Drawing.Size(0, 16);
		this.labelPathName.TabIndex = 9;
		this.txtError.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.txtError.BackColor = System.Drawing.SystemColors.ControlLightLight;
		this.txtError.Location = new System.Drawing.Point(14, 379);
		this.txtError.Multiline = true;
		this.txtError.Name = "txtError";
		this.txtError.ReadOnly = true;
		this.txtError.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
		this.txtError.Size = new System.Drawing.Size(361, 77);
		this.txtError.TabIndex = 2;
		this.dgvCalLink.AllowUserToAddRows = false;
		this.dgvCalLink.AllowUserToDeleteRows = false;
		this.dgvCalLink.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
		this.dgvCalLink.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
		dataGridViewCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvCalLink.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle;
		this.dgvCalLink.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgvCalLink.Columns.AddRange(this.LinkDest, this.SourcePath, this.SourceLink);
		dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window;
		dataGridViewCellStyle2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText;
		dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
		this.dgvCalLink.DefaultCellStyle = dataGridViewCellStyle2;
		this.dgvCalLink.Location = new System.Drawing.Point(14, 80);
		this.dgvCalLink.Name = "dgvCalLink";
		dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvCalLink.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
		this.dgvCalLink.Size = new System.Drawing.Size(473, 293);
		this.dgvCalLink.TabIndex = 12;
		this.dgvCalLink.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(dgvCalLink_CellBeginEdit);
		this.dgvCalLink.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(dgvCalLink_CellEndEdit);
		this.dgvCalLink.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(dgvCalLink_CellValidating);
		this.dgvCalLink.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(dgvCalLink_DataError);
		this.LinkDest.HeaderText = "Destination";
		this.LinkDest.Name = "LinkDest";
		this.LinkDest.Resizable = System.Windows.Forms.DataGridViewTriState.True;
		this.LinkDest.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
		this.SourcePath.HeaderText = "SourcePath";
		this.SourcePath.Name = "SourcePath";
		this.SourcePath.Resizable = System.Windows.Forms.DataGridViewTriState.True;
		this.SourceLink.HeaderText = "SourceLink";
		this.SourceLink.Name = "SourceLink";
		this.dgvCalData.AllowUserToOrderColumns = true;
		this.dgvCalData.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right;
		this.dgvCalData.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
		this.dgvCalData.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
		this.dgvCalData.CausesValidation = false;
		dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvCalData.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4;
		this.dgvCalData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgvCalData.Columns.AddRange(this.Frequency, this.Loss);
		dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Window;
		dataGridViewCellStyle5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.ControlText;
		dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
		this.dgvCalData.DefaultCellStyle = dataGridViewCellStyle5;
		this.dgvCalData.Location = new System.Drawing.Point(14, 80);
		this.dgvCalData.Name = "dgvCalData";
		dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control;
		dataGridViewCellStyle6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText;
		dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
		this.dgvCalData.RowHeadersDefaultCellStyle = dataGridViewCellStyle6;
		this.dgvCalData.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
		this.dgvCalData.Size = new System.Drawing.Size(473, 293);
		this.dgvCalData.TabIndex = 1;
		this.dgvCalData.TabStop = false;
		this.dgvCalData.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(dgvCalData_CellBeginEdit);
		this.dgvCalData.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(dgvCalData_CellEndEdit);
		this.dgvCalData.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(dgvCalData_CellValidating);
		this.dgvCalData.UserDeletedRow += new System.Windows.Forms.DataGridViewRowEventHandler(dgvCalData_UserDeletedRow);
		this.Frequency.HeaderText = "Frequency (MHz)";
		this.Frequency.Name = "Frequency";
		this.Loss.HeaderText = "Loss (dB)";
		this.Loss.Name = "Loss";
		this.menuStrip1.BackColor = System.Drawing.Color.Transparent;
		this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[3] { this.menuFile, this.menuEdit, this.menuHelp });
		this.menuStrip1.Location = new System.Drawing.Point(0, 0);
		this.menuStrip1.Name = "menuStrip1";
		this.menuStrip1.Size = new System.Drawing.Size(931, 24);
		this.menuStrip1.TabIndex = 2;
		this.menuStrip1.Text = "menuStrip1";
		this.menuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[3] { this.menuItemFileOpen, this.menuItemFileSave, this.menuItemFileSaveAs });
		this.menuFile.Name = "menuFile";
		this.menuFile.ShortcutKeyDisplayString = "F";
		this.menuFile.ShortcutKeys = System.Windows.Forms.Keys.F | System.Windows.Forms.Keys.Alt;
		this.menuFile.Size = new System.Drawing.Size(37, 20);
		this.menuFile.Text = "File";
		this.menuItemFileOpen.Image = QDART_MFG_CfgEditor.Properties.Resources.openHS;
		this.menuItemFileOpen.Name = "menuItemFileOpen";
		this.menuItemFileOpen.ShortcutKeys = System.Windows.Forms.Keys.O | System.Windows.Forms.Keys.Alt;
		this.menuItemFileOpen.Size = new System.Drawing.Size(192, 22);
		this.menuItemFileOpen.Text = "&Open Cal File...";
		this.menuItemFileOpen.Click += new System.EventHandler(btnOpenCalFile_Click);
		this.menuItemFileSave.Image = QDART_MFG_CfgEditor.Properties.Resources.saveHS;
		this.menuItemFileSave.Name = "menuItemFileSave";
		this.menuItemFileSave.ShortcutKeys = System.Windows.Forms.Keys.S | System.Windows.Forms.Keys.Alt;
		this.menuItemFileSave.Size = new System.Drawing.Size(192, 22);
		this.menuItemFileSave.Text = "&Save";
		this.menuItemFileSave.Click += new System.EventHandler(btnSave_Click);
		this.menuItemFileSaveAs.Name = "menuItemFileSaveAs";
		this.menuItemFileSaveAs.ShortcutKeys = System.Windows.Forms.Keys.A | System.Windows.Forms.Keys.Alt;
		this.menuItemFileSaveAs.Size = new System.Drawing.Size(192, 22);
		this.menuItemFileSaveAs.Text = "Save &As";
		this.menuItemFileSaveAs.Click += new System.EventHandler(btnSaveAs_Click);
		this.menuEdit.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[1] { this.menuItemEditOffset });
		this.menuEdit.Name = "menuEdit";
		this.menuEdit.ShortcutKeys = System.Windows.Forms.Keys.E | System.Windows.Forms.Keys.Alt;
		this.menuEdit.Size = new System.Drawing.Size(39, 20);
		this.menuEdit.Text = "Edit";
		this.menuItemEditOffset.Image = QDART_MFG_CfgEditor.Properties.Resources.EditTableHS;
		this.menuItemEditOffset.Name = "menuItemEditOffset";
		this.menuItemEditOffset.ShortcutKeys = System.Windows.Forms.Keys.O | System.Windows.Forms.Keys.Control;
		this.menuItemEditOffset.Size = new System.Drawing.Size(194, 22);
		this.menuItemEditOffset.Text = "Set Loss Offset";
		this.menuItemEditOffset.Click += new System.EventHandler(menuItemEditOffset_Click);
		this.menuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[2] { this.menuItemHelpAbout, this.configFilesEditorHelpToolStripMenuItem });
		this.menuHelp.Enabled = false;
		this.menuHelp.Name = "menuHelp";
		this.menuHelp.Size = new System.Drawing.Size(44, 20);
		this.menuHelp.Text = "Help";
		this.menuHelp.Visible = false;
		this.menuItemHelpAbout.Name = "menuItemHelpAbout";
		this.menuItemHelpAbout.Size = new System.Drawing.Size(200, 22);
		this.menuItemHelpAbout.Text = "About ConfigFilesEditor";
		this.menuItemHelpAbout.Click += new System.EventHandler(menuItemHelpAbout_Click);
		this.configFilesEditorHelpToolStripMenuItem.Name = "configFilesEditorHelpToolStripMenuItem";
		this.configFilesEditorHelpToolStripMenuItem.Size = new System.Drawing.Size(200, 22);
		this.configFilesEditorHelpToolStripMenuItem.Text = "ConfigFilesEditor Help";
		this.configFilesEditorHelpToolStripMenuItem.Click += new System.EventHandler(menuItemHelpAbout_Click);
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.panelMain);
		base.Name = "PathLossEditor";
		base.Size = new System.Drawing.Size(931, 489);
		this.panelMain.ResumeLayout(false);
		this.panelMain.PerformLayout();
		this.panelTreeView.ResumeLayout(false);
		this.panelGrid.ResumeLayout(false);
		this.panelGrid.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.dgvCalLink).EndInit();
		((System.ComponentModel.ISupportInitialize)this.dgvCalData).EndInit();
		this.menuStrip1.ResumeLayout(false);
		this.menuStrip1.PerformLayout();
		base.ResumeLayout(false);
	}
}
