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

Delphi控件源码

开发平台:

Delphi

  1. unit Am_yljs;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ImgList, DB, DBClient, XPBarMenu, Grids, DBGrids, StdCtrls,
  6.   ComCtrls, ExtCtrls, ToolWin, Menus, ActnList, DBGridEh;
  7. type
  8.   TAm_ylj = class(TForm)
  9.     CoolBar1: TCoolBar;
  10.     ToolBar1: TToolBar;
  11.     add1: TToolButton;
  12.     dele1: TToolButton;
  13.     YLJ1: TToolButton;
  14.     WJCZ: TToolButton;
  15.     Panel1: TPanel;
  16.     Splitter1: TSplitter;
  17.     Panel2: TPanel;
  18.     Tree: TTreeView;
  19.     Panel3: TPanel;
  20.     Splitter2: TSplitter;
  21.     Panel4: TPanel;
  22.     GroupBox1: TGroupBox;
  23.     Panel5: TPanel;
  24.     GroupBox2: TGroupBox;
  25.     ActionList1: TActionList;
  26.     Add: TAction;
  27.     Edit: TAction;
  28.     Delete: TAction;
  29.     Save: TAction;
  30.     Refresh: TAction;
  31.     Print: TAction;
  32.     Quit: TAction;
  33.     PopupMenu1: TPopupMenu;
  34.     A1: TMenuItem;
  35.     D1: TMenuItem;
  36.     E1: TMenuItem;
  37.     N5: TMenuItem;
  38.     N6: TMenuItem;
  39.     xiugai: TToolButton;
  40.     ToolButton3: TToolButton;
  41.     V_ylj: TDataSource;
  42.     DBGridEh1: TDBGridEh;
  43.     ToolButton1: TToolButton;
  44.     PopupMenu2: TPopupMenu;
  45.     N7: TMenuItem;
  46.     N8: TMenuItem;
  47.     N9: TMenuItem;
  48.     N11: TMenuItem;
  49.     Ds_Wjgl: TDataSource;
  50.     DBGridEh2: TDBGridEh;
  51.     XPBarMenu2: TXPBarMenu;
  52.     ClientDataSet1: TClientDataSet;
  53.     ClientDataSet2: TClientDataSet;
  54.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  55.     procedure AddExecute(Sender: TObject);
  56.     procedure QuitExecute(Sender: TObject);
  57.     procedure FormCreate(Sender: TObject);
  58.     procedure EditExecute(Sender: TObject);
  59.     procedure TreeClick(Sender: TObject);
  60.     procedure RefreshExecute(Sender: TObject);
  61.     procedure DeleteExecute(Sender: TObject);
  62.     procedure N7Click(Sender: TObject);
  63.     procedure N8Click(Sender: TObject);
  64.     procedure DBGridEh1DblClick(Sender: TObject);
  65.     procedure N9Click(Sender: TObject);
  66.     procedure FormShow(Sender: TObject);
  67.     procedure DBGridEh2DblClick(Sender: TObject);
  68.     procedure YLJ1Click(Sender: TObject);
  69.     procedure N5Click(Sender: TObject);
  70.     procedure N6Click(Sender: TObject);
  71.     procedure TreeChange(Sender: TObject; Node: TTreeNode);
  72.   private
  73.     { Private declarations }
  74.   public
  75.     { Public declarations }
  76.     epos1,EPos2,s_ajlb:string;//代码,名称值
  77.     procedure loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树 
  78.   end;
  79. var
  80.   Am_ylj: TAm_ylj;
  81.   gnode:TtreeNode;//当前节点
  82.   lbjs_sm1,lbjs_sm2:string;//类别级数
  83.   lb_dmgz1,lb_dmgz2:string;//代码规则
  84.   dsState:string;//增删改的状态
  85.   ylj_s1,ylj_s2:string;
  86.   s_ajxh:string;//案卷序号
  87. implementation
  88. uses mainfrms,dms, Am_ylj_bjs,u_public, Am_wjbjs;
  89. {$R *.dfm}
  90. procedure Tam_ylj.loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
  91. var
  92.   nodeId1,nodeTxt1,nodeId2,nodeTxt2:string;
  93.   SCodeFormat1,SCodeFormat2,SFirstNodeTxt:string;
  94.   level1,level2:integer;
  95.   mynode:array[0..6] of Ttreenode;
  96.   i,j:integer;//循环标志
  97. begin
  98.    //初始化变量
  99.    SCodeFormat1:=lbjs_sm1 ;//系统案卷类别代码结构
  100.    SCodeFormat2:=lbjs_sm2;//文件类别代码结构
  101.    SFirstNodeTxt:= '案卷类别';//首节点显示的文字
  102.    Screen.Cursor:=crHourGlass;
  103.    Tree.enabled:=true;
  104.    Tree.Items.Clear;
  105.    level1:=0;
  106.    //设置根节点
  107.  mynode[level1]:=Tree.Items.Add(Tree.TopItem,SFirstNodeTxt);
  108.  mynode[level1].ImageIndex:=0;
  109.  mynode[level1].SelectedIndex:=1;
  110.  //遍历数据表,利用编码字段记录排序规律,依次添加树节点
  111.   for i:=0 to treedb1.RecordCount-1 do
  112.   begin
  113.     nodeId1:=trim(treedb1.fieldbyname('qz_dm').AsString);
  114.     nodeTxt1:=nodeId1+'-'+trim(treedb1.fieldbyname('qz_mc').AsString);
  115.     level1:=GetNodeLevel(SCodeFormat1,nodeId1);//获得节点层树
  116.     if level1>0 then
  117.      begin
  118.        mynode[level1]:=tree.Items.AddChild(mynode[level1-1],nodeTxt1);
  119.        mynode[level1].ImageIndex:=0;
  120.        mynode[level1].SelectedIndex:=1;
  121.       //----------
  122.      end;
  123.   //增加第一层主表
  124.      treedb2.close;
  125.      treedb2.commandtext:='select * from sz_ajlb where qz_dm='+''''+nodeId1+''''+'';
  126.      treedb2.open;
  127.      if trim(treedb2.FieldByName('qz_dm').AsString)<>'' then
  128.       begin
  129.        for j:=0 to treedb2.recordcount-1 do
  130.        begin
  131.            nodeId2:=trim(treedb2.fieldbyname('ajlb_dm').asstring);
  132.            nodeTxt2:=NodeId2+'-'+trim(treedb2.fieldbyname('ajlb_mc').asstring);
  133.            level2:=getNodeLevel(SCodeFormat2,nodeId2);//从表的层数
  134.           if level2>1 then
  135.            begin
  136.              mynode[level2]:=tree.Items.AddChild(mynode[level2-1],nodeTxt2);
  137.              mynode[level2].ImageIndex:=0;
  138.              mynode[level2].SelectedIndex:=1;
  139.            end;
  140.          treedb2.Next;
  141.        end;
  142.        end
  143.        else
  144.           treedb2.Next;//不是符合条件的纪录
  145.     treedb1.Next;//下一条纪录
  146.   end;//end for
  147.   mynode[0].Expand(false);
  148.   screen.Cursor:=crdefault;
  149. end;
  150. //**************************************************************
  151. procedure TAm_ylj.FormClose(Sender: TObject; var Action: TCloseAction);
  152. begin
  153.   dm.V_ylj.Active:=false;//预立卷视图
  154.   dm.Am_ajgl.Active:=false;//案卷管理
  155.   dm.sz_bgqx.Active:=false;//保管期限
  156.   dm.sz_mj.active:=false;//密级
  157.   //--------------------
  158.   dm.sz_qz.Active:=false;//全宗
  159.   dm.sz_ajlb.Active:=false;//案卷类别
  160.   //---------------
  161.   dm.sz_xtajlb.Active:=false;//系统案卷类别
  162.   //---------------
  163.   dm.xt_lbjs.Active:=false;//类别级数
  164.   dm.Am_wjgl.active:=false;//文件管理
  165.   dm.V_Wjgl.Active:=false;//文件视图
  166.   dm.sz_ztlb.Active:=false;//载体类别
  167.   dm.sz_wjlb.active:=false;//文件类别
  168.   dm.sz_bm.Active:=false;//部门
  169.   action:=cafree;
  170.   Am_ylj:=nil;
  171. end;
  172. procedure TAm_ylj.AddExecute(Sender: TObject);//增加
  173. var n:integer;
  174. begin
  175.   if      tree.Selected=nil then  exit//为空退出
  176.   else
  177.   if tree.Selected.HasChildren=false then
  178.    begin
  179.      dsState:='add';
  180.      n:=pos('-',tree.selected.Text)-1;
  181.      epos1:=copy(tree.Selected.Text,1,n);//案卷代码
  182.      Epos2:=copy(tree.Selected.Text,n+2,length(tree.Selected.Text));
  183.      if am_ylj_bj=nil then
  184.      begin
  185.        am_ylj_bj:=Tam_ylj_bj.create(application);
  186.        am_ylj_bj.DBEditEh1.Text:=Epos2;
  187.        dm.Am_ajgl.Close;
  188.        dm.am_ajgl.CommandText:='select * from am_ajgl where aj_dm='+''''+''''+'';
  189.        dm.Am_ajgl.Open;
  190.        am_ylj_bj.showmodal;
  191.      end;
  192.    end;//判断是否到达最底层
  193. end;
  194. procedure TAm_ylj.QuitExecute(Sender: TObject);
  195. begin
  196.  close;
  197. end;
  198. procedure TAm_ylj.FormCreate(Sender: TObject);
  199. begin
  200.      dm.Am_ajgl.Active:=true;//案卷管理
  201.      dm.sz_bgqx.Active:=true;//保管期限
  202.      dm.sz_mj.active:=true;//密级
  203.      dm.sz_ztlb.Active:=true;//载体类别
  204.      dm.sz_wjlb.active:=true;//文件类别
  205.      dm.sz_bm.Active:=true;//部门
  206.      //-------
  207.      dm.sz_qz.Close;
  208.      dm.sz_qz.CommandText:='select * from sz_qz';
  209.      dm.sz_qz.Open;//全宗
  210.      dm.sz_ajlb.Close;
  211.      dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  212.      dm.sz_ajlb.Open;//案卷类别
  213.      //---------------
  214.      dm.sz_xtajlb.close;
  215.      dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
  216.      dm.sz_xtajlb.Open;//系统案卷类别
  217.      //刷新两个表
  218.      dm.xt_lbjs.Close;
  219.      dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_qz'+''''+'';
  220.      dm.xt_lbjs.Open;//类别级数
  221.      lbjs_sm1:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
  222.      //调出主表的编码规则
  223.      dm.xt_lbjs.Close;
  224.      dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
  225.      dm.xt_lbjs.Open;
  226.      lbjs_sm2:=dm.xt_lbjs.fieldbyname('lbjs_sm').asstring;
  227.      //调出二级表的编码规则
  228.      if dm.sz_qz.RecordCount<>0 then
  229.       begin
  230.         loadtree1(dm.sz_qz,dm.sz_ajlb);
  231.         dm.sz_qz.Close;
  232.         dm.sz_qz.CommandText:='select * from sz_qz';
  233.         dm.sz_qz.Open;
  234.         dm.sz_ajlb.Close;
  235.         dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  236.         dm.sz_ajlb.Open;
  237.         //装载树------------------
  238.       end;
  239. end;
  240. //******************************************************************************
  241. procedure TAm_ylj.EditExecute(Sender: TObject);
  242. var s:string;
  243. begin
  244.   s:=dm.V_ylj.fieldbyname('aj_xh').AsString;
  245.   if am_ylj_bj=Nil then
  246.   begin
  247.      dm.Am_ajgl.Close;
  248.      dm.am_ajgl.CommandText:='select * from am_ajgl where aj_xh='+''''+s+''''+'';
  249.      dm.Am_ajgl.Open;
  250.      am_ylj_bj:=Tam_ylj_bj.Create(self);
  251.      am_ylj_bj.ShowModal;
  252.      dm.Am_ajgl.Edit;
  253.   end;
  254. end;
  255. //******************************************************************************
  256. procedure TAm_ylj.TreeClick(Sender: TObject);
  257. var
  258.    i,Epos:integer;
  259.    Level:integer;
  260. begin
  261.  Level:=tree.Selected.Level;
  262.  if tree.selected=nil then
  263.      exit
  264.   else
  265.  if Tree.Items[0].HasChildren<>false then
  266.  begin   //选中和不选中的图片显示
  267.     for i:=0 to Tree.items.count-1 do
  268.     begin
  269.       if tree.Selected.HasChildren then
  270.          exit
  271.       else
  272.         if Level=1 then
  273.             add1.Enabled:=false
  274.         else
  275.          begin
  276.            Tree.Items[i].ImageIndex:=0;
  277.            Tree.Items[i].SelectedIndex:=1;
  278.            tree.Items[i].EndEdit(true) ;
  279.            ylj_s1:=Tree.Selected.Text;
  280.            Epos:=pos('-',ylj_s1);
  281.            ylj_s2:=copy(ylj_s1,0,Epos-1);//案卷类别代码
  282.            dm.V_ylj.Close;
  283.            dm.V_ylj.CommandText:='select * from V_ylj where ajlb_dm='+''''+ylj_s2+''''+'';
  284.            dm.V_ylj.Open;//查询有问题
  285.            dm.Am_wjgl.Close;
  286.            dm.Am_wjgl.CommandText:='select * from am_wjgl';
  287.            dm.Am_wjgl.Open;//文件管理
  288.            dm.V_Wjgl.Close;
  289.            dm.V_Wjgl.CommandText:='select * from v_wjgl';
  290.            dm.V_Wjgl.Open;//文件视图
  291.            dm.V_wjgl.MasterSource:=V_ylj;
  292.            dm.V_wjgl.MasterFields:='aj_xh';//说明当前ylj表中无值
  293.            s_ajxh:=dm.v_ylj.fieldbyname('aj_xh').AsString;
  294.            if dm.V_ylj.RecordCount<>0 then
  295.             begin
  296.               add1.Enabled:=true;
  297.               xiugai.Enabled:=true;
  298.               dele1.Enabled:=true;
  299.               wjcz.Enabled:=true;
  300.               ylj1.Enabled:=true;
  301.             end//设置按钮的状态
  302.             else
  303.             begin
  304.               add1.Enabled:=true;
  305.               xiugai.Enabled:=false;
  306.               dele1.Enabled:=false;
  307.               wjcz.Enabled:=false;
  308.               ylj1.Enabled:=false;
  309.             end;//数据表中无值
  310.          end;
  311.     end;//end for
  312.  end;
  313. end;
  314. //******************************************************************************
  315. procedure TAm_ylj.RefreshExecute(Sender: TObject);
  316. begin
  317.   dm.V_ylj.Close;
  318.   dm.V_ylj.CommandText:='select * from V_ylj where ajlb_dm='+''''+ylj_s2+''''+'';
  319.   dm.V_ylj.Open;//刷新视图
  320.   dm.V_Wjgl.Close;
  321.   dm.V_Wjgl.Close;
  322.   dm.V_Wjgl.CommandText:='select * from v_wjgl';
  323.   dm.V_Wjgl.Open;//文件视图
  324.   dm.V_wjgl.MasterSource:=V_ylj;
  325.   dm.V_wjgl.MasterFields:='aj_xh';//说明当前ylj表中无值
  326. end;
  327. //******************************************************************************
  328. procedure TAm_ylj.DeleteExecute(Sender: TObject);
  329. var
  330.    s:string;
  331. begin
  332.    s:=dm.V_ylj.fieldbyname('aj_xh').AsString;
  333.    if application.MessageBox('您确定要删除吗?','警告',mb_okcancel+mb_iconquestion)=idok then
  334.    begin
  335.      dm.Am_ajgl.Close;
  336.      dm.Am_ajgl.CommandText:='delete from am_ajgl where aj_xh='+''''+s+''''+'';
  337.      dm.Am_ajgl.Execute;
  338.      dm.Am_ajgl.Close;
  339.      dm.Am_ajgl.CommandText:='select * from am_ajgl';
  340.      dm.Am_ajgl.Open;
  341.      dm.V_ylj.Close;
  342.      dm.V_ylj.CommandText:='select * from V_ylj where ajlb_dm='+''''+ylj_s2+''''+'';
  343.      dm.V_ylj.Open;//刷新视图
  344.      If dm.v_ylj.RecordCount=0 then
  345.       begin
  346.         xiugai.Enabled:=false;
  347.         dele1.Enabled:=false;
  348.         Ylj1.Enabled:=false;
  349.         Wjcz.Enabled:=false;
  350.       end
  351.    end else
  352.      exit;
  353. end;
  354. procedure TAm_ylj.N7Click(Sender: TObject);
  355. begin
  356.    if am_ylj_bj=nil then
  357.    begin
  358.      Am_wjgl_bj:=TAm_wjgl_bj.create(application);
  359.      dm.Am_wjgl.Close;
  360.      dm.am_wjgl.CommandText:='select * from am_wjgl where wj_dm='+''''+''''+'';
  361.      dm.Am_wjgl.Open;
  362.      dm.Am_wjgl.Edit;
  363.      Am_wjgl_bj.showmodal;
  364.    end;
  365. end;
  366. procedure TAm_ylj.N8Click(Sender: TObject);
  367. var s:string;
  368. begin
  369.   s:=dm.V_Wjgl.fieldbyname('wj_xh').AsString;
  370.   if am_ylj_bj=Nil then
  371.   begin
  372.      dm.Am_wjgl.Close;
  373.      dm.am_wjgl.CommandText:='select * from am_wjgl where wj_xh='+''''+s+''''+'';
  374.      dm.Am_wjgl.Open;
  375.      am_wjgl_bj:=Tam_wjgl_bj.Create(self);
  376.      am_wjgl_bj.ShowModal;
  377.      dm.Am_wjgl.Edit;
  378.   end;
  379. end;
  380. procedure TAm_ylj.DBGridEh1DblClick(Sender: TObject);
  381. begin
  382.  edit.Execute;//修改
  383. end;
  384. procedure TAm_ylj.N9Click(Sender: TObject);
  385. var
  386.    s:string;
  387. begin
  388.    s:=dm.V_Wjgl.fieldbyname('wj_xh').AsString;
  389.    if application.MessageBox('您确定要删除吗?','警告',mb_okcancel+mb_iconquestion)=idok then
  390.    begin
  391.      dm.Am_wjgl.Close;
  392.      dm.Am_wjgl.CommandText:='delete from am_wjgl where wj_xh='+''''+s+''''+'';
  393.      dm.Am_wjgl.Execute;
  394.      dm.Am_wjgl.Close;
  395.      dm.am_wjgl.CommandText:='select * from am_wjgl';
  396.      dm.Am_wjgl.Open;
  397.      dm.V_Wjgl.Close;
  398.      dm.V_Wjgl.CommandText:='select * from v_Wjgl';
  399.      dm.V_Wjgl.Open;
  400.    end else
  401.      exit;  
  402. end;
  403. procedure TAm_ylj.FormShow(Sender: TObject);
  404. begin
  405.   frm_name:='am_ylj';
  406. end;
  407. procedure TAm_ylj.DBGridEh2DblClick(Sender: TObject);
  408. begin
  409.   n8.Click;
  410. end;
  411. procedure TAm_ylj.YLJ1Click(Sender: TObject);
  412. var s:string;
  413. begin
  414.   s:=dbgrideh1.Fields[0].Text;
  415.   dm.V_ylj.Close;
  416.   dm.V_ylj.CommandText:='update v_ylj set ajzt_mc=''案卷'',aj_bzqsrq=getdate(),aj_gdqsrq=getdate() where aj_xh='+''''+s+''''+'';
  417.   dm.V_ylj.Execute;
  418.   dm.V_ylj.Close;
  419.   dm.V_ylj.CommandText:='select * from v_ylj where ajlb_dm='+''''+ylj_s2+''''+'';
  420.   dm.v_ylj.Open;
  421.   If dm.v_ylj.RecordCount=0 then
  422.    begin
  423.     xiugai.Enabled:=false;
  424.     dele1.Enabled:=false;
  425.     Ylj1.Enabled:=false;
  426.     Wjcz.Enabled:=false;
  427.    end;
  428.   //预立卷归卷
  429.   dm.V_Wjgl.Close;
  430.   dm.V_Wjgl.CommandText:='update V_Wjgl set wj_rq=getdate(),wj_gdrq=getdate() where aj_xh='+''''+s+''''+'';
  431.   dm.V_Wjgl.Execute;
  432.   dm.V_Wjgl.Close;
  433.   dm.V_Wjgl.CommandText:='select * from V_Wjgl where aj_xh='+''''+s+''''+'';
  434.   dm.V_Wjgl.Open;//文件管理
  435. end;
  436. procedure TAm_ylj.N5Click(Sender: TObject);
  437. begin
  438.   tree.Selected.Expand(true);
  439. end;
  440. procedure TAm_ylj.N6Click(Sender: TObject);
  441. begin
  442.   tree.Selected.Collapse(true);
  443. end;
  444. procedure TAm_ylj.TreeChange(Sender: TObject; Node: TTreeNode);
  445. var i:integer;
  446. begin
  447.  for i:=0 to Tree.items.count-1 do
  448.   begin
  449.    if tree.Selected.HasChildren then
  450.     begin
  451.         add1.Enabled:=false;
  452.         xiugai.Enabled:=false;
  453.         dele1.Enabled:=false;
  454.         wjcz.Enabled:=false;
  455.         ylj1.Enabled:=false;
  456.     end
  457.    else if tree.Items[1].Selected then
  458.     begin
  459.         add1.Enabled:=false;
  460.         xiugai.Enabled:=false;
  461.         dele1.Enabled:=false;
  462.         wjcz.Enabled:=false;
  463.         ylj1.Enabled:=false;
  464.     end;
  465.  end;//end for}
  466. end;
  467. end.