⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icdemodlg.cpp

📁 IC卡操作Demo 包括了常见的IC卡种类。可执行写入、读出、校验、密码修改、批量作业等功能。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	   m_next.EnableWindow(TRUE);
       m_prev.EnableWindow(TRUE);
      }
	   MessageBox("卡已上电!","信息提示",MB_ICONINFORMATION|MB_OK);
	   m_lblpower.SetWindowText("卡状态:已上电");
       m_poweroff.EnableWindow(TRUE);
	  // m_readcard.SetFocus(); 
	   m_StatusBarCtrl->SetText("函数:unsigned power_on()",2,0);
	}

}

void CIcDemoDlg::OncmdPowerOff() 
{
	// TODO: Add your control notification handler code here
	int Rn=theApp.surepower_off(); 
	if(Rn!=0)
	  m_StatusBarCtrl->SetText(theApp.ReadWriteError(Rn),0,0);
	else
	{
		m_lblpower.SetWindowText("卡状态:未上电");
		m_lblpwd.SetWindowText("未核对密码");
	    m_lblcardtype.SetWindowText("卡型:未选择");
		m_schk.SetWindowText("校验码:");
        m_spwd.SetWindowText("密码:");
	}
			m_StatusBarCtrl->SetText("函数:unsigned power_off(void)",2,0);
}
void CIcDemoDlg::ReadCard(int Addr)
{
  
  char Hexbuff[260];
  char Rdchar[10];
  int  Getlen,Rn;
  int  i,j,k;
  CString tmp,headstr;
  CWaitCursor wait;
  int m_end;
  if(theApp.intPage<=0) return;
  m_StatusBarCtrl->SetText("正在读卡...",0,0);
  memset(Hexbuff,' ',260);
  if(Addr!=theApp.intPage)
     Rn = theApp.surerd_asc(0, 130 * (Addr - 1), 130, Hexbuff);
    //Rn = theApp.surerd_asc(2047, 0, 130, Hexbuff);
  else
     Rn = theApp.surerd_asc(0, 130 * (Addr - 1), 130-(Addr*130-theApp.lInfaceByte), Hexbuff);
  if(Rn!=0)
  {
    m_StatusBarCtrl->SetText(theApp.ReadWriteError(Rn),0,0);
	return ;
  }
 // m_lstdata.DeleteAllItems();
  k=0;
  m_end=0;
  for(i = 13 * (Addr - 1);i<12 * Addr + (Addr - 1)+1;i++)
  { 
    headstr.Format("%.4d",i*10);
	m_lstdata.SetItemText(k,0,headstr);
   	tmp=Hexbuff;
	tmp=tmp.Mid(k * 20, 20); 
    for(j=1;j<11;j++)
	{
	 // if (tmp.Mid(j*2-2,2)=="77")
	//	  MessageBox("Find it",":)",MB_OK);
	  m_lstdata.SetItemText(k,j,tmp.Mid(j*2-2,2));
	}
    memset(Rdchar,' ',10);
	if(m_end!=1)
	{
		if(Addr!=theApp.intPage || k!=(130 - (Addr*130-theApp.lInfaceByte))/10)
		   {
			   Rn = theApp.surerd_str(0, 10 * i, 10, Rdchar);
			   tmp=Rdchar;
			   tmp=tmp.Mid(0,10);
			   if(Rn!=0)
			   {
				 m_StatusBarCtrl->SetText(theApp.ReadWriteError(Rn),0,0);
				 return ;
			   }
		   }
		else
		   {
			 Getlen = (130 - (Addr*130-theApp.lInfaceByte))%10;
			 //Getlen =Getlen>0 ? Getlen : 10-Getlen;
			 Rn = theApp.surerd_str(0, 10 * i, Getlen, Rdchar);
			 tmp=Rdchar;
			 tmp=tmp.Mid(0,Getlen); 
			 m_end=1;
   		     if(Rn!=0)
			  {
				 m_StatusBarCtrl->SetText(theApp.ReadWriteError(Rn),0,0);
				 return ;
			   }
		}
	}
	else
		tmp="";
   m_lstdata.SetItemText(k,11,tmp);
   k++;
  }
  wait.Restore(); 
  m_StatusBarCtrl->SetText("读卡完成",0,0);
}

void CIcDemoDlg::OncmdReadCard() 
{
	// TODO: Add your control notification handler code here
  if(theApp.intType==64)
  {
    CPageRd dlg;
    int Rn=dlg.DoModal();
    if(Rn==IDOK)
	{
	  ReadCard(theApp.intRdPage);
	  chkPage=theApp.intRdPage;
	}
  }
  else
  {
    ReadCard(1);
	chkPage=1;
	DispPwd();
  }
  CString str ;
  str.Format("%d",chkPage);
  str="第" + str + "页";
  m_page.SetWindowText(str);
	m_StatusBarCtrl->SetText("函数:unsigned rd_asc/rd_str",2,0);
}

void CIcDemoDlg::OncmdPrev() 
{
	// TODO: Add your control notification handler code here
	if(chkPage>1) chkPage = chkPage - 1;
    ReadCard(chkPage);
	CString str ;
    str.Format("%d",chkPage);
    str="第" + str + "页";
    m_page.SetWindowText(str);
}

void CIcDemoDlg::OncmdNext() 
{
	// TODO: Add your control notification handler code here
	if(chkPage < theApp.intPage) chkPage = chkPage + 1;
     ReadCard(chkPage);
	 CString str ;
     str.Format("%d",chkPage);
     str="第" + str + "页";
     m_page.SetWindowText(str);
}

void CIcDemoDlg::OncmdWrCard() 
{
	// TODO: Add your control notification handler code here
	m_wrcard.EnableWindow(FALSE);
	if((theApp.intType>10 && theApp.intType<20) || (theApp.intType>40 && theApp.intType<60))
	{
		if(IsChkPwd==0)
		{
			MessageBox("卡未核对密码!","信息提示",MB_ICONINFORMATION|MB_OK);
            m_wrcard.EnableWindow(TRUE);
			return;
		}
	}

	m_StatusBarCtrl->SetText("正在写卡...",0,0);
	CRDCARD dlg;
	int Rn=dlg.DoModal(); 
	if(Rn==IDOK)
	  ReadCard(chkPage);
	m_StatusBarCtrl->SetText("写卡完成",0,0);
	m_wrcard.EnableWindow(TRUE);
	m_StatusBarCtrl->SetText("函数:unsigned wr_asc/wr_str",2,0);
}

void CIcDemoDlg::OncmdChkPwd() 
{
	// TODO: Add your control notification handler code here
	m_StatusBarCtrl->SetText("正在核对密码...",0,0);
	CChkSc dlg;
    int Rn=dlg.DoModal();
	if(Rn==IDOK)
	{
	  m_StatusBarCtrl->SetText("核对完成",0,0);
	  m_lblpwd.SetWindowText("已核对密码"); 
	  DispPwd();
	  IsChkPwd=1;
	}
	m_StatusBarCtrl->SetText("函数:unsigned chk_sc(unsigned zone, unsigned length, char  *buff)",2,0);
}

void CIcDemoDlg::OncmdCheck() 
{
	// TODO: Add your control notification handler code here
	CWrSm dlg;
    m_StatusBarCtrl->SetText("正在改写密码...",0,0);
	dlg.DoModal(); 
    m_StatusBarCtrl->SetText("改写完成",0,0);
	m_spwd.SetWindowText(theApp.m_Pwd);
	m_schk.SetWindowText(theApp.m_ChkP);
	theApp.surepower_on(); 
	m_StatusBarCtrl->SetText("函数:unsigned wr_sc(char  *buff)",2,0);
	
	//DispPwd();
}

BOOL CIcDemoDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
    switch(pMsg->message)
	{
		case WM_KEYDOWN:
			CString str;
			str.Format("%d",pMsg->wParam);  
			if(pMsg->wParam==33 && m_prev.IsWindowEnabled())
			  OncmdPrev();
			if(pMsg->wParam==34 && m_next.IsWindowEnabled())
			  OncmdNext();
            if(pMsg->wParam==35 && m_lst.IsWindowEnabled())
			  OncmdLst();
			if(pMsg->wParam==36 && m_fst.IsWindowEnabled())
			  OncmdFst();
            
			
	}
	return CDialog::PreTranslateMessage(pMsg);
}

BOOL CIcDemoDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(nID==IDOK || nID==IDCANCEL)
		return FALSE;
	return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

void CIcDemoDlg::OncmdFst() 
{
	// TODO: Add your control notification handler code here
	ReadCard(1);
	chkPage=1;
}

void CIcDemoDlg::OncmdLst() 
{
	// TODO: Add your control notification handler code here
	ReadCard(theApp.intPage);
	chkPage=theApp.intPage; 
}
void CIcDemoDlg::DispPwd()
{
	CString str;
	int Rn;
    char rdpwd[32];
    memset(rdpwd,' ',32);
	if(theApp.intType==42) 
	{
	 Rn=theApp.surerd_sm(rdpwd);
	 if(Rn!=0)
		theApp.ReadWriteError(Rn);
	 else
	 {
      str=rdpwd;
	  str=str.Mid(2,6); 
	  CardPwd=str;
	  str="密码:" + str;
	  m_spwd.SetWindowText(str);
	  str=rdpwd;
	  str=str.Mid(0,2);
	  str="校验码:" + str;
	  m_schk.SetWindowText(str);
	 }
	}
	 if(theApp.intType==43)
	 {
	   Rn=theApp.surerd_asc(0, 1021, 3, rdpwd);
       if(Rn!=0)
		  theApp.ReadWriteError(Rn);
	   else
	   {
		  str=rdpwd;
		  str=str.Mid(0,2);
	      str="校验码:" + str;
		  m_schk.SetWindowText(str);
          str=rdpwd;
	      str=str.Mid(2,4); 
	      CardPwd=str;
		  str="密码:" + str;
	      m_spwd.SetWindowText(str);
	   }
	}
}

void CIcDemoDlg::OncmdChkAll() 
{
	// TODO: Add your control notification handler code here
 int m_loop;
 char* Abuff=NULL;
 char* Mbuff=NULL;
 char* Fbuff=NULL;
 char* Tbuff=NULL;
 CString str,chkstr;
 CWaitCursor wait;
	m_chkall.EnableWindow(FALSE);
	if((theApp.intType>10 && theApp.intType<20) || (theApp.intType>40 && theApp.intType<60))
	{
		if(IsChkPwd==0)
		{
			MessageBox("未核对密码!","信息提示",MB_ICONINFORMATION|MB_OK);
            m_chkall.EnableWindow(TRUE);
			return;
		}
	}
Ltest:
	m_loop=0;
	Abuff=NULL;
    Mbuff=NULL;
    Fbuff=NULL;
    Tbuff=NULL;
	while(m_loop!=1)
	{
    // MessageBox("真的要退出系统吗?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDYES)  
    Abuff=NULL;
    Mbuff=NULL;
    Fbuff=NULL;
    Tbuff=NULL; 
	 if(theApp.intType>=10)
	  {
        if(theApp.surepower_on()!=0)
             if(MessageBox("卡未插入,是否继续?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDNO)
			 {
				 m_loop=1;
				 m_chkall.EnableWindow(TRUE);
				 return;
			 }
			 else
				 goto Ltest;
	  }
	 switch(theApp.intType)
	 {
		case 42:
           Abuff=new char[10];
		   memset( Abuff ,' ',10);
		   if(theApp.surerd_asc(0,0,2,Abuff)!=0)
		   {
             if(MessageBox("读卡失败,是否继续?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDNO)
			 {
				 m_loop=1;
				 return;
			 }
			 else
               goto Ltest;
		   }
		   str=Abuff;
		   if(str.Mid(0,4)!="A213")
		   {
			 if(MessageBox("读卡失败,是否继续?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDNO)
			 {
				 m_loop=1;
				 m_chkall.EnableWindow(TRUE);
				 return;
			 }
			 else
              goto Ltest;
           }
		   //str=m_spwd.Right(6);
		   Abuff=new char[6];
		   strcpy(Abuff,CardPwd);
		   if(theApp.surechk_sc(0,3,Abuff)!=0)
		   {
             MessageBox("核对密码失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           Mbuff=new char[16];
		   Fbuff=new char[16];
		   Mbuff="1234567890ABCDEF";
		   Fbuff="FFFFFFFFFFFFFFEF";
           Abuff=new char[20];
		   Tbuff=new char[20];
		   memset(Abuff,' ',20);
           memset(Tbuff,' ',20);
		   if(theApp.surewr_asc(0, 32, 8, Mbuff)!=0)
		   {
             MessageBox("写卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           if(theApp.surerd_asc(0, 32, 8, Tbuff)!=0)
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
		   str=Mbuff;
		   chkstr=Tbuff;
		   if(str!=chkstr.Mid(0,16))
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
		   if(theApp.surewr_asc(0, 32, 8, Fbuff)!=0)
		   {
             MessageBox("写卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           if(theApp.surerd_asc(0, 32, 8, Abuff)!=0)
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           str=Fbuff;
		   chkstr=Abuff;
		   if(str!=chkstr.Mid(0,16))
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
		   MessageBox("测卡成功!","信息提示",MB_ICONINFORMATION|MB_OK);
		   break;
		case 43:
           Abuff=new char[10];
		   memset( Abuff ,' ',10);
		   if(theApp.surerd_asc(0,0,2,Abuff)!=0)
		   {
             if(MessageBox("读卡失败,是否继续?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDNO)
			 {
				 m_loop=1;
				 m_chkall.EnableWindow(TRUE);
				 return;
			 }
			 else
               goto Ltest;
		   }
		   str=Abuff;
		   if(str.Mid(0,4)!="9223")
		   {
			 if(MessageBox("读卡失败,是否继续?","信息提示",MB_ICONSTOP|MB_YESNO|MB_DEFBUTTON2)==IDNO)
			 {
				 m_loop=1;
				 m_chkall.EnableWindow(TRUE);
				 return;
			 }
			 else
              goto Ltest;
           }
		   //str=m_spwd.Right(6);
		   Abuff=new char[4];
		   strcpy(Abuff,CardPwd);
		   if(theApp.surechk_sc(0,2,Abuff)!=0)
		   {
             MessageBox("核对密码失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           Mbuff=new char[16];
		   Fbuff=new char[16];
		   Mbuff="1234567890ABCDEF";
		   Fbuff="FFFFFFFFFFFFFFEF";
           Abuff=new char[20];
		   Tbuff=new char[20];
		   memset(Abuff,' ',20);
           memset(Tbuff,' ',20);
		   if(theApp.surewr_asc(0, 32, 8, Mbuff)!=0)
		   {
             MessageBox("写卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           if(theApp.surerd_asc(0, 32, 8, Tbuff)!=0)
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
		   str=Mbuff;
		   chkstr=Tbuff;
		   if(str!=chkstr.Mid(0,16))
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
		   if(theApp.surewr_asc(0, 32, 8, Fbuff)!=0)
		   {
             MessageBox("写卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           if(theApp.surerd_asc(0, 32, 8, Abuff)!=0)
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           str=Fbuff;
		   chkstr=Abuff;
		   if(str!=chkstr.Mid(0,16))
		   {
             MessageBox("读卡失败!","信息提示",MB_ICONSTOP|MB_OK);
			 goto m_next;
		   }
           MessageBox("测卡成功!","信息提示",MB_ICONINFORMATION|MB_OK);
     }

	       
m_next:
	if(theApp.intType>=10)
		theApp.surepower_off(); 
	 }
m_chkall.EnableWindow(TRUE);
wait.Restore();
//theApp.surepower_on(); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -