sz_ajlbs.~pas
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:18k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit sz_ajlbs;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, Menus, ActnList, DB, XPBarMenu, Grids, DBGridEh, StdCtrls, Mask,
  6.   DBCtrls,  ComCtrls, ExtCtrls, ToolWin, DBCtrlsEh,
  7.   DBLookupEh, DBClient;
  8. type
  9.   Tsz_ajlb = class(TForm)
  10.     CoolBar1: TCoolBar;
  11.     ToolBar1: TToolBar;
  12.     add1: TToolButton;
  13.     xiugai: TToolButton;
  14.     dele1: TToolButton;
  15.     save1: TToolButton;
  16.     Refresh1: TToolButton;
  17.     ToolButton3: TToolButton;
  18.     Panel1: TPanel;
  19.     Splitter1: TSplitter;
  20.     Panel2: TPanel;
  21.     Tree: TTreeView;
  22.     Panel3: TPanel;
  23.     Splitter2: TSplitter;
  24.     Panel4: TPanel;
  25.     Label8: TLabel;
  26.     Label9: TLabel;
  27.     Label10: TLabel;
  28.     Label1: TLabel;
  29.     Label2: TLabel;
  30.     Label3: TLabel;
  31.     Label4: TLabel;
  32.     Edit1: TEdit;
  33.     Panel5: TPanel;
  34.     GroupBox2: TGroupBox;
  35.     DBGridEh1: TDBGridEh;
  36.     XPBarMenu1: TXPBarMenu;
  37.     ActionList1: TActionList;
  38.     Add: TAction;
  39.     Edit: TAction;
  40.     Delete: TAction;
  41.     Save: TAction;
  42.     Refresh: TAction;
  43.     Print: TAction;
  44.     Quit: TAction;
  45.     PopupMenu1: TPopupMenu;
  46.     A1: TMenuItem;
  47.     D1: TMenuItem;
  48.     E1: TMenuItem;
  49.     N5: TMenuItem;
  50.     N6: TMenuItem;
  51.     Label5: TLabel;
  52.     ajlb: TDataSource;
  53.     Label6: TLabel;
  54.     sz_qz: TDataSource;
  55.     sz_xtajlb: TDataSource;
  56.     DBEdit1: TDBEdit;
  57.     DBEdit2: TDBEdit;
  58.     DBEdit3: TDBEdit;
  59.     DBEdit4: TDBEdit;
  60.     DBLookupComboBox1: TDBLookupComboBox;
  61.     procedure QuitExecute(Sender: TObject);
  62.     procedure N5Click(Sender: TObject);
  63.     procedure N6Click(Sender: TObject);
  64.     procedure AddExecute(Sender: TObject);
  65.     procedure EditExecute(Sender: TObject);
  66.     procedure DeleteExecute(Sender: TObject);
  67.     procedure SaveExecute(Sender: TObject);
  68.     procedure RefreshExecute(Sender: TObject);
  69.     procedure FormCreate(Sender: TObject);
  70.     procedure TreeClick(Sender: TObject);
  71.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  72.     procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
  73.     procedure DBEdit2KeyPress(Sender: TObject; var Key: Char);
  74.     procedure DBGridEh1CellClick(Column: TColumnEh);
  75.     procedure TreeChange(Sender: TObject; Node: TTreeNode);
  76.   private
  77.     { Private declarations }
  78.   public
  79.     { Public declarations }
  80.     procedure BtnState();//增,改时的按钮变化
  81.     procedure SaveData(TreeView:TtreeView;dbedit1,dbedit2,dbedit4:Tdbedit);//保存数据
  82.     procedure loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
  83.   end;
  84. var
  85.   sz_ajlb: Tsz_ajlb;
  86.   gnode:TtreeNode;//当前节点
  87.   lbjs_sm1,lbjs_sm2:string;//类别级数
  88.   lb_dmgz1,lb_dmgz2:string;//代码规则
  89.   dsState:string;//增删改的状态
  90. implementation
  91. uses dms,u_public;
  92. {$R *.dfm}
  93. procedure Tsz_ajlb.BtnState();
  94. begin
  95.   if add1.Enabled=true or xiugai.Enabled=true then
  96.   begin
  97.     add1.Enabled:=false;A1.Enabled:=false;
  98.     xiugai.Enabled:=false;E1.Enabled:=false;
  99.     dele1.Enabled:=false;D1.Enabled:=false;
  100.     save1.Enabled:=true;
  101.     //refresh1.Enabled:=false;
  102.   end
  103.   else
  104.   begin
  105.     add1.Enabled:=true;A1.Enabled:=true;
  106.     xiugai.Enabled:=true;E1.Enabled:=true;
  107.     dele1.Enabled:=true;D1.Enabled:=true;
  108.     save1.Enabled:=false;
  109.     refresh1.Enabled:=true;
  110.   end;
  111. end;
  112. //***********************************************
  113. procedure Tsz_ajlb.SaveData(TreeView:TtreeView;dbedit1,dbedit2,dbedit4:Tdbedit);//保存数据
  114. var
  115.   curnode:TTreenode;//已选树节点
  116.   s_xtdm,Pnodetxt,Pnodetxt2,nodetxt:string;//Pnodetxt:取出树上级节点节点的代码;nodetxt:要在树节点上增加的值
  117.   n,n_xtdm:integer;//取出'-'在已选树节点中的位置
  118.   s_dm:string;
  119. begin
  120.    dm.sz_ajlb.edit;
  121.    n:=pos('-',TreeView.Selected.Text)-1;
  122.    Pnodetxt:=copy(TreeView.Selected.Text,1,n);
  123.    //查找当前节点
  124.    n_xtdm:=StrToInt(copy(lbjs_sm2,1,1));
  125.    s_xtdm:=copy(tree.Selected.Text,1,n_xtdm);
  126.    nodetxt:=Pnodetxt+dbedit1.Text+'-'+dbedit2.Text;//现在节点等于原来的加上现在的
  127.    s_dm:=PnodeTxt+dbedit1.Text;
  128.    //增加数据到节点
  129.    dm.sz_ajlb.FieldByName('ajlb_dm').AsString:=s_dm;
  130.    //dm.sz_ajlb.FieldByName('ajlb_mc').AsString:=dbedit2.Text;
  131.    dm.sz_ajlb.FieldByName('ajlb_js').AsInteger:=tree.Selected.Level;
  132.    //dm.sz_ajlb.FieldByName('ajlb_sm').AsString:=dbEdit4.Text;
  133.    dm.sz_ajlb.FieldByName('ajlb_sjlbdm').AsString:=Pnodetxt;
  134.    dm.sz_ajlb.FieldByName('qz_dm').AsString:=s_xtdm;//将一级表的代码赋给二级表
  135.    //dm.sz_ajlb.FieldByName('xt_dm').AsString:=dbLookupcomboboxeh1.DataField;
  136.    //给数组赋值
  137.    dm.sz_ajlb.ApplyUpdates(0);
  138.    if dm.sz_ajlb.ApplyUpdates(0)=0 then
  139.    begin
  140.       application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
  141.       curnode:=TreeView.Items.AddChild(tree.Selected,nodetxt);//增加新的节点
  142.       curnode.ImageIndex:=0;
  143.       curnode.SelectedIndex:=1;
  144.    //-------按钮状态
  145.    end
  146.    else
  147.       application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
  148. end;
  149. //**************************************************
  150. procedure Tsz_ajlb.loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
  151. var
  152.   nodeId1,nodeTxt1,nodeId2,nodeTxt2:string;
  153.   SCodeFormat1,SCodeFormat2,SFirstNodeTxt:string;
  154.   level1,level2:integer;
  155.   mynode:array[0..6] of Ttreenode;
  156.   i,j:integer;//循环标志
  157. begin
  158.    //初始化变量
  159.    SCodeFormat1:=lbjs_sm1 ;//系统案卷类别代码结构
  160.    SCodeFormat2:=lbjs_sm2;//文件类别代码结构
  161.    SFirstNodeTxt:= '案卷类别';//首节点显示的文字
  162.    Screen.Cursor:=crHourGlass;
  163.    Tree.enabled:=true;
  164.    Tree.Items.Clear;
  165.    level1:=0;
  166.    //设置根节点
  167.  mynode[level1]:=Tree.Items.Add(Tree.TopItem,SFirstNodeTxt);
  168.  mynode[level1].ImageIndex:=0;
  169.  mynode[level1].SelectedIndex:=1;
  170.  //遍历数据表,利用编码字段记录排序规律,依次添加树节点
  171.   for i:=0 to treedb1.RecordCount-1 do
  172.   begin
  173.     nodeId1:=trim(treedb1.fieldbyname('qz_dm').AsString);
  174.     nodeTxt1:=nodeId1+'-'+trim(treedb1.fieldbyname('qz_mc').AsString);
  175.     level1:=GetNodeLevel(SCodeFormat1,nodeId1);//获得节点层树
  176.     if level1>0 then
  177.      begin
  178.        mynode[level1]:=tree.Items.AddChild(mynode[level1-1],nodeTxt1);
  179.        mynode[level1].ImageIndex:=0;
  180.        mynode[level1].SelectedIndex:=1;
  181.       //----------
  182.      end;
  183.   //增加第一层主表
  184.      treedb2.close;
  185.      treedb2.commandtext:='select * from sz_ajlb where qz_dm='+''''+nodeId1+''''+'';
  186.      treedb2.open;
  187.      if trim(treedb2.FieldByName('qz_dm').AsString)<>'' then
  188.       begin
  189.        for j:=0 to treedb2.recordcount-1 do
  190.        begin
  191.            nodeId2:=trim(treedb2.fieldbyname('ajlb_dm').asstring);
  192.            nodeTxt2:=NodeId2+'-'+trim(treedb2.fieldbyname('ajlb_mc').asstring);
  193.            level2:=getNodeLevel(SCodeFormat2,nodeId2);//从表的层数
  194.           if level2>1 then
  195.            begin
  196.              mynode[level2]:=tree.Items.AddChild(mynode[level2-1],nodeTxt2);
  197.              mynode[level2].ImageIndex:=0;
  198.              mynode[level2].SelectedIndex:=1;
  199.            end;
  200.          treedb2.Next;
  201.        end;
  202.        end
  203.        else
  204.           treedb2.Next;//不是符合条件的纪录
  205.     treedb1.Next;//下一条纪录
  206.   end;//end for
  207.   mynode[0].Expand(false);
  208.   screen.Cursor:=crdefault;
  209. end;
  210. //**************************************************************
  211. procedure Tsz_ajlb.QuitExecute(Sender: TObject);
  212. begin
  213.   close;
  214. end;
  215. procedure Tsz_ajlb.N5Click(Sender: TObject);
  216. begin
  217.  tree.Selected.Expand(true);
  218. end;
  219. procedure Tsz_ajlb.N6Click(Sender: TObject);
  220. begin
  221.   tree.Selected.Collapse(true);
  222. end;
  223. procedure Tsz_ajlb.AddExecute(Sender: TObject);
  224. begin
  225.  if tree.Selected=nil then  exit//为空退出
  226.   else
  227.     //dm.sz_ajlb.Close;
  228.     //dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+''+''''+'';
  229.     //dm.sz_ajlb.Open;//增加
  230.    dm.sz_ajlb.Append;
  231.   if tree.Selected.level=length(trim(lbjs_sm2)) then
  232.   begin
  233.      application.MessageBox('已经到达最底层的节点'+#13#10+'不能再增加','提示',mb_ok+mb_iconinformation);
  234.      exit;
  235.   end;
  236.   dbedit1.SetFocus;
  237.   dbedit3.Text:=inttostr(tree.Selected.level);
  238.   BtnState();//调用按钮的状态参数
  239.   dsState:='add';
  240. end;
  241. procedure Tsz_ajlb.EditExecute(Sender: TObject);
  242. var s1,s2:string;
  243.     Epos:integer;
  244. begin
  245.    if tree.selected=nil then
  246.       exit
  247.     else
  248.    if tree.Items.Count<>0 then
  249.    if Tree.Items[0].HasChildren<>false then
  250.    begin
  251.        BtnState();//调用按钮的状态参数
  252.        s1:=Tree.Selected.Text;
  253.        Epos:=pos('-',s1);//取得'-'在节点名中的位置
  254.        s2:=copy(s1,0,Epos-1);//
  255.        dm.sz_ajlb.Close;
  256.        dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
  257.        dm.sz_ajlb.Open;
  258.        //dbedit1.Text:=dm.sz_ajlb.fieldbyname('ajlb_dm').AsString;
  259.        Dbedit1.Enabled:=false;
  260.        DBEdit1.Color:=cl3DLight;
  261.        dm.sz_ajlb.edit;
  262.        add1.Enabled:=false;xiugai.Enabled:=false;dele1.Enabled:=false;
  263.        save.Enabled:=true;A1.Enabled:=false;E1.Enabled:=false;D1.Enabled:=false;
  264.    end
  265.    else
  266.    begin
  267.       application.MessageBox('当前表中没有数据,不能修改','提示',mb_ok+mb_iconinformation);
  268.       exit;
  269.    end;
  270. end;
  271. procedure Tsz_ajlb.DeleteExecute(Sender: TObject);
  272. var
  273.    epos:integer;
  274.    s1,s2:string;
  275. begin
  276.   if tree.Selected=nil then  exit
  277.   else if tree.Selected.Level=1 then exit
  278.   else if tree.Selected.HasChildren=true then
  279.     begin
  280.      application.messagebox('该部门包含下级,不能删除','提示',MB_OKCANCEL+mb_iconinformation );
  281.     end
  282.     else
  283.     begin
  284.      if application.messagebox('你确实要删除当前纪录吗?','提示',MB_OKCANCEL+mb_iconinformation )=IDOK then
  285.      begin
  286.        s1:=Tree.Selected.Text;
  287.        Epos:=pos('-',s1);//取得'-'在节点名中的位置
  288.        s2:=copy(s1,0,Epos-1);//
  289.        tree.Selected.Delete;//删除树形表中数据
  290.        dm.sz_ajlb.Close;
  291.        dm.sz_ajlb.CommandText:='delete  from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
  292.        dm.sz_ajlb.execute;
  293.        dm.sz_ajlb.Close;
  294.        dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  295.        dm.sz_ajlb.Open;
  296.        refresh.Execute;
  297.        //删除表中数据
  298.      end;
  299.    end;
  300. end;
  301. procedure Tsz_ajlb.SaveExecute(Sender: TObject);
  302. var
  303.   yanzheng:string;//yangzheng查找数据库中是否有重复记录存在
  304.   i:integer;
  305.   hint:string;
  306.   s1,s2:string;
  307.   Epos:integer;
  308. begin
  309.   if dbedit1.Text='' then
  310.    begin
  311.        application.MessageBox('文件类别代码不能为空','提示',mb_ok+mb_iconinformation);
  312.        exit;
  313.    end;
  314.   if dbedit2.Text='' then
  315.    begin
  316.       application.MessageBox('文件类别名称不能为空','提示',mb_ok+mb_iconinformation);
  317.       exit;
  318.    end;
  319.   //-----------------------------------
  320.  //判断是增加还是修改*****************************************************
  321.   if dbedit1.Enabled=true then
  322.    begin
  323.      if tree.Selected.Level=length(lbjs_sm2) then
  324.       begin
  325.         application.MessageBox('已经到达最底层节点'+#13#10+'不能增加','提示',mb_ok+mb_iconinformation);
  326.         exit;
  327.       end  else
  328.       for i:=0 to tree.Selected.Level do
  329.        begin
  330.          if tree.Selected.Level=i then
  331.           begin//&&&&
  332.                if length(dbedit1.Text)<>strtoInt(copy(lbjs_sm2,i+1,1)) then
  333.                begin
  334.                  hint:='请输入'+copy(lbjs_sm2,i+1,1)+'位代码';
  335.                  application.MessageBox(Pchar(hint),'提示',mb_okcancel+mb_iconinformation);
  336.                  exit;
  337.                end
  338.              else//
  339.                begin
  340.                  {s1:=Tree.Selected.Text;
  341.                  Epos:=pos('-',s1);//取得'-'在节点名中的位置
  342.                  s2:=copy(s1,0,Epos-1);//
  343.                  yanzheng:=s2+dbedit1.Text;
  344.                  dm.sz_ajlb.Close;
  345.                  dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+yanzheng+''''+'';
  346.                  dm.sz_ajlb.Open;
  347.                 if dm.sz_ajlb.FieldByName('ajlb_dm').AsString<>'' then
  348.                 begin
  349.                    application.MessageBox('已经有重复纪录存在','提示',mb_ok+mb_iconinformation);
  350.                    BtnState();
  351.                    exit;
  352.                 end
  353.                 else}
  354.                 begin
  355.                    SaveData(tree,dbedit1,dbedit2,dbedit4);//调用保存过程
  356.                    //refresh.Execute;
  357.                    BtnState();//调用按钮的状态参数
  358.                    break;//成功则退出循环
  359.                 end;
  360.              end;//end if 0
  361.           end//&&&&
  362.           else continue;
  363.        end;//end for
  364.    end//end 结束增加
  365.    else
  366.     begin //修改后的情况
  367.       dm.sz_ajlb.Edit;
  368.       Tree.Selected.EditText;//修改节点
  369.       Tree.Selected.Text:=Dbedit1.text+'-'+DbEdit2.Text;
  370.       tree.Selected.ImageIndex:=0;
  371.       tree.Selected.SelectedIndex:=1;
  372.       //增加数据到节点
  373.       dm.sz_ajlb.FieldByName('ajlb_dm').AsString:=dbedit1.Text;
  374.       dm.sz_ajlb.FieldByName('ajlb_mc').AsString:=dbedit2.Text;
  375.       dm.sz_ajlb.FieldByName('ajlb_js').AsInteger:=StrToInt(dbedit3.text);
  376.       dm.sz_ajlb.FieldByName('ajlb_sm').AsString:=dbEdit4.Text;
  377.       //给数组赋值
  378.        dm.sz_ajlb.ApplyUpdates(0);
  379.        application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
  380.        BtnState();
  381.        dbedit1.Enabled:=true;
  382.        dbedit1.Color:=clwindow;
  383.     end;
  384. end;
  385. procedure Tsz_ajlb.RefreshExecute(Sender: TObject);
  386. begin
  387.   dm.sz_ajlb.close;
  388.   dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  389.   dm.sz_ajlb.Open;
  390.   if dm.sz_ajlb.RecordCount<>0 then
  391.    begin
  392.      Add1.Enabled:=true;xiugai.Enabled:=true;dele1.Enabled:=true;
  393.      A1.Enabled:=true;E1.Enabled:=true;D1.Enabled:=true;save.Enabled:=false;
  394.    end
  395.   else
  396.    begin
  397.      Add1.Enabled:=true;xiugai.Enabled:=false;dele1.Enabled:=false;
  398.      A1.Enabled:=true;E1.Enabled:=false;D1.Enabled:=false;save.Enabled:=false;
  399.    end;
  400. end;
  401. procedure Tsz_ajlb.FormCreate(Sender: TObject);
  402. begin
  403.   dm.sz_qz.Close;
  404.   dm.sz_qz.CommandText:='select * from sz_qz';
  405.   dm.sz_qz.Open;
  406.   dm.sz_ajlb.Close;
  407.   dm.sz_ajlb.CommandText:='Select * from sz_ajlb';
  408.   dm.sz_ajlb.Open;
  409.   //设立主从表关系
  410.   //dm.sz_ajlb.MasterSource:=sz_qz;
  411.   //dm.sz_ajlb.MasterFields:='qz_dm';
  412.   //dm.sz_ajlb.MasterSource:=sz_xtajlb;
  413.   //dm.sz_ajlb.MasterFields:='xt_dm';
  414.   dm.sz_xtajlb.close;
  415.   dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
  416.   dm.sz_xtajlb.Open;
  417.   //刷新两个表
  418.   dm.xt_lbjs.Close;
  419.   dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_qz'+''''+'';
  420.   dm.xt_lbjs.Open;
  421.   lbjs_sm1:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
  422.   //调出主表的编码规则
  423.   dm.xt_lbjs.Close;
  424.   dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
  425.   dm.xt_lbjs.Open;
  426.   lbjs_sm2:=dm.xt_lbjs.fieldbyname('lbjs_sm').asstring;
  427.    //调出二级表的编码规则
  428.   loadtree1(dm.sz_qz,dm.sz_ajlb);
  429.   //调用系统案卷类别表
  430.   dm.sz_qz.Close;
  431.   dm.sz_qz.CommandText:='select * from sz_qz';
  432.   dm.sz_qz.Open;
  433.   dm.sz_ajlb.Close;
  434.   dm.sz_ajlb.CommandText:='Select * from sz_ajlb';
  435.   dm.sz_ajlb.Open;
  436.   //刷新两个表
  437.   dm.xt_lbjs.Close;
  438.   dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
  439.   dm.xt_lbjs.Open;
  440.   lb_dmgz2:=dm.xt_lbjs.fieldbyname('lb_dmgz').AsString;
  441.   //调用文件类别表
  442.   edit1.Text:=lb_dmgz2;
  443. end;
  444. procedure Tsz_ajlb.TreeClick(Sender: TObject);
  445. var
  446.    s1,s2:string;
  447.    i,Epos:integer;
  448. begin
  449.   if tree.selected=nil then
  450.      exit
  451.   else if tree.Selected.Level=1 then
  452.   begin
  453.      dele1.Enabled:=false;D1.Enabled:=false;
  454.      xiugai.Enabled:=false;E1.Enabled:=false;
  455.      add1.Enabled:=true;A1.Enabled:=true;
  456.   end else if tree.Selected.Level=0 then
  457.   begin
  458.      dele1.Enabled:=false;D1.Enabled:=false;
  459.      xiugai.Enabled:=false;E1.Enabled:=false;
  460.      add1.Enabled:=false;A1.Enabled:=false;
  461.      save1.Enabled:=false;
  462.   end else
  463.   begin
  464.     add1.Enabled:=true;A1.Enabled:=true;
  465.     dele1.Enabled:=true;D1.Enabled:=true;
  466.     xiugai.Enabled:=true;E1.Enabled:=true;
  467.   end;
  468.  if Tree.Items[0].HasChildren<>false then
  469.  begin   //选中和不选中的图片显示
  470.      for i:=0 to Tree.items.count-1 do
  471.     begin
  472.       Tree.Items[i].ImageIndex:=0;
  473.       Tree.Items[i].SelectedIndex:=1;
  474.       s1:=Tree.Selected.Text;
  475.       Epos:=pos('-',s1);
  476.       s2:=copy(s1,0,Epos-1);
  477.       dm.sz_ajlb.Close;
  478.       dm.sz_ajlb.CommandText:='select * from sz_ajlb where ajlb_dm='+''''+s2+''''+'';
  479.       dm.sz_ajlb.Open;
  480.       dbedit1.Text:=dm.sz_ajlb.fieldbyname('ajlb_dm').AsString;
  481.       dbedit2.Text:=dm.sz_ajlb.fieldbyname('ajlb_mc').AsString;
  482.       dbedit3.Text:=dm.sz_ajlb.fieldbyname('ajlb_js').AsString;
  483.       dbedit4.Text:=dm.sz_ajlb.fieldbyname('ajlb_sm').AsString;
  484.     end;
  485.  end;
  486. end;
  487.                                                              
  488. procedure Tsz_ajlb.FormClose(Sender: TObject; var Action: TCloseAction);
  489. begin
  490.   dm.sz_qz.Active:=false;
  491.   dm.sz_ajlb.Active:=false;
  492.   dm.sz_xtajlb.Active:=false;
  493.   tree.Free;
  494.   action:=cafree;
  495.   sz_ajlb:=Nil;
  496. end;
  497. procedure Tsz_ajlb.DBEdit1KeyPress(Sender: TObject; var Key: Char);
  498. begin
  499.   if key=#13 then
  500.   begin
  501.      key:=#0;
  502.      selectNext(activeControl,true,true);
  503.   end;
  504. end;
  505. procedure Tsz_ajlb.DBEdit2KeyPress(Sender: TObject; var Key: Char);
  506. begin
  507.   dbEdit1keyPress(Nil,key);
  508. end;
  509. procedure Tsz_ajlb.DBGridEh1CellClick(Column: TColumnEh);
  510. var
  511.   s1,s2:string;
  512.   i:integer;
  513. begin//--1单击每一行时,使树形控件也变化
  514.   s1:=DBGridEh1.Columns[2].DisplayText;
  515.   s2:=DBGridEh1.Columns[3].DisplayText;
  516.   dm.sz_ajlb.Locate('ajlb_dm','+''''+s1+''''+',[]);
  517.   //过滤要搜索的数据
  518.   //dbedit1.Text:=dm.sz_wjlb.fieldbyname('wjlb_dm').AsString;
  519.   //dbedit2.Text:=dm.sz_wjlb.fieldbyname('wjlb_mc').AsString;
  520.   //dbedit3.Text:=dm.sz_wjlb.fieldbyname('wjlb_js').AsString;
  521.   //dbedit4.Text:=dm.sz_wjlb.fieldbyname('wjlb_sm').AsString;
  522.     Add1.Enabled:=false;xiugai.Enabled:=false;
  523.     dele1.Enabled:=false;save.Enabled:=false;
  524.   if Tree.Items[0].HasChildren<>false then
  525.   begin//end if
  526.     for i:=0 to Tree.items.count-1 do
  527.       if Tree.Items[i].Text=s1+'-'+s2 then
  528.      begin
  529.          Tree.Items[i].Selected:=true;
  530.          break;
  531.      end;//end for
  532.   end;//end if
  533. end;//--1
  534. procedure Tsz_ajlb.TreeChange(Sender: TObject; Node: TTreeNode);
  535. begin
  536.   //BtnState();
  537. end;
  538. end.