📄 pieced_t.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "Pieced_T.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmPieced_T *frmPieced_T;
//---------------------------------------------------------------------------
__fastcall TfrmPieced_T::TfrmPieced_T(TComponent* Owner, HWND chWnd, AnsiString MidCode,AnsiString WhereStr)
: TStdBaseForm(Owner,chWnd,MidCode,WhereStr)
{
int iPos;
iPos=WhereStr.Pos("\t");
FPiecehCode=WhereStr.SubString(1,iPos-1);
WhereStr=WhereStr.SubString(iPos+1,WhereStr.Length());
iPos=WhereStr.Pos("\t");
FPiecehShop=WhereStr.SubString(1,iPos-1);
FPiecehTeam=WhereStr.SubString(iPos+1,WhereStr.Length());
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::FormShow(TObject *Sender)
{
scPiecedDType->ClearAll();
scPiecedDType->AddItems("0-手工录入","0");
scPiecedDType->AddItems("1-平均分配","1");
FillEdit(Handle,sePiecedProcess,"SELECT ProcessCode,ProcessName FROM sdProcess order by ProcessCode","ProcessName","ProcessCode");
InitEditControl();
FillDataToGrid();
sePiecedWo->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::FillDataToGrid()
{
TComResultSet *Rst;
AnsiString m_SQL,m_STR;
Rst= new TComResultSet(Handle,g_ClientHandle);
if(!FPiecehTeam.IsEmpty())
m_SQL=AnsiString("Select distinct TeEmployee,EmployeeName from sdTe,sdTeam,")+
AnsiString("sdEmployee where TeTeam=TeamCode and TeEmployee=EmployeeCode and TeamShopCode='"+FPiecehShop+"' and TeTeam='"+FPiecehTeam+"' ")+
AnsiString("Order by TeEmployee");
else
m_SQL=AnsiString("Select distinct TeEmployee,EmployeeName from sdTe,sdTeam,")+
AnsiString("sdEmployee where TeTeam=TeamCode and TeEmployee=EmployeeCode and TeamShopCode='"+FPiecehShop+"' ")+
AnsiString("Order by TeEmployee");
Rst->Open(WideString(m_SQL),WideString(""));
Rst->MoveFirst();
sgPieced->RowCount=1;
while(Rst->Eof == 0)
{
m_STR=AnsiString("√")+
"\t"+Rst->FieldByName("TeEmployee")+
"\t"+Rst->FieldByName("EmployeeName")+
"\t"+AnsiString("0.00");
sgPieced->AddItem(m_STR);
Rst->MoveNext();
}
Rst->Close();
delete Rst;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::InitEditControl()
{
sePiecedWo->Text="";
sePiecedProcess->ItemIndex=-1;
sePiecedQty->Text="0.00";
sePiecedPrice->Text="0.00";
scPiecedDType->ItemIndex=-1;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::btCacelClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::SetcomServer(TComServer *value)
{
comServer=value;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::scPiecedDTypeClick(TObject *Sender)
{
AnsiString tempS;
double totalQty;
totalQty=sePiecedQty->Text.ToDouble();
if(totalQty<=0)
throw Exception("团体工时的数量不能小于或等于零!");
tempS=Trim(scPiecedDType->Text);
if(scPiecedDType->ItemData[1]==1)
{
sgPieced->ReadOnly=true;
AverageTotalQty();
}
else
{
sgPieced->ReadOnly=false;
sgPieced->Options<<goEditing;
sgPieced->Options<<goAlwaysShowEditor;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::AverageTotalQty()
{
int iRowCount=0;
double aveQty,totalQty,lastQty;
totalQty=sePiecedQty->Text.ToDouble();
if(sgPieced->RowCount>1)
{
//统计选择的员工编码
for(int i=1;i<sgPieced->RowCount;i++)
{
if(sgPieced->Cells[0][i]=="√")
iRowCount=iRowCount+1;
}
if(iRowCount>0){
aveQty=totalQty/iRowCount;
aveQty=DataCarry(aveQty,2,1);
for(int i=1;i<sgPieced->RowCount;i++)
{
if(sgPieced->Cells[0][i]=="√")
sgPieced->Cells[3][i]=aveQty;
else
sgPieced->Cells[3][i]="0.00";
}
//查找最后一个选择的员工编码
for(int i=sgPieced->RowCount;i>0;i--)
{
if(sgPieced->Cells[0][i]=="√"){
lastQty=sgPieced->Cells[3][i].ToDouble();
sgPieced->Cells[3][i]=lastQty+totalQty-aveQty*iRowCount;
return;
}
}
}
else
throw Exception("没有选择可分摊的员工!");
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sgPiecedSelectCell(TObject *Sender, int ACol,
int ARow, bool &CanSelect)
{
if(ARow>0 && ACol==0)
{
if(sgPieced->Cells[0][ARow]=="")
{
sgPieced->Cells[0][ARow]="√";
if(scPiecedDType->ItemData[1]==1)
AverageTotalQty();
}
else
{
sgPieced->Cells[0][ARow]="";
sgPieced->Cells[3][ARow]="0.00";
if(scPiecedDType->ItemData[1]==1)
AverageTotalQty();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::btOkClick(TObject *Sender)
{
double TotalQty,v_Qty;
try{
StartWaitForm("正在生成记件单行......");
TotalQty = 0;
for(int i=1;i<sgPieced->RowCount;i++)
{
if(sgPieced->Cells[0][i]=="√")
TotalQty=TotalQty+sgPieced->Cells[3][i].ToDouble();
}
v_Qty= sePiecedQty->Text.ToDouble();
if(TotalQty != v_Qty)
throw Exception("工时分配后的总和不等于团体总工时,请重新分配.");
if(sgPieced->RowCount>1)
{
try{
int j;
j=comServer->ItemCount-1;
if(j>0) //如果已有明细记录
{
comServer->LocateItemByIndex(j);
j=GetDetailValue("PiecedLine").ToInt();
j=j+1;
}
else
j=1;
for(int i=1;i<sgPieced->RowCount;i++)
{
if(sgPieced->Cells[0][i]=="√")
{
comServer->AddItem();
SetDetailValue("PiecedCode",FPiecehCode);
SetDetailValue("PiecedLine",AnsiString(j));
SetDetailValue("PiecedWo",sePiecedWo->Text);
SetDetailValue("PiecedDType",scPiecedDType->ItemData[1]);
SetDetailValue("PiecedProcess",sePiecedProcess->ItemData[1]);
SetDetailValue("PiecedEmployee",sgPieced->Cells[1][i]);
SetDetailValue("PiecedQty",sgPieced->Cells[3][i]);
SetDetailValue("PiecedPrice",sePiecedPrice->Text);
SetDetailValue("PiecedQty1",0);
SetDetailValue("PiecedPrice1",0);
SetDetailValue("PiecedQty2",0);
SetDetailValue("PiecedPrice2",0);
SetDetailValue("PiecedQty3",0);
SetDetailValue("PiecedPrice3",0);
SetDetailValue("PiecedQty4",0);
SetDetailValue("PiecedPrice4",0);
SetDetailValue("PiecedQty5",0);
SetDetailValue("PiecedPrice5",0);
SetDetailValue("PiecedQty6",0);
SetDetailValue("PiecedPrice6",0);
SetDetailValue("PiecedQty7",0);
SetDetailValue("PiecedPrice7",0);
SetDetailValue("PiecedQty8",0);
SetDetailValue("PiecedPrice8",0);
SetDetailValue("PiecedQty9",0);
SetDetailValue("PiecedPrice9",0);
SetDetailValue("PiecedQty10",0);
SetDetailValue("PiecedPrice10",0);
comServer->AddToObject();
j=j+1;
}
}
}
catch(Exception &e)
{
comServer->FreeItem();
this->ModalResult=0;
throw Exception(e.Message);
}
}
}
__finally
{
EndWaitForm();
}
Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sePiecedWoButtonClick(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)
{
sePiecedWo->Text=p->ColData[1];
}
delete p;
}
//---------------------------------------------------------------------------
void __fastcall TfrmPieced_T::sePiecedProcessButtonClick(TObject *Sender)
{
AnsiString SqlStr;
SqlStr="003[序号][工序代码][工序名称]SELECT WrgNo,WrgProcess,ProcessName FROM sdWrg,sdProcess ";
SqlStr=SqlStr+"where WrgProcess=ProcessCode and WrgWo='"+sePiecedWo->Text+"' ORDER BY WrgNo";
TfrmWnQuery *p;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"工序资料查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
sePiecedProcess->LocateKey(p->ColData[2]);
}
delete p;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -