rwt.cpp
来自「一个以前收集的基于C/S架构的ERP客户端源代码」· C++ 代码 · 共 286 行
CPP
286 行
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Rwt.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "RecBaseForm"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "DateEdit"
#pragma resource "*.dfm"
TfrmRwt *frmRwt;
//---------------------------------------------------------------------------
__fastcall TfrmRwt::TfrmRwt(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
: TRecBaseForm(Owner,chWnd,MidCode,WhereStr)
{
// g_sdRsGoods =new TComResultSet(Handle,g_ClientHandle);
// g_sdRsGoods->Open("select * from sdgoods order by goodscode","GoodsCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::InitEditControl()
{
ClientGroup->AddComponent(2,true,true,false, sgRwt,sgRwt->Name);
ClientGroup->AddComponent(2,true,true,false, scRwtLoc,scRwtLoc->Name);
ClientGroup->AddComponent(2,false,false,true, FloatPanel1,FloatPanel1->Name);
// ClientGroup->AddComponent(2,true,false,true, deRwtIdate,deRwtIdate->Name);
ClientGroup->AddComponent(2,true,true,true,scRwtUnit,scRwtUnit->Name);
ClientGroup->AddComponent(2,true,true,true,scRwtUser,scRwtUser->Name);
FillComboBox(Query,scRwtLoc,"select LocCode,locname from sdLoc order by LocCode","LocCode","Locname");
FillComboBox(Query,scRwtUser,"select UserCode,UserName from sdUser order By UserCode","UserName","UserCode");
FillComboBox(Query,scRwtUnit,"SELECT UnitCode,Unitname FROM sdUnit","UnitName","UnitCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::ClearControl(bool BringToNext)
{
if(!BringToNext)
{
seRwtGoods->Text="";
seRwtGoodsName->Text="";
seRwtTime->Text ="0";
scRwtUnit->Text ="";
deRwtEdate->Text=g_sdCurDate;
deRwtIdate->Text="";
// scRwtUser->LocateKey(g_sdUserCode);
scRwtUser->Text=g_sdUserCode;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::GetDataFromComObject()
{
// g_sdRsGoods->LocateByKey(GetFieldValue("RwtGoods"));
seRwtGoods->Text=GetFieldValue("RwtGoods");
sgRwt->LocateGrid(1,seRwtGoods->Text);
if(!InitRsGoods(WideString(Trim(seRwtGoods->Text)))) //输入无效编码
{
seRwtGoodsName->Text="";//////
}
else
{
seRwtGoodsName->Text=GetGoodsValue(gtInitRs,"GoodsName");//////
}
scRwtUnit->LocateKey(GetFieldValue("RwtUnit"));
scRwtUnit->Text=scRwtUnit->ItemData[0];
seRwtTime->Text = GetFieldValue("RwtTime");
deRwtEdate->Text = GetFieldValue("RwtEdate");
deRwtIdate->Text = GetFieldValue("RwtIdate");
// scRwtUser->LocateKey(GetFieldValue("RwtUser"));
// scRwtUser->Text = scRwtUser->ItemData[0];
scRwtUser->Text = GetFieldValue("RwtUser");
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::SendDataToComObject()
{
if(deRwtIdate->Text.IsEmpty())
throw Exception("失效日期不能为空");
if(deRwtEdate->Text.IsEmpty())
throw Exception("生效日期不能为空");
SetFieldValue("RwtGoods",seRwtGoods->Text);
SetFieldValue("RwtLoc",scRwtLoc->Text);
SetFieldValue("RwtTime",seRwtTime->Text);
SetFieldValue("RwtUnit",scRwtUnit->ItemData[1]);
SetFieldValue("RwtEdate",deRwtEdate->Text);
SetFieldValue("RwtIdate",deRwtIdate->Text);
// SetFieldValue("RwtUser",scRwtUser->ItemData[1]);
SetFieldValue("RwtUser",scRwtUser->Text);
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::WaitUserInput()
{
seRwtGoods->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmRwt::GetDataToGrid()
{
scRwtUnit->LocateKey(GetFieldValue("RwtUnit"));
AnsiString s;
s = "\t" +GetFieldValue("RwtGoods")+
"\t" + scRwtUnit->ItemData[0]+
"\t" + GetFieldValue("RwtTime");
return(s);
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::RefreshGridData(int mAction)
{
AnsiString ItemStr;
ItemStr = GetDataToGrid();
// 新增
if (mAction == 0)
{
sgRwt->AddItem(ItemStr);
}
// 修改
else if(mAction == 1)
{
int i = sgRwt->Row;
sgRwt->RemoveItem(i);
sgRwt->AddItem(ItemStr,i);
}
// 删除 0
else if(mAction == 2)
{
sgRwt->RemoveItem(sgRwt->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::FillGridWithData()
{
AnsiString ItemStr;
comServer->MoveFirst();
sgRwt->RowCount = 1;
while(comServer->Eof == 0)
{
ItemStr=GetDataToGrid();
sgRwt->AddItem(ItemStr);
comServer->MoveNext();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::scRwtLocClick(TObject *Sender)
{
AnsiString s;
s = scRwtLoc->Text;
if(s.IsEmpty())
return;
if(LastRwtLoc==s)
return;
LastRwtLoc=s;
if(scRwtLoc->ItemIndex==-1)
{
MessageDlg("货位代码 "+scRwtLoc->Text+"不存在",mtWarning,TMsgDlgButtons()<<mbOK,0);
scRwtLoc->LocateKey(LastRwtLoc);
}
else
{
scRwtLoc->LocateKey(scRwtLoc->Text);
seRwtLocName->Text=scRwtLoc->ItemData[1];
s = " RwtLoc = '" + s + "'";
comServer->FilterString = s;
comServer->Query();
FillGridWithData();
comServer->MoveFirst();
GetDataFromComObject();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::seRwtGoodsButtonClick(TObject *Sender)
{
AnsiString SqlStr;
TfrmWnQuery *p;
SqlStr="003[物料编码][物料名称][计量单位]SELECT goodscode,goodsname,goodsunitcode FROM sdGoods ,sdlg " ;
SqlStr+=" where ( goodstype='1' or goodstype='2') and GOODSCODE=LGGOODSCODE and LGLOCCODE='"+scRwtLoc->Text+"' order by goodscode";
try{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"物料查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seRwtGoods->Text=p->ColData[1];
seRwtGoodsName->Text=p->ColData[2];
scRwtUnit->LocateKey(p->ColData[3]);
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::RefreshUpdateData(int MsgSrc,int MsgType)
{
/* switch(MsgSrc)
{
case euSdLoc:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(Query,scRwtLoc,"select LocCode,locname from sdLoc order by LocCode","LocCode","Locname");
break;
case euSdUser:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(Query,scRwtUser,"select UserCode,UserName from sdUser order By UserCode","UserName","UserCode");
break;
case euSdUnit:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(Query,scRwtUnit,"SELECT UnitCode,Unitname FROM sdUnit","UnitName","UnitCode");
break;
default:
break;
}*/
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::seRwtGoodsKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13)
{
TComResultSet *TResultSet=new TComResultSet(Handle,g_ClientHandle);
AnsiString strSQL;
strSQL="SELECT * FROM sdGoods ,sdlg where ( goodstype='1' or goodstype='2') and GOODSCODE=LGGOODSCODE and GOODSCODE='"+seRwtGoods->Text+"' and LGLOCCODE='"+scRwtLoc->Text+"'";
TResultSet->Close();
try
{
TResultSet->Open(strSQL,"");
if(TResultSet->RecordCount<1)
throw Exception("物料"+seRwtGoods->Text+"'不存在、不在该货位或不是成品、半成品");
seRwtGoodsName->Text=TResultSet->FieldByName("GoodsName");
scRwtUnit->LocateKey(TResultSet->FieldByName("GoodsUnitCode"));
TResultSet->Close();
}
__finally
{
delete TResultSet;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::sgRwtClick(TObject *Sender)
{
if (sgRwt->Row > 0)
{
comServer->LocateByKey(scRwtLoc->Text+"\t"+sgRwt->TextMatrix[sgRwt->Row][1]+"\t");
if (!comServer->Eof)
GetDataFromComObject();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::FormShow(TObject *Sender)
{
scRwtLoc->LocateKey(scRwtLoc->Text);
seRwtLocName->Text=scRwtLoc->ItemData[1];
comServer->FilterString = " RwtLoc = '" + scRwtLoc->Text + "'";
comServer->Query();
FillGridWithData();
comServer->MoveFirst();
GetDataFromComObject();
}
//---------------------------------------------------------------------------
void __fastcall TfrmRwt::FormClose(TObject *Sender, TCloseAction &Action)
{
// delete g_sdRsGoods;
TRecBaseForm::FormClose(Sender,Action);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?