📄 precd_p_i.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Precd_P_I.h"
#include "Prech_P_I.h"
#include "wnquery.h"
#include "func.h"
//--------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmPrecd_P_I *frmPrecd_P_I;
//--------------------------------------------------------------------------
__fastcall TfrmPrecd_P_I::TfrmPrecd_P_I(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled=false;
}
//--------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::btnOKClick(TObject *Sender)
{
double FVal,FPrice,FQty,FDQty,FTax,FAmt;
int ErrNum;
try
{
StartWaitForm("正在生成收货单,请稍候......");
if(sgPrecd->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmPrech_P_I->GetDetailValue(fiPrecdLine));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgPrecd->RowCount;i++)
{
if(sgPrecd->Cells[1][i]=="√")
{
comServer->AddItem();
SetDetailValue(fiPrecdCode,frmPrech_P_I->sePrechCode->Text);
SetDetailValue(fiPrecdLine,AnsiString(j));
SetDetailValue(fiPrecdPo,sePrecdPoCode->Text);
SetDetailValue(fiPrecdPodLine, sgPrecd->Cells[2][i]);
SetDetailValue(fiPrecdGoods, sgPrecd->Cells[3][i]);
SetDetailValue(fiPrecdUnit, sgPrecd->Cells[4][i]);
SetDetailValue(fiPrecdConv, sgPrecd->Cells[5][i]);
if(sgPrecd->Cells[7][i] == "")
throw Exception("请输入送货数量");
SetDetailValue(fiPrecdDQty, sgPrecd->Cells[7][i]);
if(sgPrecd->Cells[8][i] == "")
throw Exception("请输入收货数量");
SetDetailValue(fiPrecdQty, sgPrecd->Cells[8][i]);
SetDetailValue(fiPrecdPrice, sgPrecd->Cells[13][i]);
FDQty=sgPrecd->Cells[7][i].ToDouble();
FQty=sgPrecd->Cells[8][i].ToDouble();
if(FQty > FDQty)
throw Exception("收货数量不能多于送货数量");
FPrice=sgPrecd->Cells[13][i].ToDouble();
FVal=(FQty*FPrice)/(1+FPrechTaxRate);
FAmt=DataCarry(FVal,2,0);
FTax=DataCarry(FVal*FPrechTaxRate,2,0);
SetDetailValue(fiPrecdAmt,AnsiString(FAmt));
SetDetailValue(fiPrecdTAmt,AnsiString(FTax));
SetDetailValue(fiPrecdLoc, sgPrecd->Cells[9][i]);
SetDetailValue(fiPrecdBatch, sgPrecd->Cells[10][i]);
SetDetailValue(fiPrecdSo, sgPrecd->Cells[11][i]);
SetDetailValue(fiPrecdSodLine, sgPrecd->Cells[12][i]);
SetDetailValue(fiPrecdRDate, sgPrecd->Cells[14][i]);
SetDetailValue(fiPrecdCDate, sgPrecd->Cells[15][i]);
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->Cancel();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::InitControlGroup()
{
sgPrecd->RowCount = 1;
sePrecdPoCode->Text="";
sePrecdSupply->Text=frmPrech_P_I->scPrechSupply->Text;
sePrecdSupply->Enabled=false;
FPrechSupply=frmPrech_P_I->scPrechSupply->ItemData[cbItem2];
sePrechCurrency->Text=frmPrech_P_I->sePrechCurrency->Text;
sePrechCurrency->Enabled=false;
FPrechCurrency=frmPrech_P_I->sePrechCurrency->ItemData[cbItem2];
sePrechRate->Text=frmPrech_P_I->sePrechEnrate->Text;
sePrechTax->Text=frmPrech_P_I->scPrechTaxCode->Text;
sePrechTax->Enabled=false;
FPrechTax=frmPrech_P_I->scPrechTaxCode->ItemData[cbItem2];
if(frmPrech_P_I->scPrechTaxCode->ItemData[cbItem3] == "")
FPrechTaxRate=0;
else
FPrechTaxRate=frmPrech_P_I->scPrechTaxCode->ItemData[cbItem3].ToDouble();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
s_SQL=AnsiString(" Select PodLine,PodGoods,PodUnit,PodConvRate,podQty=PodQty-PodRQty+PodBQty,")
+AnsiString(" PodLoc,PodBatch,PodSo,PodSodLine,PodPrice,PodReqDate,PodRecDate from sdPod where PodCode='"+sePrecdPoCode->Text+"'")
+AnsiString(" and PodClose = 0 and PodQty-PodRQty+PodBQty>0 order by podline");
TComResultSet *RsPrecd;
sgPrecd->RowCount=1;
try
{
StartWaitForm("正在查询数据,请稍候......");
RsPrecd=NewResultSet();
RsPrecd->Open(s_SQL,"");
while( RsPrecd->Eof == 0)
{
double d_PodQty;
d_PodQty=StrToFloat(RsPrecd->FieldByName("PodQty"));
if(d_PodQty > 0)
{
ItemStr="\t"+AnsiString("") +
"\t"+RsPrecd->FieldByName("PodLine")+
"\t"+RsPrecd->FieldByName("PodGoods")+
"\t"+RsPrecd->FieldByName("PodUnit")+
"\t"+RsPrecd->FieldByName("PodConvRate")+
"\t"+RsPrecd->FieldByName("PodQty")+
"\t"+RsPrecd->FieldByName("PodQty")+
"\t"+RsPrecd->FieldByName("PodQty")+
"\t"+RsPrecd->FieldByName("PodLoc")+
"\t"+RsPrecd->FieldByName("PodBatch")+
"\t"+RsPrecd->FieldByName("PodSo")+
"\t"+RsPrecd->FieldByName("PodSodLine")+
"\t"+RsPrecd->FieldByName("PodPrice")+
"\t"+RsPrecd->FieldByName("PodReqDate")+
"\t"+RsPrecd->FieldByName("PodRecDate");
sgPrecd->AddItem(ItemStr);
}
RsPrecd->MoveNext();
}
RsPrecd->Close();
}
__finally
{
EndWaitForm();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::sgPrecdDblClick(TObject *Sender)
{
AnsiString SqlStr;
int ARow=sgPrecd->Row;
if (ARow >0)
{
if(sgPrecd->Col==1)
{
if (sgPrecd->Cells[1][ARow] == "√")
{
sgPrecd->Cells[1][ARow] = "";
for (int i=1;i<sgPrecd->RowCount;i++)
{
if(sgPrecd->Cells[1][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgPrecd->Cells[1][ARow] = "√";
btnOK->Enabled=true;
}
}
else if(sgPrecd->Col==9 && sgPrecd->Cells[1][ARow] == "√")
{
SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";
SqlStr+=" where lgLoccode=loccode and lggoodscode='"+sgPrecd->Cells[3][ARow]+"'";
if(g_sdQuality == false) //无需质量管理
SqlStr+= " and LocType=1 order by locCode";
else //需要质量管理
SqlStr+= " and LocType=3 order by loccode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"货位查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sgPrecd->Cells[9][ARow]=p->ColData[1];
}
delete p;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::sePrecdPoCodeButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="005[采购单号][采购日期][币种][税码][采购员]";
if(cbSameTax->Checked)
{
SqlStr+="select pohcode,pohdate,currencyname,isnull(taxname,''),pohbuyer from sdpoh,sdCurrency,sdtax";
SqlStr+=" where pohcurrency=currencycode and pohtaxcode*=taxcode and pohcheck=1 and pohclose=0 and pohcancel=0 ";
SqlStr+=" and pohsupply='"+FPrechSupply+"' and pohcurrency='"+FPrechCurrency+"' ";
SqlStr+=" and pohtaxCode='"+FPrechTax+"' order by pohcode";
}
else
{
SqlStr+="select pohcode,pohdate,currencyname,isnull(taxname,''),pohbuyer from sdpoh,sdCurrency,sdtax";
SqlStr+=" where pohcurrency=currencycode and pohtaxcode*=taxcode and pohcheck=1 and pohclose=0 and pohcancel=0 ";
SqlStr+=" and pohsupply='"+FPrechSupply+"' and pohcurrency='"+FPrechCurrency+"' ";
SqlStr+=" order by pohcode";
}
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"采购单查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sePrecdPoCode->Text=p->ColData[1];
FillGridWithData();
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::bbSelAllClick(TObject *Sender)
{
if(sgPrecd->RowCount <=1)
return;
for(int i=1;i<sgPrecd->RowCount;i++)
sgPrecd->Cells[1][i] = "√";
btnOK->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::bbSelNoneClick(TObject *Sender)
{
for(int i=1;i<sgPrecd->RowCount;i++)
sgPrecd->Cells[1][i] = "";
btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::sgPrecdSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(sgPrecd->Cells[1][ARow]=="√")
sgPrecd->ReadOnly=false;
else
sgPrecd->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPrecd_P_I::sgPrecdSetEditText(TObject *Sender,
int ACol, int ARow, const AnsiString Value)
{
if(sgPrecd->Cells[1][ARow]=="√")
{
if(ACol == 7)
sgPrecd->Cells[8][ARow]=Value;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -