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

📄 set_auth.c

📁 BC3.1编译,小交换机计费系统.使用Dos做出如此好的界面,少有.
💻 C
📖 第 1 页 / 共 2 页
字号:
    if(Cashflg[AUTH_CASH]) /* refresh the cash table */
	check_maint_cash(AUTH_CASH);

    return;
}


/* function  : locate according to the auth_code
 * date      : 1993.11.9
 */
void loc_authcd_tbl(void)
{
    AUTHCD_STRUCT  *tbl;
    UC result;
    UL locate_no;
    UC *msg ="定位卡号";     /* locate auth code */
    UC *warn="无该卡号!";    /* auth code not exist */

    pop_back(250, 295, 420, 335, 7);
    draw_back(345, 304, 410, 326, 11);
    outf(260, 308, 7, 0, "%s", msg);

    /***** LOCATE ACCODING TO THE PAGE No. AUTHCD INPUT. *****/
    set_get_color(11, 0, 12, 11, 0);
    result = get_dec(350, 306, 18, 24, 0, 6, &locate_no, 0x00);

    rid_pop();

    if(!result)      /* IF USER TYPE "Esc", RETRUN. */
	return;

    /***** Locate the position in the authcd table according
	       to the authcd number authcd typeed. *****/
    tbl = binary_authcd(locate_no);

    if(tbl != NULL)
    {
	 Count = ((UI)(tbl-Auth_cd_top)/UNIT_NUM)*UNIT_NUM+1;
         hide_finger();
         brush_tbl(ITEM_NUM, UNIT_NUM, 7);
	 disp_authcd_tbl(&Auth_cd_top[Count-1], Count);
	 locate_finger(tbl-Auth_cd_top-Count+1, 1);       /* LOCATTED */
	 return;
    }

    /***** Cann't locate, warning. *****/
    warn_mesg("", warn);
    return;
}

/* function  : modify the authcd table
 * date      : 1993.11.9
 */
void modi_authcd_tbl(void)
{
    UC res;
    UI xs, ys;
    UI result;
    UI back_in=5;
    UL input=0;
    UL lease;
    UC name_buf[25] = "";
    UNIT_STRUCT cur_unit;

    hide_finger();

    get_current(&cur_unit);
    xs = cur_unit.dot_sx;
    ys = cur_unit.dot_sy;

    switch(cur_unit.unit_y)
    {
	case 1:
//	    strcpy(name_buf, Auth_cd_top[Count+cur_unit.unit_x-1].auth_usr_nam);
	    message_disp(8," 输入汉字   Enter 确认");
	    set_get_color(0, 10, 10, 7, 0);
	    result = get_hz_str(xs, ys, 18, 86, back_in, 5, name_buf);
	    message_end();
	    if(result)
		strcpy(Auth_cd_top[Count+cur_unit.unit_x-1].auth_usr_nam, name_buf);
	    move_finger(3,1);
	    break;

	case 2:
	    message_disp(8,"0-限拨 1-市话 2-农话 3-信息台 4-国内 5-国际 Enter 确认");     /* input 0--5*/
	    input = 0;
	    do
	    {
		set_get_color(0, 10, 10, 7, LIGHTRED);
		res = get_dec(xs, ys, 18, 35, back_in, 1, &input, 0x00);
	    }while(res && input>5 );

	    if(res)
	    {
		Auth_cd_top[Count+cur_unit.unit_x-1].auth_class = input;
		Auth_cd_top[Count+cur_unit.unit_x-1].auth_set_flag = 1;
		move_finger(3,1);
	    }
	    else
		echo_finger();

	    message_end();
	    break;

	case 3:
	    set_get_color(0, 10, 10, 7, 0);
	    result = get_money(xs, ys+1, 17, 64, back_in, 3, &lease, 0x00);

	    if(result)
		Auth_cd_top[Count+cur_unit.unit_x-1].month_lease = (UI)lease;

	    if( (Count+cur_unit.unit_x) < MAX_AUTHCD  )
		move_finger(1,1);
            move_finger(2,ITEM_NUM-2);
	    break;

    }/* END OF SWITCH */

    ANewlen = authcd_tbl_len();
    return;
}

/* function  : change a page towards up
 * date      : 1993.11.9
 */
void pgup_authcd_tbl(void)
{
    /***** IF THE FIRST PAGE, RETURN. *****/
    if((Count-UNIT_NUM) < 0)
    {
	sound_bell();
	return;
    }

    /***** DISPLAY THE LAST PAGE. *****/
    hide_finger();
    brush_tbl(ITEM_NUM, UNIT_NUM, 7);
    Count = Count-UNIT_NUM;
    disp_authcd_tbl(&Auth_cd_top[Count-1], Count);

    locate_finger(UNIT_NUM-1,1);
}

/* function  : change a page towards down
 * date      : 1993.11.9
 */
