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

📄 usubsystem.pas

📁 用户权限管理系统
💻 PAS
字号:
unit uSubSystem;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzTabs, RzButton, StdCtrls, RzLabel, Grids, DBGridEh,
  cxControls, cxContainer, cxEdit, cxTextEdit, cxMemo, ExtCtrls,
  cxMaskEdit, cxDropDownEdit, RzPanel, cxRadioGroup, cxCheckBox, DB,
  DBClient, Buttons;

type
  TfrmSubSystem = class(TForm)
    RzButton1: TRzButton;
    RzButton2: TRzButton;
    RzPanel1: TRzPanel;
    RzGroupBox1: TRzGroupBox;
    RzGroupBox2: TRzGroupBox;
    Bevel1: TBevel;
    RzGroupBox3: TRzGroupBox;
    RzGroupBox4: TRzGroupBox;
    cxRadioButton1: TcxRadioButton;
    cxRadioButton2: TcxRadioButton;
    cxCheckBox1: TcxCheckBox;
    cxCheckBox2: TcxCheckBox;
    cxCheckBox3: TcxCheckBox;
    cxCheckBox4: TcxCheckBox;
    cxCheckBox5: TcxCheckBox;
    cxCheckBox6: TcxCheckBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    RzButton3: TRzButton;
    DBGridEh1: TDBGridEh;
    DBGridEh2: TDBGridEh;
    RzButton4: TRzButton;
    RzButton5: TRzButton;
    RzButton6: TRzButton;
    RzButton7: TRzButton;
    cds_Sub: TClientDataSet;
    ds_Sub: TDataSource;
    cds_SubMod: TClientDataSet;
    ds_SubMod: TDataSource;
    cds_SubRight: TClientDataSet;
    cds_SubModV21: TStringField;
    cds_SubModV01: TStringField;
    cds_SubModV02: TStringField;
    cds_SubModV03: TStringField;
    cds_SubModV04: TMemoField;
    SpeedButton5: TSpeedButton;
    procedure RzButton2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cds_SubAfterScroll(DataSet: TDataSet);
    procedure RzButton6Click(Sender: TObject);
    procedure RzButton5Click(Sender: TObject);
    procedure DBGridEh1Enter(Sender: TObject);
    procedure DBGridEh2Enter(Sender: TObject);
    procedure RzButton7Click(Sender: TObject);
    procedure cds_SubModCalcFields(DataSet: TDataSet);
    procedure SpeedButton5Click(Sender: TObject);
    procedure RzButton3Click(Sender: TObject);
    procedure RzButton1Click(Sender: TObject);
    procedure RzButton4Click(Sender: TObject);
  private
    { Private declarations }

    procedure RefreshMainData;
    procedure RefreshData(const Id: string);
    procedure SetControls;
    function GetBH: string;
    function GetModBH(const Id: string): string;

  public
    { Public declarations }
  end;

var
  frmSubSystem: TfrmSubSystem;

implementation

uses untDM, uSubSysAttr, untPublic, uSubSysModAttr, uSubRightChg,
  uSubSysUser;

{$R *.dfm}

procedure TfrmSubSystem.RefreshData(const Id: string);
var
  sSqlstr: string;
begin
  sSqlstr := 'select * from T_005_L' +
    ' where V01=' + QuotedStr(Id) +
    ' order by V02';
  if cds_SubMod.Active then
    cds_SubMod.Close;
  cds_SubMod.XMLData := DM.FreeQuery(sSqlstr);
  cds_SubMod.Active := true;

  sSqlstr := 'select * from V_005_L2' +
    ' where V01=' + QuotedStr(Id);
  if cds_SubRight.Active then
    cds_SubRight.Close;
  cds_SubRight.XMLData := DM.FreeQuery(sSqlstr);
  cds_SubRight.Active := true;
end;

procedure TfrmSubSystem.RefreshMainData;
var
  sSqlstr: string;
begin
  sSqlstr := 'select * from T_005';
  if cds_Sub.Active then
    cds_Sub.Close;
  cds_Sub.XMLData := DM.FreeQuery(sSqlstr);
  cds_Sub.Active := true;
end;

procedure TfrmSubSystem.RzButton2Click(Sender: TObject);
begin
  close;
end;

