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

📄 ufunction1.pas

📁 工廠採購管理系統
💻 PAS
字号:
unit ufunction1;

interface
uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,jpeg, Dialogs,
  Menus, ComCtrls, ToolWin, Grids, DBGrids,StdCtrls, ExtCtrls,
  DBCtrls, Mask, printers, quickrpt,Buttons,dbtables,DB, ADODB, Qrctrls,uconst,udm;

  function createid(adoqueryx:Tadoquery;id:string):string;
    procedure adoexect(adoqueryx:tadoquery;strsql:string);
    procedure adodel(adoquery1:tadoquery;strsql:string);
    function savedata(adoquery1:tadoquery;adoquery3:tadoquery;dbname:string;id:string;id1:string;zd:string):boolean;
     function isdate(str:string):boolean;
     function isinteger(str:string):boolean;
     function isfloat(str:string):boolean;
     function FormatDate(da: TDateTime): String;
     function loadpicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;
     function savepicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;

implementation
function loadpicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;
var
str:tmemorystream;
myjpeg:tjpegimage;
begin
    try

      if kzm='' then exit;
      str:=tmemorystream.Create;
      str.Position := 0;
      tblobfield(adoquery1.FieldByName(zd)).SaveToStream(str);
      str.Position := 0;
      Image1.Picture.Graphic := nil;
      if (kzm = 'jpg') then
      begin
        Image1.Picture.Graphic := Tjpegimage.create;
        Image1.Picture.Graphic.LoadFromStream(str);
         // buf.Free;
      end;
      if (kzm = 'jpeg') then
      begin
        Image1.Picture.Graphic := Tjpegimage.create;
        Image1.Picture.Graphic.LoadFromStream(str);
         // buf.Free;
      end;
      if (kzm = 'bmp') then
      begin
        Image1.Picture.Bitmap := nil;
        Image1.Picture.Bitmap.LoadFromStream(str);
         // buf.Free;
      end;
     str.Free;
    except
      showmessage('载入图片不成功,请检查是否是JPE/BMP/JPEG类型图片');
    end;
end;
function savepicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;
var
str:tmemorystream;
myjpeg:tjpegimage;
begin
try
          if kzm <> 'NULL' then
          begin
          str:=tmemorystream.Create;
            if kzm = 'jpg' then
            begin
              myjpeg := tjpegimage.Create;
              myjpeg.Assign(image1.Picture.Graphic);
              myjpeg.SaveToStream(str);
              str.Position := 0;
              tblobfield(adoquery1.FieldByName(zd)).LoadFromStream(str);
              str.free;
            end;
            if kzm = 'bmp' then
            begin
              str := tmemorystream.Create;
              image1.Picture.Bitmap.SaveToStream(str);
              str.Position := 0;
              tblobfield(adoquery1.FieldByName(zd)).LoadFromStream(str);
              str.free;
            end;
          end
except
application.messagebox('保存图片数据时出错!','提示',mb_ok+mb_iconinformation);
end;
end;
function savedata(adoquery1:tadoquery;adoquery3:tadoquery;dbname:string;id:string;id1:string;zd:string):boolean;
var
strsql:string;
begin
if adoquery1.State in[dsEdit] then
if id<>id1 then begin
strsql:='select * from '+dbname+' where '+zd+'='+''''+id+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Eof and adoquery3.Bof) then begin
application.messagebox('该代码已经存在!请选用其他的代码!','警告',mb_ok+mb_iconwarning);
result:=false;
exit;
end;
end;
if adoquery1.State in[dsinsert] then begin
strsql:='select * from '+dbname+' where '+zd+'='+''''+id+'''';
showmessage(strsql);
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.eof and adoquery3.Recordset.BOF) then begin
application.MessageBox('该代码已经存在!请选用其他的代码!','警告',mb_ok+mb_iconwarning);
result:=false;
exit;
end;
end;
result:=true;
end;
function createid(adoqueryx:Tadoquery;id:string):string;
var
getid:LongInt;
begin
if adoqueryx.recordset.eof and adoqueryx.recordset.bof then begin
result:=id + '000001';
EXIT;
END;
ADOQUERYx.Last;
getid:=STRTOINT(COPY(ADOQUERYx.Fields[0].AsString,3,6));
getid:=getid+1;
result:=id+FORMATFLOAT('000000',GETID);

end;

procedure adoexect(adoqueryx:tadoquery;strsql:string);
 begin
 if adoqueryx.Active then adoqueryx.Close;
 adoqueryx.Connection:=dm.ADOConnection1;
 adoqueryx.Connection;
 adoqueryx.sql.Clear;
 adoqueryx.sql.Add(strsql);
 adoqueryx.Prepared:=true;
 adoqueryx.Open;
 end;

 procedure adodel(adoquery1:tadoquery;strsql:string);
 begin
 if adoquery1.Active then adoquery1.Close;
 adoquery1.Connection:=dm.ADOConnection1;
 adoquery1.Connection;
 adoquery1.sql.Clear;
 adoquery1.sql.Add(strsql);
 adoquery1.ExecSQL;
 end;
 function isdate(str:string):boolean;
begin
 result:=true;
 try
   strtodate(str);
 except
   if str<>'' then
   result:=false;
 end;
end;

function isinteger(str:string):boolean;
begin
 result:=true;
 try
   strtoint(str);
 except
   result:=false;
 end;
end;

function isfloat(str:string):boolean;
begin
 result:=true;
 try
   strtofloat(str);
 except
   result:=false;
 end;
end;
function FormatDate(da: TDateTime): String;
var i:integer;
begin
  result:=formatdatetime('yyyy-mm-dd',da);
  for i:=1 to length(result) do
    if not (result[i] in ['0'..'9']) then result[i]:='-';
end;
end.

⌨️ 快捷键说明

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