popedom.pas

来自「IT业进销存管理系统源代码Delphi」· PAS 代码 · 共 597 行 · 第 1/2 页

PAS
597
字号
        if pstrUserCode <> 'SYS' then
        begin
          Close;
          CommandText := 'insert into AppGroupAction ' +
            '(gName, mName, aName, fName) values (''' +
            dsJbzl.FieldByName('gName').AsString + ''', mName, aName, fName ' +
            'from AppGroupAction where gName = ''' +
            GetFieldValue('select gName from AppUser where ID=' +
            IntToStr(pintUserId)) + ''')';
          Execute;
        end;
      end;
    end;
    SetSgAction(sgMenu.Cells[2, sgMenu.Row], sgMenu.Cells[0, sgMenu.Row]);
  end;
  if Sender = sgAction then
    with Data.Tmp, sgAction do
    begin
      Close;
      CommandText := 'delete ' +
        'from AppGroupAction ' +
        'where gName = ''' + dsJbzl.FieldByName('gName').AsString + ''' and ' +
        'mName = ''' + sgMenu.Cells[2, sgMenu.Row] + ''' and ' +
        'aName = ''' + Cells[2, Row] + ''' and ' +
        'fName = ''' + Cells[3, Row] + '''';
      Execute;
      if Trim(Cells[0, Row]) = '' then
      begin
        Close;
        CommandText := 'insert into AppGroupAction ' +
          '(gName, mName, aName, fName) values ' +
          '(''' + dsJbzl.FieldByName('gName').AsString + ''',''' + sgMenu.Cells[2, sgMenu.Row] + ''',''' + Cells[2, Row] + ''',''' + Cells[3, Row] + ''')';
        Execute;
      end;
    end;
end;

//sgMenu.DrawCell
procedure TfrmPopedom.sgMenuDrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if (ARow <> 0) Then
    with TStringGrid(Sender), TStringGrid(Sender).Canvas do
    begin
      if Trim(Cells[0, ARow]) = '-' then
      begin
        Brush.Color := $00D7D7AE;
        Pen.Color := clWindowText;
      end
      else if Trim(Cells[0, ARow]) = 'V' then
      begin
        Brush.Color := clInfoBk;
        Pen.Color := clWindowText;
      end
      else
      begin
        Brush.Color := clWhite;
        Pen.Color := clWindowText;
      end;
      if (ARow = Row) then
        if (ACol = 0) and (Sender = sgMenu)  then
          Brush.Color := clNavy
        else
          Font.Color := clBlack;
      if (Sender = sgAction) then
        if Trim(sgMenu.Cells[0, sgMenu.Row]) = '' then
          Brush.Color := $00EFEFEF;
      TextRect(rect, rect.Left + 2, rect.Top + 2, Cells[ACol, ARow]);
    end;
end;

//sgMenu.SelectCell
procedure TfrmPopedom.sgMenuSelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
  SetSgAction(sgMenu.Cells[2, ARow], sgMenu.Cells[0, ARow]);
end;

//SetSgAction
procedure TfrmPopedom.SetSgAction(mName, strCheck: string);
begin
  screen.Cursor := crHourGlass;
  with Data.Tmpl do
  begin
    Close;
    CommandText := 'select fName, aName, aCaption,aIndex ' +
      'from AppAction ' +
      'where mName = ''' + mName + '''' +
      'order by aIndex';
    Open;
    Last;
    First;
    if Eof then
    begin
      self.sgAction.RowCount := 2;
      self.sgAction.Cells[0, 1] := '';
      self.sgAction.Cells[1, 1] := '';
      self.sgAction.Cells[2, 1] := '';
      self.sgAction.Cells[3, 1] := '';
    end
    else
      self.sgAction.RowCount := RecordCount + 1;
    self.sgAction.FixedRows := 1;
    dm.Data.Tmpf.Close;
    dm.Data.Tmpf.CommandText := 'select * ' +
        'from AppGroupAction ' +
        'where gName = ''' + dsJbzl.FieldByName('gName').AsString + ''' and ' +
        'mName = ''' + mName + '''';
    dm.Data.Tmpf.Open;
    while not Eof do
    begin
      if (Trim(strCheck) <> '') and
        (not dm.Data.Tmpf.Locate('fName;aName', VarArrayOf([FieldByName('fName').AsString, FieldByName('aName').AsString]), [])) then
        self.sgAction.Cells[0, RecNo] := '  V'
      else
        self.sgAction.Cells[0, RecNo] := '';
      self.sgAction.Cells[1, RecNo] := FieldByName('aCaption').AsString;
      self.sgAction.Cells[2, RecNo] := FieldByName('aName').AsString;
      self.sgAction.Cells[3, RecNo] := FieldByName('fName').AsString;
      Next;
    end;
  end;
  screen.Cursor := crDefault;
end;

//DBGrid1.Enter
procedure TfrmPopedom.DBGrid1Enter(Sender: TObject);
begin
  DBGrid1.Columns[0].Title.Color := $00999999;
end;

//DBGrid1.Exit
procedure TfrmPopedom.DBGrid1Exit(Sender: TObject);
begin
  DBGrid1.Columns[0].Title.Color := clBtnFace;
end;

//sgMenu.Enter
procedure TfrmPopedom.sgMenuEnter(Sender: TObject);
begin
  TStringGrid(Sender).FixedColor := $00999999;
end;

//sgMenu.Exit
procedure TfrmPopedom.sgMenuExit(Sender: TObject);
begin
  TStringGrid(Sender).FixedColor := clBtnFace;
end;

//dsJbzlBeforeScroll
procedure TfrmPopedom.dsJbzlAfterScroll(DataSet: TDataSet);
var
  i: integer;
begin
  if sgMenu.Cells[1, 1] = '' then
    exit;
  screen.Cursor := crHourGlass;
  with Data.Tmpl, sgMenu do
  begin
    Close;
    CommandText := 'select * ' +
      'from AppGroupMenu ' +
      'where gName = ''' + dsJbzl.FieldByName('gName').AsString + '''';
    Open;
    for i := 1 to sgMenu.RowCount - 1 do
    begin
      if Trim(Cells[0, i]) <> '-' then
      begin
        if Locate('mName', sgMenu.Cells[2, i], []) then
          Cells[0, i] := '  V'
        else
          Cells[0, i] := '   ';
        Cells[1, i] := Cells[1, i];
      end;
    end;
  end;
  SetSgAction(sgMenu.Cells[2, sgMenu.Row], sgMenu.Cells[0, sgMenu.Row]);
  screen.Cursor := crDefault;
end;

//aAll.Execute
procedure TfrmPopedom.aAllExecute(Sender: TObject);
begin
  if Application.MessageBox(Pchar('确定分配所有功能给''' + dsJbzl.FieldByName('gName').AsString + '''吗?'),
    '权限分配', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = IDYES then
  begin
    screen.Cursor := crHourGlass;
    ClearAll;
    with Data.Tmp do
    begin
      Close;
      if pDataBaseType = 'SERVER' then
        CommandText := 'insert into AppGroupMenu ' +
          '(gName, mName) ' +
          'select ''' + dsJbzl.FieldByName('gName').AsString + ''', mName ' +
          'from AppMenu Where mIsParent<>''1'''
      else
        CommandText := 'insert into AppGroupMenu ' +
          '(gName, mName) ' +
          'select ''' + dsJbzl.FieldByName('gName').AsString + ''', mName ' +
          'from AppMenu Where not mIsParent';
      Execute;
    end;
    dsJbzlAfterScroll(dsJbzl);
    screen.Cursor := crDefault;
    Application.MessageBox(Pchar('已把所有功能分配给''' + dsJbzl.FieldByName('gName').AsString + '''!'),
     '权限分配', MB_OK + MB_ICONWARNING );
  end;
end;

//aClear.Execute
procedure TfrmPopedom.aClearExecute(Sender: TObject);
begin
  if Application.MessageBox(Pchar('确定取消已分配给''' + dsJbzl.FieldByName('gName').AsString + '''的所有功能吗?'),
    '权限分配', MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON2) = IDYES then
  begin
    screen.Cursor := crHourGlass;
    ClearAll;
    dsJbzlAfterScroll(dsJbzl);
    screen.Cursor := crDefault;
    Application.MessageBox(Pchar('已取消分配给''' + dsJbzl.FieldByName('gName').AsString + '''的所有功能!'),
      '权限分配', MB_OK + MB_ICONWARNING );
  end;
end;

//aCopy.Execute
procedure TfrmPopedom.aCopyExecute(Sender: TObject);
begin
  frmPopedomCopy := TfrmPopedomCopy.Create(self);
  frmPopedomCopy.ShowModal;
  if frmPopedomCopy.ModalResult = mrok then
  begin
    ClearAll;
    with Data.Tmp do
    begin
      Close;
      CommandText := 'insert into AppGroupMenu (gName, mName) ' +
        'select ''' + dsJbzl.FieldByName('gName').AsString + ''', mName ' +
        'from AppGroupMenu ' +
        'Where gName = ''' + frmPopedomCopy.ComboBox1.Text + '''';
      Execute;
      Close;
      CommandText := 'insert into AppGroupAction (gName, mName, aName) ' +
        'select ''' + dsJbzl.FieldByName('gName').AsString + ''', mName, aName ' +
        'from AppGroupAction ' +
        'Where gName = ''' + frmPopedomCopy.ComboBox1.Text + '''';
      Execute;
    end;
    dsJbzlAfterScroll(dsJbzl);
    Application.MessageBox(Pchar('已从''' + frmPopedomCopy.ComboBox1.Text + '''' +
      '复制权限到''' + dsJbzl.FieldByName('gName').AsString + '''!'),
      '权限分配', MB_OK + MB_ICONWARNING );
  end;
  frmPopedomCopy.Free;
end;

//ClearAll
procedure TfrmPopedom.ClearAll;
begin
  with Data.Tmp do
  begin
    Close;
    CommandText := 'delete from AppGroupMenu ' +
      'where gName = ''' + dsJbzl.FieldByName('gName').AsString + '''';
    Execute;
    Close;
    CommandText := 'delete from AppGroupAction ' +
      'where gName = ''' + dsJbzl.FieldByName('gName').AsString + '''';
    Execute;
  end;
end;

//判断用户是否有此权限
function TfrmPopedom.HavePopedom(strmName, straName, strfName: string): boolean;
var
  strgName: string;
begin
  if pstrUserCode = 'SYS' then
  begin
    Result := True;
    exit;
  end;
  strgName := GetFieldValue('select gName from AppUser where ID=' + IntToStr(pintUserId));
  if (straName = null) or (straName = '') then
    Result := GetFieldValue('select count(*) from AppGroupMenu ' +
        'where gName = ''' + strgName + ''' and ' +
        'mName = ''' + strmName + '''' ) > 0
  else
    Result := GetFieldValue('select count(*) from AppGroupAction ' +
        'where gName = ''' + strgName + ''' and ' +
        'mName = ''' + strmName + ''' and ' +
        'aName = ''' + straName + ''' and ' +
        'fName = ''' + strfName + '''') = 0;
end;

end.

⌨️ 快捷键说明

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