D7snShanfengT/山峰贸易管理/U_FileUp_TuGao.pas
DESKTOP-E401PHE\Administrator c363cb75a7 调整之后的山凤水泥厂
2026-02-26 09:41:35 +08:00

398 lines
11 KiB
ObjectPascal
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit U_FileUp_TuGao;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxDataStorage, cxEdit, DB, cxDBData, ComCtrls, ToolWin, ExtCtrls,
cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
cxClasses, cxControls, cxGridCustomView, cxGrid, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdFTP, StdCtrls, ADODB,jpeg,
BtnEdit,IniFiles;
type
TfrmFileUp_TuGao = class(TForm)
cxGrid7: TcxGrid;
TV7: TcxGridDBTableView;
FileName: TcxGridDBColumn;
FileDate: TcxGridDBColumn;
cxGridLevel6: TcxGridLevel;
Panel16: TPanel;
ToolBar6: TToolBar;
FileUp: TToolButton;
FileDel: TToolButton;
Panel1: TPanel;
Label1: TLabel;
Code: TEdit;
ODPat: TOpenDialog;
IdFTP1: TIdFTP;
SaveDialog1: TSaveDialog;
ADOQueryFile: TADOQuery;
DataSource1: TDataSource;
ADOQueryCmd: TADOQuery;
ADOQueryTemp: TADOQuery;
Panel2: TPanel;
Image2: TImage;
procedure FileUpClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FileDelClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TV7CellClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
private
lstPat: TStringList;
AJpeg: TJPEGImage;
procedure CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
procedure SaveImageOther();
procedure ReadINIFile10();
procedure InitImage();
{ Private declarations }
public
CYID:String;
{ Public declarations }
end;
var
frmFileUp_TuGao: TfrmFileUp_TuGao;
implementation
uses
U_DataLink,U_Fun;
{$R *.dfm}
procedure TfrmFileUp_TuGao.InitImage();
var
jpg:TJpegImage;
myStream:TADOBlobStream;
begin
if ADOQueryFile.IsEmpty then Exit;
//if Trim(ADOQueryFile.fieldbyname('CYID').asstring)='' then Exit;
// if cxPageControl1.ActivePageIndex=6 then
begin
//Image2.Picture.Assign(nil);
try
with ADOQueryTemp do
begin
close;
sql.Clear;
sql.Add(' select * from TP_File A where A.WBID='''+Trim(ADOQueryFile.fieldbyname('CYID').AsString)+'''');
sql.Add(' and TFType=''BJ'' ');
open;
if RecordCount>0 then
begin
if trim(ADOQueryTemp.fieldbyname('FilesOther').AsString)<>'' then
begin
myStream:=tadoblobstream.Create(tblobfield(ADOQueryTemp.fieldbyname('FilesOther')),bmread);
if myStream=nil then exit;
jpg:=TJPEGImage.Create;
jpg.LoadFromStream(myStream);
Image2.Picture.Assign(jpg);
end;
end;
end;
finally
jpg.Free;
myStream.Free;
end;
end;
end;
procedure TfrmFileUp_TuGao.ReadINIFile10();
var
programIni:Tinifile; //<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
FileName:string;
begin
FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
programIni:=Tinifile.create(FileName);
server:=programIni.ReadString('SERVER','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ','127.0.0.1');
programIni.Free;
end;
procedure TfrmFileUp_TuGao.FileUpClick(Sender: TObject);
var
i,j: Integer;
PatFile: String;
FTPPath,FConNo,MaxNo:string;
AJpeg: TJPEGImage;
begin
if Trim(Code.Text)='' then
begin
Application.MessageBox('<27><><EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
lstPat.Clear;
if ODPat.Execute then
begin
lstPat.AddStrings(ODPat.Files);
end;
if lstPat.Count > 0 then
begin
try
ReadINIFile10();
server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ','127.0.0.1');
IdFTP1.Host :=server;//PicSvr;
IdFTP1.Username := 'three';
IdFTP1.Password := '641010';
IdFTP1.Connect();
except
IdFTP1.Quit;
Application.MessageBox('<27>޷<EFBFBD><DEB7><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>飡', '<27><>ʾ', MB_ICONWARNING);
Exit;
end;
end;
Panel16.Visible:=True;
Panel16.Refresh;
AJpeg:=TJpegImage.Create();
with ADOQueryTemp do
begin
Close;
SQL.Clear;
SQL.Add('select Count(*) MM from XD_File where CYID='''+Trim(CYID)+'''');
SQL.Add('and filetype=''BJ''');
Open;
j:=fieldbyname('MM').AsInteger;
end;
Image2.Picture.LoadFromFile(ODPat.FileName);
AJpeg.Assign(Image2.Picture.Graphic);
CreThumb(AJpeg,Image2,216, 187);
try
ADOQueryCmd.Connection.BeginTrans;
for i := 0 to lstPat.Count - 1 do
begin
PatFile := ExtractFileName(lstPat[i]);
PatFile:=Copy(PatFile,(Pos('.',PatFile)+1),(Length(PatFile)-Pos('.',PatFile)) ) ;
FConNo:=Trim(Code.Text);
while Pos('/',FConNo)>0 do
begin
Delete(FConNo,Pos('/',FConNo),1);
end;
PatFile:=Trim(FConNo)+'-'+Inttostr(j+i+1)+'.'+PatFile;
if IdFTP1.Connected then
begin
try
IdFTP1.Put(lstPat[i], Trim(UserDataFlag+'YP')+'\'+Trim(PatFile));
with ADOQueryTemp do
begin
Close;
SQL.Clear;
SQL.Add('select * from XD_File where CYID='''+Trim(CYID)+'''');
SQL.Add(' and filename='''+Trim(PatFile)+'''');
SQL.Add(' and filetype=''BJ''');
Open;
if not IsEmpty then
begin
Panel16.Visible:=False;
Application.MessageBox(PChar('<27>ļ<EFBFBD><'+Trim(PatFile)+'><3E>ظ<EFBFBD>,'+inttostr(i)+'<27><><EFBFBD>ļ<EFBFBD><C4BC>ϴ<EFBFBD><CFB4>ɹ<EFBFBD><C9B9><EFBFBD>'),'<27><>ʾ',0);
Exit;
end;
end;
if GetLSNo(ADOQueryCmd,MaxNo,'BJ','XD_File',4,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('ȡͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
Exit;
end;
with ADOQueryCmd do
begin
Close;
SQL.Clear;
SQL.Add('select * from XD_File where 1=2');
Open;
end;
with ADOQueryCmd do
begin
Append;
FieldByName('XFID').Value:=Trim(MaxNo);
FieldByName('CYID').Value:=Trim(MaxNo);
FieldByName('CYNO').Value:=Trim(Code.Text);
FieldByName('filename').Value:=Trim(PatFile);
FieldByName('FileDate').Value:=SGetServerDate(ADOQueryTemp);
fieldbyname('FileType').value:=Trim('BJ');
Post;
end;
except;
//ADOQueryCmd.Connection.RollbackTrans;
//Application.MessageBox('ͼƬ<CDBC>ϴ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
end;
end;
end;
CYID:=Trim(MaxNo);
with ADOQueryFile do
begin
Close;
SQL.Clear;
SQL.Add('select * from XD_File where CYID='''+Trim(MaxNo)+'''');
open;
end;
SaveImageOther();
ADOQueryCmd.Connection.CommitTrans;
except
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('ͼƬ<CDBC>ϴ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>','<27><>ʾ',0);
end;
if IdFTP1.Connected then IdFTP1.Quit;
Panel16.Visible:=False;
if i>0 then
Application.MessageBox(PChar(inttostr(i)+'<27><><EFBFBD>ļ<EFBFBD><C4BC>ϴ<EFBFBD><CFB4>ɹ<EFBFBD><C9B9><EFBFBD>'),'<27><>ʾ',0);
ModalResult:=1;
end;
procedure TfrmFileUp_TuGao.CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
var
Bitmap: TBitmap;
Ratio: Double;
ARect: TRect;
AHeight, AHeightOffset: Integer;
AWidth, AWidthOffset: Integer;
begin
Bitmap := TBitmap.Create;
try
Ratio := AJPeg.Width /AJPeg.Height;
if Ratio > 1.333 then
begin
AHeight := Round(Width / Ratio);
AHeightOffset := (Height - AHeight) div 2;
AWidth := Width;
AWidthOffset := 0;
end
else
begin
AWidth := Round(Height * Ratio);
AWidthOffset := (Width - AWidth) div 2;
AHeight := Height;
AHeightOffset := 0;
end;
Bitmap.Width := Width;
Bitmap.Height := Height;
Bitmap.Canvas.Brush.Color := clBtnFace;
Bitmap.Canvas.FillRect(Rect(0, 0, Width, Height));
ARect := Rect(AWidthOffset, AHeightOffset, AWidth + AWidthOffset, AHeight + AHeightOffset);
Bitmap.Canvas.StretchDraw(ARect, AJPeg);
Image1.Picture.Assign(BitMap);
finally
Bitmap.Free;
end;
end;
procedure TfrmFileUp_TuGao.SaveImageOther();
var
AJpeg: TJPEGImage;
myStream: TADOBlobStream;
ImgMaxNo:String;
i,j: Integer;
PatFile: String;
FTPPath,FConNo,MaxNo,FTFID,FCYID:string;
begin
if Image2.Picture=nil then Exit;
AJpeg:=TJpegImage.Create();
with ADOQueryTemp do
begin
Close;
sql.Clear;
sql.Add('select * from TP_File where WBID='''+Trim(ADOQueryFile.fieldbyname('CYID').asstring)+'''');
Open;
end;
FTFID:=Trim(ADOQueryTemp.fieldbyname('TFID').AsString);
if Trim(FTFID)='' then
begin
if GetLSNo(ADOQueryCmd,ImgMaxNo,'TF','TP_File',3,1)=False then
begin
ADOQueryCmd.Connection.RollbackTrans;
Application.MessageBox('ȡͼƬ<CDBC><C6AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>!','<27><>ʾ',0);
Exit;
end;
end else
begin
ImgMaxNo:=Trim(FTFID);
end;
with ADOQueryCmd do
begin
close;
sql.Clear;
sql.Add( ' select * from TP_File where TFID='''+Trim(FTFID)+'''');
open;
end;
with ADOQueryCmd do
begin
if Trim(FTFID)='' then
begin
Append;
FieldByName('Filler').Value:=Trim(DName);
end
else
begin
Edit;
FieldByName('Editer').Value:=Trim(DName);
FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp);
end;
FieldByName('TFID').Value:=Trim(ImgMaxNo);
FieldByName('WBID').Value:=Trim(ADOQueryFile.fieldbyname('CYID').asstring);
FieldByName('TFType').Value:='BJ';
AJpeg.Assign(Image2.Picture.Graphic);
myStream:=TADOBlobStream.Create(TBlobField(ADOQueryCmd.FieldByName('FilesOther')), bmWrite);
AJpeg.Assign(Image2.Picture.Graphic);
AJpeg.SaveToStream(myStream);
myStream.Free;
Post;
end;
end;
procedure TfrmFileUp_TuGao.FormCreate(Sender: TObject);
begin
lstPat := TStringList.Create;
end;
procedure TfrmFileUp_TuGao.FileDelClick(Sender: TObject);
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
SQL.Add(' Delete XD_File where XFID='''+Trim(ADOQueryFile.fieldbyname('XFID').AsString)+'''');
SQL.Add(' Delete TP_File where WBID='''+Trim(CYID)+''' and TFType=''BJ'' ');
ExecSQL;
end;
with ADOQueryFile do
begin
Close;
SQL.Clear;
SQL.Add('select * from XD_File where CYID='''+Trim(CYID)+'''');
SQL.Add(' and FileType=''BJ''');
open;
end;
if ADOQueryFile.IsEmpty then
begin
with ADOQueryCmd do
begin
Close;
sql.Clear;
sql.Add('Update CP_YDang Set TPFlag=0 where CYID='''+Trim(CYID)+'''');
ExecSQL;
end;
end;
end;
procedure TfrmFileUp_TuGao.FormShow(Sender: TObject);
begin
with ADOQueryFile do
begin
Close;
SQL.Clear;
SQL.Add('select * from XD_File where CYID='''+Trim(CYID)+'''');
//sql.add(' and filetype=''BJ''');
Open;
end;
end;
procedure TfrmFileUp_TuGao.TV7CellClick(Sender: TcxCustomGridTableView;
ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
AShift: TShiftState; var AHandled: Boolean);
begin
InitImage();
end;
end.