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, 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; procedure getSystemIni(); 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; // 释放内存流 end; end; //必须输入控制 // 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:='请输入数据!'; // TcxTextEdit(TdxLayoutItem(layGroup.items[j]).Control).SetFocus; // ShowMessage('【'+mcatpion+'】,数据不能为空!'); // // 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:='请输入数据!'; // TcxButtonEdit(TdxLayoutItem(layGroup.items[j]).Control).SetFocus; // ShowMessage('【'+mcatpion+'】,数据不能为空!'); // // 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'; //服务器日期 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]; // 检查项是否是组 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]; // 检查项是否是组 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; // /// ///////////////////////////////////////// /// /************获取存储过程参数***********///// /// ///////////////////////////////////////// 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 else if mControl is TcxCheckBox then begin if TcxCheckBox(mControl).Checked then Result := Result + ',@' + mControl.Name + '=1' else Result := Result + ',@' + mControl.Name + '=0' ; end end; end; if Trim(Result) <> '' then Result := Trim(RightStr(Result, Length(Result) - 1)); end; ///////////////////////////////////////////////////////// // procedure getSystemIni(); var programIni: Tinifile; //配置文件名 FileName: string; begin FileName := ExtractFilePath(Paramstr(0)) + 'SYSTEMSET.INI'; if not FileExists(FileName) then exit; try programIni := Tinifile.create(FileName); gIsUseSkin := programIni.ReadBool('窗口设置', 'skin',true); gIsCanDesign := programIni.ReadBool('窗口设置', 'design',false); gGridNativeSet := programIni.ReadBool('窗口设置', 'grid',true); gfontSize := programIni.ReadInteger('窗口设置', '字体大小', 12); gfontName := programIni.ReadString('窗口设置', '字体名称', ''); finally programIni.Free; end; end; end.