📄 woclose.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include "WoClose.h"
//---------------------------------------------------------------------------
#pragma hdrstop
#pragma package(smart_init)
#pragma link "DateEdit"
#pragma link "ListBaseForm"
#pragma link "SDComboBox"
#pragma link "SDEdit"
#pragma link "SDGrid"
#pragma resource "*.dfm"
TfrmWoClose *frmWoClose;
//---------------------------------------------------------------------------
__fastcall TfrmWoClose::TfrmWoClose(TComponent* Owner)
: TListBaseForm(Owner,euSdWo,"")
{
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::GetWhereStrToSQL()
{
WhereStr="WoCheck=1 and WoClose=0 and WoCancel=0";
if(Trim(scWoRoute->Text) != "")
WhereStr = WhereStr + " and WoRoute='" + Trim(scWoRoute->Text) + "'";
if(Trim(seWoGoods->Text) != "")
WhereStr = WhereStr + " and WoGoods like '%" + Trim(seWoGoods->Text) + "%'";
if(chkWoCode->Checked){
if(seWoCodeT->Text.IsEmpty())
WhereStr = WhereStr + " and WoCode>='" + Trim(seWoCodeF->Text) + "'";
else{
if(seWoCodeF->Text.IsEmpty())
WhereStr = WhereStr + " and WoCode<='" + Trim(seWoCodeT->Text) + "'";
else
WhereStr = WhereStr + " and WoCode>='" + seWoCodeF->Text + "' and WoCode<='" + seWoCodeT->Text + "'";
}
}
if(chkWoSdate->Checked){
if(deWoSdateT->Text.IsEmpty())
WhereStr = WhereStr + " and WoSdate>='" + FormatDateTime("yyyy-mm-dd",deWoSdateF->Date) + "'";
else{
if(deWoSdateF->Text.IsEmpty())
WhereStr = WhereStr + " and WoSdate<='" + FormatDateTime("yyyy-mm-dd",deWoSdateT->Date) + "'";
else
WhereStr = WhereStr + " and WoSdate>='" + FormatDateTime("yyyy-mm-dd",deWoSdateF->Date) + "' and WoSdate<='" + FormatDateTime("yyyy-mm-dd",deWoSdateT->Date) + "'";
}
}
if(chkWoRdate->Checked){
if(deWoRdateT->Text.IsEmpty())
WhereStr = WhereStr + " and WoRdate>='" + FormatDateTime("yyyy-mm-dd",deWoRdateF->Date) + "'";
else{
if(deWoRdateF->Text.IsEmpty())
WhereStr = WhereStr + " and WoRdate<='" + FormatDateTime("yyyy-mm-dd",deWoRdateT->Date) + "'";
else
WhereStr = WhereStr + " and WoRdate>='" + FormatDateTime("yyyy-mm-dd",deWoRdateF->Date) + "' and WoRdate<='" + FormatDateTime("yyyy-mm-dd",deWoRdateT->Date) + "'";
}
}
int j=0;
for (int i=0;i < clbWoState->Items->Count;i++)
{
if(clbWoState->Checked[i])
{
if(j == 0)
{
WhereStr = WhereStr + " and (WoStatus=" + AnsiString(i+1);
j = j + 1;
}
else
WhereStr = WhereStr + " or WoStatus=" + AnsiString(i+1);
}
}
if (j > 0)
WhereStr = WhereStr + ")";
j = 0;
for (int i=0;i< clbWoType->Items->Count;i++)
{
if(clbWoType->Checked[i])
{
if(j == 0)
{
WhereStr = WhereStr + " and (WoType=" + AnsiString(i+1);
j = j + 1;
}
else
WhereStr = WhereStr + " or WoType=" + AnsiString(i+1);
}
}
if (j > 0)
WhereStr = WhereStr + ")";
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::InitEditControl()
{
sgWoClose->RowCount=1;
btnClose->Enabled=false;
scWoRoute->ItemIndex=-1;
scWoRoute->Text="";
seWoGoods->Text="";
chkWoCode->Checked=false;
seWoCodeF->Text="";
seWoCodeT->Text="";
chkWoSdate->Checked=false;
deWoSdateF->Text="";
deWoSdateT->Text=g_sdCurDate;
chkWoRdate->Checked=false;
deWoRdateF->Text="";
deWoRdateT->Text=g_sdCurDate;
sbBar->Panels->Items[0]->Text="操作员:"+g_sdUserCode;
sbBar->Panels->Items[1]->Text=g_sdLoginTime;
sbBar->Panels->Items[2]->Text=g_sdCurDate;
sbBar->Panels->Items[3]->Text=g_sdCompanyName;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmWoClose::GetFieldValue(int Index)
{
return ReadFieldValue(comServer,Index);
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::ChangeToBrowseState(bool agree)
{
return;
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::btnClearClick(TObject *Sender)
{
InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::btnQueryClick(TObject *Sender)
{
GetWhereStrToSQL();
FillGridWithData();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::FillGridWithData()
{
AnsiString ItemStr,StatusCode,TypeCode;
if(!WhereStr.IsEmpty())
comServer->FilterString=WideString(WhereStr);
else
comServer->FilterString=WideString("");
comServer->Query();
if(comServer->RecordCount>0)
{
sgWoClose->RowCount=1;
for(int i=0;i<comServer->RecordCount;i++)
{
comServer->LocateByIndex(i);
ItemStr=AnsiString(" ")+
"\t"+ GetFieldValue(fiWoCode)+
"\t"+ GetFieldValue(fiWoGoods)+
"\t"+ GetFieldValue(fiWoQty)+
"\t"+ GetFieldValue(fiWoCQty)+
"\t"+ GetFieldValue(fiWoWQty)+
"\t"+ GetFieldValue(fiWoRdate)+
"\t"+ GetFieldValue(fiWoSdate);
TypeCode= GetFieldValue(fiWoType);
ItemStr= ItemStr + "\t" + GetTypeNameBySwitch(TypeCode);
StatusCode=GetFieldValue(fiWoStatus);
ItemStr= ItemStr + "\t" + GetStatusNameBySwitch(StatusCode);
sgWoClose->AddItem(ItemStr);
}
}
else
sgWoClose->RowCount=1;
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmWoClose::GetTypeNameBySwitch(AnsiString SwitchStr)
{
int ch=StrToInt(SwitchStr);
switch(ch)
{
case 1:
return("常规");
case 2:
return("返工");
case 3:
return("改装");
case 4:
return("委外");
case 5:
return("副产品");
default:
return("");
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall TfrmWoClose::GetStatusNameBySwitch(AnsiString SwitchStr)
{
int ch=StrToInt(SwitchStr);
switch(ch)
{
case 1:
return("预备");
case 2:
return("确认");
case 3:
return("待下达");
case 4:
return("已下达");
case 5:
return("已完工");
default:
return("");
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::FormShow(TObject *Sender)
{
FillComboBox(scWoRoute,"select RoutehCode from sdRouteh order by RoutehCode","RoutehCode");
InitEditControl();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::btnExitClick(TObject *Sender)
{
frmWoClose->Close();
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::sgWoCloseClick(TObject *Sender)
{
int ARow=sgWoClose->Row;
int ACol=sgWoClose->Col;
if(ARow>0 && ACol == 0)
{
if(sgWoClose->Cells[0][ARow]==" ")
{
btnClose->Enabled = true;
sgWoClose->Cells[0][ARow]="√";
}
else
{
sgWoClose->Cells[0][ARow]=" ";
//找到有没有需要结清的
for (int i=1;i<sgWoClose->RowCount;i++)
{
if(sgWoClose->Cells[0][i]=="√")
{
btnClose->Enabled=true;
break;
}
else
btnClose->Enabled=false;
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmWoClose::btnCloseClick(TObject *Sender)
{
long comErrNum;
btnClose->Enabled=false;
for(int i=sgWoClose->RowCount-1; i>0;i--)
{
if(sgWoClose->Cells[0][i]=="√")
{
comServer->LocateByKey(WideString(sgWoClose->Cells[1][i]));
if(!comServer->Eof)
comServer->Close(1);
sgWoClose->Cells[0][i]="";
sgWoClose->RemoveItem(i);
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -