RTFormwork/项目代码/RTBasicsV1/A01基础公司管理/U_SYDept.pas
“ddf” 61630656e9 1
2024-07-07 09:35:27 +08:00

277 lines
7.2 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_SYDept;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
ExtCtrls, DBClient, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData,
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxClasses, cxGridCustomView, cxGrid, cxTextEdit, cxLookAndFeels,
cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, cxNavigator, U_BaseList,
dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges;
type
TfrmSYDept = class(TfrmBaseList)
ToolBar1: TToolBar;
TBRafresh: TToolButton;
TBAdd: TToolButton;
TBDel: TToolButton;
TBClose: TToolButton;
cxDBTreeList1: TcxDBTreeList;
cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
DataSource1: TDataSource;
ADOQueryTree: TADOQuery;
ToolButton1: TToolButton;
ADOQueryTemp: TADOQuery;
ADOQueryCmd: TADOQuery;
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
DPTopName: TEdit;
DPName: TEdit;
DPNo: TEdit;
CDS_Tree: TClientDataSet;
Label4: TLabel;
ToolButton2: TToolButton;
Label5: TLabel;
DPOrder: TEdit;
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TBRafreshClick(Sender: TObject);
procedure TBCloseClick(Sender: TObject);
procedure TBAddClick(Sender: TObject);
procedure cxDBTreeList1Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
procedure TBDelClick(Sender: TObject);
procedure DPNameKeyPress(Sender: TObject; var Key: Char);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
PState: Integer;
FCPID, FTopID: string;
procedure InitTree();
public
{ Public declarations }
end;
var
frmSYDept: TfrmSYDept;
implementation
uses
U_DataLink, U_RTFun;
{$R *.dfm}
procedure TfrmSYDept.InitTree();
var
i: Integer;
begin
try
ADOQueryTree.DisableControls;
with ADOQueryTree do
begin
Close;
SQL.Clear;
SQL.Add('select * from SY_Dept order by DPlevel,DPOrder,DPName');
Open;
end;
SCreateCDS(ADOQueryTree, CDS_Tree);
SInitCDSData(ADOQueryTree, CDS_Tree);
//cxDBTreeList1.Items[0].Expand(false);
cxDBTreeList1.Items[0].Expand(True);
finally
ADOQueryTree.EnableControls;
end;
//cxDBTreeList1.Items[1].Expand(False);
end;
procedure TfrmSYDept.FormDestroy(Sender: TObject);
begin
inherited;
frmSYDept := nil;
end;
procedure TfrmSYDept.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
Action := caFree;
end;
procedure TfrmSYDept.TBRafreshClick(Sender: TObject);
begin
InitTree();
end;
procedure TfrmSYDept.TBCloseClick(Sender: TObject);
begin
Close;
end;
procedure TfrmSYDept.TBAddClick(Sender: TObject);
begin
PState := 11;
DPTopName.Text := Trim(CDS_Tree.fieldbyname('DPName').AsString);
//FTopID:=Trim(ADOQueryTree.fieldbyname('CPID').AsString);
FCPID := '';
DPName.Text := '';
DPNo.Text := '';
DPName.SetFocus;
end;
procedure TfrmSYDept.cxDBTreeList1Click(Sender: TObject);
begin
PState := 22;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from SY_Dept where DPID=''' + Trim(CDS_Tree.fieldbyname('DPParent').AsString) + '''');
Open;
end;
FCPID := Trim(CDS_Tree.fieldbyname('DPID').AsString);
DPTopName.Text := Trim(ADOQueryTemp.fieldbyname('DPName').AsString);
DPName.Text := Trim(CDS_Tree.fieldbyname('DPName').AsString);
DPNo.Text := Trim(CDS_Tree.fieldbyname('DPNo').AsString);
DPOrder.Text := Trim(CDS_Tree.fieldbyname('DPOrder').AsString);
end;
procedure TfrmSYDept.ToolButton1Click(Sender: TObject);
var
maxId: string;
FInt: Integer;
begin
if Trim(DPName.Text) = '' then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ʋ<EFBFBD><C6B2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>', '<27><>ʾ', 0);
Exit;
end;
{if Trim(DPNo.Text)='' then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2BB>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;}
if Trim(DPOrder.Text) = '' then
begin
DPOrder.Text := '99';
end;
if TryStrToInt(Trim(DPOrder.Text), FInt) = False then
begin
Application.MessageBox(<><CBB3><EFBFBD>ŷǷ<C5B7><C7B7><EFBFBD><EFBFBD><EFBFBD>!', '<27><>ʾ', 0);
Exit;
end;
try
ADOQueryCmd.Connection.BeginTrans;
if PState = 11 then
begin
if GetLSNo(ADOQueryCmd, maxId, 'DP', 'SY_Dept', 3, 1) = False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
Exit;
end;
end
else
begin
maxId := Trim(FCPID);
end;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('select * from SY_Dept where DPID=''' + Trim(FCPID) + '''');
Open;
end;
with ADOQueryCmd do
begin
if PState = 11 then
begin
Append;
FieldByName('DPID').Value := Trim(maxId);
FieldByName('DPName').Value := Trim(DPName.Text);
FieldByName('DPNo').Value := Trim(DPNo.Text);
FieldByName('DPParent').Value := Trim(CDS_Tree.fieldbyname('DPID').AsString);
FieldByName('DPLevel').Value := CDS_Tree.fieldbyname('DPLevel').AsInteger + 1;
FieldByName('DPOrder').Value := StrToInt(Trim(DPOrder.Text));
Post;
end
else if PState = 22 then
begin
Edit;
FieldByName('DPID').Value := Trim(maxId);
FieldByName('DPName').Value := Trim(DPName.Text);
FieldByName('DPNo').Value := Trim(DPNo.Text);
FieldByName('DPOrder').Value := StrToInt(Trim(DPOrder.Text));
//FieldByName('CPParent').Value:=Trim(ADOQueryTree.fieldbyname('CPID').AsString);
//FieldByName('CPOrder').Value:=ADOQueryTree.fieldbyname('CPOrder').AsInteger+1;
Post;
end;
end;
ADOQueryCmd.Connection.CommitTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>!', '<27><>ʾ', 0);
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!', '<27><>ʾ', 0);
end;
end;
procedure TfrmSYDept.TBDelClick(Sender: TObject);
begin
if ADOQueryTree.FieldByName('DPLevel').AsInteger = 0 then
Exit;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from SY_Dept where DPParent=''' + Trim(CDS_Tree.fieldbyname('DPID').AsString) + '''');
Open;
if not IsEmpty then
begin
Application.MessageBox('<27>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>֯<EFBFBD><D6AF><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>', '<27><>ʾ', 0);
Exit;
end;
end;
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from SY_User where DPID=''' + Trim(CDS_Tree.fieldbyname('DPID').AsString) + '''');
Open;
if not IsEmpty then
begin
Application.MessageBox('<27><><EFBFBD><EFBFBD>֯<EFBFBD><D6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>', '<27><>ʾ', 0);
Exit;
end;
end;
if Application.MessageBox(<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', '<27><>ʾ', 32 + 4) <> IDYES then
Exit;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
sql.Add('delete SY_Dept where DPID=''' + Trim(CDS_Tree.fieldbyname('DPID').AsString) + '''');
sql.Add('delete SY_Dept where DPParent=''' + Trim(CDS_Tree.fieldbyname('DPID').AsString) + '''');
ExecSQL;
end;
InitTree();
end;
procedure TfrmSYDept.DPNameKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then
DPNo.SetFocus;
end;
procedure TfrmSYDept.FormShow(Sender: TObject);
begin
inherited;
InitTree();
end;
end.