OBS/Adminhilfe/Pax Script Beispiel Ereignisbehandlung: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Ecks (Diskussion | Beiträge) |
Keine Bearbeitungszusammenfassung |
||
| Zeile 326: | Zeile 326: | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
</pre> | </pre> | ||
[[Kategorie:Adminhilfe]] | |||
Aktuelle Version vom 8. September 2016, 09:40 Uhr
SQL-Export-Script mit Ereignisbehandlung
//-----------------------------------------------------------------------------
// Unit Name: SqlExporter
// Author: Jr
// Date: 04-Aug-2011
// Purpose:
// History:
//
// Folgende implementiere Funktionen stehen dem SQL-Exporter zur Verfügung
//
// function GetSqlExportStr(oForm: TxForm): String;
// procedure SetSQlExportStr(oForm: TxForm; cSql: String);
// function RunSQlExporter(oForm: TxForm; lAuto:Boolean): Boolean;
// function SaveDataSQlExporter(oForm: TxForm; cFileName: String; nWahl: Integer; lAuto: Boolean): Boolean;
// function ShowDataSQlExporter(oForm: TxForm): Boolean;
//
//-----------------------------------------------------------------------------
type
TEventHandler = class
procedure MyFormClose(Sender: TObject; var Action: TCloseAction);
procedure My_Bt_OK(Sender: TObject);
procedure My_Bt_Abbruch(Sender: TObject);
end;
var oForm : TxForm;
oParent : TxForm;
EventHandler : TEventHandler;
lCheck : Boolean;
const
CSV = 2;
EXCEL = 3;
HTML = 4; //Nur im Grid Möglich
//-----------------------------------------------------------------------------
// Procedure: Not available
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Not available
// Result: Not available
//-----------------------------------------------------------------------------
procedure ConvertResourceData(cName:String;oComponent:TComponent);
begin
//Hier können noch veränderungen vorgenommen werden
//DebugLine(oComponent.ClassName);
if (oComponent.ClassName = 'TPanel') then begin
TPanel(oComponent).Caption := '';
end;
end;
//-----------------------------------------------------------------------------
// Procedure: Not available
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Not available
// Result: Not available
//-----------------------------------------------------------------------------
// Die nächste Zeile nicht entfernen
//$RESOURCE START//
Procedure Init_Resource(Sender: TWinControl);
var
MainPanel:TPanel;
Label1:TLabel;
Label2:TLabel;
bt_ok:TSpeedButton;
bt_abbruch:TSpeedButton;
MaskEdit1:TMaskEdit;
MaskEdit2:TMaskEdit;
begin
MainPanel:=TPanel.Create(Sender);
with MainPanel do begin
name:='MainPanel';
parent := Sender;
Left := 5;
Top := 7;
Width := 223;
Height := 119;
TabOrder := 0;
Label1:=TLabel.Create(Sender);
with Label1 do begin
name:='Label1';
parent:=MainPanel;
Left := 22;
Top := 24;
Width := 87;
Height := 13;
Caption := 'Von Warengruppe';
ConvertResourceData('Label1',Label1);
end;
Label2:=TLabel.Create(Sender);
with Label2 do begin
name:='Label2';
parent:=MainPanel;
Left := 22;
Top := 45;
Width := 94;
Height := 13;
Caption := 'Nach Warengruppe';
ConvertResourceData('Label2',Label2);
end;
bt_ok:=TSpeedButton.Create(Sender);
with bt_ok do begin
name:='bt_ok';
parent:=MainPanel;
Left := 22;
Top := 73;
Width := 91;
Height := 27;
Caption := '&OK';
ConvertResourceData('bt_ok',bt_ok);
end;
bt_abbruch:=TSpeedButton.Create(Sender);
with bt_abbruch do begin
name:='bt_abbruch';
parent:=MainPanel;
Left := 126;
Top := 73;
Width := 78;
Height := 28;
Caption := '&Abbruch';
ConvertResourceData('bt_abbruch',bt_abbruch);
end;
MaskEdit1:=TMaskEdit.Create(Sender);
with MaskEdit1 do begin
name:='MaskEdit1';
parent:=MainPanel;
Left := 130;
Top := 17;
Width := 53;
Height := 21;
EditMask := ' 000;1;_';
TabOrder := 0;
Text := ' ';
ConvertResourceData('MaskEdit1',MaskEdit1);
end;
MaskEdit2:=TMaskEdit.Create(Sender);
with MaskEdit2 do begin
name:='MaskEdit2';
parent:=MainPanel;
Left := 129;
Top := 40;
Width := 53;
Height := 21;
Constraints.MaxHeight := 111;
EditMask := ' 000;1;_';
TabOrder := 1;
Text := ' ';
ConvertResourceData('MaskEdit2',MaskEdit2);
end;
ConvertResourceData('MainPanel',MainPanel);
end;
end;
//$RESOURCE END//
// Diese vorherige Zeile nicht entfernen
//-----------------------------------------------------------------------------
// Procedure: TEventHandler.MyFormClose
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Sender: TObject; var Action: TCloseAction
// Result:
//-----------------------------------------------------------------------------
procedure TEventHandler.MyFormClose(Sender: TObject; var Action: TCloseAction);
var oComponent : TComponent;
cVonWGR : String;
cBisWGR : String;
cSql : String;
begin
if (lCheck) then begin
Action := caNone;
cBisWGR := '';
cVonWGR := '';
oComponent := oForm.FindComponent('MaskEdit1');
if (Assigned(oComponent)) then begin
cVonWGR := TMaskEdit(oComponent).Text;
end;
oComponent := oForm.FindComponent('MaskEdit2');
if (Assigned(oComponent)) then begin
cBisWGR := TMaskEdit(oComponent).Text;
end;
if (Empty(cVonWgr) or Empty(cBisWgr)) then begin
Meldung('Von und Bis müssen gefüllt sein!');
end else begin
cSQL := GetSqlExportStr(oParent);
if (InStr('$1',cSQL) and InStr('$2',cSQL)) then begin
cSQL := StrTran(cSql,'$1',cVonWGR);
cSQL := StrTran(cSql,'$2',cBisWGR);
SetSqlExportStr(oParent,cSQL);
Action := caFree;
end else begin
Meldung('SQL Statement enthält keine Platzhalter');
Action := caFree;
end;
end;
end;
if (Action = caFree) then begin
Free;
end;
end;
//-----------------------------------------------------------------------------
// Procedure: TEventHandler.My_Bt_OK
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Sender: TObject
// Result:
//-----------------------------------------------------------------------------
procedure TEventHandler.My_Bt_OK(Sender: TObject);
begin
lCheck := True;
oForm.Close;
end;
//-----------------------------------------------------------------------------
// Procedure: TEventHandler.My_Bt_Abbruch
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Sender: TObject
// Result:
//-----------------------------------------------------------------------------
procedure TEventHandler.My_Bt_Abbruch(Sender: TObject);
begin
lCheck := False;
oForm.Close;
end;
//-----------------------------------------------------------------------------
// Procedure: Not available
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Not available
// Result: Not available
//-----------------------------------------------------------------------------
procedure Init_MainForm();
var oComponent : TComponent;
begin
oForm := CreateXForm(TxForm);
EventHandler := TEventHandler.Create();
Init_Resource(oForm);
oForm.OnClose := EventHandler.MyFormClose;
oComponent := oForm.FindComponent('bt_ok');
if (Assigned(oComponent)) then begin
TSpeedButton(oComponent).OnClick := EventHandler.My_Bt_OK;
end;
oComponent := oForm.FindComponent('bt_abbruch');
if (Assigned(oComponent)) then begin
TSpeedButton(oComponent).OnClick := EventHandler.My_Bt_Abbruch;
end;
oComponent := oForm.FindComponent('MainPanel');
if (Assigned(oComponent)) then begin
TPanel(oComponent).Left := 0;
TPanel(oComponent).Top := 0;
oForm.ClientHeight := TPanel(oComponent).Height;
oForm.ClientWidth := TPanel(oComponent).Width;
oForm.Constraints.MinHeight := oForm.Height;
oForm.Constraints.MaxHeight := oForm.Height;
oForm.Constraints.MinWidth := oForm.Width;
oForm.Constraints.MaxWidth := oForm.Width;
end else begin
oForm.Width := 400;
oForm.Height := 200;
end;
end;
//-----------------------------------------------------------------------------
// Procedure: Not available
// Author: Jr
// Date: 04-Aug-2011
// Arguments: Not available
// Result: Not available
//-----------------------------------------------------------------------------
procedure StartProc(Sender: TxForm; cParameter: String);
begin
oParent := Sender;
lCheck := False;
Init_MainForm();
oForm.Position := poMainFormCenter;
oForm.ShowModal;
end;
//-----------------------------------------------------------------------------