gosd.cpp
来自「科思ERP部分源码及控件」· C++ 代码 · 共 437 行 · 第 1/2 页
CPP
437 行
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Gosd.h"
#include "Gosh.h"
#include "wnquery.h"
//--------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmGosd *frmGosd;
//--------------------------------------------------------------------------
__fastcall TfrmGosd::TfrmGosd(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled=false;
}
//--------------------------------------------------------------------------
void __fastcall TfrmGosd::btnOKClick(TObject *Sender)
{
double FPrice,Ftmp,FQty,FAmt,FConv,FIQty;
AnsiString sIUnitCode,l_GoodsSpec,l_batch;
int ErrNum;
try
{
StartWaitForm("正在生成出库单,请稍候......");
if(sgGosd->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmGosh->GetDetailValue("GosdLine"));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgGosd->RowCount;i++)
{
if(sgGosd->Cells[1][i]=="√")
{
comServer->AddItem();
SetDetailValue("GosdCode", frmGosh->seGoshCode->Text); //入库单号
SetDetailValue("GosdLine", AnsiString(j)); //行号
SetDetailValue("GosdFrom", "1"); //行来源
SetDetailValue("GosdFromCode", seGosdFromCode->Text); //来源单号
SetDetailValue("GosdFromLine", sgGosd->Cells[2][i]); //来源行号
SetDetailValue("GosdGoods", sgGosd->Cells[3][i]);
SetDetailValue("GoodsName", sgGosd->Cells[4][i]); //物料编码
if(InitRsGoods(WideString(sgGosd->Cells[3][i])))
{
l_batch=StrToInt(GetGoodsValue(gtInitRs,"GoodsBatch"));
sIUnitCode=GetGoodsValue(gtInitRs,"GoodsUnitCode");
l_GoodsSpec=GetGoodsValue(gtInitRs,"GoodsSpec");
}
else
{
sIUnitCode="";
l_GoodsSpec="";
}
if(Trim(l_GoodsSpec)=="")
l_GoodsSpec=" ";
SetDetailValue("GoodsSpec", l_GoodsSpec);
SetDetailValue("GosdUnit", sIUnitCode);
Ftmp=StrToFloat(sgGosd->Cells[7][i]); //单据未入库数量
if(sgGosd->Cells[8][i] == "")
throw Exception("请输入入库数量");
FQty=StrToFloat(sgGosd->Cells[8][i]); //单据入库数量
if(FQty>Ftmp)
throw Exception("入库数量不能超过未入库数量");
if(sgGosd->Cells[6][i] == "")
throw Exception("缺少单位转换系数");
FConv=StrToFloat(sgGosd->Cells[6][i]); //转换系数
if(sIUnitCode==sgGosd->Cells[5][i])
SetDetailValue("GosdQty", sgGosd->Cells[8][i]); //入库数量
else
{
FIQty=FQty*FConv; //入库数量
SetDetailValue("GosdQty", FloatToStr(FIQty)); //入库数量
}
SetDetailValue("GosdPrice", sgGosd->Cells[13][i]); //入库单价
if(sgGosd->Cells[13][i] == "")
throw Exception("缺少货物单价");
FPrice=StrToFloat(sgGosd->Cells[13][i]); //单价
FAmt=FPrice*FQty;
SetDetailValue("GosdAmt", FloatToStr(FAmt)); //入库金额
SetDetailValue("GosdLoc", sgGosd->Cells[9][i]); //货位
SetDetailValue("GosdState", 1); //行状态
if (l_batch==1&&Trim(sgGosd->Cells[10][i])=="")
throw Exception("物料"+sgGosd->Cells[3][i]+"需批号管理");
SetDetailValue("GosdBatch", sgGosd->Cells[10][i]); //批号
SetDetailValue("GosdSod", sgGosd->Cells[11][i]); //订单号
SetDetailValue("GosdSodLine", sgGosd->Cells[12][i]); //订单行号
SetDetailValue("GosdDesc", " "); //备注
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->FreeItem();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::InitControlGroup()
{
sgGosd->RowCount = 1;
seGoshType->Text=frmGosh->scGoshType->Text;
pv_GoshType=StrToIntDef(frmGosh->scGoshType->ItemData[1],-1);
seGosdFromCode->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
if(seGosdFromCode->Text == "")
return;
switch(pv_GoshType)
{
case 1: //销售发货
s_SQL =" select Line=SogdLine,Goods=SogdGoods,GoodsName,Unit=SogdUnit,Conv=SogdConv,Qty=SogdQty-SogdOQty,";
s_SQL+=" Loc=SogdLoc,Price=SogdPrice,Batch=SogdBatch,So='',SodLine=0 from sdSogd,sdGoods ";
s_SQL+=" where SogdGoods=GoodsCode and SogdClose=0 and SogdCode='"+seGosdFromCode->Text+"' and ";
if(Trim(GetParamValue("10520"))=='Y')
s_SQL+=" SogdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";
s_SQL+=" SogdQty>SogdOQty order by SogdLine";
break;
case 2: //采购退货
s_SQL =" select Line=PretdLine,Goods=PretdGoods,GoodsName,Unit=PretdUnit,Conv=PretdConv,Qty=PretdQty,";
s_SQL+=" Loc=PretdLoc,Price=PretdPrice,Batch=PretdBatch,So=PretdSo,SodLine=PretdSodLine from sdPretd,sdGoods ";
s_SQL+=" where PretdGoods=GoodsCode and PretdClose=0 and PretdCode='"+seGosdFromCode->Text+"' and ";
if(Trim(GetParamValue("10520"))=='Y')
s_SQL+=" PretdLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";
s_SQL+=" PretdQty>0 order by PretdLine";
break;
case 3: //领料
s_SQL =" SELECT Line=GmtdLine,Goods=GmtdGoods,GoodsName,Unit=GmtdUnit,Conv='1',Qty=GmtdQty-GmtdOQty,";
s_SQL+=" Loc=GmtdSLoc,Price=GmtdIPrice,Batch=GmtdBatch,So='',SodLine=0 FROM sdGmtd,sdGoods ";
s_SQL+=" WHERE GmtdGoods=GoodsCode and GmtdCode='"+seGosdFromCode->Text+"' and ";
if(Trim(GetParamValue("10520"))=='Y')
s_SQL+=" GmtdSLoc in(select LrLoc from KsLocRight where LrUser= '"+g_sdUserCode+"') and ";
s_SQL+=" GmtdQty>GmtdOQty order by GmtdLine";
break;
default:
s_SQL ="";
break;
}
if(s_SQL=="")
return;
TComResultSet *RsGosd;
sgGosd->RowCount=1;
try
{
StartWaitForm("正在查询数据,请稍候......");
RsGosd=new TComResultSet(Handle,g_ClientHandle);
RsGosd->Open(s_SQL,"");
while( RsGosd->Eof == 0)
{
ItemStr="\t"+AnsiString("") +
"\t"+RsGosd->FieldByName("Line")+
"\t"+RsGosd->FieldByName("Goods")+
"\t"+RsGosd->FieldByName("GoodsName")+
"\t"+RsGosd->FieldByName("Unit")+
"\t"+RsGosd->FieldByName("Conv")+
"\t"+RsGosd->FieldByName("Qty")+
"\t"+RsGosd->FieldByName("Qty")+
"\t"+RsGosd->FieldByName("Loc")+
"\t"+RsGosd->FieldByName("Batch")+
"\t"+RsGosd->FieldByName("So")+
"\t"+RsGosd->FieldByName("SodLine")+
"\t"+RsGosd->FieldByName("Price");
sgGosd->AddItem(ItemStr);
RsGosd->MoveNext();
}
RsGosd->Close();
}
__finally
{
EndWaitForm();
}
delete RsGosd;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGosd::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?