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

📄 set_user.c

📁 BC3.1编译,小交换机计费系统.使用Dos做出如此好的界面,少有.
💻 C
📖 第 1 页 / 共 2 页
字号:
    /**** If the rate table is empty, the new item is
		  the first one in the table. ****/
    if(!UOldlen)
    {
	tbl[0] = *newitem;
	return;
    }

    /**** The new item is inserted in middle of the table. ****/
    do
    {
	 if(newitem->user_no == tbl->user_no)
	     return;

	 if(tbl->user_no > newitem->user_no)     /* INSERT HERE */
	 {
	      tblptr = &User_top[UOldlen];
	      while(tblptr > tbl)
	      {
		 *tblptr = *(tblptr-1);
		 tblptr--;
	      }

	      *tblptr = *newitem;
	      return;
	 }

	 tbl++;
	 num++;
    }while(tbl->phones && num<MAX_USERS);

    /**** The new item is the last one in the rate table. ****/
    *tbl = *newitem;
    return;
}

/* function  : locate according to the user_no
 * date      : 1993.11.9
 */
void loc_user_tbl(void)
{
    USERS_STRUCT  *tbl;
    UC result;
    UL locate_no;
    UC *msg ="定位户头号";     /* DING WEI hu tou HAO */
    UC *warn="无该户头号码!";     /* WU CI QU HAO!   */

    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. USERS INPUT. *****/
    set_get_color(11, 0, 12, 11, 0);
    result = get_dec(350, 306, 18, 24, 0, 4, &locate_no, 0x00);

    rid_pop();

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

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

    if(tbl != NULL)
    {
	 Count = ((UI)(tbl-User_top)/16)*16+1;
         hide_finger();
         brush_tbl(4, 16, 7);
	 disp_user_tbl(&User_top[Count-1], Count);
	 locate_finger(tbl-User_top-Count+1, 1);       /* LOCATTED */
	 return;
    }

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

/* function  : modify the user table
 * date      : 1993.11.9
 */
void modi_user_tbl(void)
{
    UC res;
    UI num;
    UI xs,ys,xe,ye;
    UI result;
    UI back_in=5;
    UL input=0;
    UC name_buf[25] = "";
    UC *title = "注意:";
    UC *warn = "该户头号码已有, 请重新输入!";
    USERS_STRUCT  *tbl;
    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:    /* user unit no */
	    if(Count+cur_unit.unit_x <= UOldlen)
	    {
		sound_bell();          /* add only, do not change */
		echo_finger();
		return;
	    }

	    message_disp(8," 输入1--9999之间的整数   Enter 确认");     /* input 1--9999*/

	    do
	    {
		input = 0;
		do
		{
		    set_get_color(0, 10, 10, 7, 0);
		    res = get_dec(xs, ys+1, 17, 55, back_in, 4, &input, 0x00);
		}while(res && (input<1 || input>9999) );

		if(!res)
		    break;

		tbl = User_top;
		num = 0;
		do
		{
		    result = tbl->user_no-(UI)input;

		    /*** THE AREA No. INPUTTED ALREADY EXIST, REINPUT ***/
		    /* User_top[Count+cur_unit.unit_x-1] is the item being
		     * editted, so not judge it
		     */
		    if((result==0) && (tbl!=&User_top[Count+cur_unit.unit_x-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, 7);
			bar(xs, ys, xe, ye);

			break;
		    }

		    tbl++;
		    num++;
		}while(tbl->phones && num<MAX_USERS);
	    }while(tbl->phones && num<MAX_USERS);

	    /***** RECORD THE AREA No. AND LENGTH INPUTTED. *****/
	    if(res)
	    {
		User_top[Count+cur_unit.unit_x-1].user_no = (UI)input;
		move_finger(3,1);
	    }
	    else
		echo_finger();

	    message_end();
	    break;

	case 2:    /* user unit name */
	    strcpy(name_buf, User_top[Count+cur_unit.unit_x-1].user_name);
	    message_disp(8," 输入汉字   Enter 确认");      /*chinese char*/
	    set_get_color(0, 10, 10, 7, 0);
	    result = get_hz_str(xs, ys, 18, 220, back_in, 12, name_buf);
	    message_end();
	    if(result)
		strcpy(User_top[Count+cur_unit.unit_x-1].user_name, name_buf);
	    move_finger(3,1);
	    break;

	case 3:    /* phone number of this unit */
	    input = 0;
	    do
	    {
		message_disp(8," 输入数字   Enter 确认");      /*number*/
		set_get_color(0, 10, 10, 7, 0);
		result = get_dec(xs, ys+1, 17, 60, back_in, 3, &input, 0x00);
		message_end();
	    }while(result && (input<1 || input>MAX_USERS) );

	    /***** IF NOT "Esc", RECORD THE RATE INPUTTED. *****/
	    if(result)
		User_top[Count+cur_unit.unit_x-1].phones = (UI)input;

	    if( (Count+cur_unit.unit_x) != MAX_USERS && input )
		move_finger(1,1);
	    move_finger(2,2);
	    break;
    }/* END OF SWITCH */

    UNewlen = user_tbl_len();
    return;
}

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

    /***** DISPLAY THE LAST PAGE. *****/
    hide_finger();
    brush_tbl(4, 16, 7);
    Count = Count-16;
    disp_user_tbl(&User_top[Count-1], Count);

    locate_finger(15,1);
}

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

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

    /***** IF END OF TABLE, RETURN. *****/
    if((Count+15) > UNewlen)
    {
	sound_bell();
	return;
    }

    /***** DISPLAY THE NEXT PAGE. *****/
    Count = Count+16;
    hide_finger();
    brush_tbl(4, 16, 7);
    disp_user_tbl(&User_top[Count-1], Count);

    locate_finger(0,1);
}

