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

namespace PTMedicalInsurance.Business
{
    class InpatientRegCancelProcess : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {
            string errMsg = "";
            //取消中心登记
            if (cBus.cancleRegister(TradeEnum.InpaitentRegCancel, out outParam) != 0)
            {
                //如果医保中心没有HIS所传的医保登记信息则默认撤销HIS登记信息
                int i = outParam.IndexOf("不存在有效的就诊登记信息");
                if (i != 0)
                {
                    if (DialogResult.Yes != MessageBox.Show("医保中心提示：" + outParam + "，是否强制撤销HIS医保登记信息？", "提示", MessageBoxButtons.YesNo))
                    {
                        return Exception("中心取消登记失败，", outParam);
                    }
                }
            }

            //取消医保平台登记
            if (mIS.cancleRegister(1, out outParam) != 0)
            {
                return Exception(-1, "中心取消登记成功，但云医保平台取消失败，", outParam);
            }

            //取消HIS 登记
            if (hIS.cancleRegister(out outParam) != 0)
            {
                return Exception(-1, "中心和云医保平台取消登记成功，但HIS取消失败，", outParam);
            }
            else
            {
                mIS.deleteFee(out errMsg);
                return IrisReturn("取消医保登记成功", null);
            }
        }
    }
}
