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

📄 cal_fee.c

📁 BC3.1编译,小交换机计费系统.使用Dos做出如此好的界面,少有.
💻 C
📖 第 1 页 / 共 3 页
字号:
{
    UI     i;
    FILE  *fp, *acc_fp;
    struct time tt;
    struct date dd;
    ACC_STRUCT  acc;

    getdate(&dd);
    gettime(&tt);

    acc.seral_no.year  = (UC) (dd.da_year-1900);
    acc.seral_no.month = (UC) dd.da_mon;
    acc.seral_no.day   = (UC) dd.da_day;
    acc.seral_no.hour  = tt.ti_hour;
    acc.seral_no.min   = tt.ti_min;
    acc.seral_no.sec   = tt.ti_sec;

    acc.flag = isacc;
    acc.phone_no = 0;

    acc.intern_time   = Account.intern_time;
    acc.intern_charge = Account.intern_charge;
    acc.intern_count  = Account.intern_count;

    acc.nation_time   = Account.nation_time ;
    acc.nation_charge = Account.nation_charge;
    acc.nation_count  = Account.nation_count;

    acc.local_time   = Account.local_time;
    acc.local_charge = Account.local_charge;
    acc.local_count  = Account.local_count;

    acc.month_lease  = Account.month_lease;

    for(i=0; i<5; i++)
        acc.addfee[i] = Account.addfee[i];

    message_disp(8,"正在进行扎帐处理, 请稍候...");  /* calculating, please wait... */

    if(isacc == BAN_ACC)
        fp = fopen("gfsdata\\banacc.dat","ab");
    else if(isacc == DAY_ACC)
        fp = fopen("gfsdata\\dayacc.dat","ab");
    else if(isacc == MON_ACC)
        fp = fopen("gfsdata\\monacc.dat","ab");
    else
        fp = fopen("gfsdata\\yearacc.dat","ab");

    fwrite(&acc, sizeof(ACC_STRUCT), 1, fp);
    fclose(fp);

    if(isacc == BAN_ACC)
        acc_fp = fopen("gfsdata\\feeacc.hst","ab");
    else if(isacc == DAY_ACC)
        acc_fp = fopen("gfsdata\\banacc.hst","ab");
    else if(isacc == MON_ACC)
        acc_fp = fopen("gfsdata\\dayacc.hst","ab");
    else
        acc_fp = fopen("gfsdata\\monacc.hst","ab");

    if(isacc == BAN_ACC)
        fp = fopen("gfsdata\\feeacc.dat","rb");
    else if(isacc == DAY_ACC)
        fp = fopen("gfsdata\\banacc.dat","rb");
    else if(isacc == MON_ACC)
        fp = fopen("gfsdata\\dayacc.dat","rb");
    else
        fp = fopen("gfsdata\\monacc.dat","rb");

    if(fp != NULL)
    {
        while(fread(&acc, sizeof(ACC_STRUCT), 1, fp) == 1)
            fwrite(&acc, sizeof(ACC_STRUCT), 1, acc_fp);
        fclose(fp);
    }
    fclose(acc_fp);

    if(isacc == BAN_ACC)
        remove("gfsdata\\feeacc.dat");
    else if(isacc == DAY_ACC)
        remove("gfsdata\\banacc.dat");
    else if(isacc == MON_ACC)
        remove("gfsdata\\dayacc.dat");
    else
        remove("gfsdata\\monacc.dat");

    message_end();
    return;
}

/* function  : calculate the total dialing fee for all the phone
 * called by : statistics()
 * date      : 1993.10.9
 */
void cal_one_fee(UL phone_no, UC isauthcd)
{
    UI    i;
    UC    user[10], sflg1, sflg2, sflg3;
    TIME_STRUCT    stime1, etime1, stime2, etime2, stime3, etime3;
    PHONE_STRUCT  *phone;
    AUTHCD_STRUCT *authcd;
    FILE *fp;

    sflg1 = 0;
    sflg2 = 0;
    sflg3 = 0;

    if(isauthcd == PHONE_FEE)
    {
        ltoa(phone_no, user, 10);            /* int to ASCII string */
        phone = binary_search(user);         /* locate the phone No */
        if(phone == NULL)                    /* can't find the No   */
            return;
    }
    else if(isauthcd == AUTH_CD)
    {
        authcd = binary_authcd(phone_no);          /* locate the phone No */
        if(authcd == NULL)                     /* can't find the No   */
            return;
    }

    message_disp(8,"正在计算, 请稍候...");  /* calculating, please wait... */

    Account.intern_time   = 0;
    Account.intern_charge = 0;
    Account.intern_count  = 0;

    Account.nation_time   = 0;
    Account.nation_charge = 0;
    Account.nation_count  = 0;

    Account.local_time   = 0;
    Account.local_charge = 0;
    Account.local_count  = 0;

    if(isauthcd == PHONE_FEE)
    {
        Account.month_lease = phone->month_lease;
        Account.addfee[4] = 0;
        for(i=0; i<4; i++)
            Account.addfee[i] = phone->addfee[i];
    }
    else if(isauthcd == AUTH_CD)
    {
        Account.month_lease = authcd->month_lease;
        Account.addfee[0] = authcd->addfee;
        for(i=1; i<5; i++)
            Account.addfee[i] = 0;
    }

    stime1.year = 9999;
    etime1.year = 0000;
    stime1.month = 99;
    etime1.month = 00;
    stime1.day = 99;
    etime1.day = 00;
    stime1.hour = 99;
    etime1.hour = 00;

    stime2.year = 8888;
    etime2.year = 1111;
    stime2.month = 88;
    etime2.month = 11;
    stime2.day = 88;
    etime2.day = 11;
    stime2.hour = 88;
    etime2.hour = 11;

    stime3.year = 7777;
    etime3.year = 1111;
    stime3.month = 77;
    etime3.month = 11;
    stime3.day = 77;
    etime3.day = 11;
    stime3.hour = 77;
    etime3.hour = 11;

    fp = fopen("idd.dbf","rb");
    if(fp != NULL)
    {
        while(fread(&temp_list,sizeof(RECORD_STRUCT),1,fp) == 1)
        {
            if( ( (isauthcd == PHONE_NO) && (temp_list.auth_code != 0xaaaaaa) ) ||\
                ( (isauthcd == AUTH_CD)  && (temp_list.auth_code == 0xaaaaaa) ) )
                continue;

            if( (isauthcd == PHONE_NO) && (temp_list.caller2 != phone_no) )
                continue;

            if( (isauthcd == AUTH_CD) && (temp_list.auth_code != phone_no) )
                continue;

            if(temp_list.flag == FALSE)
                continue;

            if(temp_list.time%60 != 0 )
                temp_list.time   = (temp_list.time/60 + 1)*60;

            Account.intern_time   += temp_list.time;

//            Account.intern_charge += temp_list.charge-temp_list.add;
            Account.intern_charge += temp_list.charge;
            Account.intern_count  += 1;

//            Account.addfee[4]     += (UL)temp_list.add;

            if(sflg1 == 0)
            {
                sflg1 = 1;
                stime1.year = temp_list.year1;
                stime1.month = temp_list.mon1;
                stime1.day = temp_list.day1;
                stime1.hour = temp_list.hour1;
            }
            etime1.year = temp_list.year2;
            etime1.month = temp_list.mon2;
            etime1.day = temp_list.day2;
            etime1.hour = temp_list.hour2;
        }
        fclose(fp);
    }

    fp = fopen("ddd.dbf","rb");
    if(fp != NULL)
    {
        while(fread(&temp_list,sizeof(RECORD_STRUCT),1,fp) == 1)
        {
            if( ( (isauthcd == PHONE_NO) && (temp_list.auth_code != 0xaaaaaa) ) ||\
                ( (isauthcd == AUTH_CD)  && (temp_list.auth_code == 0xaaaaaa) ) )
                continue;

            if( (isauthcd == PHONE_NO) && (temp_list.caller2 != phone_no) )
                continue;

            if( (isauthcd == AUTH_CD) && (temp_list.auth_code != phone_no) )
                continue;

            if(temp_list.flag == FALSE)
                continue;

            if(temp_list.time%60 != 0 )
                temp_list.time = (temp_list.time/60 + 1)*60;

            Account.nation_time += temp_list.time;
//            Account.nation_charge += temp_list.charge-temp_list.add;
            Account.nation_charge += temp_list.charge;
            Account.nation_count  += 1;
//            Account.addfee[4]   += (UL)temp_list.add;

            if(sflg2 == 0)
            {
                sflg2 = 1;
                stime2.year = temp_list.year1;
                stime2.month = temp_list.mon1;
                stime2.day = temp_list.day1;
                stime2.hour = temp_list.hour1;
            }
            etime2.year = temp_list.year2;
            etime2.month = temp_list.mon2;
            etime2.day = temp_list.day2;
            etime2.hour = temp_list.hour2;
        }
        fclose(fp);
    }

    if(Usr_typ == HOTEL_USR && Ldd_fflg == YES)
    {
        fp = fopen("ldd.dbf","rb");
        if(fp != NULL)
        {
            while(fread(&temp_list,sizeof(RECORD_STRUCT),1,fp) == 1)
            {
                if( ( (isauthcd == PHONE_NO) && (temp_list.auth_code != 0xaaaaaa) ) ||\
                    ( (isauthcd == AUTH_CD)  && (temp_list.auth_code == 0xaaaaaa) ) )
                    continue;

                if( (isauthcd == PHONE_NO) && (temp_list.caller2 != phone_no) )
                    continue;

                if( (isauthcd == AUTH_CD) && (temp_list.auth_code != phone_no) )
                    continue;

                if(temp_list.flag == FALSE)
                    continue;

                if(temp_list.time%60 != 0 )
                    temp_list.time = (temp_list.time/60 + 1)*60;

                Account.local_time   += temp_list.time;
//                Account.local_charge += temp_list.charge-temp_list.add;
                Account.local_charge += temp_list.charge;
                Account.local_count  += 1;
//                Account.addfee[4]    += (UL)temp_list.add;

                if(sflg3 == 0)
                {
                    sflg3 = 1;
                    stime3.year = temp_list.year1;
                    stime3.month = temp_list.mon1;
                    stime3.day = temp_list.day1;
                    stime3.hour = temp_list.hour1;
                }
                etime3.year = temp_list.year2;
                etime3.month = temp_list.mon2;
                etime3.day = temp_list.day2;
                etime3.hour = temp_list.hour2;
            }
            fclose(fp);
        }
    }

    fnd_stime(&stime1, &stime2);
    fnd_stime(&stime1, &stime3);
    fnd_etime(&etime1, &etime2);
    fnd_etime(&etime1, &etime3);

    etime1.hour++;

    fp = fopen("gfsdata\\acctime.dat","wb");
    fwrite(&stime1, sizeof(TIME_STRUCT), 1, fp);
    fwrite(&etime1, sizeof(TIME_STRUCT), 1, fp);
    fclose(fp);

    message_end();
    return;
}


void fnd_stime(TIME_STRUCT *time1, TIME_STRUCT *time2)
{
    UC flag=0;

    if(time1->year > time2->year)
        flag = 1;
    else if(time1->year == time2->year)
    {
        if(time1->month > time2->month)
            flag = 1;
        else if(time1->month == time2->month)
        {
            if(time1->day > time2->day)
                flag = 1;
            else if(time1->day == time2->day)
            {
                if(time1->hour > time2->hour)
                    flag = 1;
            }
        }
    }
    if(flag == 1)
    {
        time1->year = time2->year;
        time1->month = time2->month;
        time1->day = time2->day;
        time1->hour = time2->hour;
    }
    return;
}

void fnd_etime(TIME_STRUCT *time1, TIME_STRUCT *time2)
{
    UC flag=0;

    if(time1->year > time2->year)
        flag = 1;
    else if(time1->year == time2->year)
    {
        if(time1->month > time2->month)
            flag = 1;
        else if(time1->month == time2->month)
        {
            if(time1->day > time2->day)
                flag = 1;
            else if(time1->day == time2->day)
            {
                if(time1->hour > time2->hour)
                    flag = 1;
            }

⌨️ 快捷键说明

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