/* function  : delete in item in the user unit table
 * date      : 1993.11.9
 */
void delet_user_item(void)
{
    UI i;
    UI x, y, cur_pos;
    UI xs, ys, xe, ye;
    UC result;
    UNIT_STRUCT cur_unit;
    USERS_STRUCT  *tbl;

    get_current(&cur_unit);

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

    /***** CLEAR THE ITEM DELETED WITH "- - -". *****/
    move_finger(2, cur_unit.unit_y-1);
    for(i = 0; i < 3; 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(4, 16, 7);
	disp_user_tbl(&User_top[Count-1], Count);
	echo_finger();
	return;
     }

     /***** DELETE A ITEM *****/
     tbl = &User_top[Count+cur_unit.unit_x-1];
     cur_pos = Count+cur_unit.unit_x;
     while(tbl->phones && (cur_pos<UNewlen) )
     {
	 *tbl= *(tbl+1);
	 tbl++;
	 cur_pos++;
     }

     memset(&User_top[UNewlen-1], 0, sizeof(USERS_STRUCT));

     UNewlen--;

     if((Count+cur_unit.unit_x-1) < UOldlen)
	 UOldlen--;

     hide_finger();
     brush_tbl(4, 16, 7);
     disp_user_tbl(&User_top[Count-1], Count);   /* REDISPLAY */

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

/* function  : locate according to the page No.
 * date      : 1993.11.9
 */
void loc_user_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. USERS 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(!(UNewlen%16) && UNewlen)       /* calculate the pages */
	 page_no = UNewlen/16;
    else
	 page_no = (UI)(UNewlen/16)+1;

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

    /***** DISPLAY THE PAGE. *****/
    hide_finger();
    brush_tbl(4, 16, 7);
    Count = (UI)(locate_no-1)*16+1;
    disp_user_tbl(&User_top[Count-1], Count);

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

/* function  :    Locate the user no using the binary search method
 * calls     :    None
 * called by :    loc_user_tbl()
 * input     :    locate_no -- user
 * return    :    The position of location. If not find, return NULL
 * note      :    using binary search method
 * date      :    1993.11.9
 */
USERS_STRUCT *binary_user(UL locate_no)
{
    USERS_STRUCT *tbl, *tbl_top;
    UI tbllen;
    UI top, bottom, middle;

    tbl_top = User_top;
    tbl = User_top;
    tbllen = user_tbl_len();

    top = 0;
    bottom = tbllen-1;

    /***** Compare with the first item. *****/
    if( ((UL)tbl->user_no<locate_no) && ((UL)(tbl+1)->user_no>locate_no) )
	return(NULL);

    if((UL)tbl->user_no > locate_no)
	return(NULL);

    /***** Compare with the last item. *****/
    if((UL)tbl[bottom].user_no < locate_no)
	return(NULL);

    /***** Compare and locate in the fee table. *****/
    while(top <= bottom)
    {
	middle = (UI) (top+bottom)/2;
	tbl = &tbl_top[middle];

	if((UL)tbl->user_no == locate_no)            /* find! */
	    return(tbl);

	else if((UL)tbl->user_no < locate_no)       /* tbl->user_no < locate_no */
	    top = middle+1;
	else if((UL)tbl->user_no > locate_no)       /* tbl->user_no > locate_no */
	    bottom = middle-1;
    }

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


⌨️ 快捷键说明

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