InputAuthDlg.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. long d[8];double f[8];
  53. long idtemp=123456;
  54. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  55. //运行自定义函数
  56. SoftKey ytSoftKey;
  57. int ret=ytSoftKey.Ini();
  58. if (ret!=0 )
  59. {
  60. AfxMessageBox("没有找到加密狗");
  61. return false;
  62. }
  63. ret=ytSoftKey.timedog1(&m_id,&idtemp,&m_time1,&m_time2,&d[4],&d[5],&d[6],&d[7],
  64. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  65. s0,s1,s2,s3,s4,s5,s6,s7);
  66. if(ret!=0 && ret!=-43)
  67. {
  68. TCHAR ErrInfo[260]="";
  69. ytSoftKey.GetErrInfo(ret,ErrInfo);
  70. CString msg="出错了:";msg=msg+ErrInfo;
  71. AfxMessageBox((msg));
  72. exit(-1);
  73. }
  74. CString str="";
  75. CString temp,temp2;
  76. /////////////////////////////////////////
  77. temp.Format ("%d", abs(m_id));
  78. int leng=temp.GetLength ();
  79. if(m_id<0)
  80. temp2="1";
  81. else
  82. temp2="0";
  83. temp=temp2+temp;
  84. temp2.Format ("%02d", leng);
  85. temp=temp2+temp;
  86. str+=temp;
  87. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  88. temp.Format ("%d", abs(m_time1));
  89. leng=temp.GetLength ();
  90. if(m_time1<0)
  91. temp2="1";
  92. else
  93. temp2="0";
  94. temp=temp2+temp;
  95. temp2.Format ("%02d", leng);
  96. temp=temp2+temp;
  97. str+=temp;
  98. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  99. temp.Format ("%d", abs(m_time2));
  100. leng=temp.GetLength ();
  101. if(m_time2<0)
  102. temp2="1";
  103. else
  104. temp2="0";
  105. temp=temp2+temp;
  106. temp2.Format ("%02d", leng);
  107. temp=temp2+temp;
  108. str+=temp;
  109. //////////////////////////////////两位长度, 1为负, 0为正, 数据区
  110. temp.Format ("%d", abs(idtemp));
  111. leng=temp.GetLength ();
  112. if(idtemp<0)
  113. temp2="1";
  114. else
  115. temp2="0";
  116. temp=temp2+temp;
  117. temp2.Format ("%02d", leng);
  118. temp=temp2+temp;
  119. str+=temp;
  120. SetDlgItemText(IDC_EDIT1, str);
  121. #endif
  122. return TRUE; // return TRUE unless you set the focus to a control
  123. // EXCEPTION: OCX Property Pages should return FALSE
  124. }
  125. void InputAuthDlg::OnOK()
  126. {
  127. #ifdef TIMEDOG_VERSION//时钟狗
  128. // TODO: Add extra validation here
  129. CString authcode;
  130. GetDlgItemText(IDC_EDIT2, authcode);
  131. authcode.TrimLeft ();
  132. authcode.TrimRight ();
  133. authcode.Replace ("\n", "");
  134. authcode.Replace ("\r", "");
  135. if(authcode.GetLength ()!=240)
  136. {
  137. #ifdef BESTGIFT
  138. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  139. #else
  140. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  141. #endif
  142. return;
  143. }
  144. TCHAR DevicePath[ 260];
  145. if(FindPort(0,DevicePath)!=0)
  146. exit(1);
  147. DWORD OutID;
  148. int version;
  149. GetIDVersion(&OutID, &version, DevicePath);
  150. CString str1,str2,str3,str4,str5;
  151. str1=authcode.Mid (0, 48);
  152. str2=authcode.Mid (48, 48);
  153. str3=authcode.Mid (96, 48);
  154. str4=authcode.Mid (144, 48);
  155. str5=authcode.Mid (192, 48);
  156. SoftKey ytSoftKey;
  157. int ret=ytSoftKey.Ini();
  158. if (ret!=0 )
  159. {
  160. AfxMessageBox( "没有找到加密狗");
  161. return ;
  162. }
  163. long d[8];double f[8];
  164. char s0[50]="",s1[50]="",s2[50]="",s3[50]="",s4[50]="",s5[50]="",s6[50]="",s7[50]="";
  165. //运行自定义函数
  166. sprintf(s0, "%s", str1);
  167. sprintf(s1, "%s", str2);
  168. sprintf(s2, "%s", str3);
  169. sprintf(s3, "%s", str4);
  170. sprintf(s4, "%s", str5);
  171. //运行自定义函数
  172. ret=ytSoftKey.timedog2(&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7],
  173. &f[0],&f[1],&f[2],&f[3],&f[4],&f[5],&f[6],&f[7],
  174. s0,s1,s2,s3,s4,s5,s6,s7);
  175. if(ret!=0 && ret!=-43)
  176. {
  177. TCHAR ErrInfo[260]="";
  178. ytSoftKey.GetErrInfo(ret,ErrInfo);
  179. CString msg="出错了:";msg=msg+ErrInfo;
  180. AfxMessageBox((msg));
  181. exit(-1);
  182. }
  183. str1=s0;
  184. str2=s1;
  185. str3=s2;
  186. str4=s3;
  187. str5=s4;
  188. authcode=str1;
  189. authcode+=str2;
  190. authcode+=str3;
  191. authcode+=str4;
  192. authcode+=str5;
  193. str1+=str2;
  194. str3+=str4;
  195. DWORD id=atoi(str5.Right (8));
  196. str5=str5.Left (12);
  197. if(id!=OutID)
  198. {
  199. #ifdef BESTGIFT
  200. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  201. #else
  202. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  203. #endif
  204. return;
  205. }
  206. TCHAR HKey[20]="ffffffff",LKey[20]="ffffffff";
  207. TCHAR WHKey[41]="0",WLKey[41]="0";
  208. TCHAR year[10],month[10],day[10],hour[10],minute[10],second[10];
  209. sprintf(WHKey, "%s", str1);
  210. sprintf(WLKey, "%s", str3);
  211. CString temp;
  212. temp=str5.Left (4);
  213. str5=str5.Right (8);
  214. sprintf(year, "%s", temp);
  215. temp=str5.Left (2);
  216. str5=str5.Right (6);
  217. sprintf(month, "%s", temp);
  218. temp=str5.Left (2);
  219. str5=str5.Right (4);
  220. sprintf(day, "%s", temp);
  221. temp=str5.Left (2);
  222. str5=str5.Right (2);
  223. sprintf(hour, "%s", temp);
  224. sprintf(minute, "%s", str5);
  225. sprintf(second, "%s", "0");
  226. ret=WriteTimeAuthToEprom(30128, HKey, LKey, WHKey, WLKey, id,year,month,day,hour,minute,DevicePath);
  227. if(ret==0)
  228. {
  229. TCHAR year2[10],month2[10],day2[10],hour2[10],minute2[10],second2[10];
  230. GetRunTimer(year2, month2, day2, hour2, minute2, second2, DevicePath);
  231. DWORD time1,time2;
  232. time1=ConvertStringToTimerReal(year, month, day, hour, minute, second);
  233. sprintf(second2, "%s", "0");
  234. time2=ConvertStringToTimerReal(year2, month2, day2, hour2, minute2, second2);
  235. if(time1>time2)
  236. ConvertTimerToStringReal(time1-time2, year, month, day, hour, minute, second);
  237. else
  238. {
  239. sprintf(year, "%s", "0");
  240. sprintf(month, "%s", "0");
  241. sprintf(day, "%s", "0");
  242. sprintf(hour, "%s", "0");
  243. sprintf(minute, "%s", "0");
  244. }
  245. str1.Format ("授权成功! 您的加密锁还可以运行 %d 年 %d 月 %d 日 %d 小时 %d 分", atoi(year), atoi(month), atoi(day), atoi(hour), atoi(minute));
  246. AfxMessageBox((str1));
  247. SetDlgItemText(IDC_EDIT3, year);
  248. SetDlgItemText(IDC_EDIT4, month);
  249. SetDlgItemText(IDC_EDIT5, day);
  250. SetDlgItemText(IDC_EDIT6, hour);
  251. SetDlgItemText(IDC_EDIT7, minute);
  252. }
  253. else
  254. {
  255. #ifdef BESTGIFT
  256. AfxMessageBox(("授权申请码错误, 请重新向礼品王索取!"));
  257. #else
  258. AfxMessageBox(("授权申请码错误, 请重新向经销商索取!"));
  259. #endif
  260. return;
  261. }
  262. #endif
  263. CDialog::OnOK();
  264. }
  265. void InputAuthDlg::OnChangeEdit2()
  266. {
  267. // TODO: If this is a RICHEDIT control, the control will not
  268. // send this notification unless you override the CDialog::OnInitDialog()
  269. // function and call CRichEditCtrl().SetEventMask()
  270. // with the ENM_CHANGE flag ORed into the mask.
  271. CString authcode;
  272. GetDlgItemText(IDC_EDIT2, authcode);
  273. authcode.TrimLeft ();
  274. authcode.TrimRight ();
  275. authcode.Replace ("\n", "");
  276. authcode.Replace ("\r", "");
  277. SetDlgItemText(IDC_EDIT2, authcode);
  278. // TODO: Add your control notification handler code here
  279. }
  280. void InputAuthDlg::OnChangeEdit1()
  281. {
  282. // TODO: If this is a RICHEDIT control, the control will not
  283. // send this notification unless you override the CDialog::OnInitDialog()
  284. // function and call CRichEditCtrl().SetEventMask()
  285. // with the ENM_CHANGE flag ORed into the mask.
  286. CString authcode;
  287. GetDlgItemText(IDC_EDIT1, authcode);
  288. authcode.TrimLeft ();
  289. authcode.TrimRight ();
  290. authcode.Replace ("\n", "");
  291. authcode.Replace ("\r", "");
  292. SetDlgItemText(IDC_EDIT1, authcode);
  293. // TODO: Add your control notification handler code here
  294. }