1512 lines
43 KiB
C++
1512 lines
43 KiB
C++
//---------------------------------------------------------------------------
|
||
|
||
#include <vcl.h>
|
||
#pragma hdrstop
|
||
|
||
#include "PolicyEditFormUnit.h"
|
||
#include "PolicySave.h"
|
||
#include "GlobalUnit.h"
|
||
#include "GameUnit.h"
|
||
#include "UtilityUnit.h"
|
||
#include "Chip02FrameUnit.h"
|
||
#include "Bet02FrameUnit.h"
|
||
#include "Bet03FrameUnit.h"
|
||
//---------------------------------------------------------------------------
|
||
#pragma package(smart_init)
|
||
#pragma resource "*.dfm"
|
||
|
||
#define COLOR_OVEN TColor(0x00FFFCF2)
|
||
#define C_OD 0 //序号
|
||
#define C_CP 1 //切入点/注码
|
||
#define C_PD 2 //下注/赢走向
|
||
//#define C_ND 3 //输走向
|
||
//---------------------------------------------------------------------------
|
||
__fastcall TPolicyEditForm::TPolicyEditForm(TComponent* Owner, int iType)
|
||
: TForm(Owner)
|
||
{
|
||
m_iType = iType;
|
||
m_editPolicy = NULL;
|
||
m_colEdit = m_rowEdit = -1;
|
||
m_nRows = m_nNewNum = 0;
|
||
m_bRowChanged = m_bColChanged = m_bRoadChanged = false;
|
||
|
||
m_aDeadRB[0] = m_rbDead0;
|
||
m_aDeadRB[1] = m_rbDead1;
|
||
m_aDeadRB[2] = m_rbDead2;
|
||
|
||
m_frmSP = NULL;
|
||
|
||
m_cbLevelInstant->Hint = "若勾选,则达到条件即刻升降层级(未结算数据计入下一层级)\n否则,将等待已下注台桌全部结算完后再决定升降";
|
||
m_cbLevelIndie->Hint = "若勾选,则升降层级时赢输次差清零\n否则,仅在重置或爆缆重启时才清零";
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::FormCreate(TObject *Sender)
|
||
{
|
||
m_pEditor->Height = m_sg->DefaultRowHeight;
|
||
m_pEditor->Parent = m_sg;
|
||
m_pCombo->Height = m_sg->DefaultRowHeight;
|
||
m_pCombo->Parent = m_sg;
|
||
m_sg->Canvas->Font = m_sg->Font;
|
||
|
||
m_tsTop->TabIndex = m_iType;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::FormClose(TObject *Sender, TCloseAction &Action)
|
||
{
|
||
ClearSPFrame();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::FormMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
|
||
{
|
||
ResetIdle();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::TopMeasureTab(TObject *Sender, int Index, int &TabWidth)
|
||
{
|
||
TabWidth = (m_tsTop->Width - DPIX(40)) / 2;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::TopDrawTab(TObject *Sender, TCanvas *TabCanvas, TRect &R, int Index, bool Selected)
|
||
{
|
||
TTabSet* pTS = (TTabSet*)Sender;
|
||
|
||
int w = TabCanvas->TextWidth((*pTS->Tabs)[Index]),
|
||
l = ( R.Width() - w ) / 2,
|
||
h = TabCanvas->TextHeight((*pTS->Tabs)[Index]),
|
||
t = ( R.Height() - h ) /2;
|
||
|
||
TabCanvas->TextOut(R.Left + l, R.Top + t, (*pTS->Tabs)[Index]);
|
||
|
||
TabCanvas->Font->Color = clBlack;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::TopChange(TObject *Sender, int NewTab, bool &AllowChange)
|
||
{
|
||
SetView(NewTab);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SetView(int type)
|
||
{
|
||
m_iType = type;
|
||
m_sType = type==TYPE_P_BET ? "打法" : "注码";
|
||
|
||
m_lblPolicy->Caption = "编辑" + m_sType + ":";
|
||
m_cbPolicy->Text = "请选择" + m_sType;
|
||
m_btnSave->Caption = "保存" + m_sType;
|
||
m_btnSelect->Caption = "选择该" + m_sType;
|
||
m_panChip->Visible = type==TYPE_P_CHIP;
|
||
m_rgRoad->Visible = type==TYPE_P_BET;
|
||
|
||
m_cbPolicy->Clear();
|
||
Clear();
|
||
|
||
vector<TBasePolicy*>& aPolicies = type==TYPE_P_BET ? g_aBetPolicies : g_aChipPolicies;
|
||
m_iSelPolicy = type==TYPE_P_BET ? g_iBetPolicy : g_iChipPolicy;
|
||
if(type==TYPE_P_BET){
|
||
m_sg->ColCount = 3;
|
||
m_sg->Cells[0][0] = "序号";
|
||
m_sg->Cells[1][0] = "切入点";
|
||
m_sg->Cells[2][0] = "下注";
|
||
m_sg->ColWidths[0] = DPIX(97);
|
||
m_sg->ColWidths[1] = DPIX(150);
|
||
m_sg->ColWidths[2] = DPIX(150);
|
||
}
|
||
|
||
for(int i=0; i<aPolicies.size(); i++){
|
||
TBasePolicy* pPolicy = aPolicies[i];
|
||
|
||
m_cbPolicy->AddItem(pPolicy->name, NULL);
|
||
if(m_iSelPolicy==i){
|
||
m_cbPolicy->ItemIndex = m_iSelPolicy;
|
||
m_editPolicy = pPolicy;
|
||
|
||
m_btnDel->Enabled = pPolicy->type>1;
|
||
if(m_iType==TYPE_P_BET)
|
||
m_rgRoad->ItemIndex = ((TBetPolicy*)pPolicy)->road;
|
||
else{
|
||
m_aDeadRB[((TChipPolicy*)pPolicy)->dead]->Checked = true;
|
||
m_edDeadPause->Text = ((TChipPolicy*)pPolicy)->deadPause;
|
||
}
|
||
}
|
||
|
||
if(m_iType==TYPE_P_CHIP && (pPolicy->kind==KIND_CHIP_NOR || pPolicy->kind==KIND_CHIP_RAN)){
|
||
m_pCombo->AddItem(pPolicy->name, (TObject*)pPolicy->id);
|
||
m_aCPMap.push_back(i);
|
||
}
|
||
}
|
||
|
||
CalcNewName();
|
||
if(m_iSelPolicy<0)
|
||
m_cbPolicy->Text = AutoNewName();
|
||
|
||
UpdateGrid();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::ClearSPFrame()
|
||
{
|
||
if(m_frmSP){
|
||
delete m_frmSP;
|
||
m_frmSP = NULL;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::CalcNewName()
|
||
{
|
||
m_nNewNum = 0;
|
||
|
||
String sPreNew = "新建" + m_sType;
|
||
int lPre = sPreNew.Length();
|
||
for(int i=0; i<m_cbPolicy->Items->Count; i++){
|
||
String name = m_cbPolicy->Items->Strings[i];
|
||
if(name.Pos(sPreNew)==1){
|
||
int len = name.Length();
|
||
String suf = name.SubString(lPre+1, len-lPre);
|
||
int num = 0;
|
||
if(TryStrToInt(suf, num) && num>m_nNewNum)
|
||
m_nNewNum = num;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
String __fastcall TPolicyEditForm::AutoNewName()
|
||
{
|
||
return "新建" + m_sType + IntToStr(m_nNewNum+1);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::UpdateGrid()
|
||
{
|
||
m_btnSave->Enabled = m_bRowChanged = m_bColChanged = !m_editPolicy;
|
||
m_bRoadChanged = false;
|
||
m_btnSelect->Enabled = m_editPolicy;
|
||
m_btnDel->Enabled = m_editPolicy && m_editPolicy->type>1;
|
||
|
||
ClearSPFrame();
|
||
|
||
if(m_iType==TYPE_P_BET){
|
||
TBetPolicy* pBP = m_editPolicy ? (TBetPolicy*)m_editPolicy : NULL;
|
||
if(pBP && pBP->kind>=KIND_BET_ASK){ //特殊打法
|
||
if(pBP->kind==KIND_BET_ASK){ //庄闲问路
|
||
TBet02Frame* frmSP = new TBet02Frame(NULL);
|
||
m_frmSP = frmSP;
|
||
|
||
for(int i=0; i<2; i++)
|
||
frmSP->m_rgs[i]->OnClick = OnAskRoadClick;
|
||
}
|
||
else if(pBP->kind==KIND_BET_DIF){
|
||
TBet03Frame* frmSP = new TBet03Frame(NULL);
|
||
m_frmSP = frmSP;
|
||
|
||
frmSP->m_leBlP->OnChange = OnSPEditChange;
|
||
frmSP->m_lePlB->OnChange = OnSPEditChange;
|
||
frmSP->m_edBlP->OnChange = OnSPEditChange;
|
||
frmSP->m_edPlB->OnChange = OnSPEditChange;
|
||
}
|
||
|
||
m_frmSP->Parent = m_panEdit;
|
||
m_frmSP->Width = m_panEdit->Width;
|
||
m_frmSP->Show();
|
||
|
||
return;
|
||
}
|
||
|
||
m_rgRoad->ItemIndex = pBP ? pBP->road : 0;
|
||
}
|
||
else{
|
||
TChipPolicy* pCP = m_editPolicy ? (TChipPolicy*)m_editPolicy : NULL;
|
||
if(pCP && pCP->kind==KIND_CHIP_RAN){ //随机注码
|
||
TChip02Frame* frmSP = new TChip02Frame(NULL);
|
||
m_frmSP = frmSP;
|
||
|
||
frmSP->m_leMinChip->OnChange = OnSPEditChange;
|
||
frmSP->m_leMaxChip->OnChange = OnSPEditChange;
|
||
frmSP->Parent = m_panEdit;
|
||
frmSP->Show();
|
||
|
||
return;
|
||
}
|
||
|
||
int iDead = pCP ? pCP->dead : 0;
|
||
m_aDeadRB[iDead]->Checked = true;
|
||
m_edDeadPause->Text = pCP ? pCP->deadPause : 0;
|
||
|
||
int kind = pCP ? pCP->kind : 0;
|
||
m_cbKind->OnChange = NULL;
|
||
m_cbKind->ItemIndex = kind;
|
||
m_cbKind->OnChange = OnKindChange;
|
||
m_cbKind->Enabled = pCP ? false : true;
|
||
|
||
if(kind==KIND_CHIP_HAN){ //层级注码
|
||
m_cbTierWinRet->OnClick = NULL;
|
||
m_cbTierWinRet->Checked = pCP ? ((TTierPolicy*)pCP)->bTierWinRet : true;
|
||
m_cbTierWinRet->OnClick = OnChipOptionClick;
|
||
|
||
m_cbTierAccChip->OnClick = NULL;
|
||
m_cbTierAccChip->Checked = pCP ? ((TTierPolicy*)pCP)->bTierAccChip : true;
|
||
m_cbTierAccChip->OnClick = OnChipOptionClick;
|
||
|
||
m_cbTierLos0->OnClick = NULL;
|
||
m_cbTierLos0->Checked = pCP ? ((TTierPolicy*)pCP)->bTierLos0 : false;
|
||
m_cbTierLos0->OnClick = OnChipOptionClick;
|
||
}
|
||
else if(kind>=KIND_CHIP_LEV && kind<=KIND_CHIP_WLD){ //阶梯注码
|
||
m_cbLevelTotalDiff->OnClick = NULL;
|
||
m_cbLevelTotalDiff->Checked = pCP ? ((TLevelPolicy*)pCP)->bTotalDiff : false;
|
||
m_cbLevelTotalDiff->OnClick = OnChipOptionClick;
|
||
|
||
m_cbLevelInstant->OnClick = NULL;
|
||
m_cbLevelInstant->Checked = pCP ? ((TLevelPolicy*)pCP)->bInstant : false;
|
||
m_cbLevelInstant->OnClick = OnChipOptionClick;
|
||
|
||
if(kind==KIND_CHIP_WLD){
|
||
m_cbLevelIndie->OnClick = NULL;
|
||
m_cbLevelIndie->Checked = pCP ? ((TWLDiffPolicy*)pCP)->bIndie : false;
|
||
m_cbLevelIndie->OnClick = OnChipOptionClick;
|
||
}
|
||
}
|
||
|
||
InitChipGrid(kind);
|
||
}
|
||
|
||
int size = m_nRows = m_editPolicy ? m_editPolicy->aRows.size() : 0;
|
||
if(!size) m_nRows = 1;
|
||
|
||
LockWindowUpdate( m_sg->Handle );
|
||
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount = m_nRows+2;
|
||
else
|
||
m_sg->RowCount = m_sg->VisibleRowCount+1;
|
||
|
||
if(size){
|
||
vector<TBaseRow*>& rows = m_editPolicy->aRows;
|
||
|
||
int ind = 1;
|
||
if(m_iType==TYPE_P_CHIP){
|
||
TChipPolicy* pCP = (TChipPolicy*)m_editPolicy;
|
||
for(int i=0; i<size; i++){
|
||
TChipRow* row = (TChipRow*)rows[i];
|
||
|
||
m_sg->Cells[0][ind] = row->iSeq;
|
||
|
||
if(pCP->kind==KIND_CHIP_HAN){
|
||
m_sg->Cells[1][ind] = row->chip;
|
||
m_sg->Cells[2][ind] = ((TTierRow*)row)->hands;
|
||
m_sg->Cells[3][ind] = row->iWin;
|
||
m_sg->Cells[4][ind] = row->iLos;
|
||
}
|
||
else if(pCP->kind==KIND_CHIP_LEV || pCP->kind==KIND_CHIP_WLD){
|
||
m_sg->Cells[1][ind] = row->chip;
|
||
m_sg->Cells[2][ind] = ((TLevelRow*)row)->nCondWin;
|
||
m_sg->Cells[3][ind] = row->iWin;
|
||
m_sg->Cells[4][ind] = ((TLevelRow*)row)->nCondLos;
|
||
m_sg->Cells[5][ind] = row->iLos;
|
||
}
|
||
else if(pCP->kind==KIND_CHIP_COM){
|
||
TComboRow* cr = (TComboRow*)row;
|
||
CheckComboRow(cr);
|
||
|
||
int iCombo = m_pCombo->Items->IndexOfObject((TObject*)cr->id);
|
||
m_sg->Cells[1][ind] = m_pCombo->Items->Strings[iCombo];// .GetText();
|
||
m_sg->Objects[1][ind] = (TObject*)iCombo;
|
||
m_sg->Cells[2][ind] = cr->chip;
|
||
m_sg->Cells[3][ind] = cr->nCondWin;
|
||
m_sg->Cells[4][ind] = cr->iWin;
|
||
m_sg->Cells[5][ind] = cr->nCondLos;
|
||
m_sg->Cells[6][ind] = cr->iLos;
|
||
}
|
||
else{
|
||
m_sg->Cells[1][ind] = row->chip;
|
||
m_sg->Cells[2][ind] = row->iWin;
|
||
m_sg->Cells[3][ind] = row->iLos;
|
||
}
|
||
|
||
ind++;
|
||
}
|
||
}
|
||
else{
|
||
for(int i=0; i<size; i++){
|
||
TBetRow* row = (TBetRow*)rows[i];
|
||
|
||
m_sg->Cells[0][ind] = ind;
|
||
|
||
//转换condition
|
||
String cond;
|
||
for(int j=0; j<row->cond.size(); j++){
|
||
//item&0x3=颜色 (item&7C)>>2=个数 item&0x80=是否定长
|
||
int item = row->cond[j];
|
||
bool up = item & 0x80;
|
||
char ch = item & 0x3;
|
||
int num = (item & 0x7C) >> 2;
|
||
|
||
if(ch==1) cond += up ? "A" : "a";
|
||
else if(ch==2) cond += up ? "S" : "s";
|
||
else if(ch==3) cond += up ? "D" : "d";
|
||
if(num>1) cond += IntToStr(num);
|
||
}
|
||
m_sg->Cells[1][ind] = cond;
|
||
|
||
//转换bet
|
||
String bets;
|
||
for(int j=0; j<row->bets.size(); j++){
|
||
char bet = row->bets[j];
|
||
if(bet==1) bets += "a"; //庄/红
|
||
else if(bet==2) bets += "s"; //闲/蓝
|
||
else if(bet==3) bets += "d"; //和
|
||
else if(bet==0) bets += "x"; //不下注
|
||
else if(bet==4) bets += "z"; //本局停
|
||
}
|
||
m_sg->Cells[2][ind] = bets;
|
||
|
||
ind++;
|
||
}
|
||
}
|
||
}
|
||
else{
|
||
m_sg->Cells[0][1] = 1;
|
||
}
|
||
|
||
SetSelection(1);
|
||
|
||
LockWindowUpdate(NULL);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::Clear()
|
||
{
|
||
TStringGrid* pSG = m_sg;
|
||
|
||
for(int i=1; i<pSG->RowCount; i++){
|
||
for( int j=0; j<pSG->ColCount; j++){
|
||
pSG->Cells[j][i] = "";
|
||
}
|
||
pSG->Objects[1][i] = NULL;
|
||
}
|
||
|
||
m_colEdit = m_rowEdit = -1;
|
||
m_pEditor->Visible = false;
|
||
m_pCombo->Visible = false;
|
||
pSG->TopRow = 1;
|
||
|
||
TGridRect rtSel = {0,0,0,0};
|
||
pSG->Selection = rtSel;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::GridEndEdit()
|
||
{
|
||
if(!m_pEditor->Visible && !m_pCombo->Visible)
|
||
return;
|
||
|
||
if(m_pEditor->Visible){
|
||
m_sg->Cells[m_colEdit][m_rowEdit] = m_pEditor->Text;
|
||
m_pEditor->Visible = false;
|
||
m_sg->SetFocus();
|
||
}
|
||
else if(m_pCombo->Visible){
|
||
if(!m_sg->Cells[m_colEdit][m_rowEdit].Length()
|
||
|| (int)m_sg->Objects[m_colEdit][m_rowEdit] != m_pCombo->ItemIndex){
|
||
m_sg->Cells[m_colEdit][m_rowEdit] = m_pCombo->Text;
|
||
m_sg->Objects[m_colEdit][m_rowEdit] = (TObject*)m_pCombo->ItemIndex;
|
||
|
||
int ind = FindPolicy(TYPE_P_CHIP, (int)m_pCombo->Items->Objects[m_pCombo->ItemIndex]);
|
||
int minChip = MinChipOfPolicy(ind);
|
||
int multi = g_MinOnBet / minChip;
|
||
if(g_MinOnBet % minChip) multi++;
|
||
m_sg->Cells[2][m_rowEdit] = multi;
|
||
}
|
||
m_pCombo->Visible = false;
|
||
m_sg->SetFocus();
|
||
}
|
||
|
||
if(!m_bColChanged && m_sg->Cells[m_colEdit][m_rowEdit]!=m_sOrig){
|
||
m_btnSave->Enabled = m_bColChanged = true;
|
||
m_btnSelect->Enabled = false;
|
||
}
|
||
|
||
m_colEdit = m_rowEdit = -1;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SetSelection(int selRow)
|
||
{
|
||
TGridRect rtSel = m_sg->Selection;
|
||
if(selRow!=rtSel.Top || rtSel.Right<m_sg->ColCount-1){
|
||
rtSel.Left = 0;
|
||
rtSel.Right = m_sg->ColCount-1;
|
||
rtSel.Top = rtSel.Bottom = selRow;
|
||
m_sg->Selection = rtSel;
|
||
}
|
||
|
||
m_btnDelRow->Enabled = selRow>0;
|
||
m_btnInsRow->Enabled = selRow>0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGDrawCell(TObject *Sender, System::LongInt ACol, System::LongInt ARow, TRect &Rect, TGridDrawState State)
|
||
{
|
||
TStringGrid* pSG = (TStringGrid*)Sender;
|
||
String strText = pSG->Cells[ACol][ARow];
|
||
int x=Rect.left,y=Rect.top;
|
||
TSize szTxt = pSG->Canvas->TextExtent(strText);
|
||
|
||
int dpi5 = DPIX(5);
|
||
if( ARow==0 ){ //画下框线
|
||
x += (Rect.Width() - szTxt.cx) / 2; // -- 水平居中
|
||
y += (Rect.Height() - szTxt.cy) / 2 + 1;// -- 垂直居中
|
||
|
||
TBrushStyle rBS = pSG->Canvas->Brush->Style;
|
||
TColor rCl = pSG->Canvas->Brush->Color;
|
||
pSG->Canvas->Brush->Style = bsSolid;
|
||
pSG->Canvas->Brush->Color = clBtnFace;
|
||
pSG->Canvas->FillRect(Rect);
|
||
pSG->Canvas->TextOut(x,y,strText);
|
||
pSG->Canvas->Brush->Style = rBS;
|
||
pSG->Canvas->Brush->Color = rCl;
|
||
|
||
TPenStyle rPS = pSG->Canvas->Pen->Style;
|
||
pSG->Canvas->Pen->Style = psSolid;
|
||
rCl = pSG->Canvas->Pen->Color;
|
||
pSG->Canvas->Pen->Color = clGray;
|
||
|
||
pSG->Canvas->MoveTo( Rect.left-dpi5, Rect.bottom );
|
||
pSG->Canvas->LineTo( Rect.right, Rect.bottom );
|
||
|
||
pSG->Canvas->Pen->Color = clBtnFace;
|
||
pSG->Canvas->MoveTo( Rect.left-dpi5, Rect.top );
|
||
pSG->Canvas->LineTo( Rect.right, Rect.top );
|
||
|
||
pSG->Canvas->Pen->Color = rCl;
|
||
pSG->Canvas->Pen->Style = rPS;
|
||
}
|
||
else{
|
||
x += DPIX(4);
|
||
y += (Rect.Height() - szTxt.cy) / 2 + 1;// -- 垂直居中
|
||
|
||
bool bEven = ARow % 2;
|
||
|
||
TBrushStyle rBS = pSG->Canvas->Brush->Style;
|
||
TColor rBC = pSG->Canvas->Brush->Color;
|
||
TColor rFC = pSG->Canvas->Font->Color;
|
||
|
||
pSG->Canvas->Brush->Style = bsSolid;
|
||
|
||
if(State.Contains(gdSelected) || m_rowEdit==ARow){
|
||
pSG->Canvas->Brush->Color = clHotLight;
|
||
pSG->Canvas->Font->Color = clWhite;
|
||
}
|
||
else
|
||
pSG->Canvas->Brush->Color = bEven ? clWhite : COLOR_OVEN;
|
||
|
||
pSG->Canvas->FillRect(Rect);
|
||
|
||
if(szTxt.Width){
|
||
if(m_iType==TYPE_P_CHIP && ACol==1){ //截断超长字符串并加...
|
||
if(x + DPIX(2) + szTxt.Width > Rect.right){
|
||
int xExt = x + DPIX(2) + pSG->Canvas->TextWidth("...");
|
||
int nLen = strText.Length() - 1;
|
||
String str = strText.SubString(1, nLen);
|
||
int wS = pSG->Canvas->TextWidth(str);
|
||
|
||
while( xExt + wS > Rect.right ){
|
||
str = strText.SubString(1, --nLen);
|
||
wS = pSG->Canvas->TextWidth(str);
|
||
}
|
||
|
||
strText = str + "...";
|
||
}
|
||
}
|
||
|
||
pSG->Canvas->TextOut(x,y,strText);
|
||
}
|
||
|
||
pSG->Canvas->Brush->Style = rBS;
|
||
pSG->Canvas->Brush->Color = rBC;
|
||
pSG->Canvas->Font->Color = rFC;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::EditorKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
if(Key<37 || Key>40)
|
||
return;
|
||
|
||
int col = m_colEdit,
|
||
row = m_rowEdit;
|
||
if(Key==37 && m_pEditor->SelStart==0 && m_pEditor->SelLength==0){ //最左边左键
|
||
col--;
|
||
Key = 0;
|
||
}
|
||
else if(Key==38){
|
||
row--;
|
||
Key = 0;
|
||
}
|
||
else if(Key==39 && m_pEditor->SelStart==m_pEditor->Text.Length()){
|
||
col++;
|
||
Key = 0;
|
||
}
|
||
else if(Key==40){
|
||
row++;
|
||
Key = 0;
|
||
}
|
||
else
|
||
return;
|
||
|
||
if(row>0)
|
||
SGSelCell(col, row);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::EditorKeyPress(TObject *Sender, System::WideChar &Key)
|
||
{
|
||
if(Key==13)
|
||
GridEndEdit();
|
||
else if(Key<0x1E)
|
||
return;
|
||
else if(m_iType==TYPE_P_CHIP){
|
||
if( Key>'9' || Key<'0' ){
|
||
if(m_cbKind->ItemIndex==KIND_CHIP_WLD && Key=='-'
|
||
&& (m_colEdit==2 || m_colEdit==4)){
|
||
TEdit* pE = (TEdit*)Sender;
|
||
if(pE->SelStart!=0 || pE->Text.Pos("-")>0)
|
||
Key = 0;
|
||
}
|
||
else
|
||
Key = 0;
|
||
}
|
||
}
|
||
else{
|
||
if(m_colEdit==C_CP){
|
||
int iRoad = m_rgRoad->ItemIndex;
|
||
if( (Key>'9' || Key<'0') //不是数字
|
||
&& Key!='a' && Key!='A' && Key!='s' && Key!='S' && Key!='d' && Key!='D' ) //不是asd
|
||
Key = 0;
|
||
else if((Key=='d' || Key=='D') && iRoad>0) //非珠盘不能有d
|
||
Key = 0;
|
||
}
|
||
else if(m_colEdit==C_PD){
|
||
if(Key!='a' && Key!='s' && Key!='d' && Key!='x' && Key!='z')
|
||
Key = 0;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::EditorExit(TObject *Sender)
|
||
{
|
||
GridEndEdit();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::ComboKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
if(Key==37 || Key==39){
|
||
int col = m_colEdit;
|
||
if(Key==37) col--;
|
||
else col++;
|
||
|
||
Key = 0;
|
||
SGSelCell(col, m_rowEdit);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGSelCell(int col, int row)
|
||
{
|
||
GridEndEdit();
|
||
|
||
if(row > 0 && row <= m_nRows+1){
|
||
if(row == m_nRows+1){
|
||
m_nRows++;
|
||
m_sg->Cells[0][m_nRows] = m_nRows;
|
||
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount++;
|
||
|
||
if(!m_bColChanged && !m_bRowChanged){
|
||
m_btnSave->Enabled = m_bRowChanged = true;
|
||
m_btnSelect->Enabled = false;
|
||
}
|
||
}
|
||
|
||
if(m_sg->TopRow>0 && m_sg->TopRow > row)
|
||
m_sg->TopRow--;
|
||
else if(m_sg->TopRow + m_sg->VisibleRowCount <= row)
|
||
m_sg->TopRow++;
|
||
|
||
if(m_iType==TYPE_P_CHIP && m_cbKind->ItemIndex==KIND_CHIP_COM && col==1){
|
||
TRect rc = m_sg->CellRect(col, row);
|
||
m_pCombo->Top = rc.Top;
|
||
m_pCombo->Left = rc.Left;
|
||
m_pCombo->Width = rc.Right - rc.Left;
|
||
m_pCombo->ItemIndex = m_sg->Objects[col][row] ? (int)m_sg->Objects[col][row] : 0;;
|
||
m_pCombo->Visible = true;
|
||
m_pCombo->SetFocus();
|
||
}
|
||
else if(col>0 && col<m_sg->ColCount){
|
||
TRect rc = m_sg->CellRect(col, row);
|
||
m_pEditor->Top = rc.Top;
|
||
m_pEditor->Left = rc.Left;
|
||
m_pEditor->Width = rc.Right - rc.Left;
|
||
m_pEditor->Text = m_sg->Cells[col][row];
|
||
m_pEditor->Visible = true;
|
||
m_pEditor->SetFocus();
|
||
}
|
||
|
||
if(m_pCombo->Visible || m_pEditor->Visible){
|
||
m_colEdit = col;
|
||
m_rowEdit = row;
|
||
}
|
||
|
||
if(!m_bColChanged)
|
||
m_sOrig = m_sg->Cells[col][row];
|
||
|
||
SetSelection(row);
|
||
}
|
||
else{
|
||
SetSelection(-1);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGSelectCell(TObject *Sender, System::LongInt ACol, System::LongInt ARow, bool &CanSelect)
|
||
{
|
||
CanSelect = ARow > 0 && ARow <= m_nRows+1;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
ResetIdle();
|
||
|
||
if(m_pEditor->Visible || m_pCombo->Visible)
|
||
return;
|
||
|
||
int row = m_sg->Selection.Top,
|
||
col = 0;
|
||
if(row>0){
|
||
if(Key==37){ //选中最右格
|
||
col = m_sg->ColCount-1;
|
||
}
|
||
else if(Key==39){
|
||
col = 1;
|
||
}
|
||
else if(Key==38 && row>1){
|
||
row--;
|
||
}
|
||
else if(Key==40 && row<m_nRows){
|
||
row++;
|
||
}
|
||
}
|
||
SGSelCell(col, row);
|
||
|
||
Key = 0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGMouseWheelDown(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
||
{
|
||
TStringGrid* pSG = (TStringGrid*)Sender;
|
||
SendMessage(pSG->Handle,WM_VSCROLL,SB_LINEDOWN,0);
|
||
Handled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGMouseWheelUp(TObject *Sender, TShiftState Shift, TPoint &MousePos, bool &Handled)
|
||
{
|
||
TStringGrid* pSG = (TStringGrid*)Sender;
|
||
SendMessage(pSG->Handle,WM_VSCROLL,SB_LINEUP,0);
|
||
Handled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGTopLeftChanged(TObject *Sender)
|
||
{
|
||
TStringGrid* pSG = (TStringGrid*)Sender;
|
||
|
||
if(pSG->LeftCol>0)
|
||
pSG->LeftCol = 0;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::SGMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
|
||
{
|
||
if(Button==mbLeft){
|
||
int col, row;
|
||
m_sg->MouseToCell(X, Y, col, row);
|
||
|
||
SGSelCell(col, row);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnInsRowClick(TObject *Sender)
|
||
{
|
||
TStringGrid* pSG = m_sg;
|
||
TGridRect rtSel = pSG->Selection;
|
||
|
||
GridEndEdit();
|
||
|
||
int ind = rtSel.Top;
|
||
if(ind>0){
|
||
m_nRows++;
|
||
m_sg->Cells[0][m_nRows] = m_nRows;
|
||
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount++;
|
||
|
||
for( int i=m_nRows; i>ind; i--){
|
||
pSG->Rows[i]->Assign(pSG->Rows[i-1]);
|
||
pSG->Cells[0][i] = i;
|
||
}
|
||
|
||
for(int i=1; i<pSG->ColCount; i++){
|
||
pSG->Cells[i][ind] = "";
|
||
}
|
||
pSG->Objects[1][ind] = NULL;
|
||
|
||
if(!m_bRowChanged){
|
||
m_btnSave->Enabled = m_bRowChanged = true;
|
||
m_btnSelect->Enabled = false;
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnDelRowClick(TObject *Sender)
|
||
{
|
||
TStringGrid* pSG = m_sg;
|
||
TGridRect rtSel = pSG->Selection;
|
||
|
||
GridEndEdit();
|
||
|
||
int ind = rtSel.Top;
|
||
if(ind>0){
|
||
if(ind==1 && m_nRows==1){ //唯一一条数据,清空
|
||
for(int i=1; i<pSG->ColCount; i++)
|
||
pSG->Cells[i][1] = "";
|
||
}
|
||
else{
|
||
for( int i=ind; i<=m_nRows; i++){
|
||
pSG->Rows[i]->Assign(pSG->Rows[i+1]);
|
||
if(pSG->Cells[0][i].Length())
|
||
pSG->Cells[0][i] = i;
|
||
}
|
||
|
||
if(m_nRows>=pSG->VisibleRowCount)
|
||
pSG->RowCount--;
|
||
if(ind==m_nRows)
|
||
SetSelection(ind-1);
|
||
|
||
m_nRows--;
|
||
}
|
||
|
||
if(!m_bColChanged){
|
||
if(!m_bRowChanged || ind<=m_editPolicy->aRows.size()){ //内容改变
|
||
m_btnSave->Enabled = m_bRowChanged = m_bColChanged = true;
|
||
m_btnSelect->Enabled = false;
|
||
}
|
||
else if(m_nRows==m_editPolicy->aRows.size()){
|
||
m_btnSave->Enabled = m_bRowChanged = false;
|
||
m_btnSelect->Enabled = true;
|
||
}
|
||
}
|
||
|
||
pSG->Invalidate();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnPolicyChange(TObject *Sender)
|
||
{
|
||
TComboBox* combo = (TComboBox*)Sender;
|
||
|
||
int ind = combo->ItemIndex;
|
||
|
||
m_btnSelect->Enabled = ind>=0;
|
||
|
||
if( ind != m_iSelPolicy ){
|
||
m_iSelPolicy = ind;
|
||
if(ind>=0){
|
||
vector<TBasePolicy*>& aPolicies = m_iType==TYPE_P_BET ? g_aBetPolicies : g_aChipPolicies;
|
||
m_editPolicy = aPolicies[ind];
|
||
}
|
||
else{
|
||
m_editPolicy = NULL;
|
||
}
|
||
|
||
Clear();
|
||
UpdateGrid();
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnAddClick(TObject *Sender)
|
||
{
|
||
m_cbPolicy->ItemIndex = -1;
|
||
m_cbPolicy->Text = AutoNewName();
|
||
|
||
m_iSelPolicy = -1;
|
||
m_btnSelect->Enabled = false;
|
||
|
||
m_editPolicy = NULL;
|
||
|
||
Clear();
|
||
UpdateGrid();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnSaveClick(TObject *Sender)
|
||
{
|
||
if(m_editPolicy){ //处理特殊打法注码
|
||
if(m_iType==TYPE_P_CHIP && m_editPolicy->kind==KIND_CHIP_RAN){ //随机注码
|
||
TChip02Frame* frmSP = (TChip02Frame*)m_frmSP;
|
||
int c1 = frmSP->m_leMinChip->Text.ToInt(),
|
||
c2 = frmSP->m_leMaxChip->Text.ToInt();
|
||
|
||
g_RandomChip.minChip = Min(c1, c2);
|
||
g_RandomChip.maxChip = Max(c1, c2);
|
||
|
||
m_btnSave->Enabled = false;
|
||
|
||
return;
|
||
}
|
||
|
||
if(m_iType==TYPE_P_BET && m_editPolicy->kind==KIND_BET_ASK){ //庄闲问路
|
||
TBet02Frame* frmSP = (TBet02Frame*)m_frmSP;
|
||
|
||
for(int i=0; i<2; i++)
|
||
g_BPAskBet.bet[i] = frmSP->m_rgs[i]->ItemIndex;
|
||
|
||
m_btnSave->Enabled = false;
|
||
|
||
return;
|
||
}
|
||
|
||
if(m_iType==TYPE_P_BET && m_editPolicy->kind==KIND_BET_DIF){ //庄闲差
|
||
TBet03Frame* frmSP = (TBet03Frame*)m_frmSP;
|
||
|
||
g_BPDiffBet.diff[0] = frmSP->m_leBlP->Text.ToInt();
|
||
g_BPDiffBet.diff[1] = frmSP->m_lePlB->Text.ToInt();
|
||
strcpy(g_BPDiffBet.bets[0], ((AnsiString)frmSP->m_edBlP->Text).c_str());
|
||
strcpy(g_BPDiffBet.bets[1], ((AnsiString)frmSP->m_edPlB->Text).c_str());
|
||
|
||
m_btnSave->Enabled = false;
|
||
|
||
return;
|
||
}
|
||
}
|
||
|
||
TStringGrid* pSG = m_sg;
|
||
|
||
if(m_rowEdit>0)
|
||
GridEndEdit();
|
||
|
||
//自动清除无效空行
|
||
bool bModified = false;
|
||
for(int i=m_nRows; i>1; i--){
|
||
bool bDel = true;
|
||
for(int j=1; j<pSG->ColCount; j++){
|
||
if(pSG->Cells[j][i].Length()){
|
||
bDel = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(bDel){
|
||
pSG->Cells[0][i] = "";
|
||
m_nRows--;
|
||
bModified = true;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
|
||
if(bModified){
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount = m_nRows+2;
|
||
else
|
||
m_sg->RowCount = m_sg->VisibleRowCount+1;
|
||
|
||
SetSelection(-1);
|
||
}
|
||
|
||
//校验数据完整并生成字符串
|
||
AnsiString sTxt;
|
||
for(int i=1; i<=m_nRows; i++){
|
||
if(i>1) sTxt += ";";
|
||
for(int j=1; j<pSG->ColCount; j++){
|
||
if(j>1) sTxt += ",";
|
||
|
||
String t = pSG->Cells[j][i];
|
||
if(!t.Length()){
|
||
String msg;
|
||
msg += "第" + IntToStr(i) + "行第" + IntToStr(j+1) + "列未输入";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONERROR | MB_OK);
|
||
|
||
SetSelection(i);
|
||
return;
|
||
}
|
||
else if(m_iType==TYPE_P_CHIP){//校验跳转合法性
|
||
if(m_cbKind->ItemIndex==KIND_CHIP_NOR && (j==2||j==3) //常规
|
||
|| m_cbKind->ItemIndex==KIND_CHIP_HAN && (j==3||j==4) //层级
|
||
|| m_cbKind->ItemIndex==KIND_CHIP_LEV && (j==3||j==5) //阶梯
|
||
|| m_cbKind->ItemIndex==KIND_CHIP_WLD && (j==3||j==5) //次差
|
||
|| m_cbKind->ItemIndex==KIND_CHIP_COM && (j==4||j==6) ){ //组合
|
||
int r = 0;
|
||
if(!TryStrToInt(t, r) || r<0 || r>m_nRows){
|
||
String msg;
|
||
msg += "第" + IntToStr(i) + "行第" + IntToStr(j+1) + "列跳转有误";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONERROR | MB_OK);
|
||
|
||
SetSelection(i);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(m_iType==TYPE_P_CHIP && m_cbKind->ItemIndex==KIND_CHIP_COM && j==1){
|
||
int ind = (int)pSG->Objects[1][i];
|
||
sTxt += IntToStr((int)m_pCombo->Items->Objects[ind]);
|
||
}
|
||
else
|
||
sTxt += t;
|
||
}
|
||
}
|
||
|
||
TBasePolicy* pTmpPolicy;
|
||
if(m_iType==TYPE_P_BET){
|
||
pTmpPolicy = new TBetPolicy;
|
||
((TBetPolicy*)pTmpPolicy)->road = m_rgRoad->ItemIndex;
|
||
}
|
||
else{
|
||
//是否层级注码
|
||
int kind = m_cbKind->ItemIndex;
|
||
pTmpPolicy = kind==KIND_CHIP_HAN ? new TTierPolicy
|
||
: kind==KIND_CHIP_LEV || kind<=KIND_CHIP_COM ? new TLevelPolicy
|
||
: kind==KIND_CHIP_WLD ? new TWLDiffPolicy
|
||
: new TChipPolicy;
|
||
pTmpPolicy->kind = kind;
|
||
|
||
//爆缆处理
|
||
((TChipPolicy*)pTmpPolicy)->deadPause = m_edDeadPause->Text.ToInt();
|
||
for(int i=0; i<3; i++){
|
||
if(m_aDeadRB[i]->Checked){
|
||
((TChipPolicy*)pTmpPolicy)->dead = i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
//层级注码
|
||
if(kind==KIND_CHIP_HAN){
|
||
((TTierPolicy*)pTmpPolicy)->bTierWinRet = m_cbTierWinRet->Checked;
|
||
((TTierPolicy*)pTmpPolicy)->bTierAccChip = m_cbTierAccChip->Checked;
|
||
((TTierPolicy*)pTmpPolicy)->bTierLos0 = m_cbTierLos0->Checked;
|
||
}
|
||
else if(kind>=KIND_CHIP_LEV && kind<=KIND_CHIP_WLD){
|
||
((TLevelPolicy*)pTmpPolicy)->bTotalDiff = m_cbLevelTotalDiff->Checked;
|
||
|
||
if(m_cbLevelTotalDiff->Checked)
|
||
((TLevelPolicy*)pTmpPolicy)->bInstant = m_cbLevelInstant->Checked;
|
||
|
||
if(kind==KIND_CHIP_WLD)
|
||
((TWLDiffPolicy*)pTmpPolicy)->bIndie = m_cbLevelIndie->Checked;
|
||
}
|
||
}
|
||
|
||
int err = pTmpPolicy->ParsePolicy(sTxt.c_str(), m_iType);
|
||
if(err){
|
||
int row = err >> 16,
|
||
col = err & 0xF;
|
||
String msg;
|
||
msg += "第" + IntToStr(row) + "行第" + IntToStr(col+1) + "列输入不合规范";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONERROR | MB_OK);
|
||
|
||
SetSelection(row);
|
||
|
||
delete pTmpPolicy;
|
||
return;
|
||
}
|
||
|
||
if(m_iType==TYPE_P_CHIP && pTmpPolicy->kind==KIND_CHIP_COM){ //检查倍数合法性
|
||
for(int i=0; i<pTmpPolicy->aRows.size(); i++){
|
||
TComboRow* pCR = (TComboRow*)pTmpPolicy->aRows[i];
|
||
CheckComboRow(pCR);
|
||
|
||
int minChip = MinChipOfPolicy(pCR->iPolicy);
|
||
int mul = pCR->chip;
|
||
if(minChip * mul < g_MinOnBet){
|
||
String msg;
|
||
msg += "第" + IntToStr(i+1) + "行倍数设置小于限红";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONERROR | MB_OK);
|
||
SetSelection(i+1);
|
||
delete pTmpPolicy;
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
|
||
TPolicySaveForm* pForm = new TPolicySaveForm(this, m_iType, m_cbPolicy->Text);
|
||
if(pForm->ShowModal()==mrOk){
|
||
pTmpPolicy->name = pForm->m_name;
|
||
pTmpPolicy->type = 2;
|
||
int index = pForm->m_iPolicy;
|
||
if(index>0){
|
||
TBasePolicy* pP = m_iType==TYPE_P_BET ? g_aBetPolicies[index] : g_aChipPolicies[index];
|
||
pTmpPolicy->id = pP->id;
|
||
}
|
||
|
||
String msg = "保存" + m_sType;
|
||
int ret = SavePolicy(m_iType, pTmpPolicy, index);
|
||
if(ret>=0){
|
||
if(index<0){
|
||
m_cbPolicy->AddItem(pTmpPolicy->name, NULL);
|
||
m_cbPolicy->ItemIndex = m_cbPolicy->Items->Count-1;
|
||
|
||
if(m_iType==TYPE_P_CHIP && pTmpPolicy->kind==KIND_CHIP_NOR){
|
||
m_pCombo->AddItem(pTmpPolicy->name, (TObject*)pTmpPolicy->id);
|
||
}
|
||
|
||
CalcNewName();
|
||
|
||
PostMessage(Application->MainFormHandle, UM_POLICYCHANGED, 0x10000 | m_iType, 0);
|
||
m_iSelPolicy = m_cbPolicy->ItemIndex;
|
||
}
|
||
else if(m_iSelPolicy!=index){
|
||
m_cbPolicy->ItemIndex = index;
|
||
m_iSelPolicy = index;
|
||
|
||
if(m_iType==TYPE_P_CHIP && pTmpPolicy->kind==KIND_CHIP_NOR
|
||
&& m_pCombo->Items->IndexOfObject((TObject*)pTmpPolicy->id)<0 ){
|
||
m_pCombo->AddItem(pTmpPolicy->name, (TObject*)pTmpPolicy->id);
|
||
}
|
||
}
|
||
|
||
m_editPolicy = pTmpPolicy;
|
||
|
||
m_btnSave->Enabled = m_bRowChanged = m_bColChanged = false;
|
||
m_btnSelect->Enabled = true;
|
||
m_btnDel->Enabled = true;
|
||
|
||
msg += "成功";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONINFORMATION | MB_OK);
|
||
}
|
||
else{
|
||
msg += "失败";
|
||
MessageBox(Handle, msg.c_str(), L"保存", MB_ICONERROR | MB_OK);
|
||
delete pTmpPolicy;
|
||
}
|
||
}
|
||
else
|
||
delete pTmpPolicy;
|
||
|
||
delete pForm;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnSelectClick(TObject *Sender)
|
||
{
|
||
PostMessage(Application->MainFormHandle, UM_POLICYCHANGED, m_iType, m_iSelPolicy);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnDelClick(TObject *Sender)
|
||
{
|
||
int iPolicy = m_cbPolicy->ItemIndex;
|
||
String msg;
|
||
int inUse = IsPolicyInUse(m_iType, iPolicy);
|
||
if(inUse){
|
||
msg = m_sType + "[" + m_editPolicy->name + "]";
|
||
if(inUse==1)
|
||
msg += "正在使用中,不可删除";
|
||
else
|
||
msg += "用于台桌独立策略,不可删除";
|
||
|
||
MessageBox(Handle, msg.c_str(), L"删除", MB_ICONERROR | MB_OK);
|
||
return;
|
||
}
|
||
|
||
if(m_iType==TYPE_P_CHIP && m_editPolicy->kind==KIND_CHIP_NOR){
|
||
vector<int> combs = PolicyInCombo(m_editPolicy->id);
|
||
if(!combs.empty()){
|
||
msg = m_sType + "[" + m_editPolicy->name + "]被下列组合方案使用,不可删除\n";
|
||
for(int i=0; i<combs.size(); i++){
|
||
msg += g_aChipPolicies[combs[i]]->name + "\n";
|
||
}
|
||
MessageBox(Handle, msg.c_str(), L"删除", MB_ICONERROR | MB_OK);
|
||
return;
|
||
}
|
||
}
|
||
|
||
msg = "确定删除" + m_sType + "[" + m_editPolicy->name + "]?";
|
||
int mrRet = MessageBox(Handle, msg.c_str(), L"删除", MB_ICONQUESTION | MB_OKCANCEL);
|
||
if(mrRet==mrCancel)
|
||
return;
|
||
|
||
int ret = DeletePolicy(m_iType, iPolicy);
|
||
if(ret>=0){
|
||
m_cbPolicy->Items->Delete(iPolicy);
|
||
|
||
CalcNewName();
|
||
m_cbPolicy->Text = AutoNewName();
|
||
|
||
if(m_iType==TYPE_P_CHIP && m_editPolicy->kind==KIND_CHIP_NOR){
|
||
int iCombo = m_pCombo->Items->IndexOfObject((TObject*)m_editPolicy->id);
|
||
m_cbPolicy->Items->Delete(iCombo);
|
||
}
|
||
|
||
PostMessage(Application->MainFormHandle, UM_POLICYCHANGED, 0x20000 | m_iType, iPolicy);
|
||
OnPolicyChange(m_cbPolicy);
|
||
}
|
||
else{
|
||
String msg = "删除" + m_sType + "失败";
|
||
MessageBox(Handle, msg.c_str(), L"删除", MB_ICONERROR | MB_OK);
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnRoadClick(TObject *Sender)
|
||
{
|
||
TRadioGroup* pRG = (TRadioGroup*)Sender;
|
||
if(m_editPolicy && ((TBetPolicy*)m_editPolicy)->road!=pRG->ItemIndex)
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnAskRoadClick(TObject *Sender)
|
||
{
|
||
TRadioGroup* pRG = (TRadioGroup*)Sender;
|
||
if(pRG->ItemIndex!=g_BPAskBet.bet[pRG->Tag])
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnDeadClick(TObject *Sender)
|
||
{
|
||
TRadioButton* pRB = (TRadioButton*)Sender;
|
||
if(m_editPolicy && ((TChipPolicy*)m_editPolicy)->dead!=pRB->Tag)
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::DeadPauseExit(TObject *Sender)
|
||
{
|
||
TEdit* pE = (TEdit*)Sender;
|
||
int num = pE->Text.ToInt();
|
||
if(num<0 || num>15){
|
||
ShowMessage("请输入0-15的分钟数");
|
||
pE->SetFocus();
|
||
}
|
||
else if(m_editPolicy && ((TChipPolicy*)m_editPolicy)->deadPause!=num)
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::DeadPauseKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
|
||
{
|
||
if( Key==13 )
|
||
m_sg->SetFocus();
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnKindChange(TObject *Sender)
|
||
{
|
||
Clear();
|
||
InitChipGrid(m_cbKind->ItemIndex);
|
||
m_nRows = 1;
|
||
m_sg->RowCount = m_sg->VisibleRowCount+1;
|
||
m_sg->Cells[0][1] = 1;
|
||
SetSelection(1);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::InitChipGrid(int kind)
|
||
{
|
||
m_cbTierWinRet->Visible = kind==KIND_CHIP_HAN;
|
||
m_cbTierAccChip->Visible = kind==KIND_CHIP_HAN;
|
||
m_cbTierLos0->Visible = kind==KIND_CHIP_HAN;
|
||
m_cbLevelTotalDiff->Visible = kind>=KIND_CHIP_LEV && kind<=KIND_CHIP_WLD;
|
||
m_cbLevelIndie->Visible = kind==KIND_CHIP_WLD;
|
||
m_cbLevelInstant->Visible = kind>=KIND_CHIP_LEV && kind<=KIND_CHIP_WLD;
|
||
m_cbLevelInstant->Enabled = m_cbLevelTotalDiff->Checked;
|
||
|
||
if(kind==KIND_CHIP_HAN){
|
||
m_sg->ColCount = 5;
|
||
m_sg->Cells[0][0] = "层级";
|
||
m_sg->Cells[1][0] = "注码";
|
||
m_sg->Cells[2][0] = "手数";
|
||
m_sg->Cells[3][0] = "赢走向";
|
||
m_sg->Cells[4][0] = "输走向";
|
||
m_sg->ColWidths[0] = DPIX(70);
|
||
m_sg->ColWidths[1] = DPIX(85);
|
||
m_sg->ColWidths[2] = DPIX(80);
|
||
m_sg->ColWidths[3] = DPIX(80);
|
||
m_sg->ColWidths[4] = DPIX(80);
|
||
|
||
Hint = "层级注码按当层输赢手数差(赢>输为'赢',否则为'输')决定走向";
|
||
}
|
||
else{
|
||
if(kind==KIND_CHIP_LEV){
|
||
m_sg->ColCount = 6;
|
||
m_sg->Cells[0][0] = "层级";
|
||
m_sg->Cells[1][0] = "注码";
|
||
m_sg->Cells[2][0] = "赢利";
|
||
m_sg->Cells[3][0] = "走向";
|
||
m_sg->Cells[4][0] = "亏损";
|
||
m_sg->Cells[5][0] = "走向";
|
||
m_sg->ColWidths[0] = DPIX(60);
|
||
m_sg->ColWidths[1] = DPIX(70);
|
||
m_sg->ColWidths[2] = DPIX(72);
|
||
m_sg->ColWidths[3] = DPIX(60);
|
||
m_sg->ColWidths[4] = DPIX(72);
|
||
m_sg->ColWidths[5] = DPIX(60);
|
||
|
||
Hint = "阶梯注码按当层输赢金额(赢>输为'赢利',赢<输为'亏损')决定走向";
|
||
}
|
||
else if(kind==KIND_CHIP_WLD){
|
||
m_sg->ColCount = 6;
|
||
m_sg->Cells[0][0] = "层级";
|
||
m_sg->Cells[1][0] = "注码";
|
||
m_sg->Cells[2][0] = "大于等于";
|
||
m_sg->Cells[3][0] = "走向";
|
||
m_sg->Cells[4][0] = "小于等于";
|
||
m_sg->Cells[5][0] = "走向";
|
||
m_sg->ColWidths[0] = DPIX(60);
|
||
m_sg->ColWidths[1] = DPIX(66);
|
||
m_sg->ColWidths[2] = DPIX(74);
|
||
m_sg->ColWidths[3] = DPIX(60);
|
||
m_sg->ColWidths[4] = DPIX(74);
|
||
m_sg->ColWidths[5] = DPIX(60);
|
||
|
||
Hint = "赢输次差注码按投注输赢的次数差(赢次数-输次数)决定走向";
|
||
}
|
||
else if(kind==KIND_CHIP_COM){
|
||
m_sg->ColCount = 7;
|
||
m_sg->Cells[0][0] = "层级";
|
||
m_sg->Cells[1][0] = "常规方案";
|
||
m_sg->Cells[2][0] = "倍数";
|
||
m_sg->Cells[3][0] = "赢利";
|
||
m_sg->Cells[4][0] = "走向";
|
||
m_sg->Cells[5][0] = "亏损";
|
||
m_sg->Cells[6][0] = "走向";
|
||
m_sg->ColWidths[0] = DPIX(30);
|
||
m_sg->ColWidths[1] = DPIX(160);
|
||
m_sg->ColWidths[2] = DPIX(39);
|
||
m_sg->ColWidths[3] = DPIX(50);
|
||
m_sg->ColWidths[4] = DPIX(32);
|
||
m_sg->ColWidths[5] = DPIX(50);
|
||
m_sg->ColWidths[6] = DPIX(32);
|
||
|
||
Hint = "组合阶梯注码是每层可选不同的常规注码方案的阶梯注码";
|
||
}
|
||
else{
|
||
m_sg->ColCount = 4;
|
||
m_sg->Cells[0][0] = "序号";
|
||
m_sg->Cells[1][0] = "注码";
|
||
m_sg->Cells[2][0] = "赢走向";
|
||
m_sg->Cells[3][0] = "输走向";
|
||
m_sg->ColWidths[0] = m_sg->DefaultColWidth;
|
||
m_sg->ColWidths[1] = m_sg->DefaultColWidth;
|
||
m_sg->ColWidths[2] = m_sg->DefaultColWidth;
|
||
m_sg->ColWidths[3] = m_sg->DefaultColWidth;
|
||
|
||
Hint = "常规注码按每次投注的输赢结果决定走向('和'不变)";
|
||
}
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnChipOptionClick(TObject *Sender)
|
||
{
|
||
if(m_editPolicy){
|
||
if(Sender==m_cbTierWinRet && ((TTierPolicy*)m_editPolicy)->bTierWinRet!=m_cbTierWinRet->Checked
|
||
|| Sender==m_cbTierAccChip && ((TTierPolicy*)m_editPolicy)->bTierAccChip!=m_cbTierAccChip->Checked
|
||
|| Sender==m_cbTierLos0 && ((TTierPolicy*)m_editPolicy)->bTierLos0!=m_cbTierLos0->Checked
|
||
|| Sender==m_cbLevelTotalDiff && ((TLevelPolicy*)m_editPolicy)->bTotalDiff!=m_cbLevelTotalDiff->Checked
|
||
|| Sender==m_cbLevelInstant && ((TLevelPolicy*)m_editPolicy)->bInstant!=m_cbLevelInstant->Checked
|
||
|| Sender==m_cbLevelIndie && ((TWLDiffPolicy*)m_editPolicy)->bIndie!=m_cbLevelIndie->Checked)
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
|
||
if(Sender==m_cbLevelTotalDiff){
|
||
m_cbLevelInstant->Enabled = m_cbLevelTotalDiff->Checked;
|
||
}
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnSPEditChange(TObject *Sender)
|
||
{
|
||
m_btnSave->Enabled = true;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnTipClick(TObject *Sender)
|
||
{
|
||
PostMessage(Application->MainFormHandle, UM_OPENMAUAL, 1, 0);
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnExport(TObject *Sender)
|
||
{
|
||
TStringGrid* pSG = m_sg;
|
||
|
||
if(m_rowEdit>0)
|
||
GridEndEdit();
|
||
|
||
//自动清除无效空行
|
||
bool bModified = false;
|
||
for(int i=m_nRows; i>1; i--){
|
||
bool bDel = true;
|
||
for(int j=1; j<pSG->ColCount; j++){
|
||
if(pSG->Cells[j][i].Length()){
|
||
bDel = false;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if(bDel){
|
||
pSG->Cells[0][i] = "";
|
||
m_nRows--;
|
||
bModified = true;
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
|
||
if(bModified){
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount = m_nRows+2;
|
||
else
|
||
m_sg->RowCount = m_sg->VisibleRowCount+1;
|
||
|
||
SetSelection(-1);
|
||
}
|
||
|
||
TSaveDialog *pDlg = new TSaveDialog(this);
|
||
pDlg->Title = "导出";
|
||
pDlg->Filter = "CSV文件(*.csv)|*.CSV;";
|
||
|
||
if(pDlg->Execute(Application->MainFormHandle)){
|
||
TStringList *psl=new TStringList();
|
||
|
||
try{
|
||
String name = pDlg->FileName;
|
||
if(ExtractFileExt(name)!='.csv')
|
||
name = ChangeFileExt(name, ".csv");
|
||
|
||
for(int i=0; i<=m_nRows; i++){
|
||
String sTxt;
|
||
|
||
for(int j=0; j<pSG->ColCount; j++){
|
||
if(j>0) sTxt += ",";
|
||
|
||
String t = pSG->Cells[j][i];
|
||
if(i>0 && m_iType==TYPE_P_CHIP && m_cbKind->ItemIndex==KIND_CHIP_COM && j==1){
|
||
int ind = (int)pSG->Objects[1][i];
|
||
sTxt += IntToStr((int)m_pCombo->Items->Objects[ind]);
|
||
}
|
||
else
|
||
sTxt += t;
|
||
}
|
||
|
||
psl->Add(sTxt);
|
||
}
|
||
|
||
psl->SaveToFile(name);
|
||
|
||
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 psl;
|
||
}
|
||
|
||
delete pDlg;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
void __fastcall TPolicyEditForm::OnImport(TObject *Sender)
|
||
{
|
||
TStringGrid* pSG = m_sg;
|
||
|
||
if(m_rowEdit>0)
|
||
GridEndEdit();
|
||
|
||
TOpenDialog * pDlg = new TOpenDialog(NULL);
|
||
pDlg->Options << ofFileMustExist;
|
||
pDlg->Title = "导入";
|
||
pDlg->Filter = "CSV文件 (*.csv)|*.CSV";
|
||
|
||
if(pDlg->Execute(Application->MainFormHandle)){
|
||
TStringList *psl = new TStringList();
|
||
|
||
try{
|
||
psl->LoadFromFile(pDlg->FileName);
|
||
|
||
//检验数据合法性
|
||
if(psl->Count==0)
|
||
throw Exception("文件内容为空");
|
||
|
||
vector<TStrings*> ass;
|
||
for( int i=0; i<psl->Count; i++ ){
|
||
bool bEmpty = true;
|
||
TStringList * psTmp = new TStringList;
|
||
|
||
TStringDynArray arr = SplitString( psl->Strings[i], "," );
|
||
for(int j=1; j<pSG->ColCount; j++){
|
||
String s = "";
|
||
if(arr.size()>j){
|
||
if(m_iType==TYPE_P_BET){
|
||
int iRoad = m_rgRoad->ItemIndex;
|
||
for(int k=1; k<=arr[j].Length(); k++){
|
||
WideChar Key = arr[j][k];
|
||
if(j==C_CP){
|
||
if( Key=='a' || Key=='A' || Key=='s' || Key=='S' //as
|
||
|| iRoad==0 && (Key=='d' || Key=='D') //珠盘路d
|
||
|| Key>='0' && Key<='9' && s.Length() ) //数字,且不是第一字符
|
||
s += Key;
|
||
}
|
||
else if(j==C_PD){
|
||
if(Key=='a' || Key=='s' || Key=='d' || Key=='x' || Key=='z')
|
||
s += Key;
|
||
}
|
||
}
|
||
}
|
||
else{
|
||
int val;
|
||
if(TryStrToInt(arr[j], val)){
|
||
s = arr[j];
|
||
}
|
||
}
|
||
}
|
||
|
||
psTmp->Add(s);
|
||
if(bEmpty && s.Length())
|
||
bEmpty = false;
|
||
}
|
||
|
||
if(bEmpty)
|
||
delete psTmp;
|
||
else
|
||
ass.push_back(psTmp);
|
||
}
|
||
|
||
if(ass.empty())
|
||
throw Exception("文件格式不正确或无有效内容");
|
||
|
||
LockWindowUpdate( m_sg->Handle );
|
||
Clear();
|
||
|
||
int size = m_nRows = ass.size();
|
||
if(m_nRows>=m_sg->VisibleRowCount)
|
||
m_sg->RowCount = m_nRows+2;
|
||
else
|
||
m_sg->RowCount = m_sg->VisibleRowCount+1;
|
||
|
||
int ind = 1;
|
||
for(int i=0; i<size; i++){
|
||
m_sg->Cells[0][ind] = ind;
|
||
|
||
TStrings * psTmp = ass[i];
|
||
for(int j=0; j<psTmp->Count; j++){
|
||
if(m_iType==TYPE_P_CHIP && m_cbKind->ItemIndex==KIND_CHIP_COM && j==0){
|
||
int id = psTmp->Strings[j].ToInt();
|
||
int iCombo = m_pCombo->Items->IndexOfObject((TObject*)id);
|
||
m_sg->Cells[1][ind] = m_pCombo->Items->Strings[iCombo];
|
||
m_sg->Objects[1][ind] = (TObject*)iCombo;
|
||
}
|
||
else
|
||
m_sg->Cells[j+1][ind] = psTmp->Strings[j];
|
||
}
|
||
|
||
delete psTmp;
|
||
ind++;
|
||
}
|
||
|
||
LockWindowUpdate(NULL);
|
||
}
|
||
catch(Exception &exception){
|
||
String str = "表格导入失败!\n"+exception.Message;
|
||
MessageBox(Application->MainFormHandle, str.c_str(), L"导入",
|
||
MB_ICONERROR | MB_OK);
|
||
}
|
||
|
||
delete psl;
|
||
}
|
||
|
||
delete pDlg;
|
||
}
|
||
//---------------------------------------------------------------------------
|
||
|