apivh.cpp
来自「一个以前收集的基于C/S架构的ERP客户端源代码」· C++ 代码 · 共 709 行 · 第 1/2 页
CPP
709 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Apivd.h"
#include "Apivh.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BillBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "GenBaseForm"
#pragma link "GenBaseForm"
#pragma link "GenBaseForm"
#pragma link "GenBaseForm"
#pragma resource "*.dfm"
TfrmApivh *frmApivh;
//---------------------------------------------------------------------------
__fastcall TfrmApivh::TfrmApivh(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
: TGenBaseForm(Owner,chWnd,MidCode,WhereStr)
{
SetAutoCodeString(seApivhCode,"Acm-51");
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::ClearControl(int Section,bool BringToNext)
{
if (Section == 1)
{
if (!BringToNext)
{
seApivhCode->Text =""; //发票号
scApivhFmonth->Text =g_sdFMonth; //月份
deApivhDate->Text =g_sdCurDate; //日期
scApivhSupply->ItemIndex =-1; //供应商
scApivhCurrency->ItemIndex =-1; //币种
seApivhEnrate->Text =""; //汇率
memApivhDesc->Text =""; //备注
deApivhPDate->Text =g_sdCurDate; //应付日期
chkApivhRed->Checked =false; //红字
lbApivhUser->Caption =g_sdUserCode; //操作员
chkApivhCheck->Checked =false; //审核标志
lbApivhChecker->Caption =""; //审核人
lbApivhCheckDate->Caption =""; //审核日期
lbApivhSysDate->Caption =""; //系统日期
}
sgApivh->RowCount=1;
}
else if (Section==2)
{
if (!BringToNext)
{
seApivdLine->Text =AnsiString(comServer->ItemCount+1); //行号
scApivdAplt->ItemIndex =-1; //行类型
scApivdFrom->ItemIndex =0; //来源
if(chkApivhRed->Checked)
scApivdDocType->ItemIndex=1; //单据类型
else
scApivdDocType->ItemIndex=0; //单据类型
seApivdDocCode->Text =""; //单据号
seApivdDocLine->Text =""; //单据行号
seApivdGoods->Text =""; //货物及劳务
scApivdUnit->ItemIndex =-1; //计量单位
seApivdQty->Text =""; //数量
seApivdPrice->Text =""; //单价
seApivdDRate->Text =""; //折扣率
seApivdDAmt->Text =""; //折扣额
scApivdTaxCode->ItemIndex =-1; //税码
seApivdTRate->Text =""; //税率
seApivdTAmt->Text =""; //税额
seApivdNAmt->Text =""; //净额
seApivdAmt->Text =""; //总额
seApivdCAmt->Text =""; //核销金额
scApivdState->ItemIndex=0; //状态
memApivdDesc->Text =""; //备注
seApivdRAmt->Text =""; //红冲金额
FDRate=0;
FDAmt=0;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::InitEditControl()
{
ClientGroup->AddComponent(1,false,false,true,fpApivhHead,fpApivhHead->Name);
ClientGroup->AddComponent(2,false,false,true,fpApivhDetail,fpApivhDetail->Name);
ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
ClientGroup->AddComponent(2,true,true,true, scApivhFmonth,scApivhFmonth->Name);
ClientGroup->AddComponent(2,true,true,true,scApivdFrom,scApivdFrom->Name);
ClientGroup->AddComponent(1,false,true,false,seApivhCode,seApivhCode->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdRAmt,seApivdRAmt->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdCAmt,seApivdCAmt->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdDAmt,seApivdDAmt->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdTAmt,seApivdTAmt->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdAmt,seApivdAmt->Name);
ClientGroup->AddComponent(2,true,true,true,seApivdTRate,seApivdTRate->Name);
ClientGroup->AddComponent(1,false,true,true,scApivhSupply,scApivhSupply->Name);
ClientGroup->AddComponent(1,false,true,true,scApivhCurrency,scApivhCurrency->Name);
ClientGroup->AddComponent(1,false,true,true,chkApivhRed,chkApivhRed->Name);
ClientGroup->AddComponent(1,true,true,true,scApivdDocType,scApivdDocType->Name);
FillComboBox(Handle,scApivhFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
FillComboBox(Handle,scApivhSupply,"SELECT SupplyCode,SupplyName,SupplyTaxCode,SupplyTaxNo,supplyaddr FROM sdSupply where supplycancel=0 order by SupplyCode",
"SupplyName","SupplyCode","SupplyTaxCode","SupplyTaxNo","supplyaddr");
AnsiString sSql;
sSql =AnsiString("select currencycode,currencyname,currencyrate=coalesce(rateratio,1),currencylocal from sdcurrency,sdrate");
sSql+=" where currencycode*=ratecurrency and ";
sSql+=" ratefmonth='"+g_sdPMonth+"'";
FillComboBox(Handle,scApivhCurrency,sSql,"CurrencyName","CurrencyCode","currencyrate","currencylocal");
FillComboBox(Handle,scApivdUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
FillComboBox(Handle,scApivdAplt,"select Apltname,Apltcode,ApltFrom from sdAplt","Apltname","Apltcode","ApltFrom");
FillComboBox(Handle,scApivdTaxCode,"select Taxname,Taxcode,TAXRATE from sdTax","Taxname","Taxcode","TAXRATE");
scApivdDocType->AddItems("收货单","1");
scApivdDocType->AddItems("退货单","2");
scApivdFrom->AddItems("手 工","1");
scApivdFrom->AddItems("生 成","2");
scApivdState->AddItems("状态一","1");
scApivdState->AddItems("状态二","2");
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmApivh::GetDataToGrid()
{
scApivdAplt->LocateKey(GetDetailValue("ApivdAplt"));
scApivdDocType->LocateKey(GetDetailValue("ApivdDocType"));
AnsiString s;
s = "\t" + GetDetailValue("ApivdLine") +
"\t" + scApivdAplt->ItemData[0] +
"\t" + scApivdDocType->ItemData[0] +
"\t" + GetDetailValue("ApivdDocCode") +
"\t" + GetDetailValue("ApivdDocLine") +
"\t" + GetDetailValue("ApivdGoods") ;
return s;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr;
switch(mAction)
{
case 0: // Append
ItemStr=GetDataToGrid();
sgApivh->AddItem(ItemStr);
break;
case 1: // Modify
sgApivh->ChangeItem(ItemStr,sgApivh->Row);
break;
case 2: // Delete
sgApivh->RemoveItem(sgApivh->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::GetDataFromComObject(int Section)
{
if (Section==1)
{
seApivhCode->Text = GetHeadValue("ApivhCode");
scApivhFmonth->Text = GetHeadValue("ApivhFmonth");
deApivhDate->Text = GetHeadValue("ApivhDate");
scApivhSupply->LocateKey(GetHeadValue("ApivhSupply"));
scApivhSupply->Text = scApivhSupply->ItemData[0];
scApivhCurrency->LocateKey(GetHeadValue("ApivhCurrency"));
scApivhCurrency->Text = scApivhCurrency->ItemData[0];
seApivhEnrate->Text = GetHeadValue("ApivhEnrate");
memApivhDesc->Text = GetHeadValue("ApivhDesc");
deApivhPDate->Text = GetHeadValue("ApivhPDate");
chkApivhRed->Checked = (GetHeadValue("ApivhRed")=="-1"?true:false);
lbApivhUser->Caption = GetHeadValue("ApivhUser");
chkApivhCheck->Checked = (GetHeadValue("ApivhCheck")=="1"?true:false);
if(chkApivhCheck->Checked)
SetCheckToolbarStatus(true);
else
SetCheckToolbarStatus(false);
lbApivhChecker->Caption = GetHeadValue("ApivhChecker");
lbApivhCheckDate->Caption= GetHeadValue("ApivhCheckDate");
lbApivhSysDate->Caption = GetHeadValue("ApivhSysDate");
}
else
{
seApivdLine->Text = GetDetailValue("ApivdLine");
scApivdAplt->LocateKey(GetDetailValue("ApivdAplt"));
scApivdAplt->Text = scApivdAplt->ItemData[0];
scApivdFrom->LocateKey(GetDetailValue("ApivdFrom"));
scApivdFrom->Text=scApivdFrom->ItemData[0];
scApivdDocType->LocateKey(GetDetailValue("ApivdDocType"));
scApivdDocType->Text =scApivdDocType->ItemData[0];
seApivdDocCode->Text = GetDetailValue("ApivdDocCode");
seApivdDocLine->Text = GetDetailValue("ApivdDocLine");
seApivdGoods->Text = GetDetailValue("ApivdGoods");
scApivdUnit->LocateKey(GetDetailValue("ApivdUnit"));
scApivdUnit->Text = scApivdUnit->ItemData[0];
seApivdQty->Text =GetDetailValue("ApivdQty");
seApivdPrice->Text = GetDetailValue("ApivdPrice");
seApivdDRate->Text = GetDetailValue("ApivdDRate");
seApivdDAmt->Text = GetDetailValue("ApivdDAmt");
scApivdTaxCode->LocateKey(GetDetailValue("ApivdTaxCode"));
scApivdTaxCode->Text = scApivdTaxCode->ItemData[0];
seApivdTRate->Text = GetDetailValue("ApivdTRate");
seApivdTAmt->Text = GetDetailValue("ApivdTAmt");
seApivdNAmt->Text = GetDetailValue("ApivdNAmt");
seApivdAmt->Text = GetDetailValue("ApivdAmt");
seApivdCAmt->Text = GetDetailValue("ApivdCAmt");
scApivdState->LocateKey(GetDetailValue("ApivdState"));
scApivdState->Text=scApivdState->ItemData[0];
memApivdDesc->Text = GetDetailValue("ApivdDesc");
seApivdRAmt->Text = GetDetailValue("ApivdRAmt");
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::SendDataToComObject(int Section)
{
if (Section==1) // Head
{
SetHeadValue("ApivhCode",Trim(seApivhCode->Text));
SetHeadValue("ApivhFmonth",scApivhFmonth->Text);
SetHeadValue("ApivhDate",deApivhDate->Text);
SetHeadValue("ApivhSupply",scApivhSupply->ItemData[1]);
SetHeadValue("ApivhCurrency",scApivhCurrency->ItemData[1]);
SetHeadValue("ApivhEnrate",seApivhEnrate->Text);
SetHeadValue("ApivhDesc",memApivhDesc->Text);
SetHeadValue("ApivhPDate",deApivhPDate->Text);
SetHeadValue("ApivhRed",(chkApivhRed->Checked==true?"-1":"1"));
SetHeadValue("ApivhUser",lbApivhUser->Caption);
}
else
{
SetDetailValue("ApivdCode",seApivhCode->Text);
SetDetailValue("ApivdLine",seApivdLine->Text);
SetDetailValue("ApivdAplt",scApivdAplt->ItemData[1]);
SetDetailValue("ApivdDocType",scApivdDocType->ItemData[1]);
SetDetailValue("ApivdFrom",scApivdFrom->ItemData[1]);
SetDetailValue("ApivdDocCode",seApivdDocCode->Text);
SetDetailValue("ApivdDocLine",seApivdDocLine->Text);
SetDetailValue("ApivdGoods",seApivdGoods->Text);
SetDetailValue("ApivdUnit",scApivdUnit->ItemData[1]);
SetDetailValue("ApivdQty",seApivdQty->Text);
SetDetailValue("ApivdPrice",seApivdPrice->Text);
SetDetailValue("ApivdDRate",seApivdDRate->Text);
SetDetailValue("ApivdDAmt",seApivdDAmt->Text);
SetDetailValue("ApivdTaxCode",scApivdTaxCode->ItemData[1]);
SetDetailValue("ApivdTRate",seApivdTRate->Text);
SetDetailValue("ApivdTAmt",seApivdTAmt->Text);
SetDetailValue("ApivdNAmt",seApivdNAmt->Text);
SetDetailValue("ApivdAmt",seApivdAmt->Text);
SetDetailValue("ApivdCAmt",seApivdCAmt->Text);
SetDetailValue("ApivdState",scApivdState->ItemData[1]);
SetDetailValue("ApivdDesc",memApivdDesc->Text);
SetDetailValue("ApivdRAmt",seApivdRAmt->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::WaitUserInput(int Section)
{
if(Section ==1)
{
if(CurrentState==caAddHead)
seApivhCode->SetFocus();
}
else
{
sgApivh->Visible=false;
fpApivhDetail->Visible=true;
seApivdLine->SetFocus();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::DisplayBill()
{
if(comServer->RecordCount==0)
return;
GetDataFromComObject(1); // Head
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::GetBill(AnsiString BillID)
{
int iRow;
comServer->Find("ApivhCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::FillGridWithData()
{
sgApivh->RowCount=1;
if(comServer->RecordCount > 0)
for (int i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0); // Append
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::ChangeToBrowseState(bool Browse)
{
sgApivh->Visible=true;
fpApivhDetail->Visible=false;
if(Browse==false)
sgApivh->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::sgApivhDblClick(TObject *Sender)
{
int iRow;
iRow=sgApivh->Row;
if (iRow == 0)
{
return;
}
comServer->LocateItemByKey(seApivhCode->Text+"\t"+sgApivh->TextMatrix[iRow][1]+"\t");
if (comServer->ItemCount>0)
{
GetDataFromComObject(2); // Detail
sgApivh->Visible=false;
fpApivhDetail->Visible=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::sgApivhSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
comServer->LocateItemByKey(seApivhCode->Text+"\t"+sgApivh->TextMatrix[ARow][1]+"\t");
if (!comServer->Eof)
GetDataFromComObject(2); // Detail
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivh::btnOKClick(TObject *Sender)
{
try
{
if (CurrentState==caAddDetail||CurrentState==caAddBill)
{
if(DetailState==caAddDetail)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?