📄 quform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "QuForm.h"
#include "WnQuery.h"
#include "CommFunction.h"
#include "sdenumtype.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "fpanel"
#pragma link "SDComboBox"
#pragma link "SDGrid"
#pragma link "SDEdit"
#pragma link "DateEdit"
#pragma resource "*.dfm"
#include "midclass.h"
TfrmQuForm *frmQuForm;
//---------------------------------------------------------------------------
__fastcall TfrmQuForm::TfrmQuForm(TComponent* Owner)
: TForm(Owner)
{
FormQuery=NewDcomAppSvr(euSdFormQuery);
temRow=1;
m_CreateSqlString="";
scBool->Text ="";
scLogic->Text="";
seQuery->Text="";
sgQuery->Row=-1;
sgQuery->Cells[0][0] = "查询关系";
sgQuery->Cells[1][0] = " 查询项目";
sgQuery->Cells[2][0] = " 查询条件";
scLogic->AddItems("等于","=");
scLogic->AddItems("大于",">");
scLogic->AddItems("小于","<");
scLogic->AddItems("不大于","=>");
scLogic->AddItems("不小于",">=");
scLogic->AddItems("不等于","<>");
scLogic->AddItems("最接近","≈");
scLogic->ItemIndex=0;
}
__fastcall TfrmQuForm::TfrmQuForm(TComponent* Owner,AnsiString FormName)
: TForm(Owner)
{
FFormName=FormName;
FormQuery=NewDcomAppSvr(euSdFormQuery);
temRow=1;
m_CreateSqlString="";
scBool->Text ="";
seQuery->Text="";
sgQuery->Cells[0][0] = "查询关系";
sgQuery->Cells[1][0] = " 查询项目";
sgQuery->Cells[2][0] = " 查询条件";
scBool->AddItems(" 是","1");
scBool->AddItems(" 否","0");
scLogic->AddItems("等于","=");
scLogic->AddItems("大于",">");
scLogic->AddItems("小于","<");
scLogic->AddItems("不大于","<=");
scLogic->AddItems("不小于",">=");
scLogic->AddItems("不等于","<>");
scLogic->AddItems("最接近","≈");
scLogic->ItemIndex=0;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::FormCreate(TObject *Sender)
{
AnsiString m_Sql;
FormQuery->FilterString="FORMQUERYNAME='"+FFormName+"'";
FormQuery->OrderString="FORMQUERYLINE";
FormQuery->Query();
for(int i=0;i<FormQuery->RecordCount;i++)
{
FormQuery->LocateByIndex(i);
ListItem->Items->Strings[i]=FormQuery->FieldValue[fiFormQueryDesc];
}
if(FormQuery->RecordCount>0)
{
FormQuery->MoveFirst();
ListItem->ItemIndex=0;
FormQuerytype(FormQuery->FieldValue[fiFormQueryType]);
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::btRemoveClick(TObject *Sender)
{
int i;
i=sgQuery->Row;
if(temRow==1)
return ;
for(;i<sgQuery->RowCount;i++)
{
if(i==1)
sgQuery->Cells[0][i]="";
else
sgQuery->Cells[0][i]=sgQuery->Cells[0][1+i];
sgQuery->Cells[1][i]=sgQuery->Cells[1][1+i];
sgQuery->Cells[2][i]=sgQuery->Cells[2][1+i];
}
temRow--;
if(temRow==1)
{
sgQuery->RowCount=2;
RadioNull->Checked=true;
}
else
sgQuery->RowCount=temRow;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::btReSetClick(TObject *Sender)
{
for(int i=1;i<sgQuery->RowCount;i++)
{
sgQuery->Cells[0][i]="";
sgQuery->Cells[1][i]="";
sgQuery->Cells[2][i]="";
}
scLogic->ItemIndex=0;
temRow=1;
sgQuery->RowCount=2;
RadioNull->Checked=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::btOkClick(TObject *Sender)
{
AnsiString TempVal;
for(int i=1;i<temRow;i++)
{
TempVal=sgQuery->Cells[2][i];
if(TempVal.Pos("≈")!=0)
{
TempVal=" like '%"+TempVal.SubString(4,TempVal.Length()-4)+"%'";
}
m_CreateSqlString=m_CreateSqlString+sgQuery->Cells[0][i]+sgQuery->Cells[1][i]+TempVal;
}
m_CancelQuery=false;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::btCacelClick(TObject *Sender)
{
m_CancelQuery=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::btAddClick(TObject *Sender)
{
AnsiString YesNo;
if(ListItem->ItemIndex==-1)
return;
if(temRow==1&&RadioNull->Checked==false)
{
::MessageBox(Handle,"不能选择—或者、并且。","错误",MB_OK|MB_ICONSTOP);
return;
}
if(temRow!=1&&RadioNull->Checked==true)
{
::MessageBox(Handle,"请选择—或者、并且。","错误",MB_OK|MB_ICONSTOP);
return;
}
if(RadioNull->Checked==true)
YesNo=" ";
else if(RadioAnd->Checked==true)
YesNo=" and ";
else if(RadioOr->Checked==true)
YesNo=" or ";
sgQuery->Cells[0][temRow]=" "+YesNo+" ";
FormQuery->LocateByIndex(ListItem->ItemIndex);
sgQuery->Cells[1][temRow]=FormQuery->FieldValue[fiFormQueryField];
if(FormQuery->FieldValue[fiFormQueryType]=="1")
sgQuery->Cells[2][temRow]=scLogic->ItemData[1]+"'"+seQuery->Text+"'";
if(FormQuery->FieldValue[fiFormQueryType]=="2")
sgQuery->Cells[2][temRow]=scLogic->ItemData[1]+seQuery->Text;
if(FormQuery->FieldValue[fiFormQueryType]=="3")
sgQuery->Cells[2][temRow]=scLogic->ItemData[1]+scBool->ItemData[1];
if(FormQuery->FieldValue[fiFormQueryType]=="4")
sgQuery->Cells[2][temRow]=scLogic->ItemData[1]+"'"+sdQuery->Text+"'";
temRow++;
sgQuery->RowCount=temRow;
sgQuery->Row=temRow-1;
if(temRow==2)
RadioAnd->Checked=true;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::ListItemClick(TObject *Sender)
{
FormQuery->LocateByIndex(ListItem->ItemIndex);
seQuery->Text="";
FormQuerytype(FormQuery->FieldValue[fiFormQueryType]);
if(seQuery->Visible)
seQuery->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::scLogicChange(TObject *Sender)
{
if(seQuery->Visible)
seQuery->SetFocus();
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::FormClose(TObject *Sender,
TCloseAction &Action)
{
delete FormQuery;
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::seQueryButtonClick(TObject *Sender)
{
if(seQuery->ButtonVisible)
{
AnsiString SqlStr;
TfrmWnQuery *p;
FormQuery->LocateByIndex(ListItem->ItemIndex);
SqlStr=FormQuery->FieldValue[fiFormQueryWhere];
if(SqlStr.IsEmpty())
return;
try
{
StartWaitForm("正在查询,请稍候...");
p=new TfrmWnQuery(this,"查询项目查询",SqlStr);
}
__finally
{
EndWaitForm();
}
if(p->ShowModal()==mrOk)
{
seQuery->Text=p->ColData[1];
}
delete p;
}
}
//---------------------------------------------------------------------------
void __fastcall TfrmQuForm::FormQuerytype(AnsiString type)
{
int m_Type;
m_Type=type.ToInt();
switch(m_Type)
{
case 1:
seQuery->Visible=true;
sdQuery->Visible=false;
scBool->Visible=false;
scLogic->ItemIndex=0;
scLogic->Enabled=true;
if(FormQuery->FieldValue[fiFormQueryBtn]=="1")
seQuery->ButtonVisible=true;
else
seQuery->ButtonVisible=false;
seQuery->CharType=ctNormal;
break;
case 2:
seQuery->Visible=true;
sdQuery->Visible=false;
scBool->Visible=false;
scLogic->ItemIndex=0;
scLogic->Enabled=true;
if(FormQuery->FieldValue[fiFormQueryBtn]=="1")
seQuery->ButtonVisible=true;
else
seQuery->ButtonVisible=false;
seQuery->CharType=ctMathematic;
break;
case 3:
scBool->Visible=true;
scBool->ItemIndex=0;
seQuery->Visible=false;
sdQuery->Visible=false;
scLogic->Enabled=false;
scLogic->ItemIndex=0;
break;
case 4:
sdQuery->Visible=true;
scBool->Visible=false;
seQuery->Visible=false;
scLogic->ItemIndex=0;
scLogic->Enabled=true;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -