增加数据采集
This commit is contained in:
parent
a95db059bf
commit
737bb015fe
|
@ -0,0 +1,3 @@
|
||||||
|
dist/
|
||||||
|
config/*
|
||||||
|
.build/
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<project ver="10" name="dcu" libEmbed="true" icon="C:\Users\caoqi\Desktop\favicon.ico" ui="win" output="dcu.exe" CompanyName="单位名称" FileDescription="dcu" LegalCopyright="Copyright (C) 作者 2021" ProductName="dcu" InternalName="dcu" FileVersion="0.0.0.05" ProductVersion="0.0.0.05" publishDir="/dist/" dstrip="false">
|
||||||
|
<file name="main.aardio" path="main.aardio" comment="main.aardio"/>
|
||||||
|
<folder name="资源文件" path="res" embed="true" local="false" ignored="false"/>
|
||||||
|
<folder name="窗体文件" path="dlg" comment="目录" embed="true" local="false" ignored="false">
|
||||||
|
<file name="add.aardio" path="dlg\add.aardio" comment="dlg\add.aardio"/>
|
||||||
|
</folder>
|
||||||
|
</project>
|
|
@ -0,0 +1,24 @@
|
||||||
|
import win.ui;
|
||||||
|
/*DSG{{*/
|
||||||
|
var winform = win.form(text="新建采集内容";right=299;bottom=179;border="dialog frame";max=false;min=false)
|
||||||
|
winform.add(
|
||||||
|
button={cls="button";text="确定";left=90;top=119;right=196;bottom=154;z=5};
|
||||||
|
edit={cls="edit";left=84;top=26;right=281;bottom=50;dl=1;dr=1;dt=1;edge=1;z=2};
|
||||||
|
edit2={cls="edit";left=84;top=69;right=281;bottom=93;dl=1;dr=1;dt=1;edge=1;z=4};
|
||||||
|
static={cls="static";text="设备编号";left=8;top=29;right=78;bottom=54;dl=1;dt=1;notify=1;transparent=1;z=1};
|
||||||
|
static2={cls="static";text="文件夹地址";left=8;top=74;right=78;bottom=99;dl=1;dt=1;notify=1;transparent=1;z=3}
|
||||||
|
)
|
||||||
|
/*}}*/
|
||||||
|
|
||||||
|
winform.button.oncommand = function(id,event){
|
||||||
|
if(winform.edit.text!="" && winform.edit2.text!=""){
|
||||||
|
winform.parent.listview.addItem({winform.edit.text;winform.edit2.text})
|
||||||
|
winform.close()
|
||||||
|
}else{
|
||||||
|
winform.msgbox("请输入信息!")}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
winform.show();
|
||||||
|
win.loopMessage();
|
||||||
|
return winform;
|
|
@ -0,0 +1,20 @@
|
||||||
|
//config 配置文件
|
||||||
|
import fsys.config;
|
||||||
|
config = fsys.config("/config/");
|
||||||
|
//config = fsys.config( io.appData("/软件作者/应用程序名/") );
|
||||||
|
|
||||||
|
//不需要序列化的配置名字前请添加下划线
|
||||||
|
namespace config {
|
||||||
|
__appName = "应用程序名";
|
||||||
|
__appVersion = "1.0.0.01";
|
||||||
|
__appDescription = "这是一个测试程序";
|
||||||
|
__website = "http://www.aardio.com/";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**intellisense(config)
|
||||||
|
__appName = 应用程序名
|
||||||
|
__appVersion = 应用程序内部版本号
|
||||||
|
__appDescription = 程序说明
|
||||||
|
__website = 官方网站
|
||||||
|
? = 配置文件名,\n读写配置并序列化为一个表对象,\n表的成员值可以是支持序列化的普通变量,支持table对象\n配置文件在首次使用时自动加载,退出程序时自动保存\n!fsys_table.
|
||||||
|
end intellisense**/
|
|
@ -0,0 +1,200 @@
|
||||||
|
import win.ui;
|
||||||
|
import win.inputBox;
|
||||||
|
import win.ui.menu;
|
||||||
|
import win.util.tray;
|
||||||
|
import win.ui.atom;
|
||||||
|
import win.timer;
|
||||||
|
import console;
|
||||||
|
import win.timer;
|
||||||
|
import fsys;
|
||||||
|
import web.multipartFormData;
|
||||||
|
import inet.http;
|
||||||
|
import fsys.config;
|
||||||
|
/*DSG{{*/
|
||||||
|
mainForm = win.form(text="数据采集";right=799;bottom=399;border="dialog frame";max=false)
|
||||||
|
mainForm.add(
|
||||||
|
add={cls="button";text="新建";left=27;top=130;right=98;bottom=154;font=LOGFONT(h=-14;name='微软雅黑');z=6};
|
||||||
|
backupPath={cls="edit";left=107;top=58;right=337;bottom=84;edge=1;font=LOGFONT(h=-14;name='微软雅黑');z=11};
|
||||||
|
backupPathLabel={cls="static";text="备份文件夹";left=31;top=60;right=118;bottom=81;font=LOGFONT(h=-14;name='微软雅黑');notify=1;transparent=1;z=10};
|
||||||
|
groupbox={cls="groupbox";text="采集内容";left=18;top=110;right=346;bottom=390;edge=1;z=5};
|
||||||
|
groupbox2={cls="groupbox";text="采集日志";left=353;top=7;right=792;bottom=390;ah=1;aw=1;db=1;dr=1;edge=1;z=1};
|
||||||
|
groupbox3={cls="groupbox";text="基础配置";left=18;top=7;right=346;bottom=102;edge=1;z=2};
|
||||||
|
listbox={cls="listbox";left=360;top=24;right=785;bottom=387;edge=1;hscroll=1;items={};vscroll=1;z=12};
|
||||||
|
listview={cls="listview";left=27;top=161;right=337;bottom=384;edge=1;fullRow=1;items={};msel=false;z=7};
|
||||||
|
serverUrl={cls="edit";left=107;top=25;right=337;bottom=51;edge=1;font=LOGFONT(h=-14;name='微软雅黑');z=4};
|
||||||
|
serverUrlLabel={cls="static";text="服务器地址";left=31;top=28;right=118;bottom=49;font=LOGFONT(h=-14;name='微软雅黑');notify=1;transparent=1;z=3};
|
||||||
|
start={cls="button";text="开始采集";left=266;top=130;right=337;bottom=154;font=LOGFONT(h=-14;name='微软雅黑');z=8};
|
||||||
|
statusLabel={cls="static";left=143;top=130;right=221;bottom=154;align="center";color=32768;font=LOGFONT(h=-16;name='微软雅黑';weight=700);transparent=1;z=9}
|
||||||
|
)
|
||||||
|
/*}}*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
inputbox = win.inputBox(mainForm.hwnd)
|
||||||
|
inputbox.text = "输入框标题"
|
||||||
|
inputbox.info.text = "请在下面输入您的名字"
|
||||||
|
inputbox.input.text = "在这里输入您的名字"
|
||||||
|
name = inputbox.doModal();
|
||||||
|
|
||||||
|
if(name)
|
||||||
|
win.msgbox("您的名字是:"+name )
|
||||||
|
else
|
||||||
|
win.msgbox("你拒绝输入名字")
|
||||||
|
*/
|
||||||
|
mainForm.listview.adjust = function(cx,cy){
|
||||||
|
mainForm.listview.fillParent(/*列序号*/);
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.listview.insertColumn("设备编号",100,,0x0/*_LVCFMT_LEFT*/)
|
||||||
|
mainForm.listview.insertColumn("文件夹地址",100,,0x0/*_LVCFMT_LEFT*/) //第二列开始可以使用_LVCFMT_CENTER居中
|
||||||
|
|
||||||
|
config = fsys.config("/config/")
|
||||||
|
mainForm.bindConfig( config.winform,{
|
||||||
|
serverUrl = "text";
|
||||||
|
backupPath = "text";
|
||||||
|
listview = "items";
|
||||||
|
} );
|
||||||
|
if(mainForm.serverUrl.text==""){
|
||||||
|
mainForm.serverUrl.text='https://testsearch.ctc.ac.cn'
|
||||||
|
}
|
||||||
|
if(mainForm.backupPath.text==""){
|
||||||
|
mainForm.backupPath.text="\Backup"
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
if(table.count(mainForm.listview.items)==0){
|
||||||
|
mainForm.listview.items = {{"JN102";"D:\tmp"}};
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
var isWorking = false;
|
||||||
|
var atom,hwnd/*冲突窗口的句柄,该函数会自动激活此窗口*/ = mainForm.atom("33D501DF-BFC2-4283-8BBE-AF17AADB1C27");
|
||||||
|
if(!atom){
|
||||||
|
/*为窗口设置原子值可以避免一个程序重复运行多个实例*/
|
||||||
|
win.quitMessage(); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mainForm.onMinimize = function(lParam){
|
||||||
|
var tray = win.util.tray(mainForm) //创建托盘图标
|
||||||
|
tray.tip = "数据采集";
|
||||||
|
mainForm.show(false); //隐藏窗口
|
||||||
|
return true;//阻击默认消息传递,取消最小化过程
|
||||||
|
}
|
||||||
|
mainForm.wndproc = {
|
||||||
|
[0xACCF/*_WM_TRAYMESSAGE*/ ] = function(hwnd,message,wParam,lParam){
|
||||||
|
if( lParam = 0x205/*_WM_RBUTTONUP*/ ){
|
||||||
|
var pt = ::POINT();
|
||||||
|
::User32.GetCursorPos(pt);
|
||||||
|
//弹出托盘菜单以前,一定要前置主窗口中,不然不点击菜单不会消失
|
||||||
|
win.setForeground(mainForm.hwnd)
|
||||||
|
mainForm.popmenu.popup(pt.x,pt.y,true )
|
||||||
|
}elseif(lParam = 0x203/*_WM_LBUTTONDBLCLK*/){
|
||||||
|
mainForm.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.popmenu = win.ui.popmenu(mainForm);//创建弹出菜单
|
||||||
|
mainForm.popmenu.add('&打开',function(id){
|
||||||
|
//在下面输入菜单响应代码
|
||||||
|
mainForm.show()
|
||||||
|
});
|
||||||
|
mainForm.popmenu.add();//分隔线
|
||||||
|
mainForm.popmenu.add('&退出',function(id){ mainForm.close() })
|
||||||
|
|
||||||
|
mainForm.start.oncommand = function(id,event){
|
||||||
|
toggleWorking();
|
||||||
|
|
||||||
|
}
|
||||||
|
var timer = win.timer( mainForm );
|
||||||
|
timer.setInterval(5000)
|
||||||
|
function toggleWorking(){
|
||||||
|
if(isWorking == false){
|
||||||
|
mainForm.serverUrl.disabled = true
|
||||||
|
mainForm.backupPath.disabled = true
|
||||||
|
mainForm.add.disabled = true
|
||||||
|
mainForm.statusLabel.text="采集中..."
|
||||||
|
mainForm.start.text="停止采集"
|
||||||
|
isWorking = true
|
||||||
|
timer.enable()
|
||||||
|
}else{
|
||||||
|
mainForm.serverUrl.disabled = false
|
||||||
|
mainForm.backupPath.disabled = false
|
||||||
|
mainForm.add.disabled = false
|
||||||
|
mainForm.statusLabel.text=""
|
||||||
|
mainForm.start.text="开始采集"
|
||||||
|
isWorking=false
|
||||||
|
timer.disable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(mainForm.serverUrl && table.count(mainForm.listview.items)>0){
|
||||||
|
toggleWorking();
|
||||||
|
}
|
||||||
|
|
||||||
|
timer.onTimer = function(hwnd,msg,id,tick){
|
||||||
|
for itemIndex in mainForm.listview.each(){
|
||||||
|
var number, dir = mainForm.listview.items[itemIndex][1], mainForm.listview.items[itemIndex][2]
|
||||||
|
//批量处理文件
|
||||||
|
fsys.enum( dir, //指定要遍历的目录
|
||||||
|
"*.*", //指定查询文件名,支持windows掩码
|
||||||
|
function(dir,filename,fullpath,findData){ //指定触发器
|
||||||
|
if(filename){
|
||||||
|
mainForm.listbox.add(tostring(time.now(),"%Y-%m-%d %H:%M:%S","chs") + ":发现文件-"+filename, -1)
|
||||||
|
mainForm.listbox.add("正在上传并解析...")
|
||||||
|
var webData = web.multipartFormData();
|
||||||
|
webData.add("equip_num", number)
|
||||||
|
webData.add("file", "@"+fullpath)
|
||||||
|
var http = inet.http();
|
||||||
|
http.beginRequest( mainForm.serverUrl.text + "/api/file/", "POST" );
|
||||||
|
//小数据一次性上传
|
||||||
|
http.beginSendData(webData.size());
|
||||||
|
http.writeData(webData.readAll())
|
||||||
|
http.endSendData();
|
||||||
|
var res = web.json.parse(http.readAll())
|
||||||
|
if(res['code']==200){
|
||||||
|
import fsys
|
||||||
|
var theDir = fsys.createDir(mainForm.backupPath.text+"\"+number, false)
|
||||||
|
fsys.move(fullpath, theDir) //移动到备份文件库
|
||||||
|
mainForm.listbox.add("采集成功!")
|
||||||
|
}else{
|
||||||
|
mainForm.listbox.add("失败:"+res['msg'])
|
||||||
|
}
|
||||||
|
http.close();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}, false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.listview.onnotify = function(id,code,ptr){
|
||||||
|
|
||||||
|
select(code) {
|
||||||
|
case 0xFFFFFFFB/*_NM_RCLICK*/ {
|
||||||
|
var x,y = win.getCursorPos();
|
||||||
|
var popmenu = win.ui.popmenu(mainForm);//创建弹出菜单
|
||||||
|
popmenu.add('删除',function(id){
|
||||||
|
//在下面输入菜单响应代码
|
||||||
|
mainForm.listview.delItem( mainForm.listview.selIndex )
|
||||||
|
});
|
||||||
|
popmenu.popup(x,y,true);//弹出菜单
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mainForm.add.oncommand = function(id,event){
|
||||||
|
|
||||||
|
var frmChild = mainForm.loadForm("\dlg\add.aardio");
|
||||||
|
frmChild.doModal();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mainForm.show();
|
||||||
|
return win.loopMessage();
|
Loading…
Reference in New Issue