using DH.Commons.Enums;
using DH.Devices.Devices;
using DVPCameraType;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace DHSoftware.Views
{

    public partial class CamConfigFrm : UserControl
    {
        public int m_n_dev_count = 0;
        public static int m_CamCount = 0;
        public static dvpCameraInfo[] m_info = new dvpCameraInfo[16];

        // 在窗体类中声明一个绑定列表(用于动态更新)
        private BindingList<CameraBase> _cameraList = new BindingList<CameraBase>();
        public CamConfigFrm()
        {
            InitializeComponent();
            // 添加 ComboBox 的项
            COMBO_DEVICES.Items.AddRange(new string[] { " 度申Do3", "海康Hik", "巴斯勒Basler", "虚拟相机" });

            // 绑定 SelectedIndexChanged 事件
            COMBO_DEVICES.SelectedIndexChanged += ComboBox_SelectedIndexChanged;

            dgvCams.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvCams.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            dgvCams.DataSource = _cameraList; // 绑定数据源
            dgvCams.Location = new Point(38, 82);
            dgvCams.Name = "dgvCams";
            dgvCams.Size = new Size(284, 206);
            dgvCams.TabIndex = 1;
        }
        private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (COMBO_DEVICES.SelectedItem == null) return;

            string selectedMethod = COMBO_DEVICES.SelectedItem.ToString();
            switch (selectedMethod)
            {
                case "度申Do3":
                    Do3Think();
                    break;
                case "海康Hik":
                    HiK();
                    break;
                case "巴斯勒Basler":
                    Basler();
                    break;
                case "虚拟相机":
                    Virtul();
                    break;
                default:
                    MessageBox.Show("未找到对应方法");
                    break;
            }
        }

        // 其他方法定义...
        private void Do3Think()
        {
            InitDevList();
        }

        private void HiK()
        {

        }
        private void Basler()
        {

        }

        private void Virtul()
        {

        }
        private void btnRefreshCamList_Click(object sender, EventArgs e)
        {
            //搜索度申相机
            InitDevList();
        }

        /// <summary>
        /// 搜索度申相机
        /// </summary>
        // Initialize the device list.
        public void InitDevList()
        {







            dvpStatus status;
            uint i, n = 0;
            dvpCameraInfo dev_info = new dvpCameraInfo();

            // 清空旧数据
            _cameraList.Clear();

            // Get the number of cameras that has been connected to a computer.
            status = DVPCamera.dvpRefresh(ref n);
            Debug.Assert(status == dvpStatus.DVP_STATUS_OK);
            m_n_dev_count = (int)n;
            if (status == dvpStatus.DVP_STATUS_OK)
            {
                m_CamCount = 0;
                for (i = 0; i < n; i++)
                {
                    // Acquire each camera's information one by one.
                    status = DVPCamera.dvpEnum(i, ref dev_info);

                    if (status == dvpStatus.DVP_STATUS_OK)
                    {
                        m_info[m_CamCount] = dev_info;

                        int item = -1;
                        //if (!UserDefinedName.Checked)
                        {
                            // add FriendlyName
                            item = COMBO_DEVICES.Items.Add(dev_info.FriendlyName);
                            CameraBase info = new CameraBase
                            {
                                CameraName = dev_info.FriendlyName,
                                SerialNumber = dev_info.SerialNumber,
                                // IP = dev_info.IP
                            };

                            _cameraList.Add(info);


                        }
                        //else
                        //{
                        //    // add User Define Name
                        //    item = COMBO_DEVICES.Items.Add(dev_info.UserID);
                        //}

                        m_CamCount++;
                    }
                    else
                    {
                        Debug.Assert(status == dvpStatus.DVP_STATUS_OK);
                    }
                }
            }

            if (n == 0)
            {

            }
            else
            {

            }


        }

        private void btnsubmit_Click(object sender, EventArgs e)
        {

        }
    }
}