//自定义过程展现treeview中内容
procedure TfrmSmoke.Display_Treeview();
var
Root_Node,Child_Node,ChildSmoke_Node : TTreeNode; //临时根节点、子节点
begin
TreeView.Items.Clear;
//展现省份信息
Query_Province.Close;
Query_Province.SQL.Clear;
Query_Province.SQL.Add('Select Distinct ID,Value From Dictionary Where Type=1');
Query_Province.Open;
while not Query_Province.Eof do
begin
Root_Node:=TreeView.Items.AddFirst(nil,Trim(Query_Province.FieldByName('Value').AsString));
//展现每个省份下面对应的烟厂信息
Query_Manufactory.Close;
Query_Manufactory.SQL.Clear;
Query_Manufactory.SQL.Add('Select M_ID,M_Name From Manufacturer Where M_Province='+ Query_Province.FieldByName('ID').AsString);
Query_Manufactory.Open;
while not Query_Manufactory.Eof do
begin
Child_Node:=TreeView.Items.AddChild(Root_Node,Trim(Query_Manufactory.FieldByName('M_Name').AsString));
Query_Smoke.Close;
Query_Smoke.SQL.Clear;
Query_Smoke.sql.Add('Select * From Goods Where I_Manufacturer=' + trim(Query_Manufactory.FieldByName('M_ID').AsString));
Query_Smoke.Open;
while not Query_Smoke.Eof do
begin
ChildSmoke_Node :=TreeView.Items.AddChild(Child_Node,Trim(Query_Smoke.FieldByName('I_ID').AsString)+'--'+Trim(Query_Smoke.FieldByName('I_Name').AsString));
Query_Smoke.Next;
end;
Query_Manufactory.Next;
end;
Query_Province.Next;
end;
Query_Province.Close;
Query_Manufactory.close;
Query_Smoke.Close;
end;
//在TreeView中显示所有省份信息。
procedure TfrmSmoke.FormShow(Sender: TObject);
begin
Display_Treeview(); //显示数据库中所有的卷烟信息
end;
//单击“卷烟名称”,显示卷烟信息。
procedure TfrmSmoke.TreeViewClick(Sender: TObject);
begin
if TreeView.Items.Count <=0 then Abort;
Query_Smoke.Close;
Query_Smoke.SQL.Clear;
Query_Smoke.SQL.Add('Select * From Goods Where I_ID='''+LeftStr(TreeView.Selected.Text,Pos('--',TreeView.Selected.Text)-1)+''' ');
Query_Smoke.Open;
Edt_ID.Text :=Query_Smoke.FieldByName('I_ID').AsString;
Edt_Name.Text :=Query_Smoke.FieldByName('I_Name').AsString;
Edt_Price.Text :=Query_Smoke.FieldByName('I_Price').AsString;
Edt_BarCode.Text :=Query_Smoke.FieldByName('I_BarCode').AsString;
Edt_Box.Text :=Query_Smoke.FieldByName('I_Box').AsString;
Edt_Piece.Text :=Query_Smoke.FieldByName('I_Piece').AsString;
Edt_Bag.Text :=Query_Smoke.FieldByName('I_Bag').AsString;
Edt_Min.Text :=Query_Smoke.FieldByName('I_UpperLimit').AsString;
Edt_Max.Text :=Query_Smoke.FieldByName('I_LowerLimit').AsString;
Edt_Term.Text :=Query_Smoke.FieldByName('I_Term').AsString;
//显示当前卷烟的存储类别
ComBox_Grade.Style :=csDropDown;
ComBox_Grade.Text :=Query_Smoke.FieldByName('I_Grade').AsString;
{Query_tmp.Close;
Query_tmp.SQL.Clear;
Query_tmp.SQL.Add('Select ID,Value From Dictionary Where ID='''+Query_Smoke.FieldByName('I_Grade').AsString+''' ');
Query_tmp.Open;
ComBox_Grade.Style :=csDropDown;
ComBox_Grade.Text :=Query_tmp.FieldByName('Value').AsString;
}
//显示当前卷烟的级别
Query_tmp.Close;
Query_tmp.SQL.Clear;
Query_tmp.SQL.Add('Select ID,Value From Dictionary Where ID='''+Query_Smoke.FieldByName('I_Class').AsString+''' ');
Query_tmp.Open;
ComBox_Class.Style :=csDropDown;
ComBox_Class.Text :=Query_tmp.FieldByName('Value').AsString;
//存在卷烟即可以修改,否则不能修改。
if Length(Edt_ID.Text) >0 then
begin
Bu_Edit.Enabled :=true; //可以修改卷烟信息
end;
end;