procedure TfrmSubSystem.SetControls;
begin
  if cds_Sub.Active and (not cds_Sub.IsEmpty) then
  begin
    RefreshData(trim(cds_Sub.fieldbyname('V01').AsString));

    if cds_SubRight.Active and (not cds_SubRight.IsEmpty) then
    begin
      Label5.Caption := trim(cds_SubRight.fieldbyname('V21').AsString);
      Label6.Caption := trim(cds_SubRight.fieldbyname('V22').AsString);
      Label7.Caption := trim(cds_SubRight.fieldbyname('V24').AsString);
      Label8.Caption := trim(cds_SubRight.fieldbyname('V23').AsString);

      if cds_SubRight.fieldbyname('V03').AsInteger = 1 then
        cxCheckBox1.Checked := true
      else
        cxCheckBox1.Checked := false;
      if cds_SubRight.fieldbyname('V04').AsInteger = 1 then
        cxCheckBox2.Checked := true
      else
        cxCheckBox2.Checked := false;
      if cds_SubRight.fieldbyname('V05').AsInteger = 1 then
        cxCheckBox3.Checked := true
      else
        cxCheckBox3.Checked := false;
      if cds_SubRight.fieldbyname('V06').AsInteger = 1 then
        cxCheckBox4.Checked := true
      else
        cxCheckBox4.Checked := false;
      if cds_SubRight.fieldbyname('V07').AsInteger = 1 then
        cxCheckBox5.Checked := true
      else
        cxCheckBox5.Checked := false;
      if cds_SubRight.fieldbyname('V08').AsInteger = 1 then
        cxCheckBox6.Checked := true
      else
        cxCheckBox6.Checked := false;
    end
    else
    begin
      Label5.Caption := '';
      Label6.Caption := '';
      Label7.Caption := '';
      Label8.Caption := '';
      cxCheckBox1.Checked := false;
      cxCheckBox2.Checked := false;
      cxCheckBox3.Checked := false;
      cxCheckBox4.Checked := false;
      cxCheckBox5.Checked := false;
      cxCheckBox6.Checked := false;
    end;
  end
  else
  begin
    RefreshData('');
    Label5.Caption := '';
    Label6.Caption := '';
    Label7.Caption := '';
    Label8.Caption := '';
    cxCheckBox1.Checked := false;
    cxCheckBox2.Checked := false;
    cxCheckBox3.Checked := false;
    cxCheckBox4.Checked := false;
    cxCheckBox5.Checked := false;
    cxCheckBox6.Checked := false;
  end;
end;

procedure TfrmSubSystem.FormCreate(Sender: TObject);
begin
  Label5.Caption := '';
  Label6.Caption := '';
  Label7.Caption := '';
  Label8.Caption := '';
  if not cds_SubMod.Active then
    cds_SubMod.CreateDataSet;

  RefreshMainData;
end;

procedure TfrmSubSystem.cds_SubAfterScroll(DataSet: TDataSet);
begin
  SetControls;
end;

procedure TfrmSubSystem.RzButton6Click(Sender: TObject);
var
  V02, V03, V04: string;
begin
  if cxRadioButton1.Checked then
  begin
    if cds_Sub.Active and not cds_Sub.IsEmpty then
    begin
      frmSubSysAttr := TfrmSubSysAttr.Create(nil);
      frmSubSysAttr.iMod := 1;
      frmSubSysAttr.cxTextEdit1.Text :=
        trim(cds_Sub.fieldbyname('V01').AsString);
      frmSubSysAttr.cxTextEdit2.Text :=
        trim(cds_Sub.fieldbyname('V02').AsString);
      frmSubSysAttr.cxTextEdit3.Text :=
        trim(cds_Sub.fieldbyname('V03').AsString);
      frmSubSysAttr.cxMemo1.Text :=
        trim(cds_Sub.fieldbyname('V04').AsString);
      if frmSubSysAttr.ShowModal = mrOk then
      begin
        V02 := trim(frmSubSysAttr.cxTextEdit2.Text);
        V03 := trim(frmSubSysAttr.cxTextEdit3.Text);
        V04 := trim(frmSubSysAttr.cxMemo1.Text);
        cds_Sub.Edit;
        cds_Sub.FieldByName('V02').Value := V02;
        cds_Sub.FieldByName('V03').Value := V03;
        cds_Sub.FieldByName('V04').Value := V04;
        cds_Sub.Post;
      end;
      frmSubSysAttr.Free;
    end;
  end
  else
  begin
    if cds_SubMod.Active and not cds_SubMod.IsEmpty then
    begin
      frmSubSysModAttr := TfrmSubSysModAttr.Create(nil);
      frmSubSysModAttr.iMod := 1;
      frmSubSysModAttr.RzLabel6.Caption :=
        trim(cds_Sub.FieldByName('V01').AsString);
      frmSubSysModAttr.RzLabel7.Caption :=
        trim(cds_Sub.FieldByName('V02').AsString);
      frmSubSysModAttr.cxTextEdit1.Text :=
        trim(cds_SubMod.FieldByName('V02').AsString);
      frmSubSysModAttr.cxTextEdit2.Text :=
        trim(cds_SubMod.FieldByName('V03').AsString);
      frmSubSysModAttr.cxMemo1.Text :=
        trim(cds_SubMod.FieldByName('V04').AsString);

      if frmSubSysModAttr.ShowModal = mrOk then
      begin
        V03 := trim(frmSubSysModAttr.cxTextEdit2.Text);
        V04 := trim(frmSubSysModAttr.cxMemo1.Text);
        cds_SubMod.Edit;
        cds_SubMod.FieldByName('V03').Value := V03;
        cds_SubMod.FieldByName('V04').Value := V04;
        cds_SubMod.Post;
      end;
      frmSubSysModAttr.Free;
    end;
  end;
end;

procedure TfrmSubSystem.RzButton5Click(Sender: TObject);
var
  V01, V02, V03, V04: string;
begin
  if cxRadioButton1.Checked then
  begin
    if cds_Sub.Active then
    begin
      V01 := GetBH;

      frmSubSysAttr := TfrmSubSysAttr.Create(nil);
      frmSubSysAttr.iMod := 2;
      frmSubSysAttr.cxTextEdit1.Text := V01;
      if frmSubSysAttr.ShowModal = mrOk then
      begin
        V02 := trim(frmSubSysAttr.cxTextEdit2.Text);
        V03 := trim(frmSubSysAttr.cxTextEdit3.Text);
        V04 := trim(frmSubSysAttr.cxMemo1.Text);
        cds_Sub.Append;
        cds_Sub.FieldByName('V01').Value := V01;
        cds_Sub.FieldByName('V02').Value := V02;
        cds_Sub.FieldByName('V03').Value := V03;
        cds_Sub.FieldByName('V04').Value := V04;
        cds_Sub.Post;
      end;
      frmSubSysAttr.Free;
    end;
  end
  else
  begin
    if cds_Sub.Active and not cds_Sub.IsEmpty and
      cds_SubMod.Active then
    begin
      V01 := trim(cds_Sub.FieldByName('V01').AsString);
      V02 := GetModBH(V01);

      frmSubSysModAttr := TfrmSubSysModAttr.Create(nil);
      frmSubSysModAttr.iMod := 2;
      frmSubSysModAttr.RzLabel6.Caption := V01;
      frmSubSysModAttr.RzLabel7.Caption :=
        trim(cds_Sub.FieldByName('V02').AsString);
      frmSubSysModAttr.cxTextEdit1.Text := V02;

      if frmSubSysModAttr.ShowModal = mrOk then
      begin
        V02 := trim(frmSubSysModAttr.cxTextEdit1.Text);
        V03 := trim(frmSubSysModAttr.cxTextEdit2.Text);
        V04 := trim(frmSubSysModAttr.cxMemo1.Text);
        cds_SubMod.Append;
        cds_SubMod.FieldByName('V01').Value := V01;
        cds_SubMod.FieldByName('V02').Value := V02;
        cds_SubMod.FieldByName('V03').Value := V03;
        cds_SubMod.FieldByName('V04').Value := V04;
        cds_SubMod.Post;
      end;
      frmSubSysModAttr.Free;
    end;
  end;
end;

function TfrmSubSystem.GetBH: string;
var
  sSqlstr: string;
begin
  sSqlstr := 'select BH=dbo.FormatStr(isnull(max(V01),0)+1,2) from T_005';
  if DM.cds_User.Active then
    DM.cds_User.Close;
  DM.cds_User.XMLData := DM.FreeQuery(sSqlstr);
  DM.cds_User.Active := true;
  result := trim(DM.cds_User.fieldbyname('BH').AsString);
end;

procedure TfrmSubSystem.DBGridEh1Enter(Sender: TObject);
begin
  cxRadioButton1.Checked := true;

end;

procedure TfrmSubSystem.DBGridEh2Enter(Sender: TObject);
begin
  cxRadioButton2.Checked := true;

end;

procedure TfrmSubSystem.RzButton7Click(Sender: TObject);
var
  V01, V02: string;
begin
  if cxRadioButton1.Checked then
  begin
    if cds_Sub.Active and (not cds_Sub.IsEmpty) then
    begin
      V01 := trim(cds_Sub.fieldbyname('V01').AsString);

      if TPublicFunc.ShowQuestionMsg('您确实要删除此系统吗?') = IDYes then
      begin
        if DM.SubSysDel(V01) <> 0 then
          TPublicFunc.ShowErrorMsg('删除出错!')
        else
          cds_Sub.Delete;
      end;
    end;
  end
  else
  begin
    if cds_SubMod.Active and not cds_SubMod.IsEmpty then
    begin
      V01 := trim(cds_SubMod.fieldbyname('V01').AsString);
      V02 := trim(cds_SubMod.fieldbyname('V02').AsString);
      if TPublicFunc.ShowQuestionMsg('您确实要删除此模块吗?') = IDYes then
      begin
        if DM.SubModDel(V01, V02) <> 0 then
          TPublicFunc.ShowErrorMsg('删除出错!')
        else
          cds_SubMod.Delete;
      end;
    end;
  end;
end;

function TfrmSubSystem.GetModBH(const Id: string): string;
var
  sSqlstr: string;
begin
  sSqlstr := 'select BH=dbo.FormatStr(isnull(max(V02),0)+1,2) from T_005_L' +
    ' where V01=' + QuotedStr(Id);
  if DM.cds_User.Active then
    DM.cds_User.Close;
  DM.cds_User.XMLData := DM.FreeQuery(sSqlstr);
  DM.cds_User.Active := true;
  result := trim(DM.cds_User.fieldbyname('BH').AsString);
end;

procedure TfrmSubSystem.cds_SubModCalcFields(DataSet: TDataSet);
begin
  cds_SubModV21.Value := trim(cds_SubModV01.Value) + trim(cds_SubModV02.Value);
end;

procedure TfrmSubSystem.SpeedButton5Click(Sender: TObject);
var
  iRet, V03, V04, V05, V06, V07, V08: smallint;
  V01: string;
begin
  if cds_Sub.Active and not cds_Sub.IsEmpty then
  begin
    V01 := trim(cds_Sub.fieldbyname('V01').AsString);

    if cxCheckBox1.Checked then
      V03 := 1
    else
      V03 := 0;
    if cxCheckBox2.Checked then
      V04 := 1
    else
      V04 := 0;
    if cxCheckBox3.Checked then
      V05 := 1
    else
      V05 := 0;
    if cxCheckBox4.Checked then
      V06 := 1
    else
      V06 := 0;
    if cxCheckBox5.Checked then
      V07 := 1
    else
      V07 := 0;
    if cxCheckBox6.Checked then
      V08 := 1
    else
      V08 := 0;

    iRet := DM.SubRightAdd(V01, V03, V04, V05, V06, V07, V08);
    if iRet <> 0 then
    begin
      TPublicFunc.ShowErrorMsg('存盘出错!');
      exit;
    end;
  end;
end;

procedure TfrmSubSystem.RzButton3Click(Sender: TObject);
begin
  if cds_Sub.Active and not cds_Sub.IsEmpty then
  begin
    frmSubRightChg := TfrmSubRightChg.Create(nil);
    frmSubRightChg.V01 := trim(cds_Sub.fieldbyname('V01').AsString);
    if cds_SubRight.Active and not cds_SubRight.IsEmpty then
      frmSubRightChg.V021 := trim(cds_SubRight.fieldbyname('V02').AsString)
    else
      frmSubRightChg.V021 := '';

    frmSubRightChg.cSqlStr := 'select * from V_001 order by V01';
    if frmSubRightChg.ShowModal = mrOk then
    begin
      if cds_SubRight.Active then
      begin
        if cds_SubRight.IsEmpty then
          cds_SubRight.Append
        else
          cds_SubRight.Edit;
        cds_SubRight.fieldbyname('V02').Value := frmSubRightChg.V02;
        cds_SubRight.Post;
      end;
      Label5.Caption := frmSubRightChg.V21;
      Label6.Caption := frmSubRightChg.V22;
      Label7.Caption := frmSubRightChg.V24;
      Label8.Caption := frmSubRightChg.V23;
    end;
    frmSubRightChg.Free;
  end;
end;

procedure TfrmSubSystem.RzButton1Click(Sender: TObject);
begin
  close;
end;

procedure TfrmSubSystem.RzButton4Click(Sender: TObject);
var
  V01: string;
begin
  if cds_Sub.Active and not cds_Sub.IsEmpty then
  begin
    V01 := trim(cds_Sub.fieldbyname('V01').AsString);
    frmSubSysUser := TfrmSubSysUser.Create(nil);
    frmSubSysUser.cSqlStr := 'Q_SysUser ' + QuotedStr(V01);
    frmSubSysUser.ShowModal;
    frmSubSysUser.Free;
  end;
end;

end.

⌨️ 快捷键说明

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