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

📄 tools_unt.pas

📁 煤矿行业采掘接替计划自动生成系统
💻 PAS
字号:
unit Tools_Unt;

interface
uses comobj,Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls,variants,DBCtrls,ADODB,DB,OleCtnrs;

//删除数据表中的记录,并把当前指针指向被删除的记录的相应位置:
//若被删除的记录为第一条记录,则删除后当前指针指向删除后的表中的第一条记录
//若删除的记录的上一条有记录,则删除后当前指针指向上一条记录
function DelRecord(Tabl:TDataSet):boolean;
//进行删除操作后,对表中的编号进行调整,以使得编号是从1开始以1为间距递增排列
//function ArrangeRecord(Tabl:TDataSet;Str:string):boolean;
//获得数据表最后一条记录的字段为fieldstr的值
function GetLastRecId(AdoTabl:TDataSet;FieldStr:String):integer;
//数据表中的记录修改确定
function ModifyRec(Tabl:TDataSet):boolean;
//到路径名为filestr的路径下,若无此路径则创建,后到创建的路径下
function CDMDDir(filestr:string):string;

implementation

function DelRecord(Tabl:TDataSet):boolean;
var Bk:Tbookmark;
begin
result:=false;
try
  with Tabl do
   if (MessageDlg('确定删除该记录吗?',mtConfirmation, [mbYes, mbNo], 0) = mrYes)
      and(IsEmpty=false)
   then begin
         if recordcount=0 then cancel;
         if RecordCount=1
          then begin
                delete;close;open;
               end;
          if recordcount>1
           then begin
                 if RecNo=1
                  then begin
                        //next;
                        //Bk:=getbookmark;
                        //prior;
                        Delete;
                        close;
                        open;
                        first;
                       end
                  else begin
                        prior;
                        Bk:=getbookmark;
                        next;
                        Delete;
                        close;
                        open;
                        if recordcount>1 then  GotoBookmark(Bk);
                        FreeBookmark(Bk);
                       end;
                 //Delete;
                 //close;open;
                 //if recordcount>1 then  GotoBookmark(Bk);

                end;
         result:=true;
        end;
except
  showmessage('数据库未连接正确!');
end;

end;

function GetLastRecId(AdoTabl:TDataSet;FieldStr:String):integer;
begin
result:=0;
try
  if AdoTabl.RecordCount=0 then
      begin
        exit;
      end
  else
      begin
        AdoTabl.Last;
        result:=AdoTabl.FieldByName(FieldStr).AsInteger;
      end;
except
  showmessage('数据库未连接正确!');
end;

end;

function ModifyRec(Tabl:TDataSet):boolean;
begin
result:=false;
try
  if Tabl.RecordCount=0 then
    begin
      showmessage('数据表为空,无法修改!');
      exit;
    end;
  Tabl.Edit;
  Tabl.Post;
  result:=true;
except
  Tabl.Cancel;
  showmessage('更新没有成功!');
end;

end;

function CDMDDir(filestr:string):string;
begin
 //try
  MkDir(filestr);
 //except
  //on EInoutError do ChDir(filestr);
 //end;
  result:=filestr+'\';
end;

//function ArrangeRecord(Tabl:TDataSet;Str:String):boolean;
//begin

//end;

end.

⌨️ 快捷键说明

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