unit U_RuleManager;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,  DB, cxDBData, ADODB, ActnList,ActnMan,StdCtrls, Mask,
  RzEdit, RzDBEdit, ToolWin, ActnCtrls, DBCtrls,cxContainer,  
  ExtCtrls, RzPanel, Grids, DBGrids, RzDBGrid, XPStyleActnCtrls;

type
  Tfrm_RuleManager = class(TForm)
    ActionToolBar1: TActionToolBar;
    ActionManager1: TActionManager;
    Action1: TAction;
    Action2: TAction;
    Action3: TAction;
    Action4: TAction;
    Action5: TAction;
    ADOQuery1: TADOQuery;
    DataSource1: TDataSource;
    GroupBox1: TRzGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    RzDBEdit1: TRzDBEdit;
    RzDBMemo1: TRzDBMemo;
    RzDBGrid1: TRzDBGrid;
    procedure FormCreate(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Action2Execute(Sender: TObject);
    procedure Action3Execute(Sender: TObject);
    procedure Action4Execute(Sender: TObject);
    procedure Action5Execute(Sender: TObject);
  private
    { Private declarations }
    procedure zhuangtai(Action: Integer);
  public
    { Public declarations }
  end;

var
  frm_RuleManager: Tfrm_RuleManager;

implementation

uses U_LimitConst, DataModuleU;

{$R *.dfm}

procedure Tfrm_RuleManager.FormCreate(Sender: TObject);
begin
  ADOQuery1.Open;
end;

procedure Tfrm_RuleManager.zhuangtai(Action: Integer);
begin
  case Action of
    1: begin
        Action1.Enabled := False;
        Action2.Enabled := False;
        Action3.Enabled := False;
        Action4.Enabled := True;
        Action5.Enabled := True;
        GroupBox1.Enabled := True;
        RzDBGrid1.Enabled := False;
      end;
    2: begin
        Action1.Enabled := False;
        Action2.Enabled := False;
        Action3.Enabled := False;
        Action4.Enabled := True;
        Action5.Enabled := True;
        GroupBox1.Enabled := True;
        RzDBGrid1.Enabled := False;
      end;
    3: begin
        Action1.Enabled := True;
        Action2.Enabled := True;
        Action3.Enabled := True;
        Action4.Enabled := False;
        Action5.Enabled := False;
        GroupBox1.Enabled := False;
        RzDBGrid1.Enabled := True;
      end;
    4: begin
        Action1.Enabled := True;
        Action2.Enabled := True;
        Action3.Enabled := True;
        Action4.Enabled := False;
        Action5.Enabled := False;
        GroupBox1.Enabled := False;
        RzDBGrid1.Enabled := True;
      end;
    5: begin
        Action1.Enabled := True;
        Action2.Enabled := True;
        Action3.Enabled := True;
        Action4.Enabled := False;
        Action5.Enabled := False;
        GroupBox1.Enabled := False;
        RzDBGrid1.Enabled := True;
      end;
  end;
end;

procedure Tfrm_RuleManager.Action1Execute(Sender: TObject);
begin
  if not DmFrm.HaveFunction(Sys_Manager_RuleManager_Add) then Exit;
  zhuangtai(1);
  ADOQuery1.Append;
end;

procedure Tfrm_RuleManager.Action2Execute(Sender: TObject);
begin
  if not DmFrm.HaveFunction(Sys_Manager_RuleManager_Edit) then Exit;
  zhuangtai(2);
  ADOQuery1.Edit;
end;

procedure Tfrm_RuleManager.Action3Execute(Sender: TObject);
begin
  if not DmFrm.HaveFunction(Sys_Manager_RuleManager_Del) then Exit;
  if ADOQuery1.RecordCount > 0 then
  begin
    if Application.MessageBox('是否删除?', '提示', MB_YESNO +
      MB_ICONQUESTION) = IDYES then
    begin
      zhuangtai(3);
      DmFrm.WriteOperatLog(caption,'删除岗位:' + ADOQuery1.FieldByName('RuleName').AsString );      
      ADOQuery1.Delete;
    end;
  end;
end;

procedure Tfrm_RuleManager.Action4Execute(Sender: TObject);
begin
  if RzDBEdit1.Text = '' then
  begin
    Application.MessageBox('岗位名称不能为空!', '提示', MB_OK +
      MB_ICONINFORMATION);
    RzDBEdit1.SetFocus;
    Exit;
  end;
  if ADOQuery1.State in [dsEdit, dsInsert] then
  begin
    zhuangtai(4);
    ADOQuery1.Post;
    DmFrm.WriteOperatLog(caption,'新增或修改权岗位');
  end;
end;

procedure Tfrm_RuleManager.Action5Execute(Sender: TObject);
begin
  zhuangtai(5);
  ADOQuery1.Cancel;
end;

end.