📄 scmbh.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Scmbh.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "BillBaseForm"
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmScmbh *frmScmbh;
//---------------------------------------------------------------------------
__fastcall TfrmScmbh::TfrmScmbh(TComponent* Owner)
: TBillBaseForm(Owner, euSdScmbh,"")
{
AutoCtl=seScmbhCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::InitEditControl()
{
ClientGroup->AddComponent(1,false,false,true,fpScmbhHead,fpScmbhHead->Name);
ClientGroup->AddComponent(2,false,false,true,fpScmbhDetail,fpScmbhDetail->Name);
ClientGroup->AddComponent(2,false,false,false,btnCancel,btnCancel->Name);
ClientGroup->AddComponent(2,false,true,true,btnOK,btnOK->Name);
ClientGroup->AddComponent(2,true,true,true,scScmbdGoodsUnit,scScmbdGoodsUnit->Name);
ClientGroup->AddComponent(1,false,true,false,seScmbhCode,seScmbhCode->Name);
ClientGroup->AddComponent(1,true,true,true,scScmbhFmonth,scScmbhFmonth->Name);
//h
FillComboBox(scScmbhFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
//d
FillComboBox(scScmbdGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::ClearControl(int Section,bool BringToNext)
{
if (Section == 1)
{
if (!BringToNext)
{
seScmbhCode->Text ="";
deScmbhDate->Text =g_sdCurDate;
scScmbhFmonth->Text =g_sdCMonth;
seScmbhDesc->Text ="";
labScmbhSysDate->Caption ="";
chkScmbhCheck->Checked =false;
labScmbhChecker->Caption ="";
labScmbhCheckDate->Caption="";
labScmbhUser->Caption =g_sdUserCode;
}
sgScmbh->RowCount=1;
}
else if (Section==2)
{
if (!BringToNext)
{
seScmbdLine->Text =AnsiString(comServer->ItemCount+1);
seScmbdGoods->Text ="";
seScmbdOCost->Text ="";
seScmbdNCost->Text ="";
memScmbdDesc->Text ="";
seScmbdGoodsName->Text ="";
scScmbdGoodsUnit->Text ="";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::GetDataFromComObject(int Section)
{
AnsiString s;
if (Section==1)
{
seScmbhCode->Text = GetHeadValue(fiScmbhCode);
deScmbhDate->Text = GetHeadValue(fiScmbhDate);
scScmbhFmonth->Text = GetHeadValue(fiScmbhFmonth);
seScmbhDesc->Text = GetHeadValue(fiScmbhDesc);
labScmbhSysDate->Caption = GetHeadValue(fiScmbhSysDate);
chkScmbhCheck->Checked=(GetHeadValue(fiScmbhCheck)==1)?true:false;
if(chkScmbhCheck->Checked)
SetCheckToolbarStatus(true);
else
SetCheckToolbarStatus(false);
labScmbhChecker->Caption = GetHeadValue(fiScmbhChecker);
labScmbhCheckDate->Caption= GetHeadValue(fiScmbhCheckDate);
labScmbhUser->Caption= GetHeadValue(fiScmbhUser);
}
else
{
seScmbdLine->Text = GetDetailValue(fiScmbdLine);
g_sdRsGoods->LocateByKey(GetDetailValue(fiScmbdGoods));
seScmbdGoods->Text=GetGoodsValue("GoodsCode");
seScmbdGoodsName->Text=GetGoodsValue("GoodsName");
scScmbdGoodsUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
scScmbdGoodsUnit->Text=scScmbdGoodsUnit->ItemData[0];
seScmbdOCost->Text =GetDetailValue(fiScmbdOCost);
seScmbdNCost->Text = GetDetailValue(fiScmbdNCost);
memScmbdDesc->Text = GetDetailValue(fiScmbdDesc);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::SendDataToComObject(int Section)
{
if (Section==1) // Head
{
SetHeadValue(fiScmbhCode,seScmbhCode->Text);
SetHeadValue(fiScmbhDate,deScmbhDate->Text);
SetHeadValue(fiScmbhFmonth,scScmbhFmonth->Text);
SetHeadValue(fiScmbhDesc,seScmbhDesc->Text);
SetHeadValue(fiScmbhUser,labScmbhUser->Caption);
// SetHeadValue(fiScmbhCheck,chkScmbhCheck->Checked?"1":"0");
// SetHeadValue(fiScmbhChecker,labScmbhChecker->Caption);
}
else
{
SetDetailValue(fiScmbdCode,seScmbhCode->Text);
SetDetailValue(fiScmbdLine,seScmbdLine->Text);
SetDetailValue(fiScmbdGoods,seScmbdGoods->Text);
SetDetailValue(fiScmbdOCost,seScmbdOCost->Text);
SetDetailValue(fiScmbdNCost,seScmbdNCost->Text);
SetDetailValue(fiScmbdDesc,memScmbdDesc->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::WaitUserInput(int Section)
{
if (Section ==1)
{
seScmbhDesc->SetFocus();
}
else
{
sgScmbh->Visible=false;
fpScmbhDetail->Visible=true;
seScmbdLine->SetFocus();
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmScmbh::GetDataToGrid()
{
AnsiString ItemStr;
ItemStr="\t"+GetDetailValue(fiScmbdLine)+
"\t"+GetDetailValue(fiScmbdGoods)+
"\t"+GetDetailValue(fiScmbdOCost)+
"\t"+GetDetailValue(fiScmbdNCost);
return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr;
switch(mAction)
{
case 0: // Append
ItemStr=GetDataToGrid();
sgScmbh->AddItem(ItemStr);
break;
case 1: // Modify
sgScmbh->ChangeItem(ItemStr,sgScmbh->Row);
break;
case 2: // Delete
sgScmbh->RemoveItem(sgScmbh->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgScmbh->RowCount=1;
if(comServer->RecordCount > 0)
for (i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0); // Append
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::DisplayBill()
{
if(comServer->RecordCount==0)
return;
GetDataFromComObject(1); // Head
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::GetBill(AnsiString BillID)
{
int iRow;
iRow=comServer->Find("ScmbhCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::ChangeToBrowseState(bool Browse)
{
sgScmbh->Visible=true;
fpScmbhDetail->Visible=false;
if(Browse==false)
sgScmbh->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmScmbh::GetHeadValue(int Index)
{
AnsiString S;
S = ReadFieldValue(comServer,Index);
return S;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmScmbh::GetDetailValue(int Index)
{
AnsiString S;
S = ReadItemValue(comServer,Index);
return S;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::SetHeadValue(int Index,AnsiString Value)
{
WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::sgScmbhDblClick(TObject *Sender)
{
int iRow;
iRow=sgScmbh->Row;
if (iRow == 0)
{
return;
}
comServer->LocateItemByKey(sgScmbh->TextMatrix[iRow][2]);
if (!comServer->Eof)
{
GetDataFromComObject(2); // Detail
sgScmbh->Visible=false;
fpScmbhDetail->Visible=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::sgScmbhSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
comServer->LocateItemByKey(sgScmbh->TextMatrix[ARow][2]);
if (!comServer->Eof)
GetDataFromComObject(2); // Detail
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::btnOKClick(TObject *Sender)
{
try
{ if (CurrentState==caAddDetail||CurrentState==caAddBill)
{
for(int i=1;i<=sgScmbh->RowCount;i++)
{
comServer->LocateItemByKey(sgScmbh->TextMatrix[i][2]);
if(GetDetailValue(fiScmbdLine)==seScmbdLine->Text)
throw Exception("行号'"+seScmbdLine->Text+"'已存在");
}
if(DetailState==caAddDetail)
comServer->AddItem();
SendDataToComObject(2);
comServer->AddToObject();
ClearControl(2,false);
seScmbdLine->SetFocus();
}
else
ChangeToBrowseState();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::btnCancelClick(TObject *Sender)
{
CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::FormShow(TObject *Sender)
{
ClearControl(1,false); // Head
ClearControl(2,false); // Detail
ChangeToBrowseState();
MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::seScmbdGoodsButtonClick(TObject *Sender)
{
AnsiString SqlStr;
TfrmWnQuery *p;
SqlStr="004[物料编码][物料名称][计量单位][老成本]select goodscode ,goodsname,goodsunitcode,SCDCOST ";
SqlStr+=" from sdgoods,sdscd where goodscode=SCDGOODS ";
try{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"物料查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seScmbdGoods->Text=p->ColData[1];
seScmbdGoodsName->Text=p->ColData[2];
scScmbdGoodsUnit->LocateKey(p->ColData[3]);
seScmbdOCost->Text=p->ColData[4];
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::RefreshUpdateData(int MsgSrc,int MsgType)
{
switch(MsgSrc)
{
case euSdFc:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scScmbhFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
break;
case euSdUnit:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scScmbdGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
break;
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::seScmbhCodeKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13 && CurrentState==caNormal)
{
comServer->LocateByKey(seScmbhCode->Text);
DisplayBill();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmScmbh::seScmbdGoodsKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13)
{
TComResultSet *TResultSet=NewResultSet();
AnsiString strSQL;
strSQL="select GOODSCODE,GoodsName,GoodsUnitCode,SCDCOST from sdgoods,sdscd where SCDGOODS =GOODSCODE and GOODSCODE='"+seScmbdGoods->Text+"'";
TResultSet->Close();
try
{
TResultSet->Open(strSQL,"");
seScmbdGoodsName->Text=TResultSet->FieldByName("GoodsName");
scScmbdGoodsUnit->LocateKey(TResultSet->FieldByName("GoodsUnitCode"));
seScmbdOCost->Text=TResultSet->FieldByName("SCDCOST");
TResultSet->Close();
}
__finally
{
delete TResultSet;
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -