//chineseNumber 大写数值 import win.ui; import winex.caret; import win.ui.tabs; namespace win.dlg; class chineseNumber{ ctor(parent){ if(!parent) parent = ..win.getForeground(); var rcCaret,oldFocus = ..winex.caret.get(parent); if(!oldFocus) oldFocus = ..winex.getFocus(parent); /*DSG{{*/ this = ..win.form(text="中文化数值";right=418;bottom=30;border="none";exmode="toolwindow";mode="popup";parent=parent;topmost=1) this.add( btnClose={cls="plus";text="r";left=386;top=0;right=420;bottom=34;color=2368548;font=LOGFONT(name='Marlett';h=-15;charset=2);notify=1;z=5}; dropdown={cls="plus";left=0;top=0;right=386;bottom=31;align="right";bgcolor=16777215;border={color=-3546113;width=2};editable="edit";font=LOGFONT(h=-16);forecolor=16777215;iconStyle={align="right";font=LOGFONT(name='imtip');padding={right=8}};notify=1;textPadding={left=2;top=6;right=7;bottom=2};z=1}; menuItem={cls="plus";text="测试菜单三";left=1;top=33;right=420;bottom=78;align="right";bgcolor=11525002;border={left=1;right=1;bottom=1;color=-3546113};tabstop=1;textPadding={right=20};z=2}; menuItem2={cls="plus";text="测试菜单三";left=1;top=78;right=420;bottom=123;align="right";bgcolor=11525002;border={left=1;right=1;bottom=1;color=-3546113};tabstop=1;textPadding={right=20};z=3}; menuItem3={cls="plus";text="测试菜单三";left=1;top=123;right=420;bottom=168;align="right";bgcolor=11525002;border={left=1;right=1;bottom=1;color=-3546113};tabstop=1;textPadding={right=20};z=4} ) /*}}*/ this.autoQuitMessage = false; var lcid = ::Kernel32.GetUserDefaultLCID(); if( lcid==0x404/*zh-TW*/ || lcid == 0x0C04/*zh-HK*/ || lcid == 0x1404/*zh-MO*/ ){ this.numberChars = numberChars : '零壹貳參肆伍陸柒捌玖'; this.timeFormat = "%H時%M分%S秒"; this.timeFormat2 = "%p %I時%M分%S秒"; this.lang = "cht"; } else { this.numberChars = numberChars : '零壹贰叁肆伍陆柒捌玖'; this.timeFormat = "%H时%M分%S秒"; this.timeFormat2 = "%p %I时%M分%S秒"; this.lang = "chs"; } this.unitChars = unitChars : '拾佰仟'; this.dropdown.skin({ background={ default=0; hover=0xFF928BB3; active=0x99928BB3; } color={ disabled=0xFFCCCCCC; } iconColor={ disabled=0xFFCCCCCC; } }) this.btnClose.skin({ background={ default=0x668FB2B0; hover=0xFF928BB3; disabled=0xFFCCCCCC; } }) var menu = ..win.ui.tabs(this.menuItem,this.menuItem2,this.menuItem3) menu.skin( { foreground={ default = 0xFFFFFFFF; hover= 0xFF8ADBAF; }; checked = { foreground={ default = 0xFFDB8A8E; hover= 0xFF8ADBAF; }; } }) menu.initPopup(this.dropdown.editBox) import string.chineseNumber; this.dropdown.editBox.disableInputMethod(); this.dropdown.editBox.onChange = function(){ var items = {}; var text = string.replace(owner.text,"[\s,\_]",""); var num = string.match(text,"^([+-]?0*\d+\.?\d*)$"); if(!#num){ var data = string.match(text,"^(\d{2,4}\.[01]*\d\.\d*)$"); if(data){ if(string.endsWith(data,".")){ menu.popup(false); return; } data = ..time(data+"","%Y.%m.%d"); var zh = string.chineseNumber('〇一二三四五六七八九'); items[1] = zh.date(data,"%Y年%m月%d日"); items[2] = zh.date(data,"%Y年%m月%d日 星期%w"); } else { var tm = string.match(text,"^(\d{1,2}\:\d{1,2}\:\d{1,2})$"); if(tm){ var zh = string.chineseNumber('〇一二三四五六七八九'); items[1] = zh.time(..time(tm,"%H:%M:%S"),this.timeFormat); items[2] = zh.time(..time(tm,"%H:%M:%S"),this.timeFormat2); } elseif(string.indexOf(text,":")){ return; } elseif( text == "now" ){ var zh = string.chineseNumber('〇一二三四五六七八九'); var now = ..time(); items[1] = zh.date(now,"%Y年%m月%d日 星期%w") items[2] = zh.time(now,this.timeFormat2); items[3] = zh.datetime(now); items[4] = tostring(now,"%Y/%m/%d %H:%M:%S"); } else { try{ num = eval(text) } if(type(num)!=type.number){ if(this.lang = "cht"){ owner.showInfoTip("可输入以下格式:",'数值或金额示例: 12345.67 或 12,345.67 或 12_345.67\n自定义进制示例:2#1010 或 0xFFFF\n数学表达式示例: (12+23)*2\n日期示例: 2020.2.29\n时间示例: 23:50:56\n当前日期时间: now'); } else { owner.showInfoTip("可輸入以下格式:",'數值或金額示例: 12345.67 或 12,345.67 或 12_345.67\n自定義進位示例:2#1010 或 0xFFFF\n數學表達式示例: (12+23)*2\n日期示例: 2020.2.29\n時間示例: 23:50:56\n當前日期時間: now'); } menu.popup(false); return; } else{ items[1] = tostring(num) } } } } if(num!==null){ var zh = string.chineseNumber(this.numberChars,this.unitChars); items[#items+1] = zh.money(num); items[#items+1] = zh.number(num); var zh = string.chineseNumber(); items[#items+1] = zh.number(num); } menu.setItemTexts(items); if(!menu.isVisible()){ if(self.prevSelIndex && self.prevSelIndex<=#items){ menu.selIndex = self.prevSelIndex } else { menu.selIndex = 1; } } menu.popup(true) } import key; menu.onOk = function(strip){ self.prevSelIndex = menu.selIndex; var text = strip.text; this.onDestroy = function(){ if(this.oldFocus){ ..winex.attach(this.oldFocus,true); ..thread.delay(100); ..win.setFocus(this.oldFocus); ..winex.attach(this.oldFocus,false); } key.sendString(text); } this.close(); } this.btnClose.oncommand = function(id,event){ this.close(); } this.enableDpiScaling("init"); var hOwner = ..win.getOwner(this.hwnd) : ..win.getForeground(); if(rcCaret){ this.setPos(rcCaret.left,rcCaret.top + (rcCaret.bottom ? rcCaret.height() : this.dpiScale(50)) ); } else { ..win.center(this.hwnd,hOwner); } var scrX,scrY,scrWidth,scrHeight = ..win.getScreenPos(this.hwnd,hOwner) var x,y,cx,cy = this.getPos(); var _,minHeight = this.dpiScale(0,200); if(y + minHeight > scrHeight){ y = scrHeight - minHeight; this.setPos(x,y); } if(x+cx>scrWidth){ x = scrWidth -cx; this.setPos(x,y); } this.oldFocus = oldFocus; this.show(); ..win.setTopmost(this.hwnd) this.dropdown.editBox.setFocus(); this.dropdown.editBox.onOk = function(){ this.close() } this.dropdown.editBox.onCancel = function(){ this.close(); } }; } if( !owner ) ..win.dlg.chineseNumber().doModal(); /**intellisense() win.dlg.chineseNumber() = 创建大小数值、金额输入对话框,\n可选用参数 @1 指定父窗口句柄,注意不需要指定输入框句柄。\n此对话框会自动检测输入光标所在位置。\n\n应调用 doModal 函数显示为模态对话框\n!winform. end intellisense**/