using Newtonsoft.Json.Linq;
using PTMedicalInsurance.Helper;
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.Business
{
    class IPSettlementCancelProcess : AbstractProcess
    {
        public override CallResult Process(JObject input)
        {

            //取消中心结算信息
            if (cBus.cancleSettlement(TradeEnum.InpatientSettlementCancel, out outParam) != 0)
            {
                
                //查看是医保平台是否已经退费，如果是，则询问是否继续退费
                string SqlStr = " SELECT * FROM  BS_MedInsuSettlement WHERE  ValidFlag = 0 AND BillType = -1 ";
                SqlStr = SqlStr + " AND Hospital_Dr=" + Global.inf.hospitalDr + " AND Interface_Dr=" + Global.inf.interfaceDr;
                SqlStr = SqlStr + " AND SettlementID ='" + Global.pat.settlID + "'";

                JObject joSqlStr = new JObject();
                joSqlStr.Add("sqlStr", SqlStr);

                JObject joCancleSettlInfo = mIS.QuerySettlementInfo(joSqlStr);
                JArray jaCancleSettlInfo = JArray.Parse(JsonHelper.getDestValue(joCancleSettlInfo, "result.data"));
                if (jaCancleSettlInfo.Count == 1)
                {
                    //询问收款员是否继续进行HIS退费
                    if (DialogResult.Yes == MessageBox.Show("中心提示：" + outParam, " 该费用在医保中心已成功退费但在HIS未成功退费，是否强制退HIS费用？ ", MessageBoxButtons.YesNo))
                    {
                        return Exception(0, "该费用在医保中心已成功退费但在HIS未成功退费，收款员选择强制退HIS费用！", outParam);
                    }
                }
                else
                {
                    return Exception(-1, "取消中心结算(云医保平台未退费或未查询到退费记录)", outParam);
                }

                return Exception(-1, "取消中心结算信息失败！", outParam);

            }

            return Success();
        }
    }
}
