apivd.cpp
来自「一个以前收集的基于C/S架构的ERP客户端源代码」· C++ 代码 · 共 305 行
CPP
305 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Apivd.h"
#include "Apivh.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "StdBaseForm"
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmApivd *frmApivd;
//---------------------------------------------------------------------------
__fastcall TfrmApivd::TfrmApivd(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::InitControlGroup()
{
sgApivd->RowCount = 1;
seApivdCode->Text="";
seApivdSupply->Enabled=false;
FApivhCode=frmApivh->seApivhCode->Text;
seApivdSupply->Text=frmApivh->scApivhSupply->Text;
FApivhSupply=frmApivh->scApivhSupply->ItemData[1];
seApivdCurrency->Enabled=false;
seApivdCurrency->Text=frmApivh->scApivhCurrency->Text;
FApivhCurrency=frmApivh->scApivhCurrency->ItemData[1];
seApivdRate->Text=frmApivh->seApivhEnrate->Text;
chkApivdRed->Checked=frmApivh->chkApivhRed->Checked;
chkApivdRed->Enabled=false;
scApivdDocType->AddItems("收货单","1");
scApivdDocType->AddItems("退货单","2");
if(chkApivdRed->Checked)
scApivdDocType->ItemIndex=1;
else
scApivdDocType->ItemIndex=0;
scApivdDocType->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::seApivdCodeButtonClick(TObject *Sender)
{
AnsiString SqlStr;
TfrmWnQuery *p;
if(scApivdDocType->ItemIndex==-1)
return;
try
{
StartWaitForm("正在查询,请稍候...");
if(scApivdDocType->ItemData[1]=="1")
{
SqlStr="004[收货单号][收货日期][币种][税码]";
SqlStr+=" select PrechCode,PrechDate,PrechCurrency,PrechTaxCode from sdPrech ";
SqlStr+=" where Prechcheck=1 and Prechclose=0 and Prechcancel=0 ";
SqlStr+=" and PRECHSUPPLY='"+FApivhSupply+"' and PRECHCurrency='"+FApivhCurrency+"' order by Prechcode";
p=new TfrmWnQuery(this,"收货单查询",SqlStr);
}
else
{
SqlStr="004[退货单号][退货日期][币种][税码]";
SqlStr+=" select PrethCode,PrethDate,PrethCurrency,PrethTaxCode from sdPreth ";
SqlStr+=" where Prethcheck=1 and Prethclose=0 and Prethcancel=0 ";
SqlStr+=" and PREtHSUPPLY='"+FApivhSupply+"' and PREtHCurrency='"+FApivhCurrency+"'order by Prethcode";
p=new TfrmWnQuery(this,"退货单查询",SqlStr);
}
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seApivdCode->Text=p->ColData[1];
FApivhTax=p->ColData[4];
FillGridWithData();
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::FillGridWithData()
{
sgApivd->RowCount = 1;
AnsiString ItemStr,s_SQL,m_Price;
TComResultSet * TempRes=new TComResultSet(Handle,g_ClientHandle);
frmApivh->scApivdTaxCode->LocateKey(FApivhTax);
FApivhTaxRate=frmApivh->scApivdTaxCode->ItemData[2];
if(scApivdDocType->ItemData[1]=="1")
{
s_SQL="select line= PrecdLine,goodscode=PrecdGoods,unit=PrecdUnit";
s_SQL+=" ,qty=PrecdQty,price=PrecdPrice,goodsname=isnull((Select goodsname from sdgoods where goodscode = PrecdGoods),''),goodsSpec=isnull((Select goodsSpec from sdgoods where goodscode = PrecdGoods),'') ";
s_SQL+=" from sdPrecd where PrecdCODE='"+seApivdCode->Text+"'";
}
else
{
s_SQL="select line=PretdLine,goodscode=PretdGoods,unit=PretdUnit";
s_SQL+=" ,qty=PretdQty,price=PretdPrice ,goodsname=isnull((Select goodsname from sdgoods where goodscode = PretdGoods),''),goodsSpec=isnull((Select goodsSpec from sdgoods where goodscode = PretdGoods),'') ";
s_SQL+=" from sdPretd where PretdCODE='"+seApivdCode->Text+"'";
}
try
{
StartWaitForm("正在查询数据,请稍候......");
TempRes->Open(s_SQL,"");
while( TempRes->Eof == 0)
{
m_Price=TempRes->FieldByName("Price");
ItemStr="\t"+AnsiString("") +
"\t"+TempRes->FieldByName("line")+
"\t"+TempRes->FieldByName("goodscode")+
"\t"+TempRes->FieldByName("GoodsName")+
"\t"+TempRes->FieldByName("GoodsSpec")+
"\t"+TempRes->FieldByName("unit")+
"\t"+" "
"\t"+TempRes->FieldByName("Qty") +
"\t"+AnsiString(DataCarry(m_Price.ToDouble()/(1+FApivhTaxRate.ToDouble()),4,0))+
"\t"+"0" ;
sgApivd->AddItem(ItemStr);
TempRes->MoveNext();
}
}
__finally
{
EndWaitForm();
delete TempRes;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::sgApivdDblClick(TObject *Sender)
{
AnsiString SqlStr;
int ARow=sgApivd->Row;
if (ARow >0)
{
if(sgApivd->Col==1)
{
if (sgApivd->Cells[1][ARow] == "√")
{
sgApivd->Cells[1][ARow] = "";
for (int i=1;i<sgApivd->RowCount;i++)
{
if(sgApivd->Cells[1][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgApivd->Cells[1][ARow] = "√";
btnOK->Enabled=true;
}
}
else if(sgApivd->Col==7 && sgApivd->Cells[1][ARow] == "√")
{
SqlStr="002[行类型编码][行类型名称]select apltcode,apltname from sdaplt where ApltFrom=1 order by apltcode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"行类型查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sgApivd->Cells[7][ARow]=p->ColData[1];
}
delete p;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::bbSelAllClick(TObject *Sender)
{
if(sgApivd->RowCount <=1)
return;
for(int i=1;i<sgApivd->RowCount;i++)
sgApivd->Cells[1][i] = "√";
btnOK->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::bbSelNoneClick(TObject *Sender)
{
for(int i=1;i<sgApivd->RowCount;i++)
sgApivd->Cells[1][i] = "";
btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::btnOKClick(TObject *Sender)
{
double PQAmt,Fprice,FQty,FDRate,FDAmt, FTAmt, FNAmt,FAmt;
// 折扣率 折扣额 税额 净额 总额
int ErrNum;
try
{
StartWaitForm("正在生成收货单,请稍候......");
if(sgApivd->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmApivh->GetDetailValue("ApivdLine"));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgApivd->RowCount;i++)
{
if(sgApivd->Cells[1][i]=="√")
{
comServer->AddItem();
if(sgApivd->Cells[8][i]=="")
throw Exception("请输入数量!");
if(sgApivd->Cells[9][i]=="")
throw Exception("请输入单价!");
if(sgApivd->Cells[10][i]=="")
throw Exception("请输入折扣率!");
SetDetailValue("ApivdCode",FApivhCode);
SetDetailValue("ApivdLine",AnsiString(j));
SetDetailValue("ApivdAplt",sgApivd->Cells[7][i]);
SetDetailValue("ApivdFrom","2");
SetDetailValue("ApivdDocType",scApivdDocType->ItemData[1]);
SetDetailValue("ApivdDocCode",seApivdCode->Text);
SetDetailValue("ApivdDocLine",sgApivd->Cells[2][i]);
SetDetailValue("ApivdGoods",sgApivd->Cells[3][i]);
SetDetailValue("GoodsName",sgApivd->Cells[4][i]);
SetDetailValue("GoodsSpec",sgApivd->Cells[5][i]);
SetDetailValue("ApivdUnit",sgApivd->Cells[6][i]);
SetDetailValue("ApivdQty",sgApivd->Cells[8][i]);
FQty=sgApivd->Cells[8][i].ToDouble();
Fprice=sgApivd->Cells[9][i].ToDouble();
SetDetailValue("ApivdPrice",AnsiString(DataCarry(Fprice,2,0)));
SetDetailValue("ApivdDRate",sgApivd->Cells[10][i]);
FDRate=sgApivd->Cells[10][i].ToDouble();
//算折扣额
PQAmt=FQty*Fprice;
FDAmt=PQAmt*FDRate;
SetDetailValue("ApivdDAmt",AnsiString(DataCarry(FDAmt,2,0)));
SetDetailValue("ApivdTaxCode",FApivhTax);
SetDetailValue("ApivdTRate",FApivhTaxRate);
//算税额
FNAmt=PQAmt-FDAmt; //净额
FTAmt=FNAmt*FApivhTaxRate.ToDouble(); //税额
SetDetailValue("ApivdTAmt",AnsiString(DataCarry(FTAmt,2,0)));
SetDetailValue("ApivdNAmt",AnsiString(DataCarry(FNAmt,2,0)));
//合计总额
FAmt=DataCarry(FTAmt+FNAmt,2,0);
SetDetailValue("ApivdAmt",AnsiString(FAmt));
SetDetailValue("ApivdCAmt","0");
SetDetailValue("ApivdState","1");
SetDetailValue("ApivdDesc",sgApivd->Cells[11][i]);
SetDetailValue("ApivdRAmt","0");
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->FreeItem();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmApivd::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?