⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 set_auth.c

📁 BC3.1编译,小交换机计费系统.使用Dos做出如此好的界面,少有.
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <mem.h>
#include <dir.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <alloc.h>
#include <graphics.h>
#include <bios.h>
#include <time.h>

#include <bio.inc>
#include <menu.inc>
#include <key.inc>
#include <g_id.inc>
#include "feedef.h"

#define UNIT_NUM	16
#define ITEM_NUM	 4

typedef struct
{
  UC setup[3];
  UC close[3];
  UC change[3];
}AUTH_HEAD_STRUCT;

void send_auth_code(void);

/* function  : creat the authority code and the authorized unit relation
 * called by : set_data()
 * date      : 1993.11.8
 */
void process_auth_code(UC mode)
{
    UI    pg;

    TABLE_STRUCT  authcd_tbl = {102,99,20,18,UNIT_NUM,ITEM_NUM,
    				{35,86,35,64}, ITBL_CLR};
    TABLE_STRUCT  authcd_tblq = {102,99,20,18,UNIT_NUM,ITEM_NUM,
    				{35,86,35,64},QTBL_CLR};
    AUTHCD_STRUCT *tbl;

    clr_DialWin(1);

    set_finger_color(Dsp_clr.fng_clr);
    if(mode == INQ_AUTH)
	draw_table(&authcd_tblq);        /* draw the table frame */
    else
	draw_table(&authcd_tbl);        /* draw the table frame */

    disp_authcd_head(mode);             /* display table head   */
    disp_authcd_help(mode);
    message_disp(8,"根据右上方弹出提示窗口提示操作");

    load_authcd_tbl(1);

    ANewlen = authcd_tbl_len();          /* calculate table length */
    Count = 1;
    tbl = Auth_cd_top;

    disp_authcd_tbl(tbl,Count);          /* display 1th page of the authority code table */

    if(!(ANewlen%UNIT_NUM) && ANewlen)         /* calculate the pages and display */
	 pg = ANewlen/UNIT_NUM;
    else
	 pg = (UI)(ANewlen/UNIT_NUM)+1;
    outf(542,397,11,14,"%2u",pg);

    locate_finger(0,1);
    process_authcd_data(mode);
    unload_authcd_tbl();

    recover_screen(1);
    message_end();

    return;
}

/* function  : display the head information for authority code setting
 * called by : set_authcd_unit()
 *
 */
void disp_authcd_head(UC mode)
{
	 if(mode==SET_AUTH)
	     hz16_disp(150,80, "授  权  用  户  设  定", BLACK);   /* authcd setting */
	 else
	     hz16_disp(150,80, "授  权  用  户  查  询", BLACK);   /* authcd inquiring */

	 outf(104, 103, 7, 0, "卡号");        /* seqence no   */
	 outf(143, 103, 7, 0, "授权用户名");    /* authed authcd name    */
	 outf(228, 103, 7, 0, "级别");        /* auth class */
	 outf(270, 103, 7, 0, "月租费");    /* authed authcd name    */

	 return;
}

/* function  : display the help information
 * called by : set_authcd_unit()
 * date      : 1993.11.9
 */
void disp_authcd_help(UC mode)
{
    /*** PROMPT: ***/
    draw_back1(490, 122, 625, 357, 11);
    if(mode==SET_AUTH)
    {
	outf(500, 142, 11, 0, "F2   存盘");
	outf(500, 162, 11, 0, "F5   删除");
	outf(500, 182, 11, 0, "F6   卡号定位");
	outf(500, 202, 11, 0, "F7   页定位");
	outf(500, 222, 11, 0, "←↓→↑ 移动");
	outf(500, 242, 11, 0, "PgUp  向前翻页");
	outf(500, 262, 11, 0, "PgDn  向后翻页");
	outf(500, 282, 11, 0, "Enter 输入");

	outf(500, 322, 11, 0, "Esc   退出");
    }
    else
    {
	outf(500, 142, 11, 0, "F6   卡号定位");
	outf(500, 162, 11, 0, "F7   页定位");
	outf(500, 182, 11, 0, "←↓→↑ 移动");
	outf(500, 202, 11, 0, "PgUp  向前翻页");
	outf(500, 222, 11, 0, "PgDn  向后翻页");

	outf(500, 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  : load authority code from authcd.dat
 * called by : set_authcd_unit()
 * input     : mode -- 0 : if there is no charge.aus file, return false
 *                     1 : if there is no charge.aus file, alloc memory
 * date      : 1993.11.9
 */
UC load_authcd_tbl(UC Alloc)
{
    FILE          *fp;
    AUTHCD_STRUCT *tbl;
    UL            ss;
    int           i, num = 0;

    if(Auth_cd_top != NULL ) /* already load */
    	return(TRUE);

    fp = fopen(ChargeDataFile[AUTH_CASH],"rb");
    if(fp == NULL && Alloc == 0)
	return(FALSE);

    Auth_cd_top = (AUTHCD_STRUCT *) farcalloc( MAX_AUTHCD , sizeof(AUTHCD_STRUCT) );
    if(!Auth_cd_top)
    {
        ss = (UL) ( MAX_AUTHCD *sizeof(AUTHCD_STRUCT) );
	exit_scr(1,"Out of memery ERROR: %ld bytes.\n\nGFS system shutdown abnormally.\n\n\n\n",ss);
    }
    tbl = Auth_cd_top;

    if(fp != NULL) {
        while(fread(tbl,sizeof(AUTHCD_STRUCT), 1, fp) == 1)
        {
             tbl++;
             num++;
        }
	fclose(fp);
    }

    for(i=num; i<MAX_AUTHCD ; i++)
    {
	tbl->auth_code = i;
	tbl->auth_class = UNUSED_AUTH;
	tbl->auth_usr_nam[0] = '\0';
	tbl->month_lease = 0;
        tbl++;
    }

    return(TRUE);
}

/* function  : free the alloced space
 * called by : set_authcd_unit()
 * date      : 1993.11.9
 */
void unload_authcd_tbl(void)
{
       farfree(Auth_cd_top);
       Auth_cd_top = NULL;
       return;
}


/* function  : calculate the length of the authcd table
 * called by : set_authcd_unit()
 * output    : length of the authcd table
 * date      : 1993.11.9
 */
UI authcd_tbl_len(void)
{
    AUTHCD_STRUCT  *tbl;
    UI tbllen = MAX_AUTHCD;

    tbl = Auth_cd_top+MAX_AUTHCD-1;

    while( (tbl->auth_class == UNUSED_AUTH) && (tbllen>0) && tbl->auth_set_flag==0)
    {
	tbllen--;
	tbl--;
    }

    return(tbllen);
}

/* function  : display a page of the authority code talbe
 * input     : tbl -- the first struct of this page
 *             num -- the sequence no of the first struct of this page
 * date      : 1993.11.9
 */
void disp_authcd_tbl(AUTHCD_STRUCT *tbl, int num)
{
    UI i, j;
    UI x, y;
    UI pg;
    UNIT_STRUCT cer_unit;
    UC color;

    for(i=0;i<UNIT_NUM;i++)        /* DISPLAY No. IN THE TABLE */
    {
	 if(num+i > MAX_AUTHCD )
	     break;

	 outf(108, i*19+123, 7, 0, "%-3u", num+i-1);
    }

    pg = (UI)(num/UNIT_NUM)+1;    /* DISPLAY THIS PAGE No. */
    setfillstyle(1,11);
    bar(534, 393, 575, 377);
    outf(542, 377, 11, 14, "%2u", pg);

    if(num == ANewlen+1)      /* the table has been added, so redisplay pg */
    {
	 bar(534, 413, 575, 397);
	 outf(542, 397, 11, 14, "%2u", pg);
    }

    /***** Display a page of the rate table. *****/
    for(i=0;i<UNIT_NUM;i++)
    {
	 if( num+i > MAX_AUTHCD )
	     break;

	 if( tbl->auth_class != UNUSED_AUTH )
         {
   	     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+5;
	          y = cer_unit.dot_sy+1;

		  switch(j)
	          {
		       case 1:    /* authrized user name */
		           outf(x, y, 7, 0, "%-s", tbl->auth_usr_nam);
		           break;
		       case 2:    /* authority class */
                           if(tbl->auth_set_flag)
                               color = LIGHTRED;
                           else
                               color = 0;
		           outf(x,y,7,color,"%1d", tbl->auth_class);
		           break;
		       case 3:    /* authrized user month lease */
		           outf(x, y, 7, 0, "%6.2f", ((double)tbl->month_lease)/100);
		           break;
		       default:
			   break;
	           }/* END SWITCH */
	     }/* END FOR2 */
         }
         else if (tbl->auth_set_flag) /* have not been deleted succussfully*/
         {
	     cer_unit.unit_x = i;
	     cer_unit.unit_y = 1;
	     get_certain(&cer_unit);
	     x = cer_unit.dot_sx+5;
	     y = cer_unit.dot_sy+1;

	     outf(x, y, 7, LIGHTRED, "未下送");
         }
	 tbl++;
    }/* END FOR1 */

    return;
}

/* function  : run commands authcd inputs
 * date      : 1993.11.9
 */
void process_authcd_data(UC mode)
{
    UI input;
    UC *title = "注意:";
    UC *warn = "最多只能有这么多授权用户!";
    UC result;
    UNIT_STRUCT cur_unit;

    while(1)
    {
	input=get_key1();

	get_current(&cur_unit);

	switch(input)
	{
	    case ESC:   /* QUIT */
		 if(mode==SET_AUTH)
		 {
		     result=select_1in3();
		     switch(result)
		     {
			 case 1:     /* DON'T QUIT */
			     break;

			 case 2:     /* SAVE AND QUIT */
			     message_disp(8,"正在存盘,请稍候...");      /* saving, please wait... */
			     save_authcd_tbl(NOFRESH, 1);
			     message_end();
			     return;

			 case 3:     /* QUIT AND DON'T SAVE */
			     return;
		     }
		     break;
		 }
		 else
		 {
		     return;
		 }
	    case UP:    /* GO TO THE LAST ROW */
		 move_finger(0,1);
		 break;

	    case DOWN:  /* GO TO THE NEXT ROW */
		 if(Count+cur_unit.unit_x == MAX_AUTHCD )
		 {
		      warn_mesg(title, warn);
		      break;
		 }
		 move_finger(1,1);

/*		 if((Count+cur_unit.unit_x) <= ANewlen)
		 {
		     move_finger(1,1);
		     if((Count+cur_unit.unit_x) == ANewlen)
			 move_finger(2,cur_unit.unit_y-1);
		 }
		 else
		     sound_bell();
*/		 break;

	    case LEFT:
		 if(cur_unit.unit_y != 1)
		     move_finger(2,1);
		 else
		     sound_bell();
		 break;

	    case RIGHT:
//		 if(Auth_cd_top[Count+cur_unit.unit_x-1].auth_class != UNUSED_AUTH)
		     move_finger(3,1);
//		 else
//		     sound_bell();
		 break;

	    case PAGEUP:
		 pgup_authcd_tbl();
		 break;

	    case PAGEDOWN:
		 pgdn_authcd_tbl();
		 break;

	    case F2:    /* SAVE THE RATE TABLE */
		 if(mode==SET_AUTH)
		 {
		     message_disp(8,"正在存盘,请稍候...");      /* saving, please wait... */
		     save_authcd_tbl(REFRESH, 1);
		     message_end();
		 }
		 break;


	    case F5:    /* DELETE */
		 if(mode==SET_AUTH)
		     delet_authcd_item();
		 break;

	    case F6:   /* AREA No. LOCATE */
		 message_disp(8," 输入卡号  Enter 确认");    /*authcd no.*/
		 loc_authcd_tbl();
		 message_end();
		 break;

	    case F7:    /* PAGE No. LOCATE */
		 message_disp(8," 输入页号   Enter 确认");      /*page no.*/
		 loc_authcd_page();
		 message_end();
		 break;

	    case ENTER:
		 if(mode==SET_AUTH)
		     modi_authcd_tbl();      /* MODIFY THE RATE TABLE */
		 break;

	    default:
		 sound_bell();
		 break;
	}/* END OF SWITCH */
    }/* END OF WHILE */
}

/* function  : save the authority code setting table
 * input     : status=0 -- not refresh
 *             status=1 -- refresh
 *             send_flag=0 -- not send
 *             send_flag=1 -- send
 * date      : 1993.11.9
 */
void save_authcd_tbl(UC status, UC send_flag)
{
    FILE *authcd_file;

    ANewlen = authcd_tbl_len();
//    if(ANewlen == 0)
//        return;

    if(send_flag)
        send_auth_code();

    authcd_file = fopen(ChargeDataFile[AUTH_CASH], "wb");
    fwrite(Auth_cd_top, sizeof(AUTHCD_STRUCT), ANewlen, authcd_file);
    fclose(authcd_file);

    if(status == REFRESH)
    {
	hide_finger();
        brush_tbl(ITEM_NUM, UNIT_NUM, 7);
	disp_authcd_tbl(&Auth_cd_top[Count-1], Count);   /* REDISPLAY */
	echo_finger();
    }

⌨️ 快捷键说明

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