📄 dmad.cpp
字号:
//--------------------------------------------------------------------------
#include <vcl.h>
#include "Dmad.h"
#include "Dmah.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(GetDetailValue("DmadLine"));
j=j+1;
}
else
j=1;
try
{
for(int i=1;i<sgDmad->RowCount;i++)
{
if(sgDmad->Cells[0][i]=="√")
{
comServer->AddItem();
this->comServer->ItemValue["DmadCode"] = frmDmah->seDmahCode->Text;
this->comServer->ItemValue["DmadLine"] = IntToStr(j); //定额领单行号
this->comServer->ItemValue["DmadGmtCode"] = sgDmad->Cells[1][i];
this->comServer->ItemValue["DmadGmtdLine"] = sgDmad->Cells[2][i]; //定额领单行号
if(sgDmad->Cells[7][i] == "")
throw Exception("请输入分摊数量");
this->comServer->ItemValue["DmadQty"] = sgDmad->Cells[7][i]; //定额领单行号
if(sgDmad->Cells[8][i] == "")
throw Exception("请输入分摊工单号");
this->comServer->ItemValue["DmadWoCode"] = sgDmad->Cells[8][i];
this->comServer->ItemValue["DmadDesc"] = sgDmad->Cells[9][i]; //定额领单行号
this->comServer->ItemValue["DmadGoods"] = sgDmad->Cells[3][i];
this->comServer->ItemValue["DmadUnit"] = sgDmad->Cells[4][i];
this->comServer->ItemValue["DmadLoc"] = sgDmad->Cells[5][i];
this->comServer->ItemValue["DmadPrice"] = 0;
this->comServer->ItemValue["DmadAmt"] = 0;
/* SetDetailValue("DmadCode",frmDmah->seDmahCode->Text);
SetDetailValue("DmadLine",AnsiString(j));
SetDetailValue("DmadGmtCode",sgDmad->Cells[1][i]);
SetDetailValue("DmadGmtdLine", sgDmad->Cells[2][i]);
if(sgDmad->Cells[7][i] == "")
throw Exception("请输入分摊数量");
SetDetailValue("DmadQty", sgDmad->Cells[7][i]);
if(sgDmad->Cells[8][i] == "")
throw Exception("请输入分摊工单号");
SetDetailValue("DmadWoCode", sgDmad->Cells[8][i]);
SetDetailValue("DmadDesc", sgDmad->Cells[9][i]); */
try{
comServer->AddToObject();
}
catch(Exception &e){
throw Exception(e.Message);
}
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->FreeItem();
// 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=new TComResultSet(Handle,g_ClientHandle);
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::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 + -