import * as fs from 'fs'; import * as path from 'path';
|
export enum TTransMode{tsHttp,tsFtp,tsNone} export enum TFtpProtocol{fpftp,fpftps} export type TImageFormat='ifBlackWhite'|'ifGray256'|'ifTrueColor'|'ifColor256';
|
export class TStringList {
|
Strings:string[]=[]; get Count(){return this.Strings.length;}
|
Add(s:string){this.Strings.push(s);} Clear(){this.Strings=[];}
|
LoadFromFile(fp:string){if(fs.existsSync(fp))this.Strings=fs.readFileSync(fp,'utf8').split(/\r?\n/).filter(Boolean);}
|
SaveToFile(fp:string){fs.writeFileSync(fp,this.Strings.join('\n'),'utf8');}
|
Delete(idx:number){this.Strings.splice(idx,1);} Insert(idx:number,s:string){this.Strings.splice(idx,0,s);}
|
IndexOf(s:string){return this.Strings.indexOf(s);} get Text(){return this.Strings.join('\n');}
|
set Text(v:string){this.Strings=v.split('\n');} get CommaText(){return this.Strings.join(',');}
|
set CommaText(v:string){this.Strings=v.split(',');} Free(){} Sort(){this.Strings.sort();} Assign(s:TStringList){this.Strings=[...s.Strings];}
|
}
|
export function applyUtilsMixins(cls:any){
|
cls.prototype.GetCurrentVersionNo=function(){return "1.0.0";};
|
cls.prototype.DefinePropertyPages=function(){};
|
cls.prototype.InitExistImgList=function(cp:string){
|
let ST1=new TStringList(); this.ExistImgList.Clear();
|
ST1.LoadFromFile(path.join(cp,'Download','Context.dat'));
|
for(let i=0;i<ST1.Count;i++){ let m=this.LoadFileGetMD5(path.join(cp,'Download',ST1.Strings[i])); this.LogFile1.LogToFile(this.logTimeString()+path.join(cp,'Download',ST1.Strings[i])+',MD5='+m); this.ExistImgList.Add(m); }
|
this.LogFile1.LogToFile(this.logTimeString()+'ExistImgList.text'+this.ExistImgList.CommaText); ST1.Free();
|
};
|
cls.prototype.Initialize=function(){
|
['Activate','Click','Create','DblClick','Deactivate','Destroy','KeyPress','MouseEnter','MouseLeave','Paint'].forEach(e=>this['On'+e]=this[e+'Event']?this[e+'Event'].bind(this):null);
|
this.MpsKey='fbim';this.Seg=3;this.Ext='.tif';this.SafePixel=20;this.CaseIDLength=16;this.FormIDLength=15;this.Bt=4;this.CropBarcode='CC';
|
};
|
cls.prototype.ISB1Enter=function(){this.ISB1.SetFocus();};
|
cls.prototype._Set_Font=function(v:any){this.Font=v;};
|
['Active','AlignDisabled','AlignWithMargins','AutoScroll','AutoSize','AxBorderStyle','Caption','Color','DockSite','DoubleBuffered','DropTarget','Enabled','ExplicitHeight','ExplicitLeft','ExplicitTop','ExplicitWidth','Font','HelpFile','KeyPreview','MouseInClient','ParentCustomHint','ParentDoubleBuffered','PixelsPerInch','PopupMode','PrintScale','Scaled','ScreenSnap','SnapBuffer','UseDockManager','Visible','VisibleDockClientCount'].forEach(p=>{
|
cls.prototype['Get_'+p]=function(){return this[p];}; cls.prototype['Set_'+p]=function(v:any){this[p]=v;};
|
});
|
cls.prototype.LoadFileGetMD5=function(f:string){return "md5stub";};
|
cls.prototype.ISExistImg=function(f:string){return this.ExistImgList.IndexOf(this.LoadFileGetMD5(f))!==-1;};
|
cls.prototype.MemoInfoTransfer=function(m:string,s:string,id:TStringList,n:TStringList){
|
if(m==='ID'){for(let i=0;i<id.Count;i++)if(s===id.Strings[i])return n.Strings[i]; return '自行輸入';}
|
if(m==='NAME'){for(let i=0;i<n.Count;i++)if(s===n.Strings[i])return id.Strings[i]; return '00';} return '';
|
};
|
cls.prototype.SetSQLData=function(c:string,f:TStringList,t:TStringList){t.Clear();t.Add(c);for(let i=1;i<f.Count;i++)t.Add(f.Strings[i]);};
|
cls.prototype.GetSQLData=function(t:TStringList,c:string,no:number){
|
if(t.Count===0||no>=t.Count)return''; let cs=t.Strings[0].split(','),ts=t.Strings[no],ds=ts.split('!@!');
|
let idx=cs.indexOf(c); return(idx!==-1&&idx<ds.length)?ds[idx]:'';
|
};
|
cls.prototype.FindSQLData=function(t:TStringList,c:string,kc:string,ks:string,no:number,res:TStringList){
|
res.Clear(); if(!ks||t.Count<=1)return false;
|
let cl=c.split(','),kcl=kc.split(','),kl=ks.split(','),fidx=-1,found=false;
|
if(no===0){for(let i=1;i<t.Count;i++){let m=true;for(let n=0;n<kcl.length;n++)if(this.GetSQLData(t,kcl[n],i)!==kl[n]){m=false;break;}if(m){found=true;fidx=i;break;}}}
|
else{let m=true;for(let n=0;n<kcl.length;n++)if(t.Strings[no].indexOf('!@!'+kl[n]+'!@!')===-1){m=false;break;}if(m){found=true;fidx=no;}}
|
if(found)cl.forEach(co=>res.Add(co+','+this.GetSQLData(t,co,fidx))); return found;
|
};
|
cls.prototype.GetFindResult=function(c:string){for(let i=0;i<this.FindResult.Count;i++){let s=this.FindResult.Strings[i],idx=s.indexOf(',');if(idx>-1&&c===s.substring(0,idx))return s.substring(idx+1);}return'';};
|
cls.prototype.FileName2FormCode=function(f:string){let b=path.basename(f),v=b.indexOf('_'),v1=b.lastIndexOf('.');return(v>-1&&v1>v)?b.substring(v+1,v1):'';};
|
cls.prototype.FormCode2DocNo=function(fc:string){for(let i=0;i<this.FormID_List.Count;i++)if(this.FormID_List.Strings[i]===fc)return this.DocNo_List.Strings[i];return fc?fc.substring(0,8):'';};
|
cls.prototype.FormCode2Version=function(fc:string){return fc.substring(10,15);};
|
cls.prototype.FormCode2Page=function(fc:string){return fc.substring(8,10);};
|
cls.prototype.DocNoDir2DocNo=function(d:string){if(d!=='Attach'&&d!=='S_Attach'){let v=d.indexOf('(');if(v>0)return d.substring(0,v);}return d;};
|
cls.prototype.DocNo2DocNoDir=function(p:string,d:string){if(!d)return this.AttName;let i=0,id='';do{i++;id=d+'('+i+')';}while(fs.existsSync(path.join(p,id)));return id;};
|
cls.prototype.Add_Zoo=function(n:number,l:number){return n.toString().padStart(l,'0');};
|
cls.prototype.Str2Dir=function(p:string){if(!fs.existsSync(p))fs.mkdirSync(p,{recursive:true});};
|
cls.prototype._DelTree=function(p:string){if(fs.existsSync(p))fs.rmSync(p,{recursive:true,force:true});};
|
}
|