?? set_cash.c
字號:
#include <alloc.h>
#include <ctype.h>
#include <fcntl.h>
#include <graphics.h>
#include <io.h>
#include <mem.h>
#include <string.h>
#include <bio.inc>
#include <menu.inc>
#include <key.inc>
#include <g_id.inc>
#include "feedef.h"
#define BK_CLR 7
#define CHR_CLR 0
#define HEAD_CLR 0
#define ITBL_CLR 5
#define BK_COLOR 0 /* specify the background color */
#define CHAR_COLOR 14 /* specify the characters' color */
#define CURSOR_COLOR 12 /* specify the cursor color */
#define DRAW_KEY draw_key(x, y, x+16, y+16, "關(guān)", 7, 0)
#define CHANG_KEY chang_key1(x, y, x+16, y+16, "開", 12)
/* function : set cash pledge (ya jin) for every telephone No
* called by : set_data()
* date : 1993.10.18
*/
void set_cash_pledge(UC mode)
{
UC flag;
UI pg;
CASH_PLEDGE *tbl;
UC *title = "注意:";
UC *warn = "應(yīng)先打開開關(guān)再設(shè)定押金!";
TABLE_STRUCT cash_tbl = {115,99,20,18,16,5, {48, 72, 72, 72, 72}, ITBL_CLR};
if(Cashflg[mode] == 0) /* do not use cash pledge function */
{
warn_mesg(title, warn);
return;
}
flag = check_maint_cash(mode);
if(flag == 0)
{
message(PHO_FILE_ERR);
return;
}
flag = load_cash_tbl(mode); /* load cash file to memory */
Cash_len[mode] = cash_tbl_len(mode);
clr_DialWin(1);
set_finger_color(Dsp_clr.fng_clr);
draw_table(&cash_tbl); /* draw the table frame */
disp_cash_head(SET_CASH, mode); /* display table head */
disp_cash_help(SET_CASH, mode); /* display the help information */
message_disp(8,"根據(jù)右上方彈出提示窗口提示操作");
Count = 1;
tbl = Cash_top[mode];
disp_cash_tbl(tbl,Count,SET_CASH, mode);
if(!(Cash_len[mode]%16) && Cash_len[mode])
pg = Cash_len[mode]/16;
else
pg = (UI)(Cash_len[mode]/16)+1;
outf(542,397,11,14,"%2u",pg);
locate_finger(0,2);
input_cash_data(mode);
unload_cash_tbl(mode);
message_end();
return;
}
/* function : check if the telephones in charge.pho are the same as those
* in cash data file. If not, add to cash data file automaticly
* called by : set_cash()
* input : mode -- phone pledge or authorized code pledge
* output : 0 -- unsuccesful
* 1 -- successful
* date : 1993.11.9
*/
UC check_maint_cash(UC mode)
{
FILE *fpm, *fpc;
PHONE_STRUCT phone;
AUTHCD_STRUCT auth;
CASH_PLEDGE *cashe, ctmp={"",0,0,0};
size_t psize, asize, csize;
psize = sizeof(PHONE_STRUCT);
asize = sizeof(AUTHCD_STRUCT);
csize = sizeof(CASH_PLEDGE);
/* the phones in charge.pho are not the same as those in cash data file,
* so refresh cash data file
*/
message_disp(8,"正在進(jìn)行文件操作, 請稍候..."); /* refreshing, wait */
load_cash_tbl(mode);
Cash_len[mode] = cash_tbl_len(mode);
fpm = fopen(ChargeDataFile[mode],"rb");
fpc = fopen(CashDataFile[mode],"wb");
if(mode == PHONE_CASH)
while(fread(&phone,psize,1,fpm) == 1)
{
cashe = binary_cash(phone.phone_no, mode);
if(cashe != NULL)
fwrite(cashe,csize,1,fpc);
else
{
strcpy(ctmp.phone_no,phone.phone_no);
fwrite(&ctmp,csize,1,fpc);
}
}
else /* mode == AUTH_CASH */
while(fread(&auth,asize,1,fpm) == 1)
{
if(auth.auth_class != UNUSED_AUTH)
{
sprintf(phone.phone_no, "%03d", auth.auth_code);
cashe = binary_cash(phone.phone_no, mode);
if(cashe != NULL)
fwrite(cashe,csize,1,fpc);
else
{
strcpy(ctmp.phone_no,phone.phone_no);
fwrite(&ctmp,csize,1,fpc);
}
}
}
fclose(fpc);
fclose(fpm);
unload_cash_tbl(mode);
message_end();
return(1);
}
/* function : load the cash data to memory, and input the cash_pledge
* called by : set_cash_pledge()
* output : 0 -- the file of cash data file does not exist
* 1 -- successful
* date : 1993.10.17
*/
UC load_cash_tbl(UC mode)
{
FILE *fp;
CASH_PLEDGE *tbl;
UL ss;
int i, num = 0;
UI maxlen;
if(Cash_top[mode] != NULL) return(1); /*already loaded */
fp = fopen(CashDataFile[mode],"rb");
if(fp == NULL) /* the file does not exist */
return(0);
maxlen = (mode == PHONE_CASH)? MAX_USERS:MAX_AUTHCD;
Cash_top[mode] = (CASH_PLEDGE *)farcalloc(maxlen, sizeof(CASH_PLEDGE));
if(!Cash_top[mode])
{
ss = (UL)(maxlen*sizeof(CASH_PLEDGE));
exit_scr(1,"Out of memery ERROR: %ld bytes.\n\nGFS system shutdown abnormally.\n\n\n\n",ss);
}
tbl = Cash_top[mode];
while(fread(tbl,sizeof(CASH_PLEDGE),1,fp) == 1)
{
tbl++;
num++;
}
fclose(fp);
for(i=num;i<maxlen;i++)
(Cash_top[mode]+i)->phone_no[0] = '\0';
return(1);
}
/* function : free the memory for the cash pledge table
* called by : set_cash_pledge()
* date : 1993.9.21
*/
void unload_cash_tbl(UC mode)
{
if( Cash_top[mode] != NULL) {
farfree(Cash_top[mode]);
Cash_top[mode] = NULL;
}
return;
}
/* function : transfer the phone no in charge.pho to phone cash data file
* or transfer the authority code in charge.aus to aus cash data file
* called by : set_cash_pledge()
* output : 0 -- charge.pho does not exist
* 1 -- successful
* date : 1992.10.17
*/
UC maint_to_cash(UC mode)
{
FILE *fps,*fpd;
PHONE_STRUCT phone;
AUTHCD_STRUCT auth;
CASH_PLEDGE cashe;
void *strp;
size_t size;
fps = fopen(ChargeDataFile[mode],"rb");
if(fps == NULL)
return(0);
fpd = fopen(CashDataFile[mode],"wb");
if(mode == PHONE_CASH)
{
strp = ☎
size = sizeof(PHONE_STRUCT);
}
else
{
strp = &auth;
size = sizeof(AUTHCD_STRUCT);
}
while(fread(strp,size,1,fps) == 1)
{
if(mode == PHONE_CASH)
strcpy(cashe.phone_no,phone.phone_no);
else
{
if(auth.auth_class == UNUSED_AUTH) continue;
sprintf(cashe.phone_no, "%03d", (UI)auth.auth_code);
}
cashe.cash = 0;
cashe.limit = 0;
fwrite(&cashe,sizeof(CASH_PLEDGE),1,fpd);
}
fclose(fpd);
fclose(fps);
return(1);
}
/* function : calculate the length of cash pledge table
* called by : set_cash_pledge()
* date : 1993.10.16
*/
UI cash_tbl_len(UC mode)
{
CASH_PLEDGE *tbl;
UI tbllen = 0, maxlen;
maxlen = (mode == PHONE_CASH)? MAX_USERS:MAX_AUTHCD;
tbl = Cash_top[mode];
while(strlen(tbl->phone_no) && tbllen<maxlen)
{
tbllen++;
tbl++;
}
return(tbllen);
}
/* function : display the head Hanzi for the cash table
* called by : set_cash_pledge()
* date : 1993.9.22
*/
void disp_cash_head(UC opflg, UC mode)
{
UC *msg[2]={"分機號碼","授權(quán)卡號"};
if(opflg == SET_CASH)
outf(225, 76, BK_CLR, BLACK, "押 金 設(shè) 定"); /* No. */
else if(opflg == INQ_CASH)
outf(225, 76, BK_CLR, BLACK, "押 金 查 詢"); /* No. */
else
outf(225, 76, BK_CLR, BLACK, "透 支 報 告"); /* No. */
outf(124, 103, BK_CLR, HEAD_CLR, "序號"); /* No. */
outf(169, 103, BK_CLR, HEAD_CLR, msg[mode]); /* phone No or auth code */
outf(242, 103, BK_CLR, HEAD_CLR, "押金狀態(tài)"); /* cash now */
outf(315, 103, BK_CLR, HEAD_CLR, "押金現(xiàn)額"); /* cash now */
outf(388, 103, BK_CLR, HEAD_CLR, "押金下限"); /* cash limit */
return;
}
/* function : display the help information for input
* called by : set_cash_pledge()
* input : mode -- SET_CASH or INQ_CASH
* date : 1993.9.22
*/
void disp_cash_help(UC opflg, UC mode)
{
UC *msg[2] = {"F6 分機號定位","F6 授權(quán)卡號定位"};
hz16_disp(500,103,"單位: 元",0);
/*** PROMPT: ***/
draw_back1(480, 122, 625, 357, 11);
if(opflg == SET_CASH)
{
outf(490, 142, 11, 0, "F2 存盤");
outf(490, 162, 11, 0, msg[mode]);
outf(490, 182, 11, 0, "F7 頁定位");
outf(490, 202, 11, 0, "←↓→↑ 移動");
outf(490, 222, 11, 0, "PgUp 向前翻頁");
outf(490, 242, 11, 0, "PgDn 向后翻頁");
outf(490, 262, 11, 0, "Enter 輸入");
outf(490, 322, 11, 0, "Esc 退出");
}
else
{
outf(490, 142, 11, 0, msg[mode]);
outf(490, 162, 11, 0, "F7 頁定位");
outf(490, 182, 11, 0, "↓↑ 移動");
outf(490, 202, 11, 0, "PgUp 向前翻頁");
outf(490, 222, 11, 0, "PgDn 向后翻頁");
outf(490, 322, 11, 0, "Esc 退出");
}
/*** PAGE No. AND TOTAL PAGE ***/
draw_back1(498, 365, 607, 427, 11);
outf(518, 377, 11, 14, "第");
outf(575, 377, 11, 14, "頁");
outf(518, 397, 11, 14, "共");
outf(575, 397, 11, 14, "頁");
}
/* function : display a page of cash table
* called by : set_cash_pledge(), pgup_cash_tbl(), pgdn_cash_tbl()
* input : tbl -- the first item of this page
* num -- the xu-hao of the first item of this page
* cmode -- SET_CASH or INQ_CASH
* mode -- PHONE_CASH or AUTHCD_CASH
* date : 1993.10.16
*/
void disp_cash_tbl(CASH_PLEDGE *tbl, int num, UC cmode, UC mode)
{
UI i, j;
UI x, y;
UI pg;
UNIT_STRUCT cer_unit;
UI maxlen;
maxlen = (mode == PHONE_CASH)? MAX_USERS:MAX_AUTHCD;
for(i=0; i<16; i++) /* DISPLAY No. IN THE TABLE */
{
if(num+i > maxlen)
break;
outf(124, i*19+123, BK_CLR, HEAD_CLR, "%-3u", num+i);
}
pg = (UI)(num/16)+1; /* DISPLAY THIS PAGE No. */
setfillstyle(1,11);
bar(534, 393, 575, 377);
outf(542, 377, 11, 14, "%2u", pg);
for(i=0; i<16; i++)
{
if(!strlen(tbl->phone_no) || (num+i > maxlen))
break;
if((cmode == INQ_CASH) || (cmode == INQ_OVCASH))
{
if(tbl->flag == CASH_ON)
{
if( tbl->cash < tbl->limit)
indicator( 284+4, i*19+123+8, LIGHTRED );
else
indicator( 284+4, i*19+123+8, LIGHTGREEN );
}
}
for(j=1;j<5;j++)
{
cer_unit.unit_x = i;
cer_unit.unit_y = j;
get_certain(&cer_unit);
x = cer_unit.dot_sx+8;
y = cer_unit.dot_sy+1;
switch(j)
{
case 1: /* telephone no */
if(!strcmp(tbl->phone_no,""))
break;
outf(x,y,BK_CLR,CHR_CLR,"%-s",tbl->phone_no);
break;
case 2: /* cash switch */
if(tbl->flag == CASH_ON)
CHANG_KEY;
else
DRAW_KEY;
break;
case 3: /* cash preserved now */
outf(x,y,BK_CLR,CHR_CLR,"%7.2f",((double)tbl->cash)/100);
break;
case 4: /* cash bottom limit */
outf(x,y,BK_CLR,CHR_CLR,"%6.2f",((double)tbl->limit)/100);
break;
default:
break;
} /* END SWITCH */
} /* END FOR2 */
tbl++;
} /* END FOR1 */
return;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -