RTFormwork/public10/design/U_FormLayOutDesign.pas
2024-10-22 10:10:46 +08:00

555 lines
19 KiB
ObjectPascal
Raw Blame History

unit U_FormLayOutDesign;
interface
uses
Windows, SysUtils, Messages, Classes, Controls, StdCtrls, ComCtrls, Forms,
ExtCtrls, ComObj, DXCORE, ActiveX, cxMemo, cxButtons, Graphics, IniFiles,
Dialogs, Menus, DB, ADODB, cxLabel, BtnEdit, RTComboBox, cxTextEdit, cxMRUEdit,
cxDBData, cxGridLevel, cxButtonEdit, cxCurrencyEdit, cxGridTableView, cxGrid,
cxGridCustomTableView, cxGraphics, cxCalendar, cxCheckBox, cxGridDBTableView,StrUtils,
cxGridDBBandedTableView, cxStyles, cxPc, cxGroupBox, dxLayoutContainer, U_dataLink,
cxCustomData, cxClasses, cxTimeEdit, cxEdit, cxLookAndFeels, dxLayoutControl,
cxLookAndFeelPainters, cxGridCustomView, Buttons, cxDropDownEdit,dxSkinsCore, dxSkinWXI,dxSkinsDefaultPainters;
//function saveLayOut(dxLayoutControl1:TdxLayoutControl; ADOCmd: TADOQuery;mdesignCode:string):Boolean;
function readLayOut(dxLayoutControl1:TdxLayoutControl; ADOTmp: TADOQuery;mdesignCode:string):Boolean;
//function mustInCheck(dxLayoutControl1:TdxLayoutControl ;textFlag:string='*'):Boolean;
procedure SetFormOperRight(app:Tapplication;mParent: TwinControl; mRightCaptions: PWideChar)stdcall;external 'rtCommon.dll' Name 'SetFormOperRight_A';
function getSystemFontSize(ADOTmp: TADOQuery;mStyleCode:PWideChar): Integer;stdcall;external 'rtCommon.dll' Name 'getSystemFontSize_A';
function mustInCheck(app:Tapplication;dxLayoutControl1:TdxLayoutControl;textFlag:PWideChar):boolean;stdcall;external 'rtCommon.dll' Name 'mustInCheck_A';
function isHasDesignRight(ADOTmp: TADOQuery;userId:PWideChar): boolean;stdcall;external 'rtCommon.dll' Name 'isHasDesignRight_A';
function isUseSkin(): boolean;stdcall;external 'rtCommon.dll' Name 'isUseSkin_A';
function isGridNativeSet(): boolean;stdcall;external 'rtCommon.dll' Name 'isGridNativeSet_A';
//function readLayOut(app:Tapplication;dxLayoutControl1:TdxLayoutControl; ADOTmp: TADOQuery;mdesignCode:PWideChar):integer;stdcall;external 'rtCommon.dll' Name 'readLayOut_A';
function saveLayOut(app:Tapplication;dxLayoutControl1:TdxLayoutControl; ADOCmd: TADOQuery;mdesignCode:PWideChar):integer;stdcall;external 'rtCommon.dll' Name 'saveLayOut_A';
procedure layoutDesign(dxLayoutControl1:TdxLayoutControl;ADOTmp: TADOQuery;userId:PWideChar )stdcall;external 'rtCommon.dll' Name 'layoutDesign_A';
procedure SetShowModalHide(mHandle:Thandle;form:Tform)stdcall;external 'rtCommon.dll';
procedure InitStyleData( StyleRepository:TcxStyleRepository;mFontSize:integer);
function GetsysParam(AdoTmp:Tadoquery;StyleRepository:TcxStyleRepository;muserId: pchar; fparam1: pchar): Boolean;
procedure addQryCondition1(Application:Tapplication;AdoTmp:Tadoquery;Panel_zdy:Tpanel;layOut: TdxLayoutControl;mdesignCode:PWideChar;rowCount:integer=4)stdcall;external 'rtCommon.dll' Name 'addQryCondition';
procedure addQryCondition( AdoTmp:Tadoquery;formId:Integer;gridName:string;FlowPanel1:TFlowPanel;rowCount:integer=4);
procedure addQryContionByLay(AdoTmp:Tadoquery;formId:Integer;gridName:string;layOut:TdxLayoutControl;rowCount:integer=4);
procedure initWinData(AdoTmp:TadoQuery;obj:TwinControl;sqlStr:string);
function GetProcedureParam(layoutControl: TdxLayoutControl; EquTag: Integer=0): string;
implementation
uses
U_globalVar;
//
function readLayOut(dxLayoutControl1:TdxLayoutControl; ADOTmp: TADOQuery;mdesignCode:string):Boolean;
var
LayoutStream: TMemoryStream;
begin
LayoutStream := TMemoryStream.Create;
try
dxLayoutControl1.BeginUpdate ;
with ADOTmp do
begin
close;
sql.Clear;
sql.Add('select A.* ');
sql.Add('from SD_Design_FormLayout A');
sql.Add('where A.designCode=' + quotedStr(mdesignCode));
open;
if RecordCount>0 then
begin
TBlobField(FieldByName('fileContent')).SaveToStream(LayoutStream) ;
LayoutStream.Seek(0,soFromBeginning);
dxLayoutControl1.LoadFromStream(LayoutStream);
end;
Close;
end;
finally
dxLayoutControl1.EndUpdate();
LayoutStream.Free; // <20>ͷ<EFBFBD><CDB7>ڴ<EFBFBD><DAB4><EFBFBD>
end;
end;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// function mustInCheck(dxLayoutControl1:TdxLayoutControl ;textFlag:string='*'):Boolean;
// var
// i:integer;
// j:Integer;
// mcatpion:string;
// layGroup:TdxLayoutGroup;
// begin
// result:=false;
// for I := 0 to dxLayoutControl1.Items.Count-1 do
// begin
// // mcatpion:= TdxLayoutItem(dxLayoutControl1.Controls[i].Parent).caption ;
// // if pos(textFlag, mcatpion)>=0 then
// // begin
// // ShowMessage(dxLayoutControl1.Items[i].name);
// // end;
//
// if dxLayoutControl1.Items[i] is TdxLayoutGroup then
// begin
// layGroup := TdxLayoutGroup( dxLayoutControl1.Items[i]) ;
// for j := 0 to layGroup.Count -1 do
// begin
// // ShowMessage(layGroup.items[j].name);
// mcatpion:= TdxLayoutItem(layGroup.items[j]).Caption ;
// if pos(textFlag, mcatpion)>0 then
// begin
// if TdxLayoutItem(layGroup.items[j]).Control is TcxTextEdit then
// begin
// if Trim(TcxTextEdit(TdxLayoutItem(layGroup.items[j]).Control).Text) ='' then
// begin
// //
// mcatpion:=StringReplace(mcatpion,'[COLOR=#FF0000]*[/COLOR]','',[]);
// TcxTextEdit(TdxLayoutItem(layGroup.items[j]).Control).TextHint:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>';
// TcxTextEdit(TdxLayoutItem(layGroup.items[j]).Control).SetFocus;
// ShowMessage('<27><>'+mcatpion+'<27><>,<2C><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>Ϊ<EFBFBD><CEAA>!');
//
// exit ;
// end;
// continue;
// end;
// //
// if TdxLayoutItem(layGroup.items[j]).Control is TcxButtonEdit then
// begin
// if Trim(TcxButtonEdit(TdxLayoutItem(layGroup.items[j]).Control).Text) ='' then
// begin
// //
// mcatpion:=StringReplace(mcatpion,'[COLOR=#FF0000]*[/COLOR]','',[]);
// // TcxButtonEdit(TdxLayoutItem(layGroup.items[j]).Control).TextHint:='<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>';
// TcxButtonEdit(TdxLayoutItem(layGroup.items[j]).Control).SetFocus;
// ShowMessage('<27><>'+mcatpion+'<27><>,<2C><><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD>Ϊ<EFBFBD><CEAA>!');
//
// exit ;
// end;
// continue;
// end;
//
// end;
// end;
//
// end;
//
// end;
// result:=true;
// end;
////////////////////////////////////
procedure InitStyleData( StyleRepository:TcxStyleRepository;mFontSize:integer);
var
i:integer;
begin
if mFontSize<9 then mFontSize:=9;
for i := 0 to StyleRepository.Count-1 do
begin
TcxStyle( StyleRepository.Items[i] ).Font.Size:=mFontSize;
end;
end;
///
function GetsysParam(AdoTmp:Tadoquery;StyleRepository:TcxStyleRepository;muserId: pchar; fparam1: pchar): Boolean;
var
i:integer;
begin
result := true;
//////////////////////////////
// shortDateFormat := 'yyyy-MM-dd';
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
with AdoTmp do
begin
close;
sql.Clear;
sql.Add('select getDate()as dt');
open;
DServerDate := fieldByName('dt').AsDatetime;
end;
gFontSize:= getSystemFontSize(AdoTmp,PWideChar('01'));
for i := 0 to StyleRepository.Count-1 do
begin
if gFontSize>=9 then
TcxStyle( StyleRepository.Items[i] ).Font.Size:=gFontSize;
end;
result := true;
end;
procedure addQryCondition( AdoTmp:Tadoquery;formId:Integer;gridName:string;FlowPanel1:TFlowPanel;rowCount:integer=4);
var
i,k:integer;
textEdit:TcxTextEdit;
combox:TcxCombobox;
cxDateEdit:TcxDateEdit;
cxButtonEdit:TcxButtonEdit;
lable:Tlabel;
rows:integer;
mwidth:integer;
mdesignCode :String;
begin
mdesignCode := fDllFileName +'|'+FlowPanel1.Parent.name+ '|' + intTostr(formId) + '|' + gridName;
mwidth:=FlowPanel1.Width div rowCount ;
FlowPanel1.AutoSize:=true;
with AdoTmp do begin close;
sql.Clear;
sql.Add('select A.* ');
sql.Add('from SD_FormGrid_Design A');
sql.Add('where A.designCode=' + quotedStr(mdesignCode));
sql.Add('and columnQuery=1');
sql.Add('order by queryControlOrder');
open;
if isEmpty then
begin
exit;
end;
end;
AdoTmp.First;
while not AdoTmp.eof do
begin
if FlowPanel1.Parent.FindComponent(trim(AdoTmp.FieldByName('fieldName').AsString))<>nil then
begin
AdoTmp.next;
continue;
end;
lable:=Tlabel.Create(nil);
lable.Alignment:=taCenter;
lable.AlignWithMargins:=true;
lable.Caption:=trim(AdoTmp.FieldByName('caption').AsString)+'';
lable.Parent:=FlowPanel1 ;
if trim(AdoTmp.FieldByName('queryControlType').AsString)='combox' then
begin
combox:= TcxCombobox.Create(nil);
combox.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
combox.Text:='';
combox.Parent:= FlowPanel1 ;
combox.AlignWithMargins:=true;
combox.Width:= mwidth - lable.Width - mwidth div rowCount;
//
if trim(AdoTmp.FieldByName('sqlStr').AsString)<>'' then
initWinData(AdoTmp,combox,trim(AdoTmp.FieldByName('sqlStr').AsString));
end
else if trim(AdoTmp.FieldByName('queryControlType').AsString)='date' then
begin
cxDateEdit:= TcxDateEdit.Create(nil);
cxDateEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
cxDateEdit.Date:=date();
cxDateEdit.Properties.ShowTime:=false;
cxDateEdit.Parent:= FlowPanel1 ;
cxDateEdit.AlignWithMargins:=true;
cxDateEdit.Width:= mwidth - lable.Width - mwidth div rowCount;
end
else if trim(AdoTmp.FieldByName('queryControlType').AsString)='buttonedit' then
begin
cxButtonEdit:= TcxButtonEdit.Create(nil);
cxButtonEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
cxButtonEdit.Text:='';
cxButtonEdit.Parent:= FlowPanel1 ;
cxButtonEdit.AlignWithMargins:=true;
cxButtonEdit.Width:= mwidth - lable.Width - mwidth div rowCount;
end
else
begin
textEdit:= TcxTextEdit.Create(nil);
textEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
textEdit.Text:='';
textEdit.Parent:= FlowPanel1 ;
textEdit.AlignWithMargins:=true;
textEdit.Width:= mwidth - lable.Width - mwidth div rowCount;
end;
AdoTmp.Next ;
end;
end;
///////////////////////////////////////////////////////
procedure addQryContionByLay(AdoTmp:Tadoquery;formId:Integer;gridName:string;layOut:TdxLayoutControl;rowCount:integer=4);
var
ALayoutGroup: TdxLayoutGroup;
ALayoutGroup1: TdxLayoutGroup;
ALayoutItem: TdxLayoutItem;
itemGroup: TdxCustomLayoutItem ;
textEdit:TcxTextEdit;
combox:TcxCombobox;
cxDateEdit:TcxDateEdit;
cxButtonEdit:TcxButtonEdit;
cxCheckBox:TcxCheckBox;
mwidth,i,j,cnt:integer;
mdesignCode :String;
begin
mdesignCode := fDllFileName +'|'+layOut.Parent.name+ '|' + intTostr(formId) + '|' + gridName;
layOut.BeginUpdate; // Postpones updates
try
with AdoTmp do begin close;
sql.Clear;
sql.Add('select A.* ');
sql.Add('from SD_FormGrid_Design A');
sql.Add('where A.designCode=' + quotedStr(mdesignCode));
sql.Add('and columnQuery=1');
sql.Add('order by queryControlOrder');
open;
if isEmpty then
begin
exit;
end;
end;
// Creates a child group within the root group
for i := 0 to layOut.Items.Count - 1 do
begin
itemGroup := layOut.Items[i];
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if itemGroup is TdxLayoutGroup then
begin
ALayoutGroup:= TdxLayoutGroup(itemGroup);
break;
end;
end;
//
if (ALayoutGroup=nil) or (ALayoutGroup.Count> rowCount) then
ALayoutGroup := TdxLayoutGroup(layOut.CreateGroup(nil, layOut.Items));
ALayoutGroup.LayoutDirection:=ldHorizontal;
ALayoutGroup.Hidden:=true;
// ALayoutGroup.Name:='zdygroup1';
ALayoutGroup.CaptionOptions.Text := ''; // Specifies the group caption
ALayoutGroup.Padding.Top:=-5;
//
AdoTmp.First;
cnt:=1;
while not AdoTmp.eof do
begin
if layOut.Parent.FindComponent(trim(AdoTmp.FieldByName('fieldName').AsString))<>nil then
begin
AdoTmp.next;
continue;
end;
ALayoutItem:= TdxLayoutItem( layOut.FindItem('item_'+trim(AdoTmp.FieldByName('fieldName').AsString))) ;
if cnt mod rowCount=0 then
begin
ALayoutGroup:=TdxLayoutGroup(layOut.CreateGroup(nil, layOut.Items));
ALayoutGroup.LayoutDirection:=ldHorizontal;
ALayoutGroup.Hidden:=true;
ALayoutGroup.CaptionOptions.Text := '';
// ALayoutGroup.Padding.Top:=5;
ALayoutGroup.Offsets.Top:=5;
end;
if trim(AdoTmp.FieldByName('queryControlType').AsString)='combox' then
begin
combox:= TcxCombobox.Create(nil);
combox.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
combox.Text:='';
combox.Style.Font.Size:=gFontSize;
combox.AlignWithMargins:=true;
combox.TabOrder:=cnt;
combox.tag:=2;
//
if trim(AdoTmp.FieldByName('sqlStr').AsString)<>'' then
initWinData(AdoTmp,combox,trim(AdoTmp.FieldByName('sqlStr').AsString));
if ALayoutItem=nil then
ALayoutItem := TdxLayoutItem(layOut.CreateItem);
ALayoutItem.Control := combox;
ALayoutItem.CaptionOptions.Text:=trim(AdoTmp.FieldByName('caption').AsString) ;
ALayoutItem.Parent := ALayoutGroup;
ALayoutItem.Name:= 'item_'+trim(AdoTmp.FieldByName('fieldName').AsString) ;
end
else if trim(AdoTmp.FieldByName('queryControlType').AsString)='checkBox' then
begin
cxCheckBox:= TcxCheckBox.Create(nil);
cxCheckBox.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
cxCheckBox.AlignWithMargins:=true;
cxCheckBox.Style.Font.Size:=gFontSize;
cxCheckBox.Caption:= trim(AdoTmp.FieldByName('caption').AsString) ;
cxCheckBox.TabOrder:=cnt;
cxCheckBox.Tag:=99;
//
if ALayoutItem=nil then
ALayoutItem := TdxLayoutItem(layOut.CreateItem);
ALayoutItem.Control := cxCheckBox;
ALayoutItem.CaptionOptions.Text:='';//trim(AdoTmp.FieldByName('caption').AsString) ;
ALayoutItem.Parent := ALayoutGroup;
ALayoutItem.Name:= 'item_'+trim(AdoTmp.FieldByName('fieldName').AsString) ;
end
else if trim(AdoTmp.FieldByName('queryControlType').AsString)='date' then
begin
cxDateEdit:= TcxDateEdit.Create(nil);
cxDateEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
cxDateEdit.Date:=date();
cxDateEdit.Properties.ShowTime:=false;
cxDateEdit.AlignWithMargins:=true;
cxDateEdit.Style.Font.Size:=gFontSize;
cxDateEdit.TabOrder:=cnt;
//
if ALayoutItem=nil then
ALayoutItem := TdxLayoutItem(layOut.CreateItem);
ALayoutItem.Control := cxDateEdit;
ALayoutItem.CaptionOptions.Text:=trim(AdoTmp.FieldByName('caption').AsString) ;
ALayoutItem.Parent := ALayoutGroup;
ALayoutItem.Name:= 'item_'+trim(AdoTmp.FieldByName('fieldName').AsString) ;
end
else if trim(AdoTmp.FieldByName('queryControlType').AsString)='buttonedit' then
begin
cxButtonEdit:= TcxButtonEdit.Create(nil);
cxButtonEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
cxButtonEdit.Text:='';
cxButtonEdit.AlignWithMargins:=true;
cxButtonEdit.Style.Font.Size:=gFontSize;
cxButtonEdit.TabOrder:=cnt;
cxButtonEdit.tag:=2;
//
if ALayoutItem=nil then
ALayoutItem := TdxLayoutItem(layOut.CreateItem);
ALayoutItem.Control := cxButtonEdit;
ALayoutItem.CaptionOptions.Text:=trim(AdoTmp.FieldByName('caption').AsString) ;
ALayoutItem.Parent := ALayoutGroup;
ALayoutItem.Name:= 'item_'+trim(AdoTmp.FieldByName('fieldName').AsString) ;
end
else
begin
textEdit:= TcxTextEdit.Create(nil);
textEdit.Name:= trim(AdoTmp.FieldByName('fieldName').AsString);
textEdit.Text:='';
textEdit.AlignWithMargins:=true;
textEdit.Style.Font.Size:=gFontSize;
textEdit.TabOrder:=cnt;
textEdit.tag:=2;
//
if ALayoutItem=nil then
ALayoutItem := TdxLayoutItem(layOut.CreateItem);
ALayoutItem.Control := textEdit;
ALayoutItem.CaptionOptions.Text:=trim(AdoTmp.FieldByName('caption').AsString) ;
ALayoutItem.Parent := ALayoutGroup;
ALayoutItem.Name:= 'item_'+trim(AdoTmp.FieldByName('fieldName').AsString) ;
end;
inc(cnt);
AdoTmp.Next ;
end;
//
for i := 0 to layOut.Items.Count - 1 do
begin
itemGroup := layOut.Items[i];
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if itemGroup is TdxLayoutGroup then
begin
ALayoutGroup:= TdxLayoutGroup(itemGroup);
for j := ALayoutGroup.VisibleCount-1 downto 0 do
begin
if ALayoutGroup.VisibleItems[j] is TdxLayoutItem then
begin
if TdxLayoutItem( ALayoutGroup.VisibleItems[j] ).Control=nil then
ALayoutGroup.VisibleItems[j].Visible:=false;
end;
end;
end;
end;
finally
layOut.EndUpdate; // Resumes updates, even if an exception occurs
if layout.Items.VisibleCount=0 then layout.Visible:=false;
end;
end;
////////////////////////////////////////////////////////
procedure initWinData(AdoTmp:TadoQuery;obj:TwinControl;sqlStr:string);
var
ado1:TadoQuery;
begin
try
ado1:=TadoQuery.Create(nil);
ado1.Connection:= AdoTmp.Connection;
with ado1 do
begin
close;
sql.Clear;
sql.add(sqlStr);
open;
if RecordCount>0 then
begin
if obj is TcxCombobox then
begin
while not Eof do
begin
TcxCombobox(obj).Properties.Items.Add(trim(fields[0].AsString));
next;
end;
end;
close;
end;
end;
finally
ado1.Free;
end;
end;
//
/// /////////////////////////////////////////
/// /************<2A><>ȡ<EFBFBD><EFBFBD><E6B4A2><EFBFBD>̲<EFBFBD><CCB2><EFBFBD>***********/////
/// /////////////////////////////////////////
function GetProcedureParam(layoutControl: TdxLayoutControl; EquTag: Integer=0): string;
var
i, j, k: Integer;
mControl:TControl;
begin
Result := '';
with layoutControl do
begin
for i := 0 to layoutControl.ControlCount -1 do
begin
mControl:=layoutControl.Controls[i];
if layoutControl.FindItem(mControl) =nil then continue;
if not layoutControl.FindItem(mControl).Visible then continue;
if mControl is TLabel or (mControl.Tag=99) then
continue;
if mControl is TcxTextEdit then
begin
Result := Result + ',@'+mControl.Name + '=' + quotedStr(Trim(TcxTextEdit(mControl).Text)) ;
end
else if mControl is TcxButtonEdit then
begin
if Trim(TBtnEditC(mControl).TxtCode) <> '' then
begin
Result := Result + ',@' + mControl.Name + '=' + quotedStr(Trim(TBtnEditC(mControl).TxtCode)) ;
end
else
begin
Result := Result + ',@' + mControl.Name + '=' + quotedStr(Trim(TBtnEditC(mControl).Text)) ;
end;
end
else if mControl is TcxComboBox then
begin
Result := Result + ',@' + mControl.Name + '=' + quotedStr(Trim(TcxComboBox(mControl).Text)) ;
end;
end;
end;
if Trim(Result) <> '' then
Result := Trim(RightStr(Result, Length(Result) - 1));
end;
end.