📄 rpod.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Rpod.h"
#include "Rpoh.h"
//--------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma link "DateEdit"
#pragma resource "*.dfm"
TfrmRpod *frmRpod;
//--------------------------------------------------------------------------
__fastcall TfrmRpod::TfrmRpod(TComponent* Owner)
: TStdBaseForm(Owner)
{
btnOK->Enabled = false;
}
//--------------------------------------------------------------------------
void __fastcall TfrmRpod::btnOKClick(TObject *Sender)
{
AnsiString sMemo;
int ErrNum;
try
{
StartWaitForm("正在生成收货单,请稍候......");
if(sgRpod->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(GetDetailValue(fiRpodLine));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgRpod->RowCount;i++)
{
if(sgRpod->Cells[1][i]=="√")
{
try
{
StrToFloat(sgRpod->Cells[7][i]);
}
catch(...)
{
if(::MessageBox(Handle,"请购数量填写错误,选择'确定'继续执行,选择'取消'中断执行","错误提示",MB_OKCANCEL|MB_ICONSTOP)==IDOK)
continue;
else
return;
}
comServer->AddItem();
SetDetailValue(fiRpodLine,IntToStr(j)); //请购单行号
SetDetailValue(fiRpodCode,frmRpoh->seRpohCode->Text); //请购单号
SetDetailValue(fiRpodGoodsCode,sgRpod->Cells[3][i]); //货物名称
SetDetailValue(fiRpodUnitCode,sgRpod->Cells[5][i]); //采购单位
SetDetailValue(fiRpodConvRate,"1"); //换算比率
SetDetailValue(fiRpodFrom,"2"); //需求来源
if(sgRpod->Cells[8][i] == "")
throw Exception("请输入请购数量");
SetDetailValue(fiRpodQty,sgRpod->Cells[8][i]); //请购数量
SetDetailValue(fiRpodPrice,"0.00"); //单价
SetDetailValue(fiRpodAmt,"0.00"); //金额
SetDetailValue(fiRpodStatus,"2"); //行状态
SetDetailValue(fiRpodPQty,"0"); //生成数量
SetDetailValue(fiRpodReqDate,sgRpod->Cells[2][i]); //需求日期
SetDetailValue(fiRpodRecDate,sgRpod->Cells[2][i]); //交货日期
SetDetailValue(fiRpodLocCode,""); //入库货位
SetDetailValue(fiRpodDept,""); //需求部门
SetDetailValue(fiRpodDesc,""); //备注
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->Cancel();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::FormShow(TObject *Sender)
{
InitControlGroup();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::InitControlGroup()
{
sgRpod->RowCount = 1;
FSupplyCode=frmRpoh->scRpohSupplyCode->ItemData[1];
seRpohSupply->Text=frmRpoh->scRpohSupplyCode->ItemData[0];
seRpohSupply->Enabled=false;
deEndDate->Text="";
seRpohGoods->Text="";
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRpod::GetSqlString()
{
AnsiString s_SQL,s_Temp;
s_SQL =" Select BplanRDate,BplanGoods,GoodsName,BplanUnit,BplanQty,BplanRQty,DQty=BplanQty-BplanRQty ";
s_SQL+=" from sdBplan,sdGoods,sdPgd ";
s_SQL+=" where BplanGoods=GoodsCode and BplanGoods=PgdGoodsCode and BplanCheck=1 and BplanQty>BplanRQty ";
s_SQL+=" and PgdSupplyCode='"+FSupplyCode+"' ";
s_Temp="";
if(seRpohGoods->Text != "")
s_Temp+=" and BplanGoods ='"+seRpohGoods->Text+"'";
if(deBegDate->Text != "")
s_Temp+=" and BplanRDate >='"+deBegDate->Text+"'";
if(deEndDate->Text != "")
s_Temp+=" and BplanRDate <='"+deEndDate->Text+"'";
s_SQL+=s_Temp;
return(s_SQL);
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
s_SQL =GetSqlString();
sgRpod->RowCount=1;
TComResultSet *RsRpod;
RsRpod=NewResultSet();
RsRpod->Open(s_SQL,"");
while( RsRpod->Eof == 0)
{
ItemStr = "\t"+AnsiString("") +
"\t"+RsRpod->FieldByName("BplanRDate")+
"\t"+RsRpod->FieldByName("BplanGoods")+
"\t"+RsRpod->FieldByName("GoodsName")+
"\t"+RsRpod->FieldByName("BplanUnit")+
"\t"+RsRpod->FieldByName("BplanQty")+
"\t"+RsRpod->FieldByName("BplanRQty")+
"\t"+RsRpod->FieldByName("DQty");
sgRpod->AddItem(ItemStr);
RsRpod->MoveNext();
}
RsRpod->Close();
delete RsRpod;
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRpod::GetDetailValue(int Index)
{
return ReadItemValue(comServer,Index);
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::sgRpodDblClick(TObject *Sender)
{
int ARow=sgRpod->Row;
int ACol=sgRpod->Col;
if (ARow > 0 && ACol == 1)
{
if (sgRpod->Cells[1][ARow] == "√")
{
sgRpod->Cells[1][ARow] = "";
for (int i=1;i<sgRpod->RowCount;i++)
{
if(sgRpod->Cells[1][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgRpod->Cells[1][ARow] = "√";
btnOK->Enabled = true;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::bbQueryClick(TObject *Sender)
{
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::bbAllClick(TObject *Sender)
{
if(sgRpod->RowCount <=1)
return;
for(int i=1;i<sgRpod->RowCount;i++)
sgRpod->Cells[1][i] = "√";
btnOK->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::bbNoneClick(TObject *Sender)
{
for(int i=1;i<sgRpod->RowCount;i++)
sgRpod->Cells[1][i] = " ";
btnOK->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::seRpohGoodsButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="004[物料编码][物料名称][供应商物料代码][供应商物料名称]";
SqlStr+=" select PgdGoodsCode,GoodsName,PgdCode,PgdName from sdpgd,sdGoods ";
SqlStr+=" where PgdGoodsCode=GoodsCode and PgdSupplyCode='"+FSupplyCode+"' order by GoodsCode ";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"供应商物料查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seRpohGoods->Text=p->ColData[1];
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::seRpohGoodsExit(TObject *Sender)
{
int Founded;
Founded=g_sdRsGoods->LocateByKey(WideString(Trim(seRpohGoods->Text)));
if(Founded ==0)
seRpohGoods->Text=GetGoodsValue("GoodsCode");
else
seRpohGoods->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmRpod::sgRpodSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(sgRpod->Cells[1][ARow]=="√")
sgRpod->ReadOnly=false;
else
sgRpod->ReadOnly=true;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -