⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 groupright.pas

📁 产品信息系统!关于产品基础信息的系统!功能强大!
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit GroupRight;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Base, ActnList, ComCtrls, ToolWin, ExtCtrls, DB, ADODB, Grids,
  Wwdbigrd, Wwdbgrid, dxmdaset, DBGrids, StdCtrls;

type
  TfrmGroupRight = class(TfrmBase)
    ToolBar: TToolBar;
    tbtFirst: TToolButton;
    tbtPrior: TToolButton;
    tbtNext: TToolButton;
    tbtLast: TToolButton;
    ToolButton5: TToolButton;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    tbtSave: TToolButton;
    tbtCancel: TToolButton;
    tbtDivider3: TToolButton;
    tbtExit: TToolButton;
    ALToolbar: TActionList;
    acSave: TAction;
    acCancel: TAction;
    acFirst: TAction;
    acPrior: TAction;
    acNext: TAction;
    acLast: TAction;
    acExit: TAction;
    acAllCheck: TAction;
    acAllUnCheck: TAction;
    Panel1: TPanel;
    Panel2: TPanel;
    Splitter1: TSplitter;
    Panel3: TPanel;
    Splitter2: TSplitter;
    Panel4: TPanel;
    QModule: TADOQuery;
    QMaster: TADOQuery;
    QFunction: TADOQuery;
    dsModule: TDataSource;
    dsFunction: TDataSource;
    dsMaster: TDataSource;
    QMasterfID: TAutoIncField;
    QMasterfCode: TWideStringField;
    QMasterfName: TWideStringField;
    wwDBGrid1: TwwDBGrid;
    wwDBGrid2: TwwDBGrid;
    QRight: TADOQuery;
    QModulefID: TIntegerField;
    QModulefName: TWideStringField;
    MDFunction: TdxMemData;
    dsMDFunction: TDataSource;
    MDFunctionfID: TIntegerField;
    MDFunctionfName: TStringField;
    MDFunctionfRun: TStringField;
    MDFunctionfInsert: TStringField;
    MDFunctionfEdit: TStringField;
    MDFunctionfDelete: TStringField;
    MDFunctionfPrint: TStringField;
    MDFunctionfConfirm: TStringField;
    MDFunctionfCancel: TStringField;
    MDFunctionfModuleId: TIntegerField;
    DBGrid1: TDBGrid;
    MDFunctionfFind: TStringField;
    MDFunctionfFilter: TStringField;
    MDFunctionfExport: TStringField;
    QFunctionfID: TIntegerField;
    QFunctionfModuleID: TIntegerField;
    QFunctionfActionName: TWideStringField;
    QFunctionfName: TWideStringField;
    QFunctionfRun: TBooleanField;
    QFunctionfInsert: TBooleanField;
    QFunctionfEdit: TBooleanField;
    QFunctionfDelete: TBooleanField;
    QFunctionfPrint: TBooleanField;
    QFunctionfConfirm: TBooleanField;
    QFunctionfCancel: TBooleanField;
    QFunctionfFind: TBooleanField;
    QFunctionfFilter: TBooleanField;
    QFunctionfExport: TBooleanField;
    QRightfGroupID: TIntegerField;
    QRightfFunctionID: TIntegerField;
    QRightfRun: TBooleanField;
    QRightfInsert: TBooleanField;
    QRightfEdit: TBooleanField;
    QRightfDelete: TBooleanField;
    QRightfPrint: TBooleanField;
    QRightfConfirm: TBooleanField;
    QRightfCancel: TBooleanField;
    QRightfFind: TBooleanField;
    QRightfFilter: TBooleanField;
    QRightfExport: TBooleanField;
    MDFunctionfActionName: TStringField;
    procedure FormCreate(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
    procedure acExitExecute(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure dsMasterDataChange(Sender: TObject; Field: TField);
    procedure dsModuleDataChange(Sender: TObject; Field: TField);
    procedure acFirstExecute(Sender: TObject);
    procedure acPriorExecute(Sender: TObject);
    procedure acNextExecute(Sender: TObject);
    procedure acLastExecute(Sender: TObject);
    procedure acCancelExecute(Sender: TObject);
    procedure acAllCheckExecute(Sender: TObject);
    procedure acAllUnCheckExecute(Sender: TObject);
    procedure dsMasterStateChange(Sender: TObject);
    procedure acSaveExecute(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  protected
    bModify: Boolean;                   //标志是否修改了数据
    bCanModify: Boolean;                //是否有修改权限
    function SetRight: Boolean; virtual; //保存修改
    function CheckSave: Boolean;        //检测是否保存了修改
    procedure GetAllFunctions;          //得到子系统所有的功能
    procedure GetRight;                 //得到当前组(人)拥有的功能

    procedure GetPermiss; virtual;      {得到当前用户的权限}
  public
    { Public declarations }
  end;

var
  frmGroupRight     : TfrmGroupRight;

implementation

uses DataModule, Global, main;
{$R *.dfm}

{得到用户对当前窗体的操作权限}
procedure TfrmGroupRight.GetPermiss;
begin
  {初始化变量}
  bCanModify := G_bAdmin;

  if G_bAdmin then                      //判断是否为超级用户
    bCanModify := G_bAdmin
  else                                  //否则查找当前用户是否有当前窗体的操作权限
    with dmClient.spUserRight do
      if Locate('fModuleID;fActionName', varArrayOf([iModuleID, sFunctionName]), []) then
        bCanModify := FieldbyName('fEdit').asBoolean;
end;

procedure TfrmGroupRight.GetAllFunctions;
var
  i                 : Integer;
  sFieldName        : string;
begin
  inherited;
  if MDFunction.Active then
  begin
    MDFunction.DisableControls;
    //先清除所有的记录
    MDFunction.First;
    while not MDFunction.Eof do
      MDFunction.Delete;

    with QFunction do
      while not Eof do
      begin
        MDFunction.Append;
        for i := 0 to FieldCount - 1 do
        begin
          //取字段名称
          sFieldName := Fields[i].FieldName;
          //判断类型,赋相应的值
          case Fields[i].DataType of
            ftString, ftWideString:
              MDFunction.FieldbyName(sFieldName).asString := FieldbyName(sFieldName).asString;
            ftInteger:
              MDFunction.FieldbyName(sFieldName).asInteger := FieldbyName(sFieldName).asInteger;
            ftBoolean:
              if FieldbyName(sFieldName).asBoolean then
                MDFunction.FieldbyName(sFieldName).asString := c_UnCheck
              else
                MDFunction.FieldbyName(sFieldName).asString := '';
          end;
        end;
        Next;
      end;
    if MDFunction.State in [dsInsert, dsEdit] then MDFunction.Post;
    MDFunction.First;

    MDFunction.EnableControls;
  end;
end;

procedure TfrmGroupRight.GetRight;
var
  i                 : Integer;
  sFieldName        : string;
begin
  if MDFunction.Active then
  begin
    MDFunction.DisableControls;
    //先清除前面的标志
    with MDFunction do
    begin
      First;
      while not Eof do
      begin
        for i := 0 to FieldCount - 1 do
          if (Fields[i].DataType = ftString)
            and (Fields[i].asString = c_Check) then //如果是字符型且='+',则置为'-'
          begin
            if State <> dsEdit then Edit;
            Fields[i].asString := c_UnCheck;
          end;
        Next;
      end;
      if State in [dsInsert, dsEdit] then Post;
    end;

    //重新设置自己的标志
    with QRight do
      if Active then
      begin
        First;
        while not Eof do
        begin
          if MDFunction.Locate('fID', FieldbyName('fFunctionID').asInteger, []) then
            for i := 0 to FieldCount - 1 do
            begin
              sFieldName := Fields[i].FieldName;
              if (Fields[i].DataType = ftBoolean)
                and FieldbyName(sFieldName).asBoolean then //如果是布尔型且为真,则置为'+'
              begin
                if MDFunction.State <> dsEdit then MDFunction.Edit;
                MDFunction.FieldbyName(sFieldName).asString := c_Check;
              end;
            end;
          Next;
        end;
        if MDFunction.State in [dsInsert, dsEdit] then MDFunction.Post;
        MDFunction.First;
      end;
    MDFunction.EnableControls;
  end;
end;

function TfrmGroupRight.SetRight: Boolean;
var
  bHave             : Boolean;          //是否有真
  i                 : Integer;
begin
  Result := True;
  bHave := false;
  try
    with QRight do
    begin
      First;
      //删除全部为False的记录
      while not Eof do
      begin
        for i := 0 to FieldCount - 1 do
          if Fields[i].DataType = ftBoolean then
          begin
            bHave := Fields[i].asBoolean;
            if bHave then Break;
          end;

        if bHave then
          Next
        else
          Delete;
      end;
      //存盘
      UpdateBatch()
    end;
  except
    on Exception do
    begin
      Messagedlg('存盘失败!', mtError, [mbOk], 0);
      Result := false;
    end;
  end;
end;

function TfrmGroupRight.CheckSave: Boolean;
begin
  Result := True;
  if bModify then
  begin
    case Messagedlg('是否保存当前的修改?', mtWarning, [mbYes, mbNo, mbCancel], 0) of
      mrYes:
        begin
          Result := SetRight;
        end;
      mrNo:
        Result := True;
      mrCancel:
        Result := false;
    end;
    bModify := not Result;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -