📄 adjinvd.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "AdjInvd.h"
#include "AdjInvh.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"
TfrmAdjInvd *frmAdjInvd;
//--------------------------------------------------------------------------
__fastcall TfrmAdjInvd::TfrmAdjInvd(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled=false;
}
//--------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::btnOKClick(TObject *Sender)
{
int ErrNum;
try
{
StartWaitForm("正在生成调整单,请稍候......");
if(sgAdjInvd->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmAdjInvh->GetDetailValue(fiAdjInvdLine));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgAdjInvd->RowCount;i++)
{
if(sgAdjInvd->Cells[1][i]=="√")
{
comServer->AddItem();
SetDetailValue(fiAdjInvdCode, frmAdjInvh->seAdjInvhCode->Text);
SetDetailValue(fiAdjInvdLine, AnsiString(j));
SetDetailValue(fiAdjInvdTsCode, seAdjInvdTsCode->Text);
SetDetailValue(fiAdjInvdTsdLine, sgAdjInvd->Cells[2][i]);
SetDetailValue(fiAdjInvdLoc, sgAdjInvd->Cells[3][i]);
SetDetailValue(fiAdjInvdGoods, sgAdjInvd->Cells[4][i]);
SetDetailValue(fiAdjInvdUnit, sgAdjInvd->Cells[6][i]);
if(sgAdjInvd->Cells[9][i] == "")
throw Exception("请输入调整数量");
SetDetailValue(fiAdjInvdQty, sgAdjInvd->Cells[9][i]);
SetDetailValue(fiAdjInvdState,"2");
SetDetailValue(fiAdjInvdDesc, "");
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->Cancel();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::InitControlGroup()
{
sgAdjInvd->RowCount = 1;
seAdjInvhType->Text=frmAdjInvh->scAdjInvhType->Text;
seAdjInvdTsCode->Text="";
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
if(seAdjInvdTsCode->Text == "")
return;
s_SQL =" select TsdLine,TsdLoc,TsdGoods,GoodsName,GoodsUnitCode,Flg=(case TsdFlg when 1 then '盘盈' when -1 then '盘亏' else '盘平' end),TsdDQty,Qty=TsdFlg*TsddQty from sdTsd,sdGoods ";
s_SQL+=" where TsdGoods=GoodsCode and TsdDQty > 0 and TsdCode='"+seAdjInvdTsCode->Text+"' ";
s_SQL+=" order by TsdLine ";
TComResultSet *RsAdjInvd;
sgAdjInvd->RowCount=1;
try
{
StartWaitForm("正在查询数据,请稍候......");
RsAdjInvd=NewResultSet();
RsAdjInvd->Open(s_SQL,"");
while( RsAdjInvd->Eof == 0)
{
ItemStr="\t"+AnsiString("") +
"\t"+RsAdjInvd->FieldByName("TsdLine")+
"\t"+RsAdjInvd->FieldByName("TsdLoc")+
"\t"+RsAdjInvd->FieldByName("TsdGoods")+
"\t"+RsAdjInvd->FieldByName("GoodsName")+
"\t"+RsAdjInvd->FieldByName("GoodsUnitCode")+
"\t"+RsAdjInvd->FieldByName("Flg")+
"\t"+RsAdjInvd->FieldByName("TsdDQty")+
"\t"+RsAdjInvd->FieldByName("Qty");
sgAdjInvd->AddItem(ItemStr);
RsAdjInvd->MoveNext();
}
RsAdjInvd->Close();
delete RsAdjInvd;
}
__finally
{
EndWaitForm();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::sgAdjInvdDblClick(TObject *Sender)
{
AnsiString SqlStr;
int ARow=sgAdjInvd->Row;
if (ARow >0)
{
if(sgAdjInvd->Col==1)
{
if (sgAdjInvd->Cells[1][ARow] == "√")
{
sgAdjInvd->Cells[1][ARow] = "";
for (int i=1;i<sgAdjInvd->RowCount;i++)
{
if(sgAdjInvd->Cells[1][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgAdjInvd->Cells[1][ARow] = "√";
btnOK->Enabled=true;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::seAdjInvdTsCodeButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="004[盘点单号][盘点日期][盘点部门][仓管员]";
SqlStr+=" select TshCode,TshDate,DeptName,UserName from sdTsh,sdDept,sdUser ";
SqlStr+=" where TshDept=DeptCode and TshKeeper=UserCode and TshCheck=1 ";
SqlStr+=" order by TshDate ";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"盘点单据查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seAdjInvdTsCode->Text=p->ColData[1];
FillGridWithData();
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::bbSelAllClick(TObject *Sender)
{
if(sgAdjInvd->RowCount <=1)
return;
for(int i=1;i<sgAdjInvd->RowCount;i++)
sgAdjInvd->Cells[1][i] = "√";
btnOK->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::bbSelNoneClick(TObject *Sender)
{
for(int i=1;i<sgAdjInvd->RowCount;i++)
sgAdjInvd->Cells[1][i] = "";
btnOK->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::sgAdjInvdSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(sgAdjInvd->Cells[1][ARow]=="√")
sgAdjInvd->ReadOnly=false;
else
sgAdjInvd->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjInvd::sgAdjInvdSetEditText(TObject *Sender,
int ACol, int ARow, const AnsiString Value)
{
if(sgAdjInvd->Cells[1][ARow]=="√")
{
if(ACol == 7)
sgAdjInvd->Cells[8][ARow]=Value;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -