📄 hrm100_01.pas
字号:
unit Hrm100_01;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Bas200_04, Wwintl, wwDialog, Wwlocate, ADODB, DB,
ImgList, ActnList, ComCtrls, dxtree, dxdbtree, ToolWin,
ExtCtrls, dxdbtrel, StdCtrls, Mask, DBCtrls, Menus;
type
THrm100_01Form = class(TBas200_04Form)
Label1: TLabel;
Label2: TLabel;
DBEdit1: TDBEdit;
dxTreeViewEdit1: TdxTreeViewEdit;
ADOQuery2: TADOQuery;
ADOQuery1H100_001: TAutoIncField;
ADOQuery1H100_003: TIntegerField;
ADOQuery1H100_004: TBooleanField;
ADOQuery1H100_002: TStringField;
procedure ActSaveExecute(Sender: TObject);
procedure ActInsertExecute(Sender: TObject);
procedure ActUpdateExecute(Sender: TObject);
procedure ActDeleteExecute(Sender: TObject);
procedure dxTreeViewEdit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
AMode:string;
{ Private declarations }
public
{ Public declarations }
procedure SetInterface; override;
end;
var
Hrm100_01Form: THrm100_01Form;
implementation
uses SYSDATA, CommFun;
{$R *.dfm}
procedure THrm100_01Form.ActSaveExecute(Sender: TObject);
var
AUpdateFlag:Boolean;
AName:string;
begin
//保存
AUpdateFlag:=False;
//设置上级部门编号
if dxTreeViewEdit1.Text='' then
ADOQuery1H100_003.Value:=0
else
begin
ADOQuery2.Close;
ADOQuery2.Open;
if ADOQuery2.Locate('H100_002',dxTreeViewEdit1.Text,[loCaseInsensitive]) then
begin
ADOQuery2.Edit;
ADOQuery2.FieldByName('H100_004').Value:=False;
ADOQuery2.Post;
ADOQuery1H100_003.Value:=ADOQuery2.FieldByName('H100_001').Value;
ADOQuery1H100_004.Value:=True;
end;
end;
ADOQuery1H100_004.Value:=True;
AName:=trim(DBEdit1.Text);
//检查上级部门是否已在使用
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select 1 from HRM150 where H150_005='+IntToStr(ADOQuery1H100_003.Value));
SYSDM.qryQuery.Open;
if not SYSDM.qryQuery.IsEmpty then
begin
if ShowDialog('UMS10000084')<>IDYES then Abort; //上级部门已存在相关资料,如果增加下级部门,则相关记录会被替换,是否继续?
AUpdateFlag:=True;
end;
inherited;
ADOQuery1.Refresh;
ADOQuery1.Locate('H100_002',AName,[loCaseInsensitive]);
//替换上级部门
if AUpdateFlag then
begin
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('update HRM150 set H150_005='+IntToStr(ADOQuery1H100_001.Value)+' where H150_005='+IntToStr(ADOQuery1H100_003.Value));
SYSDM.qryQuery.ExecSQL;
end;
if AMode='ADD' then
begin
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select H100_001 from HRM100 where H100_002='+''''+AName+'''');
SYSDM.qryQuery.Open;
//插入权限表
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('insert into SYS500C(S500C_001,S500C_002,S500C_003,S500C_004)');
SYSDM.qryQuery.SQL.Add('select S500A_001,H100_001,''DEP'',0 from HRM100,SYS500A');
SYSDM.qryQuery.SQL.Add('where not exists(select 1 from SYS500C where S500C_001=S500A_001 and S500C_003=''DEP'' and S500C_002=H100_001)');
SYSDM.qryQuery.ExecSQL;
end;
end;
procedure THrm100_01Form.ActInsertExecute(Sender: TObject);
begin
inherited;
//新增
dxTreeViewEdit1.Items:=dxDBTreeView1.Items;
dxTreeViewEdit1.Text:='';
dxTreeViewEdit1.Enabled:=True;
DBEdit1.SetFocus;
AMode:='ADD';
end;
procedure THrm100_01Form.ActUpdateExecute(Sender: TObject);
begin
inherited;
//修改
dxTreeViewEdit1.Items:=dxDBTreeView1.Items;
if dxDBTreeView1.Selected.Parent<>nil then
dxTreeViewEdit1.Text:=dxDBTreeView1.Selected.Parent.Text
else
dxTreeViewEdit1.Text:='';
DBEdit1.SetFocus;
AMode:='UPD';
end;
procedure THrm100_01Form.ActDeleteExecute(Sender: TObject);
var
ATreeNode:TTreeNode;
begin
//删除
ATreeNode:=nil;
if dxDBTreeView1.Selected<>nil then
if dxDBTreeView1.Selected.Parent<>nil then ATreeNode:=dxDBTreeView1.Selected.Parent;
//检查部门资料是否已经在使用
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('select 1 from HRM150 where H150_005='+ADOQuery1H100_001.AsString);
SYSDM.qryQuery.Open;
if not SYSDM.qryQuery.IsEmpty then
begin
ShowMsg('UMS10000085'); //该记录已存在相关资料,不能删除该记录
Abort;
end;
//删除相关的权限记录
SYSDM.qryQuery.Close;
SYSDM.qryQuery.SQL.Clear;
SYSDM.qryQuery.SQL.Add('delete from SYS500C where S500C_003=''DEP'' and S500C_002='+ADOQuery1H100_001.AsString);
SYSDM.qryQuery.ExecSQL;
inherited;
//修改"最低层否"标识
if ATreeNode=nil then Exit;
if not ATreeNode.HasChildren then
begin
ADOQuery1.Edit;
ADOQuery1H100_004.Value:=True;
ADOQuery1.Post;
end;
end;
procedure THrm100_01Form.dxTreeViewEdit1KeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
inherited;
if (Key=vk_delete) or (key=vk_back) then dxTreeViewEdit1.Text:='';
end;
procedure THrm100_01Form.SetInterface;
begin
inherited;
Caption:=GetDBString('HRM10001001'); //部门资料维护
Label1.Caption:=GetDBString('HRM10001002'); //部门名称
Label2.Caption:=GetDBString('HRM10001003'); //上级部门
end;
procedure THrm100_01Form.FormCreate(Sender: TObject);
begin
inherited;
//
end;
initialization
RegisterClass(THrm100_01Form);
finalization
UnRegisterClass(THrm100_01Form);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -