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

📄 ufunction.pas

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

interface
uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,jpeg, Dialogs,
  Menus, ComCtrls, ToolWin, Grids, DBGrids,StdCtrls, ExtCtrls,DBGridEh,
  DBCtrls, Mask, printers, quickrpt,Buttons,dbtables,DB, ADODB, Qrctrls,uconst,udm1;
    function SmallTOBig(small:real):string;
    function qxjc(userid:string;zd:string):boolean;
    function qxjc1(userid:string;zd:string):boolean;
    function createid(adoqueryx:Tadoquery;id:string):string;
    procedure adoexect(adoqueryx:tadoquery;strsql:string);
    procedure adodel(adoquery1:tadoquery;strsql:string);
    procedure Compositor(ADOQDBGrid:Tadoquery;Column:TColumnEh);
    function creatdh(adoqueryx:tadoquery;ws:integer;qz:string):string;
    function loadpicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;
    function savepicture(adoquery1:tadoquery;image1:timage;kzm:string;zd:string):string;
    function savedata(adoquery1:tadoquery;dbname:string;id:string;id1:string;zd:string):boolean;
    procedure dgridpx(qusp:tadoquery;DBGrid1:tdbgrid;Column: TColumn);
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 qxjc(userid:string;zd:string):boolean;
var
adoquery1:tadoquery;
begin
adoquery1:=tadoquery.Create(nil);
strsql:='select * from user_qxsz where dh='+''''+userid+'''';
adoexect(adoquery1,strsql);
if not adoquery1.FieldByName(zd).Value then
   begin
   application.MessageBox('对不起!您没有足够的权限','警告',mb_ok+mb_iconwarning);
   result:=false;
   end else
   result:=true;
adoquery1.Close;
end;
function qxjc1(userid:string;zd:string):boolean;
var
adoquery1:tadoquery;
begin
adoquery1:=tadoquery.Create(nil);
strsql:='select * from user_qxsz where dh='+''''+userid+'''';
adoexect(adoquery1,strsql);
if not adoquery1.FieldByName(zd).Value then
   begin
   result:=false;
   end else
   result:=true;
adoquery1.Close;
end;
function savedata(adoquery1:tadoquery;dbname:string;id:string;id1:string;zd:string):boolean;
var
n:integer;
adoquery3:tadoquery;
begin
adoquery3:=tadoquery.Create(nil);
if adoquery1.State in[dsEdit] then
   begin
   if (id<>id1) and (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;
   end else begin
      strsql:='select * from '+dbname+' where '+zd+' = '+''''+id+'''';
      adoquery3.Close;
      adoquery3.Connection:=dm1.ADOConnection1;
      adoquery3.SQL.Clear;
      adoquery3.SQL.add(strsql);
      adoquery3.Open;
      n:=adoquery3.Recordset.RecordCount;
      if (n>0) 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 + '00000001';
EXIT;
END;
ADOQUERYx.Last;
getid:=STRTOINT(COPY(ADOQUERYx.Fields[0].AsString,3,8));
getid:=getid+1;
result:=id+FORMATFLOAT('00000000',GETID);

end;
procedure Compositor(ADOQDBGrid:Tadoquery;Column:TColumnEh);
var
  field_sort:string;
begin
  with Column do
  begin
    if FieldName = '' then exit;
    case Title.SortMarker of
      smNoneEh:
        begin
          Title.SortMarker := smDownEh;
          field_sort := Column.FieldName + ' ASC';
        end;
      smDownEh:field_sort := Column.FieldName + ' DESC';
      smUpEh:field_sort := Column.FieldName + ' ASC';
    end;
    try
      ADOQDBGrid.Sort := field_sort
    except
      beep;
      showmessage('排序不成功');
    end;
  end;
end;

procedure dgridpx(qusp:tadoquery;DBGrid1:tdbgrid;Column: TColumn);
var
 temp, title,cxstr: string;
 i,LastColumn:integer;
begin

 temp := trim(Column.FieldName);
 LastColumn:=dbgrid1.Columns.Count-1;
 qusp.Close;
 i:=pos('order',trim(qusp.SQL.Text));
 if i<10 then
    cxstr:=trim(qusp.SQL.text)
 else
    cxstr:=copy(trim(qusp.SQL.text),1,i-1);

for i:=0 to LastColumn do
   begin
   if i=column.Index then continue;
   DBGrid1.Columns[i].Title.Caption:=trim(DBGrid1.Columns[i].FieldName);
   end;

   LastColumn := Column.Index;
   title := DBGrid1.Columns[LastColumn].Title.Caption;
   if Pos('↑', title) > 0 then
   begin
     cxstr := cxstr+' order by ' + temp + ' desc';
     DBGrid1.Columns[LastColumn].Title.Caption := '↓' + temp;
   end
   else if Pos('↓', title) > 0 then
   begin
     cxstr := cxstr+ ' order by ' + temp + ' asc';
     DBGrid1.Columns[LastColumn].Title.Caption := '↑' + temp;
   end
   else
   begin
     cxstr := cxstr+ ' order by ' + temp + ' asc';
     DBGrid1.Columns[LastColumn].Title.Caption := '↑' + temp;
   end;
 qusp.SQL.Clear;
 qusp.SQL.Add(cxstr);
 qusp.Open;
end;

procedure adoexect(adoqueryx:tadoquery;strsql:string);
 begin
 if adoqueryx.Active then adoqueryx.Close;
 adoqueryx.Connection:=dm1.ADOConnection1;
 adoqueryx.Prepared:=true;
 adoqueryx.sql.Clear;
 adoqueryx.sql.Add(strsql);
 AdoQueryx.DisableControls;
 AdoQueryx.CacheSize := 1000;
 adoqueryx.Open;
 AdoQueryx.EnableControls;
 end;

 procedure adodel(adoquery1:tadoquery;strsql:string);
 begin
 if adoquery1.Active then adoquery1.Close;
 adoquery1.Connection:=dm1.ADOConnection1;
 adoquery1.Prepared:=true;
 adoquery1.sql.Clear;
 adoquery1.sql.Add(strsql);
 adoquery1.ExecSQL;
 end;
function creatdh(adoqueryx:tadoquery;ws:integer;qz:string):string;
var
getid:integer;
begin
if adoqueryx.recordset.eof and adoqueryx.recordset.bof then begin
       result:=qz +'001';
       EXIT;
   END;
ADOQUERYx.Last;
getid:=STRTOINT(COPY(ADOQUERYx.Fields[0].AsString,ws,3));
getid:=getid+1;
result:=qz+FORMATFLOAT('000',GETID);
end;

function SmallTOBig(small:real):string;
var
 SmallMonth,BigMonth:string;
 wei1,qianwei1:string[2];
 qianwei,dianweizhi,qian:integer;
begin
 qianwei:=-2;
 Smallmonth:=formatfloat('0.00',small);
 dianweizhi :=pos('.',Smallmonth);
 for qian:=length(Smallmonth) downto 1 do
  begin
   if qian<>dianweizhi then
    begin
    case strtoint(copy(Smallmonth,qian,1)) of
     1:wei1:='壹'; 2:wei1:='贰';
     3:wei1:='叁'; 4:wei1:='肆';
     5:wei1:='伍'; 6:wei1:='陆';
     7:wei1:='柒'; 8:wei1:='捌';
     9:wei1:='玖'; 0:wei1:='零';
    end;
 case qianwei of
  -3:qianwei1:='厘';
  -2:qianwei1:='分';
  -1:qianwei1:='角';
  0 :qianwei1:='元';
  1 :qianwei1:='拾';
  2 :qianwei1:='佰';
  3 :qianwei1:='千';
  4 :qianwei1:='万';
  5 :qianwei1:='拾';
  6 :qianwei1:='佰';
  7 :qianwei1:='千';
  8 :qianwei1:='亿';
  9 :qianwei1:='十';
  10:qianwei1:='佰';
  11:qianwei1:='千';
 end;
  inc(qianwei);
  BigMonth :=wei1+qianwei1+BigMonth;
 end;
 end;
 SmallTOBig:=BigMonth;
end;
end.

⌨️ 快捷键说明

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