using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProductionControl
{
    public partial class FrmSetParams : Form
    {
        public string ParamsData;
        private string ProcessCode;
        private string ProcessParams;

        private UI.UICodeScannerDev uiCodeScanner1;
        private UI.UIAxisDev uiAxis1;
        private UI.UIAxisDevTag uiAxisTag1;
        private UI.UISmallAxisDev uiSmallAxis1;
        private UI.UITensionDev uiTension1; 
        private UI.UIIOCardDev uiIOCard1;
        private UI.UIDefectLib uiDefectLib1;
        private UI.UILightDev uiLight1;
        private UI.UIScannerDev uiScanner1; 
        private UI.UIHeightDev uiHeightDev1;
        private UI.UISizeLib uiSizeLib1;
        private UI.UIForLib uiForLib1;
        private UI.UIIFLib uiIFLib1;
        public FrmSetParams(string processCode,string processParams)
        {
            InitializeComponent();
            ProcessCode= processCode;
            ProcessParams= processParams;
        }
        private void initData()
        {
            switch (ProcessCode)
            {
                case "CodeScanner":
                    uiCodeScanner1= new UI.UICodeScannerDev();
                    this.Controls.Add(uiCodeScanner1);
                    uiCodeScanner1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiCodeScanner1.Location = new System.Drawing.Point(0, 0);
                    uiCodeScanner1.init(); 
                    break;
                case "IOCard":
                    uiIOCard1 = new UI.UIIOCardDev();
                    this.Controls.Add(uiIOCard1);
                    uiIOCard1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiIOCard1.Location = new System.Drawing.Point(0, 0);
                    uiIOCard1.GetParamsEvent = save;
                    uiIOCard1.init();
                    uiIOCard1.setParamsData(ProcessParams);
                    break;
                case "Tension":
                    uiTension1 = new UI.UITensionDev();
                    this.Controls.Add(uiTension1);
                    uiTension1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiTension1.Location = new System.Drawing.Point(0, 0);
                    uiTension1.GetParamsEvent = save;
                    uiTension1.init();
                    uiTension1.setParamsData(ProcessParams);
                    break;
                case "Height":
                    uiHeightDev1 = new UI.UIHeightDev();
                    this.Controls.Add(uiHeightDev1);
                    uiHeightDev1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiHeightDev1.Location = new System.Drawing.Point(0, 0);
                    uiHeightDev1.GetParamsEvent = save;
                    uiHeightDev1.init();
                    uiHeightDev1.setParamsData(ProcessParams);
                    break;
                case "Axis":
                    uiAxis1 = new UI.UIAxisDev();
                    this.Controls.Add(uiAxis1);
                    uiAxis1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiAxis1.Location = new System.Drawing.Point(0, 0);
                    uiAxis1.GetParamsEvent = save;
                    uiAxis1.init();
                    uiAxis1.setParamsData(ProcessParams);
                    break;
                case "AxisTag":
                    uiAxisTag1 = new UI.UIAxisDevTag();
                    this.Controls.Add(uiAxisTag1);
                    uiAxisTag1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiAxisTag1.Location = new System.Drawing.Point(0, 0);
                    uiAxisTag1.GetParamsEvent = save;
                    uiAxisTag1.init();
                    uiAxisTag1.setParamsData(ProcessParams);
                    break;
                case "Light":
                    uiLight1 = new UI.UILightDev();
                    this.Controls.Add(uiLight1);
                    uiLight1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiLight1.Location = new System.Drawing.Point(0, 0);
                    uiLight1.GetParamsEvent = save;
                    uiLight1.init();
                    uiLight1.setParamsData(ProcessParams);
                    break;
                case "Scanner_GENTL":
                    uiScanner1 = new UI.UIScannerDev();
                    this.Controls.Add(uiScanner1);
                    uiScanner1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiScanner1.Location = new System.Drawing.Point(0, 0);
                    uiScanner1.GetParamsEvent = save;
                    uiScanner1.init( Device.ScannerDev.ScannerType.GENTL);
                    uiScanner1.setParamsData(ProcessParams);
                    break;
                case "Scanner_CC":
                    uiScanner1 = new UI.UIScannerDev();
                    this.Controls.Add(uiScanner1);
                    uiScanner1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiScanner1.Location = new System.Drawing.Point(0, 0);
                    uiScanner1.GetParamsEvent = save;
                    uiScanner1.init(Device.ScannerDev.ScannerType.CC);
                    uiScanner1.setParamsData(ProcessParams);
                    break;
                case "SmallAxis":
                    uiSmallAxis1 = new UI.UISmallAxisDev();
                    this.Controls.Add(uiSmallAxis1);
                    uiSmallAxis1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiSmallAxis1.Location = new System.Drawing.Point(0, 0);
                    uiSmallAxis1.GetParamsEvent = save;
                    uiSmallAxis1.init();
                    uiSmallAxis1.setParamsData(ProcessParams);
                    break;
                case "Defect":
                    uiDefectLib1 = new UI.UIDefectLib();
                    this.Controls.Add(uiDefectLib1);
                    uiDefectLib1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiDefectLib1.Location = new System.Drawing.Point(0, 0);
                    uiDefectLib1.GetParamsEvent = save;
                    uiDefectLib1.init();
                    uiDefectLib1.setParamsData(ProcessParams);
                    break;
                case "Size":
                    uiSizeLib1 = new UI.UISizeLib();
                    this.Controls.Add(uiSizeLib1);
                    uiSizeLib1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiSizeLib1.Location = new System.Drawing.Point(0, 0);
                    uiSizeLib1.GetParamsEvent = save;
                    uiSizeLib1.init();
                    uiSizeLib1.setParamsData(ProcessParams);
                    break;
                case "For":
                    uiForLib1 = new UI.UIForLib();
                    this.Controls.Add(uiForLib1);
                    uiForLib1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiForLib1.Location = new System.Drawing.Point(0, 0);
                    uiForLib1.GetParamsEvent = save;
                    uiForLib1.init();
                    uiForLib1.setParamsData(ProcessParams);
                    break;
                case "If":
                    uiIFLib1 = new UI.UIIFLib();
                    this.Controls.Add(uiIFLib1);
                    uiIFLib1.Dock = System.Windows.Forms.DockStyle.Fill;
                    uiIFLib1.Location = new System.Drawing.Point(0, 0);
                    uiIFLib1.GetParamsEvent = save;
                    uiIFLib1.init();
                    uiIFLib1.setParamsData(ProcessParams);
                    break;
                default:
                    throw new Exception("不支持的工序类型！");
            }
        }

        private void FrmSetParams_Load(object sender, EventArgs e)
        {
            try
            {
                initData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
        private void save(string json)
        {
            this.ParamsData = json;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
