function TCB_IMGPSScanX.Get_Color: OLE_COLOR; begin Result := OLE_COLOR(Color); end; procedure TCB_IMGPSScanX.Set_Color(Value: OLE_COLOR); begin Color := TColor(Value); end; procedure TCB_IMGPSScanX.StatrTwainScan; var ScanInfo : TScanInfo; i : Integer; begin if not Scanner.IsConfigured then begin ShowMessage(_Msg('TWAIN 掃瞄驅動尚未安裝')); Exit; end; FillChar(ScanInfo, SizeOf(ScanInfo), 0); ScanInfo.MultiPage := True; ScanInfo.ImageCount := 0; ScanInfo.Graphic := TTiffGraphic.Create; try ISB := nil; //規零 //ShowMessage(IntToStr(ScanDpi)); Scanner.RequestedXDpi := ScanDpi; Scanner.RequestedYDpi := ScanDpi; Scanner.RequestedImageFormat := ScanColor; Scanner.ShowUI := TwainShowUI; Try Scanner.OpenSource; Scanner.Duplex := ScanDuplex; //雙面 if FMode='SAMPLESCAN' then Scanner.Duplex:=False; //Scanner.FEEDERENABLED := not ScanFlatCB.Checked; // 先拿掉平台 If ScanImgSetUse Then begin Scanner.ScanBrightness := ScanBright; Scanner.ScanContrast := ScanContrast; end; except Showmessage(_Msg('掃瞄器發生錯誤!!')); Scanner.CloseSource; Exit; end; try Try Scanner.AcquireWithSourceOpen( OnAcquire, LongInt(@ScanInfo)); Except Scanner.CloseSource; end; finally Scanner.CloseSource; end; finally Scanner.CloseSource; ScanInfo.Graphic.Free; end; end; procedure TCB_IMGPSScanX.OnAcquire( const DibHandle : THandle; const XDpi : Word; const YDpi : Word; const CallBackData : LongInt ); var pScanInfo : TpScanInfo; SaveFileName : String; SaveStream : TFileStream; strResults : TBarcodeStringResult; DeleteStm : TMemoryStream; isDelete : Boolean; iGraphic,iGraphic_First,iGraphic_sec : TTiffGraphic; iRect : TRect; JpgGr : TJpegGraphic; i : Integer; TagTxt : String; function Deletepage(Graphic:TDibGraphic;BlankSize:Integer):Boolean; begin DeleteStm := TMemoryStream.Create; DeleteStm.Seek(0,soFromBeginning); Graphic.AppendToStream(DeleteStm); //DeleteStm.LoadFromFile(Path+'temp.tif'); //Isb1.Graphic.SaveToStream(DeleteStm); //Isb1.Graphic.AppendToStream(DeleteStm); if DeleteStm.Size < BlankSize Then Result:= True Else Result := False; DeleteStm.Free; //DeleteFile(Path+'temp.tif'); end; begin pScanInfo := TpScanInfo(CallBackData); isDelete := False; if pScanInfo^.MultiPage then begin pScanInfo^.Graphic.AssignFromDibHandle(DibHandle); pScanInfo^.Graphic.XDotsPerInch := XDpi; pScanInfo^.Graphic.YDotsPerInch := YDpi; TagTxt := 'height:'+inttostr(pScanInfo^.Graphic.Height)+',width:'+inttostr(pScanInfo^.Graphic.Width); if pScanInfo^.Graphic.ImageFormat = ifBlackWhite then begin ImageScrollBox1.Graphic.Assign(pScanInfo^.Graphic); ImageScrollBox1NewGraphic(ImageScrollBox1.Graphic); pScanInfo^.Graphic.Compression := tcGroup4; MpsGetBarcode(pScanInfo^.Graphic,MpsBarcodeinf); For i := 1 to MpsBarcodeinf.count do begin If (MpsBarcodeinf.r180[i] <> 0) and (Length(MpsBarcodeinf.Text[i])=FormIDLength) Then begin Rotate(pScanInfo^.Graphic,MpsBarcodeinf.r180[i]); MpsGetBarcode(pScanInfo^.Graphic,MpsBarcodeinf); //旋轉後再重取一次條碼資訊 Break; end; end; //影像反向 IF ScannerReverse then NegativeImg(pScanInfo^.Graphic); //傾斜矯正 IF ScanDeskew Then DeskewImg(pScanInfo^.Graphic); //清黑邊 IF BoardClear then CleanupBorder(pScanInfo^.Graphic); end else if pScanInfo^.Graphic.ImageFormat = ifTrueColor then begin //Ext := '.jpg'; ImageScrollBox1.Graphic.Assign(pScanInfo^.Graphic); //ImageScrollBox1NewGraphic(ImageScrollBox1.Graphic); MpsGetBarcode(ISB_BW.Graphic,MpsBarcodeinf); For i := 1 to MpsBarcodeinf.count do begin If (MpsBarcodeinf.r180[i] <> 0) and (Length(MpsBarcodeinf.Text[i])=FormIDLength) Then begin Rotate(ISB_BW.Graphic,MpsBarcodeinf.r180[i]); MpsGetBarcode(ISB_BW.Graphic,MpsBarcodeinf); //旋轉後再重取一次條碼資訊 Break; end; end; pScanInfo^.Graphic.Compression := tcJpeg; pScanInfo^.Graphic.JpegQuality := FJpgCompression; end else if pScanInfo^.Graphic.ImageFormat = ifColor256 Then begin //Ext := '.jpg'; ConvertToGray(pScanInfo^.Graphic); pScanInfo^.Graphic.Compression := tcJpeg; pScanInfo^.Graphic.JpegQuality := FJpgCompression; end else if pScanInfo^.Graphic.ImageFormat = ifGray256 Then begin //Ext := '.jpg'; ImageScrollBox1.Graphic.Assign(pScanInfo^.Graphic); ImageScrollBox1NewGraphic(ImageScrollBox1.Graphic); MpsGetBarcode(ISB_BW.Graphic,MpsBarcodeinf); For i := 1 to MpsBarcodeinf.count do begin If (MpsBarcodeinf.r180[i] <> 0) and (Length(MpsBarcodeinf.Text[i])=FormIDLength) Then begin Rotate(ISB_BW.Graphic,MpsBarcodeinf.r180[i]); MpsGetBarcode(ISB_BW.Graphic,MpsBarcodeinf); //旋轉後再重取一次條碼資訊 Break; end; end; pScanInfo^.Graphic.Compression := tcJpeg; pScanInfo^.Graphic.JpegQuality := FJpgCompression; //ShowMessage(IntToStr(pScanInfo^.Graphic.JpegQuality)); //if pScanInfo^.Graphic.Compression = tcJpeg then //begin //ShowMessage('jpg'); //end; end else begin //Ext := '.tif'; pScanInfo^.Graphic.Compression := tcPackBits; end; end; //Application.ProcessMessages; iGraphic_First := TTiffGraphic.Create; iGraphic_sec := TTiffGraphic.Create; //iGraphic := TTiffGraphic.Create; try iGraphic_First.Assign(pScanInfo^.Graphic); //Application.ProcessMessages; if CheckNeedCrop(iGraphic_First) Then begin iRect.Left := pScanInfo^.Graphic.Width div 2; //先取左邊的影像 iRect.Top := 0; iRect.Right := pScanInfo^.Graphic.Width; iRect.Bottom := pScanInfo^.Graphic.Height; CropImg(iGraphic_First,iRect); iGraphic_Sec.Assign(pScanInfo^.Graphic); //再取右邊的影像 iRect.Left := 0; iRect.Top := 0; iRect.Right := pScanInfo^.Graphic.Width div 2; iRect.Bottom := pScanInfo^.Graphic.Height; CropImg(iGraphic_Sec,iRect); end; //iGraphic.Assign(iGraphic_First); iGraphic := iGraphic_First; if iGraphic.ImageFormat=ifGray256 then //20180104 begin iGraphic.Compression:=tcJPEG; iGraphic.JpegQuality:=FJpgCompression; end; if iGraphic.ImageFormat=ifTrueColor then //20180104 begin iGraphic.Compression:=tcJPEG; iGraphic.JpegQuality:=FJpgCompression; end; //ShowMessage('WTF'); while not iGraphic.IsEmpty do begin //Application.ProcessMessages; IF (not DeviceDelete) or (not Deletepage(iGraphic,DeviceDeleteSize)) Then begin ImageScrollBox1.Graphic.Assign(iGraphic); ImageScrollBox1NewGraphic(ImageScrollBox1.Graphic); MpsGetBarcode(ISB_BW.Graphic,MpsBarcodeinf); For i := 1 To MpsBarcodeinf.Count Do Begin If MpsBarcodeinf.r180[i] <> 0 Then // 依條碼角度轉影像 Begin Rotate(iGraphic, MpsBarcodeinf.r180[i]); Break; End; End; if iGraphic.ImageFormat=ifGray256 then //20180104 因此旋轉後變為回packbits 所以要改為jpeg begin iGraphic.Compression:=tcJPEG; iGraphic.JpegQuality:=FJpgCompression; end; if iGraphic.ImageFormat=ifTrueColor then begin iGraphic.Compression:=tcJPEG; iGraphic.JpegQuality:=FJpgCompression; end; PageEnd; IF PEFileName <> '' Then begin IF LowerCase(ExtractFileExt(PEFileName)) = '.tif' Then begin if FileExists( PEFileName ) then SaveStream := TFileStream.Create( PEFileName ,fmOpenReadWrite) Else SaveStream := TFileStream.Create( PEFileName ,fmCreate ); try SaveStream.Seek(0, soFromBeginning); iGraphic.AppendToStream(SaveStream); finally SaveStream.Free; end; end Else IF LowerCase(ExtractFileExt(PEFileName)) = '.jpg' Then begin if FileExists( PEFileName ) then DeleteFile(PEFileName); //SaveStream := TFileStream.Create( PEFileName ,fmCreate ); JpgGr := TJpegGraphic.Create; try JpgGr.Assign(iGraphic); JpgGr.SaveQuality := FJpgCompression; //JpgGr.AppendToStream(SaveStream); JpgGr.SaveToFile(PEFileName); finally JpgGr.Free; //SaveStream.Free; end; end; PageDone; end; end; if iGraphic = iGraphic_First then iGraphic := iGraphic_Sec else iGraphic.Assign(nil); //iGraphic.Assign(iGraphic_Sec); end; finally //iGraphic.Free; iGraphic_First.Free; iGraphic_Sec.Free; end; end; Procedure TCB_IMGPSScanX.R_W_Scanini(Mode:Char); //'R'讀取;'W'寫入 var ini : Tinifile; begin ini := Tinifile.Create(ScaniniPath+'FBScan.ini'); try case Mode of 'R':begin DeviceDelete := ini.ReadBool('DeviceDelete','Mode',Def_DeviceDelete); DeviceDeleteSize := ini.ReadInteger('DeviceDelete','Size_New',Def_DeviceDeleteSize); ScannerReverse := ini.ReadBool('Scanner','Reverse',Def_ScannerReverse); BoardClear := ini.ReadBool('Scanner','BoardClear',Def_BoardClear); //ScanDpi := ini.ReadInteger('Scanner','Dpi',Def_ScanDpi); //ScanDuplex := ini.ReadBool('Scanner','Duplex',Def_ScanDuplex); ScanRotate := ini.ReadInteger('Scanner','ScanRotate',Def_ScanRotate); ScanDeskew := ini.ReadBool('Scanner','ScanDeskew',Def_ScanDeskew); ScanBright := ini.ReadInteger('Scanner','ScanBright',Def_ScanBright); ScanContrast := ini.ReadInteger('Scanner','ScanContrast',Def_ScanContrast); ScanImgShowMode := ini.ReadInteger('Scanner','ScanImgShowMode',Def_ScanImgShowMode); ScanImgSetUse := ini.ReadBool('Scanner','ScanImgSetUse',Def_ScanImgSetUse); //20101110 BA說掃瞄器廠商有調設定要新增此選項是否啟動 end; 'W':begin ini.WriteBool('DeviceDelete','Mode',DeviceDelete); ini.WriteInteger('DeviceDelete','Size_New',DeviceDeleteSize); ini.WriteBool('Scanner','Reverse',ScannerReverse); ini.WriteBool('Scanner','BoardClear',BoardClear); //ini.ReadInteger('Scanner','Dpi',ScanDpi); //ini.WriteBool('Scanner','Duplex',ScanDuplex); ini.WriteInteger('Scanner','ScanRotate',ScanRotate); ini.WriteBool('Scanner','ScanDeskew',ScanDeskew); ini.WriteInteger('Scanner','ScanBright',ScanBright); ini.WriteInteger('Scanner','ScanContrast',ScanContrast); ini.WriteInteger('Scanner','ScanImgShowMode',ScanImgShowMode); ini.WriteBool('Scanner','ScanImgSetUse',ScanImgSetUse); //20101110 BA說掃瞄器廠商有調設定要新增此選項是否啟動 end; end; finally ini.Free; end; end; Procedure TCB_IMGPSScanX.GetDefScanIni; //取得掃瞄的預設值 var i : Integer; PARA_NO,PARA_CONTENT: String; begin Def_DeviceDelete := True; Def_DeviceDeleteSize := 3072; //20120821 改成3000(出現) Def_ScannerReverse := False; Def_BoardClear := False; Def_ScanDpi := 300; Def_ScanDuplex := True; Def_ScanRotate := 0; Def_ScanDeskew := False; Def_ScanImgSetUse := False; Def_ScanBright := 0; Def_ScanContrast := 0; Def_ScanImgShowMode := 2; for i := 0 to WORK_INF_List.Count - 1 do begin IF GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_BLANKDEL_USE' Then //空白頁啟動 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_DeviceDelete := True Else Def_DeviceDelete := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_BLANKDEL_SIZE' Then //空白頁Size begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT = '' then Def_DeviceDeleteSize := 0 Else Def_DeviceDeleteSize := Strtoint(PARA_CONTENT); end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_REVERSE' Then //是否需反相 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_ScannerReverse := True Else Def_ScannerReverse := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_BOARDCLEAR' Then //是否清黑邊 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_BoardClear := True Else Def_BoardClear := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_DPI' Then //掃瞄DPI begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT = '' then Def_ScanDpi := 300 else Def_ScanDpi := Strtoint(PARA_CONTENT); end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_DUPLEX' Then //是否雙面掃瞄 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_ScanDuplex := True Else Def_ScanDuplex := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_ROTATE_MODE' Then //掃瞄時旋轉角度 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT = '0' then Def_ScanRotate := 0 Else if PARA_CONTENT = '1' then Def_ScanRotate := 270 Else if PARA_CONTENT = '2' then Def_ScanRotate := 180 Else if PARA_CONTENT = '3' then Def_ScanRotate := 90 Else Def_ScanRotate := 0; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_DESKEW' Then //是否傾斜矯正 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_ScanDeskew := True Else Def_ScanDeskew := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_IMGSET_USE' Then //是否使用亮度對比設定 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if UpperCase(PARA_CONTENT) ='Y' then Def_ScanImgSetUse := True else Def_ScanImgSetUse := False; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_BRIGHT' Then //亮度 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT ='' then Def_ScanBright := 0 Else Def_ScanBright := strtoint(PARA_CONTENT); if (Def_ScanBright > 255) or (Def_ScanBright < -255) then Def_ScanBright := 0; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_CONTRAST' Then //對比 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT ='' then Def_ScanContrast := 0 Else Def_ScanContrast := strtoint(PARA_CONTENT); if (Def_ScanContrast > 255) or (Def_ScanContrast < -255) then Def_ScanContrast := 0; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_SHOW_MODE' Then begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); if PARA_CONTENT = '0' then Def_ScanImgShowMode := 0 Else if PARA_CONTENT = '1' then Def_ScanImgShowMode := 1 Else if PARA_CONTENT = '2' then Def_ScanImgShowMode := 2 Else Def_ScanImgShowMode := 0; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'CASE_IN_TIME' Then //取進件截止時間 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); ScanDenialTime := PARA_CONTENT; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'SCAN_HINT' Then //掃描提示字串 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); ScanDenialHint := PARA_CONTENT; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'NO_SAVE_FORM_ID' Then //掃描不存檔之表單代號 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); NoSaveBarCodeList.CommaText := PARA_CONTENT; end Else if GetSQLData(WORK_INF_List,'PARA_NO',i) = 'LOCAL_PATH' Then //本機端路徑 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); ImagePath:= PARA_CONTENT; end Else if UpperCase(GetSQLData(WORK_INF_List,'PARA_NO',i)) = 'GUIDEFORMID' Then //當導引頁的表單 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); GuideFormIDList.CommaText := PARA_CONTENT; end Else if UpperCase(GetSQLData(WORK_INF_List,'PARA_NO',i)) = 'DIVPAGEFORMID' Then //當分案頁的表單 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); DivPageFormIDList.CommaText := PARA_CONTENT; end Else if UpperCase(GetSQLData(WORK_INF_List,'PARA_NO',i)) = 'FILE_COMPRESSION' Then //20171211 jpg to tif 壓縮比 begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); FJpgCompression := StrToInt(PARA_CONTENT); end Else if UpperCase(GetSQLData(WORK_INF_List,'PARA_NO',i)) = 'MAX_UPLOAD_SIZE' Then //取得 上傳大小的限制(MB) begin PARA_CONTENT := GetSQLData(WORK_INF_List,'PARA_CONTENT',i); FMaxUploadSize := PARA_CONTENT; end; end; ScanDuplex := Def_ScanDuplex; end; procedure TCB_IMGPSScanX.EnableImage(v:integer;Sender : TObject); var bmp : Tbitmap; begin DesableImage; bmp := TBitmap.Create; try ImageList3.GetBitmap(v,bmp); TBitBtn(Sender).Glyph.Assign(bmp); finally bmp.Free; end; ViewMouseMode(v); end; procedure TCB_IMGPSScanX.DesableImage; var bmp : Tbitmap; i : integer; begin NowClick := -1; bmp := Tbitmap.Create; try For i:= 0 to 6 do begin ImageList4.GetBitmap(i,bmp); TBitBtn(FindComponent('FC'+IntToStr(i))).Glyph.Assign(bmp); bmp.Width:=0; bmp.Handle:=0; end; finally bmp.Free; end; ViewMouseMode(NowClick); end; Procedure TCB_IMGPSScanX.DeleteImageFile(Path,FileName,CaseID:String); // 刪除檔案 (無法得到DocDir用) var i : Integer; FileList:TStringlist; DocDir : String; begin DeleteFile(Path+FileName); DocDir := Path2DocDir(Path,CaseID); //ShowMessage('DocDir='+DocDir); SetContextList('D',-1,CaseID,DocDir,FileName); {FileList:=TStringlist.Create; try if FileExists(Path+'Context.dat') then FileList.LoadFromFile(Path+'Context.dat'); for i := 0 to FileList.Count - 1 do begin if FileName = FileList.Strings[i] then begin FileList.Delete(i); FileList.SaveToFile(Path+'Context.dat'); Break; end; end; if FileList.Count = 0 then DeleteFile(Path+'Context.dat'); finally FileList.Free; end;} end; Function TCB_IMGPSScanX.DeleteDocNoFileForESCAN(Path,DocNo:String):Boolean; //刪除指定DocNo文件 var i,j,k: Integer; FName : String; ST1,ST2,ST3:TStringList; begin Result := False; //ShowMessage(DocNo); for i := ContextList.Count - 1 downto 0 do begin FName := ContextList.Strings[i]; If (DocNo = FormCode2DocNo(FileName2FormCode(FName))) or (DocNo=AttName) then begin if not ISExistImg(Path+'\'+FName) then begin DeleteFile(Path+'\'+FName); ContextList.Delete(i); end; Result := True; //有刪到指定文件 end; end; ContextList.SaveToFile(Path+'\Context.dat'); ContextList.LoadFromFile(Path+'\Context.dat'); if ContextList.Count=0 then begin _DelTree(Path); SetDocNoList('D',-1,NowCaseNo,NowDocDir,''); end; end; Function TCB_IMGPSScanX.DownLoadImage(Path,CaseID:String):Boolean; begin Result := True; if not GetftpInfo(CaseID,'download') then //取案件下載方式 begin DownFileErrStr := _Msg('取案件下載資訊失敗,')+HttpErrStr; Result := False; Exit; end; case TransMode of tsHttp: begin ShowText := _Msg('案件下載中(Http),請稍候'); DataLoading(True,True); If not Down_Img(ImageSavePath+FCaseID+'\Download\',FCaseID) then begin Showmessage(FCaseID+_msg('載入異動影像時,網路發生錯誤')+HttpErrStr); DataLoading(False,False); Exit; end; end; tsFtp: begin ShowText := _Msg('案件下載中(Ftp),請稍候'); DataLoading(True,True); SetFtpInfo; if not IIS_Ftp.FtpsConnect then begin DownFileErrStr := Format(_Msg('無法連上Ftp主機,錯誤原因:%s')+#13+'%s',[FtpErrReason,FTPSClient1.LastReceivedReply]); Result := False; Exit; end; if not IIS_Ftp.FtpsDownloadFile(FFtpExtraPath,CaseID+'.zip',Path+CaseID+'.zip',display1) then begin DownFileErrStr := Format(_Msg('錯誤原因:%s'),[FtpErrStr]); Result := False; Exit; end; ExecuteUnZip(Path+CaseID+'.zip',Path,False); DeleteFile(Path+CaseID+'.zip'); end; end; end; Procedure TCB_IMGPSScanX.CaseResort2Scanlist(Path:String); //案件的檔案重新排序給scanlist(次文件依FormID排) var i,n,v,v1 : Integer; S,S1 : TStringlist; FormID,OldName,NewName,DocNo,Doc_Type:String; x : Integer; begin S := TStringlist.Create; S1 := TStringlist.Create; try if FileExists(Path+'Context.dat') then S.LoadFromFile(Path+'Context.dat'); X := 0; for I := 1 to FORM_INF_List.Count - 1 do //在FormID有設定的 //主文件 照SQL排 20101028改 begin FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i); if FormCode2FileName(FormID,S) = '' then Continue; Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i); for n := 0 to S.Count - 1 do begin if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='1') then begin Inc(X); OldName := S.Strings[n]; //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編 NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編 S.Strings[n] := '*'+S.Strings[n]; S1.Add(OldName+','+NewName); end; end; end; for I := 0 to FORM_INF_List.Count - 1 do //次文件 照SQL排 20110512為了某個文件要先打的原因要求改 begin FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i); if FormCode2FileName(FormID,S) = '' then Continue; Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i); for n := 0 to S.Count - 1 do begin if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='2') then begin Inc(X); OldName := S.Strings[n]; //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編 NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); //從原有數量加1開始編 S.Strings[n] := '*'+S.Strings[n]; S1.Add(OldName+','+NewName); end; end; end; {for I := 0 to Doc_Inf_List.Count - 1 do //次文件 照文件代碼+掃瞄順序排 20101101改 20110512晚上又說改回來 begin DocNo := GetSQLData(Doc_Inf_List,'DOC_NO',i); Doc_Type := GetSQLData(Doc_Inf_List,'DOC_TYPE',i); for n := 0 to S.Count - 1 do begin if (S.Strings[n][1] <> '*') and (FormCode2DocNo(FileName2FormCode(S.Strings[n])) = DocNo) and (Doc_Type='2') then begin Inc(X); OldName := S.Strings[n]; NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編 S.Strings[n] := '*'+S.Strings[n]; S1.Add(OldName+','+NewName); end; end; end;} {for n := 0 to S.Count - 1 do //次文件 照掃瞄順序排 20101028改 begin for i := 0 to FORM_INF_List.Count - 1 do begin FormID := GetSQLData(FORM_INF_List,'T1.FORM_ID',i); Doc_Type := GetSQLData(FORM_INF_List,'T2.DOC_TYPE',i); if (S.Strings[n][1] <> '*') and (FileName2FormCode(S.Strings[n]) = FormID) and (Doc_Type='2') then begin Inc(X); OldName := S.Strings[n]; NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); //從原有數量加1開始編 S.Strings[n] := '*'+S.Strings[n]; S1.Add(OldName+','+NewName); end; end; end;} for i := 0 to S.Count - 1 do //FormID沒設定的或附件 begin if S.Strings[i][1] <> '*' then begin Inc(X); OldName := S.Strings[i]; //NewName := Add_Zoo(S.Count+x,3)+Copy(OldName,4,length(OldName)-3); NewName := Add_Zoo(S.Count+x,3)+FileName2NoQuene_Filename(OldName); S.Strings[i] := '*'+S.Strings[i]; S1.Add(OldName+','+NewName); end; end; S.Clear; for i := 0 to S1.Count - 1 do //開始轉換檔名 begin v := Pos(',',S1.Strings[i]); v1 := length(S1.Strings[i]); OldName := copy(S1.Strings[i],1,v-1); NewName := copy(S1.Strings[i],v+1,v1-v); //if FileExists(Path+OldName) then //begin //ReNameFile(Path+OldName,Path+NewName); S.Add(NewName); S.SaveToFile(Path+'scanlist.dat'); //end; end; ReSortFileName2Scanlist(Path); finally S.Free; S1.Free; end; end; Procedure TCB_IMGPSScanX.GetSelectImageFile; var i : Integer; FormID,FormName,DocNo : String; PreNode2Name : String; iFormID : String; iISBName : String; iISB : TImageScrollBox; begin NowSelectFileList.Clear; for i := 0 to ComponentCount -1 do begin if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then begin iISBName := ShapeName2PreViewISBName(TShape(Components[i])); iISB := TImageScrollBox(FindComponent(iISBName)); NowSelectFileList.Add(iISB.FileName); end; end; end; Procedure TCB_IMGPSScanX.ParserPoint(S:String); //解析十字點的字串 var PointList : TStringlist; Rect : TRect; begin PointList := TStringlist.Create; try PointList.Text := S; IF PointList.Count <> 6 Then begin UpLPoint := Str2Point('0,0'); UpRPoint := Str2Point('0,0'); DownLPoint := Str2Point('0,0'); DownRPoint := Str2Point('0,0'); Point_Width := '0'; Point_Height := '0'; end Else begin UpLPoint := Str2Point(PointList[0]); DownLPoint := Str2Point(PointList[1]); UpRPoint := Str2Point(PointList[2]); DownRPoint := Str2Point(PointList[3]); Point_Width := PointList[4]; Point_Height := PointList[5]; end; finally PointList.Free; end; end; Function TCB_IMGPSScanX.CheckScanDenialTime:Boolean; Var NowTime : String; begin NowTime := GetBalance2Time(Balance); NowTime := Copy(NowTime,1,2)+':'+Copy(NowTime,3,2)+':'+Copy(NowTime,5,2); Result := True; if ScanDenialTime <> '' then begin if StrtoTime(NowTime) >= StrtoTime(ScanDenialTime) then Result := False; end; end; procedure TCB_IMGPSScanX.initkscan; begin ScanDuplexCB.Enabled := False; if Scanner.IsConfigured then begin try Scanner.OpenSource; IF Scanner.DuplexCap > 0 Then begin ScanDuplexCB.Enabled := True; end; {IF Scanner.FEEDERCAP Then ScanFlatCB.Enabled := True; } Except DataLoading(False,True); Exit; end; Scanner.CloseSource; end; end; Function TCB_IMGPSScanX.CheckNeedCrop(Graphic:TDibGraphic):Boolean; //是否是A3要切影像 Var i,FormIDCount : Integer; begin Result := False; FormIDCount := 0; if (Graphic.Width > (4 * Graphic.XDotsPerInch)) {or (Graphic.Height > (15 * Graphic.YDotsPerInch))} then //if (Graphic.Width > (6 * Graphic.XDotsPerInch)) then begin for I := 1 to MpsBarcodeinf.Count do begin if (Length(MpsBarcodeinf.Text[i])=FormIDLength) and FormIDExists(MpsBarcodeinf.Text[i],False,0) then begin inc(FormIDCount); end; end; end; //ShowMessage('FormIDCount='+IntToStr(FormIDCount)+#10#13+'MpsBarcodeinf.count='+IntToStr(MpsBarcodeinf.count)); if FormIDCount = 2 then begin Result := True; end; end; Procedure TCB_IMGPSScanX.MoveImage(Path:String;mp:Integer); //移動頁數 var i,n,inx:Integer; FList,D_Flist:TStringlist; begin FList := TStringlist.Create; D_Flist := TStringlist.Create; try FList.LoadFromFile(Path+'Context.dat'); //Showmessage(Path); //Showmessage(Flist.Text); for i := 0 to FList.Count - 1 do begin Renamefile(Path+Flist.Strings[i],path+'@'+Flist.Strings[i]); Flist.Strings[i]:= '@'+Flist.Strings[i]; end; for i := 0 to ComponentCount -1 do begin if (Components[i] is TShape) and (copy(Components[i].Name,1,2)='SP') then begin inx := strtoint(Copy(TShape(Components[i]).Name,3,length(TShape(Components[i]).Name)-2)); D_Flist.Add(Flist.Strings[inx-1]); //Renamefile(Path+Flist.Strings[inx-1],path+'@'+Flist.Strings[inx-1]); end; end; //Showmessage('aa'); for i := 0 to D_Flist.Count -1 do begin for n := 0 to FList.Count - 1 do begin //if Flist.Strings[n]=StringReplace(D_Flist.Strings[i],'@','',[rfReplaceAll]) then if Flist.Strings[n]=D_Flist.Strings[i] then begin Flist.Delete(n); Break; end; end; end; //Showmessage('bb'); for i := 0 to D_Flist.Count - 1 do begin Flist.Insert(mp-1+i,D_Flist.Strings[i]); end; Flist.SaveToFile(Path+'Context.dat'); //Showmessage(Flist.Text); //Showmessage('CC'); ReSortFileName(Path); TreeView1click(self); finally FList.Free; D_Flist.Free; end; end; Function TCB_IMGPSScanX.FileName2ScanPage(FileName:String):Integer; //從檔名轉出掃瞄頁數 Var v : Integer; FName : String; begin FName := ExtractFileName(FileName); v := Pos('_',FName); if v = 0 then //附件 v := pos('.',FName); Result := Strtoint(Copy(FName,1,v-1)); end; Procedure TCB_IMGPSScanX.ReSortFileName2Scanlist(Path:String); //檔名重新排序給Scanlist.dat var i : Integer; OldName,NewName : String; S : TStringlist; begin S := TStringlist.Create; try if FileExists(Path+'scanlist.dat') then S.LoadFromFile(Path+'scanlist.dat'); for i := 0 to S.Count - 1 do begin OldName := S.Strings[i]; //NewName := Add_Zoo(i+1,3)+Copy(OldName,4,length(OldName)-3); NewName := Add_Zoo(i+1,3)+FileName2NoQuene_Filename(OldName); //ReNameFile(Path+OldName,Path+NewName); S.Strings[i] := NewName; end; S.SaveToFile(Path+'scanlist.dat'); finally S.Free; end; end; function TCB_IMGPSScanX.Get_imgdpi: WideString; begin end; function TCB_IMGPSScanX.Get_scancolor: WideString; begin end; procedure TCB_IMGPSScanX.Set_imgdpi(const Value: WideString); begin if Value ='' then begin FImgDPI := 300; ScanDpi := FImgDPI; end else begin FImgDPI := StrToInt(Value); ScanDpi := FImgDPI; Def_ScanDpi := FImgDPI; end; end; procedure TCB_IMGPSScanX.Set_scancolor(const Value: WideString); begin if value='' then begin FScanColor := 0; ScanColor := ifBlackWhite; end else begin FScanColor := StrToInt(Value); ScanColor := ifBlackWhite; end; if FScanColor = 1 then begin ScanColor := ifGray256 ; end; if FScanColor = 2 then begin ScanColor := ifTrueColor ; end; end;