curtis
22小時前 10220027159dc90f19f7c62a7b84bb00c6453d4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import * as fs from 'fs'; import * as path from 'path';
export function applyScanMixins(cls:any){
  cls.prototype.StatrTwainScan=function(){
    if(!this.Scanner.IsConfigured){this.ShowMessage(this._Msg('TWAIN 掃瞄驅動尚未安裝'));return;}
    let ScanInfo={MultiPage:true,ImageCount:0,Graphic:new this.TTiffGraphic()};
    try{this.ISB=null;this.Scanner.RequestedXDpi=this.ScanDpi;this.Scanner.RequestedYDpi=this.ScanDpi;this.Scanner.RequestedImageFormat=this.ScanColor;this.Scanner.ShowUI=this.TwainShowUI;
    try{this.Scanner.OpenSource();this.Scanner.Duplex=this.ScanDuplex;if(this.FMode==='SAMPLESCAN')this.Scanner.Duplex=false;if(this.ScanImgSetUse){this.Scanner.ScanBrightness=this.ScanBright;this.Scanner.ScanContrast=this.ScanContrast;}}catch(e){this.Showmessage(this._Msg('掃瞄器發生錯誤!!'));this.Scanner.CloseSource();return;}
    try{this.Scanner.AcquireWithSourceOpen(this.OnAcquire.bind(this),ScanInfo);}catch(e){this.Scanner.CloseSource();}}finally{this.Scanner.CloseSource();ScanInfo.Graphic.Free();}
  };
  cls.prototype.OnAcquire=function(DibHandle:any,XDpi:any,YDpi:any,CallBackData:any){ this.PageEnd(); this.PageDone(); };
  cls.prototype.PageDone=function(){
    this.ScanInfo.ImageCount++; let ISB;
    if(this.ScanMode==='smNew'){if(this.ScanImgShowMode===0||this.ScanImgShowMode===1){ISB=this.FindISB2View(this.VMode);ISB.AntiAliased=this.ScanImgShowMode===0;ISB.ZoomMode='zmFittopage';ISB.LoadFromFile(this.PEFileName,1);}}
    else if(this.ScanMode==='smReplace'){this.DisplayISB.LoadFromFile(this.PEFileName,1);}
    else if(this.ScanMode==='smInsert'||this.ScanMode==='smSample'){ISB=this.FindISB2View(this.VMode);ISB.ZoomMode='zmFittopage';ISB.LoadFromFile(this.PEFileName,1);}
  };
  cls.prototype.PageEnd=function(){
    if(this.ScanMode==='smNew'){
      this.ScanSaveFilename='';let FormID=this.BarCode2FormID();
      if(FormID!==''&&this.ISDivPageFormID(FormID))this.NowDivPageFormID=FormID;
      if(FormID!==''&&this.ISGuideFormID(FormID))this.NowGuideFormID=FormID;
      if(!this.FindDivFormCode(FormID)&&this.NowGuideFormID!=='')FormID=this.NowGuideFormID;
      let DocNo=this.FormCode2DocNo(FormID);
      if(FormID!==''&&this.FindDivFormCode(FormID)&&this.NowDivPageFormID!==''){
        this.ScanInfo.ImageCount=0;this.ClearView(1);this.ContextList.Clear();this.Context_DocnoList.Clear();this.ClearCaseIndex();this.ScanCaseno=this.BarCode2CaseID();this.NowGuideFormID='';this.NowDivPageFormID='';
      }
      if(this.ScanCaseno==='')this.ScanCaseno=this.GetNoNameCase(this.ImageSavePath);
      this.ImageSavePath=this.ImagePath;
      if(this.ScanInfo.ImageCount===0&&fs.existsSync(path.join(this.ImageSavePath,this.ScanCaseno))){this._DelTree(path.join(this.ImageSavePath,this.ScanCaseno));this.SetCaseList('D',-1,this.ScanCaseno);}
      this.ScanPath=path.join(this.ImageSavePath,this.ScanCaseno);this.Str2Dir(this.ScanPath);
      this.ScanDocDir=this.FindLastestDocDir(this.ScanCaseno,DocNo);
      if(this.DocNoNeedDiv(DocNo)){if((this.FormCode2Page(FormID)==='01'&&this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)>0)||this.ScanDocDir==='')this.ScanDocDir=this.DocNo2DocNoDir(path.join(this.ImageSavePath,this.ScanCaseno),DocNo);}
      else{this.ScanDocDir=DocNo!==''?DocNo:this.DocNo2DocNoDir(path.join(this.ImageSavePath,this.ScanCaseno),DocNo);}
      if(this.FirstDocDir==='')this.FirstDocDir=this.ScanDocDir;
      this.ScanPath=path.join(this.ImageSavePath,this.ScanCaseno,this.ScanDocDir);
      if(!fs.existsSync(this.ScanPath)&&this.ScanDocDir!==this.AttName)this.SetDocNoList('A',-1,this.ScanCaseno,this.ScanDocDir,'1');
      this.Str2Dir(this.ScanPath);
      this.ScanSaveFilename=FormID===''?this.Add_Zoo(this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)+1,3)+this.Ext:this.Add_Zoo(this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)+1,3)+'_'+FormID+this.Ext;
      if(!this.FindNoSaveBarCode()){if(this.ScanInfo.ImageCount===0){this.SetCaseList('A',-1,this.ScanCaseno);this.WriteCaseIndex(path.join(this.ImageSavePath,this.ScanCaseno));}this.SetContextList('A',-1,this.ScanCaseno,this.ScanDocDir,this.ScanSaveFilename);this.PEFileName=path.join(this.ScanPath,this.ScanSaveFilename);}
    } else if(this.ScanMode==='smReplace') {
      if(this.ScanInfo.ImageCount===0){fs.unlinkSync(path.join(this.ScanPath,this.ScanSaveFilename));this.PEFileName=path.join(this.ScanPath,this.ScanSaveFilename);}
    } else if(this.ScanMode==='smInsert') {
      this.ScanSaveFilename='';let FormID=this.BarCode2FormID();if(FormID!==''&&this.ISGuideFormID(FormID))this.NowGuideFormID=FormID;if(this.NowGuideFormID!=='')FormID=this.NowGuideFormID;
      let DocNo=this.FormCode2DocNo(FormID);this.ScanDocDir=this.FindLastestDocDir(this.ScanCaseno,DocNo);
      if(this.FMode==='ESCAN'&&this.FModeName===this._Msg('補件掃描'))this.ScanDocDir=this.FindLastestDocDirForPage(this.ScanCaseno,DocNo,FormID);
      if(this.DocNoNeedDiv(DocNo)){if((this.FormCode2Page(FormID)==='01'&&this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)>0)||this.ScanDocDir===''){this.ScanInfo.ImageCount=0;this.ScanDocDir=this.DocNo2DocNoDir(path.join(this.ImageSavePath,this.ScanCaseno),DocNo);}}
      else{this.ScanDocDir=DocNo!==''?DocNo:this.DocNo2DocNoDir(path.join(this.ImageSavePath,this.ScanCaseno),DocNo);}
      if(this.FirstDocDir==='')this.FirstDocDir=this.ScanDocDir;
      this.ScanPath=path.join(this.ImageSavePath,this.ScanCaseno,this.ScanDocDir);
      if(!fs.existsSync(this.ScanPath)&&this.ScanDocDir!=='Attach'&&this.ScanDocDir!=='S_Attach')this.SetDocNoList('A',-1,this.ScanCaseno,this.ScanDocDir,'1');
      this.Str2Dir(this.ScanPath);
      this.ScanSaveFilename=FormID===''?this.Add_Zoo(this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)+1,3)+this.Ext:this.Add_Zoo(this.GetDocDir_Page(this.ScanCaseno,this.ScanDocDir)+1,3)+'_'+FormID+this.Ext;
      this.SetContextList('A',-1,this.ScanCaseno,this.ScanDocDir,this.ScanSaveFilename);this.PEFileName=path.join(this.ScanPath,this.ScanSaveFilename);
    } else if(this.ScanMode==='smSample') {
      if(this.ScanInfo.ImageCount===0){fs.unlinkSync(path.join(this.ScanPath,this.ScanSaveFilename));this.PEFileName=path.join(this.ScanPath,this.ScanSaveFilename);let BarStr='';for(let i=1;i<=this.MpsBarCodeinf.Count;i++)BarStr+=this.MpsBarCodeinf.Text[i];this.Showmessage(this._Msg('辨識到的BarCode:\n')+BarStr);}
    }
  };
  cls.prototype.R_W_Scanini=function(m:string){
    let ini=new this.Tinifile(path.join(this.ScaniniPath,'FBScan.ini'));
    if(m==='R'){this.DeviceDelete=ini.ReadBool('DeviceDelete','Mode',this.Def_DeviceDelete);this.DeviceDeleteSize=ini.ReadInteger('DeviceDelete','Size_New',this.Def_DeviceDeleteSize);this.ScannerReverse=ini.ReadBool('Scanner','Reverse',this.Def_ScannerReverse);this.BoardClear=ini.ReadBool('Scanner','BoardClear',this.Def_BoardClear);this.ScanRotate=ini.ReadInteger('Scanner','ScanRotate',this.Def_ScanRotate);this.ScanDeskew=ini.ReadBool('Scanner','ScanDeskew',this.Def_ScanDeskew);this.ScanBright=ini.ReadInteger('Scanner','ScanBright',this.Def_ScanBright);this.ScanContrast=ini.ReadInteger('Scanner','ScanContrast',this.Def_ScanContrast);this.ScanImgShowMode=ini.ReadInteger('Scanner','ScanImgShowMode',this.Def_ScanImgShowMode);this.ScanImgSetUse=ini.ReadBool('Scanner','ScanImgSetUse',this.Def_ScanImgSetUse);}
    else if(m==='W'){ini.WriteBool('DeviceDelete','Mode',this.DeviceDelete);ini.WriteInteger('DeviceDelete','Size_New',this.DeviceDeleteSize);ini.WriteBool('Scanner','Reverse',this.ScannerReverse);ini.WriteBool('Scanner','BoardClear',this.BoardClear);ini.WriteInteger('Scanner','ScanRotate',this.ScanRotate);ini.WriteBool('Scanner','ScanDeskew',this.ScanDeskew);ini.WriteInteger('Scanner','ScanBright',this.ScanBright);ini.WriteInteger('Scanner','ScanContrast',this.ScanContrast);ini.WriteInteger('Scanner','ScanImgShowMode',this.ScanImgShowMode);ini.WriteBool('Scanner','ScanImgSetUse',this.ScanImgSetUse);}
    ini.Free();
  };
  cls.prototype.GetDefScanIni=function(){
    this.Def_DeviceDelete=true;this.Def_DeviceDeleteSize=3072;this.Def_ScannerReverse=false;this.Def_BoardClear=false;this.Def_ScanDpi=300;this.Def_ScanDuplex=true;this.Def_ScanRotate=0;this.Def_ScanDeskew=false;this.Def_ScanImgSetUse=false;this.Def_ScanBright=0;this.Def_ScanContrast=0;this.Def_ScanImgShowMode=2;
    for(let i=0;i<this.WORK_INF_List.Count;i++){
      let pn=this.GetSQLData(this.WORK_INF_List,'PARA_NO',i),pc=this.GetSQLData(this.WORK_INF_List,'PARA_CONTENT',i);
      if(pn==='SCAN_BLANKDEL_USE')this.Def_DeviceDelete=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_BLANKDEL_SIZE')this.Def_DeviceDeleteSize=pc===''?0:parseInt(pc);
      else if(pn==='SCAN_REVERSE')this.Def_ScannerReverse=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_BOARDCLEAR')this.Def_BoardClear=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_DPI')this.Def_ScanDpi=pc===''?300:parseInt(pc);
      else if(pn==='SCAN_DUPLEX')this.Def_ScanDuplex=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_ROTATE_MODE')this.Def_ScanRotate=pc==='1'?270:pc==='2'?180:pc==='3'?90:0;
      else if(pn==='SCAN_DESKEW')this.Def_ScanDeskew=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_IMGSET_USE')this.Def_ScanImgSetUse=pc.toUpperCase()==='Y';
      else if(pn==='SCAN_BRIGHT')this.Def_ScanBright=pc===''?0:parseInt(pc);
      else if(pn==='SCAN_CONTRAST')this.Def_ScanContrast=pc===''?0:parseInt(pc);
      else if(pn==='SCAN_SHOW_MODE')this.Def_ScanImgShowMode=pc==='0'?0:pc==='1'?1:2;
      else if(pn==='CASE_IN_TIME')this.ScanDenialTime=pc;
      else if(pn==='SCAN_HINT')this.ScanDenialHint=pc;
      else if(pn==='NO_SAVE_FORM_ID')this.NoSaveBarCodeList.CommaText=pc;
      else if(pn==='LOCAL_PATH')this.ImagePath=pc;
      else if(pn.toUpperCase()==='GUIDEFORMID')this.GuideFormIDList.CommaText=pc;
      else if(pn.toUpperCase()==='DIVPAGEFORMID')this.DivPageFormIDList.CommaText=pc;
      else if(pn.toUpperCase()==='FILE_COMPRESSION')this.FJpgCompression=parseInt(pc);
      else if(pn.toUpperCase()==='MAX_UPLOAD_SIZE')this.FMaxUploadSize=pc;
    }
    this.ScanDuplex=this.Def_ScanDuplex;
  };
  cls.prototype.EnableImage=function(v:number,s:any){this.DesableImage();let bmp=new this.TBitmap();this.ImageList3.GetBitmap(v,bmp);s.Glyph.Assign(bmp);bmp.Free();this.ViewMouseMode(v);};
  cls.prototype.DesableImage=function(){this.NowClick=-1;let bmp=new this.TBitmap();for(let i=0;i<=6;i++){this.ImageList4.GetBitmap(i,bmp);this.FindComponent('FC'+i).Glyph.Assign(bmp);bmp.Width=0;bmp.Handle=0;}bmp.Free();this.ViewMouseMode(this.NowClick);};
  cls.prototype.DeleteImageFile=function(p:string,f:string,c:string){if(fs.existsSync(path.join(p,f)))fs.unlinkSync(path.join(p,f));let d=this.Path2DocDir(p,c);this.SetContextList('D',-1,c,d,f);};
  cls.prototype.DeleteDocNoFileForESCAN=function(p:string,d:string){
    let r=false;
    for(let i=this.ContextList.Count-1;i>=0;i--){
      let f=this.ContextList.Strings[i];
      if(this.FormCode2DocNo(this.FileName2FormCode(f))===d||d===this.AttName){
        if(!this.ISExistImg(path.join(p,f))){fs.unlinkSync(path.join(p,f));this.ContextList.Delete(i);} r=true;
      }
    }
    this.ContextList.SaveToFile(path.join(p,'Context.dat'));this.ContextList.LoadFromFile(path.join(p,'Context.dat'));
    if(this.ContextList.Count===0){this._DelTree(p);this.SetDocNoList('D',-1,this.NowCaseNo,this.NowDocDir,'');} return r;
  };
  cls.prototype.DownLoadImage=function(p:string,c:string){return true;};
  cls.prototype.CaseResort2Scanlist=function(p:string){
    let S=new this.TStringlist(),S1=new this.TStringlist();if(fs.existsSync(path.join(p,'Context.dat')))S.LoadFromFile(path.join(p,'Context.dat'));
    let x=0;
    for(let i=1;i<this.FORM_INF_List.Count;i++){let fi=this.GetSQLData(this.FORM_INF_List,'T1.FORM_ID',i);if(this.FormCode2FileName(fi,S)==='')continue;let dt=this.GetSQLData(this.FORM_INF_List,'T2.DOC_TYPE',i);for(let n=0;n<S.Count;n++){if(S.Strings[n][0]!=='*'&&this.FileName2FormCode(S.Strings[n])===fi&&dt==='1'){x++;let on=S.Strings[n];let nn=this.Add_Zoo(S.Count+x,3)+this.FileName2NoQuene_Filename(on);S.Strings[n]='*'+S.Strings[n];S1.Add(`${on},${nn}`);}}}
    for(let i=0;i<this.FORM_INF_List.Count;i++){let fi=this.GetSQLData(this.FORM_INF_List,'T1.FORM_ID',i);if(this.FormCode2FileName(fi,S)==='')continue;let dt=this.GetSQLData(this.FORM_INF_List,'T2.DOC_TYPE',i);for(let n=0;n<S.Count;n++){if(S.Strings[n][0]!=='*'&&this.FileName2FormCode(S.Strings[n])===fi&&dt==='2'){x++;let on=S.Strings[n];let nn=this.Add_Zoo(S.Count+x,3)+this.FileName2NoQuene_Filename(on);S.Strings[n]='*'+S.Strings[n];S1.Add(`${on},${nn}`);}}}
    for(let i=0;i<S.Count;i++){if(S.Strings[i][0]!=='*'){x++;let on=S.Strings[i];let nn=this.Add_Zoo(S.Count+x,3)+this.FileName2NoQuene_Filename(on);S.Strings[i]='*'+S.Strings[i];S1.Add(`${on},${nn}`);}}
    S.Clear();for(let i=0;i<S1.Count;i++){let v=S1.Strings[i].indexOf(',');let nn=S1.Strings[i].substring(v+1);S.Add(nn);S.SaveToFile(path.join(p,'scanlist.dat'));}
    this.ReSortFileName2Scanlist(p);S.Free();S1.Free();
  };
  cls.prototype.GetSelectImageFile=function(){this.NowSelectFileList.Clear();for(let i=0;i<this.ComponentCount;i++){if(this.Components[i] instanceof this.TShape&&this.Components[i].Name.startsWith('SP')){let isn=this.ShapeName2PreViewISBName(this.Components[i]);let isb=this.FindComponent(isn);this.NowSelectFileList.Add(isb.FileName);}}};
  cls.prototype.ParserPoint=function(s:string){let p=new this.TStringlist();p.Text=s;if(p.Count!==6){this.UpLPoint={X:0,Y:0};this.UpRPoint={X:0,Y:0};this.DownLPoint={X:0,Y:0};this.DownRPoint={X:0,Y:0};this.Point_Width='0';this.Point_Height='0';}else{this.UpLPoint=this.Str2Point(p.Strings[0]);this.DownLPoint=this.Str2Point(p.Strings[1]);this.UpRPoint=this.Str2Point(p.Strings[2]);this.DownRPoint=this.Str2Point(p.Strings[3]);this.Point_Width=p.Strings[4];this.Point_Height=p.Strings[5];}p.Free();};
  cls.prototype.CheckScanDenialTime=function(){let nt=this.GetBalance2Time(this.Balance);nt=nt.substring(0,2)+':'+nt.substring(2,4)+':'+nt.substring(4,6);let r=true;if(this.ScanDenialTime!=='')if(this.StrtoTime(nt)>=this.StrtoTime(this.ScanDenialTime))r=false;return r;};
  cls.prototype.initkscan=function(){this.ScanDuplexCB.Enabled=false;if(this.Scanner.IsConfigured){try{this.Scanner.OpenSource();if(this.Scanner.DuplexCap>0)this.ScanDuplexCB.Enabled=true;}catch(e){this.DataLoading(false,true);return;}this.Scanner.CloseSource();}};
  cls.prototype.CheckNeedCrop=function(g:any){let fc=0;if(g.Width>(4*g.XDotsPerInch)){for(let i=1;i<=this.MpsBarcodeinf.Count;i++)if(this.MpsBarcodeinf.Text[i].length===this.FormIDLength&&this.FormIDExists(this.MpsBarcodeinf.Text[i],false,0))fc++;}return fc===2;};
  cls.prototype.MoveImage=function(p:string,m:number){let fl=new this.TStringlist(),df=new this.TStringlist();fl.LoadFromFile(path.join(p,'Context.dat'));for(let i=0;i<fl.Count;i++){fs.renameSync(path.join(p,fl.Strings[i]),path.join(p,'@'+fl.Strings[i]));fl.Strings[i]='@'+fl.Strings[i];}for(let i=0;i<this.ComponentCount;i++){if(this.Components[i] instanceof this.TShape&&this.Components[i].Name.startsWith('SP')){let inx=parseInt(this.Components[i].Name.substring(2));df.Add(fl.Strings[inx-1]);}}for(let i=0;i<df.Count;i++){for(let n=0;n<fl.Count;n++)if(fl.Strings[n]===df.Strings[i]){fl.Delete(n);break;}}for(let i=0;i<df.Count;i++)fl.Insert(m-1+i,df.Strings[i]);fl.SaveToFile(path.join(p,'Context.dat'));this.ReSortFileName(p);this.TreeView1Click(this);fl.Free();df.Free();};
  cls.prototype.FileName2ScanPage=function(f:string){let n=path.basename(f),v=n.indexOf('_');if(v===-1)v=n.indexOf('.');return parseInt(n.substring(0,v));};
  cls.prototype.ReSortFileName2Scanlist=function(p:string){let s=new this.TStringlist();if(fs.existsSync(path.join(p,'scanlist.dat')))s.LoadFromFile(path.join(p,'scanlist.dat'));for(let i=0;i<s.Count;i++)s.Strings[i]=this.Add_Zoo(i+1,3)+this.FileName2NoQuene_Filename(s.Strings[i]);s.SaveToFile(path.join(p,'scanlist.dat'));s.Free();};
  cls.prototype.Get_imgdpi=function(){return this.FImgDPI.toString();};cls.prototype.Get_scancolor=function(){return this.FScanColor.toString();};cls.prototype.Set_imgdpi=function(v:string){this.FImgDPI=v===''?300:parseInt(v);this.ScanDpi=this.FImgDPI;this.Def_ScanDpi=this.FImgDPI;};cls.prototype.Set_scancolor=function(v:string){this.FScanColor=v===''?0:parseInt(v);this.ScanColor=this.FScanColor===2?'ifTrueColor':(this.FScanColor===1?'ifGray256':'ifBlackWhite');};
}