?? set_phon.c
字號:
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <mem.h>
#include <alloc.h>
#include <graphics.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 NOFRESH 0
#define REFRESH 1
#define ITEM_NUM 10
#define UNUSED_CODE 2048
/* function : input the phone number
* calls :
* called by : set_data() (set_data.c)
* output : sort the phone number, and write to charge.pho
* date : 1993.9.21
*/
void set_phone_num(UC mode)
{
UI pg;
TABLE_STRUCT phone_tbl = {52,99,20,18,16,ITEM_NUM, {32, 76,35,35,35,50,50,35,35,35}, ITBL_CLR};
PHONE_STRUCT *tbl;
clr_DialWin(2);
set_finger_color(Dsp_clr.fng_clr);
draw_table(&phone_tbl); /* draw the table frame */
if(mode == SET_PCODE)
outf(170, 76, BK_CLR, BLACK, "分機(jī)內(nèi)碼、級別及計費(fèi)設(shè)定"); /* No. */
else
outf(170, 76, BK_CLR, BLACK, "立即打印分機(jī)設(shè)定"); /* No. */
outf(53, 103, BK_CLR, HEAD_CLR, "序號"); /* No. */
outf(90, 103, BK_CLR, HEAD_CLR, "話機(jī)號"); /* phone No */
if(mode == SET_PCODE)
outf(164, 103, BK_CLR, HEAD_CLR, "內(nèi)碼"); /* pcode now */
else
outf(164, 103, BK_CLR, HEAD_CLR, "打印"); /* pcode now */
outf(201, 103, BK_CLR, HEAD_CLR, "級別");
outf(236, 103, BK_CLR, HEAD_CLR, "市話");
outf(272, 103, BK_CLR, HEAD_CLR, "農(nóng)話");
outf(324, 103, BK_CLR, HEAD_CLR, "信息臺");
outf(375, 103, BK_CLR, HEAD_CLR, "國內(nèi)");
outf(411, 103, BK_CLR, HEAD_CLR, "國際");
outf(448, 103, BK_CLR, HEAD_CLR, "時長");
disp_key_help(); /* display the help information */
message_disp(8,"根據(jù)右上方彈出提示窗口提示操作");
load_phone_tbl();
Oldlen = phone_tbl_len();
Newlen = Oldlen;
Count = 1;
tbl = Phone_top;
disp_phone_tbl(tbl,Count, mode); /* display a page of phone number */
if(!(Newlen%16) && Newlen)
pg = Newlen/16;
else
pg = (UI)(Newlen/16)+1;
outf(542,397,11,14,"%2u",pg); /* display the overall page number */
locate_finger(0,1);
input_phone_num(mode);
unload_phone_tbl();
message_end();
return;
}
/* function : display the help information on the screen.
* calls : outf()
* called by : set_phone_num()
* date : 1993.9.21
*/
void disp_key_help(void)
{
/*** PROMPT: ***/
draw_back1(500, 102, 630, 337, 11);
outf(505, 142, 11, 0, "F2 存盤");
outf(505, 162, 11, 0, "F5 刪除");
outf(505, 182, 11, 0, "F9 分機(jī)號加1");
outf(505, 202, 11, 0, "←↓→ ↑移動");
outf(505, 222, 11, 0, "PgUp 向前翻頁");
outf(505, 242, 11, 0, "PgDn 向后翻頁");
outf(505, 262, 11, 0, "Enter 輸入");
outf(505, 302, 11, 0, "Esc 退出");
/*** PAGE No. AND TOTAL PAGE ***/
draw_back1(508, 365, 617, 427, 11);
outf(528, 377, 11, 14, "第");
outf(585, 377, 11, 14, "頁");
outf(528, 397, 11, 14, "共");
outf(585, 397, 11, 14, "頁");
}
/* function : load charge.pho
* called by : set_phone_num()
* date : 1993.9.21
*/
void load_phone_tbl(void)
{
FILE *fp;
PHONE_STRUCT *tbl;
UL ss;
int i, num = 0;
if(Phone_top != NULL) /* already loaded */
return;
Phone_top = (PHONE_STRUCT *) farcalloc(MAX_USERS, sizeof(PHONE_STRUCT));
if( !Phone_top )
{
ss = (UL)(MAX_USERS*sizeof(PHONE_STRUCT));
exit_scr(1,"Out of memery ERROR: %ld bytes.\n\nGFS system shutdown abnormally.\n\n\n\n",ss);
}
tbl = Phone_top;
fp = fopen(ChargeDataFile[PHONE_CASH], "rb");
if(fp != NULL) /* the file exists */
{
while(fread(tbl, sizeof(PHONE_STRUCT), 1, fp) == 1)
{
tbl++;
num++;
}
fclose(fp);
}
for(i=num;i<MAX_USERS;i++) {
tbl->phone_no[0] = '\0';
tbl->code = UNUSED_CODE;
tbl->class = 0;
tbl->feeflag[0] = 0;
tbl->feeflag[1] = 0;
tbl->feeflag[2] = 0;
tbl->feeflag[3] = 0;
tbl->feeflag[4] = 0;
tbl->max_min = 0;
tbl++;
}
return;
}
/* function : free the memory for the phone number table
* called by : set_phone_num()
* date : 1993.9.21
*/
void unload_phone_tbl(void)
{
farfree(Phone_top);
Phone_top = NULL;
return;
}
/* function : calculate the length of phone number table
* called by : set_phone_num()
* date : 1993.9.21
*/
UI phone_tbl_len(void)
{
PHONE_STRUCT *tbl;
UI tbllen = 0;
tbl = Phone_top;
while(strlen(tbl->phone_no) && tbllen<MAX_USERS)
{
tbllen++;
tbl++;
}
return(tbllen);
}
/* function : Display a page of phone num table.
* calls : None
* called by : rate_set,pgup_phone_tbl,pgdn_phone_tbl,
* loc_phone_tbl,loc_page
* input : tbl -- a pointer pointing the page
* num -- the No. of the first item of
* the page
* date : 1993.9.21
*/
void disp_phone_tbl(PHONE_STRUCT *tbl, UI num, UC mode)
{
UI i, j;
UI x, y;
UI pg;
UNIT_STRUCT cer_unit;
UC color;
for(i=0; i<16; i++) /* DISPLAY No. IN THE TABLE */
{
if(num+i > MAX_USERS)
break;
outf(55, i*19+123, BK_CLR, HEAD_CLR, "%-3u", num+i);
}
pg = (UI)(num/16)+1; /* DISPLAY THIS PAGE No. */
setfillstyle(1,11);
bar(554, 393, 580, 377);
outf(562, 377, 11, 14, "%2u", pg);
for(i=0; i<16; i++)
{
if(!strlen(tbl->phone_no) || (num+i > MAX_USERS))
break;
for(j=1;j<ITEM_NUM;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-3,y,BK_CLR,CHR_CLR,"%-s",tbl->phone_no);
break;
case 2: /* pcode */
if(mode == SET_PCODE)
{
if( tbl->code != UNUSED_CODE){
if(tbl->set_flag == 1)
color = LIGHTRED;
else
color = 0;
outf(x-8,y,BK_CLR,color,"%3u",tbl->code);
}
}
else
{
if(tbl->flag == FALSE)
outf(x,y,BK_CLR,CHR_CLR, "否");
else
outf(x,y,BK_CLR,CHR_CLR, "打");
}
break;
case 3: /* class */
if( tbl->code != UNUSED_CODE){
if(tbl->set_flag == 2)
color = LIGHTRED;
else
color = 0;
outf(x-2,y,BK_CLR,color,"%u",tbl->class);
}
break;
case 4:
case 5:
case 6:
case 7:
case 8:
if(!tbl->feeflag[j-4])
outf(x+3,y,BK_CLR,YELLOW,"否",0);
else
outf(x+3,y,BK_CLR,CHR_CLR,"計",0);
break;
case 9: /* maxinum minutes of a call */
if(tbl->max_min != 0)
outf(x-2,y,7,0,"%u",tbl->max_min);
break;
default:
break;
} /* END SWITCH */
} /* END FOR2 */
tbl++;
} /* END FOR1 */
return;
}
/* Function : Run commands user input.
* calls : save_phone_tbl,sort_phone_tbl,loc_phone_tbl,
* loc_page,pgup_phone_tbl,pgdn_phone_tbl,
* modi_phone_tbl,del_phone_tbl,set_trunk
* called by: rate_set()
* date : 1993.9.21
*/
void input_phone_num(UC mode)
{
UI input,pos;
UC *title = "注意:";
UC *warn = "最多只能有這么多分機(jī)號碼!";
UC result;
UNIT_STRUCT cur_unit;
while(1)
{
input=get_key1();
get_current(&cur_unit);
pos = Count+cur_unit.unit_x;
switch(input)
{
case ESC: /* QUIT */
result=select_1in3();
switch(result)
{
case 1: /* DON'T QUIT */
break;
case 2: /* SAVE AND QUIT */
save_phone_tbl(NOFRESH, mode);
recover_screen(2);
return;
case 3: /* QUIT AND DON'T SAVE */
recover_screen(2);
return;
}
break;
case UP: /* GO TO THE LAST ROW */
move_finger(0,1);
break;
case DOWN: /* GO TO THE NEXT ROW */
if(pos == MAX_USERS )
{
warn_mesg(title, warn);
break;
}
if(pos <= Newlen )
move_finger(1,1);
else
sound_bell();
break;
case LEFT:
if(cur_unit.unit_y > 1) /* left a step */
move_finger(2,1);
else
sound_bell();
break;
case RIGHT:
if( strlen(Phone_top[pos-1].phone_no) )
move_finger(3,1); /* right a step */
else
sound_bell();
break;
case PAGEUP:
pgup_phone_tbl(mode);
break;
case PAGEDOWN:
pgdn_phone_tbl(mode);
break;
case F2: /* SAVE THE PHONE TABLE */
save_phone_tbl(REFRESH, mode);
break;
case F5: /* DELETE */
delete_num(mode);
break;
case F9:
auto_add_one(mode);
break;
case ENTER:
modi_phone_tbl(mode); /* MODIFY THE PHONE TABLE */
break;
default:
sound_bell();
break;
}/* END OF SWITCH */
}/* END OF WHILE */
}
/* function : Modify the phone number table.
* calls : phone_tbl_len,maxnum
* called by : input_phone_num()
* date :
*/
void modi_phone_tbl(UC mode)
{
int result;
UI xs,ys,xe,ye;
UC res;
UI num;
UI pos;
UI back_in=3;
UC phone_buf[10] = "";
UC *title = "注意:";
UC *warn = "該分機(jī)號碼已有, 請重新輸入!";
PHONE_STRUCT *tbl;
UNIT_STRUCT cur_unit;
UL value;
get_current(&cur_unit);
if(mode == SET_IMPRN && cur_unit.unit_y != 2)
return;
xs = cur_unit.dot_sx;
ys = cur_unit.dot_sy;
pos = Count+cur_unit.unit_x;
hide_finger();
switch(cur_unit.unit_y)
{
case 1:
if(pos <= Oldlen)
{
sound_bell(); /* add only, do not change */
echo_finger();
break;
}
message_disp(8," 輸入數(shù)字 Enter 確認(rèn)"); /*number*/
do
{
strcpy(phone_buf,"");
set_get_color(0, 10, 10, BK_CLR, CHR_CLR);
res = get_account(xs, ys, 18, 60, 4, 8, phone_buf, 0);
if(!res) /* ESC or not change phone_buf */
break;
tbl = Phone_top;
num = 0;
do
{
result = strcmp(tbl->phone_no, phone_buf);
/*** THE phone No. INPUTTED ALREADY EXIST, REINPUT ***/
/* Phone_top[pos-1] is the item being
* editted, so not judge it
*/
if((!result) && (tbl != &Phone_top[pos-1]))
{
UNIT_STRUCT cur;
warn_mesg(title, warn);
/* clear the current item */
get_current(&cur);
xs = cur.dot_sx;
ys = cur.dot_sy;
xe = cur.dot_ex;
ye = cur.dot_ey;
setfillstyle(1, BK_CLR);
bar(xs, ys, xe, ye);
break;
}
tbl++;
num++;
}while(strlen(tbl->phone_no) && num<MAX_USERS);
}while(strlen(tbl->phone_no) && num<MAX_USERS);
/***** RECORD THE phone No. AND LENGTH INPUTTED. *****/
if(res)
{
strcpy(Phone_top[pos-1].phone_no, phone_buf);
move_finger(3,1);
}
else
echo_finger();
Newlen = phone_tbl_len();
message_end();
break;
case 2:
if(mode == SET_PCODE)
{
// message_disp(8,"請輸入內(nèi)碼"); /* input inner code*/
do {
do {
value = -1;
set_get_color(0, 10, 10, BK_CLR, LIGHTRED);
result = get_dec(xs,ys,18,24,back_in,3,&value,0x0);
}while(result &&(value > MAX_USERS-1 || !Sys_mode.com_m[(UC)(value/PhonesPerPort)]));
tbl = Phone_top;
num = 0;
do {
if(tbl->code == value && tbl!=&Phone_top[Count+cur_unit.unit_x-1])
{
UNIT_STRUCT cur;
UC *title = "注意:";
UC *warn = "該碼已有, 請重新輸入!";
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -