test_tran.ec
来自「在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便」· EC 代码 · 共 352 行
EC
352 行
/****************************************************
* 响应时间 -- test_tran()
*
* 最后修改: 周国祥 2001/08/26
****************************************************/
#include <stdio.h>
#include <curses.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <time.h>
#include "macro_def.h"
#include "public.h"
#include "mytools.h"
#include "msgapi.h"
#include "msgsys.h"
#include "tool.h"
$include "db_struct.h"
EXEC SQL INCLUDE sqlca;
EXEC SQL WHENEVER SQLERROR CALL error_handler;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler;
EXEC SQL WHENEVER NOT FOUND CALL notfound_handler;
int set_cardno();
int test_tran()
{
char bankids[50][12], hostids[50][3], banknames[50][31];
char filename[128], buf[128], tmp[20], tmp1[20], tmp2[20];
int Req_msgid, Resp_msgid, i, j, num;
int inqall = 0;
struct timeb begin_t[50], end_t;
WINDOW *my_win;
PUBLIC pub;
$long count;
$short indi;
$char bankid[12], hostid[3],bankname[31], merchant_id[16];
$S_sys_param sys;
$char sqlstr[1024];
tmp[0] = 0;
sprintf(filename, "/tmp/.test_tran.%d", getpid());
scr_dump(filename);
disp_below("响应时间");
clear_wline(stdscr, LINES-1);
h_prompt(LINES-1, 1, " < ESC 退出 > ", 0, 0);
h_prompt(LINES-1, 1, "响应时间", 0, 0);
my_win = newwin(19, 80, 3, 0);
mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
wrefresh(my_win);
if (no_init()) {
h_winprompt(my_win, 17, 4, "系统未启动!", 1, 0);
goto quit;
}
Req_msgid = gmsg_nonb(REQ_MSG);
Resp_msgid = gmsg_nonb(RESP_MSG);
if (Req_msgid < 0 || Resp_msgid < 0) {
h_winprompt(my_win, 17, 4, "系统故障!", 1, 0);
errcall(ERROR, "Get message queue error!");
goto quit;
}
memset(&pub, 0, sizeof(PUBLIC));
pub.Source_msg_type = getpid();
if (message_r_login(Resp_msgid, pub.Source_msg_type) < 0) {
h_winprompt(my_win, 17, 4, "系统故障!", 1, 0);
errcall(ERROR, "Login message queue error!");
goto quit;
}
set_prompt(PROMPT_OFF);
bankid[0] = 0;
strcpy(hostid, "00");
bankname[0] = 0;
mvwprintw(my_win, 2, 14, "联行行号: [%-11.11s][%-2.2s] [%-30.30s]", "", "","");
if (in_item(my_win, "", 2, 25, bankid, 11, NULL, NULL, 0, 0) !=
ENTER) goto end;
if (in_item(my_win, "", 2, 38, hostid, 2, NULL, NULL, 0, 0) !=
ENTER) goto end;
if(bankid[0] == '*')
{
inqall = 1;
bankid[0] = 0;
} else {
i = get_bank_name(bankid, hostid, bankname);
if (bankid[0] && i) {
h_winprompt(my_win, 17, 4, "无此联行行号!", 1, 0);
goto end;
}
mvwprintw(my_win, 2, 43, "%-30.30s", bankname);
wrefresh(my_win);
}
$select * into $sys from sys_param;
if (SQLCODE) {
errcall(ERROR, "Unable access sys_param!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto end;
}
del_st_space("sys_param", &sys);
if ( !bankid[0] && inqall == 0 ) {
$select count(*) into $count:indi
from bank_info
where (not (bank_id = adm_bank_id and host_id = adm_host_id))
and adm_bank_id = $sys.bank_id
and adm_host_id = $sys.host_id;
if (SQLCODE != 100 && SQLCODE) {
errcall(ERROR, "Unable access bank_info!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto end;
}
if (count == 0 || indi == -1) {
strcpy(bankid, sys.adm_bank_id);
strcpy(hostid, sys.adm_host_id );
get_bank_name(bankid, hostid,bankname);
mvwprintw(my_win, 2, 25, "%-11.11s", bankid);
mvwprintw(my_win, 2, 38, "%-2.2s", hostid);
mvwprintw(my_win, 2, 43, "%-30.30s", bankname);
wrefresh(my_win);
}
}
strcpy(pub.Msg_id, "0200");
pub.Tran_type = PURCHASE;
strcpy(pub.Acq_bank_id, "LOCAL");
strcpy(pub.Exp_date, "1001");
strcpy(pub.Input_mode,"011");
strcpy(pub.Terminal_id, "TEL_AUTH");
sprintf(pub.Merchant_id, "%4.4s000000", sys.bank_id);
sprintf(pub.Tran_amount, "%012ld", 10000);
strcpy(pub.Ccy_code, "156");
if (bankid[0]) {
mvwprintw(my_win, 4, 14, "处理中, 请稍候 ...");
wrefresh(my_win);
sprintf(pub.Card_no, "8%4.4s00000000000", bankid);
#ifdef zgx010730_del
set_cardno( pub.Card_no );
#endif
ftime(begin_t);
i = message_send(Req_msgid, (char *)&pub, sizeof(PUBLIC),
SWITCH_HOSTID, 3, 0);
if (i < 0) {
errcall(ERROR, "Send message error! (%d)", i);
h_winprompt(my_win, 17, 4, "MsgSnd Error!", 1, 0);
goto end;
}
i = message_recv(Resp_msgid, (char *)&pub, sizeof(PUBLIC),
&(pub.Source_msg_type), 66, 0);
if (i < 0) {
errcall(ERROR, "Recv message error! (%d)", i);
h_winprompt(my_win, 17, 4, "MsgRcv Error!", 1, 0);
goto end;
}
ftime(&end_t);
/*================== WuBin 2001-10-20 12:10 ======Start==============
get_retmsg(pub.Resp_code, tmp);
===========================2001-10-20 12:10=======End==============*/
tmp[0] = 0;
if (pub.Resp_code[0] != 0) {
if (!strcmp(pub.Resp_code, "00"))
strcpy(tmp, "系统正常");
if (!strcmp(pub.Resp_code, "56"))
strcpy(tmp, "非联网行");
if (!strcmp(pub.Resp_code, "68"))
strcpy(tmp, "连接超时");
if (!strcmp(pub.Resp_code, "79"))
strcpy(tmp, "系统繁忙");
if (!strcmp(pub.Resp_code, "88"))
strcpy(tmp, "网络错误");
if (!strcmp(pub.Resp_code, "91"))
strcpy(tmp, "网络故障");
}
/*================== WuBin 2001-10-20 12:12 ======Start==============
sprintf(tmp1, "%s-%s", pub.Resp_bank_id, pub.Resp_host_id);
mvwprintw(my_win, 4, 4,
"回应信息: %2.2s %-10.10s 响应行: %-12.12s 响应时间: %6ld 毫秒",
pub.Resp_code, tmp, tmp1,
(end_t.time - begin_t[0].time) * 1000 +
end_t.millitm - begin_t[0].millitm);
===========================2001-10-20 12:12=======End==============*/
sprintf(tmp1, "%s-%s", pub.Resp_bank_id, pub.Resp_host_id);
mvwprintw(my_win, 4, 4,
"回应信息: %-10.10s 响应行: %-12.12s 响应时间: %6ld 毫秒",
tmp, tmp1,
(end_t.time - begin_t[0].time) * 1000 +
end_t.millitm - begin_t[0].millitm);
wgetch(my_win);
} else {
mvwprintw(my_win, 4, 14, "处理中, 请稍候 ...");
wrefresh(my_win);
if (inqall == 0) {
sprintf(sqlstr,
"select bank_id, host_id, bank_name \
from bank_info \
where (not (bank_id = adm_bank_id and \
host_id = adm_bank_id )) \
and adm_bank_id = %s \
and adm_host_id = %s", sys.bank_id, sys.host_id);
} else
sprintf(sqlstr, "select bank_id,host_id,bank_name from bank_info");
$prepare s_comm from $sqlstr;
$declare tran_cur cursor for s_comm;
$open tran_cur;
if (SQLCODE) {
errcall(ERROR, "Open tran_cur error!");
h_winprompt(my_win, 17, 4, "数据库操作错误!", 1, 0);
goto end;
}
num = 0;
while (1) {
$fetch tran_cur into $bankid, $hostid, $bankname;
DelSpace(bankid);
DelSpace(hostid);
DelSpace(bankname);
if ( !strcmp( bankid, sys.bank_id ) &&
!strcmp( hostid, sys.host_id ) )
continue;
if (SQLCODE)
break;
sprintf(pub.Card_no, "8%4.4s00000000000", bankid);
#ifdef zgx010730_del
set_cardno( pub.Card_no );
#endif
strcpy(bankids[num], bankid);
strcpy(hostids[num], hostid);
strcpy(banknames[num], bankname);
ftime(&begin_t[num]);
num++;
i = message_send(Req_msgid, (char *)&pub,
sizeof(PUBLIC), SWITCH_HOSTID, 3, 0);
if (i < 0) {
errcall(ERROR, "Send message error! (%d)", i);
h_winprompt(my_win, 17, 4,
"MsgSnd Error!", 1, 0);
$close tran_cur;
goto end;
}
}
$close tran_cur;
sprintf(buf, "%-11.11s %-20.20s %-10.10s %-11.11s %-14.14s",
"联行行号", "联行名称", "回应信息",
"响应行", "响应时间(毫秒)");
CreateList(16, 80, 6, 0, buf);
for (j = 0; j < num; j++) {
i = message_recv(Resp_msgid, (char *)&pub,
sizeof(PUBLIC), &(pub.Source_msg_type), 66, 0);
if (i < 0) {
errcall(ERROR, "Recv message error! (%d)", i);
i=num;
break;
}
ftime(&end_t);
/*================== WuBin 2001-10-20 12:09 ======Start==============
get_retmsg(pub.Resp_code, tmp);
===========================2001-10-20 12:09=======End==============*/
if (pub.Resp_code[0] != 0) {
if (!strcmp(pub.Resp_code, "00"))
strcpy(tmp, "系统正常");
if (!strcmp(pub.Resp_code, "56"))
strcpy(tmp, "非联网行");
if (!strcmp(pub.Resp_code, "68"))
strcpy(tmp, "连接超时");
if (!strcmp(pub.Resp_code, "79"))
strcpy(tmp, "系统繁忙");
if (!strcmp(pub.Resp_code, "88"))
strcpy(tmp, "网络错误");
if (!strcmp(pub.Resp_code, "91"))
strcpy(tmp, "网络故障");
}
for (i = 0; i < num; i++)
/* 中行行号暂为4位 */
if (!memcmp(bankids[i], pub.Card_no + 1, 4))
break;
if (i == num)
break;
sprintf(tmp1, "%s-%s", bankids[i], hostids[i]);
sprintf(tmp2, "%s-%s", pub.Resp_bank_id, pub.Resp_host_id);
sprintf(buf,
"%-11.11s %-20.20s %-10.10s %-11.11s %8ld",
tmp1, banknames[i], tmp, tmp2,
(end_t.time - begin_t[i].time) * 1000 +
(end_t.millitm - begin_t[i].millitm));
bankids[i][0] = 0;
hostids[i][0] = 0;
AddListItem(buf, 0);
}
if (i == num) {
ftime(&end_t);
for(i=0; i < num ; i++) {
if (bankids[i][0] == 0)
continue;
sprintf(tmp1, "%s-%s", bankids[i], hostids[i]);
sprintf(tmp2, "%s-%s", pub.Resp_bank_id, pub.Resp_host_id);
sprintf(buf,
"%-11.11s %-20.20s %-10.10s %-11.11s %8ld",
tmp1, banknames[i], "超时一分", "",
(end_t.time - begin_t[i].time) * 1000 +
(end_t.millitm - begin_t[i].millitm));
AddListItem(buf, 0);
}
}
clear_wline(stdscr, LINES-1);
h_wpromptr(stdscr, LINES-1,
"上移: Home PgUp ↑ 下移: End PgDn ↓ 返回: ESC", 0, 0);
DispList(0);
FreeList();
}
end:
message_r_logout(Resp_msgid, pub.Source_msg_type);
quit:
delwin(my_win);
scr_restore(filename);
unlink(filename);
return(0);
}
int set_cardno(char * card_no)
{
int i, len, value, sum;
value = 0;
sum = 0;
for ( i = 0;i < 19; i++)
if((card_no[i] == ' ')||(card_no[i] == 0 )) break;
len = i;
for (i = len - 2; i >= 0; i--) {
value = (card_no[i] - '0') * (((len - i) % 2) ? 1 : 2);
sum += ( value % 10 ) + ( value / 10 );
}
value = 10 - (sum % 10);
card_no[len - 1] = value + '0';
return(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?