Heng.c
上传用户:bjghjy
上传日期:2007-01-07
资源大小:379k
文件大小:50k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include <windows.h>
  2. #include <windowsx.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <io.h>                 
  7. #include <sysstat.h>   
  8. #include <fcntl.h>              
  9. #include <time.h>
  10. //#include "dbf_data.h"
  11. #include "sv_jy.h"
  12. #include "jydest.h"
  13. #include "rsa.h"
  14. #define __SERVER_CCR
  15. #include "heng.h"
  16. #define MAX_PATH_LEN 128
  17. #define START_REC_NO 94
  18. //DBF_DATA CommFile;
  19. typedef struct  tag_ANSFILE
  20. {
  21. HANDLE hf[MAX_ZQS_COUNT];
  22. int recnum[MAX_ZQS_COUNT];
  23. char path[MAX_ZQS_COUNT][MAX_PATH_LEN];
  24. }ANSFILE;
  25. ANSFILE AnsFile;
  26. typedef struct  tag_REQFILE
  27. {
  28. HANDLE hf[MAX_ZQS_COUNT];
  29. int recnum[MAX_ZQS_COUNT];
  30. int currec[MAX_ZQS_COUNT];
  31. }REQFILE;
  32. REQFILE ReqFile;
  33. int ZqsCount;
  34. //char * CommBuffer;
  35. short rlen,hlen;
  36. char RetFilePath[80];
  37. BOOL fUseJy =FALSE,fTestJy=FALSE,fRsa=FALSE;
  38. int Thrd_SendJycx(int sd, int reqType, void *lpBuf, int);
  39. extern int sdJy;
  40. extern BOOL GetInitString(LPSTR, LPSTR, LPSTR);
  41. extern BOOL PutInitString(LPSTR, LPSTR, LPSTR);
  42. extern BOOL ErrMsg(HWND, LPSTR);
  43. //extern int UDP_SendBuff(LPSTR, int, LPSTR, int, LPDEST_INFO );
  44. #define WriteRecord WriteDatRec
  45. int WriteDatRec(HANDLE hd,int no,short hlen,short rlen,char  *rbuff)
  46. {
  47. DWORD bytes;
  48. int i=0;
  49. SetFilePointer(hd,(long)(hlen + rlen*(START_REC_NO +no -1)),NULL,FILE_BEGIN);
  50. do
  51. {
  52. if(LockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0))
  53. break;
  54. else
  55. Sleep(RETRY_DELAY +RETRY_DELAY/2);
  56. }while(i<LOCK_RETRY_TIMES);
  57. if(i>=LOCK_RETRY_TIMES)
  58. return -1;
  59. if(WriteFile(hd,rbuff,rlen,&bytes,NULL))
  60. {
  61. if(bytes!=(DWORD)rlen)
  62. {
  63. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  64. return -1;
  65. }
  66. }
  67. else
  68. {
  69. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  70. return -1;
  71. }
  72. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  73. return 0;
  74. }
  75. #define  ReadRecord   ReadDatRec
  76. int ReadDatRec(HANDLE hd,int no,short hlen,short rlen,char *rbuff)
  77. {
  78. DWORD bytes;
  79. int i=0;
  80. SetFilePointer(hd,(long)(hlen + rlen*(START_REC_NO+no -1)),NULL,FILE_BEGIN);
  81. do
  82. {
  83. if(LockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0))
  84. break;
  85. else
  86. Sleep(RETRY_DELAY +RETRY_DELAY/2);
  87. }while(i<LOCK_RETRY_TIMES);
  88. if(i>=LOCK_RETRY_TIMES)
  89. return -1;
  90. if(ReadFile(hd,rbuff,rlen,&bytes,NULL))
  91. {
  92. if(bytes!=(DWORD)rlen)
  93. {
  94. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  95. return -1;
  96. }
  97. }
  98. else
  99. {
  100. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  101. return -1;
  102. }
  103. UnlockFile(hd,(DWORD)(hlen + rlen*(START_REC_NO +no -1)),0,rlen,0);
  104. return 0;
  105. }
  106. int JyInit(void)
  107. {       
  108. int i,j;
  109.     char tmp[256], temp[256],temp1[256];
  110. char * prt;
  111. REQUEST_BUFFER ReqBuf;
  112. ANSWER Answer;
  113. DWORD bytes;
  114. memset(&ReqFile,0,sizeof(REQFILE));
  115. memset(&AnsFile,0,sizeof(ANSFILE));
  116. memset(&ReqBuf,0,sizeof(REQUEST_BUFFER));
  117. memset(&Answer,0,sizeof(ANSWER));
  118. if(GetInitString("JY", "RUN", tmp))
  119. {
  120. if(tmp[0] =='N' || tmp[0] =='n')
  121. {
  122. fUseJy =FALSE;
  123. return 0;
  124. }
  125. else
  126. fUseJy =TRUE;
  127. }
  128. if(GetInitString("JY", "TEST", tmp))
  129. {
  130. if(tmp[0] =='Y' || tmp[0] =='y')
  131. fTestJy =TRUE;
  132. else
  133. fTestJy =FALSE;
  134. }
  135. else fTestJy =FALSE;
  136.          
  137. if(GetInitString("JY", "RSA", tmp))
  138. {
  139. if(tmp[0] =='Y' || tmp[0] =='y')
  140. {
  141. fRsa =TRUE;
  142. if(!ReadRsaFile(R,PK,SK))
  143. ErrMsg(NULL,"读RSA加密参数失败,请在系统启动后按[Init]");
  144. }
  145. }
  146. ZqsCount=0;
  147. for(i=0;i<MAX_ZQS_COUNT;i++)
  148. {
  149. wsprintf(temp,"%s%d","COMMFILE",i);
  150. if(!GetInitString("JY", temp, tmp))
  151. {
  152. if(ZqsCount==0)
  153. {
  154. wsprintf(temp, "不能发现配置%s:n %s",
  155. (LPSTR)"COMMFILE", (LPSTR)tmp);
  156. ErrMsg(NULL, temp);
  157. }
  158. break;
  159. }
  160. else
  161. {
  162. ZqsCount++;
  163. prt=strstr(tmp,";");
  164. if(prt==NULL) 
  165. {
  166. ErrMsg(NULL,"format Reqfile;AnsFile");
  167. return -1;
  168. }
  169. else *prt=0;
  170. strcpy(temp1,tmp);
  171. if(access(temp1,0)!=0)
  172. {
  173. ReqFile.hf[i]=CreateFile(temp1,GENERIC_READ|GENERIC_WRITE,
  174. FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  175. if(ReqFile.hf[i] ==INVALID_HANDLE_VALUE)
  176. {
  177. ErrMsg(NULL, "can not create comm file!");
  178. return -1;
  179. }
  180. for(j=0;j<REQUESTLEN;j++)
  181. {
  182. if(WriteFile(ReqFile.hf[i],&ReqBuf,sizeof(REQUEST_BUFFER),&bytes,NULL))
  183. {
  184. if(bytes!=sizeof(REQUEST_BUFFER))
  185. {
  186. CloseHandle(ReqFile.hf[i]);
  187. return -1;
  188. }
  189. }
  190. else
  191. {
  192. CloseHandle(ReqFile.hf[i]);
  193. return -1;
  194. }
  195. }
  196. }
  197. else
  198. {
  199. if(access(temp1,_S_IREAD|_S_IWRITE) <0)
  200. {
  201. wsprintf(temp, "不能存取%s:n %s",
  202. (LPSTR)"COMMFILE", (LPSTR)temp1);
  203. ErrMsg(NULL, temp);
  204. return -1;
  205. }  
  206. ReqFile.hf[i]=CreateFile(temp1,GENERIC_READ|GENERIC_WRITE,
  207. FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  208. if(ReqFile.hf[i] ==INVALID_HANDLE_VALUE)
  209. {
  210. ErrMsg(NULL, "can not create comm file!");
  211. return -1;
  212. }
  213.                 }
  214. //ReqFile.hf[i]=OpenDbfBase(temp1,O_RDWR);
  215. // if(i==0)
  216. // CommFile.hf=ReqFile.hf[0];
  217. //if (ReqFile.hf[i]==-1)
  218. //{
  219. // wsprintf(temp, "不能打开%s:n %s",
  220. // (LPSTR)"COMMFILE", (LPSTR)temp1);
  221. // ErrMsg(NULL, temp);
  222. // return -1;
  223. //} 
  224. if(i==0)
  225. {
  226. // if (InitBase(CommFile.hf,&CommFile.dbfStruct,
  227. // &CommFile.fldStruct,&CommFile.fldCount)
  228. // !=SUCCEED) 
  229. // {
  230. // wsprintf(temp, "不能处始化%s:n %s",
  231. // (LPSTR)"COMMFILE", (LPSTR)temp1);
  232. // ErrMsg(NULL, temp);
  233. // return -1;
  234. // }
  235. rlen= sizeof(REQUEST_BUFFER);
  236. hlen= 0;
  237. }
  238. //ReqFile.recnum[i]= REQUESTLEN;
  239. strcpy(temp1,++prt);
  240. if(access(temp1,0)!=0)
  241. {
  242. AnsFile.hf[i]=CreateFile(temp1,GENERIC_READ|GENERIC_WRITE,
  243. FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  244. if(ReqFile.hf[i] ==INVALID_HANDLE_VALUE)
  245. {
  246. ErrMsg(NULL, "can not create comm ans file!");
  247. return -1;
  248. }
  249. for(j=0;j<ANSWERLEN;j++)
  250. {
  251. if(WriteFile(AnsFile.hf[i],&Answer,sizeof(ANSWER),&bytes,NULL))
  252. {
  253. if(bytes!=sizeof(ANSWER))
  254. {
  255. CloseHandle(ReqFile.hf[i]);
  256. CloseHandle(AnsFile.hf[i]);
  257. return -1;
  258. }
  259. }
  260. else
  261. {
  262. CloseHandle(AnsFile.hf[i]);
  263. return -1;
  264. }
  265. }
  266. }
  267. else
  268. {
  269. if(access(temp1,_S_IREAD|_S_IWRITE) <0)
  270. {
  271. wsprintf(temp, "不能存取%s:n %s",
  272. (LPSTR)"COMMFILE", (LPSTR)temp1);
  273. ErrMsg(NULL, temp);
  274. return -1;
  275. }  
  276. AnsFile.hf[i]=CreateFile(temp1,GENERIC_READ|GENERIC_WRITE,
  277. FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  278. if(AnsFile.hf[i] ==INVALID_HANDLE_VALUE)
  279. {
  280. ErrMsg(NULL, "can not create comm ans file!");
  281. return -1;
  282. }
  283.                 }
  284. //AnsFile.hf[i]=OpenDbfBase(temp1,O_RDWR);
  285. //if (ReqFile.hf[i]==-1)
  286. //{
  287. // wsprintf(temp, "不能打开%s:n %s",
  288. // (LPSTR)"COMMFILE", (LPSTR)temp1);
  289. // ErrMsg(NULL, temp);
  290. // return -1;
  291. //} 
  292. prt =strrchr(temp1,'\');
  293. ++prt; *prt =0;
  294. strcpy(&AnsFile.path[i][0],temp1);
  295. AnsFile.recnum[i]=ANSWERLEN;
  296. ReqFile.recnum[i]=REQUESTLEN;
  297. }
  298. }
  299. return 0;
  300. }
  301. int JyExit(void)
  302. {
  303. int i;
  304. for(i=0;i<ZqsCount;i++)
  305. {
  306. if(ReqFile.hf[i]!=INVALID_HANDLE_VALUE)
  307. CloseHandle(ReqFile.hf[i]);
  308. if(AnsFile.hf[i]!=INVALID_HANDLE_VALUE)
  309. CloseHandle(AnsFile.hf[i]);
  310. }
  311. return 0;
  312. }
  313. int Jy_Zqsxx(int sd)
  314. {
  315. int len;
  316. BYTE SendBuff[1024];
  317. strcpy(SendBuff, JY_ZQSXX_HEAD);
  318. len =strlen(JY_ZQSXX_HEAD);
  319. //memcpy(&SendBuff[len],&Zqsxx,sizeof(ZQSXX));
  320. //len+=sizeof(Zqsxx);
  321. memcpy(&SendBuff[len],R,DATALENGTH);
  322. len +=DATALENGTH;
  323. memcpy(&SendBuff[len],PK,DATALENGTH);
  324. len +=DATALENGTH;
  325. UDP_SendBuff("RSA.R.PK", sd, SendBuff, len,NULL);
  326. return 0;
  327. }
  328. void ClearAns(LPJY_DEST lpJyDest)
  329. {
  330. char* buff;
  331. buff =GlobalAllocPtr(GHND,rlen);
  332. if(buff !=NULL)
  333. {
  334. memset(buff,0,rlen);
  335. WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,buff);
  336. GlobalFreePtr(buff);
  337. }
  338. }
  339. void ClearReq(LPJY_DEST lpJyDest)
  340. {
  341. char* buff;
  342. buff =GlobalAllocPtr(GHND,rlen);
  343. if(buff !=NULL)
  344. {
  345. memset(buff,0,rlen);
  346. buff[0] =0;
  347. WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,buff);
  348. GlobalFreePtr(buff);
  349. }
  350. }
  351. int Jy_ChkUsr(int sd, int jyNum, LPJY_ASK_CHKUSR AskChkUser)
  352. {
  353. int ret;
  354. LPJY_DEST lpJyDest;
  355. short Qsid;
  356. REQUEST_BUFFER ReqBuf;
  357. ANSWER Answer;
  358. if(ZqsCount ==1)
  359. Qsid =1;
  360. else
  361. Qsid =AskChkUser->zqsid;
  362. if(ReqFile.hf[Qsid -1] ==INVALID_HANDLE_VALUE)
  363. return ANS_SYS_ERR;
  364. ret =CheckJyDest(sd,REQ_CHKUSR, AskChkUser->jys,
  365. AskChkUser->gddm, -1, &lpJyDest);
  366. memset(&ReqBuf,0,rlen);
  367. memset(&Answer,0,sizeof(ANSWER));
  368. ReqBuf.command =3;
  369. ReqBuf.status ='01';
  370. strcpy(ReqBuf.request.r_inq_account.argment,AskChkUser->gddm);
  371. ReqBuf.request.r_inq_account.arg_type ='2';
  372. ReqBuf.request.r_inq_account.password =atoi(AskChkUser->jymm);
  373. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskChkUser->gddm);
  374. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  375. // =(AskChkUser->jys ==0)?'Z':'H';
  376. //StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],AskChkUser->jymm);      
  377. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CHKUSR;
  378. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  379. //wsprintf(temp,"%d",sd);
  380. //StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  381. //wsprintf(temp,"%d",jyNum);
  382. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  383. if(lpJyDest==NULL)
  384. lpJyDest=GetFirstIdelRec();
  385. if(lpJyDest==NULL)
  386. {
  387. ReqFile.currec[Qsid-1]++;
  388. if(ReqFile.currec[Qsid-1]>ReqFile.recnum[Qsid-1])
  389. {
  390. ErrMsg(NULL, "无空闲交易表项!");      
  391. return ANS_SYS_ERR;
  392. }
  393. lpJyDest=AddJyDest(sd, REQ_CHKUSR, AskChkUser->jys,
  394. ReqFile.currec[Qsid-1], AskChkUser->gddm, jyNum,Qsid-1);
  395. if(lpJyDest ==NULL)
  396. {
  397. ErrMsg(NULL, "不能加交易表项!");
  398. return ANS_SYS_ERR;
  399. }
  400. //ClearAns(lpJyDest);
  401. if(WriteRecord(ReqFile.hf[Qsid-1],lpJyDest->recNum,
  402. hlen,rlen,(char *)&ReqBuf) !=0)
  403. {
  404. ErrMsg(NULL, "不能写交换文件!");      
  405. return ANS_SYS_ERR;
  406. }
  407. }
  408. else
  409. {
  410. //ClearAns(lpJyDest);
  411. if(WriteRecord(ReqFile.hf[Qsid-1],lpJyDest->recNum,
  412. hlen,rlen,(char *)&ReqBuf)!=0)
  413. {
  414. ErrMsg(NULL, "不能写交换文件1!");      
  415. return ANS_SYS_ERR;
  416. }
  417. strcpy(lpJyDest->gddm,AskChkUser->gddm);
  418. ChangeJyDest(sd, lpJyDest, REQ_CHKUSR, AskChkUser->jys,
  419. Qsid -1,jyNum);
  420. }
  421. strcpy(lpJyDest->jymm,AskChkUser->jymm);
  422. if(fTestJy)
  423. {
  424. Sleep(1000);
  425. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  426. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  427. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  428. //wsprintf(temp,"%d",jyNum);
  429. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  430. strcpy(Answer.a_inq_account.status,"000");
  431. Answer.a_inq_account.fund_account=atoi(AskChkUser->gddm);
  432. WriteRecord(AnsFile.hf[Qsid-1],lpJyDest->recNum,
  433. 0,sizeof(ANSWER),(char *)&Answer);
  434. }
  435. return 0;
  436. }
  437. int Jy_ChgPwd(int sd, int jyNum, LPJY_ASK_CHGPWD AskChgPwd)
  438. {
  439. LPJY_DEST lpJyDest=NULL;
  440. int ret;
  441. REQUEST_BUFFER ReqBuf;
  442. ANSWER Answer;
  443. ret =CheckJyDest(sd, REQ_CHGPWD, AskChgPwd->jys, AskChgPwd->gddm,
  444. AskChgPwd->userId, &lpJyDest);
  445. if(ret==-1)
  446. return ANS_SYS_ERR;
  447. if(ret==-2)
  448. return ANS_SUSP_REQ;
  449. if(ret==-3)
  450. return ANS_NO_PRIV;
  451. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  452. return ANS_SYS_ERR;
  453. memset(&ReqBuf,0,rlen);
  454. memset(&Answer,0,sizeof(ANSWER));
  455. ReqBuf.command =2;
  456. ReqBuf.status ='01';
  457. ReqBuf.request.r_chg_password.fund_account 
  458. =lpJyDest->jyzh;
  459. ReqBuf.request.r_chg_password.password =atoi(lpJyDest->jymm);
  460. ReqBuf.request.r_chg_password.password_new =atoi(AskChgPwd->xmm);
  461. //memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  462. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskChgPwd->gddm);
  463. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  464. // =(AskChgPwd->jys ==0)?'Z':'H';
  465. //StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],AskChgPwd->xmm);      
  466. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CHGPWD;
  467. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  468. //wsprintf(temp,"%d",sd);
  469. //StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  470. //wsprintf(temp,"%d",jyNum);
  471. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  472. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,(char *)&ReqBuf)!=0)
  473. {
  474. ErrMsg(NULL, "不能写交换文件!");
  475. return ANS_SYS_ERR;
  476. }
  477. ChangeJyDest(sd, lpJyDest, REQ_CHGPWD, AskChgPwd->jys, -1, jyNum);
  478. if(fTestJy)
  479. {
  480. Sleep(1000);
  481. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  482. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  483. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  484. //wsprintf(temp,"%d",jyNum);
  485. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  486. WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  487. 0,sizeof(ANSWER),(char *)&Answer);
  488. }
  489. return 0;
  490. }
  491. int Jy_BuySell(int sd, int jyNum, LPJY_ASK_BUYSELL AskBuySell)
  492. {
  493. LPJY_DEST lpJyDest;
  494. int ret;
  495. REQUEST_BUFFER ReqBuf;
  496. ANSWER Answer;
  497. ret =CheckJyDest(sd, REQ_BUYSEL, AskBuySell->jys, AskBuySell->gddm,
  498. AskBuySell->userId, &lpJyDest);
  499. if(ret==-1)
  500. return ANS_SYS_ERR;
  501. if(ret==-2)
  502. return ANS_SUSP_REQ;
  503. if(ret==-3)
  504. return ANS_NO_PRIV;
  505. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  506. return ANS_SYS_ERR;
  507. memset(&ReqBuf,0,rlen);
  508. ReqBuf.command =5;
  509. ReqBuf.status ='01';
  510. ReqBuf.request.r_ent_enter.exchange_type =
  511. (AskBuySell->jys ==0)?'2':'1';
  512. if(AskBuySell->jys ==0)
  513. strcpy(ReqBuf.request.r_ent_enter.stock_account,
  514. AskBuySell->gddm);
  515. else
  516. sprintf(ReqBuf.request.r_ent_enter.stock_account,
  517. "A%s",AskBuySell->gddm);
  518. ReqBuf.request.r_ent_enter.password =
  519. atol(lpJyDest->jymm);
  520. ReqBuf.request.r_ent_enter.entrust_bs =
  521. (AskBuySell->bs =='B')?'1':'2';
  522. strcpy(ReqBuf.request.r_ent_enter.stock_code,
  523. AskBuySell->gpdm);
  524. ReqBuf.request.r_ent_enter.entrust_price=
  525. (float)AskBuySell->wtjg/(float)100.00;
  526. ReqBuf.request.r_ent_enter.entrust_amount=
  527. AskBuySell->wtgs;
  528. ReqBuf.request.r_ent_enter.entrust_type='0';
  529. //memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  530. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskBuySell->gddm);
  531. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  532. // =(AskBuySell->jys ==0)?'Z':'H';                         
  533. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],AskBuySell->gpdm);
  534. //sprintf(temp,"%12ld",AskBuySell->wtgs);
  535. //StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);            
  536. //sprintf(temp,"%12.2f",(double)(AskBuySell->wtjg/100.00));
  537. //StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  538. //if(AskBuySell->bs =='B')
  539. // CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_BUY;
  540. //else if(AskBuySell->bs =='S')
  541. // CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_SELL;
  542. //else
  543. // CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]='E';
  544. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  545.   //wsprintf(temp,"%d",sd);
  546. //StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  547. //wsprintf(temp,"%d",jyNum);
  548. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  549. //ClearAns(lpJyDest);
  550. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,(char *)&ReqBuf)!=0)
  551. {
  552. ErrMsg(NULL, "不能写交换文件!");      
  553. return ANS_SYS_ERR;
  554. }
  555. if(ChangeJyDest(sd, lpJyDest, REQ_BUYSEL, AskBuySell->jys, -1, jyNum)<0)
  556. return ANS_SYS_ERR;
  557. if(fTestJy)
  558. {
  559. Sleep(1000);
  560. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  561. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  562. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  563. //StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],"000068");
  564. //wsprintf(temp,"%d",jyNum);
  565. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  566.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  567. 0,sizeof(ANSWER),(char *)&Answer);
  568. }
  569. return 0;
  570. }
  571. int Jy_Cancel(int sd, int jyNum, LPJY_ASK_CANCEL AskCancel)
  572. {
  573. LPJY_DEST lpJyDest;
  574. int ret;
  575. REQUEST_BUFFER ReqBuf;
  576. ANSWER Answer;
  577. ret =CheckJyDest(sd, REQ_CANCEL, AskCancel->jys, 
  578. AskCancel->gddm, AskCancel->userId, &lpJyDest);
  579. if(ret==-1)
  580. return ANS_SYS_ERR;
  581. if(ret==-2)
  582. return ANS_SUSP_REQ;
  583. if(ret==-3)
  584. return ANS_NO_PRIV;
  585. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  586. return ANS_SYS_ERR;
  587. memset(&ReqBuf,0,rlen);
  588. memset(&Answer,0,sizeof(ANSWER));
  589. ReqBuf.command =6;
  590. ReqBuf.status ='01';
  591. ReqBuf.request.r_ent_cancel.fund_account=
  592. lpJyDest->jyzh;
  593. ReqBuf.request.r_ent_cancel.password =
  594. atoi(lpJyDest->jymm);
  595. ReqBuf.request.r_ent_cancel.entrust_serial_no =
  596. atoi(AskCancel->Cancel[0].hthm);
  597. /*
  598. for(i=0;i<AskCancel->cancelCount;i++)
  599. {
  600. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  601. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCancel->gddm);
  602. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCancel->Cancel[i].hthm);          
  603. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  604. =(AskCancel->jys ==0)?'Z':'H';                      
  605. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CANCEL;
  606. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  607.   wsprintf(temp,"%d",sd);
  608. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  609. wsprintf(temp,"%d",jyNum);
  610. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  611. ClearAns(lpJyDest);
  612. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  613. CommBuffer)!=0)
  614. {
  615. ErrMsg(NULL, "不能写交换文件!");      
  616. return ANS_SYS_ERR;
  617. }
  618. }
  619. */
  620. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  621. (char *)&ReqBuf)!=0)
  622. {
  623. ErrMsg(NULL, "不能写交换文件!");      
  624. return ANS_SYS_ERR;
  625. }
  626. ChangeJyDest(sd, lpJyDest, REQ_CANCEL, AskCancel->jys, -1, jyNum);
  627. lpJyDest->recCount =1; //;AskCancel->cancelCount;
  628. if(fTestJy)
  629. {
  630. Sleep(1000);
  631. /*
  632. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  633. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  634. wsprintf(temp,"%d",AskCancel->cancelCount);
  635. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],temp);
  636. wsprintf(temp,"%d",jyNum);
  637. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  638.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  639. CommBuffer);
  640. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  641. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  642. if(hFile ==HFILE_ERROR)
  643. return ANS_SYS_ERR;
  644. for(i=0;i<AskCancel->cancelCount;i++)
  645. {
  646. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  647. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCancel->gddm);
  648. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCancel->Cancel[i].hthm);          
  649. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  650. =(AskCancel->jys ==0)?'Z':'H';                      
  651. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CANCEL;
  652. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  653. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  654.   wsprintf(temp,"%d",sd);
  655. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  656. wsprintf(temp,"%d",jyNum);
  657. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  658. _lwrite(hFile,&CommBuffer[1], rlen-1);
  659. _lwrite(hFile,"rn",2);
  660. }
  661. _lclose(hFile);
  662. */
  663. WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  664. 0,sizeof(ANSWER),(char *)&Answer);
  665. }
  666. return 0;
  667. }
  668. int Jy_Yecx(int sd, int jyNum, LPJY_ASK_YECX AskYecx)
  669. {
  670. LPJY_DEST lpJyDest;
  671. int ret,i=0;
  672. REQUEST_BUFFER ReqBuf;
  673. ANSWER Answer;
  674. ret =CheckJyDest(sd, REQ_YECX, AskYecx->jys, AskYecx->gddm,
  675. AskYecx->userId, &lpJyDest);
  676. if(ret==-1)
  677. return ANS_SYS_ERR;
  678. if(ret==-2)
  679. return ANS_SUSP_REQ;
  680. if(ret==-3)
  681. return ANS_NO_PRIV;
  682. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  683. return ANS_SYS_ERR;
  684. memset(&ReqBuf,0,rlen);
  685. memset(&Answer,0,sizeof(ANSWER));
  686. ReqBuf.command =10;
  687. ReqBuf.status ='01';
  688. ReqBuf.request.r_inq_stock.arg_type ='3';
  689. if(AskYecx->jys ==0)
  690. strcpy(ReqBuf.request.r_inq_stock.stock_account,
  691. AskYecx->gddm);
  692. else
  693. sprintf(ReqBuf.request.r_inq_stock.stock_account,
  694. "A%s",AskYecx->gddm);
  695. strcpy(ReqBuf.request.r_inq_stock.stock_code,"");
  696. ReqBuf.request.r_inq_stock.exchange_type =
  697. (AskYecx->jys ==0)?'2':'1';
  698. ReqBuf.request.r_inq_stock.inquire_mode = '1';
  699. //memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  700. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskYecx->gddm);
  701. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  702. // =(AskYecx->jys ==0)?'Z':'H';                        
  703. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],AskYecx->gpdm);      
  704. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_YECX;
  705. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  706.   //wsprintf(temp,"%d",sd);
  707. //StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  708. //wsprintf(temp,"%d",jyNum);
  709. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  710. //ClearAns(lpJyDest);
  711.     //wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  712.     //remove(temp);
  713. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  714. (char *)&ReqBuf)!=0)
  715. {
  716. ErrMsg(NULL, "不能写交换文件!");
  717. return ANS_SYS_ERR;
  718. }
  719. if(ChangeJyDest(sd, lpJyDest, REQ_YECX, AskYecx->jys, -1, jyNum) <0)
  720. return ANS_SYS_ERR;
  721. if(fTestJy)
  722. {
  723. Sleep(1000);
  724. /*
  725. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  726. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  727. if(hFile ==HFILE_ERROR)
  728. return 0;
  729. for(i=0;i<22;i++)
  730. {
  731. memset(CommBuffer,0,sizeof(CommBuffer));
  732. wsprintf(temp,"%04d",i+1);
  733. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  734. wsprintf(temp,"%8d",(i+1)*10);
  735. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);      
  736. wsprintf(temp,"%8d",(i+1)*20);
  737. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  738. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  739. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  740. _lwrite(hFile,&CommBuffer[1], rlen-1);
  741. _lwrite(hFile,"rn",2);
  742. }
  743. _lclose(hFile);
  744. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  745. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  746. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  747. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],"9000000.12");
  748. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],"2000000.99");
  749. wsprintf(temp,"%d",jyNum);
  750. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  751. */
  752.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  753. 0,sizeof(ANSWER),(char *)&Answer);
  754. }
  755. return 0;
  756. }
  757. int Jy_Cjcx(int sd, int jyNum, LPJY_ASK_CJCX AskCjcx)
  758. {
  759. LPJY_DEST lpJyDest;
  760. int ret,i=0;
  761. REQUEST_BUFFER ReqBuf;
  762. ANSWER Answer;
  763. ret =CheckJyDest(sd, REQ_CJCX, AskCjcx->jys, AskCjcx->gddm, AskCjcx->userId, &lpJyDest);
  764. if(ret==-1)
  765. return ANS_SYS_ERR;
  766. if(ret==-2)
  767. return ANS_SUSP_REQ;
  768. if(ret==-3)
  769. return ANS_NO_PRIV;
  770. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  771. return ANS_SYS_ERR;
  772. memset(&ReqBuf,0,rlen);
  773. memset(&Answer,0,sizeof(ANSWER));
  774. ReqBuf.command =9;
  775. ReqBuf.status ='01';
  776. ReqBuf.request.r_inq_real.arg_type ='3';
  777. if(AskCjcx->jys ==0)
  778. strcpy(ReqBuf.request.r_inq_real.stock_account,
  779. AskCjcx->gddm);
  780. else
  781. sprintf(ReqBuf.request.r_inq_real.stock_account,
  782. "A%s",AskCjcx->gddm);
  783. ReqBuf.request.r_inq_real.exchange_type =
  784. (AskCjcx->jys ==0)?'2':'1';
  785. //memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  786. //StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCjcx->gddm);
  787. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  788. // =(AskCjcx->jys ==0)?'Z':'H';                        
  789. //StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],AskCjcx->cjrq);      
  790. //StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCjcx->hthm);      
  791. //CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CJCX;
  792. //CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  793.   //wsprintf(temp,"%d",sd);
  794. //StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  795. //wsprintf(temp,"%d",jyNum);
  796. //StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  797. //ClearAns(lpJyDest);
  798.     //wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  799.     //remove(temp);
  800. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  801. (char *)&ReqBuf)!=0)
  802. {
  803. ErrMsg(NULL, "不能写交换文件!");
  804. return ANS_SYS_ERR;
  805. }
  806. if(ChangeJyDest(sd, lpJyDest, REQ_CJCX, AskCjcx->jys, -1, jyNum) <0)
  807. {
  808. ErrMsg(NULL,"来自Jy_Cjcx:ChangeJyDest");
  809. return ANS_SYS_ERR;
  810. }
  811. if(fTestJy)
  812. {
  813. Sleep(1000);
  814. /*
  815. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  816. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  817. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  818. wsprintf(temp,"%d",jyNum);
  819. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  820.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  821. CommBuffer);
  822. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  823. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  824. if(hFile ==HFILE_ERROR)
  825. return ANS_SYS_ERR;
  826. for(i=0;i<22;i++)
  827. {
  828. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=i-(int)(i/2)*2==0 ?'B':'S';
  829. wsprintf(temp,"%04d",i+1);
  830. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  831. wsprintf(temp,"%8d",(i+1)*100);
  832. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);      
  833. wsprintf(temp,"%8d",i+10);
  834. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  835. wsprintf(temp,"%06d",i+100);
  836. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],temp);      
  837. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  838. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  839. _lwrite(hFile,&CommBuffer[1], rlen-1);
  840. _lwrite(hFile,"rn",2);
  841. }
  842. _lclose(hFile);
  843. */
  844.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  845. 0,sizeof(ANSWER),(char *)&Answer);
  846. }
  847. return 0;
  848. }
  849. int Jy_Wtcx(int sd, int jyNum, LPJY_ASK_WTCX AskWtcx)
  850. {
  851. LPJY_DEST lpJyDest;
  852. int ret,i=0;
  853. REQUEST_BUFFER ReqBuf;
  854. ANSWER Answer;
  855. ret =CheckJyDest(sd, REQ_WTCX, AskWtcx->jys, AskWtcx->gddm,
  856. AskWtcx->userId, &lpJyDest);
  857. if(ret==-1)
  858. return ANS_SYS_ERR;
  859. if(ret==-2)
  860. return ANS_SUSP_REQ;
  861. if(ret==-3)
  862. return ANS_NO_PRIV;
  863. if(ReqFile.hf[lpJyDest->zqsid] ==INVALID_HANDLE_VALUE)
  864. return ANS_SYS_ERR;
  865. memset(&ReqBuf,0,rlen);
  866. memset(&Answer,0,sizeof(ANSWER));
  867. ReqBuf.command =8;
  868. ReqBuf.status ='01';
  869. ReqBuf.request.r_inq_entrust.arg_type ='3';
  870. if(AskWtcx->jys ==0)
  871. strcpy(ReqBuf.request.r_inq_entrust.stock_account,
  872. AskWtcx->gddm);
  873. else
  874. sprintf(ReqBuf.request.r_inq_entrust.stock_account,
  875. "A%s",AskWtcx->gddm);
  876. ReqBuf.request.r_inq_real.exchange_type =
  877. (AskWtcx->jys ==0)?'2':'1';
  878. ReqBuf.request.r_inq_entrust.inquire_mode ='1';
  879. // memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  880. // StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskWtcx->gddm);
  881. // CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  882. // =(AskWtcx->jys ==0)?'Z':'H';                        
  883. // StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],AskWtcx->wtrq);      
  884. // StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskWtcx->hthm);      
  885. // CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_WTCX;
  886. // CommBuffer[*(short*)(CommFile.fldStruct[fld_JYMM].offset)]=AskWtcx->cdcx;
  887. // CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  888. // wsprintf(temp,"%d",sd);
  889. // StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  890. // wsprintf(temp,"%d",jyNum);
  891. // StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  892. // ClearAns(lpJyDest);
  893. //    wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  894. //    remove(temp);
  895. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  896. (char *)&ReqBuf)!=0)
  897. {
  898. ErrMsg(NULL, "不能写交换文件!");
  899. return ANS_SYS_ERR;
  900. }
  901. if(ChangeJyDest(sd, lpJyDest, REQ_WTCX, AskWtcx->jys, -1, jyNum) <0)
  902. return ANS_SYS_ERR;
  903. if(fTestJy)
  904. {
  905. Sleep(1000);
  906. /*
  907. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  908. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  909. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  910. wsprintf(temp,"%d",jyNum);
  911. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  912.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  913. rlen,CommBuffer);
  914. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  915. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  916. if(hFile ==HFILE_ERROR)
  917. return ANS_SYS_ERR;
  918. for(i=0;i<22;i++)
  919. {
  920. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=i-(int)(i/2)*2==0 ?'B':'S';
  921. wsprintf(temp,"%04d",i+1);
  922. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  923. wsprintf(temp,"%8d",(i+1)*100);
  924. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);
  925. wsprintf(temp,"%8d",i+10);
  926. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  927. wsprintf(temp,"%06d",i+100);
  928. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],temp);      
  929. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  930. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  931. _lwrite(hFile,&CommBuffer[1], rlen-1);
  932. _lwrite(hFile,"rn",2);
  933. }
  934. _lclose(hFile);
  935. */
  936.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  937. 0,sizeof(ANSWER),(char *)&Answer);
  938. }
  939. return 0;
  940. }
  941. int JyDest_ChkUsr(LPJY_DEST lpJyDest)
  942. {
  943. BYTE SendBuff[2048];
  944. int ret, len;
  945.     JY_ANS_CHKUSR AnsUser;
  946. //ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  947. // rlen,CommBuffer);
  948. //stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  949. //if(stat !=';') 
  950. // return 0;
  951. REQUEST_BUFFER ReqBuf;
  952. ANSWER Answer;
  953. memset(&ReqBuf,0,rlen);
  954. memset(&Answer,0,sizeof(ANSWER));
  955. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  956. hlen,rlen,(char *)&ReqBuf);
  957. if(ReqBuf.status !='02')
  958. return 0;
  959. if(ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  960. 0,sizeof(ANSWER),(char *)&Answer)!=0)
  961. ret =-1;
  962. else
  963. {
  964. //if(strncmp(Answer.a_inq_account.status,"000",3) ==0)
  965. ret =ReqBuf.error;
  966. if(ret>=0)
  967. {
  968. //ret =0;
  969. lpJyDest->jyzh =Answer.a_inq_account.fund_account;
  970. lpJyDest->zjye =Answer.a_inq_account.current_balance;
  971. lpJyDest->kyje =Answer.a_inq_account.enable_balance;
  972. }
  973. }
  974. //FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  975. //if(lpJyDest->jyNum!=atoi(temp)) 
  976. // return 0;
  977. //ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  978. //if(ret==' ')
  979. // return 0;
  980. if(ret<0)
  981. {
  982. //ret =ANS_SYS_ERR;
  983. switch(ret)
  984. {
  985. case -51:
  986. ret ='1';
  987. break;
  988. case -52:
  989. ret ='6';
  990. break;
  991. default:
  992. ret ='1';
  993. }
  994. }
  995. else ret =ANS_SUCC;
  996. strcpy(SendBuff, JY_CHKUSR_HEAD);
  997. len =strlen(SendBuff);
  998. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  999. len +=sizeof(short);
  1000. AnsUser.jys=lpJyDest->curJys;
  1001.     AnsUser.userId=lpJyDest->userId;
  1002. strcpy(AnsUser.gddm,lpJyDest->gddm);
  1003. AnsUser.flag=(char)ret;
  1004. memcpy(&SendBuff[len],&AnsUser,sizeof(JY_ANS_CHKUSR));
  1005. len+=sizeof(AnsUser);
  1006. UDP_SendBuff("检查交易用户", lpJyDest->sd, SendBuff, len,NULL);  
  1007. lpJyDest->isReqEnd =TRUE;
  1008. //ClearReq(lpJyDest);
  1009. return 0;
  1010. }
  1011.        
  1012. int JyDest_ChgPwd(LPJY_DEST lpJyDest)
  1013. {
  1014. BYTE SendBuff[100];
  1015. int ret,len;
  1016. JY_ANS_CHGPWD AnsChgPwd;
  1017. // ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  1018. // rlen,CommBuffer);
  1019. // stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  1020. // if(stat !=';') 
  1021. // return 0;
  1022. // FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1023. // if(lpJyDest->jyNum!=atoi(temp)) 
  1024. // return 0;
  1025. //
  1026. // ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1027. // if(ret==' ')
  1028. // return 0;
  1029. REQUEST_BUFFER ReqBuf;
  1030. ANSWER Answer;
  1031. memset(&ReqBuf,0,rlen);
  1032. memset(&Answer,0,sizeof(ANSWER));
  1033. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1034. hlen,rlen,(char *)&ReqBuf);
  1035. if(ReqBuf.status !='02')
  1036. return 0;
  1037. // if(ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1038. // 0,sizeof(ANSWER),(char *)&Answer)!=0)
  1039. // ret =-1;
  1040. // else 
  1041. ret =ReqBuf.error;
  1042. if(ret<0)
  1043. ret =ANS_SYS_ERR;
  1044. else
  1045. ret =ANS_SUCC;
  1046. AnsChgPwd.flag =(char)ret;
  1047. AnsChgPwd.jys =lpJyDest->curJys;
  1048. strcpy(SendBuff, JY_CHGPWD_HEAD);
  1049. len =strlen(SendBuff);
  1050. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  1051. len +=sizeof(short);
  1052. strcpy(AnsChgPwd.gddm, lpJyDest->gddm);
  1053. memcpy(&SendBuff[len], &AnsChgPwd, sizeof(AnsChgPwd));
  1054. len +=sizeof(AnsChgPwd);
  1055. UDP_SendBuff("修改交易密码", lpJyDest->sd, SendBuff, len, NULL);
  1056. lpJyDest->isReqEnd =TRUE;
  1057. // ClearReq(lpJyDest);
  1058. return 0;
  1059. }
  1060.        
  1061. int JyDest_BuySell(LPJY_DEST lpJyDest)
  1062. {
  1063. char hthm[20];
  1064. BYTE SendBuff[100];
  1065. int ret, len;
  1066.     JY_ANS_BUYSELL AnsBuySell; 
  1067. /*
  1068. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1069. hlen,rlen,CommBuffer);
  1070. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  1071. if(stat !=';') 
  1072. return 0;
  1073. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1074. if(lpJyDest->jyNum!=atoi(temp)) 
  1075. return 0;
  1076. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1077. if(ret==' ')
  1078. return 0;
  1079. hthm[0] =0;
  1080. */
  1081. REQUEST_BUFFER ReqBuf;
  1082. ANSWER Answer;
  1083. memset(&ReqBuf,0,rlen);
  1084. memset(&Answer,0,sizeof(ANSWER));
  1085. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1086. hlen,rlen,(char *)&ReqBuf);
  1087. if(ReqBuf.status !='02')
  1088. return 0;
  1089. if(ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1090. 0,sizeof(ANSWER),(char *)&Answer)!=0)
  1091. ret =-1;
  1092. else ret =ReqBuf.error;
  1093. if(ret<0)
  1094. {
  1095. ret =ANS_SYS_ERR;
  1096. }
  1097. else
  1098. {
  1099. //FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],hthm);
  1100. //memset(temp,' ',(short)CommFile.fldStruct[fld_HTHM].wid);
  1101. //if(strncmp(hthm,temp,(short)CommFile.fldStruct[fld_HTHM].wid)==0)
  1102. // return 0;
  1103. lpJyDest->zjye =Answer.a_ent_enter.current_balance;
  1104. lpJyDest->kyje =Answer.a_ent_enter.enable_balance;
  1105. sprintf(hthm,"%06d",ret);
  1106. ret =ANS_SUCC;
  1107. }
  1108. AnsBuySell.jys=lpJyDest->curJys;
  1109. strcpy(AnsBuySell.gddm,lpJyDest->gddm);
  1110. strcpy(AnsBuySell.hthm,hthm);
  1111. AnsBuySell.bs=REQ_BUYSEL;
  1112. AnsBuySell.flag=(char)ret;
  1113. strcpy(SendBuff, JY_BUYSELL_HEAD);
  1114. len =strlen(SendBuff);
  1115. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  1116. len +=sizeof(short);
  1117. memcpy(&SendBuff[len],&AnsBuySell,sizeof(AnsBuySell));
  1118. len+=sizeof(AnsBuySell);
  1119. UDP_SendBuff("买卖委托", lpJyDest->sd, SendBuff, len, NULL);
  1120. lpJyDest->isReqEnd =TRUE;
  1121. //ClearReq(lpJyDest);
  1122. return 0;
  1123. }
  1124.        
  1125. int JyDest_Cancel(LPJY_DEST lpJyDest)
  1126. {
  1127. BYTE SendBuff[600];
  1128. int ret,len,retnum;
  1129. JY_ANS_CANCEL AnsCancel;
  1130. /*
  1131. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1132. hlen,rlen,CommBuffer);
  1133. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  1134. if(stat!=';') 
  1135. return 0;
  1136. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1137. if(lpJyDest->jyNum!=atoi(temp)) 
  1138. return 0;
  1139. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1140. if(ret==' ')
  1141. return 0;
  1142. */
  1143. REQUEST_BUFFER ReqBuf;
  1144. ANSWER Answer;
  1145. memset(&ReqBuf,0,rlen);
  1146. memset(&Answer,0,sizeof(ANSWER));
  1147.     memset(&AnsCancel,0,sizeof(JY_ANS_CANCEL));
  1148. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1149. hlen,rlen,(char *)&ReqBuf);
  1150. if(ReqBuf.status !='02')
  1151. return 0;
  1152. if(ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1153. 0,sizeof(ANSWER),(char *)&Answer)!=0)
  1154. ret =-1;
  1155. else ret =ReqBuf.error;
  1156. //FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1157. //memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1158. //if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1159. // return 0;
  1160. //retnum=atoi(temp);
  1161. retnum =1;
  1162. if(ret<0)
  1163. {
  1164. AnsCancel.flag[0] =ANS_SYS_ERR;
  1165. }
  1166. else
  1167. {
  1168. // if(retnum==1)
  1169. // {
  1170. // ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1171. lpJyDest->zjye =Answer.a_ent_cancel.current_balance;
  1172. lpJyDest->kyje =Answer.a_ent_cancel.enable_balance;
  1173. AnsCancel.flag[0] =ANS_SUCC;
  1174. // }
  1175. /*
  1176. else
  1177. {
  1178. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1179. hFile =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1180. if(hFile ==HFILE_ERROR)
  1181. return 0;
  1182. i=_llseek(hFile, 0L, FILE_END);
  1183. if(i==HFILE_ERROR)
  1184. {
  1185. _lclose(hFile);
  1186. return 0;
  1187. }
  1188. if((i-1)/(rlen+1)!=retnum)
  1189. {
  1190. _lclose(hFile);
  1191. return 0;
  1192. }
  1193. _llseek(hFile, 0L, FILE_BEGIN);
  1194. for(i =0; i<retnum; i++)
  1195. {
  1196. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1197. break;
  1198. ret=CommBuffer[*(int*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1199. AnsCancel.flag[i] =ret;
  1200. _llseek(hFile, 2L, FILE_CURRENT);
  1201. }
  1202. _lclose(hFile);
  1203. remove(temp);
  1204. }
  1205. */
  1206. }
  1207. AnsCancel.jys =lpJyDest->curJys;
  1208. strcpy(AnsCancel.gddm, lpJyDest->gddm);
  1209. strcpy(SendBuff, JY_CANCEL_HEAD);
  1210. len =strlen(SendBuff);
  1211. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  1212. len +=sizeof(short);
  1213. memcpy(&SendBuff[len], &AnsCancel, sizeof(AnsCancel));
  1214. len +=sizeof(AnsCancel);
  1215. UDP_SendBuff("撤消委托", lpJyDest->sd, SendBuff, len,NULL);
  1216. lpJyDest->isReqEnd =TRUE;
  1217. // ClearReq(lpJyDest);
  1218. return 0;
  1219. }
  1220.        
  1221. int JyDest_Yecx(LPJY_DEST lpJyDest)
  1222. {
  1223. JY_ANS_YECX AnsYecx;
  1224. int ret, i,retnum;
  1225. // ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1226. // hlen,rlen,CommBuffer);
  1227. // stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  1228. // if(stat !=';') 
  1229. // return 0;
  1230. // FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1231. // if(lpJyDest->jyNum!=atoi(temp)) 
  1232. // return 0;
  1233. // ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1234. // if(ret==' ')
  1235. // return 0;
  1236. // FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1237. // memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1238. // if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1239. // return 0;
  1240. // retnum=atoi(temp);
  1241. // if(ret==ANS_SUCC&&retnum>0)
  1242. // {
  1243. // wsprintf(tmp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1244. // hFile =OpenFile(tmp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1245. //
  1246. // if(hFile ==HFILE_ERROR)
  1247. // return 0;
  1248. //
  1249. // i=_llseek(hFile, 0L, FILE_END);
  1250. // if(i==HFILE_ERROR)
  1251. // {
  1252. // _lclose(hFile);
  1253. // return 0;
  1254. // }
  1255. // if((i)/(rlen+1)<retnum)
  1256. // {
  1257. // _lclose(hFile);
  1258. // return 0;
  1259. // }
  1260. // _llseek(hFile, 0L, FILE_BEGIN);
  1261. // }
  1262. REQUEST_BUFFER ReqBuf;
  1263. ANSWER Answer;
  1264. memset(&ReqBuf,0,rlen);
  1265. memset(&Answer,0,sizeof(Answer));
  1266. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1267. hlen,rlen,(char *)&ReqBuf);
  1268. if(ReqBuf.status !='02')
  1269. return 0;
  1270. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1271. 0,sizeof(ANSWER),(char *)&Answer);
  1272. ret =ReqBuf.error;
  1273. AnsYecx.kys=lpJyDest->kyje;
  1274. AnsYecx.zjye=lpJyDest->zjye;
  1275. if(ret>=0)
  1276. {
  1277. retnum =ret;
  1278. ret =ANS_SUCC;
  1279. //FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],temp);
  1280. //AnsYecx.kys=atof(temp);      
  1281. //FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],temp);
  1282. //AnsYecx.zjye=atof(temp);     
  1283. if(retnum>0)
  1284. {
  1285. AnsYecx.lpGptg=GlobalAllocPtr(GHND,sizeof(JY_GPTG)*retnum);
  1286. memset(&AnsYecx.lpGptg[0],0,sizeof(JY_GPTG)*retnum);
  1287. }
  1288. for(i=0;i<retnum && i<ITEMS;i++)
  1289. {
  1290. //if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1291. // break;
  1292. strcpy(AnsYecx.lpGptg[i].gpdm,Answer.a_inq_stock[i].stock_code);
  1293. sprintf(AnsYecx.lpGptg[i].kys,"%8d",
  1294. Answer.a_inq_stock[i].enable_balance);
  1295. sprintf(AnsYecx.lpGptg[i].gpye,"%8d",
  1296. Answer.a_inq_stock[i].current_balance);
  1297. /*
  1298. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  1299. &AnsYecx.lpGptg[i].gpdm[0]);
  1300. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  1301. &AnsYecx.lpGptg[i].kys[0]);
  1302. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  1303. &AnsYecx.lpGptg[i].gpye[0]);
  1304. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  1305. &AnsYecx.lpGptg[i].ghrq[0]);
  1306. _llseek(hFile, 2L, FILE_CURRENT);
  1307. */
  1308. }
  1309. // if(retnum>0)
  1310. // {
  1311. // _lclose(hFile);
  1312. // remove(tmp);
  1313. // }
  1314. AnsYecx.recnum=i;
  1315. AnsYecx.flag=ret;
  1316. if(AnsYecx.recnum >=0)
  1317. {
  1318. lpJyDest->isSending =TRUE;
  1319. Thrd_SendJycx(REQ_YECX, lpJyDest->sd, &AnsYecx, lpJyDest->jyNum);
  1320. if(retnum>0)
  1321. GlobalFreePtr(AnsYecx.lpGptg);
  1322. lpJyDest->isSending =FALSE;
  1323. }
  1324. }
  1325. else
  1326. {
  1327. AnsYecx.recnum=0;
  1328. AnsYecx.flag=ANS_SUCC;
  1329. lpJyDest->isSending =TRUE;
  1330. Thrd_SendJycx(REQ_YECX, lpJyDest->sd, &AnsYecx, lpJyDest->jyNum);
  1331. lpJyDest->isSending =FALSE;
  1332. // lpJyDest->isReqEnd =TRUE;
  1333. //        ClearReq(lpJyDest);
  1334. //     return ret;
  1335. }
  1336. lpJyDest->isReqEnd =TRUE;
  1337. return 0;
  1338. }
  1339.        
  1340. int JyDest_Cjcx(LPJY_DEST lpJyDest)
  1341. {
  1342. JY_ANS_CJCX AnsCjcx;
  1343. int i, ret,retnum;
  1344. /*
  1345. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1346. hlen,rlen,CommBuffer);
  1347. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  1348. if(stat !=';') 
  1349. return 0;
  1350. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1351. if(lpJyDest->jyNum!=atoi(temp)) 
  1352. return 0;
  1353. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1354. if(ret==' ')
  1355. return 0;
  1356. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1357. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1358. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1359. return 0;
  1360. retnum=atoi(temp);
  1361. if(ret==ANS_SUCC&&retnum>0)
  1362. {
  1363. wsprintf(tmp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1364. hFile =OpenFile(tmp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1365. if(hFile ==HFILE_ERROR)
  1366. return 0;
  1367. i=_llseek(hFile, 0L, FILE_END);
  1368. if(i==HFILE_ERROR)
  1369. {
  1370. _lclose(hFile);
  1371. return 0;
  1372. }
  1373. if((i)/(rlen+1)<retnum)
  1374. {
  1375. _lclose(hFile);
  1376. return 0;
  1377. }
  1378. _llseek(hFile, 0L, FILE_BEGIN);
  1379. }
  1380. */
  1381. REQUEST_BUFFER ReqBuf;
  1382. ANSWER Answer;
  1383. memset(&ReqBuf,0,rlen);
  1384. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1385. hlen,rlen,(char *)&ReqBuf);
  1386. if(ReqBuf.status !='02')
  1387. return 0;
  1388. memset(&Answer,0,sizeof(Answer));
  1389. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1390. 0,sizeof(ANSWER),(char *)&Answer);
  1391. ret =ReqBuf.error;
  1392. if(ret>=0)
  1393. retnum =ret;
  1394. ret =ANS_SUCC;
  1395. if(retnum>0)
  1396. {
  1397. AnsCjcx.lpCj=GlobalAllocPtr(GHND,sizeof(JY_CJ)*retnum);
  1398. memset(&AnsCjcx.lpCj[0],0,sizeof(JY_CJ)*retnum);
  1399. }
  1400. for(i=0;i<retnum && i<ITEMS;i++)
  1401. {
  1402. //memset(CommBuffer,0,sizeof(CommBuffer));
  1403. //if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1404. // break;
  1405. //if(Answer.a_inq_real[i].real_status =='2')
  1406. // continue;
  1407. sprintf(AnsCjcx.lpCj[i].hthm,"%06d",
  1408. Answer.a_inq_real[i].serial_no);
  1409. sprintf(AnsCjcx.lpCj[i].cjsj,"%06d",
  1410. Answer.a_inq_real[i].business_time);
  1411. AnsCjcx.lpCj[i].mmbz=(Answer.a_inq_real[i].bs=='1')?'B':'S';
  1412. strcpy(AnsCjcx.lpCj[i].gpdm,
  1413. Answer.a_inq_real[i].stock_code);
  1414. sprintf(AnsCjcx.lpCj[i].cjgs,"%8d",
  1415. Answer.a_inq_real[i].business_amount);
  1416. sprintf(AnsCjcx.lpCj[i].cjjg,"%6.2f",
  1417. Answer.a_inq_real[i].business_price);
  1418. /*
  1419. FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],
  1420. &AnsCjcx.lpCj[i].hthm[0]);
  1421. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  1422. &AnsCjcx.lpCj[i].cjsj[0]);
  1423. AnsCjcx.lpCj[i].mmbz=
  1424. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1425. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  1426. &AnsCjcx.lpCj[i].gpdm[0]);
  1427. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  1428. &AnsCjcx.lpCj[i].cjgs[0]);
  1429. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  1430. &AnsCjcx.lpCj[i].cjjg[0]);
  1431. _llseek(hFile, 2L, FILE_CURRENT);
  1432. */
  1433. }
  1434. AnsCjcx.recnum=i;
  1435. AnsCjcx.flag =ret;
  1436. if(AnsCjcx.recnum >=0)
  1437. {
  1438. lpJyDest->isSending =TRUE;
  1439. Thrd_SendJycx(REQ_CJCX, lpJyDest->sd, &AnsCjcx, lpJyDest->jyNum);
  1440. if(retnum>0)
  1441. GlobalFreePtr(AnsCjcx.lpCj);
  1442. lpJyDest->isSending =FALSE;
  1443. }
  1444. }
  1445. else
  1446. {
  1447. AnsCjcx.recnum=0;
  1448. AnsCjcx.flag =ANS_SUCC;
  1449. lpJyDest->isSending =TRUE;
  1450. Thrd_SendJycx(REQ_CJCX, lpJyDest->sd, &AnsCjcx, lpJyDest->jyNum);
  1451. lpJyDest->isSending =FALSE;
  1452. }
  1453. lpJyDest->isReqEnd =TRUE;
  1454. return 0;
  1455. }
  1456. int JyDest_Wtcx(LPJY_DEST lpJyDest)
  1457. {
  1458. JY_ANS_WTCX AnsWtcx;
  1459. int ret, i,retnum;
  1460. /*
  1461. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1462. hlen,rlen,CommBuffer);
  1463. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  1464. if(stat !=';') 
  1465. return 0;
  1466. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1467. if(lpJyDest->jyNum!=atoi(temp)) return 0;
  1468. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1469. if(ret==' ')
  1470. return 0;
  1471. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1472. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1473. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1474. return 0;
  1475. retnum=atoi(temp);
  1476. if(ret==ANS_SUCC&&retnum>0)
  1477. {
  1478. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1479. hFile =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1480. if(hFile ==HFILE_ERROR)
  1481. return 0;
  1482. i=_llseek(hFile, 0L, FILE_END);
  1483. if(i==HFILE_ERROR)
  1484. {
  1485. _lclose(hFile);
  1486. return 0;
  1487. }
  1488. if((i)/(rlen+1)<retnum)
  1489. {
  1490. _lclose(hFile);
  1491. return 0;
  1492. }
  1493. _llseek(hFile, 0L, FILE_BEGIN);
  1494. }
  1495. */
  1496. REQUEST_BUFFER ReqBuf;
  1497. ANSWER Answer;
  1498. memset(&ReqBuf,0,rlen);
  1499. ReadRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1500. hlen,rlen,(char *)&ReqBuf);
  1501. if(ReqBuf.status !='02')
  1502. return 0;
  1503. memset(&Answer,0,sizeof(Answer));
  1504. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1505. 0,sizeof(ANSWER),(char *)&Answer);
  1506. ret =ReqBuf.error;
  1507. if(ret>=0)
  1508. retnum =ret;
  1509. ret =ANS_SUCC;
  1510. if(retnum>0)
  1511. {
  1512. AnsWtcx.lpWt =GlobalAllocPtr(GHND,sizeof(JY_WT)*retnum);
  1513. memset(&AnsWtcx.lpWt[0], 0, sizeof(JY_WT)*retnum);
  1514. }
  1515. for(i=0;i<retnum && i<ITEMS;i++)
  1516. {
  1517. //if(Answer.a_inq_entrust[i].entrust_status=='4')
  1518. // continue;
  1519. sprintf(AnsWtcx.lpWt[i].hthm,"%06d",
  1520. Answer.a_inq_entrust[i].entrust_serial_no);
  1521. sprintf(AnsWtcx.lpWt[i].wtsj,"  :  : ");
  1522. AnsWtcx.lpWt[i].mmbz=
  1523. (Answer.a_inq_entrust[i].entrust_bs=='1')?'B':'S';
  1524. strcpy(AnsWtcx.lpWt[i].gpdm,
  1525. Answer.a_inq_entrust[i].stock_code);
  1526. sprintf(AnsWtcx.lpWt[i].wtgs,"%8d",
  1527. Answer.a_inq_entrust[i].entrust_amount);
  1528. sprintf(AnsWtcx.lpWt[i].wtjg,"%6.2f",
  1529. Answer.a_inq_entrust[i].entrust_price);
  1530. /*
  1531. memset(CommBuffer,0,sizeof(CommBuffer));
  1532. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1533. break;
  1534. FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],
  1535. &AnsWtcx.lpWt[i].hthm[0]);
  1536. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  1537. &AnsWtcx.lpWt[i].wtsj[0]);
  1538. AnsWtcx.lpWt[i].mmbz=
  1539. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1540. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  1541. &AnsWtcx.lpWt[i].gpdm[0]);
  1542. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  1543. &AnsWtcx.lpWt[i].wtgs[0]);
  1544. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  1545. &AnsWtcx.lpWt[i].wtjg[0]);
  1546. _llseek(hFile, 2L, FILE_CURRENT);
  1547. */
  1548. }
  1549. AnsWtcx.recnum=i;
  1550. AnsWtcx.flag =ret;
  1551. if(AnsWtcx.recnum >=0)
  1552. {
  1553. lpJyDest->isSending =TRUE;
  1554. Thrd_SendJycx(REQ_WTCX, lpJyDest->sd, &AnsWtcx, lpJyDest->jyNum);
  1555. if(AnsWtcx.recnum>0)
  1556. GlobalFreePtr(AnsWtcx.lpWt);
  1557. lpJyDest->isSending =FALSE;
  1558. }
  1559. }
  1560. else
  1561. {
  1562. AnsWtcx.recnum=0;
  1563. AnsWtcx.flag =ANS_SUCC;
  1564. lpJyDest->isSending =TRUE;
  1565. Thrd_SendJycx(REQ_WTCX, lpJyDest->sd, &AnsWtcx, lpJyDest->jyNum);
  1566. lpJyDest->isSending =FALSE;
  1567. }
  1568. lpJyDest->isReqEnd =TRUE;
  1569. return 0;
  1570. }
  1571. int Thrd_SendJycx(int reqType, int sd, char *lpBuf, int jyNum)
  1572. {
  1573. char SendBuff[2048];
  1574. LPJY_ANS_YECX lpAnsYecx;
  1575. LPJY_ANS_CJCX lpAnsCjcx;
  1576. LPJY_ANS_WTCX lpAnsWtcx;
  1577. int i, len, recCount, sendCount, sendNum;
  1578. sendNum =0;
  1579. sendCount =MAX_CX_SENDCOUNT;
  1580. switch(reqType)
  1581. {
  1582. case REQ_YECX:
  1583. lpAnsYecx =(LPJY_ANS_YECX)lpBuf;
  1584. recCount =lpAnsYecx->recnum;
  1585. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1586. {
  1587. sendNum =i*MAX_CX_SENDCOUNT;
  1588. if(sendNum+sendCount >recCount)
  1589. sendCount =recCount-sendNum;
  1590. strcpy(SendBuff, JY_YECX_HEAD);
  1591. len =strlen(SendBuff);
  1592. *(short *)&SendBuff[len] =jyNum;
  1593. len +=sizeof(short);
  1594. lpAnsYecx->recnum=sendCount;
  1595. memcpy(&SendBuff[len],lpAnsYecx,sizeof(JY_ANS_YECX)-sizeof(LPJY_GPTG));
  1596.             len+=sizeof(JY_ANS_YECX)-sizeof(LPJY_GPTG);
  1597. if(sendCount==0&&sendNum!=0)
  1598. break;
  1599. if(sendCount>0)
  1600. {
  1601. memcpy(&SendBuff[len], &lpAnsYecx->lpGptg[sendNum],
  1602. sizeof(JY_GPTG)*sendCount);
  1603. len +=sizeof(JY_GPTG)*sendCount;
  1604. }
  1605. if(UDP_SendBuff("余额查询", sd, SendBuff, len,NULL)<0)
  1606. return -1;
  1607. }
  1608. break;
  1609. case REQ_CJCX:
  1610. lpAnsCjcx =(LPJY_ANS_CJCX)lpBuf;
  1611. recCount =lpAnsCjcx->recnum;
  1612. sendCount =MAX_CX_SENDCOUNT;
  1613. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1614. {
  1615. sendNum =i*MAX_CX_SENDCOUNT;
  1616. if(sendNum+sendCount >recCount)
  1617. sendCount =recCount-sendNum;
  1618. strcpy(SendBuff, JY_CJCX_HEAD);
  1619. len =strlen(SendBuff);
  1620. *(short *)&SendBuff[len] =jyNum;
  1621. len +=sizeof(short);
  1622. lpAnsCjcx->recnum=sendCount;
  1623.             memcpy(&SendBuff[len],lpAnsCjcx,sizeof(JY_ANS_CJCX)-sizeof(LPJY_CJ));
  1624.             len+=sizeof(JY_ANS_CJCX)-sizeof(LPJY_CJ);
  1625. if(sendCount==0&&sendNum!=0)
  1626. break;
  1627. if(sendCount>0)
  1628. {
  1629.   memcpy(&SendBuff[len], &lpAnsCjcx->lpCj[sendNum],
  1630. sizeof(JY_CJ)*sendCount);
  1631. len +=sizeof(JY_CJ)*sendCount;
  1632. }
  1633. if(UDP_SendBuff("成交查询", sd, SendBuff, len,NULL)<0)
  1634. return -1; 
  1635. }
  1636. break;
  1637. case REQ_WTCX:
  1638. lpAnsWtcx =(LPJY_ANS_WTCX)lpBuf;
  1639. recCount =lpAnsWtcx->recnum;
  1640. sendCount =MAX_CX_SENDCOUNT;
  1641. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1642. {
  1643. sendNum =i*MAX_CX_SENDCOUNT;
  1644. if(sendNum+sendCount >recCount)
  1645. sendCount =recCount-sendNum;
  1646. strcpy(SendBuff, JY_WTCX_HEAD);
  1647. len =strlen(SendBuff);
  1648. *(short *)&SendBuff[len] =jyNum;
  1649. len +=sizeof(short);
  1650. lpAnsWtcx->recnum=sendCount;
  1651. memcpy(&SendBuff[len],lpAnsWtcx,sizeof(JY_ANS_WTCX)-sizeof(LPJY_WT));
  1652.             len+=sizeof(JY_ANS_WTCX)-sizeof(LPJY_WT);
  1653. if(sendCount>0)
  1654. {
  1655. memcpy(&SendBuff[len], &lpAnsWtcx->lpWt[sendNum],
  1656. sizeof(JY_WT)*sendCount);
  1657. len +=sizeof(JY_WT)*sendCount;
  1658. }
  1659. if(sendCount==0&&sendNum!=0)
  1660. break;
  1661. if(UDP_SendBuff("委托查询", sd, SendBuff, len,NULL)<0)
  1662. return -1;
  1663. }
  1664. break;
  1665. }
  1666. strcpy(SendBuff, JY_CXEND_HEAD);
  1667. len =strlen(SendBuff);
  1668. UDP_SendBuff("查询成功", sd, SendBuff, len,NULL);
  1669. return 0;
  1670. }
  1671. int Jy_SendRet(int sd, char reqType, char ret, int jyNum)
  1672. {
  1673. int len;
  1674. BYTE SendBuff[100];
  1675. LPSTR lpHead;
  1676. if(ret ==ANS_TIME_OUT)
  1677. lpHead =JY_TIMEOUT_HEAD;
  1678. else
  1679. switch(reqType)
  1680. {
  1681. case REQ_CHKUSR:
  1682. lpHead =JY_CHKUSR_HEAD;
  1683. break;
  1684. case REQ_CHGPWD:
  1685. lpHead =JY_CHGPWD_HEAD;
  1686. break;
  1687. case REQ_BUYSEL:
  1688. lpHead =JY_BUYSELL_HEAD;
  1689. break;
  1690. case REQ_CANCEL:
  1691. lpHead =JY_CANCEL_HEAD;
  1692. break;
  1693. case REQ_YECX:
  1694. lpHead =JY_YECX_HEAD;
  1695. break;
  1696. case REQ_CJCX:
  1697. lpHead =JY_CJCX_HEAD;
  1698. break;
  1699. case REQ_WTCX:
  1700. lpHead =JY_WTCX_HEAD;
  1701. break;
  1702. }
  1703. strcpy(SendBuff, lpHead);
  1704. len =strlen(SendBuff);
  1705. *(short *)&SendBuff[len] =jyNum;
  1706. len +=sizeof(short);
  1707. SendBuff[len++] =(char)ret;
  1708. UDP_SendBuff("发送结果", sd, SendBuff, len,NULL);
  1709. return 0;
  1710. }