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

Delphi控件源码

开发平台:

Delphi

  1. unit Am_gdajs;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, XPBarMenu, DB, Menus, ActnList, Grids, DBGridEh, StdCtrls,
  6.   ComCtrls, ExtCtrls, ToolWin, DBClient, ImgList;
  7. type
  8.   TAm_gdaj = class(TForm)
  9.     CoolBar1: TCoolBar;
  10.     ToolBar1: TToolBar;
  11.     AJCD: TToolButton;
  12.     AJRK: TToolButton;
  13.     AJCK: TToolButton;
  14.     REFRESH1: TToolButton;
  15.     ToolButton3: TToolButton;
  16.     Panel1: TPanel;
  17.     Splitter1: TSplitter;
  18.     Panel2: TPanel;
  19.     Tree: TTreeView;
  20.     Panel3: TPanel;
  21.     Panel4: TPanel;
  22.     GroupBox1: TGroupBox;
  23.     Ds_Ajgl: TDataSource;
  24.     DBGridEh1: TDBGridEh;
  25.     ImageList1: TImageList;
  26.     PopupMenu1: TPopupMenu;
  27.     N_ajcd: TMenuItem;
  28.     N_AJRk: TMenuItem;
  29.     N_ajCk: TMenuItem;
  30.     AJTZH: TToolButton;
  31.     N4: TMenuItem;
  32.     N5: TMenuItem;
  33.     ToolButton1: TToolButton;
  34.     PopupMenu2: TPopupMenu;
  35.     N6: TMenuItem;
  36.     N7: TMenuItem;
  37.     XPBarMenu1: TXPBarMenu;
  38.     ToolButton2: TToolButton;
  39.     procedure QuitExecute(Sender: TObject);
  40.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  41.     procedure TreeClick(Sender: TObject);
  42.     procedure FormCreate(Sender: TObject);
  43.     procedure AJCDClick(Sender: TObject);
  44.     procedure AJCKClick(Sender: TObject);
  45.     procedure AJRKClick(Sender: TObject);
  46.     procedure DBGridEh1DblClick(Sender: TObject);
  47.     procedure AJTZHClick(Sender: TObject);
  48.     procedure DBGridEh1CellClick(Column: TColumnEh);
  49.     procedure N4Click(Sender: TObject);
  50.     procedure N5Click(Sender: TObject);
  51.     procedure N6Click(Sender: TObject);
  52.     procedure N7Click(Sender: TObject);
  53.     procedure N_ajcdClick(Sender: TObject);
  54.     procedure N_AJRkClick(Sender: TObject);
  55.     procedure N_ajCkClick(Sender: TObject);
  56.     procedure ToolButton2Click(Sender: TObject);
  57.     procedure REFRESH1Click(Sender: TObject);
  58.   private
  59.     { Private declarations }
  60.   public
  61.     { Public declarations }
  62.     procedure loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
  63.   end;
  64. var
  65.   Am_gdaj: TAm_gdaj;
  66.   gnode:TtreeNode;//当前节点
  67.   lbjs_sm1,lbjs_sm2:string;//类别级数
  68.   lb_dmgz1,lb_dmgz2:string;//代码规则
  69.   dsState:string;//增删改的状态
  70.   s,gdaj_s1,gdaj_s2:string;//s1,s2分别是树节点:文本,代码
  71. implementation
  72. uses DMs, ajgls,u_public, ajgl_bjs, am_ajbj_rks, am_ajyjs,mainfrms,
  73.   am_yjdys, Am_Gdaj_ps, Am_Ajtzs;
  74. {$R *.dfm}
  75. procedure TAm_gdaj.loadTree1(treeDb1,treeDb2:TClientDataSet);//初始化树
  76. var
  77.   nodeId1,nodeTxt1,nodeId2,nodeTxt2:string;
  78.   SCodeFormat1,SCodeFormat2,SFirstNodeTxt:string;
  79.   level1,level2:integer;
  80.   mynode:array[0..6] of Ttreenode;
  81.   i,j:integer;//循环标志
  82. begin
  83.    //初始化变量
  84.    SCodeFormat1:=lbjs_sm1 ;//系统案卷类别代码结构
  85.    SCodeFormat2:=lbjs_sm2;//文件类别代码结构
  86.    SFirstNodeTxt:= '案卷类别';//首节点显示的文字
  87.    Screen.Cursor:=crHourGlass;
  88.    Tree.enabled:=true;
  89.    Tree.Items.Clear;
  90.    level1:=0;
  91.    //设置根节点
  92.  mynode[level1]:=Tree.Items.Add(Tree.TopItem,SFirstNodeTxt);
  93.  mynode[level1].ImageIndex:=0;
  94.  mynode[level1].SelectedIndex:=1;
  95.  //遍历数据表,利用编码字段记录排序规律,依次添加树节点
  96.   for i:=0 to treedb1.RecordCount-1 do
  97.   begin
  98.     nodeId1:=trim(treedb1.fieldbyname('qz_dm').AsString);
  99.     nodeTxt1:=nodeId1+'-'+trim(treedb1.fieldbyname('qz_mc').AsString);
  100.     level1:=GetNodeLevel(SCodeFormat1,nodeId1);//获得节点层树
  101.     if level1>0 then
  102.      begin
  103.        mynode[level1]:=tree.Items.AddChild(mynode[level1-1],nodeTxt1);
  104.        mynode[level1].ImageIndex:=0;
  105.        mynode[level1].SelectedIndex:=1;
  106.       //----------
  107.      end;
  108.   //增加第一层主表
  109.      treedb2.close;
  110.      treedb2.commandtext:='select * from sz_ajlb where qz_dm='+''''+nodeId1+''''+'';
  111.      treedb2.open;
  112.      if trim(treedb2.FieldByName('qz_dm').AsString)<>'' then
  113.       begin
  114.        for j:=0 to treedb2.recordcount-1 do
  115.        begin
  116.            nodeId2:=trim(treedb2.fieldbyname('ajlb_dm').asstring);
  117.            nodeTxt2:=NodeId2+'-'+trim(treedb2.fieldbyname('ajlb_mc').asstring);
  118.            level2:=getNodeLevel(SCodeFormat2,nodeId2);//从表的层数
  119.           if level2>1 then
  120.            begin
  121.              mynode[level2]:=tree.Items.AddChild(mynode[level2-1],nodeTxt2);
  122.              mynode[level2].ImageIndex:=0;
  123.              mynode[level2].SelectedIndex:=1;
  124.            end;
  125.          treedb2.Next;
  126.        end;
  127.        end
  128.        else
  129.           treedb2.Next;//不是符合条件的纪录
  130.     treedb1.Next;//下一条纪录
  131.   end;//end for
  132.   mynode[0].Expand(false);
  133.   screen.Cursor:=crdefault;
  134. end;
  135. //**************************************************************
  136. procedure TAm_gdaj.QuitExecute(Sender: TObject);
  137. begin
  138.   close;
  139. end;
  140. procedure TAm_gdaj.FormClose(Sender: TObject; var Action: TCloseAction);
  141. begin
  142.   dm.V_ajgd.Active:=false;//归档视图
  143.   dm.Am_ajgl.Active:=true;//案卷管理
  144.   dm.sz_bgqx.Active:=true;//保管期限
  145.   dm.sz_mj.active:=true;//密级
  146.   //--------------------
  147.   dm.sz_qz.Active:=false;//全宗
  148.   dm.sz_ajlb.Active:=false;//案卷类别
  149.   //---------------
  150.   dm.sz_xtajlb.Active:=false;//系统案卷类别
  151.   //---------------
  152.   dm.xt_lbjs.Active:=false;//类别级数
  153.   dm.Am_wjgl.active:=false;//文件管理
  154.   dm.V_Wjgl.Active:=false;//文件视图
  155.   dm.sz_ztlb.Active:=false;//载体类别
  156.   dm.sz_wjlb.active:=false;//文件类别
  157.   dm.sz_bm.Active:=false;//部门
  158.   dm.v_ajgd.active:=false;
  159.   action:=cafree;
  160.   am_gdaj:=nil;
  161. end;
  162. procedure TAm_gdaj.TreeClick(Sender: TObject);
  163. var
  164.    i,Epos:integer;
  165. begin
  166.   if tree.selected=nil then
  167.      exit
  168.   else
  169.  if Tree.Items[0].HasChildren<>false then
  170.  begin   //选中和不选中的图片显示
  171.     for i:=0 to Tree.items.count-1 do
  172.     begin
  173.       if tree.Selected.HasChildren then
  174.          exit
  175.       else
  176.          begin
  177.            Tree.Items[i].ImageIndex:=0;
  178.            Tree.Items[i].SelectedIndex:=1;
  179.            gdaj_s1:=Tree.Selected.Text;
  180.            Epos:=pos('-',gdaj_s1);
  181.            gdaj_s2:=copy(gdaj_s1,0,Epos-1);//为选中树节点的代码
  182.            dm.V_ajgd.Close;
  183.            dm.V_ajgd.CommandText:='select * from v_ajgd where ajlb_dm = '+''''+gdaj_s2+''''+'';
  184.            dm.V_ajgd.Open;//查找当前代码
  185.           if dm.V_AJGD.Active then showmessage('true');           
  186.            if dm.V_ajgd.RecordCount<>0 then
  187.             begin
  188.               if dbgrideh1.Columns[0].DisplayText='入库案卷' then
  189.                 begin
  190.                   AJCK.Enabled:=true;N_AJCK.Enabled:=true;
  191.                   ajrk.Enabled:=false;N_ajrk.Enabled:=false;
  192.                   ajcd.Enabled:=false;N_ajcd.Enabled:=false;
  193.                   ajtzh.Enabled:=false;
  194.                   N6.Enabled:=true;
  195.                 end
  196.                 else
  197.                 If dbgrideh1.Columns[0].DisplayText='归档案卷' then
  198.                  begin
  199.                    ajck.Enabled:=false;N_ajck.Enabled:=false;
  200.                    ajrk.Enabled:=true;N_ajrk.Enabled:=true;
  201.                    ajcd.Enabled:=true;N_ajcd.Enabled:=true;
  202.                    ajtzh.Enabled:=true;
  203.                    N6.Enabled:=true;
  204.                  end;//根据表格判断不用刷新数据库
  205.             end//设置按钮的状态
  206.            else
  207.             begin
  208.                AJCK.Enabled:=false;N_ajck.Enabled:=false;
  209.                ajrk.Enabled:=false;N_ajrk.Enabled:=false;
  210.                ajcd.Enabled:=false;N_ajcd.Enabled:=false;
  211.                ajtzh.Enabled:=false;
  212.                N6.Enabled:=false;
  213.             end;
  214.          end;
  215.     end;
  216.  end;
  217. end;
  218. procedure TAm_gdaj.FormCreate(Sender: TObject);
  219. begin
  220.    dm.Am_ajgl.Active:=true;//案卷管理
  221.    dm.sz_bgqx.Active:=true;//保管期限
  222.    dm.sz_mj.active:=true;//密级
  223.    dm.sz_ztlb.Active:=true;//载体类别
  224.    dm.sz_bm.Active:=true;//部门
  225.    dm.sz_kw.Active:=true;//库位
  226.    //-------
  227.    dm.sz_qz.Close;
  228.    dm.sz_qz.CommandText:='select * from sz_qz';
  229.    dm.sz_qz.Open;//全宗
  230.    dm.sz_ajlb.Close;
  231.    dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  232.    dm.sz_ajlb.Open;//案卷类别
  233.    //---------------
  234.    dm.sz_xtajlb.close;
  235.    dm.sz_xtajlb.CommandText:='select * from sz_xtajlb';
  236.    dm.sz_xtajlb.Open;//系统案卷类别
  237.    //刷新两个表
  238.    dm.xt_lbjs.Close;
  239.    dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_qz'+''''+'';
  240.    dm.xt_lbjs.Open;//类别级数
  241.    lbjs_sm1:=dm.xt_lbjs.fieldbyname('lbjs_sm').AsString;
  242.    //调出主表的编码规则
  243.    dm.xt_lbjs.Close;
  244.    dm.xt_lbjs.CommandText:='select * from xt_lbjs where lb_dm='+''''+'sz_ajlb'+''''+'';
  245.    dm.xt_lbjs.Open;
  246.    lbjs_sm2:=dm.xt_lbjs.fieldbyname('lbjs_sm').asstring;
  247.    //调出二级表的编码规则
  248.    loadtree1(dm.sz_qz,dm.sz_ajlb);
  249.    dm.sz_qz.Close;
  250.    dm.sz_qz.CommandText:='select * from sz_qz';
  251.    dm.sz_qz.Open;
  252.    dm.sz_ajlb.Close;
  253.    dm.sz_ajlb.CommandText:='select * from sz_ajlb';
  254.    dm.sz_ajlb.Open;
  255.    //装载树-------------------------------------------
  256.    frm_name:='Am_Gdaj';
  257.    dm.am_yjml.active:=true;//移交目录
  258.    dm.Am_Ajyj.Active:=true;//案卷移交
  259. end;
  260. procedure TAm_gdaj.AJCDClick(Sender: TObject);
  261. var s2:string;
  262. begin
  263.   if DBGrideh1.Columns[0].DisplayText='入库案卷' then
  264.     begin
  265.      AJCD.Enabled:=false;
  266.      exit;
  267.     end;
  268.    s:=dm.v_ajgd.fieldbyname('aj_xh').AsString;
  269.    s2:=DM.v_ajgd.fieldbyname('ajlb_dm').AsString;
  270.    dm.V_ajgd.Close;
  271.    dm.V_ajgd.CommandText:='update v_ajgd set ajzt_mc=''案卷'' ,aj_gdjsrq=Null where aj_xh='+''''+s+''''+'';
  272.    dm.V_ajgd.Execute;//对归档案卷进行管理
  273.    dm.V_AJGD.Close;
  274.    dm.v_ajgd.CommandText:='select * from v_Ajgd where ajlb_dm='+''''+s2+''''+'';
  275.    dm.v_ajgd.Open;//案卷归档管理
  276. end;
  277. procedure TAm_gdaj.AJCKClick(Sender: TObject);
  278. var s:string;
  279. begin
  280.   if DBGrideh1.Columns[0].DisplayText='归档案卷' then
  281.     begin
  282.      AJCK.Enabled:=false;
  283.      exit;
  284.     end;
  285.   s:=dm.v_ajgd.fieldbyname('aj_xh').AsString;
  286.   dm.V_ajgd.Close;
  287.   dm.V_ajgd.CommandText:='update v_ajgd set ajzt_mc=''归档案卷'',aj_bzjsrq=null,kw_dm=Null where aj_xh='+''''+s+''''+'';
  288.   dm.V_ajgd.Execute;
  289.   dm.V_AJGD.Close;
  290.   dm.v_ajgd.CommandText:='select * from v_Ajgd where ajlb_dm='+''''+gdaj_s2+''''+'';
  291.   dm.v_ajgd.Open;//案卷归档管理
  292. end;
  293. procedure TAm_gdaj.AJRKClick(Sender: TObject);
  294. var zcg_s:string;
  295. begin
  296.  if DBGrideh1.Columns[0].DisplayText='入库案卷' then
  297.     begin
  298.      AJRK.Enabled:=false;
  299.      exit;
  300.     end;
  301.  zcg_s:=dm.v_ajgd.fieldbyname('aj_xh').AsString;
  302.  dm.Am_ajgl.Close;
  303.  dm.am_ajgl.CommandText:='select * from am_ajgl where aj_xh='+''''+zcg_s+''''+'';
  304.  dm.Am_ajgl.Open;
  305.   if am_ajgl_rk=Nil then
  306.   begin
  307.      am_ajgl_rk:=Tam_ajgl_rk.create(self);
  308.      am_ajgl_rk.showmodal;
  309.   end;
  310. end;
  311. procedure TAm_gdaj.DBGridEh1DblClick(Sender: TObject);
  312. var zcg_s:string;
  313. begin
  314.  zcg_s:=dm.v_ajgd.fieldbyname('aj_xh').AsString;
  315.  dm.Am_ajgl.Close;
  316.  dm.am_ajgl.CommandText:='select * from am_ajgl where aj_xh='+''''+zcg_s+''''+'';
  317.  dm.Am_ajgl.Open;
  318.  if am_ajgl_rk=Nil then
  319.   begin
  320.      am_ajgl_rk:=Tam_ajgl_rk.create(self);
  321.      am_ajgl_rk.DBLookupComboboxEh4.Enabled:=false;
  322.      am_ajgl_rk.DBLookupComboboxEh4.Color:=cl3dLight;
  323.      am_ajgl_rk.Save.Visible:=false;
  324.      am_ajgl_rk.Caption:='案卷浏览';
  325.      am_ajgl_rk.showmodal;
  326.   end;
  327. end;
  328. procedure TAm_gdaj.AJTZHClick(Sender: TObject);
  329. var
  330.   s_xh:string;//序号
  331.   s_dm:string;//代码
  332. begin
  333.  s_xh:=dm.v_ajgd.fieldbyname('aj_xh').AsString;
  334.  s_dm:=dm.v_ajgd.fieldbyname('aj_dm').AsString;
  335.  dm.Am_ajgl.Close;
  336.  dm.am_ajgl.CommandText:='select * from am_ajgl where aj_xh='+''''+s_xh+''''+'';
  337.  dm.Am_ajgl.Open;
  338.  if am_ajtz=Nil then
  339.   begin
  340.      am_ajtz:=Tam_ajtz.create(self);
  341.      am_ajtz.DBLookupComboboxEh4.Enabled:=false;
  342.      am_ajtz.DBLookupComboboxEh4.Color:=cl3dLight;
  343.      am_ajtz.DBLookupComboboxEh1.Enabled:=true;
  344.      am_ajtz.DBLookupComboboxEh1.Color:=clWindow;
  345.      am_ajtz.showmodal;
  346.   end;
  347. end;
  348. procedure TAm_gdaj.DBGridEh1CellClick(Column: TColumnEh);
  349. begin
  350.  if dbgrideh1.Columns[0].DisplayText='入库案卷' then
  351.   begin
  352.     AJCK.Enabled:=true;
  353.     ajrk.Enabled:=false;
  354.     ajcd.Enabled:=false;
  355.   end
  356.   else
  357.   If dbgrideh1.Columns[0].DisplayText='归档案卷' then
  358.    begin
  359.      ajck.Enabled:=false;
  360.      ajrk.Enabled:=true;
  361.      ajcd.Enabled:=true;
  362.    end;//根据表格判断不用刷新数据库
  363. end;
  364. procedure TAm_gdaj.N4Click(Sender: TObject);
  365. begin
  366.  tree.Selected.Expand(true);
  367. end;
  368. procedure TAm_gdaj.N5Click(Sender: TObject);
  369. begin
  370.   tree.Selected.Collapse(true);
  371. end;
  372. procedure TAm_gdaj.N6Click(Sender: TObject);
  373. var zcg_s:string;
  374.     r:Trect;
  375. begin
  376.  inherited;
  377.  r:=mainfrm.MdiRect;
  378.  zcg_s:=dm.V_ajgd.fieldbyname('aj_xh').AsString;
  379.  dm.Am_ajgl.Close;
  380.  dm.Am_ajgl.CommandText:='select * from Am_ajgl where aj_xh='+''''+zcg_s+''''+'';
  381.  dm.Am_ajgl.Open;
  382.   if am_ajyj=Nil then
  383.   begin
  384.      am_ajyj:=Tam_ajyj.create(self);
  385.      dm.Am_Ajyj.Append;
  386.      am_ajyj.show;
  387.      am_ajyj.DBEdit8.SetFocus;
  388.      am_ajyj.BoundsRect:=rect(r.left+90,r.top,r.right-r.Left-90,r.bottom-r.Top);
  389.   end;//案卷移交
  390. end; 
  391. procedure TAm_gdaj.N7Click(Sender: TObject);
  392. var r:Trect;
  393. begin
  394.  inherited;
  395.  r:=mainfrm.mdirect;
  396.  if am_yjdy=nil then
  397.  begin
  398.     am_yjdy:=Tam_yjdy.create(self);
  399.     am_yjdy.show;
  400.     am_yjdy.BoundsRect:=rect(r.Left,r.Top,r.Right-r.Left,r.Bottom-r.Top);
  401.  end;
  402. end;
  403. procedure TAm_gdaj.N_ajcdClick(Sender: TObject);
  404. begin
  405.  Ajcd.Click;
  406. end;
  407. procedure TAm_gdaj.N_AJRkClick(Sender: TObject);
  408. begin
  409.  ajrk.Click;
  410. end;
  411. procedure TAm_gdaj.N_ajCkClick(Sender: TObject);
  412. begin
  413.  Ajck.Click;
  414. end;
  415. procedure TAm_gdaj.ToolButton2Click(Sender: TObject);
  416. begin
  417.  am_gdaj_P:=Tam_gdaj_P.create(application);
  418.  am_gdaj_P.quickrep1.preview;
  419. end;
  420. procedure TAm_gdaj.REFRESH1Click(Sender: TObject);
  421. begin
  422.  dm.V_AJGD.close;
  423.  dm.V_AJGD.CommandText:='select * from v_gdaj where aj_dm='+''''+gdaj_s2+''''+'';
  424.  dm.v_ajgd.Open;
  425. end;
  426. end.