klfx.ec

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

EC
270
字号
/*******************************************************
 *	卡类分析(klfx)
 *
 * 最后修改:	周国祥 2001/08/19
 *******************************************************/
#include <curses.h>
#include <tool.h>
#include "mytools.h"
#include "analysis.h"

struct {
	char	name[10];
	char	type[3];
} card_type[7]={{"信用卡","01"},
		{"借记卡","02"},
		{"威士卡","51"},
		{"万事达","52"},
		{"运通卡","53"},
		{"大莱卡","54"},
		{"JCB 卡","55"}};

int	get2date ( my_win, line, col, date1, date2, table )
WINDOW	*my_win;
int	line, col;
char	*date1, *date2;
char	*table;
{
int	ret;
$char	logic_date[15];

	/* get logic_date */
/*
	EXEC SQL DECLARE cur_0 CURSOR FOR
	SELECT DISTINCT local_date FROM settle_line;
	EXEC SQL OPEN cur_0;
	if (SQLCODE) {
		daylog(ERROR,"open settle_line cursor[%ld]",SQLCODE);
		return (-1);
	}
	EXEC SQL FETCH cur_0 INTO :local_date;
	if (SQLCODE == SQLNOTFOUND)
		strcpy ( local_date, "" );
	else
		if (SQLCODE) {
			EXEC SQL CLOSE cur_0;
			daylog(ERROR,"fetch settle_line cursor[%ld]",SQLCODE);
			return (-1);
		}
	EXEC SQL CLOSE cur_0;
*/
	getdatef ( logic_date, "" );

	/* get local_sys_date */
	getdatef ( date1, "" );
	strcpy ( date2, date1 );

	h_winprompt ( my_win, line, col,
		"  日期: [        ] 到 [        ] ", 0, 0 );

	ret = in_item ( my_win, "", line, col+9, date1, 8, NULL, NULL, 0, 0 );
	if ( ret != ENTER ) {
/*
		if ( ret == ESCAPE )
			return ( -1 );
		h_winprompt ( my_win, 18, 4, "输入错误!  ", 1, 0 );
*/
		return ( -1 );
	}
	ret = in_item ( my_win, "", line, col+23, date2, 8, NULL, NULL, 0, 0 );
	if ( ret != ENTER ) {
/*
		if ( ret == ESCAPE )
			return ( -1 );
		h_winprompt ( my_win, 18, 4, "输入错误!  ", 1, 0 );
*/
		return ( -1 );
	}

	if ( !strcmp( date1, date2 ) && !strcmp( date1, logic_date) )
		strcpy ( table, "cur_tran_ls" );
	else
		strcpy ( table, "his_tran_ls" );
	h_winprompt ( my_win, 18, 4, "              ", 0, 0 );
	return ( 0 );
}

double calc_double(char *);

int	klfx ()
{
WINDOW	*my_win;
$char	str[400], table[30], date1[15], date2[15];
$int	i, count1, count2, total_count;
$double	amount1, amount2, total_amount;
$char	in_date1[15], in_date2[15];
char    ddcount[20],ddamount[20],dd_total_count[20],dd_total_amount[20];
$short	indi1, indi2;
char	tmp[80], scr_dump_file[80];

        strcpy(audit_title, "卡类分析");

	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 ( 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, "");


	mvwprintw(my_win, 4, 22, "处理中, 请稍候 ...");
	wrefresh(my_win);

	count1 = total_count = 0;
	amount1 = total_amount = 0;
/* select total_count,total_amount from posls and history_ls to print percent */
	sprintf(str,
		"select count(*), sum(tran_amt) from cur_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' ", date1, date2 );
	$prepare s_comm0 from $str;
	$declare klfx_cur0 cursor for s_comm0;
	$open klfx_cur0;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		h_winprompt(my_win, 17, 4, "数据库操作错误!", 1,0);
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	$fetch klfx_cur0 into $count1:indi1, $amount1:indi2;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		$close klfx_cur0;
		h_winprompt(my_win, 17, 4, "数据库操作错误!", 1,0);
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	if ( SQLCODE == SQLNOTFOUND || indi1 == -1 || indi2 == -1 ) {
		count1 = 0;
		amount1 = 0;
	}
	$close klfx_cur0;

	sprintf(str,
		"select count(*), sum(tran_amt) from his_tran_ls \
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and resp_code=\'00\' ", date1, date2 );
	$prepare s_comm1 from $str;
	$declare klfx_cur1 cursor for s_comm1;
	$open klfx_cur1;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		h_winprompt(my_win, 17, 4, "数据库操作错误!", 1,0);
		delwin ( my_win );
		scr_restore ( scr_dump_file );
		unlink ( scr_dump_file );
		return ( -1 );
	}
	$fetch klfx_cur1 into $total_count:indi1, $total_amount:indi2;
	if ( SQLCODE && SQLCODE != SQLNOTFOUND ) {
		$close klfx_cur1;
		h_winprompt(my_win, 17, 4, "数据库操作错误!", 1,0);
		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 klfx_cur1;

	total_count += count1;
	total_amount += amount1;

	CreateList(16, 56, 6, 12, "卡类型  交易笔数   百分比       交易金额   百分比");

    for ( i=0; i<7; i++ ) {
	sprintf ( str,
		"select count(*) from cur_tran_ls	\
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and card_type=\'%s\' and resp_code=\'00\'",
		date1, date2, card_type[i].type );

	count1 = query_count ( str );
	if ( count1 ) {
		sprintf ( str,
			"select sum(tran_amt) from cur_tran_ls	\
			where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
			and card_type=\'%s\' and resp_code=\'00\'",
			date1, date2, card_type[i].type );
		amount1 = calc_double ( str );
	}else	amount1 = 0;

	sprintf ( str,
		"select count(*) from his_tran_ls	\
		where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
		and card_type=\'%s\' and resp_code=\'00\'",
		date1, date2, card_type[i].type );

	count2 = query_count ( str );
	if ( count2 ) {
		sprintf ( str,
			"select sum(tran_amt) from his_tran_ls	\
			where local_sys_date >= \'%s\' and local_sys_date <= \'%s\' \
			and card_type=\'%s\' and resp_code=\'00\'",
			date1, date2, card_type[i].type );
		amount2 = calc_double ( str );
	}else	amount2 = 0;

        mystruct.type=DDINT;
        mystruct.ddnum.intnum=count1+count2;
        strcpy(ddcount,add_demical(mystruct));
        mystruct.type=DDDOUB;
        mystruct.ddnum.doublenum=amount1+amount2;
        strcpy(ddamount,add_demical(mystruct));

	sprintf(str, "%-8.8s%8s  ", card_type[i].name, ddcount);
	if (count1+count2)
		sprintf(tmp, "%6.2f%%   ",
			(double)(count1+count2)/total_count*100);
	else
		strcpy(tmp, "          ");
	strcat(str, tmp);
	sprintf(tmp, "%14s  ", ddamount);
	strcat(str, tmp);
	if ((amount1+amount2) > 0.005)
		sprintf(tmp, "%6.2f%%", (amount1+amount2)/total_amount*100);
	else
		strcpy(tmp, "       ");
	strcat(str, tmp);
	if (count1+count2) AddListItem(str,1);
	else AddListItem(str, 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));
	AddListItem(" ",0);
	sprintf(str,"总计    %8s            %14s         ",
		dd_total_count,dd_total_amount);
	AddListItem(str,0);
	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 + -
显示快捷键?