//------------------------------------------------------------------//
// //
// 单元名: SubjectList //
// //
// 作者: guo //
// //
// 版本: V0.1 //
// //
// 日期: 2007-2-6 //
// //
// 用途与描述:会计科目 //
// 0.1只作界面 //
// //
//------------------------------------------------------------------//
{ 修改日期 2007-3-9
完成功能 }
unit SubjectList;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, Buttons, Menus, DB, ImgList, StdCtrls,
ToolWin, ADODB,WinSkinData, ActnList;
type
TEditStatus = (Add,AddChild,Edit,Look);
PNodeData = ^TNodeData;
TNodeData = record
Subject_no: string;
Parent_no: string;
essential: Integer;
Subject_name: string;
Subject_Code: string;
//Subject_Type: Integer;
Money_Type: Integer;
Balance_flag: Boolean;
Branch_flag: Boolean;
Employee_flag: Boolean;
Deal_flag: Boolean;
item_flag: Boolean;
Number_flag: Boolean;
Number_unit: Integer;
Delete_Flag: Boolean;
end;
TfrmSubjectList = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
tv1: TTreeView;
tv2: TTreeView;
tv3: TTreeView;
tv4: TTreeView;
tv5: TTreeView;
ImageList1: TImageList;
ToolBar: TToolBar;
tbtNew: TToolButton;
tbtModify: TToolButton;
tbtDelete: TToolButton;
tbtDivider1: TToolButton;
tbtPrior: TToolButton;
tbtFind: TToolButton;
tbtDivider3: TToolButton;
tbtExit: TToolButton;
ToolButton5: TToolButton;
ToolButton7: TToolButton;
StatusBar2: TStatusBar;
Panel1: TPanel;
Label1: TLabel;
edtNo: TEdit;
edtChildNo: TEdit;
Label2: TLabel;
edtSubjectCode: TEdit;
Label4: TLabel;
edtSubjectName: TEdit;
Label5: TLabel;
GroupBox1: TGroupBox;
chkBalance0: TRadioButton;
chkBalance1: TRadioButton;
GroupBox2: TGroupBox;
chkBranch: TCheckBox;
chkEmployee: TCheckBox;
chkDeal: TCheckBox;
chkItem: TCheckBox;
chkNumber: TCheckBox;
cbNumberUnit: TComboBox;
cbMoneyType: TComboBox;
Label7: TLabel;
Button1: TButton;
Button2: TButton;
ToolButton1: TToolButton;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure tv1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure tbtNewClick(Sender: TObject);
procedure tbtModifyClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure tv1Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
procedure tv2Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
procedure tv3Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
procedure tv4Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
procedure tv5Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
procedure ToolButton1Click(Sender: TObject);
procedure tbtExitClick(Sender: TObject);
procedure tbtPriorClick(Sender: TObject);
procedure tv1KeyUp(Sender: TObject;
var Key: Word;
Shift: TShiftState);
procedure PageControl1Change(Sender: TObject);
private
FEditStatus: TEditStatus;
FNode:TTreeNode;
procedure LoadCombo;
//初始化窗体COMBO组件
procedure LoadTV;
//初始化窗体TREEVIEW组件
procedure LoadEdit;
//初始化EDIT与check组件
function FindNode(aSubject_no:string;aTV : TTreeView):TTreeNode;
//查找NODE
function GetSelected: TTreeNode;
function GetTV: TTreeView;
procedure SetEditStatus(const Value: TEditStatus);
public
property EditStatus:TEditStatus read FEditStatus write SetEditStatus;
function GetMax(aEssential,aLen: integer;aParentNo: string = ''): string;
end;
var
frmSubjectList: TfrmSubjectList;
implementation
uses dataModule,Global,Main;
{$R *.dfm}
function TfrmSubjectList.FindNode(aSubject_no: string;
aTV: TTreeView): TTreeNode;
var
i:Integer;
begin
Result := nil;
for i:= 0 to aTV.Items.Count -1do
if PNodeData(aTV.Items.Item
.Data)^.Subject_no = aSubject_no then
begin
Result := aTV.Items.Item;
Exit;
end;
end;
procedure TfrmSubjectList.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TfrmSubjectList.FormDestroy(Sender: TObject);
begin
frmSubjectList := nil;
end;
procedure TfrmSubjectList.LoadCombo;
var
Query : TadoQuery;
i:Integer;
begin
try
//cbSubjectType.Clear;
cbNumberUnit.Clear;
cbMoneyType.Clear;
//cbSubjectType.Items.Add('');
cbNumberUnit.Items.Add('');
cbMoneyType.Items.Add('');
Query := TadoQuery.Create(nil);
Query.Connection := Main.frmMain.Conn;
Query.Close;
Query.SQL.Text := 'select * from CW_Accountant_code where Nindex=3';
Query.Open;
{for i:= 0 to Query.RecordCount -1do
begin
cbSubjectType.Items.Add(Query.fieldbyname('sm1').Value);
cbSubjectType.ItemIndex := 0;
Query.Next;
end;
}
//科目类型列表
Query.Close;
Query.SQL.Text := 'select * from CW_Accountant_code where Nindex=2';
Query.Open;
for i:= 0 to Query.RecordCount -1do
begin
cbMoneyType.Items.Add(Query.fieldbyname('sm1').Value);
cbMoneyType.ItemIndex := 0;
Query.Next;
end;
//货币种类列表
Query.Close;
Query.SQL.Text := 'select * from CW_Accountant_code where Nindex=4';
Query.Open;
for i:= 0 to Query.RecordCount -1do
begin
cbNumberUnit.Items.Add(Query.fieldbyname('sm1').Value);
cbNumberUnit.ItemIndex := 0;
Query.Next;
end;
//数量单位列表
finally
Query.Free;
end;
end;
procedure TfrmSubjectList.LoadTV;
var
Query : TadoQuery;
i : Integer;
P : PNodeData;
Node:TTreeNode;
begin
try
tv1.Items.Clear;
tv2.Items.Clear;
tv3.Items.Clear;
tv4.Items.Clear;
tv5.Items.Clear;
Query := TadoQuery.Create(nil);
Query.Connection := Main.frmMain.Conn;
Query.Close;
Query.SQL.Text := 'select * from CW_Accountant_Subject';
Query.Open;
for i := 0 to Query.RecordCount -1do
begin
New(p);
p^.Subject_no := Query.FieldByName('Subject_no').Value;
p^.Parent_no := Query.FieldByName('Parent_no').Value;
p^.essential := Query.FieldByName('essential').Value;
p^.Subject_name := Query.FieldByName('Subject_name').Value;
p^.Subject_Code := Query.FieldByName('Subject_Code').Value;
//p^.Subject_Type := Query.FieldByName('Subject_Type').Value;
p^.Money_Type := Query.FieldByName('Money_Type').Value;
p^.Balance_flag := Query.FieldByName('Balance_flag').Value;
p^.Branch_flag := Query.FieldByName('Branch_flag').Value;
p^.Employee_flag := Query.FieldByName('Employee_flag').Value;
p^.Deal_flag := Query.FieldByName('Deal_flag').Value;
p^.item_flag := Query.FieldByName('item_flag').Value;
p^.Number_flag := Query.FieldByName('Number_flag').Value;
p^.Number_unit := Query.FieldByName('Number_unit').Value;
p^.Delete_Flag := Query.FieldByName('Delete_Flag').Value;
case p^.essential of
0 : //资产类
begin
Node := tv1.Items.AddChildObject(FindNode(p^.Parent_no,tv1),
p^.Subject_no + ' ' + P^.Subject_name,p);
Node.StateIndex := 0;
Node.ImageIndex := 0;
Node.EndEdit(False);
end;
1 : //负债类
begin
Node := tv2.Items.AddChildObject(FindNode(p^.Parent_no,tv2),
p^.Subject_no + ' ' + P^.Subject_name,p);
Node.StateIndex := 0;
Node.ImageIndex := 0;
Node.EndEdit(False);
end;
2 : //权益类
begin
Node := tv3.Items.AddChildObject(FindNode(p^.Parent_no,tv3),
p^.Subject_no + ' ' + P^.Subject_name,p);
Node.StateIndex := 0;
Node.ImageIndex := 0;
Node.EndEdit(False);
end;
3 : //成本类
begin
Node := tv4.Items.AddChildObject(FindNode(p^.Parent_no,tv4),
p^.Subject_no + ' ' + P^.Subject_name,p);
Node.StateIndex := 0;
Node.ImageIndex := 0;
Node.EndEdit(False);
end;
4 : //损益类
begin
Node := tv5.Items.AddChildObject(FindNode(p^.Parent_no,tv5),
p^.Subject_no + ' ' + P^.Subject_name,p);
Node.StateIndex := 0;
Node.ImageIndex := 0;
Node.EndEdit(False);
end;
end;
Query.Next;
end;
finally
Query.Free;
end;
end;
procedure TfrmSubjectList.FormCreate(Sender: TObject);
begin
LoadCombo;
LoadTV;
EditStatus :=Look;
end;
//TV单击事件
procedure TfrmSubjectList.tv1Click(Sender: TObject);
var
i: Integer;
P: PNodeData;
Node: TTreeNode;
Subject_no: string;
begin
LoadEdit;
Node := GetSelected;
if Node = nil then
Exit;
case Node.Level of
0 :
begin
Label7.Visible := False;
edtChildNo.Visible := False;
edtNo.Text := PNodeData(Node.Data)^.Subject_no;
end;
else
begin
Label7.Visible := True;
edtChildNo.Visible := True;
edtNo.Enabled := False;
edtNo.Text := PNodeData(Node.Data)^.Parent_no;
edtChildNo.Text := Copy(PNodeData(Node.Data)^.Subject_no,Length(PNodeData(Node.Data)^.Parent_no) + 1,Length(PNodeData(Node.Data)^.Subject_no));
end;
end;
edtSubjectName.Text := PNodeData(Node.Data)^.Subject_Name;
edtSubjectCode.Text := PNodeData(Node.Data)^.Subject_Code;
//cbSubjectType.Text := Main.frmMain.GetData(PNodeData(Node.Data)^.Subject_Type,1);
cbMoneyType.Text := Main.frmMain.GetData(PNodeData(Node.Data)^.Money_Type,1);
if PNodeData(Node.Data)^.Balance_flag then
chkBalance0.Checked := True
else
chkBalance1.Checked := True;
chkBranch.Checked := PNodeData(Node.Data)^.Branch_flag;
chkEmployee.Checked := PNodeData(Node.Data)^.Employee_flag;
chkDeal.Checked := PNodeData(Node.Data)^.Deal_flag;
chkItem.Checked := PNodeData(Node.Data)^.item_flag;
chkNumber.Checked := PNodeData(Node.Data)^.Number_flag;
cbNumberUnit.Text :=frmMain.GetData(PNodeData(Node.Data)^.Number_unit,1);
end;
procedure TfrmSubjectList.SetEditStatus(const Value: TEditStatus);
procedure SetEnabled(b:Boolean);
var
i:Integer;
begin
for i := 0 to Panel1.ControlCount -1do
begin
Panel1.Controls.Enabled := b;
end;
end;
procedure setToolBar(B:Boolean);
var
i:Integer;
begin
for i := 0 to ToolBar.ControlCount -1do
TToolButton(ToolBar.Controls).Enabled := b;
end;
var
p: PNodeData;
begin
FEditStatus := Value;
case FEditStatus of
Add :
begin
LoadEdit;
SetEnabled(True);
SetToolBar(False);
New(p);
p^.essential := PageControl1.ActivePageIndex;
Label7.Visible := False;
edtChildNo.Visible := False;
p^.Parent_no := '0';
p^.Delete_Flag :=False;
FNode := gettv.Items.AddObject(Nil,'新建一级科目',p);
PageControl1.Enabled := False;
edtNo.Text := GetMax(PageControl1.ActivePageIndex,lvl1);
edtSubjectName.Text := '新建一级科目';
FNode.Selected := True;
end;
AddChild :
begin
if GetSelected = nil then
begin
ShowMessage('你要添加子科目前必须先选择父科目!');
Exit;
end;
LoadEdit;
SetEnabled(True);
SetToolBar(False);
New(p);
p^.essential := PageControl1.ActivePageIndex;
GroupBox1.Enabled := False;
chkBalance0.Checked :=PNodeData(GetSelected.Data)^.Balance_flag;
chkBalance1.Checked := not PNodeData(GetSelected.Data)^.Balance_flag;
Label7.Visible := True;
edtChildNo.Visible := True;
p^.Parent_no := PNodeData(GetSelected.Data)^.Subject_no;
p^.Delete_Flag :=False;
FNode := gettv.Items.AddChildObject(GetSelected,'新建科目',p);
FNode.Selected := True;
FNode.Expand(True);
PageControl1.Enabled := False;
edtNo.Text := PNodeData(GetSelected.Data)^.Parent_no;//更改LVL2为动态获取LVL的函数可以动态设置下级科目的代码长度
edtNo.Enabled := false;
edtChildNo.Text := GetMax(PageControl1.ActivePageIndex,lvl2,PNodeData(GetSelected.Data)^.Parent_no);//更改LVL2为动态获取LVL的函数可以动态设置下级科目的代码长度
edtSubjectName.Text := '新建科目';
FNode.Selected := True;
end;
Edit :
begin
SetEnabled(True);
SetToolBar(False);
edtNo.Enabled := not edtChildNo.Visible;
if FNode.Parent <> nil then
GroupBox1.Enabled :=False;
if GetSelected.getFirstChild <> nil then
begin
edtChildNo.Enabled := False;
edtNo.Enabled := False;
GroupBox1.Enabled :=False;
end;
PageControl1.Enabled := False;
end;
Look :
begin
LoadEdit;
SetEnabled(False);
SetToolBar(True);
PageControl1.Enabled := True;
end;
end;
end;
function TfrmSubjectList.GetSelected: TTreeNode;
begin
Result := nil;
case PageControl1.ActivePageIndex of
0: Result := tv1.Selected;
1: Result := tv2.Selected;
2: Result := tv3.Selected;
3: Result := tv4.Selected;
4: Result := tv5.Selected;
end;
end;
function TfrmSubjectList.GetTV: TTreeView;
begin
case PageControl1.ActivePageIndex of
0: Result := tv1;
1: Result := tv2;
2: Result := tv3;
3: Result := tv4;
4: Result := tv5;
end;
end;
//保存科目
procedure TfrmSubjectList.Button1Click(Sender: TObject);
function isSubject_No(aSubject_No:string):Boolean;
var
Query: TADOQuery;
begin
try
Result := true;
Query := TADOQuery.Create(nil);
Query.Connection := frmMain.Conn;
Query.SQL.Text := 'select * from CW_Accountant_Subject where Subject_No =' +
'''' + aSubject_No + '''';
Query.Open;
if Query.Bof then
Result := False;
finally
Query.Free;
end;
end;
function CheckIn: string;
begin
Result := '';
if edtNo.Text ='' then
begin
Result := '科目编号不能为空!';
edtNo.SetFocus;
Exit;
end else
begin
if edtChildNo.Visible then
begin
if isSubject_No(Trim(edtNo.Text) + Trim(edtChildNo.Text))then
begin
Result := '科目编号为 ' + Trim(edtNo.Text) + Trim(edtChildNo.Text) + ' 的编号已经存在,请另外输入其它编号!';
edtChildNo.SetFocus;
Exit;
end;
end
else
begin
if isSubject_No(Trim(edtNo.Text)) then
begin
Result := '科目编号为 ' + Trim(edtNo.Text) + ' 的编号已经存在,请另外输入其它编号!';
edtNo.SetFocus;
Exit;
end;
end;
end;
if edtChildNo.Visible and (edtChildNo.Text ='') then
begin
Result := '科目编号不完整!';
edtChildNo.SetFocus;
Exit;
end;
if edtSubjectName.Text ='' then
begin
Result := '科目名称不能为空!';
edtSubjectName.SetFocus;
Exit;
end;
{ if cbSubjectType.Text ='' then
begin
Result := '科目类型不能为空!';
cbSubjectType.SetFocus;
Exit;
end;
}
if cbMoneyType.Text ='' then
begin
Result := '货币种类不能为空!';
cbMoneyType.SetFocus;
Exit;
end;
if chkNumber.Checked and (cbNumberUnit.Text = '') then
begin
Result := '数量单位不能为空!';
cbNumberUnit.SetFocus;
Exit;
end;
end;
var
Query: TADOQuery;
ErrStr:string;
Subject_no:string;
begin
ErrStr := CheckIn ;
if ErrStr <>'' then
begin
ShowMessage(ErrStr);
Exit;
end;
try
Query := TADOQuery.Create(nil);
Query.Connection := frmMain.Conn;
if FNode <> nil then
Subject_no := PNodeData(FNode.data)^.Subject_no
else
Subject_no :='';
if edtChildNo.Visible then
PNodeData(FNode.data)^.Subject_no := Trim(edtNo.Text) + Trim(edtChildNo.Text)
else
PNodeData(FNode.data)^.Subject_no := Trim(edtNo.Text);
PNodeData(FNode.data)^.Subject_name := Trim(edtSubjectName.Text);
PNodeData(FNode.data)^.Subject_Code := Trim(edtSubjectCode.Text);
PNodeData(FNode.data)^.Money_Type := frmMain.GetValue(Trim(cbMoneyType.Text),2,1);
PNodeData(FNode.data)^.Balance_flag := chkBalance0.Checked;
PNodeData(FNode.data).Branch_flag := chkBranch.Checked;
PNodeData(FNode.data)^.Employee_flag := chkEmployee.Checked;
PNodeData(FNode.data)^.Deal_flag := chkDeal.Checked;
PNodeData(FNode.data)^.item_flag := chkItem.Checked;
PNodeData(FNode.data)^.Number_flag := chkNumber.Checked;
if chkItem.Checked then
PNodeData(FNode.data)^.Number_unit := frmMain.GetValue(Trim(cbNumberUnit.Text),4,1)
else
PNodeData(FNode.data)^.Number_unit := 0;
PNodeData(FNode.data)^.Delete_Flag := True;
FNode.Text := PNodeData(FNode.data)^.Subject_no + ' ' + PNodeData(FNode.data)^.Subject_name;
Query.SQL.Text := 'INSERT INTO CW_Accountant_Subject(' +
'Subject_No, Parent_No, Essential, Subject_Name, Subject_Code, '+
'Money_Type, Balance_Flag, Branch_Flag, Employee_Flag, Deal_Flag, Item_Flag,'+
'Number_Flag,Number_unit, Delete_Flag) ' +
'VALUESSubject_No, arent_No, :Essential, :Subject_Name, :Subject_Code, '+
':Money_Type, :Balance_Flag, :Branch_Flag, :Employee_Flag, eal_Flag, :Item_Flag,'+
':Number_Flag,:Number_unit, elete_Flag)';
case EditStatus of
Add:
begin
end;
AddChild:
begin
end;
Edit:
begin
if Subject_no ='' then
begin
ShowMessage('数据错误,无法更改!');
EditStatus := Look;
Query.Free;
PageControl1.Enabled := True;
end;
Query.SQL.Text := 'UPDATE CW_Accountant_Subject ' +
'SET Subject_no = :Subject_no, Parent_no = arent_no, '+
'essential = :essential, Subject_name = :Subject_name, '+
'Subject_Code = :Subject_Code,Balance_flag = :Balance_flag,'+
'Money_Type = :Money_Type, Branch_flag = :Branch_flag,' +
'Employee_flag = :Employee_flag,Deal_flag = eal_flag,'+
'item_flag = :item_flag, Number_flag = :Number_flag,' +
'Number_unit = :Number_unit,Delete_Flag = elete_Flag ' +
'WHERE (Subject_no =' + '''' + Subject_no + '''' + ')';
end;
end;
Query.Parameters.ParamByName('Subject_No').Value := PNodeData(FNode.data)^.Subject_no;
Query.Parameters.ParamByName('Parent_No').Value :=PNodeData(FNode.data)^.Parent_no;
Query.Parameters.ParamByName('Essential').Value :=PNodeData(FNode.data)^.Essential;
Query.Parameters.ParamByName('Subject_name').Value :=PNodeData(FNode.data)^.Subject_name;
Query.Parameters.ParamByName('Subject_Code').Value := PNodeData(FNode.data)^.Subject_Code;
Query.Parameters.ParamByName('Money_Type').Value := PNodeData(FNode.data)^.Money_Type;
Query.Parameters.ParamByName('Balance_flag').Value := PNodeData(FNode.data)^.Balance_flag;
Query.Parameters.ParamByName('Branch_flag').Value := PNodeData(FNode.data)^.Branch_flag;
Query.Parameters.ParamByName('Employee_flag').Value := PNodeData(FNode.data)^.Employee_flag;
Query.Parameters.ParamByName('Deal_flag').Value := PNodeData(FNode.data)^.Deal_flag;
Query.Parameters.ParamByName('item_flag').Value := PNodeData(FNode.data)^.item_flag;
Query.Parameters.ParamByName('Number_flag').Value := PNodeData(FNode.data)^.Number_flag;
Query.Parameters.ParamByName('Number_unit').Value := PNodeData(FNode.data)^.Number_unit;
Query.Parameters.ParamByName('Delete_Flag').Value := PNodeData(FNode.data)^.Delete_Flag;
try
if Query.ExecSQL = 0 then
if EditStatus = edit then
LoadTV
else
begin
FNode.Free;
FNode :=nil;
end;
except
if EditStatus = edit then
LoadTV
else
begin
FNode.Free;
FNode :=nil;
end;
end;
EditStatus := Look;
finally
Query.Free;
PageControl1.Enabled := True;
frmSubjectList.tv1Click(nil);
GetTV.SetFocus;
end;
end;
procedure TfrmSubjectList.tbtNewClick(Sender: TObject);
begin
EditStatus := Add;
end;
// 获取下一个科目编号
function TfrmSubjectList.GetMax(aEssential,aLen: integer;aParentNo: string = ''): string;
var
Query:TADOQuery;
Tmpstr:string;
i: Integer;
begin
try
Query := TADOQuery.Create(nil);
Query.Connection := frmMain.Conn;
Tmpstr := '';
for i := 0 to aLen -1do
Tmpstr := Tmpstr + '_';
if aParentNo = '' then
begin
Query.SQL.Text := 'select Max(Subject_No) + 1 as Max from CW_Accountant_Subject where Essential =' +
IntToStr(aEssential);
Query.Open;
if Query.FieldByName('max').IsNull then
begin
Result := IntToStr(aEssential + 1) + '001';
end
else
Result :=inttostr(strtoint(Copy(Query.FieldByName('max').value,1,aLen)));
end
else
begin
Query.SQL.Text := 'select Max(Subject_No) + 1 as Max from CW_Accountant_Subject where Essential =' +
IntToStr(aEssential) + ' And Subject_No like ' +'''' + aParentNo + Tmpstr + '''';
Query.Open;
if Query.FieldByName('max').IsNull then
begin
Tmpstr := '';
for i := 0 to aLen -2do
Tmpstr := Tmpstr + '0';
Result := Tmpstr + '1';
end else
Result := Copy(inttostr(Query.FieldByName('max').value) ,Length(Query.FieldByName('max').value)-alen + 1,Length(Query.FieldByName('max').value));
end;
finally
Query.Free;
end;
end;
procedure TfrmSubjectList.tbtModifyClick(Sender: TObject);
begin
EditStatus :=AddChild;
end;
procedure TfrmSubjectList.Button2Click(Sender: TObject);
begin
if EditStatus <> Edit then
begin
FNode.Free;
FNode := nil;
end;
EditStatus := look;
frmSubjectList.tv1Click(nil);
GetTV.SetFocus;
end;
procedure TfrmSubjectList.LoadEdit;
var
i:integer;
begin
for i := 0 to Panel1.ControlCount -1do
begin
if Panel1.Controls.ClassName = 'TEdit' then
TEdit(Panel1.Controls).Text :='';
if Panel1.Controls.ClassName = 'TCheckBox' then
TCheckBox(Panel1.Controls).Checked := False;
if Panel1.Controls.ClassName = 'TComboBox' then
TComboBox(Panel1.Controls).ItemIndex := 0;
end;
end;
procedure TfrmSubjectList.tv1Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
begin
AllowEdit := False;
end;
procedure TfrmSubjectList.tv2Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
begin
AllowEdit := False;
end;
procedure TfrmSubjectList.tv3Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
begin
AllowEdit := False;
end;
procedure TfrmSubjectList.tv4Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
begin
AllowEdit := False;
end;
procedure TfrmSubjectList.tv5Editing(Sender: TObject;
Node: TTreeNode;
var AllowEdit: Boolean);
begin
AllowEdit := False;
end;
procedure TfrmSubjectList.ToolButton1Click(Sender: TObject);
begin
FNode := GetSelected;
if FNode = nil then
begin
ShowMessage('请选择要修改的科目!');
Exit;
end;
EditStatus := Edit;
frmSubjectList.tv1Click(nil);
end;
procedure TfrmSubjectList.tbtExitClick(Sender: TObject);
var
Query: TADOQuery;
begin
FNode := GetSelected;
if FNode = nil then
begin
ShowMessage('请选择要删除的科目后再进行删除操作!');
Exit;
end;
if not PNodeData(FNode.Data)^.Delete_Flag then
begin
ShowMessage('该科目是系统内置科目,不允许删除!');
Exit;
end;
if FNode.getFirstChild <> nil then
begin
ShowMessage('该科目下面有子科目,不能进行删除操作!');
Exit;
end;
if MessageBox(Self.Handle,PChar('是否删除科目编号为 ' + PNodeData(FNode.Data)^.Subject_no + ' 的科目?'),PChar('删除科目:'), MB_YESNO) = mrNo then
Exit;
try
Query := TADOQuery.Create(nil);
Query.Connection := frmMain.Conn;
Query.SQL.Text := 'Delete from CW_Accountant_Subject where Subject_no =' +
'''' + PNodeData(FNode.Data)^.Subject_no + '''';
if Query.ExecSQL = 0 then
begin
ShowMessage('删除失败!');
Exit;
end;
FNode.Free;
EditStatus := Look;
MessageBox(Self.Handle,PChar('删除成功!'),PChar('删除科目:'), MB_OK);
frmSubjectList.tv1Click(nil);
finally
Query.Free;
end;
end;
procedure TfrmSubjectList.tbtPriorClick(Sender: TObject);
begin
// if FNode <> nil then
// begin
FNode := nil;
//end;
frmSubjectList.FormCreate(nil);
EditStatus := Look;
frmSubjectList.tv1Click(nil);
end;
procedure TfrmSubjectList.tv1KeyUp(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if not ((Key = 40) or (Key = 39) or (Key = 38) or (Key = 37)) then
Exit;
frmSubjectList.tv1Click(nil);
end;
procedure TfrmSubjectList.PageControl1Change(Sender: TObject);
begin
frmSubjectList.tv1Click(nil);
end;
end.
树的操作..
乘法表 应该是嵌套2个1-9的for循环...
6年写不出这样的东西确实有点那个了..