📄 cformquery.pas
字号:
unit CFormQuery;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, CFormBase, CFrameMenu, IWControl, IWCompLabel, IWExtCtrls, jpeg,
IWHTMLControls, IWCompCheckbox, IWCompListbox, IWCompEdit, IWCompButton;
type
TformQuery = class(TformBase)
IWHRule1: TIWHRule;
iwcSex: TIWComboBox;
iwcbSex: TIWCheckBox;
iwcbAge: TIWCheckBox;
iwcCompare: TIWComboBox;
iweAge: TIWEdit;
iwcbCorp: TIWCheckBox;
iwcCorp: TIWComboBox;
iwcbEduLevel: TIWCheckBox;
iwcEduLevel: TIWComboBox;
iwcbEngLevel: TIWCheckBox;
iwcEngLevel: TIWComboBox;
iwcbTechLevel: TIWCheckBox;
iwcTech: TIWComboBox;
iwcTechLevel: TIWComboBox;
IWHRule2: TIWHRule;
iwbQuery: TIWButton;
IWButton2: TIWButton;
procedure IWAppFormCreate(Sender: TObject);
procedure iwbQueryClick(Sender: TObject);
private
function GetFilterAge: Boolean;
function GetFilterCorp: Boolean;
function GetFilterEduLevel: Boolean;
function GetFilterEngLevel: Boolean;
function GetFilterSex: Boolean;
function GetFilterTech: Boolean;
function GetMultiFilter: Boolean;
function GetFilterConcatStr: string;
{ Private declarations }
public
{ Public declarations }
FSexList,
FCorpList,
FEduLevelList,
FEngLevelList,
FTechList,
FTechLevelList: TStrings;
function ValidateInput: Boolean;
published
property FilterSex: Boolean read GetFilterSex;
property FilterAge: Boolean read GetFilterAge;
property FilterCorp: Boolean read GetFilterCorp;
property FilterEduLevel: Boolean read GetFilterEduLevel;
property FilterEngLevel: Boolean read GetFilterEngLevel;
property FilterTech: Boolean read GetFilterTech;
property MultiFilter: Boolean read GetMultiFilter;
property FilterConcatStr: string read GetFilterConcatStr;
end;
var
formQuery: TformQuery;
implementation
uses CWebUtils, DatamoduleUnit, CFormHumanList;
{$R *.dfm}
function TformQuery.GetFilterAge: Boolean;
begin
result := iwcbAge.Checked;
end;
function TformQuery.GetFilterConcatStr: string;
begin
if MultiFilter then
result := ' and '
else
result := '';
end;
function TformQuery.GetFilterCorp: Boolean;
begin
Result := iwcbCorp.Checked;
end;
function TformQuery.GetFilterEduLevel: Boolean;
begin
Result := iwcbEduLevel.Checked;
end;
function TformQuery.GetFilterEngLevel: Boolean;
begin
Result := iwcbEngLevel.Checked;
end;
function TformQuery.GetFilterSex: Boolean;
begin
Result := iwcbSex.Checked;
end;
function TformQuery.GetFilterTech: Boolean;
begin
Result := iwcbTechLevel.Checked;
end;
function TformQuery.GetMultiFilter: Boolean;
var
I: Integer;
begin
Result := False;
I := 0;
if FilterSex then
Inc(I);
if FilterCorp then
Inc(I);
if FilterEduLevel then
Inc(I);
if FilterEngLevel then
Inc(I);
if FilterAge then
Inc(I);
if FilterTech then
Inc(I);
Result := I > 1;
end;
procedure TformQuery.IWAppFormCreate(Sender: TObject);
begin
inherited;
//初始化各个ComboBox
with dmHR do
begin
FCorpList := GetDataDicList(badoCorp, 'CorpID', 'ChnName');
FillValueToCombo(iwcCorp, FCorpList);
FSexList := GetDataDicList(badoSex, 'SexCode', 'SexName');
FillValueToCombo(iwcSex, FSexList);
FEduLevelList := GetDataDicList(badoEduLevel, 'EduLevelCode',
'EduLevelName');
FillValueToCombo(iwcEduLevel, FEduLevelList);
FEngLevelList := GetDataDicList(badoEngLevel, 'EngLevelCode',
'EngLevelName');
FillValueToCombo(iwcEngLevel, FEngLevelList);
FTechList := GetDataDicList(badoTech, 'TechCode', 'Name');
FillValueToCombo(iwcTech, FTechList);
FTechLevelList := GetDataDicList(badoTechLevel, 'TechLevel', 'LevelName');
FillValueToCombo(iwcTechLevel, FTechLevelList);
end;
end;
procedure TformQuery.iwbQueryClick(Sender: TObject);
var
SQuery: string;
SWhere: string;
begin
inherited;
//有效性校验
if not ValidateInput then
Exit;
if not FilterTech then
SQuery := 'Select * from TblHuman Where '
else
SQuery := 'Select TblHuman.* FROM TblHuman INNER JOIN TblHumanTech ON (TblHuman.HID = TblHumanTech.HID) AND (TblHuman.CorpID = TblHumanTech.CorpID) '
+ #13#10 +
format('Where (TblHumanTech.TechCode=%s) and (TblHumanTech.TechLevel=%s) ',
[GetKeyFromCombo(iwcTech, FTechList), GetKeyFromCombo(iwcTechLevel,
FTechLevelList)]);
if FilterSex then
begin
if FilterTech then
SWhere := ' and ' + format(' (SexCode=''%s'')',
[GetKeyFromCombo(iwcSex, FSexList)])
else
SWhere := format(' (SexCode=''%s'')',
[GetKeyFromCombo(iwcSex, FSexList)]);
end;
if FilterAge then
SWhere := SWhere + FilterConcatStr + Format('(Age%s%s) ', [iwcCompare.Text,
iweAge.Text]);
if FilterCorp then
SWhere := SWhere + FilterConcatStr + Format('(CorpID=%s)',
[GetKeyFromCombo(iwcCorp, FCorpList)]);
if FilterEduLevel then
SWhere := SWhere + FilterConcatStr + Format('(EduLevelCode=%s)',
[GetKeyFromCombo(iwcEduLevel, FEduLevelList)]);
if FilterEngLevel then
SWhere := SWhere + FilterConcatStr + Format('(EngLevelCode=%s)',
[GetKeyFromCombo(iwcEngLevel, FEngLevelList)]);
SQuery := SQuery + SWhere;
with dmhr do
begin
badoHuman.Active := False;
badoHuman.CommandText := SQuery;
badoHuman.Active := True;
end;
Move(TFormHumanList);
end;
function TformQuery.ValidateInput;
begin
//校验输入的有效性
Result := False;
if (not FilterSex) and (not FilterAge) and (not FilterCorp) and (not
FilterEduLevel) and (not FilterEngLevel) and (not FilterTech) then
begin
WebApplication.ShowMessage('必须指定至少一个限定条件');
Exit;
end;
if FilterAge then
if StrToIntDef(iweAge.Text, -1) = -1 then
begin
WebApplication.ShowMessage('无效的数字');
Exit;
end;
Result := True;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -