//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "uMainForm.h"
#include <stdio.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm_Main *Form_Main;
//---------------------------------------------------------------------------
__fastcall TForm_Main::TForm_Main(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm_Main::FormCreate(TObject *Sender)
{
FLogonTimeList = new TList();
FBlockTimeList = new TList();
FStatDate = new TStringList();
FAgentInfos = new TList();
FAgentList = new TList();
FCCList = new TList();
m_uDBConfig = new TForm_DBConfig(this);
m_uDBConfig->BitBtn1->OnClick = BitBtnOKClick;
FStatDate->LoadFromFile(ChangeFileExt(Application->ExeName,".cfg"));
if (m_uDBConfig->ShowModal() != mrOk)
{
Application->Terminate();
return;
}
ADOQuery_stat->ConnectionString = WideString(
"Provider=" + FProvider +
";Password=" + FPassword +
";User ID=" + FUserName +
";Data Source=" + FDataSource +
";Persist Security Info=True");
}
//---------------------------------------------------------------------------
void __fastcall TForm_Main::BitBtnOKClick(TObject *Sender)
{
TModalResult Result;
Result = mrOk;
if (m_uDBConfig->ComboBox1->ItemIndex < 0)
Result = mrCancel;
else if (m_uDBConfig->Edit1->Text == "")
Result = mrCancel;
else if (m_uDBConfig->Edit2->Text == "")
Result = mrCancel;
else if (m_uDBConfig->Edit3->Text == "")
Result = mrCancel;
if (Result != mrOk)
m_uDBConfig->ModalResult = mrNone;
else
{
FProvider = gsProvider[m_uDBConfig->ComboBox1->ItemIndex];
FDataSource = m_uDBConfig->Edit1->Text;
FUserName = m_uDBConfig->Edit2->Text;
FPassword = m_uDBConfig->Edit3->Text;
m_uDBConfig->ModalResult = mrOk;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm_Main::ToolButton_RefreshClick(TObject *Sender)
{
ToolButton_Save->Enabled = false;
if (!GetEmployers())
{
ShowMessage("读取座席信息失败!");
return;
}
if (!GetAgentStatInfo())
{
ShowMessage("读取座席统计信息失败!");
return;
}
if (!GetCCStatInfo())
{
ShowMessage("读取话务统计信息失败!");
return;
}
ToolButton_Save->Enabled = true;
}
//---------------------------------------------------------------------------
bool TForm_Main::GetEmployers()
{
//TODO: Add your source code here
ADOQuery_stat->Close();
ADOQuery_stat->SQL->Clear();
ADOQuery_stat->SQL->Add("select EMP_CODE,EMP_NAME from call.dbo.EMP_INFO");
try
{
ADOQuery_stat->Open();
FEmployer.clear();
}
catch(...)
{
return false;
}
while (!ADOQuery_stat->Eof)
{
FEmployer.insert(std::pair<int,AnsiString>(
ADOQuery_stat->FieldByName("EMP_CODE")->AsInteger,
ADOQuery_stat->FieldByName("EMP_NAME")->AsString));
ADOQuery_stat->Next();
}
return true;
}
//---------------------------------------------------------------------------
bool TForm_Main::GetAgentStatInfo()
{
int iCode, iIndex;
AnsiString asDate, asISODate, asSQL;
int iData;
AnsiString asData;
float fData;
for (int i=0;i<FStatDate->Count;i++)
{
asISODate = FStatDate->Strings[i];
asDate.sprintf("%s-%s-%s",
asISODate.SubString(1,4).c_str(),
asISODate.SubString(5,2).c_str(),
asISODate.SubString(7,2).c_str());
//1: 读取话务总数
asSQL = "select telephonistid as EMP_CODE, count(talktime) as DISTRIBUTED_CALL ";
asSQL += "from ivsp.dbo.ccs_call ";
asSQL += "where substring(callcreatetime,1,10) = '";
asSQL += asDate;
asSQL += "' ";
asSQL += "group by telephonistid";
if (!QueryDB(asSQL, "DISTRIBUTED_CALL", dtInteger, aiDistributed))
return false;
//2: 读取呼入受理总数
asSQL = "select telephonistid as EMP_CODE, count(talktime) as CALLIN_SUCC "
"from ivsp.dbo.ccs_call "
"where substring(callcreatetime,1,10)='" + asDate + "' "
"and createcause in (0,1,15) and clearcause in(0,1) and talktime > 0 "
"group by telephonistid";
if (!QueryDB(asSQL, "CALLIN_SUCC", dtInteger, aiCallIn_Succ))
return false;
//3: 读取呼出总数
asSQL = "select telephonistid as EMP_CODE, count(talktime) as CALLOUT "
"from ivsp.dbo.ccs_call "
"where substring(callcreatetime,1,10)='" + asDate + "' " +
"and createcause = 2"
"group by telephonistid";
if (!QueryDB(asSQL, "CALLOUT", dtInteger, aiOutCall))
return false;
//4: 读取受理总数
asSQL = "select telephonistid as EMP_CODE, count(talktime) as ACCEPTED "
"from ivsp.dbo.ccs_call "
"where substring(callcreatetime,1,10)='" + asDate + "' " +
"and clearcause in(0,1) and talktime > 0"
"group by telephonistid";
if (!QueryDB(asSQL, "ACCEPTED", dtInteger, aiAccepted))
return false;
//5: 读取服务时长
asSQL = "select telephonistid as EMP_CODE, "
"right('0'+convert(varchar(2),sum(isnull(talktime,0))/3600),2)+':'+"
"right('0'+convert(varchar(2),(sum(isnull(talktime,0)) % 3600) / 60),2)+':'+"
"right('0'+convert(varchar(2),sum(isnull(talktime,0)) % 60),2)"
" as SERVETIME "
"from ivsp.dbo.ccs_call "
"where substring(callcreatetime,1,10)='" + asDate + "' " +
"and clearcause in(0,1) and talktime > 0"
"group by telephonistid";
if (!QueryDB(asSQL, "SERVETIME", dtString, aiServeTime))
return false;
//6: 读取登录时长
if (!QueryOprTime(oprLogon, asDate, FLogonTimeList))
return false;
for (int iAgent=0;iAgent<FLogonTimeList->Count;iAgent++)
{
TStringList *sList = NULL;
sList = ((TStringList*)(FLogonTimeList->Items[iAgent]));
if (NULL == sList)
return false;
UpdateAgentInfo(aiServeTime, StrToInt(sList->Strings[0]), &(sList->Strings[1]));
}
//7: 读取闭塞时长
if (!QueryOprTime(oprBlock, asDate, FBlockTimeList))
return false;
for (int iAgent=0;iAgent<FBlockTimeList->Count;iAgent++)
{
TStringList *sList = NULL;
sList = ((TStringList*)(FBlockTimeList->Items[iAgent]));
if (NULL == sList)
return false;
UpdateAgentInfo(aiBlockTime, StrToInt(sList->Strings[0]), &(sList->Strings[1]));
}
//8: 读取振铃时长
asSQL = "select telephonistid as EMP_CODE, sum(isnull(waitanswertime,0)) as ALERTINGTIME from ivsp.dbo.ccs_call"
" where substring(callcreatetime,1,10)='" + asDate +
"' and createcause in (0,1,15)"
" group by telephonistid";
if (!QueryDB(asSQL, "ALERTINGTIME", dtFloat, aiAlertingTime))
return false;
//9: 显示数据
TAgentStatInfo *pInfo = NULL;
AnsiString asTemp;
for (int j=0;j<FAgentInfos->Count;j++)
{
pInfo = (TAgentStatInfo*)(FAgentInfos->Items[j]);
TStringList *sList = new TStringList();
sList->Add(FStatDate->Strings[i]);
s