354 lines
9.3 KiB
ObjectPascal
354 lines
9.3 KiB
ObjectPascal
|
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;
|
|||
|
|
|||
|
type
|
|||
|
TfrmSYDept = class(TForm)
|
|||
|
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;
|
|||
|
cxGrid4: TcxGrid;
|
|||
|
Tv4: TcxGridDBTableView;
|
|||
|
cxGridDBColumn1: TcxGridDBColumn;
|
|||
|
cxGridDBColumn7: TcxGridDBColumn;
|
|||
|
cxGridDBColumn8: TcxGridDBColumn;
|
|||
|
cxGridLevel2: TcxGridLevel;
|
|||
|
Label4: TLabel;
|
|||
|
ToolButton2: TToolButton;
|
|||
|
CDS_User: TClientDataSet;
|
|||
|
DSUser: TDataSource;
|
|||
|
Label5: TLabel;
|
|||
|
DPOrder: TEdit;
|
|||
|
v4Column1: TcxGridDBColumn;
|
|||
|
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);
|
|||
|
procedure ToolButton2Click(Sender: TObject);
|
|||
|
procedure cxDBTreeList1DblClick(Sender: TObject);
|
|||
|
procedure v4Column1PropertiesEditValueChanged(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
|
|||
|
frmSYDept:=nil;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSYDept.FormClose(Sender: TObject; var Action: TCloseAction);
|
|||
|
begin
|
|||
|
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
|
|||
|
InitTree();
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSYDept.ToolButton2Click(Sender: TObject);
|
|||
|
begin
|
|||
|
if CDS_Tree.IsEmpty=False then
|
|||
|
begin
|
|||
|
if CDS_User.IsEmpty then Exit;
|
|||
|
if Application.MessageBox('ȷ<><C8B7>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֯<EFBFBD><D6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>','<27><>ʾ',32+4)<>IDYES then Exit;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
sql.Add('Update SY_User Set DPID='''+Trim(CDS_Tree.fieldbyname('DPID').AsString)+'''');
|
|||
|
sql.Add(' where UserId='''+Trim(CDS_User.fieldbyname('UserId').AsString)+'''');
|
|||
|
ExecSQL;
|
|||
|
end;
|
|||
|
with CDS_User do
|
|||
|
begin
|
|||
|
Edit;
|
|||
|
FieldByName('Dept').Value:=Trim(CDS_Tree.fieldbyname('DPName').AsString);
|
|||
|
Post;
|
|||
|
end;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSYDept.cxDBTreeList1DblClick(Sender: TObject);
|
|||
|
begin
|
|||
|
if CDS_Tree.FieldByName('DPLevel').Value=0 then
|
|||
|
begin
|
|||
|
with ADOQueryTemp do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
SQL.Add('select A.*,Dept=(select DPName from SY_Dept where DPID=A.DPID) ');
|
|||
|
SQL.Add(' from SY_User A where UserId not in(''Admin'',''Test'') ');
|
|||
|
SQL.Add(' and Valid=''Y'' ');
|
|||
|
Open;
|
|||
|
end;
|
|||
|
SCreateCDS(ADOQueryTemp,CDS_User);
|
|||
|
SInitCDSData(ADOQueryTemp,CDS_User);
|
|||
|
end else
|
|||
|
begin
|
|||
|
with ADOQueryTemp do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
SQL.Clear;
|
|||
|
SQL.Add('exec P_Select_Dept_User :CYType');
|
|||
|
Parameters.ParamByName('CYType').Value:=Trim(CDS_Tree.fieldbyname('DPID').AsString);
|
|||
|
Open;
|
|||
|
end;
|
|||
|
SCreateCDS(ADOQueryTemp,CDS_User);
|
|||
|
SInitCDSData(ADOQueryTemp,CDS_User);
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
procedure TfrmSYDept.v4Column1PropertiesEditValueChanged(Sender: TObject);
|
|||
|
var
|
|||
|
mvalue:string;
|
|||
|
begin
|
|||
|
mvalue:=TcxTextEdit(Sender).EditingText;
|
|||
|
with CDS_User do
|
|||
|
begin
|
|||
|
Edit;
|
|||
|
FieldByName('MoneyUserName').Value:=Trim(mvalue);
|
|||
|
Post;
|
|||
|
end;
|
|||
|
with ADOQueryCmd do
|
|||
|
begin
|
|||
|
Close;
|
|||
|
sql.Clear;
|
|||
|
sql.Add('Update SY_User Set MoneyUserName='''+Trim(mvalue)+'''');
|
|||
|
sql.Add(' where UserId='''+Trim(CDS_User.fieldbyname('UserId').AsString)+'''');
|
|||
|
ExecSQL;
|
|||
|
end;
|
|||
|
end;
|
|||
|
|
|||
|
end.
|