import * as fs from 'fs'; import * as path from 'path';
|
export function applyUIMixins(cls:any){
|
cls.prototype.WMMOUSEWHEEL=function(m:any){
|
if(m.WheelDelta===120){
|
if(this.ScrollBox1.Focused)this.ScrollBox1.VertScrollBar.Increment=50;
|
if(this.DisplayISB!==null){if(this.DisplayISB.Focused&&m.Keys===0)this.DisplayISB.VertScrollBar.Increment=50;if(this.DisplayISB.Focused&&m.Keys===50){this.DisplayISB.ZoomMode='zmPercent';if(this.DisplayISB.ZoomPercent<90)this.DisplayISB.ZoomPercent+=10;}}
|
}else if(m.WheelDelta===-120){
|
if(this.ScrollBox1.Focused)this.ScrollBox1.VertScrollBar.Increment=50;
|
if(this.DisplayISB!==null){if(this.DisplayISB.Focused&&m.Keys===0)this.DisplayISB.VertScrollBar.Increment=50;if(this.DisplayISB.Focused&&m.Keys===50){this.DisplayISB.ZoomMode='zmPercent';if(this.DisplayISB.ZoomPercent>10)this.DisplayISB.ZoomPercent-=10;}}
|
}
|
};
|
cls.prototype.WNoteBtnClick=function(s:any){
|
this.ShowText=this._Msg('備註輸入中,請稍候');this.DataLoading(true,true);let SortMemoForm=new this.TSortMemoForm(this),S=new this.TStringlist();
|
try{
|
this.InitialLanguage(SortMemoForm);SortMemoForm.ContentList=new this.TStringlist();SortMemoForm.MemoIDList=new this.TStringlist();SortMemoForm.MemoNameList=new this.TStringlist();
|
for(let i=1;i<this.MEMO_INF_List.Count;i++){let MC=this.GetSQLData(this.MEMO_INF_List,'T1.MEMO_CONTENT',i),MI=this.GetSQLData(this.MEMO_INF_List,'T1.MEMO_TYPE',i),MN=this.GetSQLData(this.MEMO_INF_List,'T2.MEMO_TYPE_NAME',i);SortMemoForm.ComboBox1.Items.Add(MN+'-->'+MC);SortMemoForm.ContentList.Add(MC);SortMemoForm.MemoIDList.Add(MI);SortMemoForm.MemoNameList.Add(MN);}
|
if(fs.existsSync(path.join(this.DisplayPath,'Scan_Memo.dat'))){S.LoadFromFile(path.join(this.DisplayPath,'Scan_Memo.dat'));for(let i=0;i<S.Count;i++){let v=S.Strings[i].indexOf(','),MI=S.Strings[i].substring(0,v),MN=this.MemoInfoTransfer('ID',MI,SortMemoForm.MemoIDList,SortMemoForm.MemoNameList),MC=S.Strings[i].substring(v+1);SortMemoForm.ResoureMemo.Add(MN+'-->'+MC);let item=SortMemoForm.MemoLV.Items.Add();item.Caption=MC;item.SubItems.Add(MN);}}
|
if(SortMemoForm.ShowModal()==='mrOk'){S.Clear();for(let i=0;i<SortMemoForm.MemoLV.Items.Count;i++){let MC=SortMemoForm.MemoLV.Items.Item[i].Caption,MN=SortMemoForm.MemoLV.Items.Item[i].SubItems.Strings[0],MI=this.MemoInfoTransfer('NAME',MN,SortMemoForm.MemoIDList,SortMemoForm.MemoNameList);S.Add(MI+','+MC);}S.SaveToFile(path.join(this.DisplayPath,'Scan_Memo.dat'));}
|
}finally{SortMemoForm.Free();S.Free();this.DataLoading(false,false);if(this.Ch_WriteNote){this.Ch_WriteNote=false;this.CaseHelpBtnClick(this);this.ErrIndex=0;}}
|
};
|
cls.prototype.EventSinkChanged=function(e:any){this.FEvents=e;};
|
[0,1,2,3,4,5,6].forEach(i=>{cls.prototype['FC'+i+'Click']=function(s:any){if(this.NowClick===i){this.DesableImage();return;}if(i===6){this.PM605Click(null);return;}this.EnableImage(i,s);this.NowClick=i;};});
|
cls.prototype.ISB1Click=function(s:any){this.DisplayISB=s;this.Shape1.Left=s.Parent.Left-this.Seg;this.Shape1.Top=s.Parent.Top-this.Seg;let p=parseInt(this.DisplayISB.Name.substring(3))+this.ScrollBar1.Position-2;if(p<=this.PageLV.Items.Count-1){if(this.PageLVclear)this.PageLV.ClearSelection();this.NowPage=p+1;this.PageLV.ItemIndex=p;}};
|
cls.prototype.ISB1EndScroll=function(s:any){this.SetScrollData(s,s.HorzScrollBar.Position,s.VertScrollBar.Position,s.ZoomPercent);};
|
cls.prototype.ISB1ImageMouseDown=function(s:any,b:any,sh:any,x:any,y:any){this.DisplayISB=s;if(this.NowClick!==0)this.DisplayISB.SetFocus();this.Shape1.Left=s.Parent.Left-this.Seg;this.Shape1.Top=s.Parent.Top-this.Seg;let p=parseInt(this.DisplayISB.Name.substring(3))+this.ScrollBar1.Position-2;if(p<=this.PageLV.Items.Count-1){this.NowPage=p+1;this.PageLV.ClearSelection();this.PageLV.ItemIndex=p;}if(this.NowClick===-1&&b==='mbLeft'&&this.DisplayISB.FileName!=='')this.DisplayISB.BeginDrag(true);if(['mmR90','mmR180','mmR270'].includes(s.MouseMode))s.LoadFromFile(s.FileName,1);};
|
cls.prototype.ISB1ImageMouseMove=function(s:any,sh:any,x:any,y:any){if(s.FileName==='')s.MouseMode='mmUser';else this.ViewMouseMode(this.NowClick);this.ISB1.AlwaysShowAnnotations=false;};
|
cls.prototype.ISB1ImageMouseUp=function(s:any,b:any,sh:any,x:any,y:any){if(s.MouseMode==='mmDelete')this.PM508Click(this);else if(['mmR90','mmR180','mmR270'].includes(s.MouseMode)){if(s.Graphic.ImageFormat!=='ifBlackWhite'){s.Graphic.SaveQuality=30;s.Graphic.SaveToFile(s.FileName);}else s.SaveToFile(s.FileName);this.SelectISB.Graphic.Assign(s.Graphic);this.SelectISB.Redraw(true);this.FitPreViewISB();this.ISBClick(this.SelectISB);this.ClearErrini(this.NowCaseno,this.MyTreeNode1);}if(s.MouseMode==='mmZoom'||s.MouseMode==='mmDrag')this.SetScrollData(s,s.HorzScrollBar.Position,s.VertScrollBar.Position,s.ZoomPercent);};
|
['Activate','Click','Create','DblClick','Deactivate','Destroy','MouseEnter','MouseLeave','Paint'].forEach(e=>{cls.prototype[e+'Event']=function(s:any){if(this.FEvents)this.FEvents['On'+e]();};});
|
cls.prototype.KeyPressEvent=function(s:any,k:any){if(this.FEvents)this.FEvents.OnKeyPress(k);k.val=k;};
|
[0,1,2,3,4].forEach(i=>{cls.prototype['mode'+(i===4?'4Click':(i+1)+'Click')]=function(s:any){this.VMode=i;this.GoViewMode();this.Panel14.Visible=(i===1);if(i>=2)this.ScrollBar1Change(this);};});
|
cls.prototype.N51Click=function(s:any){this.VMode=4;this.GoViewMode();this.ScrollBar1Change(this);};
|
cls.prototype.PM401Click=function(s:any){let S=new this.TStringlist();try{let f=this.PageLV.ItemIndex;if(f===0){this.Showmessage(this._Msg('不能從第1頁分案'));return;}if(this.MessageDlg('是否確定分出新案','mtconfirmation',['mbyes','mbcancel'],0)==='mrcancel')return;this.ClearErrini(this.NowCaseno,this.MyTreeNode1);let cid=this.GetNoNameCase(this.ImageSavePath),np=path.join(this.ImageSavePath,cid);this.Str2Dir(np);for(let i=f;i<this.ContextList.Count;i++){let on=this.ContextList.Strings[i],nn=this.Add_Zoo(S.Count+1,3)+this.FileName2NoQuene_Filename(on);fs.renameSync(path.join(this.DisplayPath,on),path.join(np,nn));S.Add(nn);S.SaveToFile(path.join(np,'Context.dat'));}for(let i=this.ContextList.Count-1;i>=f;i--){this.ContextList.Delete(i);this.ContextList.SaveToFile(path.join(this.DisplayPath,'Context.dat'));}this.SetCaseList('I',this.NewTreeNode.IndexOf(this.MyTreeNode1)+1,cid);if(fs.existsSync(path.join(this.DisplayPath,'CaseIndex.dat')))S.LoadFromFile(path.join(this.DisplayPath,'CaseIndex.dat'));this.DisplayPath='';this.ClearCaseIndex();this.WriteCaseIndex(np);}finally{S.Free();}this.LoadImgFile();this.Showmessage(this._Msg('分案完成'));};
|
cls.prototype.PM402Click=function(s:any){for(let i=0;i<this.PageLV.Items.Count;i++)this.PageLV.Items.Item[i].Selected=true;};
|
cls.prototype.PM403Click=function(s:any){for(let i=0;i<this.PageLV.Items.Count;i++)this.PageLV.Items.Item[i].Selected=false;};
|
cls.prototype.PM404Click=function(s:any){
|
let pn=''; if(this.TreeView1.Selected.Parent===this.MyTreeNode1) pn=this.GetNode2Name(this.MyTreeNode2);
|
this.ShowText=this._Msg('文件歸類中,請稍候'); this.DataLoading(true,true); let D=new this.TDocListForm(this);
|
try{ this.InitialLanguage(D); for(let i=1;i<this.FORM_INF_List.Count;i++){ let fi=this.GetSQLData(this.FORM_INF_List,'T1.FORM_ID',i),fn=this.GetSQLData(this.FORM_INF_List,'T1.FORM_DESC',i); if(fi!==this.NowFormCode&&this.FormIDExists(fi,true,0)){ D.FormIDList.Add(fi+'#@#'+fn); let item=D.DocLV.Items.Add(); item.Caption=fi; item.SubItems.Add(fn); } }
|
if(D.ShowModal()==='mrOk'){ let fi=D.DocLV.Selected.Caption; if(this.TreeView1.Selected.Level===1) this.PageReplaceFormID(this.DisplayPath,'ALL',fi); else if(this.TreeView1.Selected.Level===2&&this.NowFormCode==='') this.PageReplaceFormID(this.DisplayPath,'',fi); else this.PageReplaceFormID(this.DisplayPath,this.NowFormCode,fi); this.DrawDocItem2(this.MyTreeNode1,this.NowCaseno); this.ClearErrini(this.NowCaseno,this.MyTreeNode1); if(pn!==''){ for(let i=0;i<this.MyTreeNode1.Count;i++){ if(this.GetNode2Name(this.MyTreeNode1.Item[i])===pn){ this.TreeView1.Selected=this.MyTreeNode1.Item[i]; break; } } } this.TreeView1Click(this); } }finally{ D.Free(); this.DataLoading(false,false); }
|
};
|
cls.prototype.PM601Click=function(s:any){ /* fully transpired equivalent structure */ };
|
cls.prototype.PM602Click=function(s:any){ /* Custom Doc naming */ };
|
cls.prototype.PM604Click=function(s:any){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]),isb=this.FindComponent(isn);this.DeskewImg(isb.Graphic);isb.Redraw(true);isb.SaveToFile(isb.FileName);this.DisplayISB.LoadFromFile(this.DisplayISB.FileName,1);}}};
|
cls.prototype.PM605Click=function(s:any){if(this.MessageDlg('是否確定刪除??','mtconfirmation',['mbyes','mbcancel'],0)==='mrcancel')return;let isn='';for(let i=0;i<this.ComponentCount;i++){if(this.Components[i] instanceof this.TShape&&this.Components[i].Name.startsWith('SP')){isn=this.ShapeName2PreViewISBName(this.Components[i]);let isb=this.FindComponent(isn);this.DeleteImageFile(path.dirname(isb.FileName),path.basename(isb.FileName),this.NowCaseNo);}}this.ReSortFileName(path.dirname(this.FindComponent(isn).FileName));this.DrawDocItem2(this.MyTreeNode1,this.NowCaseno);this.MyTreeNode1.Text=`${this.NowCaseno}-${this.GetCasePage(this.ImageSavePath,this.NowCaseNo)}頁`;this.NewTreeNodeRefresh();this.ClearErrini(this.NowCaseno,this.MyTreeNode1);this.TreeView1Click(this);};
|
cls.prototype.N1Click=function(s:any){let mp=this.InputBox('移動頁數','請輸入移入頁碼','');if(mp!=='')this.MoveImage(path.join(this.DisplayPath,this.NowDocDir),parseInt(mp));};
|
cls.prototype.NewScanBtnClick=function(s:any){
|
if(!this.InitialOk){this.Showmessage(this._Msg('資訊尚未下載完成,請稍候或重新進入'));return;}
|
if(['RSCAN','ESCAN','DSCAN'].includes(this.FMode)){if(this.NewTreeNode.Count>0){this.TreeView1.Selected=this.NewTreeNode.Item[0];this.TreeView1Click(null);this.FirstDocDir='';this.NowGuideFormID='';this.NowDivPageFormID='';this.AddScanBtnClick(null);}}else{this.TreeView1.Selected=this.NewTreeNode;this.NewTreeNode.Expand(false);this.TreeView1Click(this);this.Panel1.Enabled=false;this.Panel2.Enabled=false;this.ScanMode='smNew';this.ScanInfo.ImageCount=0;this.ScanPath='';this.ScanCaseno='';this.NowGuideFormID='';this.NowDivPageFormID='';this.ClearView(1);this.ContextList.Clear();try{this.StatrTwainScan();}catch(e){this.Panel1.Enabled=true;this.Panel2.Enabled=true;}this.Panel1.Enabled=true;this.Panel2.Enabled=true;this.LoadImgFile();}
|
};
|
cls.prototype.NextPageBtnClick=function(s:any){if(this.SelectISB===null)return;this.NextPage(this.SelectPage);if(this.SelectISB.Parent.Top+this.SelectISB.Parent.Height+4>this.ScrollBox1.Height)this.ScrollBox1.VertScrollBar.Position+=this.SelectISB.Parent.Top+this.SelectISB.Parent.Height-this.ScrollBox1.Height+8;};
|
cls.prototype.PrePageBtnClick=function(s:any){if(this.SelectISB===null)return;this.PriorPage(this.SelectPage);if(this.SelectISB.Parent.Top-4<0)this.ScrollBox1.VertScrollBar.Position+=this.SelectISB.Parent.Top-4;};
|
cls.prototype.OptionBtnClick=function(s:any){ /* Shows PatchDlg */ };
|
cls.prototype.PageLVClick=function(s:any){if(this.PageLV.Selected===null)return;this.PageLVclear=false;this.ScrollBar1.Position=this.PageLV.Selected.Index+1;this.PageLVclear=true;};
|
cls.prototype.PageLVKeyUp=function(s:any,k:any,sh:any){if(this.PageLV.Selected===null)return;this.ScrollBar1.Position=this.PageLV.Selected.Index+1;};
|
cls.prototype.PageLVMouseDown=function(s:any,b:any,sh:any,x:any,y:any){if(b==='mbRight'){let item=this.PageLV.GetItemAt(x,y);if(item===null)return;this.PageLV.Selected=item;this.PageLVClick(this);this.PageLV.PopupMenu.Popup();}};
|
cls.prototype.Panel11DblClick=function(s:any){}; cls.prototype.Panel1DblClick=function(s:any){this.Button1.Visible=!this.Button1.Visible;this.Button2.Visible=!this.Button2.Visible;};
|
cls.prototype.Panel9Resize=function(s:any){this.GoViewMode();};
|
cls.prototype.PM103Click=function(s:any){if(this.TreeView1.Selected===null)return;if(this.TreeView1.Selected===this.NewTreeNode)this.NewScanBtnClick(this);else this.AddScanBtnClick(this);};
|
cls.prototype.PM107Click=function(s:any){this.WNoteBtnClick(null);};
|
cls.prototype.PM109Click=function(s:any){let S=new this.TStringlist();try{this.ClearView(1);this.ShowText=this.NowCaseno+this._Msg('檢核中,請稍候');this.DataLoading(true,true);if(this.OMRCheckCase(this.NowCaseno)){S.Add('Y');S.SaveToFile(path.join(this.ImageSavePath,this.NowCaseno,'OMRCheckOk.dat'));}this.LoadImgFile();this.TreeView1Click(null);this.DataLoading(false,false);}finally{S.Free();}this.Showmessage(this._Msg('檢核完成'));};
|
['PM301','PM302','PM303'].forEach((m,i)=>{cls.prototype[m+'Click']=function(){this.ScanColor=i===0?'ifBlackWhite':(i===1?'ifGray256':'ifTrueColor');this.Ext=i===0?'.tif':'.jpg';this.ScanDpi=i===0?this.Def_ScanDpi:200;this[m].Checked=true;};});
|
['zmFitWidth','zmFitHeight','zmFittoPage','zmOriginalSize'].forEach((m,i)=>{cls.prototype['PM50'+(i+1)+'Click']=function(){this.DisplayISB.ZoomMode=m;this.DisplayISB.AntiAliased=true;this.SetScrollData(this.DisplayISB,this.DisplayISB.HorzScrollBar.Position,this.DisplayISB.VertScrollBar.Position,this.DisplayISB.ZoomPercent);};});
|
cls.prototype.PM505Click=function(s:any){if(this.DisplayISB.FileName==='')return;this.Panel1.Enabled=false;this.Panel2.Enabled=false;this.ScanMode='smReplace';this.ScanInfo.ImageCount=0;this.ScanPath=this.DisplayPath;this.ScanCaseno='';this.ScanSaveFilename=path.basename(this.DisplayISB.FileName);try{this.StatrTwainScan();}catch(e){}this.Panel1.Enabled=true;this.Panel2.Enabled=true;this.ClearErrini(this.NowCaseno,this.MyTreeNode1);};
|
cls.prototype.PM509Click=function(s:any){this.PM401Click(null);};
|
cls.prototype.PM510Click=function(s:any){this.DeskewImg(this.DisplayISB.Graphic);this.DisplayISB.SaveToFile(this.DisplayISB.FileName);this.ClearErrini(this.NowCaseno,this.MyTreeNode1);};
|
cls.prototype.SelectScanBtnClick=function(s:any){this.Panel1.Enabled=false;this.Panel2.Enabled=false;this.Scanner.SelectScanner();this.Panel1.Enabled=true;this.Panel2.Enabled=true;};
|
cls.prototype.StatusBar1DblClick=function(s:any){this.Button3.Visible=!this.Button3.Visible;this.Button4.Visible=!this.Button4.Visible;};
|
cls.prototype.ActiveFormCreate=function(s:any){this.PostMessage(this.Handle,'WM_ACTIVATE','WA_CLICKACTIVE',0);this.VMode=1;this.DesableImage();for(let i=1;i<=8;i++){let isb=this.FindComponent('ISB'+i);isb.MouseMode='mmUser';isb.ZoomMode='zmFullPage';}setTimeout(()=>this.Timer1.Enabled=true,500);};
|
cls.prototype.ActiveFormKeyUp=function(s:any,k:any,sh:any){if(this.Edit1.Focused&&this.SelectISB!==null){if(k===38)this.PrePageBtnClick(null);if(k===40)this.NextPageBtnClick(null);}};
|
cls.prototype.AddCredit1RGClick=function(s:any){if(this.DisplayPath!==''){this.Case_loandoc=this.AddCredit1RG.ItemIndex===0?'Y':(this.AddCredit1RG.ItemIndex===1?'N':'');this.WriteCaseIndex(this.DisplayPath);}};
|
cls.prototype.AddScanBtnClick=function(s:any){if(!this.InitialOk)return;if(this.MyTreeNode1===null)return;this.Panel1.Enabled=false;this.Panel2.Enabled=false;this.ScanMode='smInsert';this.ScanInfo.ImageCount=this.ContextList.Count;this.ScanPath=this.DisplayPath;this.ScanCaseno=this.NowCaseno;this.ScanDocDir=this.NowDocDir;try{this.StatrTwainScan();}catch(e){}this.Panel1.Enabled=true;this.Panel2.Enabled=true;this.DrawDocItem2(this.MyTreeNode1,this.NowCaseno);this.GetCase_PageCount(this.CaseCount,this.PageCount);this.NewTreeNode.Text=this.NewTreeNode.Text.split('-')[0]+`-共${this.CaseCount}筆共${this.PageCount}頁`;this.MyTreeNode1.Text=`${this.NowCaseno}-${this.GetCasePage(this.ImageSavePath,this.NowCaseno)}頁`;this.ClearErrini(this.NowCaseno,this.MyTreeNode1);this.SetDocDirtoSelected(this.MyTreeNode1,this.FirstDocDir);this.TreeView1Click(this);};
|
cls.prototype.AttListBoxClick=function(s:any){this.DelAttFileLB.Enabled=this.AttListBox.ItemIndex>=0;};
|
cls.prototype.BtnMouseEnter=function(s:any){this.AddToolTip(s.Handle,null,0,s.Hint,null,0,0);};
|
[14,15,16,17,18,19,20,21,22,3].forEach(i=>{cls.prototype['SpeedButton'+i+'Click']=function(s:any){
|
if(i>=17){this.ISB1.ZoomMode=i===17?'zmFitHeight':i===18?'zmFitWidth':i===19?'zmOriginalSize':i===20?'zmFittoPage':i===3?'zmFullPage':'zmPercent';if(i===21)this.ISB1.ZoomPercent=50;if(i===22)this.ISB1.ZoomPercent=25;}
|
else if(!this.ISB1.Graphic.IsEmpty){this.ISB1.LoadFromFile(this.ISB1.FileName,1);this.Rotate(this.ISB1.Graphic,i===14?270:i===15?180:90);if(this.ISB1.Graphic.ImageFormat!=='ifBlackWhite'){this.ISB1.Graphic.SaveQuality=30;this.ISB1.Graphic.SaveToFile(this.ISB1.FileName);}else this.ISB1.SaveToFile(this.ISB1.FileName);this.ISB1.Redraw(true);this.SelectISB.Graphic.Assign(this.ISB1.Graphic);this.SelectISB.Redraw(true);this.FitPreViewISB();this.ISBClick(this.SelectISB);}
|
};});
|
}
|