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

namespace QDART_MFG_CfgEditor;

public class WCNStationCalPanel : UserControl
{
	private string target_file;

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

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

	private root rt = new root();

	private Instrument sg = new Instrument();

	private Instrument pm = new Instrument();

	private IContainer components;

	private Panel pl_pad_pm;

	public Label label20;

	public ComboBox cb_pm_pad;

	private Panel pl_pad_sg;

	public Label label14;

	public ComboBox cb_sg_pad;

	private Panel pl_ip_pm;

	public TextBox tb_pm_ip;

	public Label lb_pm_ip;

	private Panel pl_ip_sg;

	public TextBox tb_sg_ip;

	public Label lb_sg_ip;

	private Panel pl_sad_pm;

	public Label label18;

	public ComboBox cb_pm_sad;

	private Panel pl_sad_sg;

	public Label label12;

	public ComboBox cb_sg_sad;

	public Label label17;

	public Label label11;

	public Label label16;

	public Label label10;

	public ComboBox cb_pm_remote;

	public ComboBox cb_sg_remote;

	public ComboBox cb_pm_name;

	public ComboBox cb_sg_name;

	public Label label15;

	public Label label1;

	private ToolTip toolTip1;

	public WCNStationCalPanel(RootConfig cfg)
	{
		InitializeComponent();
		InitVar(cfg);
		InitControls();
		InitProperty();
	}

	private void InitVar(RootConfig cfg)
	{
		sgInstlist.Clear();
		pmInstlist.Clear();
		RootConfigAllInstList[] instList = cfg.All[0].InstList;
		foreach (RootConfigAllInstList rootConfigAllInstList in instList)
		{
			switch (rootConfigAllInstList.Name)
			{
			case "WCN":
			{
				InfoItem[] infoItem3 = rootConfigAllInstList.InfoItem;
				foreach (InfoItem infoItem4 in infoItem3)
				{
					sgInstlist.Add(infoItem4.Name, infoItem4.Value);
				}
				break;
			}
			case "WCNStationCalSG":
			{
				InfoItem[] infoItem = rootConfigAllInstList.InfoItem;
				foreach (InfoItem infoItem2 in infoItem)
				{
					pmInstlist.Add(infoItem2.Name, infoItem2.Value);
				}
				break;
			}
			}
		}
		RootConfigAllPanel[] panel = cfg.All[0].Panel;
		foreach (RootConfigAllPanel rootConfigAllPanel in panel)
		{
			if (!(cfg.Station == rootConfigAllPanel.Name))
			{
				continue;
			}
			RootConfigAllPanelFile[] file = rootConfigAllPanel.File;
			foreach (RootConfigAllPanelFile rootConfigAllPanelFile in file)
			{
				string type;
				if ((type = rootConfigAllPanelFile.Type) != null && type == "Target")
				{
					target_file = Common.GetPath(rootConfigAllPanelFile.Value);
				}
			}
		}
		LoadTargetFile(target_file);
	}

	private void InitControls()
	{
		List<string> list = new List<string>();
		for (int i = 1; i < 100; i++)
		{
			list.Add(i.ToString());
		}
		cb_sg_pad.Items.AddRange(list.ToArray());
		cb_pm_pad.Items.AddRange(list.ToArray());
		cb_sg_name.Items.AddRange(sgInstlist.Keys.ToArray());
		cb_pm_name.Items.AddRange(pmInstlist.Keys.ToArray());
		cb_sg_remote.Items.AddRange(new string[3] { "GPIB", "IP", "USB" });
		cb_pm_remote.Items.AddRange(new string[3] { "GPIB", "IP", "USB" });
		tb_sg_ip.Tag = new Tip(tb_sg_ip, lb_sg_ip, toolTip1, Tip.TxtContent.IP_ADDRESS, "ip", "Example: 192.168.0.2", "IP address, Format like: 192.168.0.2");
		tb_pm_ip.Tag = new Tip(tb_pm_ip, lb_pm_ip, toolTip1, Tip.TxtContent.IP_ADDRESS, "ip", "Example: 192.168.0.2", "IP address, Format like: 192.168.0.2");
	}

	private void InitProperty()
	{
	}