void pgdn_authcd_tbl(void)
{
    UC *title = "注意:";
    UC *warn  = "最多只能有这么多授权用户!";

    /***** IF MORE THAN THE MAX LENGTH, WARN AND RETURN. *****/
    if(Count+UNIT_NUM-1 >= MAX_AUTHCD )
    {
        warn_mesg(title, warn);
	return;
    }

    /***** IF END OF TABLE, RETURN. *****/
    if((Count+UNIT_NUM-1) > ANewlen)
    {
	sound_bell();
	return;
    }

    /***** DISPLAY THE NEXT PAGE. *****/
    Count = Count+UNIT_NUM;
    hide_finger();
    brush_tbl(ITEM_NUM, UNIT_NUM, 7);
    disp_authcd_tbl(&Auth_cd_top[Count-1], Count);

    locate_finger(0,1);
}

/* function  : delete in item in the authority code table
 * date      : 1993.11.9
 */
void delet_authcd_item(void)
{
    UI i;
    UI x, y;
    UI xs, ys, xe, ye;
    UC result;
    UNIT_STRUCT cur_unit;

    get_current(&cur_unit);

    if((Count+cur_unit.unit_x) > ANewlen)
    {
	    sound_bell();
	    return;
    }

    /***** CLEAR THE ITEM DELETED WITH "- - - -". *****/
    move_finger(2, cur_unit.unit_y-1);
    for(i = 0; i < ITEM_NUM; i++)
    {
	hide_finger();
	get_current(&cur_unit);
	xs = cur_unit.dot_sx;
	ys = cur_unit.dot_sy;
	xe = cur_unit.dot_ex;
	ye = cur_unit.dot_ey;
	setfillstyle(1,0);
	bar(xs,ys,xe,ye);

	x = (cur_unit.dot_ex-cur_unit.dot_sx-8)/2+cur_unit.dot_sx;
	y = (cur_unit.dot_ey-cur_unit.dot_sy-16)/2+cur_unit.dot_sy;
	outf(x, y, 0, 14, "%s", "-");

	move_finger(3,1);
    }

    /***** DISPLAY THE DELETE MENU. *****/
    move_finger(2,2);
    sound_alarm();

    result = select_1in2(10);
    /***** NOT DELETE *****/
    if(!result || result==1)
    {
	hide_finger();
        brush_tbl(ITEM_NUM, UNIT_NUM, 7);
	disp_authcd_tbl(&Auth_cd_top[Count-1], Count);
	echo_finger();
	return;
     }

     /***** DELETE A ITEM *****/
     Auth_cd_top[Count+cur_unit.unit_x-1].auth_class = UNUSED_AUTH;
     Auth_cd_top[Count+cur_unit.unit_x-1].auth_usr_nam[0] = '\0';
     Auth_cd_top[Count+cur_unit.unit_x-1].month_lease = 0;
     Auth_cd_top[Count+cur_unit.unit_x-1].auth_set_flag = 1;

     ANewlen = authcd_tbl_len();          /* calculate table length */

     hide_finger();
     brush_tbl(ITEM_NUM, UNIT_NUM, 7);
     disp_authcd_tbl(&Auth_cd_top[Count-1], Count);   /* REDISPLAY */

     locate_finger(0,1);
     echo_finger();
}

/* function  : locate according to the page No.
 * date      : 1993.11.9
 */
void loc_authcd_page(void)
{
    UL locate_no;
    UI page_no;
    UC result;
    UC *msg="定位页号";
    UC *warn="没有该页号!";

    /***** DISPLAY THE PAGE LOCATE WINDOW. *****/
    pop_back(250, 295, 400, 335, 7);
    draw_back(330, 304, 390, 326, 11);
    outf(260, 308, 7, 0, "%s", msg);

    /***** LOCATE ACCODING TO THE PAGE No. AUTHCD INPUT. *****/
    set_get_color(11, 0, 12, 11, 0);
    result = get_dec(335, 306, 18, 24, 0, 3, &locate_no, 0x00);

    rid_pop();

    if(!result)   /* "Esc" */
	return;

    if(!(ANewlen%UNIT_NUM) && ANewlen)       /* calculate the pages */
	 page_no = ANewlen/UNIT_NUM;
    else
	 page_no = (UI)(ANewlen/UNIT_NUM)+1;

    if(!locate_no || locate_no > page_no)
    {
         warn_mesg("", warn);
	 return;
    }

    /***** DISPLAY THE PAGE. *****/

    hide_finger();
    brush_tbl(ITEM_NUM, UNIT_NUM, 7);
    Count = (UI)(locate_no-1)*UNIT_NUM+1;
    disp_authcd_tbl(&Auth_cd_top[Count-1], Count);

    locate_finger(0,1);       /* LOCATTED */
}

/* function  :    Locate the authcd no using the binary search method
 * calls     :    None
 * called by :    loc_authcd_tbl()
 * input     :    locate_no -- authcd
 * return    :    The position of location. If not find, return NULL
 * note      :    using binary search method
 * date      :    1993.11.9
 */
AUTHCD_STRUCT *binary_authcd(UL locate_no)
{
   if(locate_no < MAX_AUTHCD)
    {
        if(Auth_cd_top[(UI)locate_no].auth_class != UNUSED_AUTH)
            return &Auth_cd_top[(UI)locate_no];
    }

    return(NULL);                 /* not find! */
}

/* function  :    Send authority code
 * calls     :    ToCPU()
 * called by :    save_authcd_tbl(UC status)
* input     :     none
 * return    :    none
 * note      :
 * date      :    1996.01.21
 */
void send_auth_code()
{
    int           i, j;
    UC            tmp[14];
    AUTHCD_STRUCT *tbl;
    int 	  err=0;
    UC            port;
    UL		  passwd;
    char          msg[60], buf[150], *bufp;
    char *fname ="gfsdata\\authhead.dat";
    FILE *fp;
    AUTH_HEAD_STRUCT auth_head;
    struct date d;

    /* get date */
    getdate(&d);

    /* read the authority code head */
    fp = fopen(fname,"rb");
    if(fp != NULL) {
        fread(&auth_head, sizeof(AUTH_HEAD_STRUCT), 1, fp);
        fclose(fp);
    }
    else {
        message_disp(8, "先设定密码字头");
        delay_10ms(100);
        message_end();
    }

    /* shake hand with host */
    if(ShakeHandAll() != 0) return;

    randomize(); /* initializes the random number generator */

    /* download the deleted authority codes */
    tbl = Auth_cd_top;
    for(i=0; i<ANewlen ; i++) {
    	if (tbl->auth_set_flag) {
            err = 0;
            if(tbl->auth_class == UNUSED_AUTH || tbl->auth_class == 0)
                sprintf(tmp, "099999%04d00", tbl->auth_code);
            else
	    {
                passwd = rand()*2.74+10000L; /* passwd between 10000--99999*/
                sprintf(tmp, "%06ld%04d%02d", passwd, (int)tbl->auth_code, (int)tbl->auth_class);
            }
            for(port=0; port<PORT_NUM; port++)
                if(Sys_mode.com_m[port])
                    if(DownloadCode(tmp, 6, 6, 0xBA, port) != 0) err=1;
            if(!err)
	    {
	        tbl->auth_set_flag = 0;
                if(tbl->auth_class != UNUSED_AUTH && tbl->auth_class != 0)
                {
		    if(check_prn() == FALSE)
		    {
                        sprintf(msg, "卡号:%03d 授权码: %lu", (int)tbl->auth_code, passwd);
                        message_disp(8, msg);
                        while(!kbhit());
                        message_end();
                    }
                    else
                    {
//                        message_disp(8,"正在打印,请稍候...");   /* printing */

                        /* print the client notification */
                        fp = fopen("gfsdata\\client.txt", "r");
                        if(fp == NULL)
                            prnf("卡号:%03d 授权码: %lu\n", (int)tbl->auth_code, passwd);
                        else
                        {
                            while( fgets(buf, 130, fp) != NULL)
			    {
                                for(j=strlen(buf);j<150;j++)
                            	    buf[j] = 0;

                                bufp = strstr(buf, "%");
                                while( bufp != NULL)
                                {
                                    switch(*(bufp+1))
                                    {
                                        case 'G':
					     if(tbl->auth_usr_nam) {
					         sprintf(msg, "%10s",tbl->auth_usr_nam);
                                                 strncpy(bufp, msg, strlen(msg));
                                             }
                                             else
					         strncpy(bufp, "      客人", 10);
                                             break;
                                         case 'C':
                                             sprintf(msg, "%03d", (int)tbl->auth_code);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
                                         case 'P':
                                             sprintf(msg, "%lu", passwd);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
                                         case 'O':
                                             sprintf(msg, "%2s",auth_head.setup);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
					 case 'S':
                                             sprintf(msg, "%2s",auth_head.close);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
                                         case 'X':
                                             sprintf(msg, "%2s",auth_head.change);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
                                         case 'U':
                                             strncpy(bufp, Usr_nam, strlen(Usr_nam));
                                             break;
                                         case 'D':
                                             sprintf(msg,"%d年%02d月%02d日",d.da_year,d.da_mon,d.da_day);
                                             strncpy(bufp, msg, strlen(msg));
                                             break;
                                         default:
                                             break;
                                    }
                                    bufp = strstr(bufp+1, "%");
				}
				j = strlen(buf);
				if(buf[j-1] != '\n')
				    buf[j] ='\n';
				prnf(buf);
			    }
			    fclose(fp);
			}

//                        message_end();
                    } /* end of if(check_prn() */
                }  /* end of if(tbl->auth_class) */
            }/* end of if(!err) */
        }
        tbl++;
    }

}

int ShakeHand(UC port)
{
    char *title = "错误";
    char *shake = "癥WHQCSN

⌨️ 快捷键说明

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