博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多标签主界面使用TRzPageControl
阅读量:5946 次
发布时间:2019-06-19

本文共 5671 字,大约阅读时间需要 18 分钟。

// Author: CXG 2010-08-07 08:22:30

unit uMain;

{.$HINTS OFF}
interface

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, RzTabs, RzSplit, RzPanel, ExtCtrls, ComCtrls, RzButton
  ,ADODB, DB, ImgList, StdCtrls, RzStatus
  ;

type

  TFormMain = class(TForm)
    MainMenu1: TMainMenu;
    RzToolBar1: TRzToolbar;
    RzPageControl1: TRzPageControl;
    RzSizePanel1: TRzSizePanel;
    TreeView1: TTreeView;
    RzToolButton1: TRzToolButton;
    ImageList1: TImageList;
    RzStatusBar1: TRzStatusBar;
    RzMarqueeStatus1: TRzMarqueeStatus;
    RzToolButton3: TRzToolButton;
    RzToolButton2: TRzToolButton;
    RzStatusPane1: TRzStatusPane;
    RzStatusPane2: TRzStatusPane;
    procedure RzPageControl1Close(Sender: TObject;
      var AllowClose: Boolean);
    procedure RzToolButton1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RzPageControl1DblClick(Sender: TObject);
  private
    { Private declarations }
    function GetTabSheet(const Acaption: string): TRzTabSheet;
    procedure CloseTabsheet;
    function ActiveExistTabsheet(const Acaption: string): boolean;
    procedure MenuTreeClick(Sender: TObject);
    procedure SetTreeNodesImage;
    procedure todo(const aCaption: string);
    procedure BLMenu;
    procedure openForm(AFormClass: TFormClass; var aForm: TForm;
      aOwner: TWinControl);
  public
    { Public declarations }
  end;

var

  FormMain: TFormMain;
const
  Const_Max = 20;  

implementation

uses

  uFunction
  , uDM, uDictionary, uCategory, uMenu, uOperator, uDataStruct;

{$R *.dfm}

procedure TFormMain.openForm(AFormClass: TFormClass; var aForm: TForm;

  aOwner: TWinControl);
begin
  if aOwner = nil then Exit;
  if aForm = nil then
    aForm := AFormClass.Create(aOwner);
  with aForm do
  begin
    ManualDock(aOwner);
    WindowState := wsMaximized;
    Align := alClient;
    Show;
  end;
end;

procedure TFormMain.SetTreeNodesImage;

var
  i: Integer;
begin
  if TreeView1.Items.Count <= 0 then Exit;
 
  TreeView1.Images := Imagelist1;
  for i := 0 to TreeView1.Items.Count - 1 do
  begin
    if TreeView1.Items[i].HasChildren  then
    begin
      TreeView1.Items[i].ImageIndex := 0;
      TreeView1.Items[i].SelectedIndex := 1;

    end else begin

      TreeView1.Items[i].ImageIndex := 2;
      TreeView1.Items[i].SelectedIndex := 2;
    end;
  end;
end;

procedure TFormMain.todo(const aCaption: string);

begin
  if Pos('数据字典', acaption) <> 0 then begin
    if ActiveExistTabsheet('数据字典') then Exit;
    openForm(TformDictionary, tform(formdictionary), GetTabSheet('数据字典'));
  end else if Pos('系统菜单', aCaption) <> 0 then begin
    if ActiveExistTabsheet('系统菜单') then Exit;
    openForm(Tformmenu, tform(formMenu), GetTabSheet('系统菜单'));
  end else if Pos('货品类别管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('货品类别管理') then Exit;
    openForm(TformCategory, tform(formCategory), GetTabSheet('货品类别管理'));
  end else if Pos('操作员管理', aCaption) <> 0 then begin
    if ActiveExistTabsheet('操作员管理') then Exit;
    openForm(TFormOperator, tform(FormOperator), GetTabSheet('操作员管理'));
  end;

                     

end;

procedure TFormMain.CloseTabsheet;

var
  i: Integer;  
begin
  if RzPageControl1.PageCount <= 0 then Exit;
  if RzPageControl1.ActivePage = nil then exit;
  for i := 0 to RzPageControl1.ActivePage.ControlCount - 1 do
    if RzPageControl1.ActivePage.Controls[i] is TForm then
    begin
      TForm(RzPageControl1.ActivePage.Controls[i]).Close;
      Break;
    end;
  RzPageControl1.ActivePage.PageControl := nil;
  RzPageControl1.ActivePage.Free;
  RzPageControl1.SelectNextPage(true);
end;

function TFormMain.ActiveExistTabsheet(const Acaption: string): boolean;

var
  i: Integer;
begin
  result := false;
  if RzPageControl1.PageCount <= 0 then exit;
  for i := 0 to RzPageControl1.PageCount - 1 do
  begin
    if RzPageControl1.Pages[i].Caption = Acaption then
    begin
      result := true;
      RzPageControl1.activepage := RzPageControl1.pages[i];
      Break;
    end;
  end; 
end;

function TFormMain.GetTabSheet(const Acaption: string): TRzTabSheet;

var
  tabSheet: TRzTabSheet;
begin
  Result := nil;
  if RzPageControl1.PageCount > const_max then
  begin
    showmessage('out of ' + inttostr(const_max));
    exit;
  end;
  tabSheet := TRzTabSheet.Create(RzPageControl1);
  tabSheet.PageControl := RzPageControl1;
  tabSheet.Caption := Acaption;
  RzPageControl1.ActivePage := tabSheet;
  Result := tabSheet;
end;

procedure   TFormMain.BLMenu;

    procedure   GetItems(AItem:TMenuItem);
    var
        I:integer;
    begin
        AItem.OnClick := MenuTreeClick;
        for   I:=0   to   AItem.Count-1   do   begin
            GEtItems(AItem.Items[I]);
        end;
    end;
var
    I:integer;
begin
    for   I:=0   to   MainMenu1.Items.Count-1   do   begin
        GetItems(MainMenu1.Items.Items[I]);
    end;
end;

procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);

begin
//  if MessageDlg('是否关闭系统',  mtConfirmation, [mbYes, mbNo], 0) = mrYes then
//  begin
//    CanClose := True;
//  end else CanClose := False;

end;

procedure TFormMain.FormShow(Sender: TObject);

var
  d: TADOQuery;
begin
  RzStatusPane2.Caption := G_Operator.name;
  d := TADOQuery.Create(nil);
  try
    with d do
    begin
      Connection := dm.ADOConnection1;
      Close;
      SQL.Clear;
      SQL.Text := 'select id, name from modules order by id';
      Open;
    end;
    uFunction.CreateTree(d, TreeView1, 'modules', 'id', 'name', false);
    uFunction.SetDataSet(d, dm.ADOConnection1, 'modules');
  finally
    d.Free;
  end;
  uFunction.TreeToMenu(TreeView1, nil, MainMenu1.Items);
  SetTreeNodesImage;
  BLMenu;
  TreeView1.OnClick := MenuTreeClick;
end;

procedure TFormMain.MenuTreeClick(Sender: TObject);

begin
  if Sender is TTreeView then
    todo(TTreeView(Sender).Selected.Text)
  else if Sender is TMenuItem then
    todo(StripHotkey(TMenuItem(Sender).Caption));
end;

procedure TFormMain.RzPageControl1Close(Sender: TObject;

  var AllowClose: Boolean);
begin
  closetabsheet;
end;

procedure TFormMain.RzPageControl1DblClick(Sender: TObject);

begin
  CloseTabsheet;
end;

procedure TFormMain.RzToolButton1Click(Sender: TObject);

begin
  Close;
end;

end.

 

转载地址:http://bcbxx.baihongyu.com/

你可能感兴趣的文章
【290】Python 函数
查看>>
godaddy域名转发(域名跳转)设置教程
查看>>
silverlight学习布局之:布局stackpanel
查看>>
理解并自定义HttpHandler
查看>>
从前后端分离到GraphQL,携程如何用Node实现?\n
查看>>
JavaScript标准库系列——RegExp对象(三)
查看>>
Linux Namespace系列(09):利用Namespace创建一个简单可用的容器
查看>>
oracle中create table with as和insert into with as语句
查看>>
kafka连接异常
查看>>
11g废弃的Hint - BYPASS_UJVC
查看>>
为什么工业控制系统需要安全防护?
查看>>
Mongodb部署记录[3]-主从搭建
查看>>
hive sql操作
查看>>
tomcat 深度优化
查看>>
127 - "Accordian" Patience
查看>>
阿里云CentOS7安装Oracle11GR2
查看>>
nginc+memcache
查看>>
php正则匹配utf-8编码的中文汉字
查看>>
MemCache在Windows环境下的搭建及启动
查看>>
linux下crontab实现定时服务详解
查看>>