📄 currency.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Currency.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmCurrency *frmCurrency;
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmCurrency::GetFieldValue(int FieldIndex)
{
WideString S;
S = ReadFieldValue(comServer,FieldIndex);
return(S);
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::ClearControl(bool BringToNext)
{
if(!BringToNext)
{
seCode->Text = "";
seName->Text = "";
seSym->Text = "";
scPos->Text = "";
seAmtDec->Text = "0";
sePriceDec->Text = "0";
scCarry->Text = "";
cbLocal->Checked = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::GetDataFromComObject()
{
seCode->Text = GetFieldValue(fiCurrencyCode);
sgCurrency->LocateGrid(1,seCode->Text);
seName->Text = GetFieldValue(fiCurrencyName);
seSym->Text = GetFieldValue(fiCurrencySym);
scPos->LocateKey(GetFieldValue(fiCurrencyPos));
scPos->Text =scPos->ItemData[0];
seAmtDec->Text = GetFieldValue(fiCurrencyAmtDec);
sePriceDec->Text = GetFieldValue(fiCurrencyPriceDec);
scCarry->LocateKey(GetFieldValue(fiCurrencyCarry));
scCarry->Text =scCarry->ItemData[0];
cbLocal->Checked = (GetFieldValue(fiCurrencyLocal) == "1");
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::SendDataToComObject()
{
WriteFieldValue(comServer,fiCurrencyCode,seCode->Text);
WriteFieldValue(comServer,fiCurrencyName,seName->Text);
WriteFieldValue(comServer,fiCurrencySym,seSym->Text);
WriteFieldValue(comServer,fiCurrencyPos,scPos->ItemData[1]);
if(seAmtDec->Text.IsEmpty())
WriteFieldValue(comServer,fiCurrencyAmtDec,("0"));
else
WriteFieldValue(comServer,fiCurrencyAmtDec,seAmtDec->Text);
if(sePriceDec->Text.IsEmpty())
WriteFieldValue(comServer,fiCurrencyPriceDec,"0");
else
WriteFieldValue(comServer,fiCurrencyPriceDec,sePriceDec->Text);
WriteFieldValue(comServer,fiCurrencyCarry,scCarry->ItemData[1]);
WriteFieldValue(comServer,fiCurrencyLocal,cbLocal->Checked ? "1":"0");
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::WaitUserInput()
{
seCode->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmCurrency::GetDataToGrid()
{
AnsiString s;
s = "\t" + GetFieldValue(fiCurrencyCode) +
"\t" + GetFieldValue(fiCurrencyName) +
"\t" + GetFieldValue(fiCurrencyAmtDec) +
"\t" + GetFieldValue(fiCurrencyPriceDec);
return(s);
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::RefreshGridData(int mAction)
{
AnsiString ItemStr;
ItemStr = GetDataToGrid();
if (mAction == 0) //Add
{
sgCurrency->AddItem(ItemStr);
}
else if(mAction == 1) //Edit
{
int i = sgCurrency->Row;
sgCurrency->RemoveItem(i);
sgCurrency->AddItem(ItemStr,i);
}
else if(mAction == 2) //Del
{
sgCurrency->RemoveItem(sgCurrency->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::FillGridWithData()
{
AnsiString ItemStr;
comServer->MoveFirst();
sgCurrency->RowCount = 1;
while (comServer->Eof == 0)
{
ItemStr = GetDataToGrid();
sgCurrency->AddItem(ItemStr);
comServer->MoveNext();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::InitEditControl()
{
ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
ClientGroup->AddComponent(2,true,true,false, sgCurrency,sgCurrency->Name);
ClientGroup->AddComponent(2,false,false,false,seCode,seCode->Name);
scPos->AddItems("首位","1");
scPos->AddItems("末位","2");
scCarry->AddItems("四舍五入","1");
scCarry->AddItems("取整","2");
scCarry->AddItems("向上取整","3");
}
//---------------------------------------------------------------------------
__fastcall TfrmCurrency::TfrmCurrency(TComponent* Owner)
: TRecBaseForm(Owner,euSdCurrency,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::FormClose(TObject *Sender,
TCloseAction &Action)
{
TRecBaseForm::FormClose(Sender,Action);
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::FormShow(TObject *Sender)
{
FillGridWithData();
comServer->MoveFirst();
GetDataFromComObject();
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::seCodeKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13 && CurrentState==caNormal)
{
comServer->LocateByKey(seCode->Text);
GetDataFromComObject();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmCurrency::sgCurrencyClick(TObject *Sender)
{
if (sgCurrency->Row > 0)
comServer->LocateByKey(sgCurrency->TextMatrix[sgCurrency->Row][1]);
if (!comServer->Eof)
GetDataFromComObject();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -