public bool BackReg()
        {
            if (ifrmRegInvoiceInput.HaveMedicarePay)
            {
                try
                {
                    //先调用医保接口退号
                    MIOPInterface.MiRefundRegister(ifrmRegInvoiceInput.RegPatList.VisitNO, string.Empty, ifrmRegInvoiceInput.InputVoiceNO);
                }
                catch (Exception err)
                {
                    MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    return(false);
                }
            }

            try
            {
                string invoiceNO = ifrmRegInvoiceInput.InputVoiceNO;
                Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(invoiceNO);           //票据号
                    request.AddData(LoginUserInfo.EmpId); //操作员ID
                });
                ServiceResponseData retdata = InvokeWcfService("OPProject.Service", "RegisterController", "BackReg", requestAction);

                return(true);
            }
            catch (Exception err)
            {
                MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                return(false);
            }
        }
        public void GetRegMedicareCaculate()
        {
            try
            {
                //调用医保读卡和试算接口,算出医保金额
                PatientInfo miPatInfo = MIOPInterface.ReadMediaCard();
                if (!MIOPInterface.PatCheck(ifrmRegister.CurPatlist.PatName, ifrmRegister.CurPatlist.MedicareCard, ifrmRegister.CurPatlist.IDNumber, miPatInfo))
                {
                    return;
                }

                ifrmRegister.MedicardReadInfo = miPatInfo.ShowMiPatInfo;
                Action <ClientRequestData> requestAction1 = ((ClientRequestData request) =>
                {
                    request.AddData(ifrmRegister.CurPatlist.RegTypeID);
                });
                ServiceResponseData         retdata1  = InvokeWcfService("OPProject.Service", "RegisterController", "GetRegInfoByRegId", requestAction1);
                DataTable                   dtRegInfo = retdata1.GetData <DataTable>(0);
                Dictionary <string, string> dic       = MIOPInterface.MiRegBuget(ifrmRegPayMentInfo.SocialCard, LoginUserInfo.EmpName, LoginUserInfo.EmpId, ifrmRegister.CurPatlist, ifrmRegPayMentInfo.RegTotalFee, dtRegInfo, ifrmRegPayMentInfo.InvoiceNO, ifrmRegPayMentInfo.IdentityNum);
                ifrmRegPayMentInfo.MedicarePay     = Convert.ToDecimal(dic["MedicarePay"]);     // ifrmRegPayMentInfo.RegTotalFee;//假数据
                ifrmRegPayMentInfo.MedicareMIPay   = Convert.ToDecimal(dic["MedicareMIPay"]);   // ifrmRegPayMentInfo.RegTotalFee;//假数据
                ifrmRegPayMentInfo.MedicarePersPay = Convert.ToDecimal(dic["MedicarePersPay"]); // ifrmRegPayMentInfo.RegTotalFee;//假数据
                ifrmRegPayMentInfo.SetMedicardInfo = dic["MedicardInfo"].ToString();            // "43625436";
                ifrmRegPayMentInfo.MIBudgetID      = Convert.ToInt32(dic["ID"]);                //医保预结算ID
            }
            catch (Exception err)
            {
                MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
        }
        public void ReadMedicareCard()
        {
            try
            {
                //调用医保读卡接口,获取医保卡号和医保卡相关信息
                PatientInfo miPatInfo      = MIOPInterface.ReadMediaCard();
                string      medicareCardNO = miPatInfo.CardNo;
                ifrmRegPayMentInfo.SocialCard  = miPatInfo.CardNo;
                ifrmRegPayMentInfo.IdentityNum = miPatInfo.IcNo;
                Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                {
                    // 医保卡 类型是3,根据公共方法里面的参数而来
                    request.AddData(OP_Enum.MemberQueryType.医保卡号);
                    request.AddData(medicareCardNO);
                });
                ServiceResponseData retdataMember = InvokeWcfService("OPProject.Service", "RegisterController", "QueryMemberInfo", requestAction);
                DataTable           dtMemberInfo  = retdataMember.GetData <DataTable>(0);
                if (dtMemberInfo == null || dtMemberInfo.Rows.Count == 0)
                {
                    //MessageBoxShowError("系统中没有该医保卡号病人信息");
                    //return;
                    //没有此医保卡病人信息时,默认弹出新病人窗口
                    AddMemberInfo();
                }
                else
                {
                    if (dtMemberInfo.Rows.Count > 0)
                    {
                        if (!MIOPInterface.PatCheck(dtMemberInfo.Rows[0]["MemberName"].ToString(), dtMemberInfo.Rows[0]["MedicareCard"].ToString(), dtMemberInfo.Rows[0]["IDNumber"].ToString(), miPatInfo))
                        {
                            return;
                        }
                    }

                    ifrmRegister.MedicardReadInfo = miPatInfo.ShowMiPatInfo;//显示医保信息
                    if (dtMemberInfo.Rows.Count > 1)
                    {
                        ((IFrmQueryMember)iBaseView["FrmQueryMember"]).LoadPatInfo(dtMemberInfo);//把病人数据源直接赋值到界面
                        (iBaseView["FrmQueryMember"] as Form).Text = "选择账户";
                        (iBaseView["FrmQueryMember"] as Form).ShowDialog();
                    }
                    else
                    {
                        SetPatListBasic(dtMemberInfo, 0);
                    }
                }
            }
            catch (Exception err)
            {
                MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
        }
        public void GetBacRegReadCard(string sPatName)
        {
            ///调用医保读卡接口
            PatientInfo miPatInfo = MIOPInterface.ReadMediaCard();

            if (!miPatInfo.PersonName.Equals(sPatName))
            {
                MessageBoxShowError("此卡与挂号的卡不符!");
                return;
            }
            //string MedicareCardNO = miPatInfo.CardNo;
            //string MedicardInfo = "卡号:" + miPatInfo.CardNo + "姓名:" + miPatInfo.PersonName + "医保类别:" + miPatInfo.PersonType + "身份证号码:" + miPatInfo.IdNo + "余额:" + miPatInfo.PersonCount; //"12345678900987654";
            ifrmRegInvoiceInput.MedicareInfo = miPatInfo.ShowMiPatInfo;
        }
        public bool SaveRegister()
        {
            //调用医保读卡接口,获取医保卡号和医保卡相关信息
            OP_PatList curPatlist = ifrmRegister.CurPatlist;

            curPatlist.OperatorID = LoginUserInfo.EmpId;
            if (!string.IsNullOrEmpty(ifrmRegister.MedicardReadInfo))
            {
                try
                {
                    //调用医保接口正式结算 如果医保结算失败,直接return
                    MIOPInterface.MiRegister(ifrmRegPayMentInfo.MIBudgetID, string.Empty);
                }
                catch (Exception err)
                {
                    MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    return(false);
                }
            }

            try
            {
                decimal totalRegFee    = ifrmRegPayMentInfo.RegTotalFee;
                string  regPayMentCode = ifrmRegPayMentInfo.GetPatMentCode;
                //decimal medicarcPay = ifrmRegPayMentInfo.MedicarePay;
                decimal medicarcPay     = ifrmRegPayMentInfo.MedicareMIPay;
                decimal medicarePersPay = ifrmRegPayMentInfo.MedicarePersPay;
                decimal shouldPay       = ifrmRegPayMentInfo.ShoudPay;
                decimal promFee         = ifrmRegPayMentInfo.PromFee;
                Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(curPatlist);      //病人对象
                    request.AddData(totalRegFee);     //挂号总金额
                    request.AddData(regPayMentCode);  //支付方式Code
                    request.AddData(medicarcPay);     //医保统筹支付金额
                    request.AddData(shouldPay);       //应付金额
                    request.AddData(promFee);         //优惠金额
                    request.AddData(medicarePersPay); //医保个账支付金额
                });
                ServiceResponseData retdata     = InvokeWcfService("OPProject.Service", "RegisterController", "SaveRegister", requestAction);
                DataTable           dtRegPrint  = retdata.GetData <DataTable>(0);
                OP_PatList          backPatlist = retdata.GetData <OP_PatList>(1);
                if (dtRegPrint == null || dtRegPrint.Rows.Count == 0)
                {
                    MessageBoxShowError("找不到打印数据");
                    return(false);
                }

                if (!string.IsNullOrEmpty(ifrmRegister.MedicardReadInfo))
                {
                    MIOPInterface.MiRegisterComplete(ifrmRegPayMentInfo.MIBudgetID, backPatlist.VisitNO, dtRegPrint.Rows[0]["invoiceNO"].ToString());
                }

                //票据打印
                RegInvoicePrint(dtRegPrint);
                return(true);
            }
            catch (Exception err)
            {
                MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                if (ifrmRegPayMentInfo.MIBudgetID > 0)
                {
                    //需要回退医保挂号
                    MIOPInterface.MiRefundRegister(string.Empty, ifrmRegPayMentInfo.MIBudgetID.ToString(), string.Empty);
                }

                return(false);
            }
        }
        /// <summary>
        /// 挂号支付界面初始化
        /// </summary>
        /// <returns>返回初始化是否成功</returns>
        private bool RegPayDataInit()
        {
            try
            {
                OP_PatList curPatlist = ifrmRegister.CurPatlist;
                Action <ClientRequestData> requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(LoginUserInfo.EmpId);  //人员ID
                    request.AddData(curPatlist.RegTypeID); //挂号类别ID
                    request.AddData(curPatlist.PatTypeID); //病人类型ID
                });
                ServiceResponseData retdata = InvokeWcfService("OPProject.Service", "RegisterController", "RegPayMentInit", requestAction);
                string    invoiceNO         = retdata.GetData <string>(0);  //票据号
                decimal   regFee            = retdata.GetData <decimal>(1); //挂号费
                DataTable dtPayMent         = retdata.GetData <DataTable>(2);
                bool      isMedicardPat     = retdata.GetData <bool>(3);
                ifrmRegPayMentInfo.RegDeptName     = curPatlist.RegDeptName;
                ifrmRegPayMentInfo.MedicarePay     = 0;
                ifrmRegPayMentInfo.MedicareMIPay   = 0;
                ifrmRegPayMentInfo.MedicarePersPay = 0;
                ifrmRegPayMentInfo.PromFee         = 0;
                ifrmRegPayMentInfo.GetRegPayment(dtPayMent);
                ifrmRegPayMentInfo.RegTotalFee = Convert.ToDecimal(regFee.ToString("0.00"));
                ifrmRegPayMentInfo.InvoiceNO   = invoiceNO;
                ifrmRegPayMentInfo.ActPay      = ifrmRegPayMentInfo.RegTotalFee;

                //如果病人类型是医保类型,则直接调用医保挂号预算接口,算出医保预算支付金额
                if (isMedicardPat == true)
                {
                    if (string.IsNullOrEmpty(ifrmRegister.MedicardReadInfo))
                    {
                        PatientInfo miPatInfo = MIOPInterface.ReadMediaCard();
                        if (!MIOPInterface.PatCheck(curPatlist.PatName, curPatlist.MedicareCard, curPatlist.IDNumber, miPatInfo))
                        {
                            return(false);
                        }

                        string medicareCardNO = miPatInfo.CardNo;
                        ifrmRegPayMentInfo.SocialCard  = miPatInfo.CardNo;
                        ifrmRegPayMentInfo.IdentityNum = miPatInfo.IcNo;
                        curPatlist.MedicareCard        = miPatInfo.CardNo;
                        ifrmRegister.MedicardReadInfo  = miPatInfo.ShowMiPatInfo;
                        //PatientInfo miPatInfo = MIOPInterface.ReadMediaCard();
                        //string MedicareCardNO = miPatInfo.CardNo;// "12345678900987654";
                        //string MedicardInfo = "卡号:" + miPatInfo.CardNo + " 姓名:" + miPatInfo.PersonName + " 医保类别:" + miPatInfo.PersonType + " 身份证号码:" + miPatInfo.IdNo + " 余额:" + miPatInfo.PersonCount; //"12345678900987654";
                        //ifrmRegister.MedicardReadInfo = MedicardInfo;
                        //curPatlist.MedicareCard = miPatInfo.CardNo;
                    }

                    Action <ClientRequestData> requestAction1 = ((ClientRequestData request) =>
                    {
                        request.AddData(curPatlist.RegTypeID);
                    });
                    ServiceResponseData retdata1  = InvokeWcfService("OPProject.Service", "RegisterController", "GetRegInfoByRegId", requestAction1);
                    DataTable           dtRegInfo = retdata1.GetData <DataTable>(0);
                    //医保预算
                    Dictionary <string, string> dic = MIOPInterface.MiRegBuget(ifrmRegPayMentInfo.SocialCard, LoginUserInfo.EmpName, LoginUserInfo.EmpId, curPatlist, regFee, dtRegInfo, ifrmRegPayMentInfo.InvoiceNO, ifrmRegPayMentInfo.IdentityNum);
                    decimal dMedicarePay            = Convert.ToDecimal(dic["MedicarePay"].ToString()); // ifrmRegPayMentInfo.RegTotalFee;//假数据
                    ifrmRegPayMentInfo.MedicarePay = dMedicarePay;
                    decimal dMedicareMIPay = Convert.ToDecimal(dic["MedicareMIPay"].ToString());        // ifrmRegPayMentInfo.RegTotalFee;//假数据
                    ifrmRegPayMentInfo.MedicareMIPay = dMedicareMIPay;                                  // ifrmRegPayMentInfo.RegTotalFee;//假数据
                    decimal dMedicarePersPay = Convert.ToDecimal(dic["MedicarePersPay"].ToString());    // ifrmRegPayMentInfo.RegTotalFee;//假数据
                    ifrmRegPayMentInfo.MedicarePersPay = dMedicarePersPay;


                    ifrmRegPayMentInfo.SetMedicardInfo = dic["MedicardInfo"].ToString(); // "43625436";
                    ifrmRegPayMentInfo.MIBudgetID      = Convert.ToInt32(dic["ID"]);     //医保预结算ID
                }

                else
                {
                    ifrmRegPayMentInfo.ShoudPay = Convert.ToDecimal(regFee.ToString("0.00")) - Convert.ToDecimal(ifrmRegPayMentInfo.MedicarePay);//应付金额
                }
                ifrmRegPayMentInfo.ReadMedicareEnabled    = isMedicardPat;
                ifrmRegPayMentInfo.ExpMedicardInfoVisible = isMedicardPat;
                return(true);
            }
            catch (Exception err)
            {
                MessageBoxShow(err.Message, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                return(false);
            }
        }