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

Delphi控件源码

开发平台:

Delphi

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