📄 adjcoh.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "AdjCoh.h"
#include "WnQuery.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"
TfrmAdjCoh *frmAdjCoh;
//---------------------------------------------------------------------------
__fastcall TfrmAdjCoh::TfrmAdjCoh(TComponent* Owner)
: TBillBaseForm(Owner,euSdAdjCoh,"")
{
AutoCtl=seAdjCohCode;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::InitEditControl()
{
ClientGroup->AddComponent(1,false,false,true,fpAdjCohHead,fpAdjCohHead->Name);
ClientGroup->AddComponent(2,false,false,true,fpAdjCohDetail,fpAdjCohDetail->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,scAdjCodGoodsUnit,scAdjCodGoodsUnit->Name);
ClientGroup->AddComponent(1,false,true,false,seAdjCohCode,seAdjCohCode->Name);
ClientGroup->AddComponent(1,true,true,true,scAdjCohFmonth,scAdjCohFmonth->Name);
ClientGroup->AddComponent(1,true,true,true,scAdjCohKeeper,scAdjCohKeeper->Name);
//h
FillComboBox(scAdjCohFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
FillComboBox(scAdjCohPosType,"select postypename,postypecode from sdpostype where POSTYPEFLG=6 ","postypename","postypecode");
FillComboBox(scAdjCohKeeper,"select username,keepercode from sdkeeper ,sduser where keepercode=usercode","username","KeeperCode");
//d
FillComboBox(scAdjCodBatch,"SELECT BatchCode FROM sdBatch","BatchCode");
FillComboBox(scAdjCodGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::ClearControl(int Section,bool BringToNext)
{
if (Section == 1)
{
if (!BringToNext)
{
seAdjCohCode->Text ="";
deAdjCohDate->Text =g_sdCurDate;
scAdjCohFmonth->Text =g_sdCMonth;
seAdjCohDesc->Text ="";
chkAdjCohPost->Checked =false;
labAdjCohPoster->Caption ="";
scAdjCohPosType->ItemIndex =-1;
scAdjCohPosType->Text ="";
labAdjCohSysDate->Caption ="";
scAdjCohKeeper->LocateKey(g_sdUserCode);
scAdjCohKeeper->Text =scAdjCohKeeper->ItemData[0];
chkAdjCohCheck->Checked =false;
labAdjCohChecker->Caption ="";
labAdjCohUser->Caption =g_sdUserCode;
}
sgAdjCoh->RowCount=1;
}
else if (Section==2)
{
if (!BringToNext)
{
seAdjCodLine->Text =AnsiString(comServer->ItemCount+1);
seAdjCodGoods->Text ="";
seAdjCodAmt->Text ="";
scAdjCodBatch->Text ="";
memAdjCodDesc->Text ="";
seAdjCodGoodsName->Text ="";
scAdjCodGoodsUnit->Text ="";
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::GetDataFromComObject(int Section)
{
AnsiString s;
if (Section==1)
{
seAdjCohCode->Text = GetHeadValue(fiAdjCohCode);
deAdjCohDate->Text = GetHeadValue(fiAdjCohDate);
scAdjCohFmonth->Text = GetHeadValue(fiAdjCohFmonth);
seAdjCohDesc->Text = GetHeadValue(fiAdjCohDesc);
scAdjCohPosType->LocateKey(GetHeadValue(fiAdjCohPosType));
scAdjCohPosType->Text =scAdjCohPosType->ItemData[0];
labAdjCohSysDate->Caption = GetHeadValue(fiAdjCohSysDate);
scAdjCohKeeper->LocateKey(GetHeadValue(fiAdjCohKeeper));
scAdjCohKeeper->Text =scAdjCohKeeper->ItemData[0];
if(GetHeadValue(fiAdjCohPost)=="1")
chkAdjCohPost->Checked =true;
else
chkAdjCohPost->Checked =false;
labAdjCohPoster->Caption=(GetHeadValue(fiAdjCohPoster));
chkAdjCohCheck->Checked=(GetHeadValue(fiAdjCohCheck)==1)?true:false;
if(chkAdjCohCheck->Checked)
SetCheckToolbarStatus(true);
else
SetCheckToolbarStatus(false);
labAdjCohChecker->Caption = GetHeadValue(fiAdjCohChecker);
labAdjCohUser->Caption =GetHeadValue(fiAdjCohUser);
}
else
{
seAdjCodLine->Text = GetDetailValue(fiAdjCodLine);
g_sdRsGoods->LocateByKey(GetDetailValue(fiAdjCodGoods));
seAdjCodGoods->Text=GetGoodsValue("GoodsCode");
seAdjCodGoodsName->Text=GetGoodsValue("GoodsName");
scAdjCodGoodsUnit->LocateKey(GetGoodsValue("GoodsUnitCode"));
scAdjCodGoodsUnit->Text=scAdjCodGoodsUnit->ItemData[0];
scAdjCodBatch->Text =GetDetailValue(fiAdjCodBatch);
seAdjCodAmt->Text = GetDetailValue(fiAdjCodAmt);
memAdjCodDesc->Text = GetDetailValue(fiAdjCodDesc);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::SendDataToComObject(int Section)
{
if (Section==1) // Head
{
SetHeadValue(fiAdjCohCode,seAdjCohCode->Text);
SetHeadValue(fiAdjCohDate,deAdjCohDate->Text);
SetHeadValue(fiAdjCohFmonth,scAdjCohFmonth->Text);
SetHeadValue(fiAdjCohDesc,seAdjCohDesc->Text);
SetHeadValue(fiAdjCohPosType,scAdjCohPosType->ItemData[1]);
SetHeadValue(fiAdjCohKeeper,scAdjCohKeeper->ItemData[1]);
SetHeadValue(fiAdjCohUser,labAdjCohUser->Caption);
// SetHeadValue(fiAdjCohCheck,chkAdjCohCheck->Checked?"1":"0");
// SetHeadValue(fiAdjCohChecker,labAdjCohChecker->Caption);
}
else
{
SetDetailValue(fiAdjCodCode,seAdjCohCode->Text);
SetDetailValue(fiAdjCodLine,seAdjCodLine->Text);
SetDetailValue(fiAdjCodGoods,seAdjCodGoods->Text);
SetDetailValue(fiAdjCodBatch,scAdjCodBatch->Text);
SetDetailValue(fiAdjCodAmt,seAdjCodAmt->Text);
SetDetailValue(fiAdjCodDesc,memAdjCodDesc->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::WaitUserInput(int Section)
{
if (Section ==1)
{
seAdjCohDesc->SetFocus();
}
else
{
sgAdjCoh->Visible=false;
fpAdjCohDetail->Visible=true;
seAdjCodLine->SetFocus();
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmAdjCoh::GetDataToGrid()
{
AnsiString ItemStr;
ItemStr="\t"+GetDetailValue(fiAdjCodLine)+
"\t"+GetDetailValue(fiAdjCodGoods)+
"\t"+GetDetailValue(fiAdjCodBatch)+
"\t"+GetDetailValue(fiAdjCodAmt);
return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr;
switch(mAction)
{
case 0: // Append
ItemStr=GetDataToGrid();
sgAdjCoh->AddItem(ItemStr);
break;
case 1: // Modify
sgAdjCoh->ChangeItem(ItemStr,sgAdjCoh->Row);
break;
case 2: // Delete
sgAdjCoh->RemoveItem(sgAdjCoh->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgAdjCoh->RowCount=1;
if(comServer->RecordCount > 0)
for (i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0); // Append
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::DisplayBill()
{
if(comServer->RecordCount==0)
return;
GetDataFromComObject(1); // Head
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::GetBill(AnsiString BillID)
{
int iRow;
iRow=comServer->Find("AdjCohCode='"+BillID+"'");
if (iRow>0) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::ChangeToBrowseState(bool Browse)
{
sgAdjCoh->Visible=true;
fpAdjCohDetail->Visible=false;
if(Browse==false)
sgAdjCoh->SetFocus();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmAdjCoh::GetHeadValue(int Index)
{
AnsiString S;
S = ReadFieldValue(comServer,Index);
return S;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmAdjCoh::GetDetailValue(int Index)
{
AnsiString S;
S = ReadItemValue(comServer,Index);
return S;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::SetHeadValue(int Index,AnsiString Value)
{
WriteFieldValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::sgAdjCohDblClick(TObject *Sender)
{
int iRow;
iRow=sgAdjCoh->Row;
if (iRow == 0)
{
return;
}
comServer->LocateItemByKey(sgAdjCoh->TextMatrix[iRow][2]);
if (!comServer->Eof)
{
GetDataFromComObject(2); // Detail
sgAdjCoh->Visible=false;
fpAdjCohDetail->Visible=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::sgAdjCohSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if (ARow > 0)
comServer->LocateItemByKey(sgAdjCoh->TextMatrix[ARow][2]);
if (!comServer->Eof)
GetDataFromComObject(2); // Detail
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::btnOKClick(TObject *Sender)
{
try
{
if (CurrentState==caAddDetail||CurrentState==caAddBill)
{
for(int i=1;i<=sgAdjCoh->RowCount;i++)
{
comServer->LocateItemByKey(sgAdjCoh->TextMatrix[i][2]);
if(GetDetailValue(fiAdjCodLine)==seAdjCodLine->Text)
throw Exception("行号'"+seAdjCodLine->Text+"'已存在");
}
if(DetailState==caAddDetail)
comServer->AddItem();
SendDataToComObject(2);
comServer->AddToObject();
ClearControl(2,false);
seAdjCodLine->SetFocus();
}
else
ChangeToBrowseState();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::FormShow(TObject *Sender)
{
ClearControl(1,false); // Head
ClearControl(2,false); // Detail
MoveToFirst();
ChangeToBrowseState();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::btnCancelClick(TObject *Sender)
{
CancelChange();
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::seAdjCodGoodsButtonClick(TObject *Sender)
{
AnsiString SqlStr;
TfrmWnQuery *p;
SqlStr="003[物料编码][物料名称][计量单位]select goodscode ,goodsname,goodsunitcode ";
SqlStr+=" from Sdcd,sdgoods,sdstock where goodscode=stockgoodscode and cdgoods=goodscode ";
try{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"物料查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seAdjCodGoods->Text=p->ColData[1];
seAdjCodGoodsName->Text=p->ColData[2];
scAdjCodGoodsUnit->LocateKey(p->ColData[3]);
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::RefreshUpdateData(int MsgSrc,int MsgType)
{
switch(MsgSrc)
{
case euSdFc:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scAdjCohFmonth,"SELECT Fcmonth FROM sdFc","Fcmonth");
break;
case euSdKeeper:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scAdjCohKeeper,"select username,keepercode from sdkeeper ,sduser where keepercode=usercode","username","KeeperCode");
break;
case euSdUnit:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scAdjCodGoodsUnit,"select Unitname,unitcode from sdunit","unitname","unitcode");
break;
case euSdPosType:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scAdjCohPosType,"select postypename,postypecode from sdpostype where POSTYPEFLG=6 ","postypename","postypecode");
break;
case euSdBatch:
if(ShowUpdateMessage(MsgSrc,MsgType))
FillComboBox(scAdjCodBatch,"SELECT BatchCode FROM sdBatch","BatchCode");
break;
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::seAdjCohCodeKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key==13&& CurrentState==caNormal)
{
comServer->LocateByKey(seAdjCohCode->Text);
DisplayBill();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmAdjCoh::seAdjCodGoodsKeyDown(TObject *Sender,
WORD &Key, TShiftState Shift)
{
if(Key==13)
{
TComResultSet *TResultSet=NewResultSet();
AnsiString strSQL;
strSQL="select GOODSCODE,GoodsName,GoodsUnitCode from Sdcd,sdgoods,sdstock where goodscode=stockgoodscode and cdgoods=goodscode and GOODSCODE='"+seAdjCodGoods->Text+"'";
try
{
TResultSet->Close();
TResultSet->Open(strSQL,"");
if(TResultSet->RecordCount<1)
throw Exception("物料"+seAdjCodGoods->Text+"'不存在或未初始化");
seAdjCodGoodsName->Text=TResultSet->FieldByName("GoodsName");
scAdjCodGoodsUnit->LocateKey(TResultSet->FieldByName("GoodsUnitCode"));
TResultSet->Close();
}
__finally
{
delete TResultSet;
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -