📄 pbeh.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Pbeh.h"
#include "Pbed.h"
#include "func.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "GenBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmPbeh *frmPbeh;
//---------------------------------------------------------------------------
__fastcall TfrmPbeh::TfrmPbeh(TComponent* Owner)
: TGenBaseForm(Owner,euSdPbeh,"")
{
AutoCtl=sePbehCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::InitEditControl()
{
ClientGroup->AddComponent(1,true,true,false,sgPbeh,sgPbeh->Name);
ClientGroup->AddComponent(1,false,false,true,FloatPanel1,FloatPanel1->Name);
ClientGroup->AddComponent(1,false,true,false,sePbehCode,sePbehCode->Name);
ClientGroup->AddComponent(1,true,true,true,scPbehFmonth,scPbehFmonth->Name);
ClientGroup->AddComponent(1,false,true,true,sePbehCurrency,sePbehCurrency->Name);
ClientGroup->AddComponent(2,false,false,true,FloatPanel2,FloatPanel2->Name);
ClientGroup->AddComponent(2,true,true,true,sePbedPrecdLine,sePbedPrecdLine->Name);
ClientGroup->AddComponent(2,true,true,true,sePbedGoods,sePbedGoods->Name);
ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
//Pbeh
FillEdit(sePbehCurrency,"SELECT CurrencyCode,CurrencyName FROM sdCurrency order by CurrencyCode","CurrencyName","CurrencyCode");
FillComboBox(scPbehExpense,"select Expensecode,ExpenseName from sdExpense order by ExpenseCode","ExpenseName","ExpenseCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::ClearControl(int Section,bool BringToNext)
{
if (Section == 1)
{
if (!BringToNext)
{
sePbehCode->Text ="";
scPbehFmonth->Text =g_sdPMonth;
dePbehDate->Text=g_sdCurDate;
sePbehCurrency->ItemIndex=-1;
sePbehCurrency->Text ="";
scPbehExpense->ItemIndex=-1;
scPbehExpense->Text ="";
cbxPbehCheck->Checked =false;
labPbehChecker->Caption ="";
labPbehUser->Caption =g_sdUserCode;
labPbehSysDate->Caption = "";
memPbehDesc->Text="";
//新增单据,工具栏使能
SetCheckToolbarStatus(false);
}
sgPbeh->RowCount=1;
}
else if (Section==2)
{
if (!BringToNext)
{
sePbedLine->Text =AnsiString(comServer->ItemCount+1);
sePbedPrecCode->Text="";
sePbedPrecdLine->Text="";
sePbedGoods->Text="";
labPbedGoodsName->Caption ="";
sePbedAmt->Text="";
memPbedDesc->Text="";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::GetDataFromComObject(int Section)
{
if (Section==1)
{
sePbehCode->Text =GetHeadValue(fiPbehCode);
scPbehFmonth->Text =GetHeadValue(fiPbehFmonth);
dePbehDate->Text=GetHeadValue(fiPbehDate);
sePbehCurrency->LocateKey(GetHeadValue(fiPbehCurrency));
scPbehExpense->LocateKey(GetHeadValue(fiPbehExpense));
cbxPbehCheck->Checked =GetHeadValue(fiPbehCheck)=="1";
labPbehChecker->Caption =GetHeadValue(fiPbehChecker);
labPbehUser->Caption =GetHeadValue(fiPbehUser);
labPbehSysDate->Caption =GetHeadValue(fiPbehSysDate);
//根据审核、取消状态,设置工具栏
if((GetHeadValue(fiPbehCheck)=="1"))
SetCheckToolbarStatus(true);
else
SetCheckToolbarStatus(false);
}
else
{
sePbedLine->Text=GetDetailValue(fiPbedLine);
sePbedPrecCode->Text=GetDetailValue(fiPbedPrecCode);
sePbedPrecdLine->Text=GetDetailValue(fiPbedPrecdLine);
g_sdRsGoods->LocateByKey(WideString(GetDetailValue(fiPbedGoods)));
sePbedGoods->Text = GetGoodsValue("GoodsCode");
labPbedGoodsName->Caption = GetGoodsValue("GoodsName");
sePbedAmt->Text=GetDetailValue(fiPbedAmt);
memPbedDesc->Text=GetDetailValue(fiPbedDesc);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::SendDataToComObject(int Section)
{
if (Section==1)
{
SetHeadValue(fiPbehCode,sePbehCode->Text);
SetHeadValue(fiPbehFmonth,scPbehFmonth->Text);
SetHeadValue(fiPbehDate,dePbehDate->Text);
SetHeadValue(fiPbehCurrency,sePbehCurrency->ItemData[1]);
SetHeadValue(fiPbehExpense,scPbehExpense->ItemData[1]);
SetHeadValue(fiPbehUser,labPbehUser->Caption);
SetHeadValue(fiPbehDesc,memPbehDesc->Text);
}
else
{
SetDetailValue(fiPbedCode,sePbehCode->Text);
SetDetailValue(fiPbedLine,sePbedLine->Text);
SetDetailValue(fiPbedPrecCode,sePbedPrecCode->Text);
SetDetailValue(fiPbedPrecdLine,sePbedPrecdLine->Text);
SetDetailValue(fiPbedGoods,sePbedGoods->Text);
SetDetailValue(fiPbedAmt,sePbedAmt->Text);
SetDetailValue(fiPbedDesc,memPbedDesc->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::WaitUserInput(int Section)
{
if (Section ==1)
{
if(sePbehCode->Enabled)
sePbehCode->SetFocus();
}
else
{
sgPbeh->Visible=false;
FloatPanel2->Visible=true;
if(sePbedPrecCode->Enabled)
sePbedPrecCode->SetFocus();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr=GetItemStringToGrid();
switch(mAction)
{
case 0:
sgPbeh->AddItem(ItemStr);
break;
case 1:
i = sgPbeh->Row;
sgPbeh->ChangeItem(ItemStr,i);
break;
case 2:
sgPbeh->RemoveItem(sgPbeh->Row);
break;
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPbeh::GetItemStringToGrid()
{
AnsiString s_ItemStr;
s_ItemStr = "\t"+GetDetailValue(fiPbedLine)+
"\t"+GetDetailValue(fiPbedPrecCode)+
"\t"+GetDetailValue(fiPbedPrecdLine)+
"\t"+GetDetailValue(fiPbedGoods)+
"\t"+GetDetailValue(fiPbedAmt)+
"\t"+GetDetailValue(fiPbedDesc);
return s_ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::DisplayBill()
{
if(comServer->RecordCount<=0)
return;
GetDataFromComObject(1);
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::GetBill(AnsiString BillID)
{
int iRow;
iRow=comServer->Find("PbehCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgPbeh->RowCount=1;
if(comServer->RecordCount>0)
{
for (i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0);
}
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPbeh::GetHeadValue(int Index)
{
return ReadFieldValue(comServer,Index);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmPbeh::GetDetailValue(int Index)
{
return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::SetHeadValue(int Index,AnsiString Value)
{
WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::FormCreate(TObject *Sender)
{
// FormIniFile="D:\Test.Ini";
// SetGridWidth(Name,sgRpoh,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::FormClose(TObject *Sender,
TCloseAction &Action)
{
TGenBaseForm::FormClose(Sender,Action);
// WriteGridWidth(Name,sgRpoh,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::FormShow(TObject *Sender)
{
InitEditControl();
ClearControl(1,false);
ClearControl(2,false);
TGenBaseForm::MoveToFirst();
ChangeToBrowseState();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::sgPbehSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
{
comServer->LocateItemByKey(WideString(sgPbeh->TextMatrix[ARow][1]));
}
if (!comServer->Eof)
{
GetDataFromComObject(2);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::sgPbehDblClick(TObject *Sender)
{
int iRow;
iRow=sgPbeh->Row;
if (iRow == 0)
{
return;
}
sgPbeh->Visible=false;
FloatPanel2->Visible=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::ChangeToBrowseState(bool agree)
{
sgPbeh->Visible=true;
FloatPanel2->Visible=false;
if(agree == false)
sgPbeh->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::btnOKClick(TObject *Sender)
{
try
{
if ((CurrentState==caAddDetail)||(CurrentState==caAddBill))
{
if(DetailState==caAddDetail)
comServer->AddItem();
SendDataToComObject(2);
comServer->AddToObject();
ClearControl(2,false);
sePbedPrecCode->SetFocus();
}
else
ChangeToBrowseState();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::btnCancelClick(TObject *Sender)
{
CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::RefreshUpdateData(int MsgSrc,int MsgType)
{
switch(MsgSrc)
{
case euSdCurrency:
if(ShowUpdateMessage(MsgSrc,MsgType))
{
FillEdit(sePbehCurrency,"SELECT CurrencyCode,CurrencyName FROM sdCurrency order by CurrencyCode","CurrencyName","CurrencyCode");
}
break;
case euSdExpense:
if(ShowUpdateMessage(MsgSrc,MsgType))
{
FillComboBox(scPbehExpense,"select Expensecode,ExpenseName from sdExpense order by ExpenseCode","ExpenseName","ExpenseCode");
}
break;
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::GenrateBill()
{
int TempCount;
TempCount = comServer->ItemCount;
SetControlState(caAddBill);
TfrmPbed *p=new TfrmPbed(this);
p->GetComObject(comServer);
try
{
p->ShowModal();
}
__finally
{
delete p;
}
if (TempCount < comServer->ItemCount)
TGenBaseForm::tbSaveClick(NULL);
else
CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::sePbehCurrencyButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="002[货币代码][货币名称]select Currencycode,CurrencyName ";
SqlStr+=" from sdCurrency ";
SqlStr+=" order by CurrencyCode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"货币查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sePbehCurrency->LocateKey(p->ColData[1]);
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::sePbehCodeExit(TObject *Sender)
{
if(CurrentState==caNormal && sePbehCode->Text != GetHeadValue(fiPbehCode))
{
comServer->LocateByKey(WideString(sePbehCode->Text));
DisplayBill();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::sePbedPrecCodeButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="006[收货单号][收货行号][收货物料][物料名称][收货数量][收货金额] ";
SqlStr+=" select PrechCode,PrecdLine,PrecdGoods,GoodsName,PrecdQty,PrecdAmt ";
SqlStr+=" from sdPrech,sdPrecd,sdGoods ";
SqlStr+=" where PrechCode=PrecdCode and PrechCheck=1 and PrecdGoods=GoodsCode ";
SqlStr+=" and PrechCurrency='"+sePbehCurrency->ItemData[1]+"' order by PrechCode,PrecdLine ";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"收货单查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sePbedPrecCode->Text=p->ColData[1];
sePbedPrecdLine->Text=p->ColData[2];
sePbedGoods->Text=p->ColData[3];
labPbedGoodsName->Caption=p->ColData[4];
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPbeh::UnDoChange()
{
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -