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

金融证券系统

开发平台:

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 MAX_PATH_LEN 128
  15. #define START_REC_NO 100
  16. DBF_DATA CommFile;
  17. typedef struct  tag_ANSFILE
  18. {
  19. int hf[MAX_ZQS_COUNT];
  20. int recnum[MAX_ZQS_COUNT];
  21. char path[MAX_ZQS_COUNT][MAX_PATH_LEN];
  22. }ANSFILE;
  23. ANSFILE AnsFile;
  24. typedef struct  tag_REQFILE
  25. {
  26. int hf[MAX_ZQS_COUNT];
  27. int recnum[MAX_ZQS_COUNT];
  28. int currec[MAX_ZQS_COUNT];
  29. }REQFILE;
  30. REQFILE ReqFile;
  31. int ZqsCount;
  32. char * CommBuffer;
  33. short rlen,hlen;
  34. char RetFilePath[80];
  35. BOOL fUseJy =FALSE,fTestJy=FALSE,fRsa=FALSE;
  36. int Thrd_SendJycx(int sd, int reqType, void *lpBuf, int);
  37. extern int sdJy;
  38. extern BOOL GetInitString(LPSTR, LPSTR, LPSTR);
  39. extern BOOL PutInitString(LPSTR, LPSTR, LPSTR);
  40. extern BOOL ErrMsg(HWND, LPSTR);
  41. //extern int UDP_SendBuff(LPSTR, int, LPSTR, int, LPDEST_INFO );
  42. int JyInit(void)
  43. {       
  44. int i;
  45.     char tmp[256], temp[256],temp1[256];
  46. char * prt;
  47. memset(&ReqFile,0,sizeof(REQFILE));
  48. memset(&AnsFile,0,sizeof(ANSFILE));
  49. CommBuffer =NULL;
  50. CommFile.hf =-1;
  51. if(GetInitString("JY", "RUN", tmp))
  52. {
  53. if(tmp[0] =='N' || tmp[0] =='n')
  54. {
  55. fUseJy =FALSE;
  56. return 0;
  57. }
  58. else
  59. fUseJy =TRUE;
  60. }
  61. if(GetInitString("JY", "TEST", tmp))
  62. {
  63. if(tmp[0] =='Y' || tmp[0] =='y')
  64. fTestJy =TRUE;
  65. else
  66. fTestJy =FALSE;
  67. }
  68. else 
  69. fTestJy =FALSE;
  70.          
  71. if(GetInitString("JY", "RSA", tmp))
  72. {
  73. if(tmp[0] =='Y' || tmp[0] =='y')
  74. {
  75. fRsa =TRUE;
  76. if(!ReadRsaFile(R,PK,SK))
  77. ErrMsg(NULL,"读RSA加密参数失败,请在系统启动后按[Init]");
  78. }
  79. }
  80. ZqsCount=0;
  81. for(i=0;i<MAX_ZQS_COUNT;i++)
  82. {
  83. wsprintf(temp,"%s%d","COMMFILE",i);
  84. if(!GetInitString("JY", temp, tmp))
  85. {
  86. if(ZqsCount==0)
  87. {
  88. wsprintf(temp, "不能发现配置%s:n %s",
  89. (LPSTR)"COMMFILE", (LPSTR)tmp);
  90. ErrMsg(NULL, temp);
  91. }
  92. break;
  93. }
  94. else
  95. {
  96. ZqsCount++;
  97. prt=strstr(tmp,";");
  98. if(prt==NULL) 
  99. {
  100. ErrMsg(NULL,"format Reqfile;AnsFile");
  101. return -1;
  102. }
  103. else *prt=0;
  104. strcpy(temp1,tmp);
  105. if(access(temp1,_S_IREAD|_S_IWRITE) <0)
  106. {
  107. wsprintf(temp, "不能存取%s:n %s",
  108. (LPSTR)"COMMFILE", (LPSTR)temp1);
  109. ErrMsg(NULL, temp);
  110. return -1;
  111. }  
  112.                 
  113. ReqFile.hf[i]=OpenDbfBase(temp1,O_RDWR);
  114. if(i==0)
  115. CommFile.hf=ReqFile.hf[0];
  116. if (ReqFile.hf[i]==-1)
  117. {
  118. wsprintf(temp, "不能打开%s:n %s",
  119. (LPSTR)"COMMFILE", (LPSTR)temp1);
  120. ErrMsg(NULL, temp);
  121. return -1;
  122. if(i==0)
  123. {
  124. if (InitBase(CommFile.hf,&CommFile.dbfStruct,
  125. &CommFile.fldStruct,&CommFile.fldCount)
  126. !=SUCCEED) 
  127. {
  128. wsprintf(temp, "不能处始化%s:n %s",
  129. (LPSTR)"COMMFILE", (LPSTR)temp1);
  130. ErrMsg(NULL, temp);
  131. return -1;
  132. }
  133. rlen=*(short *)CommFile.dbfStruct.rlen;
  134. hlen=*(short *)CommFile.dbfStruct.hlen;
  135. }
  136. ReqFile.recnum[i]=GetRecNum(ReqFile.hf[i]);
  137. strcpy(temp1,++prt);
  138. AnsFile.hf[i]=OpenDbfBase(temp1,O_RDWR);
  139. if (ReqFile.hf[i]==-1)
  140. {
  141. wsprintf(temp, "不能打开%s:n %s",
  142. (LPSTR)"COMMFILE", (LPSTR)temp1);
  143. ErrMsg(NULL, temp);
  144. return -1;
  145. prt =strrchr(temp1,'\');
  146. ++prt; *prt =0;
  147. strcpy(&AnsFile.path[i][0],temp1);
  148. AnsFile.recnum[i]=GetRecNum(AnsFile.hf[i]);
  149. AnsFile.recnum[i]=min(AnsFile.recnum[i],ReqFile.recnum[i]);
  150. ReqFile.recnum[i]=AnsFile.recnum[i];
  151. }
  152. }
  153. if(ZqsCount)
  154. if((CommBuffer =GlobalAllocPtr(GHND,*(short*)CommFile.dbfStruct.rlen))==NULL)
  155. {
  156.       ErrMsg(NULL, "不能分配交换文件记录内存!");
  157.       return -1;
  158. }
  159. return 0;
  160. }
  161. int JyExit(void)
  162. {
  163. int i;
  164. for(i=0;i<ZqsCount;i++)
  165. {
  166. if(ReqFile.hf[i]!=-1)
  167. CloseDbf(ReqFile.hf[i]);
  168. if(AnsFile.hf[i]!=-1)
  169. CloseDbf(AnsFile.hf[i]);
  170. }
  171. if(CommFile.fldStruct)
  172. GlobalFreePtr(CommFile.fldStruct);
  173. if(CommBuffer)
  174.         GlobalFreePtr(CommBuffer);
  175. return 0;
  176. }
  177. int Jy_Zqsxx(int sd)
  178. {
  179. int len;
  180. BYTE SendBuff[1024];
  181. strcpy(SendBuff, JY_ZQSXX_HEAD);
  182. len =strlen(JY_ZQSXX_HEAD);
  183. //memcpy(&SendBuff[len],&Zqsxx,sizeof(ZQSXX));
  184. //len+=sizeof(Zqsxx);
  185. memcpy(&SendBuff[len],R,DATALENGTH);
  186. len +=DATALENGTH;
  187. memcpy(&SendBuff[len],PK,DATALENGTH);
  188. len +=DATALENGTH;
  189. UDP_SendBuff("RSA.R.PK", sd, SendBuff, len,NULL);
  190. return 0;
  191. }
  192. void ClearAns(LPJY_DEST lpJyDest)
  193. {
  194. char* buff;
  195.     HANDLE hd;    
  196. if((hd =GlobalAlloc(GHND,rlen))==NULL) return;
  197.     if((buff=GlobalLock(hd))==NULL) return;
  198. memset(buff,' ',rlen);
  199. WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,buff);
  200. GlobalUnlock(hd);
  201. GlobalFree(hd);
  202. }
  203. void ClearReq(LPJY_DEST lpJyDest)
  204. {
  205. char* buff;
  206.     HANDLE hd;    
  207. if((hd =GlobalAlloc(GHND,rlen))==NULL) return;
  208.     if((buff=GlobalLock(hd))==NULL) return;
  209. memset(buff,' ',rlen);
  210. buff[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]='0';
  211. WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,buff);
  212. GlobalUnlock(hd);
  213. GlobalFree(hd);
  214. }
  215. int Jy_ChkUsr(int sd, int jyNum, LPJY_ASK_CHKUSR AskChkUser)
  216. {
  217. int ret;
  218. LPJY_DEST lpJyDest;
  219.     char temp[20];  
  220. short Qsid;
  221. if(ZqsCount ==1)
  222. Qsid =1;
  223. else
  224. Qsid =AskChkUser->zqsid;
  225. if(ReqFile.hf[Qsid -1] ==-1)
  226. return ANS_SYS_ERR;
  227. ret =CheckJyDest(sd,REQ_CHKUSR, AskChkUser->jys,
  228. AskChkUser->gddm, -1, &lpJyDest);
  229. memset(CommBuffer,' ',rlen);
  230. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskChkUser->gddm);
  231. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  232. =(AskChkUser->jys ==0)?'Z':'H';
  233. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],AskChkUser->jymm);      
  234. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CHKUSR;
  235. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  236. wsprintf(temp,"%d",sd);
  237. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  238. wsprintf(temp,"%d",jyNum);
  239. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  240. if(lpJyDest==NULL)
  241. lpJyDest=GetFirstIdelRec();
  242. if(lpJyDest==NULL)
  243. {
  244. ReqFile.currec[Qsid-1]++;
  245. if(ReqFile.currec[Qsid-1]>ReqFile.recnum[Qsid-1])
  246. {
  247. ErrMsg(NULL, "无空闲交易表项!");      
  248. return ANS_SYS_ERR;
  249. }
  250. lpJyDest=AddJyDest(sd, REQ_CHKUSR, AskChkUser->jys,
  251. ReqFile.currec[Qsid-1], AskChkUser->gddm, jyNum,Qsid-1);
  252. if(lpJyDest ==NULL)
  253. {
  254. ErrMsg(NULL, "不能加交易表项!");
  255. return ANS_SYS_ERR;
  256. }
  257. ClearAns(lpJyDest);
  258. if(WriteRecord(ReqFile.hf[Qsid-1],lpJyDest->recNum,
  259. hlen,rlen,CommBuffer) !=0)
  260. {
  261. ErrMsg(NULL, "不能写交换文件!");      
  262. return ANS_SYS_ERR;
  263. }
  264. }
  265. else
  266. {
  267. ClearAns(lpJyDest);
  268. if(WriteRecord(ReqFile.hf[Qsid-1],lpJyDest->recNum,
  269. hlen,rlen,CommBuffer)!=0)
  270. {
  271. ErrMsg(NULL, "不能写交换文件1!");      
  272. return ANS_SYS_ERR;
  273. }
  274. strcpy(lpJyDest->gddm,AskChkUser->gddm);
  275. ChangeJyDest(sd, lpJyDest, REQ_CHKUSR, AskChkUser->jys,
  276. Qsid -1,jyNum);
  277. }
  278. if(fTestJy)
  279. {
  280. Sleep(1000);
  281. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  282. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  283. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  284. wsprintf(temp,"%d",jyNum);
  285. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  286. WriteRecord(AnsFile.hf[Qsid-1],lpJyDest->recNum,hlen,
  287. rlen,CommBuffer);
  288. }
  289. return 0;
  290. }
  291. int Jy_ChgPwd(int sd, int jyNum, LPJY_ASK_CHGPWD AskChgPwd)
  292. {
  293. LPJY_DEST lpJyDest=NULL;
  294. int ret;
  295. char temp[20];
  296. ret =CheckJyDest(sd, REQ_CHGPWD, AskChgPwd->jys, AskChgPwd->gddm,
  297. AskChgPwd->userId, &lpJyDest);
  298. if(ret==-1)
  299. return ANS_SYS_ERR;
  300. if(ret==-2)
  301. return ANS_SUSP_REQ;
  302. if(ret==-3)
  303. return ANS_NO_PRIV;
  304. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  305. return ANS_SYS_ERR;
  306. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  307. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskChgPwd->gddm);
  308. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  309. =(AskChgPwd->jys ==0)?'Z':'H';
  310. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],AskChgPwd->xmm);      
  311. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CHGPWD;
  312. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  313. wsprintf(temp,"%d",sd);
  314. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  315. wsprintf(temp,"%d",jyNum);
  316. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  317. ClearAns(lpJyDest);
  318. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,CommBuffer)!=0)
  319. {
  320. ErrMsg(NULL, "不能写交换文件!");
  321. return ANS_SYS_ERR;
  322. }
  323. ChangeJyDest(sd, lpJyDest, REQ_CHGPWD, AskChgPwd->jys, -1, jyNum);
  324. if(fTestJy)
  325. {
  326. Sleep(1000);
  327. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  328. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  329. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  330. wsprintf(temp,"%d",jyNum);
  331. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  332. WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,CommBuffer);
  333. }
  334. return 0;
  335. }
  336. int Jy_BuySell(int sd, int jyNum, LPJY_ASK_BUYSELL AskBuySell)
  337. {
  338. LPJY_DEST lpJyDest;
  339. int ret;
  340. char temp[20];
  341. ret =CheckJyDest(sd, REQ_BUYSEL, AskBuySell->jys, AskBuySell->gddm,
  342. AskBuySell->userId, &lpJyDest);
  343. if(ret==-1)
  344. return ANS_SYS_ERR;
  345. if(ret==-2)
  346. return ANS_SUSP_REQ;
  347. if(ret==-3)
  348. return ANS_NO_PRIV;
  349. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  350. return ANS_SYS_ERR;
  351. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  352. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskBuySell->gddm);
  353. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  354. =(AskBuySell->jys ==0)?'Z':'H';                         
  355. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],AskBuySell->gpdm);
  356. sprintf(temp,"%12ld",AskBuySell->wtgs);
  357. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);            
  358. sprintf(temp,"%12.2f",(double)(AskBuySell->wtjg/100.00));
  359. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  360. if(AskBuySell->bs =='B')
  361. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_BUY;
  362. else if(AskBuySell->bs =='S')
  363. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_SELL;
  364. else
  365. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]='E';
  366. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  367.   wsprintf(temp,"%d",sd);
  368. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  369. wsprintf(temp,"%d",jyNum);
  370. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  371. ClearAns(lpJyDest);
  372. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,CommBuffer)!=0)
  373. {
  374. ErrMsg(NULL, "不能写交换文件!");      
  375. return ANS_SYS_ERR;
  376. }
  377. if(ChangeJyDest(sd, lpJyDest, REQ_BUYSEL, AskBuySell->jys, -1, jyNum)<0)
  378. return ANS_SYS_ERR;
  379. if(fTestJy)
  380. {
  381. Sleep(1000);
  382. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_NULL;
  383. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  384. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  385. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],"000068");
  386. wsprintf(temp,"%d",jyNum);
  387. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  388.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,CommBuffer);
  389. }
  390. return 0;
  391. }
  392. int Jy_Cancel(int sd, int jyNum, LPJY_ASK_CANCEL AskCancel)
  393. {
  394. LPJY_DEST lpJyDest;
  395. int ret,i;
  396. char temp[20];
  397. HFILE hFile;
  398. OFSTRUCT os;
  399. ret =CheckJyDest(sd, REQ_CANCEL, AskCancel->jys, 
  400. AskCancel->gddm, AskCancel->userId, &lpJyDest);
  401. if(ret==-1)
  402. return ANS_SYS_ERR;
  403. if(ret==-2)
  404. return ANS_SUSP_REQ;
  405. if(ret==-3)
  406. return ANS_NO_PRIV;
  407. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  408. return ANS_SYS_ERR;
  409. for(i=0;i<AskCancel->cancelCount;i++)
  410. {
  411. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  412. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCancel->gddm);
  413. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCancel->Cancel[i].hthm);          
  414. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  415. =(AskCancel->jys ==0)?'Z':'H';                      
  416. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CANCEL;
  417. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  418.   wsprintf(temp,"%d",sd);
  419. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  420. wsprintf(temp,"%d",jyNum);
  421. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  422. ClearAns(lpJyDest);
  423. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  424. CommBuffer)!=0)
  425. {
  426. ErrMsg(NULL, "不能写交换文件!");      
  427. return ANS_SYS_ERR;
  428. }
  429. }
  430. ChangeJyDest(sd, lpJyDest, REQ_CANCEL, AskCancel->jys, -1, jyNum);
  431. lpJyDest->recCount =AskCancel->cancelCount;
  432. if(fTestJy)
  433. {
  434. Sleep(1000);
  435. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  436. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  437. wsprintf(temp,"%d",AskCancel->cancelCount);
  438. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],temp);
  439. wsprintf(temp,"%d",jyNum);
  440. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  441.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  442. CommBuffer);
  443. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  444. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  445. if(hFile ==HFILE_ERROR)
  446. return ANS_SYS_ERR;
  447. for(i=0;i<AskCancel->cancelCount;i++)
  448. {
  449. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  450. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCancel->gddm);
  451. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCancel->Cancel[i].hthm);          
  452. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  453. =(AskCancel->jys ==0)?'Z':'H';                      
  454. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CANCEL;
  455. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  456. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  457.   wsprintf(temp,"%d",sd);
  458. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  459. wsprintf(temp,"%d",jyNum);
  460. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  461. _lwrite(hFile,&CommBuffer[1], rlen-1);
  462. _lwrite(hFile,"rn",2);
  463. }
  464. _lclose(hFile);
  465. }
  466. return 0;
  467. }
  468. int Jy_Yecx(int sd, int jyNum, LPJY_ASK_YECX AskYecx)
  469. {
  470. LPJY_DEST lpJyDest;
  471. int ret,i=0;
  472. char temp[20];
  473. HFILE hFile;
  474. OFSTRUCT os;
  475. ret =CheckJyDest(sd, REQ_YECX, AskYecx->jys, AskYecx->gddm,
  476. AskYecx->userId, &lpJyDest);
  477. if(ret==-1)
  478. return ANS_SYS_ERR;
  479. if(ret==-2)
  480. return ANS_SUSP_REQ;
  481. if(ret==-3)
  482. return ANS_NO_PRIV;
  483. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  484. return ANS_SYS_ERR;
  485. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  486. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskYecx->gddm);
  487. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  488. =(AskYecx->jys ==0)?'Z':'H';                        
  489. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],AskYecx->gpdm);      
  490. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_YECX;
  491. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  492.   wsprintf(temp,"%d",sd);
  493. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  494. wsprintf(temp,"%d",jyNum);
  495. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  496. ClearAns(lpJyDest);
  497.     wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  498.     remove(temp);
  499. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  500. CommBuffer)!=0)
  501. {
  502. ErrMsg(NULL, "不能写交换文件!");
  503. return ANS_SYS_ERR;
  504. }
  505. if(ChangeJyDest(sd, lpJyDest, REQ_YECX, AskYecx->jys, -1, jyNum) <0)
  506. return ANS_SYS_ERR;
  507. if(fTestJy)
  508. {
  509. Sleep(1000);
  510. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  511. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  512. if(hFile ==HFILE_ERROR)
  513. return 0;
  514. for(i=0;i<22;i++)
  515. {
  516. memset(CommBuffer,0,sizeof(CommBuffer));
  517. wsprintf(temp,"%04d",i+1);
  518. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  519. wsprintf(temp,"%8d",(i+1)*10);
  520. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);      
  521. wsprintf(temp,"%8d",(i+1)*20);
  522. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  523. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  524. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  525. _lwrite(hFile,&CommBuffer[1], rlen-1);
  526. _lwrite(hFile,"rn",2);
  527. }
  528. _lclose(hFile);
  529. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  530. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  531. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  532. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],"9000000.12");
  533. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],"2000000.99");
  534. wsprintf(temp,"%d",jyNum);
  535. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  536.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  537. CommBuffer);
  538. }
  539. return 0;
  540. }
  541. int Jy_Cjcx(int sd, int jyNum, LPJY_ASK_CJCX AskCjcx)
  542. {
  543. LPJY_DEST lpJyDest;
  544. int ret,i=0;
  545. char temp[20];
  546. HFILE hFile;
  547. OFSTRUCT os;
  548. ret =CheckJyDest(sd, REQ_CJCX, AskCjcx->jys, AskCjcx->gddm, AskCjcx->userId, &lpJyDest);
  549. if(ret==-1)
  550. return ANS_SYS_ERR;
  551. if(ret==-2)
  552. return ANS_SUSP_REQ;
  553. if(ret==-3)
  554. return ANS_NO_PRIV;
  555. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  556. return ANS_SYS_ERR;
  557.       
  558. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  559. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskCjcx->gddm);
  560. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  561. =(AskCjcx->jys ==0)?'Z':'H';                        
  562. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],AskCjcx->cjrq);      
  563. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskCjcx->hthm);      
  564. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_CJCX;
  565. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  566.   wsprintf(temp,"%d",sd);
  567. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  568. wsprintf(temp,"%d",jyNum);
  569. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  570. ClearAns(lpJyDest);
  571.     wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  572.     remove(temp);
  573. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  574. CommBuffer)!=0)
  575. {
  576. ErrMsg(NULL, "不能写交换文件!");
  577. return ANS_SYS_ERR;
  578. }
  579. if(ChangeJyDest(sd, lpJyDest, REQ_CJCX, AskCjcx->jys, -1, jyNum) <0)
  580. {
  581. ErrMsg(NULL,"来自Jy_Cjcx:ChangeJyDest");
  582. return ANS_SYS_ERR;
  583. }
  584. if(fTestJy)
  585. {
  586. Sleep(1000);
  587. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  588. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  589. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  590. wsprintf(temp,"%d",jyNum);
  591. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  592.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  593. CommBuffer);
  594. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  595. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  596. if(hFile ==HFILE_ERROR)
  597. return ANS_SYS_ERR;
  598. for(i=0;i<22;i++)
  599. {
  600. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=i-(int)(i/2)*2==0 ?'B':'S';
  601. wsprintf(temp,"%04d",i+1);
  602. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  603. wsprintf(temp,"%8d",(i+1)*100);
  604. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);      
  605. wsprintf(temp,"%8d",i+10);
  606. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  607. wsprintf(temp,"%06d",i+100);
  608. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],temp);      
  609. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  610. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  611. _lwrite(hFile,&CommBuffer[1], rlen-1);
  612. _lwrite(hFile,"rn",2);
  613. }
  614. _lclose(hFile);
  615. }
  616. return 0;
  617. }
  618. int Jy_Wtcx(int sd, int jyNum, LPJY_ASK_WTCX AskWtcx)
  619. {
  620. LPJY_DEST lpJyDest;
  621. int ret,i=0;
  622. char temp[20];
  623. HFILE hFile;
  624. OFSTRUCT os;
  625. ret =CheckJyDest(sd, REQ_WTCX, AskWtcx->jys, AskWtcx->gddm,
  626. AskWtcx->userId, &lpJyDest);
  627. if(ret==-1)
  628. return ANS_SYS_ERR;
  629. if(ret==-2)
  630. return ANS_SUSP_REQ;
  631. if(ret==-3)
  632. return ANS_NO_PRIV;
  633. if(ReqFile.hf[lpJyDest->zqsid] ==-1)
  634. return ANS_SYS_ERR;
  635. memset(CommBuffer,' ',*(short *)CommFile.dbfStruct.rlen);
  636. StringToFld(CommBuffer,CommFile.fldStruct[fld_GDDM],AskWtcx->gddm);
  637. CommBuffer[*(short*)(CommFile.fldStruct[fld_STKNO].offset)]
  638. =(AskWtcx->jys ==0)?'Z':'H';                        
  639. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],AskWtcx->wtrq);      
  640. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],AskWtcx->hthm);      
  641. CommBuffer[*(short*)(CommFile.fldStruct[fld_ASKNO].offset)]=REQ_WTCX;
  642. CommBuffer[*(short*)(CommFile.fldStruct[fld_JYMM].offset)]=AskWtcx->cdcx;
  643. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  644. wsprintf(temp,"%d",sd);
  645. StringToFld(CommBuffer,CommFile.fldStruct[fld_ADDR],temp);
  646. wsprintf(temp,"%d",jyNum);
  647. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  648. ClearAns(lpJyDest);
  649.     wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  650.     remove(temp);
  651. if(WriteRecord(ReqFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,rlen,
  652. CommBuffer)!=0)
  653. {
  654. ErrMsg(NULL, "不能写交换文件!");
  655. return ANS_SYS_ERR;
  656. }
  657. if(ChangeJyDest(sd, lpJyDest, REQ_WTCX, AskWtcx->jys, -1, jyNum) <0)
  658. return ANS_SYS_ERR;
  659. if(fTestJy)
  660. {
  661. Sleep(1000);
  662. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=ANS_SUCC;
  663. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  664. StringToFld(CommBuffer,CommFile.fldStruct[fld_JYMM],"22");
  665. wsprintf(temp,"%d",jyNum);
  666. StringToFld(CommBuffer,CommFile.fldStruct[fld_SERI],temp);
  667.     WriteRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  668. rlen,CommBuffer);
  669. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  670. hFile =OpenFile(temp, &os, OF_CREATE|OF_SHARE_DENY_NONE|OF_WRITE);
  671. if(hFile ==HFILE_ERROR)
  672. return ANS_SYS_ERR;
  673. for(i=0;i<22;i++)
  674. {
  675. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)]=i-(int)(i/2)*2==0 ?'B':'S';
  676. wsprintf(temp,"%04d",i+1);
  677. StringToFld(CommBuffer,CommFile.fldStruct[fld_GPDM],temp);      
  678. wsprintf(temp,"%8d",(i+1)*100);
  679. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTGS],temp);
  680. wsprintf(temp,"%8d",i+10);
  681. StringToFld(CommBuffer,CommFile.fldStruct[fld_WTJG],temp);      
  682. wsprintf(temp,"%06d",i+100);
  683. StringToFld(CommBuffer,CommFile.fldStruct[fld_HTHM],temp);      
  684. StringToFld(CommBuffer,CommFile.fldStruct[fld_DATE],"111111");      
  685. CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)]=';';
  686. _lwrite(hFile,&CommBuffer[1], rlen-1);
  687. _lwrite(hFile,"rn",2);
  688. }
  689. _lclose(hFile);
  690. }
  691. return 0;
  692. }
  693. int JyDest_ChkUsr(LPJY_DEST lpJyDest)
  694. {
  695. BYTE SendBuff[2048];
  696. int ret, len;
  697. char stat,temp[10];
  698.     JY_ANS_CHKUSR AnsUser;
  699. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  700. rlen,CommBuffer);
  701. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  702. if(stat !=';') 
  703. return 0;
  704. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  705. if(lpJyDest->jyNum!=atoi(temp)) 
  706. return 0;
  707. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  708. if(ret==' ')
  709. return 0;
  710. strcpy(SendBuff, JY_CHKUSR_HEAD);
  711. len =strlen(SendBuff);
  712. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  713. len +=sizeof(short);
  714. AnsUser.jys=lpJyDest->curJys;
  715.     AnsUser.userId=lpJyDest->userId;
  716. strcpy(AnsUser.gddm,lpJyDest->gddm);
  717. AnsUser.flag=(char)ret;
  718. memcpy(&SendBuff[len],&AnsUser,sizeof(JY_ANS_CHKUSR));
  719. len+=sizeof(AnsUser);
  720. UDP_SendBuff("检查交易用户", lpJyDest->sd, SendBuff, len,NULL);  
  721. lpJyDest->isReqEnd =TRUE;
  722. ClearReq(lpJyDest);
  723. return 0;
  724. }
  725.        
  726. int JyDest_ChgPwd(LPJY_DEST lpJyDest)
  727. {
  728. BYTE SendBuff[100];
  729. int ret, stat, len;
  730. JY_ANS_CHGPWD AnsChgPwd;
  731.     char temp[10];
  732. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,hlen,
  733. rlen,CommBuffer);
  734. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  735. if(stat !=';') 
  736. return 0;
  737. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  738. if(lpJyDest->jyNum!=atoi(temp)) 
  739. return 0;
  740. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  741. if(ret==' ')
  742. return 0;
  743. AnsChgPwd.flag =(char)ret;
  744. AnsChgPwd.jys =lpJyDest->curJys;
  745. strcpy(SendBuff, JY_CHGPWD_HEAD);
  746. len =strlen(SendBuff);
  747. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  748. len +=sizeof(short);
  749. strcpy(AnsChgPwd.gddm, lpJyDest->gddm);
  750. memcpy(&SendBuff[len], &AnsChgPwd, sizeof(AnsChgPwd));
  751. len +=sizeof(AnsChgPwd);
  752. UDP_SendBuff("修改交易密码", lpJyDest->sd, SendBuff, len, NULL);
  753. lpJyDest->isReqEnd =TRUE;
  754. ClearReq(lpJyDest);
  755. return 0;
  756. }
  757.        
  758. int JyDest_BuySell(LPJY_DEST lpJyDest)
  759. {
  760. char hthm[20],temp[10];
  761. BYTE SendBuff[100];
  762. int stat, ret, len;
  763.     JY_ANS_BUYSELL AnsBuySell; 
  764. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  765. hlen,rlen,CommBuffer);
  766. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  767. if(stat !=';') 
  768. return 0;
  769. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  770. if(lpJyDest->jyNum!=atoi(temp)) 
  771. return 0;
  772. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  773. if(ret==' ')
  774. return 0;
  775. hthm[0] =0;
  776. if(ret==ANS_SUCC)
  777. {
  778. FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],hthm);
  779. memset(temp,' ',(short)CommFile.fldStruct[fld_HTHM].wid);
  780. if(strncmp(hthm,temp,(short)CommFile.fldStruct[fld_HTHM].wid)==0)
  781. return 0;
  782. }
  783. AnsBuySell.jys=lpJyDest->curJys;
  784. strcpy(AnsBuySell.gddm,lpJyDest->gddm);
  785. strcpy(AnsBuySell.hthm,hthm);
  786. AnsBuySell.bs=REQ_BUYSEL;
  787. AnsBuySell.flag=(char)ret;
  788. strcpy(SendBuff, JY_BUYSELL_HEAD);
  789. len =strlen(SendBuff);
  790. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  791. len +=sizeof(short);
  792. memcpy(&SendBuff[len],&AnsBuySell,sizeof(AnsBuySell));
  793. len+=sizeof(AnsBuySell);
  794. UDP_SendBuff("买卖委托", lpJyDest->sd, SendBuff, len, NULL);
  795. lpJyDest->isReqEnd =TRUE;
  796. ClearReq(lpJyDest);
  797. return 0;
  798. }
  799.        
  800. int JyDest_Cancel(LPJY_DEST lpJyDest)
  801. {
  802. BYTE SendBuff[600];
  803. int ret, stat, len, i,retnum;
  804. JY_ANS_CANCEL AnsCancel;
  805. char temp[20],tmp[13];
  806. HFILE hFile;
  807. OFSTRUCT os;
  808. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  809. hlen,rlen,CommBuffer);
  810. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  811. if(stat!=';') 
  812. return 0;
  813. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  814. if(lpJyDest->jyNum!=atoi(temp)) 
  815. return 0;
  816. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  817. if(ret==' ')
  818. return 0;
  819. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  820. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  821. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  822. return 0;
  823. retnum=atoi(temp);
  824. if(ret!=ANS_SUCC)
  825. AnsCancel.flag[0] =ret;
  826. else
  827. {
  828. if(retnum==1)
  829. {
  830. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  831. AnsCancel.flag[0] =ret;
  832. }
  833. else
  834. {
  835. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  836. hFile =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READ);
  837. if(hFile ==HFILE_ERROR)
  838. return 0;
  839. i=_llseek(hFile, 0L, FILE_END);
  840. if(i==HFILE_ERROR)
  841. {
  842. _lclose(hFile);
  843. return 0;
  844. }
  845. if((i-1)/(rlen+1)!=retnum)
  846. {
  847. _lclose(hFile);
  848. return 0;
  849. }
  850. _llseek(hFile, 0L, FILE_BEGIN);
  851. for(i =0; i<retnum; i++)
  852. {
  853. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  854. break;
  855. ret=CommBuffer[*(int*)(CommFile.fldStruct[fld_ANSNO].offset)];
  856. AnsCancel.flag[i] =ret;
  857. _llseek(hFile, 2L, FILE_CURRENT);
  858. }
  859. _lclose(hFile);
  860. remove(temp);
  861. }
  862. }
  863. AnsCancel.jys =lpJyDest->curJys;
  864. strcpy(AnsCancel.gddm, lpJyDest->gddm);
  865. strcpy(SendBuff, JY_CANCEL_HEAD);
  866. len =strlen(SendBuff);
  867. *(short *)&SendBuff[len] =lpJyDest->jyNum;
  868. len +=sizeof(short);
  869. memcpy(&SendBuff[len], &AnsCancel, sizeof(AnsCancel));
  870. len +=sizeof(AnsCancel);
  871. UDP_SendBuff("撤消委托", lpJyDest->sd, SendBuff, len,NULL);
  872. lpJyDest->isReqEnd =TRUE;
  873. ClearReq(lpJyDest);
  874. return 0;
  875. }
  876.        
  877. int JyDest_Yecx(LPJY_DEST lpJyDest)
  878. {
  879. char temp[40],tmp[40];
  880. JY_ANS_YECX AnsYecx;
  881. int ret, i,retnum;
  882. char stat;
  883. HFILE hFile;
  884. OFSTRUCT os;
  885.     HANDLE hd;
  886. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  887. hlen,rlen,CommBuffer);
  888. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  889. if(stat !=';') 
  890. return 0;
  891. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  892. if(lpJyDest->jyNum!=atoi(temp)) 
  893. return 0;
  894. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  895. if(ret==' ')
  896. return 0;
  897. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  898. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  899. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  900. return 0;
  901. retnum=atoi(temp);
  902. if(ret==ANS_SUCC&&retnum>0)
  903. {
  904. wsprintf(tmp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  905. hFile =OpenFile(tmp, &os, OF_SHARE_DENY_NONE|OF_READ);
  906. if(hFile ==HFILE_ERROR)
  907. return 0;
  908. i=_llseek(hFile, 0L, FILE_END);
  909. if(i==HFILE_ERROR)
  910. {
  911. _lclose(hFile);
  912. return 0;
  913. }
  914. if((i)/(rlen+1)<retnum)
  915. {
  916. _lclose(hFile);
  917. return 0;
  918. }
  919. _llseek(hFile, 0L, FILE_BEGIN);
  920. }
  921. if(ret==ANS_SUCC)
  922. {
  923. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],temp);
  924. AnsYecx.kys=atof(temp);      
  925. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],temp);
  926. AnsYecx.zjye=atof(temp);     
  927. if(retnum>0)
  928. {
  929. //AnsYecx.lpGptg=(LPJY_GPTG)malloc(sizeof(JY_GPTG)*retnum);
  930. hd =GlobalAlloc(GHND,sizeof(JY_GPTG)*retnum);
  931. AnsYecx.lpGptg=GlobalLock(hd);
  932. memset(&AnsYecx.lpGptg[0],0,sizeof(JY_GPTG)*retnum);
  933. }
  934. for(i=0;i<retnum;i++)
  935. {
  936. memset(CommBuffer,0,sizeof(CommBuffer));
  937. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  938. break;
  939. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  940. &AnsYecx.lpGptg[i].gpdm[0]);
  941. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  942. &AnsYecx.lpGptg[i].kys[0]);
  943. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  944. &AnsYecx.lpGptg[i].gpye[0]);
  945. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  946. &AnsYecx.lpGptg[i].ghrq[0]);
  947. _llseek(hFile, 2L, FILE_CURRENT);
  948. }
  949. if(retnum>0)
  950. {
  951. _lclose(hFile);
  952. remove(tmp);
  953. }
  954. AnsYecx.recnum=retnum;
  955. AnsYecx.flag=ret;
  956. if(AnsYecx.recnum >=0)
  957. {
  958. lpJyDest->isSending =TRUE;
  959. Thrd_SendJycx(REQ_YECX, lpJyDest->sd, &AnsYecx, lpJyDest->jyNum);
  960. if(retnum>0)
  961. {
  962. //free(AnsYecx.lpGptg);
  963. GlobalUnlock(hd);
  964. GlobalFree(hd);
  965. }
  966. lpJyDest->isSending =FALSE;
  967. }
  968. }
  969. else
  970. {
  971. lpJyDest->isReqEnd =TRUE;
  972.         ClearReq(lpJyDest);
  973.      return ret;
  974. }
  975. lpJyDest->isReqEnd =TRUE;
  976. ClearReq(lpJyDest);
  977. return 0;
  978. }
  979.        
  980. int JyDest_Cjcx(LPJY_DEST lpJyDest)
  981. {
  982. JY_ANS_CJCX AnsCjcx;
  983. int i, ret,retnum;
  984. char stat, temp[40],tmp[40];
  985. HFILE hFile;
  986. OFSTRUCT os;
  987. HANDLE hd;
  988. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  989. hlen,rlen,CommBuffer);
  990. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];                     
  991. if(stat !=';') 
  992. return 0;
  993. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  994. if(lpJyDest->jyNum!=atoi(temp)) 
  995. return 0;
  996. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  997. if(ret==' ')
  998. return 0;
  999. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1000. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1001. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1002. return 0;
  1003. retnum=atoi(temp);
  1004. if(ret==ANS_SUCC&&retnum>0)
  1005. {
  1006. wsprintf(tmp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1007. hFile =OpenFile(tmp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1008. if(hFile ==HFILE_ERROR)
  1009. return 0;
  1010. i=_llseek(hFile, 0L, FILE_END);
  1011. if(i==HFILE_ERROR)
  1012. {
  1013. _lclose(hFile);
  1014. return 0;
  1015. }
  1016. if((i)/(rlen+1)<retnum)
  1017. {
  1018. _lclose(hFile);
  1019. return 0;
  1020. }
  1021. _llseek(hFile, 0L, FILE_BEGIN);
  1022. }
  1023. if(ret==ANS_SUCC)
  1024. if(retnum>0)
  1025. {
  1026. //AnsCjcx.lpCj=(LPJY_CJ)malloc(sizeof(JY_CJ)*retnum);
  1027. hd =GlobalAlloc(GHND,sizeof(JY_CJ)*retnum);
  1028. AnsCjcx.lpCj=GlobalLock(hd);
  1029. memset(&AnsCjcx.lpCj[0],0,sizeof(JY_CJ)*retnum);
  1030. }
  1031. for(i=0;i<retnum;i++)
  1032. {
  1033. memset(CommBuffer,0,sizeof(CommBuffer));
  1034. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1035. break;
  1036. FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],
  1037. &AnsCjcx.lpCj[i].hthm[0]);
  1038. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  1039. &AnsCjcx.lpCj[i].cjsj[0]);
  1040. AnsCjcx.lpCj[i].mmbz=
  1041. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1042. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  1043. &AnsCjcx.lpCj[i].gpdm[0]);
  1044. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  1045. &AnsCjcx.lpCj[i].cjgs[0]);
  1046. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  1047. &AnsCjcx.lpCj[i].cjjg[0]);
  1048. _llseek(hFile, 2L, FILE_CURRENT);
  1049. }
  1050. if(retnum>0)
  1051. {
  1052. _lclose(hFile);
  1053. remove(tmp);
  1054. }
  1055. AnsCjcx.recnum=retnum;
  1056. AnsCjcx.flag =ret;
  1057. if(AnsCjcx.recnum >=0)
  1058. {
  1059. lpJyDest->isSending =TRUE;
  1060. Thrd_SendJycx(REQ_CJCX, lpJyDest->sd, &AnsCjcx, lpJyDest->jyNum);
  1061. if(retnum>0)
  1062. {
  1063. //free(AnsCjcx.lpCj);
  1064. GlobalUnlock(hd);
  1065. GlobalFree(hd);
  1066. }
  1067. lpJyDest->isSending =FALSE;
  1068. }
  1069. }
  1070. else
  1071. {
  1072. lpJyDest->isReqEnd =TRUE;
  1073. ClearReq(lpJyDest);
  1074. return ret;
  1075. }
  1076. lpJyDest->isReqEnd =TRUE;
  1077. ClearReq(lpJyDest);
  1078. return 0;
  1079. }
  1080. int JyDest_Wtcx(LPJY_DEST lpJyDest)
  1081. {
  1082. JY_ANS_WTCX AnsWtcx;
  1083. int ret, i,retnum;
  1084. char stat, temp[40],tmp[40];
  1085. HFILE hFile;
  1086. OFSTRUCT os;
  1087. HANDLE hd;
  1088. ReadRecord(AnsFile.hf[lpJyDest->zqsid],lpJyDest->recNum,
  1089. hlen,rlen,CommBuffer);
  1090. stat=CommBuffer[*(short*)(CommFile.fldStruct[fld_STAT].offset)];
  1091. if(stat !=';') 
  1092. return 0;
  1093. FldToString(CommBuffer,&CommFile.fldStruct[fld_SERI],temp);
  1094. if(lpJyDest->jyNum!=atoi(temp)) return 0;
  1095. ret=CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1096. if(ret==' ')
  1097. return 0;
  1098. FldToString(CommBuffer,&CommFile.fldStruct[fld_JYMM],temp);
  1099. memset(tmp,' ',(short)CommFile.fldStruct[fld_JYMM].wid);
  1100. if(ret==ANS_SUCC&&strncmp(temp,tmp,(short)CommFile.fldStruct[fld_JYMM].wid)==0)
  1101. return 0;
  1102. retnum=atoi(temp);
  1103. if(ret==ANS_SUCC&&retnum>0)
  1104. {
  1105. wsprintf(temp,"%s%d%s",AnsFile.path[lpJyDest->zqsid],lpJyDest->recNum,".ANS");
  1106. hFile =OpenFile(temp, &os, OF_SHARE_DENY_NONE|OF_READ);
  1107. if(hFile ==HFILE_ERROR)
  1108. return 0;
  1109. i=_llseek(hFile, 0L, FILE_END);
  1110. if(i==HFILE_ERROR)
  1111. {
  1112. _lclose(hFile);
  1113. return 0;
  1114. }
  1115. if((i)/(rlen+1)<retnum)
  1116. {
  1117. _lclose(hFile);
  1118. return 0;
  1119. }
  1120. _llseek(hFile, 0L, FILE_BEGIN);
  1121. }
  1122. if(ret==ANS_SUCC)
  1123. if(retnum>0)
  1124. {
  1125. //AnsWtcx.lpWt=(LPJY_WT)malloc(sizeof(JY_WT)*retnum);
  1126. hd =GlobalAlloc(GHND,sizeof(JY_WT)*retnum);
  1127. AnsWtcx.lpWt =GlobalLock(hd);
  1128. memset(&AnsWtcx.lpWt[0], 0, sizeof(JY_WT)*retnum);
  1129. }
  1130. for(i=0;i<retnum;i++)
  1131. {
  1132. memset(CommBuffer,0,sizeof(CommBuffer));
  1133. if((short)_lread(hFile,&CommBuffer[1],rlen -1)!=rlen -1)
  1134. break;
  1135. FldToString(CommBuffer,&CommFile.fldStruct[fld_HTHM],
  1136. &AnsWtcx.lpWt[i].hthm[0]);
  1137. FldToString(CommBuffer,&CommFile.fldStruct[fld_DATE],
  1138. &AnsWtcx.lpWt[i].wtsj[0]);
  1139. AnsWtcx.lpWt[i].mmbz=
  1140. CommBuffer[*(short*)(CommFile.fldStruct[fld_ANSNO].offset)];
  1141. FldToString(CommBuffer,&CommFile.fldStruct[fld_GPDM],
  1142. &AnsWtcx.lpWt[i].gpdm[0]);
  1143. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTGS],
  1144. &AnsWtcx.lpWt[i].wtgs[0]);
  1145. FldToString(CommBuffer,&CommFile.fldStruct[fld_WTJG],
  1146. &AnsWtcx.lpWt[i].wtjg[0]);
  1147. _llseek(hFile, 2L, FILE_CURRENT);
  1148. }
  1149. if(retnum>0)
  1150. {
  1151. _lclose(hFile);
  1152. remove(tmp);
  1153. }
  1154. AnsWtcx.recnum=retnum;
  1155. AnsWtcx.flag =ret;
  1156. if(AnsWtcx.recnum >=0)
  1157. {
  1158. lpJyDest->isSending =TRUE;
  1159. Thrd_SendJycx(REQ_WTCX, lpJyDest->sd, &AnsWtcx, lpJyDest->jyNum);
  1160. if(AnsWtcx.recnum>0)
  1161. {
  1162. //free(AnsWtcx.lpWt);
  1163. GlobalUnlock(hd);
  1164. GlobalFree(hd);
  1165. }
  1166. lpJyDest->isSending =FALSE;
  1167. }
  1168. }
  1169. else
  1170. {
  1171. lpJyDest->isReqEnd =TRUE;
  1172. ClearReq(lpJyDest);
  1173. return ret;
  1174. }
  1175. lpJyDest->isReqEnd =TRUE;
  1176. ClearReq(lpJyDest);
  1177. return 0;
  1178. }
  1179. int Thrd_SendJycx(int reqType, int sd, char *lpBuf, int jyNum)
  1180. {
  1181. char SendBuff[2048];
  1182. LPJY_ANS_YECX lpAnsYecx;
  1183. LPJY_ANS_CJCX lpAnsCjcx;
  1184. LPJY_ANS_WTCX lpAnsWtcx;
  1185. int i, len, recCount, sendCount, sendNum;
  1186. sendNum =0;
  1187. sendCount =MAX_CX_SENDCOUNT;
  1188. switch(reqType)
  1189. {
  1190. case REQ_YECX:
  1191. lpAnsYecx =(LPJY_ANS_YECX)lpBuf;
  1192. recCount =lpAnsYecx->recnum;
  1193. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1194. {
  1195. sendNum =i*MAX_CX_SENDCOUNT;
  1196. if(sendNum+sendCount >recCount)
  1197. sendCount =recCount-sendNum;
  1198. strcpy(SendBuff, JY_YECX_HEAD);
  1199. len =strlen(SendBuff);
  1200. *(short *)&SendBuff[len] =jyNum;
  1201. len +=sizeof(short);
  1202. lpAnsYecx->recnum=sendCount;
  1203. memcpy(&SendBuff[len],lpAnsYecx,sizeof(JY_ANS_YECX)-sizeof(LPJY_GPTG));
  1204.             len+=sizeof(JY_ANS_YECX)-sizeof(LPJY_GPTG);
  1205. if(sendCount==0&&sendNum!=0)
  1206. break;
  1207. if(sendCount>0)
  1208. {
  1209. memcpy(&SendBuff[len], &lpAnsYecx->lpGptg[sendNum],
  1210. sizeof(JY_GPTG)*sendCount);
  1211. len +=sizeof(JY_GPTG)*sendCount;
  1212. }
  1213. if(UDP_SendBuff("余额查询", sd, SendBuff, len,NULL)<0)
  1214. return -1;
  1215. }
  1216. break;
  1217. case REQ_CJCX:
  1218. lpAnsCjcx =(LPJY_ANS_CJCX)lpBuf;
  1219. recCount =lpAnsCjcx->recnum;
  1220. sendCount =MAX_CX_SENDCOUNT;
  1221. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1222. {
  1223. sendNum =i*MAX_CX_SENDCOUNT;
  1224. if(sendNum+sendCount >recCount)
  1225. sendCount =recCount-sendNum;
  1226. strcpy(SendBuff, JY_CJCX_HEAD);
  1227. len =strlen(SendBuff);
  1228. *(short *)&SendBuff[len] =jyNum;
  1229. len +=sizeof(short);
  1230. lpAnsCjcx->recnum=sendCount;
  1231.             memcpy(&SendBuff[len],lpAnsCjcx,sizeof(JY_ANS_CJCX)-sizeof(LPJY_CJ));
  1232.             len+=sizeof(JY_ANS_CJCX)-sizeof(LPJY_CJ);
  1233. if(sendCount==0&&sendNum!=0)
  1234. break;
  1235. if(sendCount>0)
  1236. {
  1237.   memcpy(&SendBuff[len], &lpAnsCjcx->lpCj[sendNum],
  1238. sizeof(JY_CJ)*sendCount);
  1239. len +=sizeof(JY_CJ)*sendCount;
  1240. }
  1241. if(UDP_SendBuff("成交查询", sd, SendBuff, len,NULL)<0)
  1242. return -1; 
  1243. }
  1244. break;
  1245. case REQ_WTCX:
  1246. lpAnsWtcx =(LPJY_ANS_WTCX)lpBuf;
  1247. recCount =lpAnsWtcx->recnum;
  1248. sendCount =MAX_CX_SENDCOUNT;
  1249. for(i =0; i<=recCount/MAX_CX_SENDCOUNT; i++)
  1250. {
  1251. sendNum =i*MAX_CX_SENDCOUNT;
  1252. if(sendNum+sendCount >recCount)
  1253. sendCount =recCount-sendNum;
  1254. strcpy(SendBuff, JY_WTCX_HEAD);
  1255. len =strlen(SendBuff);
  1256. *(short *)&SendBuff[len] =jyNum;
  1257. len +=sizeof(short);
  1258. lpAnsWtcx->recnum=sendCount;
  1259. memcpy(&SendBuff[len],lpAnsWtcx,sizeof(JY_ANS_WTCX)-sizeof(LPJY_WT));
  1260.             len+=sizeof(JY_ANS_WTCX)-sizeof(LPJY_WT);
  1261. if(sendCount>0)
  1262. {
  1263. memcpy(&SendBuff[len], &lpAnsWtcx->lpWt[sendNum],
  1264. sizeof(JY_WT)*sendCount);
  1265. len +=sizeof(JY_WT)*sendCount;
  1266. }
  1267. if(sendCount==0&&sendNum!=0)
  1268. break;
  1269. if(UDP_SendBuff("委托查询", sd, SendBuff, len,NULL)<0)
  1270. return -1;
  1271. }
  1272. break;
  1273. }
  1274. strcpy(SendBuff, JY_CXEND_HEAD);
  1275. len =strlen(SendBuff);
  1276. UDP_SendBuff("查询成功", sd, SendBuff, len,NULL);
  1277. return 0;
  1278. }
  1279. int Jy_SendRet(int sd, char reqType, char ret, int jyNum)
  1280. {
  1281. int len;
  1282. BYTE SendBuff[100];
  1283. LPSTR lpHead;
  1284. if(ret ==ANS_TIME_OUT)
  1285. lpHead =JY_TIMEOUT_HEAD;
  1286. else
  1287. switch(reqType)
  1288. {
  1289. case REQ_CHKUSR:
  1290. lpHead =JY_CHKUSR_HEAD;
  1291. break;
  1292. case REQ_CHGPWD:
  1293. lpHead =JY_CHGPWD_HEAD;
  1294. break;
  1295. case REQ_BUYSEL:
  1296. lpHead =JY_BUYSELL_HEAD;
  1297. break;
  1298. case REQ_CANCEL:
  1299. lpHead =JY_CANCEL_HEAD;
  1300. break;
  1301. case REQ_YECX:
  1302. lpHead =JY_YECX_HEAD;
  1303. break;
  1304. case REQ_CJCX:
  1305. lpHead =JY_CJCX_HEAD;
  1306. break;
  1307. case REQ_WTCX:
  1308. lpHead =JY_WTCX_HEAD;
  1309. break;
  1310. }
  1311. strcpy(SendBuff, lpHead);
  1312. len =strlen(SendBuff);
  1313. *(short *)&SendBuff[len] =jyNum;
  1314. len +=sizeof(short);
  1315. SendBuff[len++] =(char)ret;
  1316. UDP_SendBuff("发送结果", sd, SendBuff, len,NULL);
  1317. return 0;
  1318. }