📄 renshiprint.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "RenShiPrint.h"
#include "DM1.h"
#include "PrintSet.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFormRenShiPrint *FormRenShiPrint;
//---------------------------------------------------------------------------
__fastcall TFormRenShiPrint::TFormRenShiPrint(TComponent* Owner)
: TForm(Owner)
{
}
//------------------------------------------
int __fastcall TFormRenShiPrint::CheckTj()
{
if (ComboBoxColumn1->ItemIndex == -1) return 1;
if (ComboBoxTj1->ItemIndex == -1) return 1;
if (Edit1->Text.Trim().IsEmpty()) return 1;
if (pRenShi->FieldByName(ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex])->DataType == ftInteger)
{
try
{
StrToInt(Edit1->Text);
}
catch(...)
{
return 2;
}
return 3;
}
else if (pRenShi->FieldByName(ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex])->DataType == ftSmallint)
{
try
{
StrToInt(Edit1->Text);
}
catch(...)
{
return 2;
}
return 3;
}
else if (pRenShi->FieldByName(ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex])->DataType == ftWord)
{
try
{
StrToInt(Edit1->Text);
}
catch(...)
{
return 2;
}
return 3;
}
else if (pRenShi->FieldByName(ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex])->DataType == ftFloat)
{
try
{
StrToFloat(Edit1->Text);
}
catch(...)
{
return 2;
}
return 3;
}
else if (pRenShi->FieldByName(ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex])->DataType == ftBoolean)
{
if (Edit1->Text.Trim() == "1" || Edit1->Text.Trim() == "0" || Edit1->Text.Trim().LowerCase() == "true" || Edit1->Text.Trim().LowerCase() == "false")
{
if (Edit1->Text.Trim().LowerCase() == "true") Edit1->Text = "1";
else if(Edit1->Text.Trim().LowerCase() == "false") Edit1->Text = "0";
}
else
{
return 2;
}
return 3;
}
else return 4;
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::FormCreate(TObject *Sender)
{
pRenShi = GetQuery("QRenShi");
DataSource1->DataSet = pRenShi;
StringGrid1->Cells[0][0] = "关系";
StringGrid1->Cells[1][0] = "列";
StringGrid1->Cells[2][0] = "条件";
StringGrid1->Cells[3][0] = "值";
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::FormShow(TObject *Sender)
{
pRenShi->Open();
ComboBoxColumn1->Items->Clear();
ComboBoxColumn2->Items->Clear();
for (int i = 0;i < DBGrid1->Columns->Count; i++)
{
ComboBoxColumn1->Items->Add(DBGrid1->Columns->Items[i]->Title->Caption);
ComboBoxColumn2->Items->Add(DBGrid1->Columns->Items[i]->FieldName);
}
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::FormClose(TObject *Sender,
TCloseAction &Action)
{
pRenShi->Close();
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::FormKeyPress(TObject *Sender, char &Key)
{
if(Key==VK_RETURN)
{
SendMessage(this->Handle,WM_NEXTDLGCTL,0,0);
Key=0;
}
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::RBAllClick(TObject *Sender)
{
GroupBoxTj->Visible = false;
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::RBTjClick(TObject *Sender)
{
GroupBoxTj->Visible = true;
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::BitBtnAddClick(TObject *Sender)
{
int nFlag,nRow;
AnsiString sTemp;
nFlag = CheckTj();
if (nFlag == 1)
{
ShowMessage("请输入查询条件!");
return;
}
if (nFlag == 2)
{
ShowMessage("输入的值与该字段的数据类型不匹配!");
Edit1->SetFocus();
return;
}
if (RBAnd->Checked) sTemp = sTemp + " and";
else sTemp = sTemp + " or";
if (nFlag == 3)
{
sTemp = sTemp + " " + ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex] + " " + ComboBoxTj2->Items->Strings[ComboBoxTj1->ItemIndex] + " " + Edit1->Text.Trim();
}
else
{
sTemp = sTemp + " " + ComboBoxColumn2->Items->Strings[ComboBoxColumn1->ItemIndex] + " " + ComboBoxTj2->Items->Strings[ComboBoxTj1->ItemIndex] + " '" + Edit1->Text.Trim() + "'";
}
Memo2->Lines->Add(sTemp);
if (RBAnd->Checked) sTemp = "与";
else sTemp = "或";
nRow = StringGrid1->RowCount - 1;
StringGrid1->Cells[0][nRow] = sTemp;
StringGrid1->Cells[1][nRow] = ComboBoxColumn1->Text;
StringGrid1->Cells[2][nRow] = ComboBoxTj1->Text;
StringGrid1->Cells[3][nRow] = Edit1->Text;
StringGrid1->RowCount +=1;
Edit1->Text = "";
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::BitBtnClearClick(TObject *Sender)
{
for(int i = 1; i < StringGrid1->RowCount ; i++)
{
StringGrid1->Cells[0][i] = "";
StringGrid1->Cells[1][i] = "";
StringGrid1->Cells[2][i] = "";
StringGrid1->Cells[3][i] = "";
}
StringGrid1->RowCount = 2;
Memo2->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::BitBtn1Click(TObject *Sender)
{
if (RBTj->Checked)
{
if (Memo2->Lines->Count < 1 )
{
ShowMessage("请输入查询条件并按'添加'按钮!");
return;
}
}
pRenShi->Close();
pRenShi->SQL->Clear();
pRenShi->SQL->Add("select * from renshi where 1 = 1");
if (RBTj->Checked)
{
pRenShi->SQL->Add(Memo2->Text);
}
pRenShi->Prepared = true;
pRenShi->Open();
}
//---------------------------------------------------------------------------
void __fastcall TFormRenShiPrint::BitBtn2Click(TObject *Sender)
{
TFormPrintSet *FormPrintSet = new TFormPrintSet(this);
FormPrintSet->SetDataSource(pRenShi);
FormPrintSet->SetGrid(DBGrid1);
FormPrintSet->ShowModal();
delete FormPrintSet;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -