InputAuthDlg.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // InputAuthDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "DBServer.h"
  5. #include "InputAuthDlg.h"
  6. #include "my32.h"
  7. #include "SoftKey.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // InputAuthDlg dialog
  15. InputAuthDlg::InputAuthDlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(InputAuthDlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(InputAuthDlg)
  19. // NOTE: the ClassWizard will add member initialization here
  20. //}}AFX_DATA_INIT
  21. }
  22. void InputAuthDlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(InputAuthDlg)
  26. // NOTE: the ClassWizard will add DDX and DDV calls here
  27. //}}AFX_DATA_MAP
  28. }
  29. BEGIN_MESSAGE_MAP(InputAuthDlg, CDialog)
  30. //{{AFX_MSG_MAP(InputAuthDlg)
  31. ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
  32. ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
  33. //}}AFX_MSG_MAP
  34. END_MESSAGE_MAP()
  35. /////////////////////////////////////////////////////////////////////////////
  36. // InputAuthDlg message handlers
  37. BOOL InputAuthDlg::OnInitDialog()
  38. {
  39. CDialog::OnInitDialog();
  40. #ifdef TIMEDOG_VERSION//时钟狗
  41. // TODO: Add extra initialization here
  42. SetDlgItemText(IDC_STATIC1, ("授权申请码, 请把此申请码提供给经销商") );
  43. SetDlgItemText(IDC_STATIC2, ("请在下方框中输入经销商提供给您的授权码") );
  44. SetWindowText(("输入授权码"));
  45. SetDlgItemText(IDOK, ("确定") );
  46. SetDlgItemText(IDCANCEL, ("取消") );
  47. TCHAR DevicePath[ 260];
  48. if(FindPort(0,DevicePath)!=0)
  49. exit(1);
  50. int version;
  51. GetIDVersion((DWORD*)&m_id, &version, DevicePath);
  52. int d[8];double f[8];
  53. int idtemp=123456;
  54. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  55. //运行自定义函数
  56. #if 0
  57. SoftKey ytSoftKey;
  58. int ret=ytSoftKey.IniEx();
  59. if (ret!=0 )
  60. {
  61. AfxMessageBox("没有找到加密狗");
  62. return false;
  63. }
  64. ret=ytSoftKey.timedog1(&m_id,&idtemp,&m_time1,&m_time2,&d[4],&d[5],&d[6],&d[7],
  65. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  66. s0,s1,s2,s3,s4,s5,s6,s7);
  67. #else
  68. int ret = SoftKey::GetInstance()->timedog1(&m_id,&idtemp,&m_time1,&m_time2,&d[4],&d[5],&d[6],&d[7],
  69. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  70. s0,s1,s2,s3,s4,s5,s6,s7);
  71. #endif
  72. if(ret!=0 && ret!=-43)
  73. {
  74. TCHAR ErrInfo[260]="";
  75. SoftKey::GetInstance()->GetErrInfo(ret,ErrInfo);
  76. CString msg="出错了:";msg=msg+ErrInfo;
  77. AfxMessageBox((msg));
  78. exit(-1);
  79. }
  80. CString str="";
  81. CString temp,temp2;
  82. /////////////////////////////////////////
  83. temp.Format ("%d", abs(m_id));
  84. int leng=temp.GetLength ();
  85. if(m_id<0)
  86. temp2="1";
  87. else
  88. temp2="0";
  89. temp=temp2+temp;
  90. temp2.Format ("%02d", leng);
  91. temp=temp2+temp;
  92. str+=temp;
  93. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  94. temp.Format ("%d", abs(m_time1));
  95. leng=temp.GetLength ();
  96. if(m_time1<0)
  97. temp2="1";
  98. else
  99. temp2="0";
  100. temp=temp2+temp;
  101. temp2.Format ("%02d", leng);
  102. temp=temp2+temp;
  103. str+=temp;
  104. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  105. temp.Format ("%d", abs(m_time2));
  106. leng=temp.GetLength ();
  107. if(m_time2<0)
  108. temp2="1";
  109. else
  110. temp2="0";
  111. temp=temp2+temp;
  112. temp2.Format ("%02d", leng);
  113. temp=temp2+temp;
  114. str+=temp;
  115. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  116. temp.Format ("%d", abs(idtemp));
  117. leng=temp.GetLength ();
  118. if(idtemp<0)
  119. temp2="1";
  120. else
  121. temp2="0";
  122. temp=temp2+temp;
  123. temp2.Format ("%02d", leng);
  124. temp=temp2+temp;
  125. str+=temp;
  126. SetDlgItemText(IDC_EDIT1, str);
  127. #endif
  128. return TRUE; // return TRUE unless you set the focus to a control
  129. // EXCEPTION: OCX Property Pages should return FALSE
  130. }
  131. void InputAuthDlg::OnOK()
  132. {
  133. #ifdef TIMEDOG_VERSION//时钟狗
  134. // TODO: Add extra validation here
  135. CString authcode;
  136. GetDlgItemText(IDC_EDIT2, authcode);
  137. authcode.TrimLeft ();
  138. authcode.TrimRight ();
  139. authcode.Replace ("\n", "");
  140. authcode.Replace ("\r", "");
  141. if(authcode.GetLength ()!=240)
  142. {
  143. #ifdef BESTGIFT
  144. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  145. #else
  146. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  147. #endif
  148. return;
  149. }
  150. TCHAR DevicePath[ 260];
  151. if(FindPort(0,DevicePath)!=0)
  152. exit(1);
  153. DWORD OutID;
  154. int version;
  155. GetIDVersion(&OutID, &version, DevicePath);
  156. CString str1,str2,str3,str4,str5;
  157. str1=authcode.Mid (0, 48);
  158. str2=authcode.Mid (48, 48);
  159. str3=authcode.Mid (96, 48);
  160. str4=authcode.Mid (144, 48);
  161. str5=authcode.Mid (192, 48);
  162. #if 0
  163. SoftKey ytSoftKey;
  164. int ret=ytSoftKey.IniEx();
  165. if (ret!=0 )
  166. {
  167. AfxMessageBox( "没有找到加密狗");
  168. return ;
  169. }
  170. int d[8];double f[8];
  171. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  172. //运行自定义函数
  173. sprintf(s0, "%s", str1);
  174. sprintf(s1, "%s", str2);
  175. sprintf(s2, "%s", str3);
  176. sprintf(s3, "%s", str4);
  177. sprintf(s4, "%s", str5);
  178. //运行自定义函数
  179. ret=ytSoftKey.timedog2(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  180. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  181. s0,s1,s2,s3,s4,s5,s6,s7);
  182. if(ret!=0 && ret!=-43)
  183. {
  184. TCHAR ErrInfo[260]="";
  185. ytSoftKey.GetErrInfo(ret,ErrInfo);
  186. CString msg="出错了:";msg=msg+ErrInfo;
  187. AfxMessageBox((msg));
  188. exit(-1);
  189. }
  190. #else
  191. int d[8];double f[8];
  192. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  193. //运行自定义函数
  194. sprintf(s0, "%s", str1);
  195. sprintf(s1, "%s", str2);
  196. sprintf(s2, "%s", str3);
  197. sprintf(s3, "%s", str4);
  198. sprintf(s4, "%s", str5);
  199. //运行自定义函数
  200. int ret = SoftKey::GetInstance()->timedog2(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  201. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  202. s0,s1,s2,s3,s4,s5,s6,s7);
  203. if(ret!=0 && ret!=-43)
  204. {
  205. TCHAR ErrInfo[260]="";
  206. SoftKey::GetInstance()->GetErrInfo(ret,ErrInfo);
  207. CString msg="出错了:";msg=msg+ErrInfo;
  208. AfxMessageBox((msg));
  209. exit(-1);
  210. }
  211. #endif
  212. str1=s0;
  213. str2=s1;
  214. str3=s2;
  215. str4=s3;
  216. str5=s4;
  217. authcode=str1;
  218. authcode+=str2;
  219. authcode+=str3;
  220. authcode+=str4;
  221. authcode+=str5;
  222. str1+=str2;
  223. str3+=str4;
  224. DWORD id=atoi(str5.Right (8));
  225. str5=str5.Left (12);
  226. if(id!=OutID)
  227. {
  228. #ifdef BESTGIFT
  229. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  230. #else
  231. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  232. #endif
  233. return;
  234. }
  235. TCHAR HKey[50]="ffffffff",LKey[50]="ffffffff";
  236. TCHAR WHKey[41]="0",WLKey[41]="0";
  237. TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
  238. sprintf(WHKey, "%s", str1);
  239. sprintf(WLKey, "%s", str3);
  240. CString temp;
  241. temp=str5.Left (4);
  242. str5=str5.Right (8);
  243. sprintf(year, "%s", temp);
  244. temp=str5.Left (2);
  245. str5=str5.Right (6);
  246. sprintf(month, "%s", temp);
  247. temp=str5.Left (2);
  248. str5=str5.Right (4);
  249. sprintf(day, "%s", temp);
  250. temp=str5.Left (2);
  251. str5=str5.Right (2);
  252. sprintf(hour, "%s", temp);
  253. sprintf(minute, "%s", str5);
  254. sprintf(second, "%s", "0");
  255. ret=WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id,year,month,day,hour,minute,DevicePath);
  256. if(ret==0)
  257. {
  258. TCHAR year2[10],month2[10],day2[10],hour2[10],minute2[10],second2[10];
  259. GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
  260. DWORD time1,time2;
  261. time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  262. sprintf(second2, "%s", "0");
  263. time2=ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
  264. if(time1>time2)
  265. ConvertTimerToStringReal(time1-time2, year, month, day, hour, minute, second);
  266. else
  267. {
  268. sprintf(year, "%s", "0");
  269. sprintf(month, "%s", "0");
  270. sprintf(day, "%s", "0");
  271. sprintf(hour, "%s", "0");
  272. sprintf(minute, "%s", "0");
  273. }
  274. str1.Format ("授权成功! 您的加密锁还可以运行 %d 年 %d 月 %d 日 %d 小时 %d 分", atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
  275. AfxMessageBox((str1));
  276. SetDlgItemText(IDC_EDIT3, year);
  277. SetDlgItemText(IDC_EDIT4, month);
  278. SetDlgItemText(IDC_EDIT5, day);
  279. SetDlgItemText(IDC_EDIT6, hour);
  280. SetDlgItemText(IDC_EDIT7, minute);
  281. }
  282. else
  283. {
  284. #ifdef BESTGIFT
  285. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  286. #else
  287. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  288. #endif
  289. return;
  290. }
  291. #endif
  292. CDialog::OnOK();
  293. }
  294. void InputAuthDlg::OnChangeEdit2()
  295. {
  296. // TODO: If this is a RICHEDIT control, the control will not
  297. // send this notification unless you override the CDialog::OnInitDialog()
  298. // function and call CRichEditCtrl().SetEventMask()
  299. // with the ENM_CHANGE flag ORed into the mask.
  300. CString authcode;
  301. GetDlgItemText(IDC_EDIT2, authcode);
  302. authcode.TrimLeft ();
  303. authcode.TrimRight ();
  304. authcode.Replace ("\n", "");
  305. authcode.Replace ("\r", "");
  306. SetDlgItemText(IDC_EDIT2, authcode);
  307. // TODO: Add your control notification handler code here
  308. }
  309. void InputAuthDlg::OnChangeEdit1()
  310. {
  311. // TODO: If this is a RICHEDIT control, the control will not
  312. // send this notification unless you override the CDialog::OnInitDialog()
  313. // function and call CRichEditCtrl().SetEventMask()
  314. // with the ENM_CHANGE flag ORed into the mask.
  315. CString authcode;
  316. GetDlgItemText(IDC_EDIT1, authcode);
  317. authcode.TrimLeft ();
  318. authcode.TrimRight ();
  319. authcode.Replace ("\n", "");
  320. authcode.Replace ("\r", "");
  321. SetDlgItemText(IDC_EDIT1, authcode);
  322. // TODO: Add your control notification handler code here
  323. }