sqefx.ec

来自「在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便」· EC 代码 · 共 312 行

EC
312
字号
/****************************************************
 *	授权额分析 sqefx()
 *
 * 最后修改:	周国祥 2001/08/26
 * 最后修改:	Wubin 2001/09/04
 ****************************************************/
#include <curses.h>
#include <tool.h>
#include "mytools.h"
#include "analysis.h"
$include "db_struct.h";

struct {
	double	min;
	double	max;
} amount_tbl[6]={{0.00, 500.00}, {500.00,1000.00}, {1000.00,2000.00},
		{2000.00,3000.00}, {3000.00,5000.00},{5000.00,100000000.00}};

double calc_double(char *);
int	sqefx ()
{
WINDOW	*my_win;
$char	sqlstr[2048], str[1024], table[30], date1[15], date2[15];
$char	in_date1[15], in_date2[15];
$int	i, count, count1, count2, total_count;
$short	indi1, indi2;
$double	amount, amount1, amount2, total_amount;
char    ddcount[20],ddamount[20],dd_total_count[20],dd_total_amount[20],
        dd_average[20];
S_sys_param sy;
char	scr_dump_file[80];
char	acq_bank[12];
int	ret = 0;

        strcpy(audit_title, "授权额分析");
	count = total_count = 0;
	amount = total_amount = 0;

	sprintf( scr_dump_file, "/tmp/.screen_dump.%d", getpid() );
	scr_dump ( scr_dump_file );

	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,"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	set_prompt(PROMPT_OFF);
	wrefresh(my_win);

	if ( i = select_sys_param(&sy) ) {
		errcall(ERROR, "查本地参数表错误[%d]!",i);
		h_winprompt(my_win, 17, 4, "查本地参数表错误!",1,0);
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	if ( get2date( my_win, 2, 20, in_date1, in_date2, table ) < 0 ) {
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}

	date2str(in_date1, date1, "");
	date2str(in_date2, date2, "");

	strcpy(acq_bank,G_bankid);
	if ((strcmp(G_cen_bankid, G_bankid)) == 0) {
		mvwprintw(my_win, 3,22, "请输入银行行号: [%11s]", " ");
		ret = in_item(my_win,"", 3, 39, acq_bank, 11, NULL, NULL, 0, 0);
		if (ret != ENTER) {
			delwin(my_win);
			scr_restore(scr_dump_file);
			unlink(scr_dump_file);
			return(-1);
		}
	} else {
		mvwprintw(my_win, 3,22, "请输入银行行号: [%s]", acq_bank);
	}

	DelSpace(acq_bank);
	errcall(ERROR,"银行行号: [%s]",acq_bank);
	mvwprintw(my_win, 4, 22, "处理中, 请稍候 ...");
	wrefresh(my_win);

/* select total_count,total_amount from cur_tran_ls and his_tran_ls to print percent */
#ifdef Wubin20020607_mod
	sprintf(sqlstr,
		"select count(*), sum(tran_amt) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' and acq_host_id=\'%s\' ",
		date1, date2, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
	sprintf(sqlstr,
		"select count(*), sum(tran_amt) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2, acq_bank);
#endif
	$prepare s_comm0 from $sqlstr;
	$declare sqefx_cur0 cursor for s_comm0;
	$open sqefx_cur0;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	$fetch sqefx_cur0 into $count:indi1, $amount:indi2;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		$close sqefx_cur0;
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	if ( SQLCODE == SQLNOTFOUND || indi1 == -1 || indi2 == -1 ) {
		count = 0;
		amount = 0;
	}
	$close sqefx_cur0;


#ifdef Wubin20020607_mod
	sprintf(sqlstr,
		"select count(*), sum(tran_amt) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' and acq_host_id=\'%s\' ",
		date1, date2, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
	sprintf(sqlstr,
		"select count(*), sum(tran_amt) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2, acq_bank);
#endif
	$prepare s_comm1 from $sqlstr;
	$declare sqefx_cur1 cursor for s_comm1;
	$open sqefx_cur1;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	$fetch sqefx_cur1 into $total_count:indi1, $total_amount:indi2;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		$close sqefx_cur1;
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	if ( SQLCODE == SQLNOTFOUND || indi1 == -1 || indi2 == -1 ) {
		total_count = 0;
		total_amount = 0;
	}
	$close sqefx_cur1;

	total_count += count;
	total_amount += amount;

	CreateList(16, 74, 6, 3,
	"     金额范围        交易笔数    百分比       交易金额    百分比");

    for ( i=0; i<6; i++ ) {
#ifdef Wubin20020607_mod
	sprintf ( str,
		"select count(*) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\'  and acq_host_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
	sprintf ( str,
		"select count(*) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, acq_bank);
#endif
	count1 = query_count ( str );
	if ( count1 ) {
#ifdef Wubin20020607_mod
		sprintf ( str,
		"select sum(tran_amt) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\'  and acq_host_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
		sprintf ( str,
		"select sum(tran_amt) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, acq_bank);
#endif
		amount1 = calc_double ( str );
	}else	amount1 = 0;


#ifdef Wubin20020607_mod
	sprintf ( str,
		"select count(*) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\'  and acq_host_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
	sprintf ( str,
		"select count(*) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, acq_bank);
#endif

	count2 = query_count ( str );
	if ( count2 ) {
#ifdef Wubin20020607_mod
		sprintf ( str,
		"select sum(tran_amt) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\'  and acq_host_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, /* sy.adm_bank_id */sy.bank_id, sy.host_id);
#else
		sprintf ( str,
		"select sum(tran_amt) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and tran_amt > %12.2lf and tran_amt < %12.2lf \
		and resp_code=\'00\' and auth_no IS NOT NULL and acq_bank_id=\'%s\' ",
		date1, date2,
		amount_tbl[i].min, amount_tbl[i].max+0.01, acq_bank);
#endif
		amount2 = calc_double ( str );
	}else	amount2 = 0;

	count = count1 + count2;
	amount = amount1 + amount2;

        mystruct.type=DDINT;
        mystruct.ddnum.intnum=count;
        strcpy(ddcount,add_demical(mystruct));
        mystruct.type=DDDOUB;
        mystruct.ddnum.doublenum=amount;
        strcpy(ddamount,add_demical(mystruct));


	if ( i == 0 ) sprintf(str, "%7s -- ", "");
	else sprintf(str, "%07.2f -- ", amount_tbl[i].min);

	if (i == 5 ) sprintf(sqlstr, "%7s   %8s   ", "", ddcount);
	else sprintf(sqlstr, "%07.2f   %8s   ", amount_tbl[i].max, ddcount);
	strcat(str, sqlstr);

	if (count)
	    sprintf(sqlstr, "%6.2f%%   %14s  ",
		    (double)count/total_count*100, ddamount);
	else
	    sprintf(sqlstr, "%7s   %14s   ", "", ddamount);
	strcat(str, sqlstr);

	if (amount > 0.005)
	    sprintf(sqlstr, "%6.2lf%%", amount/total_amount*100);
	else
	    sprintf(sqlstr, "%7s", "");
	strcat(str, sqlstr);

	if (count) AddListItem(str,1);
	else AddListItem(str, 0);
   
    }
    AddListItem(" ",0);
    mystruct.type=DDINT;
    mystruct.ddnum.intnum=total_count;
    strcpy(dd_total_count,add_demical(mystruct));
    mystruct.type=DDDOUB;
    mystruct.ddnum.doublenum=total_amount;
    strcpy(dd_total_amount,add_demical(mystruct));
    mystruct.type=DDDOUB;
    if(total_count) mystruct.ddnum.doublenum=total_amount/total_count;
    else mystruct.ddnum.doublenum=0.0;
    strcpy(dd_average,add_demical(mystruct));
    sprintf(str,"%-21.21s%8s   %7s   %14s   %7s",
		"总计", dd_total_count, "", dd_total_amount, "");
    AddListItem(str,0);
    if ( total_count ) {
    	AddListItem(" ",0);
	sprintf(str,"平均每笔授权金额: %s",dd_average);
	AddListItem(str,1);
    }
    h_wpromptr(stdscr, LINES-1, "上移: Home PgUp ↑ 下移: End PgDn ↓打印:CTRL_P  返回: ESC", 0, 0);
    DispList(0);
    FreeList();
    delwin ( my_win );
    clear_wline ( stdscr, LINES-1 );
    scr_restore ( scr_dump_file );
    unlink ( scr_dump_file );
    return ( 0 );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?