using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using QC.QSPRSchedulerWrapper;

namespace QC.SmartMatchApp;

public class GVViewerCtrl : UserControl
{
	private ArrayList listOfGV = new ArrayList();

	private IContainer components;

	private Panel panel1;

	private DataGridView dataGridViewGV;

	public GVViewerCtrl()
	{
		InitializeComponent();
		SetupGrid();
	}

	private void SetupGrid()
	{
		dataGridViewGV.ColumnCount = 2;
		dataGridViewGV.Columns[0].Name = "GV Name";
		dataGridViewGV.Columns[1].Name = "GV Value";
	}

	public void AddGVToList(string GVName)
	{
		listOfGV.Add(GVName);
	}

	public void UpdateGlobalVbleView(QSPRScheduler Scheduler)
	{
		if (base.InvokeRequired)
		{
			BeginInvoke((MethodInvoker)delegate
			{
				UpdateGlobalVbleView(Scheduler);
			});
			return;
		}
		dataGridViewGV.Rows.Clear();
		if (Scheduler == null)
		{
			throw new Exception("QSPR Scheduler is not set");
		}
		foreach (string item in listOfGV)
		{
			Scheduler.GetGlobalVariable(item, out var value);
			dataGridViewGV.Rows.Add(item, value);
		}
	}

	public void ClearGVGrid()
	{
		dataGridViewGV.Rows.Clear();
	}

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

	private void InitializeComponent()
	{
		this.panel1 = new System.Windows.Forms.Panel();
		this.dataGridViewGV = new System.Windows.Forms.DataGridView();
		this.panel1.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.dataGridViewGV).BeginInit();
		base.SuspendLayout();
		this.panel1.Controls.Add(this.dataGridViewGV);
		this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
		this.panel1.Location = new System.Drawing.Point(0, 0);
		this.panel1.Name = "panel1";
		this.panel1.Size = new System.Drawing.Size(280, 335);
		this.panel1.TabIndex = 0;
		this.dataGridViewGV.AllowUserToAddRows = false;
		this.dataGridViewGV.AllowUserToDeleteRows = false;
		this.dataGridViewGV.AllowUserToOrderColumns = true;
		this.dataGridViewGV.AllowUserToResizeRows = false;
		this.dataGridViewGV.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
		this.dataGridViewGV.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
		this.dataGridViewGV.Dock = System.Windows.Forms.DockStyle.Fill;
		this.dataGridViewGV.Location = new System.Drawing.Point(0, 0);
		this.dataGridViewGV.Name = "dataGridViewGV";
		this.dataGridViewGV.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
		this.dataGridViewGV.Size = new System.Drawing.Size(280, 335);
		this.dataGridViewGV.TabIndex = 0;
		base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 13f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.Controls.Add(this.panel1);
		base.Name = "GVViewerCtrl";
		base.Size = new System.Drawing.Size(280, 335);
		this.panel1.ResumeLayout(false);
		((System.ComponentModel.ISupportInitialize)this.dataGridViewGV).EndInit();
		base.ResumeLayout(false);
	}
}
