using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Variables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PTMedicalInsurance.Helper
{
    class InvokeOcxCenter : IInvokeCenter
    {
        public int Business(string inputData, ref string outputData, ref string pErrMsg)
        {
            pErrMsg = "";
            outputData = "";
            JObject joRtn = new JObject();
            try
            {


                try
                {
                    //chsinterfaceyn.chsdllClass InterfaceBase_Yn1 = new chsinterfaceyn.chsdllClass();
                    //InterfaceBase_Yn1.SetDir(IntPath);
                }
                catch (Exception ex)
                {
                    pErrMsg = "invokeInitByDLL.SetDir 异常:" + ex.Message;
                    MessageBox.Show(pErrMsg);
                }
                finally
                {
                    //Global.writeLog("invokeInitByDLL.SetDir设置医保动态库目录(" + IntPath + ")", "", pErrMsg);
                }




                inputData = inputData.Replace("\n", "").Replace("\t", "").Replace("\r", "");

                //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();

                //调用业务函数
                //string pRtn =InterfaceBase_Yn.BusinessHandleW(fixmedins_code, infosyscode, infosyssign, inputData);

                //string pRtn = InterfaceBase_Yn.UploadFile(fixmedins_code, infosyscode, infosyssign, Global.inf.fileName,inputData);


                //joRtn = JObject.Parse(pRtn);

                if (joRtn["infcode"].ToString() != "0")
                {
                    pErrMsg = joRtn["err_msg"].ToString();
                    //outputData = pRtn;
                    return -1;
                }
                else
                {
                    //outputData = pRtn;
                    return 0;
                }
            }
            catch (Exception ex)
            {
                pErrMsg = "invokeInitByDLL.BusinessHandle 异常:" + ex.Message;
                return -1;
            }
            finally
            {
                Global.writeLog("invokeInitByDLL.BusinessHandle医保动态库通用业务函数", inputData, outputData);
            }
        }

        public int BusinessExt(string inputData, ref string outputData, ref string pErrMsg)
        {
            throw new NotImplementedException();
        }

        public int DownloadFile(string inputData, ref string outputData)
        {
            throw new NotImplementedException();
        }

        public int Init(ref string pErrMsg)
        {
            pErrMsg = "";
            JObject joRtn = new JObject();
            try
            {
                //chsinterfaceyn.chsdllClass InterfaceBase_Yn = new chsinterfaceyn.chsdllClass();

                //string pRtn = InterfaceBase_Yn.Init(fixmedins_code, infosyscode, infosyssign, url);

                //joRtn = JObject.Parse(pRtn);
                if (joRtn["infcode"].ToString() != "0")
                {
                    pErrMsg = joRtn["err_msg"].ToString();
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception ex)
            {
                pErrMsg = "invokeInitByDLL.Init 异常:" + ex.Message;
                return -1;
            }
            finally
            {
                Global.writeLog("invokeInitByDLL.Init医保动态库初始化(" +  ")", "", pErrMsg);
            }
        }

        public int UploadFile(string inputData, ref string outputData, ref string pErrMsg)
        {
            throw new NotImplementedException();
        }
    }
}
