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, TypInfo,
  cxLookAndFeelPainters, cxGridCustomView, Buttons, cxDropDownEdit;


//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:string='*'):boolean;
function  mustInCheck_R(app:Tapplication;dxLayoutGroup:TdxLayoutGroup ;textFlag:string='*'):Boolean;
//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;pdesignCode:PWideChar):boolean;
procedure layoutDesign(dxLayoutControl1:TdxLayoutControl;ADOTmp: TADOQuery;userId:string );
procedure SetShowModalHide(mHandle:Thandle;form:Tform);
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();
function IsHasDesignRight(ADOTmp: TADOQuery;userId:String): boolean;
function TryGetTextProperty(AComponent: TComponent; out Value: string): Boolean;
procedure HideUnenabledButton(Toolbar: TToolbar);
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;


 ////////////////////////////////////
 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;

  InitStyleData(StyleRepository,gFontSize);

  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.Properties.OnEditValueChanged:=TfilterClick;
      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('窗口设置', '字体名称', '');
    gIsYsUse  := programIni.ReadBool('窗口设置', 'stand', false);
  finally
    programIni.Free;
  end;
end;

 //必须输入控制
 function  mustInCheck(app:Tapplication;dxLayoutControl1:TdxLayoutControl ;textFlag:string='*'):Boolean;
 var
   i:integer;
   j:Integer;
   mcatpion:string;
   mValue:string;
   layGroup:TdxLayoutGroup;
 begin
  result:=false;
  if textFlag='' then  textFlag:='*';

  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;
    //ShowMessage(mcatpion);
    if (dxLayoutControl1.Items[i] is TdxLayoutGroup) or (dxLayoutControl1.Items[i] is TdxLayoutAutoCreatedGroup) then
    begin
      if not mustInCheck_R(app,TdxLayoutGroup(dxLayoutControl1.Items[i]),textFlag) then
        Exit;
    end
    else if dxLayoutControl1.Items[i]  is TdxLayoutItem then
    begin
      mcatpion:= TdxLayoutItem(dxLayoutControl1.Items[i]).Caption ;
     // ShowMessage(mcatpion);
      if pos(textFlag, mcatpion)>0 then
      begin
        if TryGetTextProperty(TComponent(TdxLayoutItem(dxLayoutControl1.Items[i]).Control),mValue) then
        begin
          if Trim(mValue)='' then
          begin
            mcatpion:=StringReplace(mcatpion,'[COLOR=#FF0000]*[/COLOR]','',[rfIgnoreCase]);
            ShowMessage('【'+mcatpion+'】,数据不能为空!');
             exit ;
          end;
        end;
      end;

    end;
  end;
  result:=true;
 end;
 ///////////////////////////////////////////////////
 function  mustInCheck_R(app:Tapplication;dxLayoutGroup:TdxLayoutGroup ;textFlag:string='*'):Boolean;
var
  i:integer;
  j:Integer;
  mcatpion:string;
  mValue:string;
begin
  result:=false;
  if textFlag='' then  textFlag:='*';

  for I := 0 to dxLayoutGroup.Count - 1 do
  begin
    if (dxLayoutGroup.Items[i] is TdxLayoutGroup) or (dxLayoutGroup.Items[i] is TdxLayoutAutoCreatedGroup) then
    begin
      if not mustInCheck_R(app,TdxLayoutGroup(dxLayoutGroup.Items[i]),textFlag) then
        Exit;
    end
    else if dxLayoutGroup.Items[i]  is TdxLayoutItem then
    begin
      mcatpion:= TdxLayoutItem(dxLayoutGroup.Items[i]).Caption ;
     // ShowMessage(mcatpion);
      if pos(textFlag, mcatpion)>0 then
      begin
        if TryGetTextProperty(TComponent(TdxLayoutItem(dxLayoutGroup.Items[i]).Control),mValue) then
        begin
          if Trim(mValue)='' then
          begin
            mcatpion:=StringReplace(mcatpion,'[COLOR=#FF0000]*[/COLOR]','',[rfIgnoreCase]);
            ShowMessage('【'+mcatpion+'】,数据不能为空!');
             exit ;
          end;
        end;
      end;
    end;
  end;
  result:=true;
end;

///////////////////////////////////////////////////////
 procedure SetShowModalHide(mHandle:Thandle;form:Tform);
 begin
     enablewindow(mHandle,true);

 end;
 /////////////////////////////////
 procedure layoutDesign(dxLayoutControl1:TdxLayoutControl;ADOTmp: TADOQuery;userId:string );
 begin
  if not IsHasDesignRight(ADOTmp,PWideChar(userId)) then
    exit;
   dxLayoutControl1.Customization := True;
 end;
 /////////////////////////////////////
function saveLayOut(app:Tapplication;dxLayoutControl1:TdxLayoutControl; ADOCmd: TADOQuery;pdesignCode:PWideChar):Boolean;
var
  LayoutStream: TMemoryStream;
  mdesignCode:string;
begin
  mdesignCode:= pdesignCode ;
  LayoutStream := TMemoryStream.Create;
  try
     dxLayoutControl1.SaveToStream(LayoutStream);
    with ADOCmd 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
        edit;
      end
      else
      begin
        append;
        FieldByName('designCode').value:=mdesignCode;
        FieldByName('fileGroup').value:='1';
        FieldByName('height').value:=0;

      end;
      TBlobField(FieldByName('fileContent')).LoadFromStream(LayoutStream);
      Post;
    end;
  finally
    LayoutStream.Free; // 释放内存流
  end;
end;
 /// ///////////////////////////////////////////////////
//
/// ////////////////////////////////////////////////////
function IsHasDesignRight(ADOTmp: TADOQuery;userId:String): boolean;
begin
  result := false;
  try
    /// ////////////////////////////////////
    // 权限控制
    with ADOTmp do
    begin
      close;
      sql.Clear;
      Filtered := false;
      sql.Add('select count(userid) as cnt');
      sql.Add('from sy_user A');
      sql.Add('where userid=' + quotedStr(userId));
      sql.Add('and canDesign=1');
      sql.Add('and valid=''Y''');
      open;

      if fieldByName('cnt').AsInteger > 0 then
      begin
        result := true;
      end;
      close;
    end;
  except
    application.MessageBox('获取操作权限时发生错误!', '警告信息', 0);
  end;
end;
/////////////////////////////////////////////////////////////
//
function TryGetTextProperty(AComponent: TComponent; out Value: string): Boolean;
begin
  try
    Value := GetStrProp(AComponent, 'Text');
    Result := True;
  except
    Result := False;
  end;
end;

////////////////////////////////////////////////////////////
//
procedure HideUnenabledButton(Toolbar: TToolbar);
var
  i:Integer;
begin
  for i := 0 to Toolbar.ButtonCount - 1 do
  begin
    if not ToolBar.Buttons[i].Enabled and ToolBar.Buttons[i].Visible then
    begin
      ToolBar.Buttons[i].Visible := False;
    end;
  end;
end;

end.
