📄 gmth_w.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Gmth_W.h"
#include "Dml.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "DateEdit"
#pragma link "fpanel"
#pragma link "GenBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmGmth_W *frmGmth_W;
//---------------------------------------------------------------------------
__fastcall TfrmGmth_W::TfrmGmth_W(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
: TGenBaseForm(Owner,chWnd,MidCode,WhereStr)
{
AutoCtl=seGmthCode;
//SetAutoCodeString(seGmthCode,"ACM-006");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::InitEditControl()
{
ClientGroup->AddComponent(1,false,false,true,PnlGmth,PnlGmth->Name);
ClientGroup->AddComponent(1,true,true,true,scGmthType,scGmthType->Name);
ClientGroup->AddComponent(1,false,true,false,seGmthCode,seGmthCode->Name);
ClientGroup->AddComponent(1,false,true,true,seGmthWo,seGmthWo->Name);
ClientGroup->AddComponent(1,true,true,true,scGmthFmonth,scGmthFmonth->Name);
ClientGroup->AddComponent(2,true,true,true,PnlGmtd,PnlGmtd->Name);
//
scGmthType->ClearAll();
scGmthType->AddItems("R-工单定额领料","1");
scGmthType->AddItems("W-工单自由领料","2");
scGmthType->AddItems("A-工单工序补料","3");
scGmthType->AddItems("C-共用材料领料","4");
scGmthType->AddItems("D-部门直接领料","5");
//
FillComboBox(Handle,scGmthFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
FillComboBox(Handle,scGmthPosType,"SELECT PosTypeCode,PosTypeName FROM sdPosType where PosTypeFlg=3 order by PosTypeName","PosTypeName","PosTypeCode");
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::RefreshUpdateData(int MsgSrc,int MsgType)
{
/*
try
{
switch(MsgSrc)
{
case euSdFc:
if(ShowUpdateMessage(MsgSrc,MsgType)){
StartWaitForm("正在刷新引用数据!");
FillComboBox(Handle,scGmthFmonth,"SELECT FcMonth FROM sdFc order by FcMonth","FcMonth");
EndWaitForm();
break;
}
case euSdPosType:
if(ShowUpdateMessage(MsgSrc,MsgType)){
StartWaitForm("正在刷新引用数据!");
FillComboBox(Handle,scGmthPosType,"SELECT PosTypeCode,PosTypeName FROM sdPosType order by PosTypeCode","PosTypeName","PosTypeCode");
EndWaitForm();
break;
}
default:
break;
}
}
__finally
{
//AddCode;
}
*/
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::ClearControl(int Section,bool BringToNext)
{
if(Section == 1)
{
if(!BringToNext)
{
seGmthCode->Text="";
deGmthDate->Text=g_sdCurDate;
scGmthFmonth->LocateKey(g_sdMMonth);
scGmthPosType->ItemIndex=-1;
scGmthType->ItemIndex=1;
seGmthWo->Text="";
labUser->Caption=g_sdUserCode;
chkGmthCheck->Checked=false;
labChecker->Caption="";
labCheckDate->Caption="";
memGmthDesc->Text="";
}
sgGmth->RowCount=1;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GetDataFromComObject(int Section)
{
if(Section==1){
seGmthCode->Text=GetHeadValue("GmthCode");
deGmthDate->Text=GetHeadValue("GmthDate");
scGmthFmonth->LocateKey(GetHeadValue("GmthFmonth"));
scGmthPosType->LocateKey(GetHeadValue("GmthPosType"));
scGmthType->LocateKey(GetHeadValue("GmthType"));
seGmthWo->Text=GetHeadValue("GmthWoCode");
memGmthDesc->Text=GetHeadValue("GmthDesc");
labUser->Caption=GetHeadValue("GmthUser");
chkGmthCheck->Checked=GetHeadValue("GmthCheck")=="1";
if(chkGmthCheck->Checked)
SetCheckToolbarStatus(true);
else
SetCheckToolbarStatus(false);
labChecker->Caption=GetHeadValue("GmthChecker");
labCheckDate->Caption=GetHeadValue("GmthCheckDate");
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SendDataToComObject(int Section)
{
if(Section==1){
SetHeadValue("GmthCode",seGmthCode->Text);
SetHeadValue("GmthDate",deGmthDate->Text);
SetHeadValue("GmthFmonth",scGmthFmonth->Text);
SetHeadValue("GmthPosType",scGmthPosType->ItemData[1]);
SetHeadValue("GmthWoCode",seGmthWo->Text);
SetHeadValue("GmthUser",labUser->Caption);
SetHeadValue("GmthDesc",memGmthDesc->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::WaitUserInput(int Section)
{
if(Section ==1)
{
if(seGmthCode->Enabled)
seGmthCode->SetFocus();
else
deGmthDate->SetFocus();
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmGmth_W::GetDataToGrid()
{
AnsiString ItemStr;
ItemStr=AnsiString("√");
ItemStr+="\t"+GetDetailValue("GmtdLine")+
"\t"+GetDetailValue("GmtdGoods")+
"\t"+GetDetailValue("GmtdGoodsName")+
"\t"+GetDetailValue("GmtdGoodsSpec")+
"\t"+GetDetailValue("GmtdUnit")+
"\t"+GetDetailValue("GmtdPQty")+
"\t"+GetDetailValue("GmtdCQty")+
"\t"+GetDetailValue("GmtdQty")+
"\t"+GetDetailValue("GmtdSLoc");
return ItemStr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::RefreshGridData(int mAction)
{
int i;
AnsiString ItemStr=GetDataToGrid();
switch(mAction)
{
case 0: //Add
sgGmth->AddItem(ItemStr);
sgGmth->Row=sgGmth->RowCount-1;
break;
case 1: //Edit
sgGmth->ChangeItem(ItemStr,sgGmth->Row);
break;
case 2: //Delete
sgGmth->RemoveItem(sgGmth->Row);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::FillGridWithData()
{
int i;
AnsiString ItemStr;
sgGmth->RowCount=1;
if(comServer->RecordCount > 0){
for(i=0;i<comServer->ItemCount;i++)
{
comServer->LocateItemByIndex(i);
RefreshGridData(0);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::DisplayBill()
{
if(comServer->RecordCount>0)
{
GetDataFromComObject(1);
FillGridWithData();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GetBill(AnsiString BillID)
{
bool iRow;
iRow=comServer->Find("GmthCode='"+BillID+"'");
if(iRow) //FIND THIS BILL
{
DisplayBill();
}
else
if (ShowMessageWindow("在数据库中没有查到记录:"+BillID+",要增加吗?",mwsConfirmation)==IDYES)
{
AddHeadRecord();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::FormShow(TObject *Sender)
{
//单据不能删除行
tbAddDetail->Visible=false;
tbEditDetail->Visible=false;
tbDeleteDetail->Visible=false;
tbEditAll->Visible=true;
sgGmth->ReadOnly=true;
ClearControl(1,false);
MoveToFirst();
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::ChangeToBrowseState(bool t_browse)
{
sgGmth->ReadOnly=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::GenrateBill()
{
if(comServer->ItemCount>0)
{
::MessageBox(Handle,"当前的单据已经存在,不能再执行生成操作...","错误",MB_OK|MB_ICONSTOP);
SetControlToBrowseState(1);
SetControlState(caCancel);
return;
}
try
{
StartWaitForm("正在生成,请稍侯...");
Query->Close();
// Query->SQL->Clear();
// Query->SQL->Add("exec sdGmtd_W_Genrate '"+GetHeadValue("GmthCode")+"','"+GetHeadValue("GmthWoCode")+"'");
// Query->ExecSQL();
// Query->Close();
Query->Execute("exec sdGmtd_W_Genrate '"+GetHeadValue("GmthCode")+"','"+GetHeadValue("GmthWoCode")+"'");
Query->Close();
SaveRecord();
comServer->FilterString=" GmthCode = '"+seGmthCode->Text+"'" ;
comServer->Query();
}
__finally
{
EndWaitForm();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::EditBill()
{
if(sgGmth->RowCount>1)
{
sgGmth->SetFocus();
sgGmth->ReadOnly=false;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::SendAllDetailValue()
{
if(sgGmth->RowCount>1)
{
for(int i=1;i<sgGmth->RowCount;i++)
{
if(sgGmth->Cells[0][i]=="√")
{
AnsiString Keystr;
Keystr=seGmthCode->Text+"\t"+sgGmth->Cells[1][i];
comServer->LocateItemByKey(Keystr);
comServer->EditItem();
SetDetailValue("GmtdQty",sgGmth->Cells[8][i]);
SetDetailValue("GmtdSLoc",sgGmth->Cells[9][i]);
try
{
comServer->AddToObject();
}
catch(Exception &e)
{
throw Exception(e.Message);
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthClick(TObject *Sender)
{
int iRow=sgGmth->Row;
int iCol=sgGmth->Col;
if(iRow>0 && iCol==0 && CurrentState==caEditBill)
{
if(sgGmth->Cells[0][iRow]=="√")
sgGmth->Cells[0][iRow]="";
else
sgGmth->Cells[0][iRow]="√";
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthDblClick(TObject *Sender)
{
int ARow=sgGmth->Row;
int ACol=sgGmth->Col;
if(sgGmth->Cells[0][ARow]!="√" || comServer->ItemCount<=0)
return;
if(ARow>0 && ACol==2)
{
TfrmDml *Dmlfrm;
try{
StartWaitForm("正在启动<工序材料分摊>界面...");
AnsiString l_line=WideString(sgGmth->Cells[1][ARow]);
if (l_line.IsEmpty())
l_line=0 ;
comServer->LocateItemByKey(seGmthCode->Text+"\t"+l_line+"\t");
AnsiString t_GmthCode=GetDetailValue("GmtdCode");
AnsiString t_GmthCheck=GetHeadValue("GmthCheck");
AnsiString t_GmtdLine=GetDetailValue("GmtdLine");
AnsiString t_GmtdWo=GetDetailValue("GmtdWoCode");
AnsiString t_GmtdGoods=GetDetailValue("GmtdGoods");
AnsiString t_GmtdQty=GetDetailValue("GmtdQty");
AnsiString FWhereString,FParamString;
FWhereString="DmlGmtCode='"+t_GmthCode+"' and DmlGmtdLine='"+t_GmtdLine+"'";
FParamString=t_GmthCode+"\t"+t_GmthCheck+"\t"+t_GmtdLine+"\t"+t_GmtdWo+"\t"+t_GmtdGoods+"\t"+t_GmtdQty;
Dmlfrm=new TfrmDml(this,g_ClientHandle,"1061101",FWhereString,FParamString);
EndWaitForm();
Dmlfrm->ShowModal();
}
__finally{
delete Dmlfrm;
}
}
if(ARow>0 && ACol==9 && CurrentState!=caNormal)
{
AnsiString SqlStr;
SqlStr="003[货位编码][货位名称][货位类型]SELECT LgLocCode,LocName,LocType";
SqlStr+=" FROM sdLoc,sdLg WHERE LocCode=LgLocCode and LocType=1 and";
SqlStr+=" LgGoodsCode='"+sgGmth->Cells[2][ARow]+"' ORDER BY LgLocCode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"物料在制货位查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sgGmth->Cells[9][ARow]=p->ColData[1];
}
delete p;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::sgGmthSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(ARow > 0)
{
FCurRow=ARow;
comServer->LocateItemByKey(seGmthCode->Text+"\t"+sgGmth->TextMatrix[ARow][1]);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::seGmthCodeKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
AnsiString tempS=seGmthCode->Text;
if(Key==13 && CurrentState==caNormal && !tempS.IsEmpty())
{
comServer->LocateByKey(tempS);
DisplayBill();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmGmth_W::seGmthWoButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="006[加工单号][加工件码][要求数量][要求日期][订单单号][订单行号]SELECT WoCode,WoGoods,WoQty,WoRDate,";
SqlStr=SqlStr+"WoSoCode,WoSodLine from sdWo where WoCheck=1 and WoClose=0 ORDER BY WoCode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"加工订单查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seGmthWo->Text=p->ColData[1];
}
delete p;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmGmth_W::BeforeCheck()
{
SetHeadValue("GmthCheck",1);
SetHeadValue("GmthChecker",g_sdUserCode);
SetHeadValue("GmthCheckDate",g_sdCurDate);
return true;
}
//---------------------------------------------------------------------------
bool __fastcall TfrmGmth_W::BeforeUnCheck()
{
SetHeadValue("GmthCheck",0);
SetHeadValue("GmthChecker","");
SetHeadValue("GmthCheckDate",NULL);
return true;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -