private void lblOK_Click(object sender, EventArgs e)
        {
            if (!checkInput())
            {
                return;
            }

            if (SendCard.CheckCard() == "1")
            {
                SkyComm.ShowMessageInfo("该自助机没有卡,请在其他自助机上继续发卡!");
                return;
            }
            this.lblOK.Enabled     = false;
            this.btnReturn.Enabled = false;
            this.btnExit.Enabled   = false;
            panel2.Enabled         = false;
            _telphone      = this.txtTel.Text.Trim();
            _childName     = this.txtName.Text.Trim();
            _childSex      = this.rbtnBoy.Checked ? "男" : "女";
            _childBirthDay = this.txtYear.Text.Trim() + "-" + this.txtMonth.Text.Trim() + "-" + this.txtDay.Text.Trim();
            string CardNo = string.Empty;

            string strDiagnoseid = string.Empty;
            CardAuthorizationFacade eCardAuthorizationFacade = new CardAuthorizationFacade();

            using (WaitDialogForm form = new WaitDialogForm("正在发卡中,请稍候...", "正在组织发卡数据,请稍候......", new Size(240, 60)))
            {
                #region 办理就诊卡
                if (eLCardAuthorizationData != null)
                {
                    eLCardAuthorizationData.Tables[0].Rows.Clear();
                }

                SetCardInfo(IdInfo, _telphone);
                eLCardAuthorizationData = (CardAuthorizationData)eCardAuthorizationFacade.insertEntity(eLCardAuthorizationData);
                strDiagnoseid           = eLCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_DIAGNOSEID].ToString();
                CardNo = eLCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CARDID].ToString();
                //写卡,如果失败则重试
                bool isSuccess = false;
                form.Caption = "正在写卡中,请稍候...";
                try
                {
                    for (int i = 0; i < 3; i++)
                    {
                        //第一次写卡
                        if (SendCard.WriteCard(CardNo) == false)
                        {
                            //第一次写卡失败,再进行第二次写卡
                            if (SendCard.WriteCard(CardNo) == false)
                            {
                                //第二次写卡失败以后将卡回收
                                SendCard.ReturnCard();
                            }
                            else
                            {
                                isSuccess = true;
                                break;
                            }
                        }
                        else
                        {
                            isSuccess = true;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Skynet.LoggingService.LogService.GlobalInfoMessage("发卡失败:" + ex.Message);
                    SkyComm.ShowMessageInfo("发卡失败:" + ex.Message);
                    isSuccess = false;
                    this.btnReturn.Enabled = true;
                    this.btnExit.Enabled   = true;
                    this.lblOK.Enabled     = true;
                    panel2.Enabled         = true;
                }

                //写卡失败
                if (isSuccess == false)
                {
                    //撤消已发卡的信息
                    eCardAuthorizationFacade.deleteEntityAndCardSaving(eLCardAuthorizationData);
                    eLCardAuthorizationData = new CardAuthorizationData();
                    strDiagnoseid           = string.Empty;
                    SkynetMessage.MsgInfo("写卡失败,请在其他自助机上重试!");
                    this.lblOK.Enabled     = true;
                    this.btnReturn.Enabled = true;
                    this.btnExit.Enabled   = true;
                    panel2.Enabled         = true;

                    //第二次写卡失败以后将卡回收
                    SendCard.ReturnCard();
                    return;
                }
                #endregion
                form.Close();
            }
            #region 充值
            try
            {
                SkyComm.eCardAuthorizationData = eLCardAuthorizationData;
                SkyComm.DiagnoseID             = SkyComm.eCardAuthorizationData.Tables[0].Rows[0]["DIAGNOSEID"].ToString();
                SkyComm.cardInfoStruct.CardNo  = CardNo;
                SkyComm.cardBlance             = 0;
                CardSavingFacade cf = new CardSavingFacade();
                SkyComm.cardallmoney = 0;

                int     Savingsucceed = 0;
                decimal RechargeMoney = 0;
                string  strModeType   = "现金";
                try
                {
                    //充值,弹出界面选择是现金充值还是银行卡预存
                    if (!string.IsNullOrEmpty(AutoHostConfig.PosInterfaceType))
                    {
                        FrmCardSavingMain frm = new FrmCardSavingMain();
                        frm.CallType = 2;
                        frm.ShowDialog();
                        Savingsucceed = frm.Savingsucceed;
                        RechargeMoney = frm.RechargeMoney;
                        strModeType   = frm.MODETYPE;
                        frm.Dispose();
                    }
                    else
                    {
                        //拍照
                        switch (AutoHostConfig.ReadCardType)
                        {
                        case "XUHUI":
                            AutoServiceSDK.SdkService.Common_XH camera = new AutoServiceSDK.SdkService.Common_XH();
                            camera.TakeCamera(SkyComm.cardInfoStruct.CardNo, SkyComm.eCardAuthorizationData.Tables[0].Rows[0]["PATIENTNAME"].ToString(), AutoHostConfig.Machineno);
                            break;

                        default:
                            break;
                        }

                        FrmCardSavingCash frm = new FrmCardSavingCash();
                        frm.CallType = 2;
                        frm.ShowDialog();
                        Savingsucceed = frm.Savingsucceed;
                        RechargeMoney = frm.RechargeMoney;
                        frm.Dispose();
                    }
                    if (Savingsucceed == 1)
                    {
                        eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_MODETYPE] = strModeType;
                        if (!eLCardAuthorizationData.Tables[0].Columns.Contains("OPERATORNAME"))
                        {
                            eLCardAuthorizationData.Tables[0].Columns.Add("OPERATORNAME");

                            eLCardAuthorizationData.Tables[0].Rows[0]["OPERATORNAME"] = SysOperatorInfo.OperatorName;
                        }
                        eCardAuthorizationFacade.updateEntity(eLCardAuthorizationData);
                        eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_ADDMONEY] = RechargeMoney;

                        //打印发卡凭证
                        PrintSendCardReport(eLCardAuthorizationData);
                    }
                }
                catch (Exception ex2)
                {
                    Skynet.LoggingService.LogService.GlobalInfoMessage("发卡充值失败:" + ex2.Message);
                }
                finally
                {
                }

                if (Savingsucceed == 1)
                {
                    SendCard.OutputCard();
                    try
                    {
                        Common_XH theCamera_XH = new Common_XH();
                        theCamera_XH.DoorLightOpen(LightTypeenum.出卡槽, LightOpenTypeenum.闪烁);
                        theCamera_XH.DoorLightOpen(LightTypeenum.发卡器, LightOpenTypeenum.闪烁);
                        theCamera_XH.DoorLightOpen(LightTypeenum.凭条, LightOpenTypeenum.闪烁);
                    }
                    catch (Exception exception)
                    {
                    }
                    SkyComm.ShowMessageInfo("发卡成功,请取走您的就诊卡!");
                }
                else
                {
                    //回收卡信息并且注册卡
                    //撤消已发卡的信息
                    Skynet.LoggingService.LogService.GlobalInfoMessage("充值失败,撤消发卡信息");
                    eCardAuthorizationFacade.deleteEntityAndCardSaving(eLCardAuthorizationData);
                    eLCardAuthorizationData = new CardAuthorizationData();
                    strDiagnoseid           = string.Empty;
                    this.lblOK.Enabled      = true;
                    this.btnReturn.Enabled  = true;
                    this.btnExit.Enabled    = true;
                    panel2.Enabled          = true;

                    //发卡失败以后将卡进行回收
                    SendCard.ReturnCard();
                    return;
                }
            }
            catch (Exception ex)
            {
                Skynet.LoggingService.LogService.GlobalInfoMessage("发卡失败:" + ex.Message + ",系统回收卡机中的卡");

                //发卡失败以后将卡进行回收
                SendCard.ReturnCard();

                SkynetMessage.MsgInfo("发卡失败:" + ex.Message);
                return;
            }
            finally
            {
                this.lblOK.Enabled     = true;
                this.btnReturn.Enabled = true;
                this.btnExit.Enabled   = true;
                panel2.Enabled         = true;

                SkyComm.cardInfoStruct = new CardInformationStruct();
                SkyComm.eCardAuthorizationData.Tables[0].Clear();
                SkyComm.DiagnoseID   = string.Empty;
                SkyComm.cardBlance   = 0;
                SkyComm.cardallmoney = 0;
            }
            #endregion

            SystemFramework.Voice.Voice voice = new SystemFramework.Voice.Voice();
            voice.PlayText("请在就诊卡出口取走您的就诊卡!");
            voice.EndJtts();


            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
        private void lblOK_Click(object sender, EventArgs e)
        {
            ucTime1.Sec = 60;
            ucTime1.timer1.Stop();


            if (SendCard.CheckCard() == "1")
            {
                SkyComm.ShowMessageInfo("该自助机没有卡,请在其他自助机上进行补卡操作!");
                ucTime1.timer1.Start();
                return;
            }
            this.lblOK.Enabled = false;
            //this.btnReturn.Enabled = false;
            this.btnExit.Enabled = false;
            //DataSet dsNewInfo = new DataSet();
            int     checkCount = 0;
            DataRow drCard     = ((DataView)this.gdvMain.DataSource).ToTable().NewRow();

            for (int i = 0; i < this.gdvMain.RowCount; i++)
            {
                if (Convert.ToBoolean(gdvMain.GetDataRow(i)["PITCHON1"].ToString()))
                {
                    drCard = gdvMain.GetDataRow(i);
                    checkCount++;
                }
            }
            if (checkCount == 0)
            {
                SkyComm.ShowMessageInfo("请选择一条卡信息进行补卡操作!");
                ucTime1.timer1.Start();
                eLCardAuthorizationData = new CardAuthorizationData();
                this.lblOK.Enabled      = true;
                //this.btnReturn.Enabled = true;
                this.btnExit.Enabled = true;
                return;
            }
            else if (checkCount > 1)
            {
                SkyComm.ShowMessageInfo("只能选择一条卡信息进行补卡操作!");
                ucTime1.timer1.Start();
                eLCardAuthorizationData = new CardAuthorizationData();
                this.lblOK.Enabled      = true;
                //this.btnReturn.Enabled = true;
                this.btnExit.Enabled = true;
                return;
            }

            if (SkyComm.eCardAuthorizationData != null && SkyComm.eCardAuthorizationData.Tables.Count != 0 && SkyComm.eCardAuthorizationData.Tables[0].Rows.Count != 0)
            {
                if (drCard["CARDID"].ToString() == SkyComm.eCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString())
                {
                    SkyComm.ShowMessageInfo("不能对当前正在使用的就诊卡进行补卡操作!");
                    ucTime1.timer1.Start();
                    eLCardAuthorizationData = new CardAuthorizationData();
                    this.lblOK.Enabled      = true;
                    //this.btnReturn.Enabled = true;
                    this.btnExit.Enabled = true;
                    return;
                }
            }

            FrmYesNoAlert frmAlert = new FrmYesNoAlert();

            frmAlert.Title = "提示";
            frmAlert.Msg   = "是否确认对选择的卡信息进行补卡操作?         【卡号:" + drCard["CARDID"].ToString() + "】【姓名:" + drCard["PATIENTNAME"].ToString() + "】";
            if (frmAlert.ShowDialog() == DialogResult.Cancel)
            {
                this.ucTime1.timer1.Start();
                eLCardAuthorizationData = new CardAuthorizationData();
                this.lblOK.Enabled      = true;
                //this.btnReturn.Enabled = true;
                this.btnExit.Enabled = true;
                return;
            }
            CardAuthorizationFacade eCardAuthorizationFacade = new CardAuthorizationFacade();

            using (WaitDialogForm form = new WaitDialogForm("正在发卡中,请稍候...", "正在组织发卡数据,请稍候......", new Size(240, 60)))
            {
                #region 补卡

                eLCardAuthorizationData = (CardAuthorizationData)eCardAuthorizationFacade.CancleAndReissueCard(drCard["ACCOUNT_ID"].ToString(), drCard["CARDID"].ToString(), SysOperatorInfo.OperatorID, drCard["CIRCUIT_STATE"].ToString());
                //写卡,如果失败则重试
                bool isSuccess = false;
                form.Caption = "正在写卡中,请稍候...";
                try
                {
                    for (int i = 0; i < 3; i++)
                    {
                        //第一次写卡
                        if (SendCard.WriteCard(eLCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString()) == false)
                        {
                            //第一次写卡失败,再进行第二次写卡
                            if (SendCard.WriteCard(eLCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString()) == false)
                            {
                                //第二次写卡失败以后将卡回收
                                SendCard.ReturnCard();
                            }
                            else
                            {
                                isSuccess = true;
                                break;
                            }
                        }
                        else
                        {
                            isSuccess = true;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Skynet.LoggingService.LogService.GlobalInfoMessage("发卡失败:" + ex.Message);
                    SkyComm.ShowMessageInfo("发卡失败:" + ex.Message);
                    isSuccess = false;
                    //this.btnReturn.Enabled = true;
                    this.btnExit.Enabled = true;
                    this.lblOK.Enabled   = true;
                }

                //写卡失败
                if (isSuccess == false)
                {
                    //撤消已注销挂失并补卡的信息
                    //eCardAuthorizationFacade.deleteEntityAndCardSaving(eLCardAuthorizationData);
                    eCardAuthorizationFacade.TranBackBussiness(drCard["ACCOUNT_ID"].ToString(), eLCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString(), drCard["CARDID"].ToString(), drCard["CIRCUIT_STATE"].ToString(), eLCardAuthorizationData);
                    SkynetMessage.MsgInfo("写卡失败,请在其他自助机上重试!");
                    this.lblOK.Enabled = true;
                    //this.btnReturn.Enabled = true;
                    this.btnExit.Enabled = true;
                    this.ucTime1.timer1.Start();
                    //第二次写卡失败以后将卡回收
                    SendCard.ReturnCard();
                    return;
                }
                #endregion
                form.Close();
            }
            #region 充值
            try
            {
                SkyComm.eCardAuthorizationData = eLCardAuthorizationData;//暂注释
                SkyComm.DiagnoseID             = SkyComm.eCardAuthorizationData.Tables[0].Rows[0]["DIAGNOSEID"].ToString();
                SkyComm.cardInfoStruct.CardNo  = eLCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString();
                SkyComm.cardBlance             = 0;
                CardSavingFacade cf = new CardSavingFacade();
                SkyComm.cardallmoney = 0;

                int     Savingsucceed = 0;
                decimal RechargeMoney = 0;
                string  strModeType   = "现金";
                string  projectType   = SkyComm.getvalue("项目版本标识");
                if (!string.IsNullOrEmpty(projectType) && projectType == "锡林郭勒盟医院")
                {
                    //eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_MODETYPE] = strModeType;
                    if (!eLCardAuthorizationData.Tables[0].Columns.Contains("OPERATORNAME"))
                    {
                        eLCardAuthorizationData.Tables[0].Columns.Add("OPERATORNAME");

                        eLCardAuthorizationData.Tables[0].Rows[0]["OPERATORNAME"] = SysOperatorInfo.OperatorName;
                    }
                    eCardAuthorizationFacade.updateEntity(eLCardAuthorizationData);
                    //eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_ADDMONEY] = RechargeMoney;
                    Savingsucceed = 1;
                    //打印发卡凭证
                    PrintSendCardReport(eLCardAuthorizationData, drCard["PATIENTNAME"].ToString());
                }
                else
                {
                    try
                    {
                        //充值,弹出界面选择是现金充值还是银行卡预存
                        if (!string.IsNullOrEmpty(AutoHostConfig.PosInterfaceType))
                        {
                            FrmCardSavingMain frm = new FrmCardSavingMain();
                            frm.CallType = 2;
                            frm.ShowDialog();
                            Savingsucceed = frm.Savingsucceed;
                            RechargeMoney = frm.RechargeMoney;
                            strModeType   = frm.MODETYPE;
                            frm.Dispose();
                        }
                        else
                        {
                            //拍照
                            switch (AutoHostConfig.ReadCardType)
                            {
                            case "XUHUI":
                            case "XUHUIM1":
                                AutoServiceSDK.SdkService.Common_XH camera = new AutoServiceSDK.SdkService.Common_XH();
                                camera.TakeCamera(SkyComm.cardInfoStruct.CardNo, SkyComm.eCardAuthorizationData.Tables[0].Rows[0]["PATIENTNAME"].ToString(), AutoHostConfig.Machineno);
                                break;

                            default:
                                break;
                            }

                            FrmCardSavingCash frm = new FrmCardSavingCash();
                            frm.CallType = 2;
                            frm.ShowDialog();
                            Savingsucceed = frm.Savingsucceed;
                            RechargeMoney = frm.RechargeMoney;
                            frm.Dispose();
                        }
                        if (Savingsucceed == 1)
                        {
                            eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_MODETYPE] = strModeType;
                            if (!eLCardAuthorizationData.Tables[0].Columns.Contains("OPERATORNAME"))
                            {
                                eLCardAuthorizationData.Tables[0].Columns.Add("OPERATORNAME");

                                eLCardAuthorizationData.Tables[0].Rows[0]["OPERATORNAME"] = SysOperatorInfo.OperatorName;
                            }
                            eCardAuthorizationFacade.updateEntity(eLCardAuthorizationData);
                            eLCardAuthorizationData.Tables[0].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_ADDMONEY] = RechargeMoney;

                            //打印发卡凭证
                            PrintSendCardReport(eLCardAuthorizationData, drCard["PATIENTNAME"].ToString());
                        }
                    }
                    catch (Exception ex2)
                    {
                        Skynet.LoggingService.LogService.GlobalInfoMessage("补卡充值失败:" + ex2.Message);
                    }
                    finally
                    {
                        //SkyComm.cardInfoStruct = new CardInformationStruct();
                        //SkyComm.eCardAuthorizationData.Tables[0].Clear();
                        //SkyComm.DiagnoseID = string.Empty;
                        //SkyComm.cardBlance = 0;
                        //SkyComm.cardallmoney = 0;
                    }
                }
                if (Savingsucceed == 1)
                {
                    SendCard.OutputCard();

                    SkyComm.ShowMessageInfo("补卡成功,请取走您的就诊卡!");
                }
                else
                {
                    //撤消已注销挂失并补卡的信息
                    Skynet.LoggingService.LogService.GlobalInfoMessage("充值失败,撤消发卡信息");
                    //eCardAuthorizationFacade.deleteEntityAndCardSaving(eLCardAuthorizationData);
                    DataSet dsCardAuthorizationData = (DataSet)eLCardAuthorizationData;
                    eCardAuthorizationFacade.TranBackBussiness(drCard["ACCOUNT_ID"].ToString(), eLCardAuthorizationData.Tables[0].Rows[0]["CARDID"].ToString(), drCard["CARDID"].ToString(), drCard["CIRCUIT_STATE"].ToString(), eLCardAuthorizationData);
                    eLCardAuthorizationData = new CardAuthorizationData();
                    this.lblOK.Enabled      = true;
                    //this.btnReturn.Enabled = true;
                    this.btnExit.Enabled = true;

                    //发卡失败以后将卡进行回收
                    SendCard.ReturnCard();
                    ucTime1.timer1.Start();

                    return;
                }
            }
            catch (Exception ex)
            {
                Skynet.LoggingService.LogService.GlobalInfoMessage("发卡失败:" + ex.Message + ",系统回收卡机中的卡");

                //发卡失败以后将卡进行回收
                SendCard.ReturnCard();

                SkynetMessage.MsgInfo("发卡失败:" + ex.Message);
                ucTime1.timer1.Start();

                return;
            }
            finally
            {
                SkyComm.cardInfoStruct = new CardInformationStruct();
                SkyComm.eCardAuthorizationData.Tables[0].Clear();
                SkyComm.DiagnoseID   = string.Empty;
                SkyComm.cardBlance   = 0;
                SkyComm.cardallmoney = 0;

                this.lblOK.Enabled = true;
                //this.btnReturn.Enabled = true;
                this.btnExit.Enabled = true;
            }
            #endregion

            SystemFramework.Voice.Voice voice = new SystemFramework.Voice.Voice();
            voice.PlayText("请在就诊卡出口取走您的就诊卡!");
            voice.EndJtts();
            ucTime1.timer1.Start();
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }