fstatdialcountry.cpp

来自「一套BCB6开发的电话管理系统」· C++ 代码 · 共 199 行

CPP
199
字号
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "FStatDialCountry.h"
#include "DStatDialCountry.h"
#include "PStatDialCountry.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFrmStatDialCountry *FrmStatDialCountry;
//---------------------------------------------------------------------------
__fastcall TFrmStatDialCountry::TFrmStatDialCountry( TIniFile *pMessageIniFile,
        TDMTelSys* pDMTelSys,TComponent* Owner)
        : MaxLen( 0), pMsgIniFile( pMessageIniFile), pDMTelSys( pDMTelSys), TForm(Owner)
{
    HKTelRateQuery->Close();
    HKTelRateQuery->Open();
    HKTelRateQuery->First();
    while( !HKTelRateQuery->Eof) {
        if( HKTelRateMap.find( "119001" + HKTelRateQuery->FieldByName( "locate")->AsString )
            == HKTelRateMap.end() )
        {
            HKTelRateMap[ "119001" + HKTelRateQuery->FieldByName( "locate")->AsString ]
                = StrToFloat( HKTelRateQuery->FieldByName( "rate")->AsString) ;
            HKTelUnitMap[ "119001" + HKTelRateQuery->FieldByName( "locate")->AsString ]
                = StrToInt( HKTelRateQuery->FieldByName( "second")->AsString );

            if( MaxLen < 6 + HKTelRateQuery->FieldByName( "locate")->AsString.Length()) {
                MaxLen = 6  +HKTelRateQuery->FieldByName( "locate")->AsString.Length();
            }
        }
        HKTelRateQuery->Next();
    }

    TLocateOptions Options;
    Options.Clear();
    Options << loPartialKey;
    if( pDMTelSys->UserRightQuery->Locate( "FormID", Variant( "FrmStatDialCountry"), Options)) {
        if( pDMTelSys->UserRightQuery->FieldByName( "Write")->AsString == "No") {
            PrintToolButton->Enabled = false;
        }
    }
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::FindToolButtonClick(TObject *Sender)
{
    DlgStatDialCountry = new TDlgStatDialCountry( BeginDate, EndDate, this);

    if( DlgStatDialCountry->ShowModal() == mrOk) {
        String SQLStr = "select A.*, B.name from GS_Bill A left join department B on A.department_number = B.number";
        SQLStr += " where startdate >= :BeginDate";// + BeginDate.DateString() + "'";
        SQLStr += " and startdate <= :EndDate";// + EndDate.DateString() + "'";
        SQLStr += " and dialnumber like '11900%' and len( dialnumber) > 6" ;
        SQLStr += " order by phone";

        CDSStatCountry->Close();
        StatDialCountryQuery->Close();
        StatDialCountryQuery->SQL->Clear();
        StatDialCountryQuery->SQL->Add( SQLStr);
        StatDialCountryQuery->Parameters->Clear();
        StatDialCountryQuery->Parameters->ParseSQL( SQLStr, true);
        StatDialCountryQuery->Parameters->ParamByName( "EndDate")->Value = EndDate;
        StatDialCountryQuery->Parameters->ParamByName( "BeginDate")->Value = BeginDate;
        CDSStatCountry->Open();
    }
}
//---------------------------------------------------------------------------
void __fastcall TFrmStatDialCountry::FormClose(TObject *Sender,
      TCloseAction &Action)
{
    Action = caFree;
    FrmStatDialCountry = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TFrmStatDialCountry::ExitToolButtonClick(TObject *Sender)
{
    Close();        
}
//---------------------------------------------------------------------------
void __fastcall TFrmStatDialCountry::StatDialCountryQueryCalcFields(
      TDataSet *DataSet)
{
    int second;
    String TimeStr = StatDialCountryQuery->FieldByName( "duration")->AsString;
    if( TimeStr.data() == 0) {
        return;
    }
    String str =     StatDialCountryQuery->FieldByName( "dialnumber")->AsString;
    int hIndex, mIndex;
    hIndex = TimeStr.Pos( ":");
    second = StrToInt( TimeStr.SubString( 1, hIndex - 1)) * 3600;
    TimeStr = TimeStr.SubString( hIndex + 1, TimeStr.Length());
    mIndex = TimeStr.Pos( ":");
    second += StrToInt( TimeStr.SubString( 1, mIndex - 1)) * 60;
    TimeStr = TimeStr.SubString( mIndex + 1, TimeStr.Length());
    second += StrToInt( TimeStr);

    //StatDialCountryQuery->Edit();
    StatDialCountryQuery->FieldByName( "TDuration")->AsInteger = second;

    StatDialCountryQuery->FieldByName( "SDateTime")->AsDateTime
        = StatDialCountryQuery->FieldByName( "StartDate")->AsDateTime
            + StatDialCountryQuery->FieldByName( "StartTime")->AsDateTime;
    int times = 0;
    std::map< String, float>::iterator pIter;

    for( int i = MaxLen; i > 5; --i){
        String subStr = str.SubString( 1, i);
        pIter = HKTelRateMap.find( subStr);
        if( pIter != HKTelRateMap.end()) {
            if( second % HKTelUnitMap[ subStr] != 0) {
                times = second / HKTelUnitMap[ subStr] + 1;
            }
            else {
                times = second / HKTelUnitMap[ subStr];
            }

            StatDialCountryQuery->FieldByName( "Cost")->AsString
                = FormatFloat( "##00.00", HKTelRateMap[ subStr] * times);
            TotalMoney += HKTelRateMap[ subStr] * times;
            break;
        }
    }
    //StatDialCountryQuery->Post();
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::PrintToolButtonClick(TObject *Sender)
{
    PrtStatDialCountry = new TPrtStatDialCountry( this);
    PrtStatDialCountry->Visible = false;


    if( CDSStatCountry->Aggregates->Items[0]->Value().IsNull() == false) {
        TotalSecond = CDSStatCountry->Aggregates->Items[0]->Value().operator int();
    }
    if( CDSStatCountry->Aggregates->Items[1]->Value().IsNull() == false) {
//        TotalMoney = CDSStatCountry->Aggregates->Items[0]->Value().operator int();
    }

    int hour = TotalSecond / 3600;
    int minute = (TotalSecond - hour * 3600) / 60;
    int second = TotalSecond - hour * 3600 - 60 * minute;

    String str = "";
    if( hour < 10)
        str = "0" ;
    str += IntToStr( hour) + ":";
    if( minute < 10)
        str += "0";
    str += IntToStr( minute) + ":";
    if( second < 10)
        str += "0";
    str += IntToStr( second);
    PrtStatDialCountry->QRLabel6->Caption = str;
    PrtStatDialCountry->QRLabel7->Caption = FormatFloat( "##00.00", TotalMoney);
    PrtStatDialCountry->QRLabel5->Caption = BeginDate.DateString() + "-" + EndDate.DateString();

    if( pDMTelSys->GSNameQuery->Active == false) {
        pDMTelSys->GSNameQuery->Open();
    }

    PrtStatDialCountry->ReportTitle->Caption = pDMTelSys->GSNameQuery->FieldByName( "coname")->AsString;
    PrtStatDialCountry->QuickRep1->PreviewModal();
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::FirstPageToolButtonClick(
      TObject *Sender)
{
    CDSStatCountry->First();
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::PrevPageToolButtonClick(
      TObject *Sender)
{
    CDSStatCountry->Prior();        
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::NextPageToolButtonClick(
      TObject *Sender)
{
    CDSStatCountry->Next();        
}
//---------------------------------------------------------------------------

void __fastcall TFrmStatDialCountry::LastPageToolButtonClick(
      TObject *Sender)
{
    CDSStatCountry->Last();        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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