448 lines
12 KiB
C++
448 lines
12 KiB
C++
//---------------------------------------------------------------------------
|
|
|
|
#include <vcl.h>
|
|
#include <DateUtils.hpp>
|
|
#include "BetLogFormUnit.h"
|
|
#include "GlobalUnit.h"
|
|
#include "UtilityUnit.h"
|
|
|
|
#pragma hdrstop
|
|
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma resource "*.dfm"
|
|
TBetLogForm *BetLogForm = NULL;
|
|
|
|
vector<TBetLog*> g_aBetLogs; //挂机日志
|
|
//---------------------------------------------------------------------------
|
|
__fastcall TBetLogForm::TBetLogForm(TComponent* Owner)
|
|
: TForm(Owner)
|
|
{
|
|
m_nShowRows = 0;
|
|
m_bAutoScroll = true;
|
|
m_bSearch = false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormCreate(TObject *Sender)
|
|
{
|
|
m_dg->ColWidths[0] = DPIX(120);
|
|
m_dg->ColWidths[1] = m_dg->ClientWidth - m_dg->ColWidths[0];
|
|
|
|
m_dg->Canvas->Font = m_dg->Font;
|
|
|
|
/////////////////////////////////////////////////////
|
|
// test
|
|
// int ts = DateTimeToUnix(Now(), false);
|
|
// for(int i=0; i<200; i++){
|
|
// TBetLog* pLog = new TBetLog;
|
|
// pLog->ts = ts++;
|
|
// pLog->ev = LOGEVT_START;
|
|
// g_aBetLogs.push_back(pLog);
|
|
// }
|
|
//
|
|
////////////////////////////////////////////////////
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormResize(TObject *Sender)
|
|
{
|
|
int nRows = m_dg->ClientHeight / m_dg->DefaultRowHeight;
|
|
|
|
if(nRows!=m_nShowRows){
|
|
m_nShowRows = nRows;
|
|
|
|
m_bAutoScroll = (m_dg->TopRow + m_nShowRows) >= m_dg->RowCount;
|
|
ShowLogs();
|
|
}
|
|
|
|
int nBlank = m_dg->ClientHeight % m_dg->DefaultRowHeight;
|
|
if(nBlank)
|
|
ClientHeight -= nBlank;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
|
{
|
|
ResetIdle();
|
|
|
|
if(m_sbSearch->Focused()){
|
|
if(Key=='A' && Shift.Contains( ssCtrl )){
|
|
SearchSelAll();
|
|
}
|
|
else if(Key==VK_ESCAPE){
|
|
m_dg->SetFocus();
|
|
}
|
|
}
|
|
else if(m_dg->ScrollBars==ssVertical){
|
|
if(Key==VK_UP){
|
|
m_dg->Perform(WM_VSCROLL,SB_LINEUP,0);
|
|
}
|
|
else if(Key==VK_DOWN){
|
|
m_dg->Perform(WM_VSCROLL,SB_LINEDOWN,0);
|
|
}
|
|
else if(Key==VK_HOME){
|
|
m_dg->Perform(WM_VSCROLL,SB_TOP,0);
|
|
}
|
|
else if(Key==VK_END){
|
|
m_dg->Perform(WM_VSCROLL,SB_BOTTOM,0);
|
|
}
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::ShowLogs()
|
|
{
|
|
LockWindowUpdate( m_dg->Handle );
|
|
|
|
vector<TBetLog*>& aLogs = m_bSearch ? m_aSearchLogs : g_aBetLogs;
|
|
|
|
if( aLogs.size()+1 < m_nShowRows ){
|
|
if(m_dg->RowCount!=m_nShowRows){
|
|
m_dg->RowCount = m_nShowRows;
|
|
m_dg->ScrollBars = ssNone;
|
|
|
|
m_bAutoScroll = true;
|
|
|
|
if(m_dg->TopRow>0){
|
|
m_dg->OnTopLeftChanged = NULL;
|
|
m_dg->TopRow = 0;
|
|
m_dg->OnTopLeftChanged = LogsTopChanged;
|
|
}
|
|
}
|
|
else{
|
|
m_dg->Invalidate();
|
|
}
|
|
}
|
|
else{
|
|
m_dg->RowCount = aLogs.size() + 1;
|
|
if(m_dg->ScrollBars==ssNone)
|
|
m_dg->ScrollBars = ssVertical;
|
|
|
|
if(m_bAutoScroll){
|
|
m_dg->OnTopLeftChanged = NULL;
|
|
m_dg->TopRow = m_dg->RowCount - m_nShowRows;
|
|
m_dg->OnTopLeftChanged = LogsTopChanged;
|
|
}
|
|
}
|
|
|
|
LockWindowUpdate( NULL );
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormClose(TObject *Sender, TCloseAction &Action)
|
|
{
|
|
BetLogForm->Hide();
|
|
delete BetLogForm;
|
|
BetLogForm = NULL;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
|
{
|
|
m_dg->Perform(WM_VSCROLL,SB_LINEDOWN,0);
|
|
Handled = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsMouseWheelUp(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
|
{
|
|
m_dg->Perform(WM_VSCROLL,SB_LINEUP,0);
|
|
Handled = true;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::UMLogUpdate(TMessage &msg)
|
|
{
|
|
if(m_bSearch){
|
|
String sT = m_sSearch.UpperCase();
|
|
for(int i=m_iSearchEnd; i<g_aBetLogs.size(); i++){
|
|
TBetLog* pLog = g_aBetLogs[i];
|
|
|
|
String txt = GetLogText(pLog, 0xFF);
|
|
if(txt.Pos(sT)>0)
|
|
m_aSearchLogs.push_back(pLog);
|
|
}
|
|
|
|
m_iSearchEnd = g_aBetLogs.size();
|
|
}
|
|
|
|
ShowLogs();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::ClearClick(TObject *Sender)
|
|
{
|
|
m_sbSearch->Text = "";
|
|
m_sbSearch->Modified = false;
|
|
m_aSearchLogs.clear();
|
|
m_bSearch = false;
|
|
|
|
for(int i=0; i<g_aBetLogs.size(); i++)
|
|
delete g_aBetLogs[i];
|
|
g_aBetLogs.clear();
|
|
|
|
ShowLogs();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SaveClick(TObject *Sender)
|
|
{
|
|
TSaveDialog *pDlg = new TSaveDialog(this);
|
|
pDlg->Filter = "文本文件(*.txt)|*.txt;";
|
|
|
|
if(pDlg->Execute(Application->MainFormHandle)){
|
|
try{
|
|
String name = pDlg->FileName;
|
|
if(ExtractFileExt(name)!='.txt')
|
|
name = ChangeFileExt(name, ".txt");
|
|
|
|
FILE* fp = fopen( ((AnsiString)name).c_str(), "w" );
|
|
if(fp){
|
|
vector<TBetLog*>& aLogs = m_bSearch ? m_aSearchLogs : g_aBetLogs;
|
|
for(int i=0; i<aLogs.size(); i++){
|
|
TBetLog* pLog = aLogs[i];
|
|
String txt = GetLogText(pLog, 0xFF);
|
|
fprintf(fp, "%s\n", ((AnsiString)txt).c_str());
|
|
}
|
|
|
|
fclose(fp);
|
|
}
|
|
|
|
MessageBox(Application->MainFormHandle, L"文件保存成功", L"保存",
|
|
MB_ICONINFORMATION | MB_OK);
|
|
}
|
|
catch(Exception &exception){
|
|
String str = "文件保存失败!\n"+exception.Message;
|
|
MessageBox(Application->MainFormHandle, str.c_str(), L"保存",
|
|
MB_ICONERROR | MB_OK);
|
|
}
|
|
}
|
|
|
|
delete pDlg;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
String __fastcall TBetLogForm::GetLogText(TBetLog* pLog, int iCol)
|
|
{
|
|
String txt;
|
|
if(pLog){
|
|
if(iCol==0 || iCol==0xFF){
|
|
TDateTime dt = UnixToDateTime(pLog->ts,false);
|
|
txt = dt.FormatString("mm-dd hh:nn:ss ");
|
|
}
|
|
|
|
if(iCol==1 || iCol==0xFF){
|
|
txt += pLog->tno;
|
|
|
|
if(pLog->ev==LOGEVT_START){
|
|
txt += "开始挂机 ";
|
|
txt += g_bSimulate ? "模拟" : "实打";
|
|
|
|
if(g_settings.bWaitNew)
|
|
txt += " 新局";
|
|
if(g_settings.bInitBetChipByStart)
|
|
txt += " 重置";
|
|
if(g_settings.iFloatMode>0)
|
|
txt += " 游台";
|
|
}
|
|
else if(pLog->ev==LOGEVT_END){
|
|
if(pLog->op==1)
|
|
txt += "总体止赢 ";
|
|
else if(pLog->op==2)
|
|
txt += "总体止损 ";
|
|
else if(pLog->op==3)
|
|
txt += "本金不足 ";
|
|
else if(pLog->op==4)
|
|
txt += "游台爆缆 ";
|
|
else if(pLog->op==5)
|
|
txt += "账户止赢 ";
|
|
else if(pLog->op==6)
|
|
txt += "账户止损 ";
|
|
else if(pLog->op==7)
|
|
txt += "动态止损 ";
|
|
else if(pLog->op==8)
|
|
txt += "总体阶梯爆缆 ";
|
|
|
|
if(pLog->op==4 || pLog->op==8)
|
|
txt += "台桌停止";
|
|
else
|
|
txt += "停止挂机";
|
|
}
|
|
else if(pLog->ev==LOGEVT_RESET){
|
|
if(pLog->op==-1){
|
|
txt += "恢复";
|
|
}
|
|
else if(pLog->op==0){
|
|
txt += "重置当期赢利";
|
|
}
|
|
else{
|
|
if(pLog->op==1)
|
|
txt += "总体止赢 ";
|
|
else if(pLog->op==2)
|
|
txt += "总体止损 ";
|
|
else if(pLog->op==7)
|
|
txt += "动态止损 ";
|
|
|
|
if(pLog->num)
|
|
txt += "新局重启";
|
|
else{
|
|
int nPause = pLog->op==7 ? g_settings.nU2DPause
|
|
: pLog->op==1 ? g_settings.nTotalWinPause
|
|
: g_settings.nTotalLosPause;
|
|
txt += "暂停" + IntToStr(nPause) + "分钟";
|
|
}
|
|
}
|
|
}
|
|
else if(pLog->ev==LOGEVT_ROUND){
|
|
txt += " 新局 ";
|
|
}
|
|
else if(pLog->ev==LOGEVT_BET){
|
|
if(pLog->op==0)
|
|
txt += " 本手不下";
|
|
else if(pLog->op==4)
|
|
txt += " 本局停止";
|
|
else{
|
|
txt += " 下注 ";
|
|
txt += pLog->op==1 ? "庄 " : pLog->op==2 ? "闲 " : "和 ";
|
|
txt += IntToStr(pLog->num);
|
|
}
|
|
}
|
|
else if(pLog->ev==LOGEVT_RES){
|
|
txt += " 结算 ";
|
|
txt += pLog->op==1 ? "赢 " : pLog->op==2 ? "输 " : "和 ";
|
|
txt += IntToStr(pLog->num);
|
|
}
|
|
else if(pLog->ev==LOGEVT_DEAD || pLog->ev==LOGEVT_STOPWIN || pLog->ev==LOGEVT_STOPLOS){
|
|
if(pLog->ev==LOGEVT_DEAD)
|
|
txt += " 爆缆 ";
|
|
else if(pLog->ev==LOGEVT_STOPWIN)
|
|
txt += " 止赢 ";
|
|
else
|
|
txt += " 止损 ";
|
|
|
|
if(pLog->op==2){
|
|
if(pLog->num)
|
|
txt += "暂停" + IntToStr(pLog->num) + "分钟";
|
|
else
|
|
txt += "立即重启";
|
|
}
|
|
else if(pLog->op==1)
|
|
txt += "新局重启";
|
|
else
|
|
txt += "本桌停止";
|
|
}
|
|
else if(pLog->ev==LOGEVT_SWITCH){
|
|
if(pLog->op)
|
|
txt += "实打转模拟";
|
|
else
|
|
txt += "模拟转实打";
|
|
}
|
|
else if(pLog->ev==LOGEVT_QUASH){
|
|
txt += " 注单撤销";
|
|
}
|
|
}
|
|
}
|
|
return txt;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsDrawCell(TObject *Sender, System::LongInt ACol, System::LongInt ARow, TRect &Rect, TGridDrawState State)
|
|
{
|
|
m_dg->Canvas->Brush-> Color = Graphics::clNone;
|
|
m_dg->Canvas->FillRect(Rect);
|
|
|
|
vector<TBetLog*>& aLogs = m_bSearch ? m_aSearchLogs : g_aBetLogs;
|
|
|
|
if(ARow<aLogs.size()){
|
|
TBetLog* pLog = aLogs[ARow];
|
|
|
|
TColor clr = pLog->ev==LOGEVT_ROUND ? clLime
|
|
: pLog->ev==LOGEVT_BET ? clAqua
|
|
: (pLog->ev==LOGEVT_RES || pLog->ev==LOGEVT_QUASH) ? clWebPink
|
|
: pLog->ev==LOGEVT_DEAD || pLog->ev==LOGEVT_STOPWIN || pLog->ev==LOGEVT_STOPLOS ? clRed
|
|
: clYellow;
|
|
m_dg->Canvas->Font->Color = clr;
|
|
|
|
String txt = GetLogText(pLog, ACol);
|
|
TSize szTxt = m_dg->Canvas->TextExtent(txt);
|
|
|
|
int x = Rect.left + 2,
|
|
y = Rect.top;
|
|
y += (Rect.Height() - szTxt.cy) / 2;// -- 垂直居中
|
|
m_dg->Canvas->TextOut(x,y,txt);
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsTopChanged(TObject *Sender)
|
|
{
|
|
m_bAutoScroll = (m_dg->TopRow + m_nShowRows) >= m_dg->RowCount;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsSelectCell(TObject *Sender, System::LongInt ACol, System::LongInt ARow, bool &CanSelect)
|
|
{
|
|
CanSelect = false;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SearchInvokeSearch(TObject *Sender)
|
|
{
|
|
if(m_sbSearch->Modified){
|
|
m_sbSearch->Modified = false;
|
|
m_aSearchLogs.clear();
|
|
|
|
m_sSearch = m_sbSearch->Text;
|
|
if(m_sSearch.Length()){
|
|
String sT = m_sSearch.UpperCase();
|
|
for(int i=0; i<g_aBetLogs.size(); i++){
|
|
TBetLog* pLog = g_aBetLogs[i];
|
|
|
|
String txt = GetLogText(pLog, 0xFF);
|
|
if(txt.Pos(sT)>0)
|
|
m_aSearchLogs.push_back(pLog);
|
|
}
|
|
|
|
m_iSearchEnd = g_aBetLogs.size();
|
|
m_bSearch = true;
|
|
m_bAutoScroll = false;
|
|
m_dg->TopRow = 0;
|
|
}
|
|
else{
|
|
m_bSearch = false;
|
|
m_bAutoScroll = true;
|
|
m_dg->SetFocus();
|
|
}
|
|
|
|
ShowLogs();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SearchExit(TObject *Sender)
|
|
{
|
|
m_sbSearch->Text = m_sSearch;
|
|
m_sbSearch->Color = clWhite;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SearchEnter(TObject *Sender)
|
|
{
|
|
m_sbSearch->Color = clWebCornSilk;
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SearchDblClick(TObject *Sender)
|
|
{
|
|
SearchSelAll();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::SearchSelAll()
|
|
{
|
|
if(m_sbSearch->Text.Length()){
|
|
m_sbSearch->SelStart = 0;
|
|
m_sbSearch->SelLength = m_sbSearch->Text.Length();
|
|
}
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormDeactivate(TObject *Sender)
|
|
{
|
|
if(Showing && m_sbSearch->Color!=clWhite)
|
|
SearchExit(NULL);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::FormActivate(TObject *Sender)
|
|
{
|
|
m_dg->SetFocus();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
void __fastcall TBetLogForm::LogsMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
|
|
{
|
|
ResetIdle();
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|