	private void LoadTargetFile(string target)
	{
		sg = null;
		pm = null;
		using FileStream fileStream = new FileStream(target_file, FileMode.Open, FileAccess.Read, FileShare.Read);
		rootInstrumentConfList rootInstrumentConfList = null;
		XmlSerializer xmlSerializer = new XmlSerializer(typeof(root));
		rt = (root)xmlSerializer.Deserialize(fileStream);
		if (rt != null)
		{
			rootInstrumentConfList = rt.InstrumentConfList;
			if (rootInstrumentConfList.Instruments.Length != 0)
			{
				rootInstrumentConfListInstruments rootInstrumentConfListInstruments = rootInstrumentConfList.Instruments[0];
				Instrument[] instrument = rootInstrumentConfListInstruments.Instrument;
				foreach (Instrument instrument2 in instrument)
				{
					if (instrument2.Model.Contains("PM_"))
					{
						pm = instrument2;
					}
					else if (instrument2.Model.Contains("SG_"))
					{
						sg = instrument2;
					}
				}
			}
		}
		fileStream.Close();
	}

	public void SaveResult()
	{
	}

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

	private void InitializeComponent()
	{
		this.components = new System.ComponentModel.Container();
		this.pl_pad_pm = new System.Windows.Forms.Panel();
		this.label20 = new System.Windows.Forms.Label();
		this.cb_pm_pad = new System.Windows.Forms.ComboBox();
		this.pl_pad_sg = new System.Windows.Forms.Panel();
		this.label14 = new System.Windows.Forms.Label();
		this.cb_sg_pad = new System.Windows.Forms.ComboBox();
		this.pl_ip_pm = new System.Windows.Forms.Panel();
		this.tb_pm_ip = new System.Windows.Forms.TextBox();
		this.lb_pm_ip = new System.Windows.Forms.Label();
		this.pl_ip_sg = new System.Windows.Forms.Panel();
		this.tb_sg_ip = new System.Windows.Forms.TextBox();
		this.lb_sg_ip = new System.Windows.Forms.Label();
		this.pl_sad_pm = new System.Windows.Forms.Panel();
		this.label18 = new System.Windows.Forms.Label();
		this.cb_pm_sad = new System.Windows.Forms.ComboBox();
		this.pl_sad_sg = new System.Windows.Forms.Panel();
		this.label12 = new System.Windows.Forms.Label();
		this.cb_sg_sad = new System.Windows.Forms.ComboBox();
		this.label17 = new System.Windows.Forms.Label();
		this.label11 = new System.Windows.Forms.Label();
		this.label16 = new System.Windows.Forms.Label();
		this.label10 = new System.Windows.Forms.Label();
		this.cb_pm_remote = new System.Windows.Forms.ComboBox();
		this.cb_sg_remote = new System.Windows.Forms.ComboBox();
		this.cb_pm_name = new System.Windows.Forms.ComboBox();
		this.cb_sg_name = new System.Windows.Forms.ComboBox();
		this.label15 = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
		this.pl_pad_pm.SuspendLayout();
		this.pl_pad_sg.SuspendLayout();
		this.pl_ip_pm.SuspendLayout();
		this.pl_ip_sg.SuspendLayout();
		this.pl_sad_pm.SuspendLayout();
		this.pl_sad_sg.SuspendLayout();
		base.SuspendLayout();
		this.pl_pad_pm.Controls.Add(this.label20);
		this.pl_pad_pm.Controls.Add(this.cb_pm_pad);
		this.pl_pad_pm.Location = new System.Drawing.Point(362, 84);
		this.pl_pad_pm.Name = "pl_pad_pm";
		this.pl_pad_pm.Size = new System.Drawing.Size(82, 48);
		this.pl_pad_pm.TabIndex = 54;
		this.label20.AutoSize = true;
		this.label20.Location = new System.Drawing.Point(-1, 3);
		this.label20.Name = "label20";
		this.label20.Size = new System.Drawing.Size(25, 13);
		this.label20.TabIndex = 14;
		this.label20.Text = "pad";
		this.cb_pm_pad.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_pm_pad.FormattingEnabled = true;
		this.cb_pm_pad.Location = new System.Drawing.Point(2, 18);
		this.cb_pm_pad.Name = "cb_pm_pad";
		this.cb_pm_pad.Size = new System.Drawing.Size(51, 21);
		this.cb_pm_pad.TabIndex = 12;
		this.pl_pad_sg.Controls.Add(this.label14);
		this.pl_pad_sg.Controls.Add(this.cb_sg_pad);
		this.pl_pad_sg.Location = new System.Drawing.Point(362, 35);
		this.pl_pad_sg.Name = "pl_pad_sg";
		this.pl_pad_sg.Size = new System.Drawing.Size(82, 48);
		this.pl_pad_sg.TabIndex = 55;
		this.label14.AutoSize = true;
		this.label14.Location = new System.Drawing.Point(-1, 3);
		this.label14.Name = "label14";
		this.label14.Size = new System.Drawing.Size(25, 13);
		this.label14.TabIndex = 14;
		this.label14.Text = "pad";
		this.cb_sg_pad.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_sg_pad.FormattingEnabled = true;
		this.cb_sg_pad.Location = new System.Drawing.Point(2, 18);
		this.cb_sg_pad.Name = "cb_sg_pad";
		this.cb_sg_pad.Size = new System.Drawing.Size(51, 21);
		this.cb_sg_pad.TabIndex = 12;
		this.pl_ip_pm.Controls.Add(this.tb_pm_ip);
		this.pl_ip_pm.Controls.Add(this.lb_pm_ip);
		this.pl_ip_pm.Location = new System.Drawing.Point(535, 85);
		this.pl_ip_pm.Name = "pl_ip_pm";
		this.pl_ip_pm.Size = new System.Drawing.Size(120, 46);
		this.pl_ip_pm.TabIndex = 52;
		this.tb_pm_ip.Location = new System.Drawing.Point(4, 18);
		this.tb_pm_ip.Name = "tb_pm_ip";
		this.tb_pm_ip.Size = new System.Drawing.Size(90, 20);
		this.tb_pm_ip.TabIndex = 20;
		this.lb_pm_ip.AutoSize = true;
		this.lb_pm_ip.Location = new System.Drawing.Point(1, 2);
		this.lb_pm_ip.Name = "lb_pm_ip";
		this.lb_pm_ip.Size = new System.Drawing.Size(15, 13);
		this.lb_pm_ip.TabIndex = 19;
		this.lb_pm_ip.Text = "ip";
		this.pl_ip_sg.Controls.Add(this.tb_sg_ip);
		this.pl_ip_sg.Controls.Add(this.lb_sg_ip);
		this.pl_ip_sg.Location = new System.Drawing.Point(535, 36);
		this.pl_ip_sg.Name = "pl_ip_sg";
		this.pl_ip_sg.Size = new System.Drawing.Size(120, 46);
		this.pl_ip_sg.TabIndex = 53;
		this.tb_sg_ip.Location = new System.Drawing.Point(4, 18);
		this.tb_sg_ip.Name = "tb_sg_ip";
		this.tb_sg_ip.Size = new System.Drawing.Size(90, 20);
		this.tb_sg_ip.TabIndex = 20;
		this.lb_sg_ip.AutoSize = true;
		this.lb_sg_ip.Location = new System.Drawing.Point(1, 2);
		this.lb_sg_ip.Name = "lb_sg_ip";
		this.lb_sg_ip.Size = new System.Drawing.Size(15, 13);
		this.lb_sg_ip.TabIndex = 19;
		this.lb_sg_ip.Text = "ip";
		this.pl_sad_pm.Controls.Add(this.label18);
		this.pl_sad_pm.Controls.Add(this.cb_pm_sad);
		this.pl_sad_pm.Location = new System.Drawing.Point(448, 83);
		this.pl_sad_pm.Name = "pl_sad_pm";
		this.pl_sad_pm.Size = new System.Drawing.Size(82, 48);
		this.pl_sad_pm.TabIndex = 50;
		this.pl_sad_pm.Visible = false;
		this.label18.AutoSize = true;
		this.label18.Location = new System.Drawing.Point(-1, 3);
		this.label18.Name = "label18";
		this.label18.Size = new System.Drawing.Size(24, 13);
		this.label18.TabIndex = 17;
		this.label18.Text = "sad";
		this.cb_pm_sad.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_pm_sad.FormattingEnabled = true;
		this.cb_pm_sad.Location = new System.Drawing.Point(2, 18);
		this.cb_pm_sad.Name = "cb_pm_sad";
		this.cb_pm_sad.Size = new System.Drawing.Size(54, 21);
		this.cb_pm_sad.TabIndex = 16;
		this.pl_sad_sg.Controls.Add(this.label12);
		this.pl_sad_sg.Controls.Add(this.cb_sg_sad);
		this.pl_sad_sg.Location = new System.Drawing.Point(448, 35);
		this.pl_sad_sg.Name = "pl_sad_sg";
		this.pl_sad_sg.Size = new System.Drawing.Size(82, 48);
		this.pl_sad_sg.TabIndex = 51;
		this.pl_sad_sg.Visible = false;
		this.label12.AutoSize = true;
		this.label12.Location = new System.Drawing.Point(-1, 3);
		this.label12.Name = "label12";
		this.label12.Size = new System.Drawing.Size(24, 13);
		this.label12.TabIndex = 17;
		this.label12.Text = "sad";
		this.cb_sg_sad.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_sg_sad.FormattingEnabled = true;
		this.cb_sg_sad.Location = new System.Drawing.Point(2, 18);
		this.cb_sg_sad.Name = "cb_sg_sad";
		this.cb_sg_sad.Size = new System.Drawing.Size(54, 21);
		this.cb_sg_sad.TabIndex = 16;
		this.label17.AutoSize = true;
		this.label17.Location = new System.Drawing.Point(262, 86);
		this.label17.Name = "label17";
		this.label17.Size = new System.Drawing.Size(39, 13);
		this.label17.TabIndex = 48;
		this.label17.Text = "remote";
		this.label11.AutoSize = true;
		this.label11.Location = new System.Drawing.Point(262, 37);
		this.label11.Name = "label11";
		this.label11.Size = new System.Drawing.Size(39, 13);
		this.label11.TabIndex = 49;
		this.label11.Text = "remote";
		this.label16.AutoSize = true;
		this.label16.Location = new System.Drawing.Point(135, 87);
		this.label16.Name = "label16";
		this.label16.Size = new System.Drawing.Size(33, 13);
		this.label16.TabIndex = 46;
		this.label16.Text = "name";
		this.label10.AutoSize = true;
		this.label10.Location = new System.Drawing.Point(135, 38);
		this.label10.Name = "label10";
		this.label10.Size = new System.Drawing.Size(33, 13);
		this.label10.TabIndex = 47;
		this.label10.Text = "name";
		this.cb_pm_remote.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_pm_remote.FormattingEnabled = true;
		this.cb_pm_remote.Location = new System.Drawing.Point(265, 102);
		this.cb_pm_remote.Name = "cb_pm_remote";
		this.cb_pm_remote.Size = new System.Drawing.Size(72, 21);
		this.cb_pm_remote.TabIndex = 44;
		this.cb_sg_remote.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_sg_remote.FormattingEnabled = true;
		this.cb_sg_remote.Location = new System.Drawing.Point(265, 53);
		this.cb_sg_remote.Name = "cb_sg_remote";
		this.cb_sg_remote.Size = new System.Drawing.Size(72, 21);
		this.cb_sg_remote.TabIndex = 45;
		this.cb_pm_name.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_pm_name.FormattingEnabled = true;
		this.cb_pm_name.Location = new System.Drawing.Point(137, 102);
		this.cb_pm_name.Name = "cb_pm_name";
		this.cb_pm_name.Size = new System.Drawing.Size(102, 21);
		this.cb_pm_name.TabIndex = 42;
		this.cb_sg_name.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
		this.cb_sg_name.FormattingEnabled = true;
		this.cb_sg_name.Location = new System.Drawing.Point(137, 53);
		this.cb_sg_name.Name = "cb_sg_name";
		this.cb_sg_name.Size = new System.Drawing.Size(102, 21);
		this.cb_sg_name.TabIndex = 43;
		this.label15.AutoSize = true;
		this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.label15.Location = new System.Drawing.Point(3, 102);
		this.label15.Name = "label15";
		this.label15.Size = new System.Drawing.Size(98, 20);
		this.label15.TabIndex = 40;
		this.label15.Text = "Power Meter";
		this.label1.AutoSize = true;
		this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12f, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0);
		this.label1.Location = new System.Drawing.Point(3, 53);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(130, 20);
		this.label1.TabIndex = 41;
		this.label1.Text = "Signal Generator";
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.pl_pad_pm);
		base.Controls.Add(this.pl_pad_sg);
		base.Controls.Add(this.pl_ip_pm);
		base.Controls.Add(this.pl_ip_sg);
		base.Controls.Add(this.pl_sad_pm);
		base.Controls.Add(this.pl_sad_sg);
		base.Controls.Add(this.label17);
		base.Controls.Add(this.label11);
		base.Controls.Add(this.label16);
		base.Controls.Add(this.label10);
		base.Controls.Add(this.cb_pm_remote);
		base.Controls.Add(this.cb_sg_remote);
		base.Controls.Add(this.cb_pm_name);
		base.Controls.Add(this.cb_sg_name);
		base.Controls.Add(this.label15);
		base.Controls.Add(this.label1);
		base.Name = "WCNStationCalPanel";
		base.Size = new System.Drawing.Size(772, 159);
		this.pl_pad_pm.ResumeLayout(false);
		this.pl_pad_pm.PerformLayout();
		this.pl_pad_sg.ResumeLayout(false);
		this.pl_pad_sg.PerformLayout();
		this.pl_ip_pm.ResumeLayout(false);
		this.pl_ip_pm.PerformLayout();
		this.pl_ip_sg.ResumeLayout(false);
		this.pl_ip_sg.PerformLayout();
		this.pl_sad_pm.ResumeLayout(false);
		this.pl_sad_pm.PerformLayout();
		this.pl_sad_sg.ResumeLayout(false);
		this.pl_sad_sg.PerformLayout();
		base.ResumeLayout(false);
		base.PerformLayout();
	}
}
