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

📄 main.pas

📁 从文档管理升华到知识管理文档是知识的容器
💻 PAS
📖 第 1 页 / 共 3 页
字号:
      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;
      ADOConnection1.CommitTrans;
      end;
      except
      begin
        ADOConnection1.RollbackTrans;
       MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
       exit;
      end; 
      end;
    end;
  if tmpn<>nil then
   begin
    sepn:=tmpn.getNextSibling;
    if sepn<>nil then    //把当前记录移到的下两条记录之间
    begin
      TreeView1.Selected.MoveTo(sepn,naInsert);
    end
    else
    begin             //当前记录只有下一条记录,用增加方式移到最后
      TreeView1.Selected.MoveTo(tmpn,naAdd);
    end;
  end;
end;

procedure TWdForm.I2Click(Sender: TObject);
var
 tmpn:TTreeNode;
 ss,st,sd,sm:string;  //SS为下一个记录号,ST为下级最后一个记录号,SD为当前记录号
 i:integer;             //sm为下级记录号
begin
   tmpn:=TreeView1.Selected.getNextSibling;  //得到上一个记录

   if tmpn<>nil then
   begin
    with ADOQuery1 do
    begin
    try
      begin
         ADOConnection1.BeginTrans;
         close;
         sql.Clear; //得到下一条记录号
         sql.Add('select id from table2 where xh=:xh');
         idh:=integer(pmydata(tmpn.data^));
         Parameters.ParamByName('xh').Value:=idh;
         open;
         ss:=Fields[0].AsString;
         close;
         sql.Clear; //得到当前记录的记录号
         sql.Add('select id from table2 where xh=:xh');
         idh:=integer(pmydata(TreeView1.Selected.Data^));
         Parameters.ParamByName('xh').Value:=idh;
         open;
         sm:=Fields[0].AsString;
         close;
         sql.Clear; //得到当前记录的应得记录号
         sql.Add('select id from table2 where parentid='+''''+ss+''''+' order by id');
         //idh:=integer(pmydata(tmpn.Data^));
         //Parameters.ParamByName('xh').Value:=idh;
         open;
         last;
         st:=Fields[0].AsString;
         if st='' then
         begin
           sd:=ss+'0001';
         end
         else
         begin
           sd:=getbh(st);
         end;
         i:=length(sm);
         close;
         sql.Clear;
         sql.Add('update table2 set parentid='+''''+sd+''''+'+right(parentid,len(Parentid)-'+intTostr(i)+
         '),id='+''''+sd+''''+'+right(id,len(id)-'+intTostr(i)+') where left(parentid,'+intTostr(i)+')='+''''+sm+'''');
        // showmessage(sql.text);
         ExecSQL;
         close;
         sql.Clear; //让当前记录的ParentId=下一条记录号
         sql.Add('update table2 set parentId='+''''+ss+''''+' where xh=:xh');
         idh:=integer(pmydata(TreeView1.Selected.Data^));
         Parameters.ParamByName('xh').Value:=idh;
         ExecSQL;
         close;
         sql.Clear; //修改当前记录的Id
         sql.Add('update table2 set Id='+''''+sd+''''+' where xh=:xh');
         idh:=integer(pmydata(TreeView1.Selected.Data^));
         Parameters.ParamByName('xh').Value:=idh;
         ExecSQL;
         ADOConnection1.CommitTrans;
       end;
       except
       begin
         ADOConnection1.RollbackTrans;
         MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
         exit;
       end;
      end;
    end;
    TreeView1.Selected.MoveTo(tmpn,naAddChild);
  end;
end;

procedure TWdForm.O2Click(Sender: TObject);
var
 tmpn:TTreeNode;
 ss,st,sd,sm:string;  //SS为上级记录号,ST为上级最后一个记录号,SD为当前应得记录号
 i:integer;           //sm为当前的记录号
begin
  tmpn:=TreeView1.Selected.Parent;
   if tmpn<>nil then
   begin
    with ADOQuery1 do
    begin
    try
    begin
     ADOConnection1.BeginTrans;
      close;
      sql.Clear; //得到上级记录号
      sql.Add('select id from table2 where xh=:xh');
      idh:=integer(pmydata(tmpn.data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;
      ss:=Fields[0].AsString;
      close;
      sql.Clear; //得到当前记录号
      sql.Add('select id from table2 where xh=:xh');
      idh:=integer(pmydata(TreeView1.Selected.data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;
      sm:=Fields[0].AsString;
      i:=length(sm);
      close;
      sql.Clear; //得到上级最后一条记录号
      sql.Add('select id from table2 where parentId=(select parentid from table2 where xh=:xh ) order by id');
      idh:=integer(pmydata(tmpn.data^));
      Parameters.ParamByName('xh').Value:=idh;
      open;
      last;
      st:=Fields[0].AsString;
      if st='' then  //如果上级是根,得到上级最后一条记录号
      begin
        close;
        sql.Clear;
        sql.Add('select id from table2 where len(id)=4 order by id');
        open;
        last;
        st:=Fields[0].AsString;
      end;
      sd:=getbh(st);  //得到当前记录应得的记录号
      close;//修改当前记录的子记录号
      sql.Clear;
      sql.Add('update table2 set parentid='+''''+sd+''''+'+right(parentid,len(Parentid)-'+intTostr(i)+
           '),id='+''''+sd+''''+'+right(id,len(id)-'+intTostr(i)+') where left(parentid,'+intTostr(i)+')='+''''+sm+'''');
      ExecSQL;
      close;
      sql.Clear; //修改当前记录的记录号
      sql.add('update table2 set Id='+''''+sd+''''+',parentId='+''''+''''+' where xh=:xh');
      idh:=integer(pmydata(TreeView1.Selected.data^));
      Parameters.ParamByName('xh').Value:=idh;
      ExecSQL;
      ADOConnection1.CommitTrans;
      end;
      except
      begin
       ADOConnection1.RollbackTrans;
       MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
       exit;
      end;
      end;
    end;
    TreeView1.Selected.MoveTo(tmpn,naAdd);
   end;
end;

procedure TWdForm.ToolButton4Click(Sender: TObject);
begin
 try
 if edit1.Text<>'' then
 begin
  if OleContainer1.State<>osEmpty then
   begin
   OleContainer1.Close;
   OleContainer1.CreateLinkToFile(edit1.Text,false);
   //OleContainer1.DoVerb(ovshow);
   OleContainer1.Run;
   end
  else //if OleContainer1.State=osempty then
    begin
     OleContainer1.CreateLinkToFile(edit1.Text,false);
     //OleContainer1.DoVerb(ovshow);
     OleContainer1.Run;
    end;
 end;
 except
   showmessage('文件地址有问题请检查!') ;
 end;

end;

procedure TWdForm.TreeView1Edited(Sender: TObject; Node: TTreeNode;
  var S: String);
  var i:integer;
begin
    if  node.Data<>nil then
   begin
    ADOQuery2.Close; //treeview 内容发生改变后,通过DATA属性对数据库中对应记录进行相应的改变
    adoquery2.SQL.Clear;
    adoquery2.SQL.add('update table2 set name='+''''+s+''''+' where xh=:xh') ;
    i:=integer(pmydata(node.data^));
    ADOQuery2.Parameters.ParamByName('xh').Value:=inttostr(i);
    try
     begin
      ADOConnection1.BeginTrans;
      adoquery2.ExecSQL;
      ADOConnection1.CommitTrans;
    end;
    except
    begin
     ADOConnection1.RollbackTrans;
     MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
     exit;
    end;
    end;
    adoquery2.Close;
   end;
end;

//选择记录后,修改相关属性的状态值
procedure TWdForm.TreeView1GetSelectedIndex(Sender: TObject;
  Node: TTreeNode);
begin
 yn:=true;
 Nodel:=TreeView1.Selected;
 if nodel.getFirstChild<>nil then  //是否有子项
  begin
    BitBtn1.Enabled:=false;
    edit1.Enabled:=false;
    ToolButton2.Enabled:=False;
    ToolButton5.Enabled:=False;
  end
 else
  begin
    BitBtn1.Enabled:=True;
    ToolButton2.Enabled:=true;
    ToolButton5.Enabled:=true;
    edit1.Enabled:=True;
  end;
end;
//清除所有数据
procedure TWdForm.N13Click(Sender: TObject);
begin
  if MessageDlg('数据将要被全部删除,是否继续? ',mtInformation,[mbYes,mbno],1)=mrYes then
  begin
   try
     ADOConnection1.BeginTrans;
     with ADOQuery1 do
     begin
       close;
       sql.Clear;
       sql.Add('delete from table2');
       ExecSQL;
       ADOConnection1.CommitTrans;
     end;
   except
     begin
       ADOConnection1.RollbackTrans;
       MessageDlg('操作执行失败,请检查后重新执行',mtError,[mbok],0);
       exit;
     end;
   end;
     TreeView1.Items.Clear;
  end;
end;
//进入数据库维护
procedure TWdForm.N14Click(Sender: TObject);
begin
 Application.CreateForm(TPasswordDlg, PasswordDlg);
 try
 PasswordDlg.ShowModal;
 finally
 PasswordDlg.Free;
 end;
end;

//文件复制
procedure TWdForm.ToolButton2Click(Sender: TObject);
var s:string;
begin
 if SelectDirectory('选择文件夹', '', S) then
   copyfile(Pchar(edit1.Text),pchar(s+'\'+nodel.Text),true);
end;
//文件移动到新的目录,同时修改记录
procedure TWdForm.ToolButton5Click(Sender: TObject);
var s:string;
begin
 if SelectDirectory('选择文件夹', '', S) then
 begin
   movefile(Pchar(edit1.Text),pchar(s));
   if Length(s)=3 then
     edit1.Text:=s+nodel.text
   else
     edit1.Text:=s+'\'+nodel.text;
   ToolButton3.Click;
 end;
end;

end.

⌨️ 快捷键说明

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