using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Xml.Serialization;
using QSEQ;

namespace QDART_MFG_CfgEditor;

public class QSeqPanel : UserControl
{
	private enum MouseEventFlag : uint
	{
		Move = 1u,
		LeftDown = 2u,
		LeftUp = 4u
	}

	public delegate void TargetFileChangedEventHandler(string targetfile);

	private string target_file;

	private int currentDLL;

	private int currentDG;

	private int currentRS;

	private int currentDV;

	private bool manualAction = true;

	private QSEQ.root ori = new QSEQ.root();

	private QSEQ.root res = new QSEQ.root();

	private BindingSource bsRoot = new BindingSource();

	private BindingSource bsStationCfg = new BindingSource();

	private BindingSource bsLogAndDllCfg = new BindingSource();

	private BindingSource bsDllCfg = new BindingSource();

	private BindingSource bsDll = new BindingSource();

	private BindingSource bsDeviceGroups = new BindingSource();

	private BindingSource bsDeviceGroup = new BindingSource();

	private BindingSource bsResources = new BindingSource();

	private BindingSource bsResource = new BindingSource();

	private BindingSource bsDevices = new BindingSource();

	private IContainer components;

	private TextBox tbDomain;

	private TextBox tbTester;

	private Label label2;

	private Label label1;

	private Panel panel1;

	private GroupBox groupBox1;

	private GroupBox groupBox3;

	private GroupBox groupBox4;

	private TextBox tbSheetLog;

	private TextBox tbSeqLog;

	private Label label4;

	private Label label3;

	private GroupBox groupBox5;

	private DataGridView dgResources;

	private GroupBox groupBox2;

	private DataGridView dgDeviceGroups;

	private GroupBox groupBox7;

	private DataGridView dgDevices;

	private TextBox tbXmlLog;

	private Label label6;

	private Label lbDeviceID;

	private Label lbDeviceGroupID;

	private DataGridView dgDlls;

	private GroupBox groupBox6;

	private RichTextBox richTextBox1;

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

	public event TargetFileChangedEventHandler TargetFileChanged;

	[DllImport("user32.dll")]
	private static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

	[DllImport("user32.dll")]
	public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

	public QSeqPanel(RootConfig cfg)
	{
		InitializeComponent();
		InitVar(cfg);
		InitControls();
	}

	private void InitVar(RootConfig cfg)
	{
		RootConfigAllPanel[] panel = cfg.All[0].Panel;
		foreach (RootConfigAllPanel rootConfigAllPanel in panel)
		{
			if (cfg.Station.ToUpper() == rootConfigAllPanel.Name.ToUpper() && rootConfigAllPanel.File.Length > 0)
			{
				TargetFile = Common.GetPath(rootConfigAllPanel.File[0].Value);
			}
		}
		LoadTargetFile();
		BindingUI();
	}

	private void InitControls()
	{
	}

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

	private void LoadTargetFile()
	{
		string targetFile = TargetFile;
		if (File.Exists(targetFile))
		{
			using (FileStream fileStream = new FileStream(targetFile, FileMode.Open, FileAccess.Read, FileShare.Read))
			{
				XmlSerializer xmlSerializer = new XmlSerializer(typeof(QSEQ.root));
				ori = (QSEQ.root)xmlSerializer.Deserialize(fileStream);
				fileStream.Close();
			}
		}
	}

	private void BindingUI()
	{
		bsRoot.Clear();
		bsStationCfg.Clear();
		bsLogAndDllCfg.Clear();
		bsDllCfg.Clear();
		bsDll.Clear();
		bsDeviceGroups.Clear();
		bsDeviceGroup.Clear();
		bsResources.Clear();
		bsResource.Clear();
		bsDevices.Clear();
		tbTester.DataBindings.Clear();
		tbDomain.DataBindings.Clear();
		tbSeqLog.DataBindings.Clear();
		tbSheetLog.DataBindings.Clear();
		tbXmlLog.DataBindings.Clear();
		lbDeviceGroupID.DataBindings.Clear();
		lbDeviceID.DataBindings.Clear();
		if (ori != null)
		{
			try
			{
				bsRoot.Add(ori);
				bsStationCfg.DataSource = bsRoot;
				bsStationCfg.DataMember = "StationConfigSession";
				tbTester.DataBindings.Add("Text", bsStationCfg, "TesterName");
				tbDomain.DataBindings.Add("Text", bsStationCfg, "DomainName");
				bsLogAndDllCfg.DataSource = bsRoot;
				bsLogAndDllCfg.DataMember = "DeviceConfigSession";
				tbSeqLog.DataBindings.Add("Text", bsLogAndDllCfg, "SequenceLogFileNameTemplate");
				tbSheetLog.DataBindings.Add("Text", bsLogAndDllCfg, "XMLLogStyleSheet");
				tbXmlLog.DataBindings.Add("Text", bsLogAndDllCfg, "XMLLogFileNameTemplate");
				bsDllCfg.DataSource = bsLogAndDllCfg;
				bsDllCfg.DataMember = "Libraries";
				bsDll.DataSource = bsDllCfg;
				bsDll.DataMember = "DLL";
				dgDlls.AutoGenerateColumns = true;
				dgDlls.DataSource = bsDll;
				dgDlls.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
				bsDeviceGroups.DataSource = bsLogAndDllCfg;
				bsDeviceGroups.DataMember = "DeviceGroups";
				bsDeviceGroup.DataSource = bsDeviceGroups;
				bsDeviceGroup.DataMember = "DeviceGroup";
				dgDeviceGroups.AutoGenerateColumns = false;
				dgDeviceGroups.DataSource = bsDeviceGroup;
				dgDeviceGroups.Columns.Add("ID", "ID");
				dgDeviceGroups.Columns["ID"].DataPropertyName = "ID";
				dgDeviceGroups.Columns.Add("DeviceLogFileNameTemplate", "Device Log Name");
				dgDeviceGroups.Columns["DeviceLogFileNameTemplate"].DataPropertyName = "DeviceLogFileNameTemplate";
				dgDeviceGroups.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
				dgDeviceGroups.Columns[0].Frozen = true;
				lbDeviceGroupID.DataBindings.Add("Text", bsDeviceGroup, "ID");
				bsResources.DataSource = bsDeviceGroup;
				bsResources.DataMember = "Resources";
				bsResource.DataSource = bsResources;
				bsResource.DataMember = "Resource";
				dgResources.AutoGenerateColumns = true;
				dgResources.DataSource = bsResource;
				dgResources.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
				bsDevices.DataSource = bsDeviceGroup;
				bsDevices.DataMember = "Device";
				lbDeviceID.DataBindings.Add("Text", bsDevices, "ID");
				dgDevices.AutoGenerateColumns = false;
				dgDevices.DataSource = bsDevices;
				dgDevices.Columns.Add("ID", "ID");
				dgDevices.Columns["ID"].DataPropertyName = "ID";
				dgDevices.Columns.Add("NOTINUSE", "NotInUse");
				dgDevices.Columns["NOTINUSE"].DataPropertyName = "NOTINUSE";
				dgDevices.Columns.Add("UUT", "IsMobile");
				dgDevices.Columns["UUT"].DataPropertyName = "UUT";
				dgDevices.Columns.Add("Type", "DeviceType");
				dgDevices.Columns["Type"].DataPropertyName = "Type";
				dgDevices.Columns.Add("ConfigString", "ConfigString");
				dgDevices.Columns["ConfigString"].DataPropertyName = "ConfigString";
				dgDevices.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
				dgDevices.Columns[0].Frozen = true;
				((BindingList<DeviceGroup>)bsDeviceGroup.List).AllowNew = true;
				((BindingList<DeviceGroup>)bsDeviceGroup.List).AllowRemove = true;
				((BindingList<Resource>)bsResource.List).AllowNew = true;
				((BindingList<Resource>)bsResource.List).AllowRemove = true;
				((BindingList<Device>)bsDevices.List).AllowNew = true;
				((BindingList<Device>)bsDevices.List).AllowRemove = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}
	}

	private void dgDlls_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
	{
		if (e.Button == MouseButtons.Right && e.RowIndex >= 0)
		{
			click();
			((DataGridView)sender).ClearSelection();
			((DataGridView)sender).Rows[e.RowIndex].Selected = true;
			RightClickMenu();
		}
	}

	private void dgDeviceGroups_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
	{
		if (e.Button == MouseButtons.Right && e.RowIndex >= 0)
		{
			click();
			((DataGridView)sender).ClearSelection();
			((DataGridView)sender).Rows[e.RowIndex].Selected = true;
			RightClickMenu();
		}
	}

	private void dgResources_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
	{
		if (e.Button == MouseButtons.Right && e.RowIndex >= 0)
		{
			click();
			((DataGridView)sender).ClearSelection();
			((DataGridView)sender).Rows[e.RowIndex].Selected = true;
			RightClickMenu();
		}
	}

	private void dgDevices_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
	{
		if (e.Button == MouseButtons.Right && e.RowIndex >= 0)
		{
			click();
			((DataGridView)sender).ClearSelection();
			((DataGridView)sender).Rows[e.RowIndex].Selected = true;
			RightClickMenu();
		}
	}

	private void click()
	{
		mouse_event(MouseEventFlag.Move, 0, 0, 0u, UIntPtr.Zero);
		mouse_event(MouseEventFlag.LeftDown, 0, 0, 0u, UIntPtr.Zero);
		mouse_event(MouseEventFlag.LeftUp, 0, 0, 0u, UIntPtr.Zero);
	}

	private void RightClickMenu()
	{
		ContextMenuStrip contextMenuStrip = new ContextMenuStrip();
		contextMenuStrip.Items.Add("Delete");
		contextMenuStrip.Show(Control.MousePosition.X, Control.MousePosition.Y);
		contextMenuStrip.Click += contextMenuStrip1_ItemClicked;
	}

	private void contextMenuStrip1_ItemClicked(object sender, EventArgs e)
	{
		SendKeys.Send("{Delete}");
	}

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

	public void SaveResult()
	{
		try
		{
			string text = "";
			text = TargetFile;
			if (!File.Exists(text))
			{
				string directoryName = Path.GetDirectoryName(text);
				if (!Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				FileStream fileStream = File.Create(text);
				fileStream.Close();
			}
			if (File.GetAttributes(text).ToString().IndexOf("ReadOnly") != -1)
			{
				File.SetAttributes(text, FileAttributes.Normal);
			}
			SerialToFile(text);
		}
		catch
		{
		}
	}

	public void SaveResultAs()
	{
		try
		{
			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)
			{
				return;
			}
			targetFile = saveFileDialog.FileName;
			if (!File.Exists(targetFile))
			{
				string directoryName = Path.GetDirectoryName(targetFile);
				if (!Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				FileStream fileStream = File.Create(targetFile);
				fileStream.Close();
			}
			if (File.GetAttributes(targetFile).ToString().IndexOf("ReadOnly") != -1)
			{
				File.SetAttributes(targetFile, FileAttributes.Normal);
			}
			SerialToFile(targetFile);
			TargetFile = targetFile;
			OnFileChange(TargetFile);
			LoadTargetFile();
			BindingUI();
		}
		catch
		{
		}
	}

	private void SerialToFile(string fileName)
	{
		XmlSerializer xmlSerializer = new XmlSerializer(typeof(QSEQ.root));
		using StreamWriter streamWriter = new StreamWriter(fileName);
		xmlSerializer.Serialize(streamWriter, ori);
		streamWriter.Close();
	}

	private void dgDlls_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex == -1)
		{
			return;
		}
		((DataGridView)sender).ClearSelection();
		((DataGridView)sender).Rows[e.RowIndex].Selected = true;
		DataGridViewRow dataGridViewRow = ((DataGridView)sender).SelectedRows[0];
		if (dataGridViewRow.Cells.Count == 0)
		{
			return;
		}
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.DLL, (DataGridView)sender, e.RowIndex);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
			{
				bsDll.EndEdit();
				bsDll.AllowNew = true;
				DLLs dLLs = (DLLs)bsDll.Current;
				dLLs.DLL = qSeqPopUpEditForm.Tag.ToString();
				manualAction = false;
				bsRoot.Clear();
				bsRoot.Add(ori);
				dgDeviceGroups.CurrentCell = dgDeviceGroups.Rows[currentDG].Cells[0];
				dgResources.CurrentCell = dgResources.Rows[currentRS].Cells[0];
				dgDevices.CurrentCell = dgDevices.Rows[currentDV].Cells[0];
				((DataGridView)sender).CurrentCell = ((DataGridView)sender).Rows[e.RowIndex].Cells[0];
				manualAction = true;
			}
			else
			{
				((DataGridView)sender).Rows[e.RowIndex].Cells["DLL"].Value = qSeqPopUpEditForm.Tag.ToString();
			}
		}
	}

	private void dgDeviceGroups_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex == -1)
		{
			return;
		}
		((DataGridView)sender).ClearSelection();
		((DataGridView)sender).Rows[e.RowIndex].Selected = true;
		DataGridViewRow dataGridViewRow = ((DataGridView)sender).SelectedRows[0];
		if (dataGridViewRow.Cells.Count == 0)
		{
			return;
		}
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.DeviceGroup, (DataGridView)sender, e.RowIndex);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			Dictionary<string, string> dictionary = (Dictionary<string, string>)qSeqPopUpEditForm.Tag;
			if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
			{
				bsDeviceGroup.AllowNew = true;
				DeviceGroup deviceGroup = (DeviceGroup)bsDeviceGroup.Current;
				deviceGroup.ID = dictionary["ID"];
				deviceGroup.DeviceLogFileNameTemplate = dictionary["DeviceLogFileNameTemplate"];
				currentDG = e.RowIndex;
				manualAction = false;
				bsRoot.Clear();
				bsRoot.Add(ori);
				((DataGridView)sender).CurrentCell = ((DataGridView)sender).Rows[e.RowIndex].Cells[0];
				dgDlls.CurrentCell = dgDlls.Rows[currentDLL].Cells[0];
				manualAction = true;
			}
			else
			{
				((DataGridView)sender).Rows[e.RowIndex].Cells["ID"].Value = dictionary["ID"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["DeviceLogFileNameTemplate"].Value = dictionary["DeviceLogFileNameTemplate"];
			}
		}
	}

	private void dgResources_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex == -1)
		{
			return;
		}
		((DataGridView)sender).ClearSelection();
		((DataGridView)sender).Rows[e.RowIndex].Selected = true;
		DataGridViewRow dataGridViewRow = ((DataGridView)sender).SelectedRows[0];
		if (dataGridViewRow.Cells.Count == 0)
		{
			return;
		}
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.Resource, (DataGridView)sender, e.RowIndex);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			Dictionary<string, string> dictionary = (Dictionary<string, string>)qSeqPopUpEditForm.Tag;
			if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
			{
				bsDeviceGroup.AllowNew = true;
				bsResource.AllowNew = true;
				Resource resource = new Resource();
				resource.name = dictionary["name"];
				resource.config = dictionary["config"];
				((DeviceGroup)bsDeviceGroup.Current).Resources.Resource[e.RowIndex] = resource;
				manualAction = false;
				bsRoot.Clear();
				bsRoot.Add(ori);
				dgDeviceGroups.CurrentCell = dgDeviceGroups.Rows[currentDG].Cells[0];
				dgDlls.CurrentCell = dgDlls.Rows[currentDLL].Cells[0];
				dgDevices.CurrentCell = dgDevices.Rows[currentDV].Cells[0];
				((DataGridView)sender).CurrentCell = ((DataGridView)sender).Rows[e.RowIndex].Cells[0];
				manualAction = true;
			}
			else
			{
				((DataGridView)sender).Rows[e.RowIndex].Cells["name"].Value = dictionary["name"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["config"].Value = dictionary["config"];
			}
		}
	}

	private void dgDevices_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
	{
		if (e.RowIndex == -1)
		{
			return;
		}
		((DataGridView)sender).ClearSelection();
		((DataGridView)sender).Rows[e.RowIndex].Selected = true;
		DataGridViewRow dataGridViewRow = ((DataGridView)sender).SelectedRows[0];
		if (dataGridViewRow.Cells.Count == 0)
		{
			return;
		}
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.DeviceCfg, (DataGridView)sender, e.RowIndex);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			Dictionary<string, string> dictionary = (Dictionary<string, string>)qSeqPopUpEditForm.Tag;
			if (((DataGridView)sender).Rows[e.RowIndex].IsNewRow)
			{
				bsDeviceGroup.AllowNew = true;
				bsDevices.AllowNew = true;
				Device device = new Device();
				device.ID = dictionary["ID"];
				device.NOTINUSE = dictionary["NOTINUSE"];
				device.UUT = dictionary["UUT"];
				device.Type = dictionary["Type"];
				device.ConfigString = dictionary["ConfigString"];
				((DeviceGroup)bsDeviceGroup.Current).Device[e.RowIndex] = device;
				manualAction = false;
				bsRoot.Clear();
				bsRoot.Add(ori);
				dgDeviceGroups.CurrentCell = dgDeviceGroups.Rows[currentDG].Cells[0];
				dgDlls.CurrentCell = dgDlls.Rows[currentDLL].Cells[0];
				dgResources.CurrentCell = dgResources.Rows[currentRS].Cells[0];
				((DataGridView)sender).CurrentCell = ((DataGridView)sender).Rows[e.RowIndex].Cells[0];
				manualAction = true;
			}
			else
			{
				((DataGridView)sender).Rows[e.RowIndex].Cells["ID"].Value = dictionary["ID"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["NOTINUSE"].Value = dictionary["NOTINUSE"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["UUT"].Value = dictionary["UUT"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["Type"].Value = dictionary["Type"];
				((DataGridView)sender).Rows[e.RowIndex].Cells["ConfigString"].Value = dictionary["ConfigString"];
			}
		}
	}

	private void tbTester_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.TesterName, ((TextBox)sender).Text);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			((TextBox)sender).Text = qSeqPopUpEditForm.Tag.ToString();
		}
	}

	private void tbDomain_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.DomainName, ((TextBox)sender).Text);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			((TextBox)sender).Text = qSeqPopUpEditForm.Tag.ToString();
		}
	}

	private void tbSeqLog_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.SeqLogTxt, ((TextBox)sender).Text);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			((TextBox)sender).Text = qSeqPopUpEditForm.Tag.ToString();
		}
	}

	private void tbSheetLog_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.SheetLog, ((TextBox)sender).Text);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			((TextBox)sender).Text = qSeqPopUpEditForm.Tag.ToString();
		}
	}

	private void tbXmlLog_MouseDoubleClick(object sender, MouseEventArgs e)
	{
		QSeqPopUpEditForm qSeqPopUpEditForm = new QSeqPopUpEditForm(Common.EditTypes.XmlLog, ((TextBox)sender).Text);
		if (qSeqPopUpEditForm.ShowDialog() == DialogResult.OK)
		{
			((TextBox)sender).Text = qSeqPopUpEditForm.Tag.ToString();
		}
	}

	private void dgDlls_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
	{
		if (MessageBox.Show("Are you sure to delete select row?", "Delete Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
		{
			e.Cancel = true;
		}
	}

	private void dgDeviceGroups_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
	{
		if (MessageBox.Show("Are you sure to delete select row?", "Delete Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
		{
			e.Cancel = true;
		}
	}

	private void dgResources_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
	{
		if (MessageBox.Show("Are you sure to delete select row?", "Delete Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
		{
			e.Cancel = true;
		}
	}

	private void dgDevices_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
	{
		if (MessageBox.Show("Are you sure to delete select row?", "Delete Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.OK)
		{
			e.Cancel = true;
		}
	}

	private void dgDeviceGroups_SelectionChanged(object sender, EventArgs e)
	{
		if (dgDeviceGroups.Rows != null && dgDeviceGroups.Rows.Count > 0 && dgDeviceGroups.CurrentRow != null && manualAction)
		{
			currentDG = dgDeviceGroups.CurrentRow.Index;
		}
	}

	private void dgDlls_SelectionChanged(object sender, EventArgs e)
	{
		if (dgDlls.Rows != null && dgDlls.Rows.Count > 0 && dgDlls.CurrentRow != null && manualAction)
		{
			currentDLL = dgDlls.CurrentRow.Index;
		}
	}

	private void dgResources_SelectionChanged(object sender, EventArgs e)
	{
		if (dgResources.Rows != null && dgResources.Rows.Count > 0 && dgResources.CurrentRow != null && manualAction)
		{
			currentRS = dgResources.CurrentRow.Index;
		}
	}

	private void dgDevices_SelectionChanged(object sender, EventArgs e)
	{
		if (dgDevices.Rows != null && dgDevices.Rows.Count > 0 && dgDevices.CurrentRow != null && manualAction)
		{
			currentDV = dgDevices.CurrentRow.Index;
		}
	}

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

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

	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();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.tbDomain = new System.Windows.Forms.TextBox();
		this.tbTester = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		this.panel1 = new System.Windows.Forms.Panel();
		this.groupBox6 = new System.Windows.Forms.GroupBox();
		this.richTextBox1 = new System.Windows.Forms.RichTextBox();
		this.groupBox5 = new System.Windows.Forms.GroupBox();
		this.dgResources = new System.Windows.Forms.DataGridView();
		this.groupBox7 = new System.Windows.Forms.GroupBox();
		this.dgDevices = new System.Windows.Forms.DataGridView();
		this.lbDeviceID = new System.Windows.Forms.Label();
		this.groupBox2 = new System.Windows.Forms.GroupBox();
		this.dgDeviceGroups = new System.Windows.Forms.DataGridView();
		this.lbDeviceGroupID = new System.Windows.Forms.Label();
		this.groupBox3 = new System.Windows.Forms.GroupBox();
		this.dgDlls = new System.Windows.Forms.DataGridView();
		this.groupBox4 = new System.Windows.Forms.GroupBox();
		this.tbXmlLog = new System.Windows.Forms.TextBox();
		this.tbSheetLog = new System.Windows.Forms.TextBox();
		this.label6 = new System.Windows.Forms.Label();
		this.tbSeqLog = new System.Windows.Forms.TextBox();
		this.label4 = new System.Windows.Forms.Label();
		this.label3 = new System.Windows.Forms.Label();
		this.groupBox1.SuspendLayout();
		this.panel1.SuspendLayout();
		this.groupBox6.SuspendLayout();
		this.groupBox5.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgResources).BeginInit();
		this.groupBox7.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgDevices).BeginInit();
		this.groupBox2.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgDeviceGroups).BeginInit();
		this.groupBox3.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dgDlls).BeginInit();
		this.groupBox4.SuspendLayout();
		base.SuspendLayout();
		this.groupBox1.Controls.Add(this.tbDomain);
		this.groupBox1.Controls.Add(this.tbTester);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Location = new System.Drawing.Point(3, 5);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(455, 40);
		this.groupBox1.TabIndex = 2;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "StationConfig";
		this.tbDomain.Location = new System.Drawing.Point(310, 17);
		this.tbDomain.Name = "tbDomain";
		this.tbDomain.ReadOnly = true;
		this.tbDomain.Size = new System.Drawing.Size(123, 20);
		this.tbDomain.TabIndex = 2;
		this.tbDomain.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(tbDomain_MouseDoubleClick);
		this.tbTester.Location = new System.Drawing.Point(82, 16);
		this.tbTester.Name = "tbTester";
		this.tbTester.ReadOnly = true;
		this.tbTester.Size = new System.Drawing.Size(123, 20);
		this.tbTester.TabIndex = 1;
		this.tbTester.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(tbTester_MouseDoubleClick);
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(231, 20);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(74, 13);
		this.label2.TabIndex = 0;
		this.label2.Text = "Domain Name";
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(10, 19);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(68, 13);
		this.label1.TabIndex = 0;
		this.label1.Text = "Tester Name";
		this.panel1.Controls.Add(this.groupBox6);
		this.panel1.Controls.Add(this.groupBox5);
		this.panel1.Controls.Add(this.groupBox1);
		this.panel1.Controls.Add(this.groupBox7);
		this.panel1.Controls.Add(this.groupBox2);
		this.panel1.Controls.Add(this.groupBox3);
		this.panel1.Controls.Add(this.groupBox4);
		this.panel1.Location = new System.Drawing.Point(2, 0);
		this.panel1.Name = "panel1";
		this.panel1.Size = new System.Drawing.Size(935, 482);
		this.panel1.TabIndex = 1;
		this.groupBox6.Controls.Add(this.richTextBox1);
		this.groupBox6.Font = new System.Drawing.Font("Microsoft Sans Serif", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.groupBox6.ForeColor = System.Drawing.Color.Blue;
		this.groupBox6.Location = new System.Drawing.Point(748, 278);
		this.groupBox6.Name = "groupBox6";
		this.groupBox6.Size = new System.Drawing.Size(171, 195);
		this.groupBox6.TabIndex = 18;
		this.groupBox6.TabStop = false;
		this.groupBox6.Text = "Instructions";
		this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
		this.richTextBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.richTextBox1.ForeColor = System.Drawing.Color.Blue;
		this.richTextBox1.Location = new System.Drawing.Point(18, 35);
		this.richTextBox1.Name = "richTextBox1";
		this.richTextBox1.ReadOnly = true;
		this.richTextBox1.Size = new System.Drawing.Size(150, 130);
		this.richTextBox1.TabIndex = 0;
		this.richTextBox1.Text = "Edit:\n\tDouble Click\nDelete:\n\tRight Click";
		this.groupBox5.Controls.Add(this.dgResources);
		this.groupBox5.Location = new System.Drawing.Point(464, 147);
		this.groupBox5.Name = "groupBox5";
		this.groupBox5.Size = new System.Drawing.Size(455, 116);
		this.groupBox5.TabIndex = 15;
		this.groupBox5.TabStop = false;
		this.groupBox5.Text = "Resources";
		this.dgResources.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgResources.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgResources.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgResources.Location = new System.Drawing.Point(3, 16);
		this.dgResources.Name = "dgResources";
		this.dgResources.ReadOnly = true;
		this.dgResources.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
		this.dgResources.Size = new System.Drawing.Size(449, 97);
		this.dgResources.TabIndex = 0;
		this.dgResources.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgResources_CellDoubleClick);
		this.dgResources.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dgResources_CellMouseDown);
		this.dgResources.SelectionChanged += new System.EventHandler(dgResources_SelectionChanged);
		this.dgResources.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(dgResources_UserDeletingRow);
		this.groupBox7.Controls.Add(this.dgDevices);
		this.groupBox7.Controls.Add(this.lbDeviceID);
		this.groupBox7.Location = new System.Drawing.Point(6, 278);
		this.groupBox7.Name = "groupBox7";
		this.groupBox7.Size = new System.Drawing.Size(736, 195);
		this.groupBox7.TabIndex = 16;
		this.groupBox7.TabStop = false;
		this.groupBox7.Text = "Device";
		this.dgDevices.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgDevices.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgDevices.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgDevices.Location = new System.Drawing.Point(3, 16);
		this.dgDevices.Name = "dgDevices";
		this.dgDevices.ReadOnly = true;
		this.dgDevices.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
		this.dgDevices.Size = new System.Drawing.Size(730, 176);
		this.dgDevices.TabIndex = 0;
		this.dgDevices.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgDevices_CellDoubleClick);
		this.dgDevices.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dgDevices_CellMouseDown);
		this.dgDevices.SelectionChanged += new System.EventHandler(dgDevices_SelectionChanged);
		this.dgDevices.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(dgDevices_UserDeletingRow);
		this.lbDeviceID.AutoSize = true;
		this.lbDeviceID.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.lbDeviceID.ForeColor = System.Drawing.Color.Red;
		this.lbDeviceID.Location = new System.Drawing.Point(51, 0);
		this.lbDeviceID.Name = "lbDeviceID";
		this.lbDeviceID.Size = new System.Drawing.Size(0, 16);
		this.lbDeviceID.TabIndex = 17;
		this.groupBox2.Controls.Add(this.dgDeviceGroups);
		this.groupBox2.Controls.Add(this.lbDeviceGroupID);
		this.groupBox2.Location = new System.Drawing.Point(3, 148);
		this.groupBox2.Name = "groupBox2";
		this.groupBox2.Size = new System.Drawing.Size(455, 116);
		this.groupBox2.TabIndex = 14;
		this.groupBox2.TabStop = false;
		this.groupBox2.Text = "DeviceGroup";
		this.dgDeviceGroups.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgDeviceGroups.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dgDeviceGroups.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgDeviceGroups.Location = new System.Drawing.Point(3, 16);
		this.dgDeviceGroups.Name = "dgDeviceGroups";
		this.dgDeviceGroups.ReadOnly = true;
		this.dgDeviceGroups.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
		this.dgDeviceGroups.Size = new System.Drawing.Size(449, 97);
		this.dgDeviceGroups.TabIndex = 13;
		this.dgDeviceGroups.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgDeviceGroups_CellDoubleClick);
		this.dgDeviceGroups.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dgDeviceGroups_CellMouseDown);
		this.dgDeviceGroups.SelectionChanged += new System.EventHandler(dgDeviceGroups_SelectionChanged);
		this.dgDeviceGroups.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(dgDeviceGroups_UserDeletingRow);
		this.lbDeviceGroupID.AutoSize = true;
		this.lbDeviceGroupID.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.lbDeviceGroupID.ForeColor = System.Drawing.Color.Red;
		this.lbDeviceGroupID.Location = new System.Drawing.Point(80, 0);
		this.lbDeviceGroupID.Name = "lbDeviceGroupID";
		this.lbDeviceGroupID.Size = new System.Drawing.Size(0, 16);
		this.lbDeviceGroupID.TabIndex = 17;
		this.groupBox3.Controls.Add(this.dgDlls);
		this.groupBox3.Location = new System.Drawing.Point(464, 1);
		this.groupBox3.Name = "groupBox3";
		this.groupBox3.Size = new System.Drawing.Size(455, 135);
		this.groupBox3.TabIndex = 8;
		this.groupBox3.TabStop = false;
		this.groupBox3.Text = "Libraries";
		this.dgDlls.BackgroundColor = System.Drawing.SystemColors.Control;
		this.dgDlls.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		dataGridViewCellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
		dataGridViewCellStyle.BackColor = System.Drawing.SystemColors.Window;
		dataGridViewCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 134);
		dataGridViewCellStyle.ForeColor = System.Drawing.Color.Black;
		dataGridViewCellStyle.SelectionBackColor = System.Drawing.SystemColors.Highlight;
		dataGridViewCellStyle.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
		dataGridViewCellStyle.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
		this.dgDlls.DefaultCellStyle = dataGridViewCellStyle;
		this.dgDlls.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dgDlls.Location = new System.Drawing.Point(3, 16);
		this.dgDlls.Name = "dgDlls";
		this.dgDlls.ReadOnly = true;
		this.dgDlls.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
		this.dgDlls.Size = new System.Drawing.Size(449, 116);
		this.dgDlls.TabIndex = 8;
		this.dgDlls.CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(dgDlls_CellDoubleClick);
		this.dgDlls.CellMouseDown += new System.Windows.Forms.DataGridViewCellMouseEventHandler(dgDlls_CellMouseDown);
		this.dgDlls.SelectionChanged += new System.EventHandler(dgDlls_SelectionChanged);
		this.dgDlls.UserDeletingRow += new System.Windows.Forms.DataGridViewRowCancelEventHandler(dgDlls_UserDeletingRow);
		this.groupBox4.Controls.Add(this.tbXmlLog);
		this.groupBox4.Controls.Add(this.tbSheetLog);
		this.groupBox4.Controls.Add(this.label6);
		this.groupBox4.Controls.Add(this.tbSeqLog);
		this.groupBox4.Controls.Add(this.label4);
		this.groupBox4.Controls.Add(this.label3);
		this.groupBox4.Location = new System.Drawing.Point(3, 50);
		this.groupBox4.Name = "groupBox4";
		this.groupBox4.Size = new System.Drawing.Size(455, 86);
		this.groupBox4.TabIndex = 9;
		this.groupBox4.TabStop = false;
		this.groupBox4.Text = "Logs";
		this.tbXmlLog.Location = new System.Drawing.Point(106, 61);
		this.tbXmlLog.Name = "tbXmlLog";
		this.tbXmlLog.ReadOnly = true;
		this.tbXmlLog.Size = new System.Drawing.Size(327, 20);
		this.tbXmlLog.TabIndex = 3;
		this.tbXmlLog.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(tbXmlLog_MouseDoubleClick);
		this.tbSheetLog.Location = new System.Drawing.Point(106, 38);
		this.tbSheetLog.Name = "tbSheetLog";
		this.tbSheetLog.ReadOnly = true;
		this.tbSheetLog.Size = new System.Drawing.Size(327, 20);
		this.tbSheetLog.TabIndex = 3;
		this.tbSheetLog.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(tbSheetLog_MouseDoubleClick);
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(12, 64);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(45, 13);
		this.label6.TabIndex = 1;
		this.label6.Text = "Xml Log";
		this.tbSeqLog.Location = new System.Drawing.Point(106, 14);
		this.tbSeqLog.Name = "tbSeqLog";
		this.tbSeqLog.ReadOnly = true;
		this.tbSeqLog.Size = new System.Drawing.Size(327, 20);
		this.tbSeqLog.TabIndex = 3;
		this.tbSeqLog.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(tbSeqLog_MouseDoubleClick);
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(12, 41);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(56, 13);
		this.label4.TabIndex = 1;
		this.label4.Text = "Sheet Log";
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(12, 17);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(77, 13);
		this.label3.TabIndex = 0;
		this.label3.Text = "Sequence Log";
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.panel1);
		base.Name = "QSeqPanel";
		base.Size = new System.Drawing.Size(937, 485);
		base.Load += new System.EventHandler(QSeqPanel_Load);
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		this.panel1.ResumeLayout(false);
		this.groupBox6.ResumeLayout(false);
		this.groupBox5.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.dgResources).EndInit();
		this.groupBox7.ResumeLayout(false);
		this.groupBox7.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.dgDevices).EndInit();
		this.groupBox2.ResumeLayout(false);
		this.groupBox2.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.dgDeviceGroups).EndInit();
		this.groupBox3.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.dgDlls).EndInit();
		this.groupBox4.ResumeLayout(false);
		this.groupBox4.PerformLayout();
		base.ResumeLayout(false);
	}
}
