📄 dmad.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Dmad.h"
#include "Dmah.h"
#include "wnquery.h"
#include "func.h"
//--------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma link "SDComboBox"
#pragma resource "*.dfm"
TfrmDmad *frmDmad;
//--------------------------------------------------------------------------
__fastcall TfrmDmad::TfrmDmad(TComponent* Owner)
: TStdBaseForm(Owner)
{
InitControlGroup();
btnOK->Enabled = false;
FillGridWithData();
}
//--------------------------------------------------------------------------
void __fastcall TfrmDmad::btnOKClick(TObject *Sender)
{
int ErrNum;
try
{
StartWaitForm("正在生成共用件分摊,请稍候...");
if(sgDmad->RowCount>1)
{
int j;
j=comServer->ItemCount-1;
if(j>=0)
{
comServer->LocateItemByIndex(j);
j=StrToInt(frmDmah->GetDetailValue(fiDmadLine));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgDmad->RowCount;i++)
{
if(sgDmad->Cells[0][i]=="√")
{
comServer->AddItem();
SetDetailValue(fiDmadCode,frmDmah->seDmahCode->Text);
SetDetailValue(fiDmadLine,AnsiString(j));
SetDetailValue(fiDmadGmtCode,sgDmad->Cells[1][i]);
SetDetailValue(fiDmadGmtdLine, sgDmad->Cells[2][i]);
if(sgDmad->Cells[7][i] == "")
throw Exception("请输入分摊数量");
SetDetailValue(fiDmadQty, sgDmad->Cells[7][i]);
if(sgDmad->Cells[8][i] == "")
throw Exception("请输入分摊工单号");
SetDetailValue(fiDmadWoCode, sgDmad->Cells[8][i]);
SetDetailValue(fiDmadDesc, sgDmad->Cells[9][i]);
try{
comServer->AddToObject();
}
catch(Exception &e){
throw Exception(e.Message);
}
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->Cancel();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::btnCancelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::InitControlGroup()
{
sgDmad->RowCount = 1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::FillGridWithData()
{
AnsiString ItemStr,s_SQL;
double d_PrecdQty;
s_SQL=AnsiString(" Select gmtdcode,gmtdline,gmtdgoods,gmtdunit,gmtdDloc,gmtdqty=gmtdqty-gmtddqty from sdgmtd ,sdgmth")
+AnsiString(" where gmtdcode=gmthcode and GmthType=4 and gmthcheck=1 and gmtdqty-gmtddqty>0 order by gmtdcode,gmtdline");
sgDmad->RowCount=1;
TComResultSet *RsDmad;
try
{
StartWaitForm("正在查询数据,请稍候...");
RsDmad=NewResultSet();
RsDmad->Open(s_SQL,"");
sgDmad->RowCount=1;
while( RsDmad->Eof == 0)
{
ItemStr=AnsiString("√") +
"\t"+RsDmad->FieldByName("GmtdCode")+
"\t"+RsDmad->FieldByName("GmtdLine")+
"\t"+RsDmad->FieldByName("GmtdGoods")+
"\t"+RsDmad->FieldByName("GmtdUnit")+
"\t"+RsDmad->FieldByName("GmtdDLoc")+
"\t"+RsDmad->FieldByName("GmtdQty")+
"\t"+RsDmad->FieldByName("GmtdQty")+
"\t"+AnsiString("")+
"\t"+AnsiString("");
sgDmad->AddItem(ItemStr);
RsDmad->MoveNext();
}
RsDmad->Close();
delete RsDmad;
}
__finally
{
EndWaitForm();
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::GetComObject(TComServer *comServerPtr)
{
comServer = comServerPtr;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::SetDetailValue(int Index,AnsiString Value)
{
WriteItemValue(comServer,Index,Value);
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::sgDmadDblClick(TObject *Sender)
{
AnsiString SqlStr;
int ARow=sgDmad->Row;
if (ARow >0)
{
if(sgDmad->Col==0)
{
if (sgDmad->Cells[0][ARow] == "√")
{
sgDmad->Cells[0][ARow] = "";
for (int i=1;i<sgDmad->RowCount;i++)
{
if(sgDmad->Cells[0][i]=="√")
{
btnOK->Enabled=true;
break;
}
else
btnOK->Enabled=false;
}
}
else
{
sgDmad->Cells[0][ARow] = "√";
btnOK->Enabled = true;
}
}
else if(sgDmad->Col==8 && sgDmad->Cells[0][ARow] == "√")
{
SqlStr="002[工单号][加工件码]select wocode,wogoods from sdwo ";
SqlStr+=" where wocheck=1 and woclose=0 order by wocode";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"工单查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sgDmad->Cells[8][ARow]=p->ColData[1];
}
delete p;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::bbSelAllClick(TObject *Sender)
{
if(sgDmad->RowCount <=1 )
return;
for(int i=1;i<sgDmad->RowCount;i++)
sgDmad->Cells[1][i] = "√";
btnOK->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::bbSelNoneClick(TObject *Sender)
{
for(int i=1;i<sgDmad->RowCount;i++)
sgDmad->Cells[1][i] = "";
btnOK->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmDmad::sgDmadSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(sgDmad->Cells[0][ARow]=="√")
{
sgDmad->ReadOnly=false;
btnOK->Enabled = true;
}
else
sgDmad->ReadOnly=true;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -