stati.c
来自「在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便」· C语言 代码 · 共 201 行
C
201 行
/********************************************************
* 交易分析 stati()
* 根据联行行号, 特约单位, EDC 号统计交易笔数
*
* 最后修改: 周国祥 2001/08/17
*******************************************************/
#include <curses.h>
#include "db_struct_c.h"
#include "macro_def.h"
#include "mytools.h"
#include "tool.h"
#define T_NUM 11
extern double calc_double();
int stati()
{
int trans_set[] = { PURCHASE, REFUND, WITHDRAWAL, DEPOSIT, AUTH_PUR,
PRE_AUTH, CONFIRM, TRANS_OUT, ADJUST, OFFLINE,
POS_VOID}; /* INQUERY,CHG_PWD,REVERSAL 不在当前流水表和历史流水表中记录 */
long num[T_NUM], his_num, total_num;
double sum[T_NUM], his_sum, total_sum;
WINDOW *my_win;
S_sys_param sy;
char start_date[11], end_date[11], bankid[12], hostid[3];
char in_date1[15], in_date2[15];
char merchant_id[16];
char terminal_id[9], name[51], trans_name[9], filename[128];
char condition[300], buffer[300];
int i;
bankid[0] = terminal_id[0] = merchant_id[0] = 0;
strcpy(hostid, "00");
if (!select_sys_param(&sy)) {
strcpy(bankid, sy.bank_id);
strcpy(hostid, sy.host_id);
}
sprintf(filename, "/tmp/.stati.%d", getpid());
scr_dump(filename);
disp_below("交易分析");
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);
set_prompt(PROMPT_OFF);
getdatef(in_date1, "");
strcpy(in_date2, in_date1);
mvwprintw(my_win, 2, 14, "日 期: [ ] 到 [ ]");
if (in_item(my_win, "", 2, 25, in_date1, 8, NULL, NULL, 0, 0) !=
ENTER) goto end;
if (in_item(my_win, "", 2, 39, in_date2, 8, NULL, NULL, 0, 0) !=
ENTER) goto end;
date2str(in_date1, start_date, "");
date2str(in_date2, end_date, "");
mvwprintw(my_win, 3, 14, "联行行号: [%-11.11s][%-2.2s] [%-30.30s]", bankid, hostid , "");
if (in_item(my_win, "", 3, 25, bankid, 11, NULL, NULL, 4, 0) != ENTER)
goto end;
if (in_item(my_win, "", 3, 38, hostid, 2, NULL, NULL, 4, 0) != ENTER)
goto end;
DelSpace(bankid);
DelSpace(hostid);
i = get_bank_name(bankid, hostid, name);
if (i) {
h_winprompt(my_win, 17, 4, "无此联行行号!", 1, 0);
goto end;
}
mvwprintw(my_win, 3, 43, "%-30.30s", name);
mvwprintw(my_win, 4, 14, "商户编号: [%-15.15s] [%-40.40s]",
merchant_id, "");
if (in_item(my_win, "", 4, 25, merchant_id, 15, NULL, NULL, 0, 0) !=
ENTER) goto end;
DelSpace(merchant_id);
name[0] = '\0';
i = get_merchant_name(merchant_id, name);
if (!is_blank_str(merchant_id) && i) {
h_winprompt(my_win, 17, 4, "无此商户编号!", 1, 0);
goto end;
}
mvwprintw(my_win, 4, 43, "%-40.40s", name);
mvwprintw(my_win, 5, 14, "EDC 编号: [%-8s] [%-30.30s]",
terminal_id, "");
if (in_item(my_win, "", 5, 25, terminal_id, 8, NULL, NULL, 0, 0) !=
ENTER) goto end;
DelSpace(terminal_id);
name[0] = '\0';
i = get_terminal_name(terminal_id, name);
if (!is_blank_str(terminal_id) && i) {
h_winprompt(my_win, 17, 4, "无此 EDC 编号!", 1, 0);
goto end;
}
mvwprintw(my_win, 5, 36, "%-30.30s", name);
wrefresh(my_win);
mvwprintw(my_win, 7, 14, "处理中, 请稍候 ...");
wrefresh(my_win);
#ifdef zgx010817_modi
sprintf(condition, "ret_code = \'00\' and sd_bankid = \'%s\' and equip_date >= \'%s\' and equip_date <= \'%s\'", bankid, start_date, end_date);
#else
sprintf(condition, "resp_code = \'00\' and edc_err_flag = \'0\' and acq_bank_id = \'%s\' and local_sys_date >= \'%s\' and local_sys_date <= \'%s\'", bankid, start_date, end_date);
#endif
if (!is_blank_str(merchant_id)) {
sprintf(buffer, " and merchant_id = \'%s\'", merchant_id);
strcat(condition, buffer);
}
if (!is_blank_str(terminal_id)) {
sprintf(buffer, " and terminal_id = \'%s\'", terminal_id);
strcat(condition, buffer);
}
total_num = total_sum = 0;
memset(num, 0, T_NUM * sizeof(long));
memset(sum, 0, T_NUM * sizeof(double));
for (i = 0; i < T_NUM; i++) {
sprintf(buffer,
"select count(*) from cur_tran_ls where tran_type = %d and %s",
trans_set[i], condition);
num[i] = query_count(buffer);
his_num = 0;
sprintf(buffer,
"select count(*) from his_tran_ls where tran_type = %d and %s",
trans_set[i], condition);
his_num = query_count(buffer);
num[i] += his_num;
total_num += num[i];
if (num[i]) {
sprintf(buffer,"select sum(tran_amt) from cur_tran_ls where tran_type = %d and %s",trans_set[i], condition);
sum[i] = calc_double(buffer);
his_sum = 0.0;
sprintf(buffer,"select sum(tran_amt) from his_tran_ls where tran_type = %d and %s",trans_set[i], condition);
his_sum = calc_double(buffer);
sum[i] += his_sum;
total_sum += sum[i];
}
}
CreateList(13, 58, 9, 11, "交易类型 交易笔数 百分比 交易金额 百分比");
for (i = 0; i < T_NUM; i++) {
type2buf(trans_set[i], trans_name);
sprintf(buffer, "%8.8s %8ld ", trans_name, num[i]);
if (num[i])
sprintf(name, "%6.2f%% ", (double)num[i]/total_num*100);
else
strcpy(name, " ");
strcat(buffer, name);
sprintf(name, "%12.2lf ", sum[i]);
strcat(buffer, name);
if (sum[i] > 0.005)
sprintf(name, "%6.2f%%", sum[i]/total_sum*100);
else
strcpy(name, " ");
strcat(buffer, name);
if (num[i])
AddListItem(buffer, 1);
else
AddListItem(buffer, 0);
}
AddListItem("", 0);
sprintf(buffer, "总计 %8ld %12.2lf ",
total_num, total_sum);
AddListItem(buffer, 0);
if (total_sum > 0.005) {
AddListItem("", 0);
sprintf(buffer, "平均每笔交易金额: %.2lf", total_sum/total_num);
AddListItem(buffer, 1);
}
clear_wline(stdscr, LINES-1);
h_wpromptr(stdscr, LINES-1, "上移: Home PgUp ↑ 下移: End PgDn ↓ 返回: ESC", 0, 0);
DispList(0);
FreeList();
end:
delwin(my_win);
clear_wline ( stdscr, LINES-1 );
scr_restore(filename);
unlink(filename);
return(0);
}
int is_blank_str(char *str)
{
char *s = str;
while (*s == ' ') s++;
if (*s == 0) return(1);
else return(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?