📄 pisd.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Pisd.h"
#include "Pish.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"
TfrmPisd *frmPisd;
//--------------------------------------------------------------------------
__fastcall TfrmPisd::TfrmPisd(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled=false;
}
//--------------------------------------------------------------------------
void __fastcall TfrmPisd::btnOKClick(TObject *Sender)
{
double FPrice,Ftmp,FQty,FAmt,FConv,FIQty;
AnsiString sIUnitCode;
int ErrNum;
try
{
StartWaitForm("正在生成入库单,请稍候......");
if(sgPisd->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmPish->GetDetailValue(fiPisdLine));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgPisd->RowCount;i++)
{
if(sgPisd->Cells[1][i]=="√")
{
comServer->AddItem();
SetDetailValue(fiPisdCode, frmPish->sePishCode->Text); //入库单号
SetDetailValue(fiPisdLine, AnsiString(j)); //行号
SetDetailValue(fiPisdFrom, "1"); //行来源
SetDetailValue(fiPisdFromCode, sePisdFromCode->Text); //来源单号
SetDetailValue(fiPisdFromLine, sgPisd->Cells[2][i]); //来源行号
SetDetailValue(fiPisdGoods, sgPisd->Cells[3][i]); //物料编码
if(g_sdRsGoods->LocateByKey(WideString(sgPisd->Cells[3][i]))==0)
sIUnitCode=GetGoodsValue("GoodsUnitCode");
else
sIUnitCode="";
Ftmp=StrToFloat(sgPisd->Cells[7][i]); //单据未入库数量
if(sgPisd->Cells[8][i] == "")
throw Exception("请输入入库数量");
FQty=StrToFloat(sgPisd->Cells[8][i]); //单据入库数量
if(FQty>Ftmp)
throw Exception("入库数量不能超过未入库数量");
if(sgPisd->Cells[6][i] == "")
throw Exception("缺少单位转换系数");
FConv=StrToFloat(sgPisd->Cells[6][i]); //转换系数
if(sIUnitCode==sgPisd->Cells[5][i])
SetDetailValue(fiPisdQty, sgPisd->Cells[8][i]); //入库数量
else
{
FIQty=FQty*FConv; //入库数量
SetDetailValue(fiPisdQty, FloatToStr(FIQty)); //入库数量
}
SetDetailValue(fiPisdPrice, sgPisd->Cells[13][i]); //入库单价
if(sgPisd->Cells[13][i] == "")
throw Exception("缺少货物单价");
FPrice=StrToFloat(sgPisd->Cells[13][i]); //单价
FAmt=FPrice*FQty;
SetDetailValue(fiPisdAmt, FloatToStr(FAmt)); //入库金额
SetDetailValue(fiPisdLoc, sgPisd->Cells[9][i]); //货位
// SetDetailValue(fiPisdState, sgPisd->Cells[][i]); //行状态
SetDetailValue(fiPisdBatch, sgPisd->Cells[10][i]); //批号
SetDetailValue(fiPisdSod, sgPisd->Cells[11][i]); //订单号
SetDetailValue(fiPisdSodLine, sgPisd->Cells[12][i]); //订单行号
// SetDetailValue(fiPisdDesc, sgPisd->Cells[][i]); //备注
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->Cancel();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::InitControlGroup()
{
sgPisd->RowCount = 1;
sePishType->Text=frmPish->scPishType->Text;
pv_PishType=StrToIntDef(frmPish->scPishType->ItemData[1],-1);
sePisdFromCode->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
if(sePisdFromCode->Text == "")
return;
switch(pv_PishType)
{
case 1: //采购收货
s_SQL =" select Line=PrecdLine,Goods=PrecdGoods,GoodsName,Unit=PrecdUnit,Conv=PrecdConv,Qty=PrecdQty-PrecdIQty,";
s_SQL+=" Loc=PrecdLoc,Price=PrecdPrice,Batch=PrecdBatch,So=PrecdSo,SodLine=PrecdSodLine from sdPrecd,sdGoods ";
s_SQL+=" where PrecdGoods=GoodsCode and PrecdClose=0 and PrecdCode='"+sePisdFromCode->Text+"' and ";
s_SQL+=" PrecdQty>PrecdIQty order by PrecdLine";
break;
case 2: //生产入库
s_SQL ="";
break;
case 3: //销售退货
s_SQL =" select Line=SretdLine,Goods=SretdGoods,GoodsName,Unit=SretdUnit,Conv=SretdConv,Qty=SretdQty-SretdOQty,";
s_SQL+=" Loc=SretdLoc,Price=SretdPrice,Batch=SretdBatch,So='',SodLine=0 from sdSretd,sdGoods ";
s_SQL+=" where SretdGoods=GoodsCode and SretdClose=0 and SretdCode='"+sePisdFromCode->Text+"' and ";
s_SQL+=" SretdQty>SretdOQty order by SretdLine";
break;
case 4: //退料
s_SQL ="";
break;
default:
s_SQL ="";
break;
}
if(s_SQL=="")
return;
TComResultSet *RsPisd;
sgPisd->RowCount=1;
try
{
StartWaitForm("正在查询数据,请稍候......");
RsPisd=NewResultSet();
RsPisd->Open(s_SQL,"");
while( RsPisd->Eof == 0)
{
ItemStr="\t"+AnsiString("") +
"\t"+RsPisd->FieldByName("Line")+
"\t"+RsPisd->FieldByName("Goods")+
"\t"+RsPisd->FieldByName("GoodsName")+
"\t"+RsPisd->FieldByName("Unit")+
"\t"+RsPisd->FieldByName("Conv")+
"\t"+RsPisd->FieldByName("Qty")+
"\t"+RsPisd->FieldByName("Qty")+
"\t"+RsPisd->FieldByName("Loc")+
"\t"+RsPisd->FieldByName("Batch")+
"\t"+RsPisd->FieldByName("So")+
"\t"+RsPisd->FieldByName("SodLine")+
"\t"+RsPisd->FieldByName("Price");
sgPisd->AddItem(ItemStr);
RsPisd->MoveNext();
}
RsPisd->Close();
}
__finally
{
EndWaitForm();
}
delete RsPisd;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::sgPisdDblClick(TObject *Sender)
{
AnsiString SqlStr;
int ARow=sgPisd->Row;
if (ARow >0)
{
if(sgPisd->Col==1)
{
if (sgPisd->Cells[1][ARow] == "√")
{
sgPisd->Cells[1][ARow] = "";
for (int i=1;i<sgPisd->RowCount;i++)
{
if(sgPisd->Cells[1][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgPisd->Cells[1][ARow] = "√";
btnOK->Enabled=true;
}
}
else if(sgPisd->Col==9 && sgPisd->Cells[1][ARow] == "√")
{
SqlStr="002[货位代码][货位名称]select loccode,locname from sdLoc,sdlg ";
SqlStr+=" where lgLoccode=loccode and lggoodscode='"+sgPisd->Cells[3][ARow]+"'";
SqlStr+=" and LocType=1 order by locCode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"货位查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sgPisd->Cells[9][ARow]=p->ColData[1];
}
delete p;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::sePisdFromCodeButtonClick(TObject *Sender)
{
AnsiString SqlStr;
switch(pv_PishType)
{
case 1: //采购收货
SqlStr="006[采购收货单][收货日期][供应商][币种][税码][操作员]";
SqlStr+="select PrechCode,PrechDate,SupplyName,CurrencyName,isnull(TaxName,''),PrechUser from sdPrech,sdSupply,sdCurrency,sdTax";
SqlStr+=" where Prechcurrency=currencycode and Prechtaxcode*=taxcode and Prechcheck=1 and Prechclose=0 and Prechcancel=0 ";
SqlStr+=" and PrechSupply=SupplyCode order by Prechcode";
break;
case 2: //生产入库
SqlStr="";
break;
case 3: //销售退货
SqlStr="006[销售退货单][退货日期][客户][币种][税码][操作员]";
SqlStr+="select SrethCode,SrethDate,ClientName,CurrencyName,isnull(TaxName,''),SrethUser from sdSreth,sdClient,sdCurrency,sdTax";
SqlStr+=" where Srethcurrency=currencycode and Srethtaxcode*=taxcode and Srethcheck=1 and Srethclose=0 and Srethcancel=0 ";
SqlStr+=" and SrethClient=ClientCode order by Srethcode";
break;
case 4: //退料
SqlStr="";
break;
default:
SqlStr="";
break;
}
if(SqlStr=="")
return;
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"入库来源单据查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sePisdFromCode->Text=p->ColData[1];
FillGridWithData();
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::bbSelAllClick(TObject *Sender)
{
if(sgPisd->RowCount <=1)
return;
for(int i=1;i<sgPisd->RowCount;i++)
sgPisd->Cells[1][i] = "√";
btnOK->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::bbSelNoneClick(TObject *Sender)
{
for(int i=1;i<sgPisd->RowCount;i++)
sgPisd->Cells[1][i] = "";
btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::sgPisdSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(sgPisd->Cells[1][ARow]=="√")
sgPisd->ReadOnly=false;
else
sgPisd->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPisd::sgPisdSetEditText(TObject *Sender,
int ACol, int ARow, const AnsiString Value)
{
if(sgPisd->Cells[1][ARow]=="√")
{
if(ACol == 7)
sgPisd->Cells[8][ARow]=Value;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -