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

📄 groupright.pas

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

procedure TfrmGroupRight.FormCreate(Sender: TObject);
begin
  inherited;
  //得到权限许可
  GetPermiss;
  acAllCheck.Enabled := bCanModify;
  acAllUnCheck.Enabled := bCanModify;

  if not MDFunction.Active then MDFunction.Open;
  if not QMaster.Active then QMaster.Open;
  if not QModule.Active then QModule.Open;
  if not QRight.Active then QRight.Open;
  if not QFunction.Active then QFunction.Open;
  GetAllFunctions;
  GetRight;
end;

procedure TfrmGroupRight.DBGrid1DblClick(Sender: TObject);
var
  i, iCol           : Integer;
  sFieldName,cFieldName        : string;
begin
  inherited;
  if bCanModify then
  begin
    //ShowMessage('bCanModify');
    iCol := TStringGrid(DBGrid1).Col;
    cFieldName:=DBGrid1.Columns[iCol-1].FieldName;
    //ShowMessage(cFieldName);
    with MDFunction do
    begin
      if Trim(FieldByName(cFieldName).asString) = c_UnCheck then
      begin
        if State <> dsEdit then Edit;
        //如果运行权未选择,则先选择运行权
        if (MDFunction.FieldByName(cFieldName).FieldName<>'fRun') and (FieldByName('fRun').asString <> c_Check) then FieldByName('fRun').asString := c_Check;
        FieldByName(cFieldName).AsString:= c_Check;
        bModify := True;
      end
      else if Trim(MDFunction.FieldByName(cFieldName).asString) = c_Check then
      begin
        if MDFunction.State <> dsEdit then MDFunction.Edit;
        MDFunction.FieldByName(cFieldName).asString := c_UnCheck;
        bModify := True;
        //如果取消运行权,则其它的权利都取消
        //ShowMessage('jin');
        //ShowMessage(IntToStr(MDFunction.Fields.Count));
        //Exit;
        if FieldByName(cFieldName).FieldName='fRun' then
        begin
            //ShowMessage(IntToStr(MDFunction.Fields.Count));
            //Exit;
          for i := MDFunction.Fields.IndexOf(FieldByName(cFieldName)) to FieldCount - 1 do
            if (Fields[i].DataType = ftString)
              and (Fields[i].asString = c_Check) then
              Fields[i].asString := c_UnCheck;
        end;
      end
      else
      begin
        //ShowMessage('jin1');
        exit;
      end;

      //更新权限
      if not QRight.Locate('fFunctionID', FieldbyName('fID').asInteger, []) then
      begin
        QRight.Append;
        QRight.FieldbyName('fFunctionID').asInteger := FieldbyName('fID').asInteger;
        QRight.FieldbyName('fGroupId').asInteger := QMaster.FieldbyName('fID').asInteger;
      end
      else
        QRight.Edit;

      for i := 0 to QRight.FieldCount - 1 do
      begin
        sFieldName := QRight.Fields[i].FieldName;
        if (QRight.Fields[i].DataType = ftBoolean) then
        begin
          //if not (QRight.State in [dsInsert,dsEdit]) then QRight.Edit ;
          QRight.FieldbyName(sFieldName).asBoolean :=
            FieldbyName(sFieldName).asString = c_Check;
        end;
      end;
    end;

    dsMasterStateChange(self);
  end;
end;

procedure TfrmGroupRight.acExitExecute(Sender: TObject);
begin
  inherited;
  Close;
end;

procedure TfrmGroupRight.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  inherited;
  CanClose := CheckSave;
end;

procedure TfrmGroupRight.dsMasterDataChange(Sender: TObject;
  Field: TField);
begin
  inherited;
  GetRight;
  dsMasterStateChange(self);
end;

procedure TfrmGroupRight.dsModuleDataChange(Sender: TObject;
  Field: TField);
begin
  inherited;
  GetAllFunctions;
  GetRight;
end;

procedure TfrmGroupRight.acFirstExecute(Sender: TObject);
begin
  inherited;
  QMaster.First;
end;

procedure TfrmGroupRight.acPriorExecute(Sender: TObject);
begin
  inherited;
  QMaster.Prior;
end;

procedure TfrmGroupRight.acNextExecute(Sender: TObject);
begin
  inherited;
  QMaster.Next;
end;

procedure TfrmGroupRight.acLastExecute(Sender: TObject);
begin
  inherited;
  QMaster.Last;
end;

procedure TfrmGroupRight.acCancelExecute(Sender: TObject);
begin
  inherited;
  if Messagedlg('您确定要取消修改吗?', mtWarning, [mbOk, mbCancel], 0) = mrOk then
  begin
    QRight.CancelBatch();
    GetRight;
    bModify := false;
    dsMasterStateChange(self);
  end;
end;

procedure TfrmGroupRight.acAllCheckExecute(Sender: TObject);
var
  i                 : Integer;
  sFieldName        : string;
begin
  inherited;
  MDFunction.DisableControls;

  with MDFunction do
  begin
    First;
    while not Eof do
    begin

      //更新权限,如果在Right表中没有该记录,则增加,否则置编辑状态
      if not QRight.Locate('fFunctionID', FieldbyName('fID').asInteger, []) then
      begin
        QRight.Append;
        QRight.FieldbyName('fFunctionID').asInteger := FieldbyName('fID').asInteger;
        QRight.FieldbyName('fGroupId').asInteger := QMaster.FieldbyName('fID').asInteger;
      end
      else
        QRight.Edit;

      for i := 0 to FieldCount - 1 do
      begin
        sFieldName := Fields[i].FieldName;
        if (Fields[i].DataType = ftString)
          and (Fields[i].asString = c_UnCheck) then //如果是字符型且='-',则置为'+'
        begin
          if State <> dsEdit then Edit;
          Fields[i].asString := c_Check;
          //Right表中也相应的置为True
          QRight.FieldbyName(sFieldName).asBoolean := True;

          bModify := True;
        end;
      end;

      {For i:=0 to QRight.FieldCount-1 do
          if (QRight.Fields[i].DataType = ftBoolean) Then
               QRight.Fields[i].AsBoolean:=True;}

      Next;
    end;
    if State in [dsInsert, dsEdit] then Post;
    First;
  end;

  MDFunction.EnableControls;

  dsMasterStateChange(self);
end;

procedure TfrmGroupRight.acAllUnCheckExecute(Sender: TObject);
var
  i                 : Integer;
begin
  inherited;
  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;
          bModify := True;
        end;
      Next;
    end;
    if State in [dsInsert, dsEdit] then Post;
    First;
  end;

  //清除Right表中的所有权限
  with QRight do
  begin
    First;
    while not Eof do
    begin
        self.QFunction.First;
        if Self.QFunction.Locate('fID',self.QRight.FieldValues['fFunctionID'],[]) then
            Delete
        else
            Self.QRight.Next;
    end;
  end;

  MDFunction.EnableControls;

  dsMasterStateChange(self);
end;

procedure TfrmGroupRight.dsMasterStateChange(Sender: TObject);
begin
  inherited;
  {设置导航按钮的有效性}
  acFirst.Enabled := (not QMaster.Bof) and not bModify;
  acLast.Enabled := (not QMaster.Eof) and not bModify;
  acPrior.Enabled := (acFirst.Enabled) and not bModify;
  acNext.Enabled := (acLast.Enabled) and not bModify;

  acSave.Enabled := bModify;
  acCancel.Enabled := bModify;

  wwDBGrid1.Enabled := not bModify;
  wwDBGrid2.Enabled := not bModify;

end;

procedure TfrmGroupRight.acSaveExecute(Sender: TObject);
begin
  inherited;
  if SetRight then
  begin
    bModify := false;
    dsMasterStateChange(self);
    //self.DBGrid1.Refresh;
    Self.MDFunction.Refresh;
  end;
end;

procedure TfrmGroupRight.FormDestroy(Sender: TObject);
begin
  inherited;
    frmGroupRight := nil;
end;

procedure TfrmGroupRight.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
    Action:=caFree;
end;

end.

⌨️ 快捷键说明

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