// InputAuthDlg.cpp : implementation file // #include "stdafx.h" #include "DBServer.h" #include "InputAuthDlg.h" #include "my32.h" #include "SoftKey.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // InputAuthDlg dialog InputAuthDlg::InputAuthDlg(CWnd* pParent /*=NULL*/) : CDialog(InputAuthDlg::IDD, pParent) { //{{AFX_DATA_INIT(InputAuthDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void InputAuthDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(InputAuthDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(InputAuthDlg, CDialog) //{{AFX_MSG_MAP(InputAuthDlg) ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2) ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // InputAuthDlg message handlers BOOL InputAuthDlg::OnInitDialog() { CDialog::OnInitDialog(); #ifdef TIMEDOG_VERSION//时钟狗 // TODO: Add extra initialization here SetDlgItemText(IDC_STATIC1, ("授权申请码, 请把此申请码提供给经销商") ); SetDlgItemText(IDC_STATIC2, ("请在下方框中输入经销商提供给您的授权码") ); SetWindowText(("输入授权码")); SetDlgItemText(IDOK, ("确定") ); SetDlgItemText(IDCANCEL, ("取消") ); TCHAR DevicePath[ 260]; if(FindPort(0,DevicePath)!=0) exit(1); int version; GetIDVersion((DWORD*)&m_id, &version, DevicePath); int d[8];double f[8]; int idtemp=123456; char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]=""; //运行自定义函数 SoftKey ytSoftKey; int ret=ytSoftKey.IniEx(); if (ret!=0 ) { AfxMessageBox("没有找到加密狗"); return false; } ret=ytSoftKey.timedog1(&m_id,&idtemp,&m_time1,&m_time2,&d[4],&d[5],&d[6],&d[7], &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7], s0,s1,s2,s3,s4,s5,s6,s7); if(ret!=0 && ret!=-43) { TCHAR ErrInfo[260]=""; ytSoftKey.GetErrInfo(ret,ErrInfo); CString msg="出错了:";msg=msg+ErrInfo; AfxMessageBox((msg)); exit(-1); } CString str=""; CString temp,temp2; ///////////////////////////////////////// temp.Format ("%d", abs(m_id)); int leng=temp.GetLength (); if(m_id<0) temp2="1"; else temp2="0"; temp=temp2+temp; temp2.Format ("%02d", leng); temp=temp2+temp; str+=temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format ("%d", abs(m_time1)); leng=temp.GetLength (); if(m_time1<0) temp2="1"; else temp2="0"; temp=temp2+temp; temp2.Format ("%02d", leng); temp=temp2+temp; str+=temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format ("%d", abs(m_time2)); leng=temp.GetLength (); if(m_time2<0) temp2="1"; else temp2="0"; temp=temp2+temp; temp2.Format ("%02d", leng); temp=temp2+temp; str+=temp; //////////////////////////////////两位长度, 1为负, 0为正, 数据区 temp.Format ("%d", abs(idtemp)); leng=temp.GetLength (); if(idtemp<0) temp2="1"; else temp2="0"; temp=temp2+temp; temp2.Format ("%02d", leng); temp=temp2+temp; str+=temp; SetDlgItemText(IDC_EDIT1, str); #endif return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void InputAuthDlg::OnOK() { #ifdef TIMEDOG_VERSION//时钟狗 // TODO: Add extra validation here CString authcode; GetDlgItemText(IDC_EDIT2, authcode); authcode.TrimLeft (); authcode.TrimRight (); authcode.Replace ("\n", ""); authcode.Replace ("\r", ""); if(authcode.GetLength ()!=240) { #ifdef BESTGIFT AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!")); #else AfxMessageBox(("授权申请码错误, 请重新向经销商索取!")); #endif return; } TCHAR DevicePath[ 260]; if(FindPort(0,DevicePath)!=0) exit(1); DWORD OutID; int version; GetIDVersion(&OutID, &version, DevicePath); CString str1,str2,str3,str4,str5; str1=authcode.Mid (0, 48); str2=authcode.Mid (48, 48); str3=authcode.Mid (96, 48); str4=authcode.Mid (144, 48); str5=authcode.Mid (192, 48); SoftKey ytSoftKey; int ret=ytSoftKey.IniEx(); if (ret!=0 ) { AfxMessageBox( "没有找到加密狗"); return ; } int d[8];double f[8]; char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]=""; //运行自定义函数 sprintf(s0, "%s", str1); sprintf(s1, "%s", str2); sprintf(s2, "%s", str3); sprintf(s3, "%s", str4); sprintf(s4, "%s", str5); //运行自定义函数 ret=ytSoftKey.timedog2(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7], &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7], s0,s1,s2,s3,s4,s5,s6,s7); if(ret!=0 && ret!=-43) { TCHAR ErrInfo[260]=""; ytSoftKey.GetErrInfo(ret,ErrInfo); CString msg="出错了:";msg=msg+ErrInfo; AfxMessageBox((msg)); exit(-1); } str1=s0; str2=s1; str3=s2; str4=s3; str5=s4; authcode=str1; authcode+=str2; authcode+=str3; authcode+=str4; authcode+=str5; str1+=str2; str3+=str4; DWORD id=atoi(str5.Right (8)); str5=str5.Left (12); if(id!=OutID) { #ifdef BESTGIFT AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!")); #else AfxMessageBox(("授权申请码错误, 请重新向经销商索取!")); #endif return; } TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff"; TCHAR WHKey[41]="0",WLKey[41]="0"; TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10]; sprintf(WHKey, "%s", str1); sprintf(WLKey, "%s", str3); CString temp; temp=str5.Left (4); str5=str5.Right (8); sprintf(year, "%s", temp); temp=str5.Left (2); str5=str5.Right (6); sprintf(month, "%s", temp); temp=str5.Left (2); str5=str5.Right (4); sprintf(day, "%s", temp); temp=str5.Left (2); str5=str5.Right (2); sprintf(hour, "%s", temp); sprintf(minute, "%s", str5); sprintf(second, "%s", "0"); ret=WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id,year,month,day,hour,minute,DevicePath); if(ret==0) { TCHAR year2[10],month2[10],day2[10],hour2[10],minute2[10],second2[10]; GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath); DWORD time1,time2; time1=ConvertStringToTimerReal(year, month, day, hour, minute, second); sprintf(second2, "%s", "0"); time2=ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2); if(time1>time2) ConvertTimerToStringReal(time1-time2, year, month, day, hour, minute, second); else { sprintf(year, "%s", "0"); sprintf(month, "%s", "0"); sprintf(day, "%s", "0"); sprintf(hour, "%s", "0"); sprintf(minute, "%s", "0"); } str1.Format ("授权成功! 您的加密锁还可以运行 %d 年 %d 月 %d 日 %d 小时 %d 分", atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute)); AfxMessageBox((str1)); SetDlgItemText(IDC_EDIT3, year); SetDlgItemText(IDC_EDIT4, month); SetDlgItemText(IDC_EDIT5, day); SetDlgItemText(IDC_EDIT6, hour); SetDlgItemText(IDC_EDIT7, minute); } else { #ifdef BESTGIFT AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!")); #else AfxMessageBox(("授权申请码错误, 请重新向经销商索取!")); #endif return; } #endif CDialog::OnOK(); } void InputAuthDlg::OnChangeEdit2() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. CString authcode; GetDlgItemText(IDC_EDIT2, authcode); authcode.TrimLeft (); authcode.TrimRight (); authcode.Replace ("\n", ""); authcode.Replace ("\r", ""); SetDlgItemText(IDC_EDIT2, authcode); // TODO: Add your control notification handler code here } void InputAuthDlg::OnChangeEdit1() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CDialog::OnInitDialog() // function and call CRichEditCtrl().SetEventMask() // with the ENM_CHANGE flag ORed into the mask. CString authcode; GetDlgItemText(IDC_EDIT1, authcode); authcode.TrimLeft (); authcode.TrimRight (); authcode.Replace ("\n", ""); authcode.Replace ("\r", ""); SetDlgItemText(IDC_EDIT1, authcode); // TODO: Add your control notification handler code here }