private void identityCard_Click(object sender, EventArgs e)
 {
     if (SkyComm.getvalue("自助机类型") == "0")
     {
         #region  柜式自助机驱动
         FrmReadIdenetityGS FrmReadIdenetity = new FrmReadIdenetityGS();
         try
         {
             timer1.Stop();
             if (FrmReadIdenetity.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
             {
                 #region 验证卡状态
                 string CardID = FrmReadIdenetity.strCardNO;
                 BusinessFacade.His.CardClubManager.CardAuthorizationFacade eCardAuthorizationFacade = new BusinessFacade.His.CardClubManager.CardAuthorizationFacade();
                 if (SystemInfo.SystemConfigs["是否启用就诊卡与副卡关联"].DefaultValue.ToString() == "1")
                 {
                     bool isSecondaryCard = false;//是否副卡
                     CardID = eCardAuthorizationFacade.GetMotherCardID(CardID, "", ref isSecondaryCard);
                 }
                 CardAuthorizationData eCardAuthorizationData = (CardAuthorizationData)eCardAuthorizationFacade.SelectPatientAndCardInfoByCardID(CardID);
                 if (eCardAuthorizationData.Tables[0].Rows.Count == 0)
                 {
                     MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "卡号无效");
                     registerInfo.ShowDialog();
                     this.Close();
                     return;
                 }
                 CardID = eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CARDID].ToString();
                 if (!string.IsNullOrEmpty(CardID))
                 {
                     if (Convert.ToInt32(eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CIRCUIT_STATE]) == 1)
                     {
                         MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "此卡已挂失不能使用!");
                         registerInfo.ShowDialog();
                         this.Close();
                         return;
                     }
                     if (Convert.ToInt32(eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CIRCUIT_STATE]) == 2)
                     {
                         MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "此卡已注销不能使用");
                         registerInfo.ShowDialog();
                         this.Close();
                         return;
                     }
                     if (Skynet.Framework.Common.SystemInfo.SystemConfigs["是否启用卡有效期"].DefaultValue.Equals("1"))
                     {
                         var dtCard = eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].AsEnumerable();
                         _isVilid = dtCard.Where(a => a.Field <DateTime>(CardAuthorizationData.T_CARD_AUTHORIZATION_CARDVALIDDATE) <= DateTime.Now).ToList().Count > 0 ? true : false;
                         if (_isVilid)
                         {
                             MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "该卡已经过了有效期,请联系管理员!");
                             registerInfo.ShowDialog();
                             this.Close();
                             return;
                         }
                     }
                 }
                 else
                 {
                     MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "请持身份证在窗口签约");
                     registerInfo.ShowDialog();
                     this.Close();
                     return;
                 }
                 #endregion
                 SkyComm.cardInfoStruct.CardNo         = CardID;
                 SkyComm.DiagnoseID                    = eCardAuthorizationData.Tables[0].Rows[0]["DIAGNOSEID"].ToString();
                 SkyComm.cardInfoStruct.isIdentityCard = true;
                 CardRead cardUtility = new CardRead(this);
                 strMsg            = cardUtility.GetPatiantInfo();
                 this.DialogResult = DialogResult.OK;
             }
             timer1.Start();
         }
         catch (Exception ex)
         {
             timer1.Start();
             FrmReadIdenetity.Dispose();
             Skynet.LoggingService.LogService.GlobalInfoMessage("读取居民身份证信息失败:" + ex.Message);
             return;
         }
         finally
         {
             FrmReadIdenetity.Dispose();
         }
         #endregion
     }
     else
     {
         #region  壁挂式自助机驱动
         FrmReadIdenetityBG FrmReadIdenetity = new FrmReadIdenetityBG();
         try
         {
             timer1.Stop();
             if (FrmReadIdenetity.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
             {
                 #region 验证卡状态
                 string CardID = FrmReadIdenetity.strCardNO;
                 BusinessFacade.His.CardClubManager.CardAuthorizationFacade eCardAuthorizationFacade = new BusinessFacade.His.CardClubManager.CardAuthorizationFacade();
                 if (SystemInfo.SystemConfigs["是否启用就诊卡与副卡关联"].DefaultValue.ToString() == "1")
                 {
                     bool isSecondaryCard = false;//是否副卡
                     CardID = eCardAuthorizationFacade.GetMotherCardID(CardID, "", ref isSecondaryCard);
                 }
                 CardAuthorizationData eCardAuthorizationData = (CardAuthorizationData)eCardAuthorizationFacade.SelectPatientAndCardInfoByCardID(CardID);
                 if (eCardAuthorizationData.Tables[0].Rows.Count == 0)
                 {
                     MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "卡号无效");
                     registerInfo.ShowDialog();
                     this.Close();
                     return;
                 }
                 CardID = eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CARDID].ToString();
                 if (!string.IsNullOrEmpty(CardID))
                 {
                     if (Convert.ToInt32(eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CIRCUIT_STATE]) == 1)
                     {
                         MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "此卡已挂失不能使用!");
                         registerInfo.ShowDialog();
                         this.Close();
                         return;
                     }
                     if (Convert.ToInt32(eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].Rows[0][CardAuthorizationData.T_CARD_AUTHORIZATION_CIRCUIT_STATE]) == 2)
                     {
                         MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "此卡已注销不能使用");
                         registerInfo.ShowDialog();
                         this.Close();
                         return;
                     }
                     if (Skynet.Framework.Common.SystemInfo.SystemConfigs["是否启用卡有效期"].DefaultValue.Equals("1"))
                     {
                         var dtCard = eCardAuthorizationData.Tables["T_CARD_AUTHORIZATION"].AsEnumerable();
                         _isVilid = dtCard.Where(a => a.Field <DateTime>(CardAuthorizationData.T_CARD_AUTHORIZATION_CARDVALIDDATE) <= DateTime.Now).ToList().Count > 0 ? true : false;
                         if (_isVilid)
                         {
                             MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "该卡已经过了有效期,请联系管理员!");
                             registerInfo.ShowDialog();
                             this.Close();
                             return;
                         }
                     }
                 }
                 else
                 {
                     MyAlert registerInfo = new MyAlert(AlertTypeenum.信息, "请持身份证在窗口签约");
                     registerInfo.ShowDialog();
                     this.Close();
                     return;
                 }
                 #endregion
                 SkyComm.cardInfoStruct.CardNo         = CardID;
                 SkyComm.DiagnoseID                    = eCardAuthorizationData.Tables[0].Rows[0]["DIAGNOSEID"].ToString();
                 SkyComm.cardInfoStruct.isIdentityCard = true;
                 CardRead cardUtility = new CardRead(this);
                 strMsg            = cardUtility.GetPatiantInfo();
                 this.DialogResult = DialogResult.OK;
             }
             timer1.Start();
         }
         catch (Exception ex)
         {
             timer1.Start();
             FrmReadIdenetity.Dispose();
             Skynet.LoggingService.LogService.GlobalInfoMessage("读取居民身份证信息失败:" + ex.Message);
             return;
         }
         finally
         {
             FrmReadIdenetity.Dispose();
         }
         #endregion
     }
 }
        /// <summary>
        /// 读卡返回病人信息实体
        /// </summary>
        /// <param name="mark">区别门诊【mark="C"】或者住院【mark!="H"】或者出院【mark!="L"】</param>
        /// <param name="cardInfoStruct">卡信息</param>
        /// <param name="isZz">是否是自助打印</param>
        /// <returns>病人信息实体</returns>
        public override DataSet OpenAndGetPatiantInfo(string mark, ref CardInformationStruct cardInfoStruct)
        {
            if (mark.ToUpper() == "R")//若为挂号,采用原有刷卡操作逻辑
            {
                try
                {
                    SkyComm.cardInfoStruct = this.Read();

                    //FrmMain.cardInfoStruct.CardNo = "000118247826721";//仅作测试 需要删除
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            int     IS_FEECHARGING_CARD = -1;
            DataSet dsReturn            = new DataSet();

            BusinessFacade.His.CardClubManager.CardAuthorizationFacade eCardAuthorizationFacade =
                new BusinessFacade.His.CardClubManager.CardAuthorizationFacade();

            //判断当前卡状态
            //0 正常1 冻结2 注销
            if (cardInfoStruct.CardNo != null)
            {
                DataSet dsCard = eCardAuthorizationFacade.getCardStatusByAccount_ID(SkyComm.cardInfoStruct.CardNo);
                if (dsCard != null && dsCard.Tables.Count <= 0 && dsCard.Tables[0].Rows.Count <= 0)
                {
                    throw new Exception("卡号不存在或此卡已被注销,不能继续使用!");
                }
                if (dsCard.Tables[0].Rows.Count <= 0)
                {
                    throw new Exception("卡号不存在或此卡已被注销,不能继续使用!");
                }
                //SkyComm.cardData = dsCard.Copy();
                SkyComm.cardInfoStruct.CardAccountID = dsCard.Tables[0].Rows[0]["ACCOUNT_ID"].ToString();
                string cir_sta          = dsCard.Tables[0].Rows[0]["CIRCUIT_STATE"].ToString();
                string cir_sta_auditing = dsCard.Tables[0].Rows[0]["AUDITING_STATE"].ToString();
                SkyComm.cardInfoStruct.CardTypeID = Convert.ToInt32(dsCard.Tables[0].Rows[0]["TYPEID"]);
                SkyComm.DiagnoseID = dsCard.Tables[0].Rows[0]["DIAGNOSEID"].ToString();
                if (cir_sta == "1")
                {
                    throw new Exception("此卡已冻结,不能继续使用!");
                }
                else if (cir_sta == "2")
                {
                    throw new Exception("此卡已注销,不能继续使用!");
                }
                else if (cir_sta_auditing == "1")//当卡没有冻结或注销时,才判断是否需要审核
                {
                    //卡未审核
                    throw new Exception("此卡还未审核,不能继续使用!");
                }

                if (mark.ToUpper() == "C" || mark.ToUpper() == "R")//门诊
                {
                    dsReturn = eCardAuthorizationFacade.OpenAndGetPatiantInfoByAccount_IDForClinic(SkyComm.cardInfoStruct.CardAccountID, ref IS_FEECHARGING_CARD);
                }
                else if (mark.ToUpper() == "H")//住院
                {
                    dsReturn = eCardAuthorizationFacade.OpenAndGetPatiantInfoByAccount_IDForInpatient(SkyComm.cardInfoStruct.CardAccountID, ref IS_FEECHARGING_CARD);
                }
                else if (mark.ToUpper() == "L")//出院
                {
                    dsReturn = eCardAuthorizationFacade.OpenAndGetPatiantInfoByAccount_IDForLeave(SkyComm.cardInfoStruct.CardAccountID, ref IS_FEECHARGING_CARD);
                }
                else
                {
                    throw new Exception("参数错误,不能继续使用!");
                }

                if (!Directory.Exists(Application.StartupPath + "\\ReportXML"))
                {
                    Directory.CreateDirectory(Application.StartupPath + "\\ReportXML");//
                }
                SkyComm.cardInfoStruct.Is_FEECHARGING_CARD = IS_FEECHARGING_CARD;
                dsReturn.WriteXml(Application.StartupPath + "\\ReportXML\\CardInterface.xml");
                return(dsReturn);
            }
            return(null);
        }