⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 从文档管理升华到知识管理文档是知识的容器
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    rootNode.SelectedIndex:=0;       //创建根内容
    parent:=ADOQuery1.Fields[0].AsString;
    with adoquery2 do
    begin
     close;
     sql.Clear;
     sql.Add('select id,name  from table2 where parentid=:parent');
     Parameters.ParamByName('parent').Value:=parent;
    // showmessage(sql.Text);
     open;
     First;
     while not eof do
     begin
      Nodel:=TreeView1.Items.AddChild(rootnode,Fields[1].asstring);
      nodel.SelectedIndex:=0;
      nodel.ImageIndex:=0;
      next;
     end;
    end;
    ADOQuery1.Next;
  end;   }

end;

procedure TWdForm.N3Click(Sender: TObject);
var ss:string;
begin
 nodel:=TreeView1.Selected;
 IF nodel=nil then exit;
  if MessageDlg('将要删除当前记录及下级所有记录,请确认!',mtWarning,[mbyes,mbno],0)=mryes then
  begin
   yn:=false;
   ADOQuery2.Close;
   adoquery2.SQL.Clear;
   adoquery2.SQL.add('select id from table2 where xh=:xh') ;
   idh:=integer(pmydata(nodel.data^));
   ADOQuery2.Parameters.ParamByName('xh').Value:=inttostr(idh);
   ADOQuery2.open;
   ss:=adoquery2.Fields[0].AsString;
   adoquery2.Close;
   adoquery2.Close;
   adoquery2.SQL.Clear;
   adoquery2.SQL.add('delete from table2 where id like'+''''+ss+'%'+'''') ;
   try
     begin
      ADOConnection1.BeginTrans;
      adoquery2.ExecSQL;
      ADOConnection1.CommitTrans;
    end;
    except
    begin
     ADOConnection1.RollbackTrans;
     MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
     exit;
    end;
    end;
   TreeView1.Selected.Delete;
   yn:=true;

  end;
end;

procedure TWdForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 ADOConnection1.Connected:=False;
 //OleContainer1.Close;
 OleContainer1.Free;
end;

procedure TWdForm.N1Click(Sender: TObject);
 var shuju:PMyData;
     i,j:integer;
     ss,st:string;
begin
 yn:=false;
 if treeview1.Items.Count=0 then
   begin
    with ADOQuery1 do//录入第一条记录
    begin
      close;
      sql.Clear;
      sql.Add('insert into table2(id,name) values('+''''+'0000'+''''+','+''''
      +'我的文档记录'+''''+')');
     try
     begin
      ADOConnection1.BeginTrans;
      ExecSQL;
      ADOConnection1.CommitTrans;
    end;
    except
    begin
     ADOConnection1.RollbackTrans;
     MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
     exit;
    end;
    end;
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select xh from table2 where id='+''''+'0000'+'''');
      open;
      new(shuju);
      shuju^.nIndex:=Fields[0].AsInteger;
    end;
    Rootnode:=treeview1.Items.Add(nil,'我的文档记录');
    TreeView1.Selected:=rootNode;   //把shuju指针赋值给当前结点data
    rootNode.data:=shuju;
   end;
   end
  else
   begin
     if treeview1.Selected=nil then exit;
      with ADOQuery1 do
      begin
        close;
        sql.Clear;
        sql.Add('select parentid from table2 where xh=:xh');
        idh:=integer(pmydata(treeview1.Selected.data^));
        Parameters.ParamByName('xh').Value:=inttostr(idh);
        open;           //得到当前结点的父结点
        ss:=Fields[0].AsString;
        if ss<>'' then       //有父结点
        begin
          close;
          sql.Clear;
          sql.Add('select id from table2 where parentId='+''''+ss+''''+' order by id');
          open;
          Last;   //得到同级结点的最大id号
          i:=strToInt(Fields[0].AsString);
          j:=length(Fields[0].AsString);
          i:=i+1;
          st:=stringofchar('0',j-length(IntToStr(i)))+IntToStr(i); //重到录入数据的id号
          close;
          sql.Clear;
          sql.Add('insert into table2(id,name,parentID) values('+''''+st+''''+','+''''
          +'新的文档'+''''+','+''''+ss+''''+')');
          try
          begin
            ADOConnection1.BeginTrans;
            ExecSQL;
            ADOConnection1.CommitTrans;
          end;
          except
          begin
           ADOConnection1.RollbackTrans;
           MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
           exit;
          end;
         end;
        end
        else
        begin    //没有父结点的
        with ADOQuery1 do
        begin
          Close;
          sql.Clear;
          sql.Add('select id from table2 where len(id)=4 order by id');
          open;
          Last;
          i:=strToInt(Fields[0].AsString);
          i:=i+1;
          //st:=Fields[0].AsString;
          st:=stringofchar('0',4-length(IntToStr(i)))+IntToStr(i);
          close;
          sql.Clear;
          sql.Add('insert into table2(id,name) values('+''''+st+''''+','+''''
          +'新的文档'+''''+')');
          try
             begin
              ADOConnection1.BeginTrans;
              ExecSQL;
              ADOConnection1.CommitTrans;
            end;
            except
            begin
             ADOConnection1.RollbackTrans;
             MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
             exit;
            end;
            end;
        end;
   end;
 end;
     with ADOQuery1 do
     begin
        close;
        SQL.Clear;
        SQL.Add('select xh from table2 where id='+''''+st+'''');
        open;
        new(shuju);     //把录入数据的序号赋值给对就的treeview结点的data
        shuju^.nIndex:=Fields[0].AsInteger;
       nodel:=TreeView1.Items.Add(TreeView1.Selected,'新的文档');
       Treeview1.Selected:=nodel;
       nodel.Data:=shuju;
       yn:=true;
       //Nodel.EditText;}
     end;
  end;
end;

procedure TWdForm.N7Click(Sender: TObject);
begin
 TreeView1.Selected.EditText;
end;

procedure TWdForm.N12Click(Sender: TObject);
begin
 Application.CreateForm(TaboutBox,aboutBox);
 try
   AboutBox.ShowModal;
 finally
   AboutBox.Free;
 end;


end;

procedure TWdForm.N9Click(Sender: TObject);
begin
 TreeView1.FullExpand;
end;

procedure TWdForm.N10Click(Sender: TObject);
begin
 TreeView1.FullCollapse;
end;

procedure TWdForm.TreeView1Change(Sender: TObject; Node: TTreeNode);

begin
  StatusBar1.SimpleText:='当前所在层次:'+intTostr(TreeView1.Selected.Level);
  if yn then
   begin
    ADOQuery2.Close;
    adoquery2.SQL.Clear;  //如果选择记录后,EDIT从数据库中得到值
    adoquery2.SQL.add('select path1 from  table2 where xh=:xh') ;
    idh:=integer(pmydata(node.data^));
    ADOQuery2.Parameters.ParamByName('xh').Value:=inttostr(idh);
    ADOQuery2.open;
    edit1.Text:=ADOQuery2.Fields[0].AsString;
    ADOQuery2.Close;
    //ADOQuery2.Free;
  end;
end;

procedure TWdForm.U1Click(Sender: TObject);
var
 tmpn:TTreeNode;
 i:integer;
 s1,s2:string;
begin               //记录上移
   Nodel:=TreeView1.Selected;
   tmpn:=TreeView1.Selected.getPrevSibling;
   if tmpn<>nil then
   begin
    with ADOQuery1 do
    begin
      ADOConnection1.BeginTrans;
      try
      begin
      close;
      sql.Clear;
      sql.Add('select id from table2 where xh=:xh');
      idh:=integer(pmydata(Nodel.Data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;            //把当前选择的记录ID赋值给S1
      s1:=Fields[0].AsString;
      i:=length(s1);
      close;
      sql.Clear; //把当前选择的记录ID赋值为haha
      sql.Add('update table2 set id='+''''+'haha'+''''+' where xh=:xh');
      Parameters.ParamByName('xh').Value:=idh;
      ExecSQL;
      close;//把当前选择的记录的下级记录ID及parentId进行修改HAHA
      sql.Clear;
      sql.Add('update table2 set parentid='+''''+'haha'+''''+'+right(parentid,len(Parentid)-'+intTostr(i)+
         '),id='+''''+'haha'+''''+'+right(id,len(id)-'+intTostr(i)+') where left(parentid,'+intTostr(i)+')='+''''+s1+'''');
      ExecSQL;
      close;
      sql.Clear;
      sql.Add('select id from table2 where xh=:xh');
      idh:=integer(pmydata(tmpn.Data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;            //把当前选择的记录的上一条记录ID赋值给S2
      s2:=Fields[0].AsString;
      close;
      sql.Clear; //把当前选择的上一条记录ID赋值为s1
      sql.Add('update table2 set id='+''''+s1+''''+' where xh=:xh');
      Parameters.ParamByName('xh').Value:=idh;
      ExecSQL;
      close;//把当前选择的上一条记录的下级记录ID及parentId进行修改
      sql.Clear;
      sql.Add('update table2 set parentid='+''''+s1+''''+'+right(parentid,len(Parentid)-'+intTostr(i)+
         '),id='+''''+s1+''''+'+right(id,len(id)-'+intTostr(i)+') where left(parentid,'+intTostr(i)+')='+''''+s2+'''');
      ExecSQL;
      close;
      sql.Clear; //把当前选择的记录ID赋值为s2
      sql.Add('update table2 set id='+''''+s2+''''+' where xh=:xh');
      idh:=integer(Pmydata(Nodel.Data^));
      Parameters.ParamByName('xh').Value:=idh;
      ExecSQL;
      close;//把当前选择的记录的下级记录ID及parentId进行修改
      sql.Clear;
      sql.Add('update table2 set parentid='+''''+s2+''''+'+right(parentid,len(Parentid)-'+intTostr(i)+
         '),id='+''''+s2+''''+'+right(id,len(id)-'+intTostr(i)+') where left(parentid,4)='+''''+'haha'+'''');
      ExecSQL;
      TreeView1.Selected.MoveTo(tmpn,nainsert);
      ADOConnection1.CommitTrans;
      end;
      except
      begin
       ADOConnection1.RollbackTrans;
       MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
       exit;
      end;
      end;
    end;
   end;
end;

procedure TWdForm.D2Click(Sender: TObject);
var
 tmpn,sepn:TTreeNode;
 s1,s2:string;
 i:integer;
begin                    //记录下移
   nodel:=treeview1.Selected;
   tmpn:=TreeView1.Selected.getNextSibling;
    with ADOQuery2 do
    begin
      close;
      sql.Clear;
      sql.Add('select id from table2 where xh=:xh');
      idh:=integer(pmydata(Nodel.Data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;            //把当前选择的记录ID赋值给S1
      s1:=Fields[0].AsString;
      i:=length(s1);
      try
      begin
      ADOConnection1.BeginTrans;
      close;
      sql.Clear; //把当前选择的记录ID赋值为haha
      sql.Add('update table2 set id='+''''+'haha'+''''+' where xh=:xh');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -