📄 srgh.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Srgh.h"
#include "srgd.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "GenBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmSrgh *frmSrgh;
//---------------------------------------------------------------------------
__fastcall TfrmSrgh::TfrmSrgh(TComponent* Owner)
: TGenBaseForm(Owner,euSdSrgh,"")
{
AutoCtl=seSrghCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::InitEditControl()
{
ClientGroup->AddComponent(1,false,false,true,fpSrghHead,fpSrghHead->Name);
ClientGroup->AddComponent(1,false,true,false,seSrghCode,seSrghCode->Name);
ClientGroup->AddComponent(1,true,true,true,scSrghUser,scSrghUser->Name);
ClientGroup->AddComponent(1,true,true,true,scSrghFmonth,scSrghFmonth->Name);
ClientGroup->AddComponent(1,false,true,true,scSrghType,scSrghType->Name);
ClientGroup->AddComponent(2,false,false,true,fpSrgdDetail,fpSrgdDetail->Name);
ClientGroup->AddComponent(2,false,true,true,seSrgdSug,seSrgdSug->Name);
ClientGroup->AddComponent(2,true,true,true,seSrgdGoods,seSrgdGoods->Name);
ClientGroup->AddComponent(2,true,true,true,scSrgdUnit,scSrgdUnit->Name);
ClientGroup->AddComponent(2,true,true,true,scSrgdLoc,scSrgdLoc->Name);
ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
//Srgh
FillComboBox(scSrghFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
scSrghType->ClearAll();
scSrghType->AddItems("1-销售备货释放","1");
scSrghType->AddItems("2-生产备货释放","2");
scSrghType->AddItems("3-其它释放","3");
FillComboBox(scSrghUser,"select UserCode,username from sduser order by usercode",
"UserName","UserCode");
FillComboBox(scSrgdUnit,"select UnitCode,UnitName from sdUnit order by UnitCode",
"UnitName","UnitCode");
FillComboBox(scSrgdLoc,"select LocCode,LocName from sdLoc order by LocCode",
"LocName","LocCode");
}
void __fastcall TfrmSrgh::ClearControl(int Section,bool BringToNext)
{
if (Section == 1)
{
if (! BringToNext)
{
seSrghCode->Text=""; //释放单号
deSrghDate->Text=g_sdCurDate; //开单日期
scSrghFmonth->LocateKey(g_sdFMonth); //财务月份
scSrghType->LocateKey("1"); //释放类型
scSrghUser->LocateKey(g_sdUserCode);//操作员
mSrghDesc->Lines->Clear();
cbxSrghCheck->Checked=false; //审核标志
lSrghChecker->Caption=""; //审核人
lSrghCheckDate->Caption=""; //审核日期
lSysDate->Caption=""; //系统日期
//新增单据,工具栏使能
// SetCheckToolbarStatus(false);
}
sgSrgh->RowCount=1;
}
else if (Section==2)
{
if (!BringToNext)
{
seSrgdLine->Text=""; //行号
seSrgdSug->Text=""; //备货单号
seSrgdSugdLine->Text=""; //备货单行号
seSrgdGoods->Text=""; //物料编码
lSrgdGoodsName->Caption=""; //备货物料名称
scSrgdUnit->ItemIndex=0; //计量单位
scSrgdLoc->ItemIndex=0; //货位
seSrgdQty->Text="0"; //释放数量
mSrgdDesc->Lines->Clear(); //备注
}
}
}
void __fastcall TfrmSrgh::GetDataFromComObject(int Section)
{
AnsiString s;
if (Section==1)
{
seSrghCode->Text=GetHeadValue(fiSrghCode); //释放单号
deSrghDate->Text=GetHeadValue(fiSrghDate);; //释放日期
scSrghFmonth->LocateKey(GetHeadValue(fiSrghFmonth)); //财务月份
scSrghType->LocateKey(GetHeadValue(fiSrghType)); //释放类型
scSrghUser->LocateKey(GetHeadValue(fiSrghUser));//操作员
mSrghDesc->Text = GetHeadValue(fiSrghDesc);
lSysDate->Caption = GetHeadValue(fiSrghSysDate);
if(GetHeadValue(fiQcshCheck)=="1")
{
cbxSrghCheck->Checked=true; //审核标志
lSrghChecker->Caption=GetHeadValue(fiSrghChecker); //审核人
lSrghCheckDate->Caption=GetHeadValue(fiSrghCheckDate); //审核日期
SetCheckToolbarStatus(true);
}else
{
cbxSrghCheck->Checked=false; //审核标志
lSrghChecker->Caption=""; //审核人
lSrghCheckDate->Caption=""; //审核日期
SetCheckToolbarStatus(false);
}
}
else
{
seSrgdLine->Text=GetDetailValue(fiSrgdLine); //行号
seSrgdSug->Text=GetDetailValue(fiSrgdSug); //备货单号
seSrgdSugdLine->Text=GetDetailValue(fiSrgdSugdLine); //备货单行号
seSrgdGoods->Text=GetDetailValue(fiSrgdGoods); //物料编码
scSrgdUnit->LocateKey(GetDetailValue(fiSrgdUnit)); //计量单位
scSrgdLoc->LocateKey(GetDetailValue(fiSrgdLoc)); //货位
seSrgdQty->Text=GetDetailValue(fiSrgdQty); //释放数量
mSrgdDesc->Text = GetDetailValue(fiSrghDesc); //备注
}
}
void __fastcall TfrmSrgh::SendDataToComObject(int Section)
{
if (Section==1) // Head
{
SetHeadValue(fiSrghCode,seSrghCode->Text); //释放单号
SetHeadValue(fiSrghDate,deSrghDate->Text); //开单日期
SetHeadValue(fiSrghFmonth,scSrghFmonth->ItemData[0]); //财务月份
SetHeadValue(fiSrghType,scSrghType->ItemData[1]); //释放类型
SetHeadValue(fiSrghUser,scSrghUser->ItemData[1]);//操作员
SetHeadValue(fiSrghDesc,mSrghDesc->Text);
}
else
{
SetDetailValue(fiSrgdLine,seSrgdLine->Text); //行号
SetDetailValue(fiSrgdSug,seSrgdSug->Text); //备货单号
SetDetailValue(fiSrgdSugdLine,seSrgdSugdLine->Text); //备货单行号
SetDetailValue(fiSrgdGoods,seSrgdGoods->Text); //物料编码
SetDetailValue(fiSrgdUnit,scSrgdUnit->ItemData[1]); //计量单位
SetDetailValue(fiSrgdLoc,scSrgdLoc->ItemData[1]); //货位
SetDetailValue(fiSrgdQty,seSrgdQty->Text); //释放数量
SetDetailValue(fiSrgdDesc,mSrgdDesc->Text); //备注
}
}
void __fastcall TfrmSrgh::WaitUserInput(int Section)
{
if (Section ==1)
{
if(seSrghCode->Enabled)
seSrghCode->SetFocus();
else
deSrghDate->SetFocus();
}
else
{
sgSrgh->Visible=false;
fpSrgdDetail->Visible=true;
seSrgdQty->SetFocus();
}
}
void __fastcall TfrmSrgh::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr;
switch(mAction)
{
case 0: // Append
ItemStr=GetDataToGrid();
sgSrgh->AddItem(ItemStr);
break;
case 1: // Modify
i=sgSrgh->Row;
ItemStr=GetDataToGrid();
sgSrgh->ChangeItem(ItemStr,i);
break;
case 2: // Delete
sgSrgh->RemoveItem(sgSrgh->Row);
}
}
void __fastcall TfrmSrgh::DisplayBill()
{
if(comServer->RecordCount==0)
return;
GetDataFromComObject(1); // Head
FillGridWithData();
}
void __fastcall TfrmSrgh::GetBill(AnsiString BillID)
{
int iRow;
iRow=comServer->Find("SrghCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
void __fastcall TfrmSrgh::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgSrgh->RowCount=1;
if(comServer->RecordCount > 0)
for (i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0); // Append
}
}
void __fastcall TfrmSrgh::ChangeToBrowseState(bool Browse)
{
sgSrgh->Visible=true;
fpSrgdDetail->Visible=false;
if(Browse==false)
sgSrgh->SetFocus();
}
void __fastcall TfrmSrgh::GenrateBill()
{
int TempCount;
TempCount = comServer->ItemCount;
// SetControlState(caAddBill);
StartWaitForm("正在启动生成界面");
TfrmSrgd *p=new TfrmSrgd(this);
try
{
p->GetComObject(comServer);
EndWaitForm();
p->ShowModal();
if (TempCount < comServer->ItemCount)
TGenBaseForm::tbSaveClick(NULL);
else
CancelChange();
}
__finally
{
delete p;
}
}
AnsiString __fastcall TfrmSrgh::GetDataToGrid()
{
AnsiString ItemStr;
ItemStr="\t"+GetDetailValue(fiSrgdLine)+
"\t"+GetDetailValue(fiSrgdSug)+
"\t"+GetDetailValue(fiSrgdSugdLine)+
"\t"+GetDetailValue(fiSrgdGoods)+
"\t"+GetDetailValue(fiSrgdUnit)+
"\t"+GetDetailValue(fiSrgdLoc)+
"\t"+GetDetailValue(fiSrgdQty);
return ItemStr;
}
AnsiString __fastcall TfrmSrgh::GetDetailValue(int FieldIndex)
{
return ReadItemValue(comServer,FieldIndex);
}
AnsiString __fastcall TfrmSrgh::GetHeadValue(int Index)
{
return ReadFieldValue(comServer,Index);
}
void __fastcall TfrmSrgh::SetHeadValue(int Index ,AnsiString Value)
{
WriteFieldValue(comServer,Index,Value);
}
void __fastcall TfrmSrgh::SetDetailValue(int Index, AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
void __fastcall TfrmSrgh::RefreshUpdateData(int MsgSrc,int MsgType)
{
switch(MsgSrc)
{
case euSdFc:
{
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scSrghFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
break;
}
case euSdUser:
{
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scSrghUser,"select UserCode,username from sduser order by usercode",
"UserName","UserCode");
break;
}
case euSdUnit:
{
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scSrgdUnit,"select UnitCode,UnitName from sdUnit order by UnitCode",
"UnitName","UnitCode");
break;
}
case euSdLoc:
{
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scSrgdLoc,"select LocCode,LocName from sdLoc order by LocCode",
"LocName","LocCode");
break;
}
default:
break;
}
}
void __fastcall TfrmSrgh::seSrgdSugButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="007[备货单号][行号][物料编码][物料名称][货位][计量单位][备货数量]";
SqlStr+= " select SughCode,SugdLine,SugdGoods,GoodsName,SugdLoc,SugdUnit,SugdQty ";
SqlStr+= " from sdsugh ";
SqlStr+= " right outer join sdSugd on SughCode=SugdCode ";
SqlStr+= " left outer join sdGoods on SugdGoods=GoodsCode ";
SqlStr+= " where SughCheck=1 and SughType="+scSrghType->ItemData[1];
SqlStr+= " order by SughCode,SugdLine ";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"系统用户查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seSrgdSug->Text = p->ColData[1];
seSrgdSugdLine->Text = p->ColData[2];
seSrgdGoods->Text = p->ColData[3];
scSrgdLoc->LocateKey(p->ColData[5]);
scSrgdUnit->LocateKey(p->ColData[6]);
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::seSrgdGoodsChange(TObject *Sender)
{
int GoodsFound=g_sdRsGoods->LocateByKey(WideString(seSrgdGoods->Text));
if(GoodsFound == 0)
lSrgdGoodsName->Caption=GetGoodsValue("GoodsName");
else
lSrgdGoodsName->Caption=""; //备货物料名称
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::FormShow(TObject *Sender)
{
// InitEditControl();
ClearControl(1,false); // Head
ClearControl(2,false); // Detail
ChangeToBrowseState();
MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::FormClose(TObject *Sender, TCloseAction &Action)
{
TGenBaseForm::FormClose(Sender,Action);
WriteGridWidth(Name,sgSrgh,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::FormCreate(TObject *Sender)
{
FormIniFile="D:\Test.Ini";
SetGridWidth(Name,sgSrgh,FormIniFile);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::btnOKClick(TObject *Sender)
{
TGenBaseForm::tbSaveClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::btnCancelClick(TObject *Sender)
{
TGenBaseForm::muCancelClick(Sender);
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::sgSrghDblClick(TObject *Sender)
{
int iRow;
iRow=sgSrgh->Row;
if (iRow == 0)
{
return;
}
sgSrgh->Visible=false;
fpSrgdDetail->Visible=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::sgSrghSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
{
comServer->LocateItemByKey(WideString(sgSrgh->TextMatrix[ARow][1]));
}
if (!comServer->Eof)
{
GetDataFromComObject(2); // Detail
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmSrgh::seSrghCodeExit(TObject *Sender)
{
if(CurrentState==caNormal && seSrghCode->Text != GetHeadValue(fiSrghCode))
{
comServer->LocateByKey(WideString(seSrghCode->Text));
DisplayBill();
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -