📄 ag_main.pas
字号:
if Function_DB_ReadRight.GetFunctionResourceRight <> 1 then
begin
MessageDlg('对不起,您没有权限执行当前工作!', mtInformation, [mbOk], 0);
Exit;
end;
WriteToHistroy('综合查询', Now, Time, '用户《' + FrmMain.UserName +
'》于服务器' +
FrmMain.ServerName + '执行了<综合查询>', FrmMain.UserName);
GQ_UQueryMain.SetWork;
end;
procedure TFrmAG_Main.N1Click(Sender: TObject);
begin
TEdit(PopupMenu1.PopupComponent).Text := '';
end;
procedure TFrmAG_Main.DBGrid1DblClick(Sender: TObject);
begin
if ((ReportType = '历史结果') and (HistroyDone)) then
Exit;
{if Panel4.Align <> alNone then
begin
Panel1.Align := alNone;
Panel4.Align := alNone;
end
else
begin
Panel1.Align := alLeft;
Panel4.Align := alTop;
end;}
if Panel1.Align = alLeft then
begin
Panel1.Align := alNone;
Panel4.Align := alNone;
end
else
begin
Panel1.Align := alLeft;
Panel1.Width := 314;
Panel4.Align := alTop;
Panel4.Height := 113;
end;
end;
procedure TFrmAG_Main.GroupingCheckBoxClick(Sender: TObject);
var
i: integer;
ReportFieldConstraint: TReportFieldConstraint;
begin
for i := 0 to ConstraintComponentsList.Count - 1 do
begin
if i = TCheckBox(Sender).Tag then
Continue;
ReportFieldConstraint :=
TReportFieldConstraint(ConstraintComponentsList.Objects[i]);
if ReportFieldConstraint.ACheckBox.Checked then
ReportFieldConstraint.GroupingCheckBox.Checked :=
TCheckBox(Sender).Checked;
end;
end;
{-------------------------------------------------------------------------------}
function TFrmAG_Main.ReadReportList(ReportType: string): Boolean;
var
ti: TIniFile;
i, j, ReportTypeCount, ReportCount: integer;
CReportType, ReportName: string;
begin
Result := False;
Screen.Cursor := crHourGlass;
ti := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'system.ini');
ReportTypeCount := ti.ReadInteger('System', 'ReportTypeCount', 0);
if ReportTypeCount = 0 then
begin
ti.Free;
Screen.Cursor := crDefault;
Exit;
end;
for i := 1 to ReportTypeCount do
begin
CReportType := ti.ReadString('ReportTypeList', 'ReportType' + IntToStr(i),
'');
if ((ReportType <> '统计分析子系统') and (ReportType <> CReportType)) then
Continue;
if CReportType = '' then
Continue;
ReportCount := ti.ReadInteger(CReportType, 'ReportCount', 0);
if ReportCount = 0 then
Continue;
for j := 1 to ReportCount do
begin
ReportName := ti.ReadString(CReportType, 'Report' + IntToStr(j), '');
if ReportName = '' then
Continue;
CreateToolButton(ReportName);
end;
end;
ti.Free;
Result := True;
Screen.Cursor := crDefault;
end;
function TFrmAG_Main.GetReportFieldsMessage: Boolean;
var
ADOQuery: TADOQuery;
ReportFieldMessage: TReportFieldMessage;
i: integer;
begin
Result := False;
if ReportCName = '' then
Exit;
ReportEName := PublicUnit.GetReportEName(ReportCName);
ADOQuery := TADOQuery.Create(Self);
with ADOQuery do
begin
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+ FrmMain.DbUser + ';Password=' + FrmMain.DbPass + ';Initial Catalog=' +
FrmMain.DbName + ';Data Source=' + PublicUnit.ServerName;
Sql.Add('Select *');
Sql.Add('From ' + ReportEName);
try
Open;
except
Screen.Cursor := crDefault;
ShowMessage('数据库无法打开或表《' + ReportEName +
'》无法打开,请与系统管理员联系!');
Exit;
end;
if ReportFields.Count <> 0 then
for i := ReportFields.Count - 1 downto 0 do
ReportFields.Objects[i].Free;
ReportFields.Clear;
while not Eof do
begin
ReportFieldMessage := TReportFieldMessage.Create;
ReportFieldMessage.FieldName := FieldByName('FieldName').Asstring;
ReportFieldMessage.FieldType := FieldByName('FieldType').Asstring;
ReportFieldMessage.DataType := FieldByName('DataType').Asstring;
ReportFieldMessage.Visible := (FieldByName('Visible').AsInteger = 1);
ReportFieldMessage.OrderType := '';
ReportFieldMessage.Constraints := FieldByName('Const').Asstring;
ReportFieldMessage.RpVisible := (FieldByName('Visible').AsInteger = 1);
ReportFields.AddObject(ReportFieldMessage.FieldName, ReportFieldMessage);
Next;
end;
Close;
Free;
end;
Result := True;
end;
function TFrmAG_Main.SetReportRequest: Boolean;
var
i: integer;
CReportFieldMessage: TReportFieldMessage;
CReportFieldConstraint: TReportFieldConstraint;
OrderType: array[0..3] of string;
MeasureHaving, DementionHaving: Boolean;
begin
Result := False;
OrderType[0] := '';
OrderType[1] := 'Asc';
OrderType[2] := 'Desc';
Dementions.Clear;
Measures.Clear;
MeasureHaving := False;
DementionHaving := False;
for i := 0 to ReportFields.Count - 1 do
begin
CReportFieldMessage := TReportFieldMessage(ReportFields.Objects[i]);
CReportFieldConstraint :=
TReportFieldConstraint(ConstraintComponentsList.Objects[i]);
CReportFieldMessage.FieldName := Copy(CReportFieldConstraint.ALable.Caption,
1, Length(CReportFieldConstraint.ALable.Caption) - 2);
CReportFieldMessage.Constraints := CReportFieldConstraint.AEdit.Text;
//if CReportFieldMessage.Constraints<>'' then CReportFieldConstraint.ACheckBox.Checked:=True;
CReportFieldMessage.Visible := CReportFieldConstraint.ACheckBox.Checked;
CReportFieldMessage.OrderType :=
OrderType[CReportFieldConstraint.AComboBox.ItemIndex];
if not CReportFieldConstraint.ACheckBox.Checked then
CReportFieldConstraint.GroupingCheckBox.Checked := False;
CReportFieldMessage.Grouping :=
CReportFieldConstraint.GroupingCheckBox.Checked;
if CReportFieldMessage.FieldType = '指标' then
begin
Measures.AddObject(ReportFields[i], CReportFieldMessage);
if CReportFieldMessage.Visible then
MeasureHaving := True
end
else
begin
Dementions.AddObject(ReportFields[i], CReportFieldMessage);
if CReportFieldMessage.Visible then
DementionHaving := True
end;
end;
if ((not MeasureHaving) or (not DementionHaving)) then
Exit;
Result := True;
end;
{-------------------------------------------------------------------------------}
procedure TFrmAG_Main.CreateConstraintComponents;
var
CReportFieldMessage: TReportFieldMessage;
ReportFieldConstraint: TReportFieldConstraint;
ACheckBox: TCheckBox;
ALabel: TLabel;
AEdit: TEdit;
AComboBox: TComboBox;
GroupingCheckBox: TCheckBox;
i, ATop: integer;
begin
if ConstraintComponentsList.Count <> 0 then
for i := ConstraintComponentsList.Count - 1 downto 0 do
ConstraintComponentsList.Objects[i].Free;
ConstraintComponentsList.Clear;
ATop := 65;
for i := 0 to ReportFields.Count - 1 do
begin
CReportFieldMessage := TReportFieldMessage(ReportFields.Objects[i]);
ReportFieldConstraint := TReportFieldConstraint.Create;
ACheckBox := TCheckBox.Create(Application);
ALabel := TLabel.Create(Application);
AEdit := TEdit.Create(Application);
AComboBox := TComboBox.Create(Application);
GroupingCheckBox := TCheckBox.Create(Application);
ReportFieldConstraint.ACheckBox := ACheckBox;
ReportFieldConstraint.ALable := ALabel;
ReportFieldConstraint.AEdit := AEdit;
ReportFieldConstraint.AComboBox := AComboBox;
ReportFieldConstraint.GroupingCheckBox := GroupingCheckBox;
ConstraintComponentsList.AddObject(CReportFieldMessage.FieldName,
ReportFieldConstraint);
if CReportFieldMessage.RpVisible then
Inc(ATop, 25);
with ACheckBox do
begin
Parent := Panel1;
Top := ATop;
Left := 1;
Width := 12;
Caption := '';
Checked := CReportFieldMessage.RpVisible;
Hint := '是否需要该数据项';
ShowHint := True;
Tag := i;
Visible := CReportFieldMessage.RpVisible;
end;
with ALabel do
begin
Parent := Panel1;
Top := ATop + 3;
Left := 15;
Width := 85;
Caption := CReportFieldMessage.FieldName + ':';
if CReportFieldMessage.FieldType = '维码' then
Font.Color := clBlue
else if CReportFieldMessage.FieldType = '维属性' then
Font.Color := clGreen
else if CReportFieldMessage.FieldType = '指标' then
Font.Color := clRed;
Visible := CReportFieldMessage.RpVisible;
end;
with AEdit do
begin
Parent := Panel1;
Top := ATop;
Left := 97;
Width := 165;
Text := CReportFieldMessage.Constraints;
Tag := i;
ReadOnly := True;
Hint := '条件编辑框,请双击该框';
ShowHint := True;
PopupMenu := PopupMenu1;
if CReportFieldMessage.DataType = '日期' then
OnDblClick := ChangeDateConstriant
else if CReportFieldMessage.DataType = '字符' then
OnDblClick := ChangeCharConstriant
else if CReportFieldMessage.DataType = '时间' then
OnDblClick := ChangeTimeConstriant
else if CReportFieldMessage.DataType = '数字' then
OnDblClick := ChangeNumConstriant;
Visible := CReportFieldMessage.RpVisible;
end;
with AComboBox do
begin
Parent := Panel1;
Top := ATop;
Left := 265;
Width := 33;
Style := csDropDownList;
Items.Add('无');
Items.Add('正');
Items.Add('逆');
ItemIndex := 0;
Hint := '数据项是否需要排序';
ShowHint := True;
Tag := i;
Visible := CReportFieldMessage.RpVisible;
end;
with GroupingCheckBox do
begin
Parent := Panel1;
Top := ATop;
Left := 300;
Width := 33;
Caption := '';
Checked := False;
Hint := '是否需要按该数据项进行小计';
ShowHint := True;
Tag := i;
Visible := ((CReportFieldMessage.RpVisible) and
(CReportFieldMessage.FieldType <> '指标'));
OnClick := GroupingCheckBoxClick;
end;
end;
end;
procedure TFrmAG_Main.ChangeDateConstriant(Sender: TObject);
var
s, s2: string;
BeginDate, EndDate: TDate;
begin
if not (Sender is TEdit) then
Exit;
s := TEdit(Sender).Text;
if s <> '' then
begin
BeginDate := StrToDate(Copy(s, 10, Pos(''' and', s) - 10));
s2 := Copy(s, Pos('and ''', s) + 5, 1000);
EndDate := StrToDate(Copy(s2, 1, Length(s2) - 1));
end
else
begin
BeginDate := Now;
EndDate := Now;
end;
if AG_SelDate.SetWork(BeginDate, EndDate) then
TEdit(Sender).Text := 'Between ''' + DateToStr(BeginDate) + ''' and ''' +
DateToStr(EndDate) + '''';
end;
procedure TFrmAG_Main.ChangeCharConstriant(Sender: TObject);
var
CFieldName, s: string;
begin
if not (Sender is TEdit) then
Exit;
s := TEdit(Sender).Text;
CFieldName :=
TReportFieldMessage(ReportFields.Objects[TEdit(Sender).Tag]).FieldName;
if AG_Selchar.SetWork(CFieldName, s) then
if s <> '' then
TEdit(Sender).Text := 'In (' + s + ')'
else
TEdit(Sender).Text := '';
end;
procedure TFrmAG_Main.ChangeTimeConstriant(Sender: TObject);
var
s, s2: string;
BeginTime, EndTime: TTime;
begin
if not (Sender is TEdit) then
Exit;
s := TEdit(Sender).Text;
if s <> '' then
begin
BeginTime := StrToTime(Copy(s, 10, Pos(''' and', s) - 10));
s2 := Copy(s, Pos('and ''', s) + 5, 1000);
EndTime := StrToTime(Copy(s2, 1, Length(s2) - 1));
end
else
begin
BeginTime := Time();
EndTime := Time();
end;
if AG_SelTime.SetWork(BeginTime, EndTime) then
TEdit(Sender).Text := 'Between ''' + TimeToStr(BeginTime) + ''' and ''' +
TimeToStr(EndTime) + '''';
end;
procedure TFrmAG_Main.ChangeNumConstriant(Sender: TObject);
var
s: string;
BeginNum, EndNum: integer;
begin
if not (Sender is TEdit) then
Exit;
s := TEdit(Sender).Text;
if s <> '' then
begin
BeginNum := StrToInt(Copy(s, 9, Pos(' and', s) - 9));
EndNum := StrToInt(Copy(s, Pos('and ', s) + 4, 1000));
end
else
begin
BeginNum := 0;
EndNum := 1000;
end;
if AG_SelNum.SetWork(BeginNum, EndNum) then
begin
if BeginNum > EndNum then
ShowMessage('您取得的下界大于上界,系统不予采纳,请重试!')
else
TEdit(Sender).Text := 'Between ' + IntToStr(BeginNum) + ' and ' +
IntToStr(EndNum);
end;
end;
procedure TFrmAG_Main.CreateToolButton(ButtonName: string);
var
AToolButton: TToolButton;
begin
AToolButton := TToolButton.Create(ToolBar3);
ToolButtonList.AddObject(ButtonName, AToolButton);
with AToolButton do
begin
Parent := ToolBar3;
Caption := ButtonName;
Cursor := crHandPoint;
AutoSize := True;
OnClick := ToolButtonClick;
end;
end;
procedure TFrmAG_Main.ToolButtonClick(Sender: TObject);
begin
if Panel1.Align = alNone then
DBGrid1DblClick(Sender);
ReportCName := TToolButton(Sender).Caption;
Label1.Visible := False;
DbGrid1.Visible := False;
Label1.Caption := ReportCName;
MyPageDesign.ReportName := '';
if TToolButton(Sender).Caption = '销售额统计' then
MultiFact := True
else
MultiFact := False;
GetReportFieldsMessage;
CreateConstraintComponents;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -