📄 mpc.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Mpc.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "RecBaseForm"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmMpc *frmMpc;
//---------------------------------------------------------------------------
__fastcall TfrmMpc::TfrmMpc(TComponent* Owner)
: TRecBaseForm(Owner,euSdMpc,"")
{
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmMpc::GetFieldValue(int iFieldIndex)
{
return ReadFieldValue(comServer,iFieldIndex);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::SetFieldValue(int iFieldIndex,AnsiString sFieldValue)
{
WriteFieldValue(comServer,iFieldIndex,sFieldValue);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmMpc::GetDataToGrid()
{
AnsiString s;
s = GetFieldValue(fiMpcGoods)+
"\t" + GetFieldValue(fiMpcQty);
return (s);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::InitEditControl()
{
ClientGroup->AddComponent(2,false,false,true, fpMpc,fpMpc->Name);
ClientGroup->AddComponent(2,true,true,false, sgMpc,sgMpc->Name);
ClientGroup->AddComponent(2,true,true,true, seMpcGoodsName,seMpcGoodsName->Name);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::ClearControl(bool BringToNext)
{
if(!BringToNext)
EmptyAll(fpMpc);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::WaitUserInput()
{
if(seMpcGoods->Enabled)
seMpcGoods->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::GetDataFromComObject()
{
AnsiString tempS = GetFieldValue(fiMpcGoods);
seMpcGoods->Text = tempS;
//MoveFirst,MovePrority,MoveNext,MoveLast
sgMpc->LocateGrid(0,tempS);
if(g_sdRsGoods->LocateByKey(WideString(tempS))==0)
seMpcGoodsName->Text=GetGoodsValue("GoodsName");
seMpcQty->Text=GetFieldValue(fiMpcQty);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::SendDataToComObject()
{
SetFieldValue(fiMpcGoods,seMpcGoods->Text);
SetFieldValue(fiMpcQty,seMpcQty->Text);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::RefreshGridData(int mAction)
{
AnsiString sGridItem;
sGridItem=GetDataToGrid();
int i;
switch(mAction)
{
case 0: //新增
sgMpc->AddItem(sGridItem);
sgMpc->Row=sgMpc->RowCount-1;
break;
case 1: //修改
sgMpc->ChangeItem(sGridItem,sgMpc->Row);
break;
case 2: //删除
sgMpc->RemoveItem(sgMpc->Row);
} ;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::FillGridWithData()
{
AnsiString ItemStr;
comServer->MoveFirst();
sgMpc->RowCount = 1;
while (comServer->Eof == 0)
{
ItemStr = GetDataToGrid();
sgMpc->AddItem(ItemStr);
comServer->MoveNext();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::FormShow(TObject *Sender)
{
if(comServer->RecordCount>0)
{
FillGridWithData();
comServer->MoveFirst();
GetDataFromComObject();
}
else
{
ClearControl(false);
sgMpc->RowCount=1;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::FormClose(TObject *Sender,
TCloseAction &Action)
{
TRecBaseForm::FormClose(Sender,Action);
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::sgMpcClick(TObject *Sender)
{
int ARow;
ARow=sgMpc->Row;
if(ARow > 0)
comServer->LocateByKey(WideString(sgMpc->TextMatrix[ARow][0]));
if(!comServer->Eof)
GetDataFromComObject();
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::seMpcGoodsButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="004[产品编码][产品名称][计量单位][批量]";
SqlStr+="Select GoodsCode,GoodsName,GoodsUnitCode,GoodsEoq from sdGoods where (GoodsType=1 or GoodsType=2) and GoodsFrom=2 order by GoodsCode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"产品数据查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seMpcGoods->Text=p->ColData[1];
seMpcGoodsName->Text = p->ColData[2];
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmMpc::seMpcGoodsExit(TObject *Sender)
{
AnsiString tempGoods;
tempGoods=seMpcGoods->Text;
if(!tempGoods.IsEmpty())
{
if(g_sdRsGoods->LocateByKey(WideString(tempGoods))==0)
seMpcGoodsName->Text=GetGoodsValue("GoodsName");
else
ShowMessage("录入的产品编码:'"+tempGoods+"'不存在!");
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -