using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DirectoryDownload.Helper;
using DirectoryDownload.Business;
using Newtonsoft.Json.Linq;
using System.Data;
using System.Windows.Forms;

namespace DirectoryDownload.FormSetter
{
    class ComboxSetter
    {
        public void setCbxInterfaceDataSource(Sunny.UI.UIComboBox cbx)
        {
            IrisInterfaceService iris = new IrisInterfaceService();
            DataTable dt = new DataTable();
            JObject joRtn = iris.getInterface();
            JArray jaParams = new JArray();
            jaParams = JArray.Parse(JsonHelper.getJsonValue(joRtn,"result.data"));
            if (jaParams.Count == 0)
            {
                DataTableSetter dts = new DataTableSetter();
                dt = dts.setDgvInterfaceDataTable();
                return;
            }
            else
            {
                dt = (DataTable)jaParams.ToObject(typeof(DataTable));
                GlobalVariables.interfaceDr_Download = int.Parse(dt.Rows[0]["ID"].ToString());
            }
            dt.AcceptChanges();
            cbx.DataSource = dt;
            cbx.DisplayMember = "InterfaceName";
            cbx.ValueMember = "ID";
            
        }
    }
}
