using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Common;
using PTMedicalInsurance.Helper;
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;
using PTMedicalInsurance.Forms.Setters.CenterQuery;

namespace PTMedicalInsurance.Forms
{
    public partial class CenterQuery : Form
    {
        InvokeHelper invoker = new InvokeHelper();
        public CenterQuery()
        {
            InitializeComponent();
            cbxMedType_1.SelectedIndex = 0;
            cbxCertType_1.SelectedIndex = 0;
            dtBeginDate_1.Value = DateTime.Now.AddDays(-180);
            GridViewSetter grd = new GridViewSetter();
            grd.SetHeaderTextOfResult1(dgvResult1);
        }

        private void btnQuery_1_Click(object sender, EventArgs e)
        {
            JObject joTmp = new JObject();
            joTmp.Add("psn_no",tbx_PsnNO_1.Text);
            joTmp.Add("psn_cert_type", tools.getDestPosStrBySpliter(cbxCertType_1.Text, 1, "."));
            joTmp.Add("certno", tbCertNO_1.Text);
            joTmp.Add("med_type", tools.getDestPosStrBySpliter(cbxMedType_1.Text,1,"."));
            joTmp.Add("begin_date", dtBeginDate_1.Value.ToString("yyyy-MM-dd"));
            joTmp.Add("exp_content", "");

            JObject joData = new JObject();
            joData.Add("data",joTmp);
            JObject joRtn = invoker.invokeCenterService("3688", JsonHelper.setCenterInpar("3688", joData.ToString()));
            string error = "";
            if (JsonHelper.parseCenterReturnJson(joRtn, out error) != 0)
            {
                MessageBox.Show("查询门诊结算信息异常：" + error);
            }
            else
            {
                DataTable dt = JsonConvert.DeserializeObject<DataTable>(joRtn["output"]["result"].ToString(), new ReadDataTableConverter());
                dgvResult1.DataSource = dt;
            }
        }

        private void btClose_1_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
