unit U_WinFormRight;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit,DBGrids, DB, cxDBData,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, ADODB,StrUtils,
  Midas,cxGridCustomTableView, cxGridTableView, cxGridDBTableView,cxTimeEdit,
    cxGrid,cxDBLookupComboBox,cxCalendar, cxCurrencyEdit,cxExportGrid4Link,
  ExtCtrls, Buttons,DBClient,FTComboBox,cxDropDownEdit,cxMemo;
var
  gP1:string;
  gP2:string;
  gP3:string;
  gP4:string;
  gP5:string;
procedure  SetFormCtrlRight(mWinFormRight:string;mParent:TWinControl);
procedure SetWinFormCtrlOperRight(ADOQueryTmp:TADOQuery;mParent:TWinControl;frmName:string);
procedure SetWinFormDispCSS(ADOQueryTmp:TADOQuery;mParent:TWinControl);
implementation
uses
  U_global;
//////////////////////////////////////////////////////////////
  //mWinFormRight:1: 此参数为主程序传进的控制窗口权限的参数;
  //              2:也可以用户自定义更加实际传值
  //mParent:可以是toolBar;也可以是panel和groupBox的容器面板;
//////////////////////////////////////////////////////////////
procedure  SetFormCtrlRight(mWinFormRight:string;mParent:TWinControl);
var
  i:integer;
  mCaption:string;
begin
  if mWinFormRight='' then exit;
  try
    ///////////////////////////////////////////////
    if mParent is TtoolBar then
    begin
      for i:=0 to TtoolBar(mParent).ButtonCount-1 do
      begin
        mCaption:=trim(TtoolBar(mParent).Buttons[i].Caption);
        if (mCaption='关闭') or (mCaption='退出') or (mCaption='放弃') then exit;
        /////////////////////////////
        if  trim(mWinFormRight)='查询' then
        begin
          if pos(mCaption, '查询,刷新,过滤,高级查询')>0 then      //,查看,详细
          begin
            //TtoolBar(mParent).Buttons[i].Enabled :=false;
            TtoolBar(mParent).Buttons[i].Visible :=true;
          end
          else
          begin
           TtoolBar(mParent).Buttons[i].Visible :=false;
          end;
        end
        else
        begin
          if (pos(mCaption,mWinFormRight)>0 )
             or (pos(mCaption, '查询,刷新,过滤,高级查询,详细')>0) then   //查看,
          begin
            TtoolBar(mParent).Buttons[i].Visible :=true;
          end
          else
          begin
           TtoolBar(mParent).Buttons[i].Visible :=false;
          end;
        end;
      end;
      exit;
    end;
    ///////////////////////////////////////////////////
    if  trim(mWinFormRight)='查询' then exit;
    with mParent do
    begin
      for i:=0 to ControlCount-1 do
      begin
        mCaption:='';
        if (Controls[i] is TBitBtn) then
          mCaption:=trim(TBitBtn(Controls[i]).Caption)
        else if (Controls[i] is TButton) then
          mCaption:=trim(TButton(Controls[i]).Caption)
        else if (Controls[i] is TSpeedButton) then
          mCaption:=trim(TSpeedButton(Controls[i]).Caption)
        else
          continue;
        if (Controls[i] is TBitBtn)
           or  (Controls[i] is TButton)
           or  (Controls[i] is TSpeedButton) then
        begin
          if (pos(mCaption, mWinFormRight)>0)
             or (mCaption='查询') or (mCaption='过滤') or (mCaption='高级过滤') then
          begin
            Controls[i].Visible :=true;
          end
          else
            Controls[i].Visible :=false;
        end;
      end;
    end;

  except
    application.MessageBox('初始化窗口权限发生错误','警告信息',0);
  end;
end;
//////////////////////////////////////////////////////////////////
  //
//////////////////////////////////////////////////////////////////
procedure SetWinFormCtrlOperRight(ADOQueryTmp:TADOQuery;mParent:TWinControl;frmName:string);
var
  i:integer;
  mtable, mfield:string;
begin
  with ADOQueryTmp do
  begin
    close;
    sql.Clear ;
    sql.Add('select * from XC_FormFieldOperCtrl');
    sql.Add('where valid=''Y''');
    Open;
    if IsEmpty then exit;
  end;

  with mParent do
  begin
    for i:=0 to ControlCount-1 do
    begin
      if Controls[i] is TLabel then continue;
      //SplitCtrName(Controls[i].Name,'9',mtable,mfield) ;
      if ADOQueryTmp.Locate('moduleName;fieldByName',varArrayOf([frmName,mfield]),[]) then
      begin
        if Controls[i] is Tmemo   then
          Tmemo(Controls[i]).ReadOnly :=true
        else if  Controls[i] is Tcxmemo then
          (Controls[i] as Tcxmemo).Properties.ReadOnly :=true
        else
          Controls[i].Enabled :=false;
      end;
    end;
  end;
end;
///////////////////////////////////////////////////////////////////////////
  //功能:设置窗口显示内容风格样式
///////////////////////////////////////////////////////////////////////////
procedure SetWinFormDispCSS(ADOQueryTmp:TADOQuery;mParent:TWinControl);
begin

  try
    with  ADOQueryTmp do
    begin
      close;
      sql.Clear ;
      sql.Add('select *  ');
      sql.Add('from XS_ErpParam');
      sql.Add('where SetId=''S100''');
      sql.Add('and SetType=''FORM''');
      Open;
      if RecordCount>0 then
      begin
        //P1 ToolBar显示风格
        if trim(fieldByName('P1').AsString) ='0' then
          TtoolBar(mParent).List :=false
        else
          TtoolBar(mParent).List :=true;
      end;
      close;
    end;
  except
  end;
end;

end.