using Newtonsoft.Json;
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 BurronModel.JsonToTable
{
    public partial class ToTableForm : Form
    {
        public ToTableForm()
        {
            InitializeComponent();
        }

        #region Json
        string rtn = "{\"body\":{\"output\":{\"medinsinfo\":" +
           "[{\"fixmedins_code\":\"1200001001569\",\"fixmedins_name\":\"天津河西区普瑞眼科医院有限公司\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"05\"}," +
           "{\"fixmedins_code\":\"2101001008151\",\"fixmedins_name\":\"沈阳普瑞眼科医院有限公司\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"08\"}," +
           "{\"fixmedins_code\":\"2299001010539\",\"fixmedins_name\":\"长春市朝阳区普瑞眼科医院有限责任公司\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}," +
           "{\"fixmedins_code\":\"2399001000058\",\"fixmedins_name\":\"哈尔滨普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"04\"}," +
           "{\"fixmedins_code\":\"3100001000345\",\"fixmedins_name\":\"上海普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"06\"}," +
           "{\"fixmedins_code\":\"3401001003686\",\"fixmedins_name\":\"合肥瑶海区普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"07\"}," +
           "{\"fixmedins_code\":\"3401021003685\",\"fixmedins_name\":\"合肥瑶海区普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"07\"}," +
           "{\"fixmedins_code\":\"3401241000077\",\"fixmedins_name\":\"庐江普瑞眼科门诊部\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}," +
           "{\"fixmedins_code\":\"3401411000018\",\"fixmedins_name\":\"合肥经济开发区普瑞眼科门诊部\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}," +
           "{\"fixmedins_code\":\"3499001000024\",\"fixmedins_name\":\"合肥普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"02\"}," +
           "{\"fixmedins_code\":\"3699001100065\",\"fixmedins_name\":\"南昌普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"02\"}," +
           "{\"fixmedins_code\":\"3701001011408\",\"fixmedins_name\":\"济南普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"05\"}," +
           "{\"fixmedins_code\":\"4199001000200\",\"fixmedins_name\":\"郑州普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"08\"}," +
           "{\"fixmedins_code\":\"4201041030603\",\"fixmedins_name\":\"武汉普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"02\"}," +
           "{\"fixmedins_code\":\"5000001006966\",\"fixmedins_name\":\"重庆普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"05\"}," +
           //"{\"fixmedins_code\":\"5101001002094\",\"fixmedins_name\":\"成都普瑞眼科医院有限责任公司\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}," +
           //"{\"fixmedins_code\":\"5199001000058\",\"fixmedins_name\":\"成都普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"10\"}," +
           //"{\"fixmedins_code\":\"5299001102440\",\"fixmedins_name\":\"贵州普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"02\"}," +
           //"{\"fixmedins_code\":\"5399001000144\",\"fixmedins_name\":\"昆明普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"04\"}," +
           //"{\"fixmedins_code\":\"6101001000198\",\"fixmedins_name\":\"西安普瑞眼科医院有限责任公司\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"03\"}," +
           //"{\"fixmedins_code\":\"6201001100030\",\"fixmedins_name\":\"兰州普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"06\"}," +
           //"{\"fixmedins_code\":\"6299001100030\",\"fixmedins_name\":\"兰州普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"06\"}," +
           "{\"fixmedins_code\":\"6599001102925\",\"fixmedins_name\":\"乌鲁木齐普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"06\"}," +
           "{\"fixmedins_code\":\"6600001000519\",\"fixmedins_name\":\"乌鲁木齐普瑞眼科医院（有限公司）\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"05\"}," +
           "{\"fixmedins_code\":\"H34010202798\",\"uscc\":\"91340102MA2WCNTB23\",\"fixmedins_name\":\"合肥瑶海区普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"07\"}," +
           "{\"fixmedins_code\":\"H34010400768\",\"uscc\":\"91340100MA2MYPJ64A\",\"fixmedins_name\":\"合肥普瑞眼科医院\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"04\"}," +
           "{\"fixmedins_code\":\"H34012400958\",\"uscc\":\"91340124MA2RG8M04F\",\"fixmedins_name\":\"庐江普瑞眼科门诊部\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}," +
           "{\"fixmedins_code\":\"H34017200925\",\"uscc\":\"91340111MA2PGYQ5X2\",\"fixmedins_name\":\"合肥经济开发区普瑞眼科门诊部\",\"fixmedins_type\":\"1\",\"hosp_lv\":\"11\"}]" +
           "},\"infcode\":0,\"inf_refmsgid\":\"340121202209022050100314008840\"},\"code\":200,\"csbCode\":200,\"message\":\"SUCCESS\",\"requestId\":\"ac11000116621230090334471d0121\",\"state\":{}}";
        #endregion

        private void ToTableForm_Load(object sender, EventArgs e)
        {
            GetTableData();
        }

        public void GetTableData()
        {
            if (!string.IsNullOrWhiteSpace(rtn))
            {
                JObject jo = (JObject)JsonConvert.DeserializeObject(rtn);
                string code = jo["code"].ToString();
                string csbCode = jo["csbCode"].ToString();
                string message = jo["message"].ToString();
                string requestId = jo["requestId"].ToString();

                string data = jo["body"]["output"]["medinsinfo"].ToString();
                if (code == "200" && message == "SUCCESS")
                {
                    //MessageBox.Show(message);
                    this.button1.Text = requestId;
                    dataGridView1.DataSource = JsonConvert.DeserializeObject(data);
                    int coon = dataGridView1.Columns.Count;
                    for (int i = 0; i < coon; i++)
                    {
                        dataGridView1.AutoResizeColumn(i);
                    }

                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            GetTableData();
        }
    }
}
