lae界面开发工具入门之介绍十三--如何获取数据?
2019独角兽企业重金招聘Python工程师标准>>>
测试程序下载:http://pan.baidu.com/s/1dERKj2D
APP数据来源大致分三种:
1、线上数据
服务器端返回的数据,一般采用用HTTP或者HTTPS、SOCKET连接方式与APP客户交互,可以返回json格式或者二进制。
local json = luaopen_cjson();function HelperURLResponeFunc(urlresponse) local urlrequest = urlresponse:getRequest();if(urlrequest.thread ~= nil) then--LXZMessageBox("urlrequest.thread:"..type(urlrequest.thread));coroutine.resume(urlrequest.thread, urlresponse);end
endlocal service_host = "http://120.55.84.103:8080/";--服务器地址
local function HelperPostGetJSON(url, data, fn)local co = coroutine.create(function (thread) local urlrequest = _urlRequest:new();urlrequest.nRequestType = eRequestPost;urlrequest.func = "HelperURLResponeFunc";urlrequest.url = url.."?";for k,v in pairs(data) dourlrequest.url = urlrequest.url ..k.."="..v.."&";end urlrequest.url = TrimRightChar(urlrequest.url, '&');urlrequest.url = TrimRightChar(urlrequest.url, '?');urlrequest.thread = thread;--LXZMessageBox(urlrequest.url);local curl = CLXZCurl:Instance();curl:send(urlrequest); local urlresponse = coroutine.yield();if(fn~=nil) thenfn(urlresponse);end end);coroutine.resume(co, co); end--从服务器获取数据
local function OnServer(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口--创建协程,在协程里可以顺序执行异步代码HelperCoroutine(function(thread)HelperPostGetJSON(service_host.."getid", {}, function(urlresponse)--异步调用接口LXZMessageBox("urlresponse:getResponseData:"..urlresponse:getResponseData())local res = json.decode(urlresponse:getResponseData());if res thenHelperSetWindowText(wnd, res.id);elseHelperSetWindowText(wnd, "从服务器获取失败");endcoroutine.resume(thread);end); coroutine.yield(); end);end
2、本地配置数据
可读取key-value模式文本数据文件
--从配置文件读取数据
local function OnCfg(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口local cfg = ILXZCoreCfg:new_local();cfg:load(LXZAPIGetWritePath().."data.cfg");local id = cfg:GetInt("id");if id thenHelperSetWindowText(wnd, id);elseHelperSetWindowText(wnd, "配置文件错误");endend
3、sqlite3数据库
集成有sqlite数据库,可直接跟sqlite交互。
--数据库相关
local function DBInitialize(dbname)LXZDoFile("sqlite3.lua"); --数据库模块local corecfg = ICGuiGetLXZCoreCfg(); local dbfullpath = "";if(corecfg.IsEditTool==true) then --如果是lae工具中.dbfullpath = LXZAPIGetWritePath().."Edit"..dbname; --防止产生数据库同名时无法同时打开。elsedbfullpath = LXZAPIGetWritePath()..dbname;end--打开sqlite3local db = sqlite3.open(dbfullpath); db:exec("drop table Test"); --删除存在的表 sql = "create table Test(id INTEGER PRIMARY KEY autoincrement, name VARCHAR(32), userid INTERGER)";local d,err = db:exec(sql); --创建Test表,id作为主键,自动增加,name名字可变长.sql = "insert into Test(id,name,userid) values(100, \"我是个测试名字!\", 1111111)" --插入测试数据.local d,err = db:exec(sql); return db;
end--文件加载时初始化.
local db=DBInitialize("TestData.db");--从数据库读取数据
local function OnSqlite(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口local sql="select * from Test where id=100";local d,err = db:exec(sql); local users = HelperDBSelect(db, sql, true); if users and users[1] thenHelperSetWindowText(wnd, users[1].userid);elseHelperSetWindowText(wnd, "该数据不存在.");end
end
1、测试程序界面
测试代码:
LXZDoFile("LXZHelper.lua");
LXZDoFile("serial.lua");
local json = luaopen_cjson();function HelperURLResponeFunc(urlresponse) local urlrequest = urlresponse:getRequest();if(urlrequest.thread ~= nil) then--LXZMessageBox("urlrequest.thread:"..type(urlrequest.thread));coroutine.resume(urlrequest.thread, urlresponse);end
endlocal service_host = "http://120.55.84.103:8080/";--服务器地址
local function HelperPostGetJSON(url, data, fn)local co = coroutine.create(function (thread) local urlrequest = _urlRequest:new();urlrequest.nRequestType = eRequestPost;urlrequest.func = "HelperURLResponeFunc";urlrequest.url = url.."?";for k,v in pairs(data) dourlrequest.url = urlrequest.url ..k.."="..v.."&";end urlrequest.url = TrimRightChar(urlrequest.url, '&');urlrequest.url = TrimRightChar(urlrequest.url, '?');urlrequest.thread = thread;--LXZMessageBox(urlrequest.url);local curl = CLXZCurl:Instance();curl:send(urlrequest); local urlresponse = coroutine.yield();if(fn~=nil) thenfn(urlresponse);end end);coroutine.resume(co, co); end--从服务器获取数据
local function OnServer(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口--创建协程,在协程里可以顺序执行异步代码HelperCoroutine(function(thread)HelperPostGetJSON(service_host.."getid", {}, function(urlresponse)--异步调用接口LXZMessageBox("urlresponse:getResponseData:"..urlresponse:getResponseData())local res = json.decode(urlresponse:getResponseData());if res thenHelperSetWindowText(wnd, res.id);elseHelperSetWindowText(wnd, "从服务器获取失败");endcoroutine.resume(thread);end); coroutine.yield(); end);end--数据库相关
local function DBInitialize(dbname)LXZDoFile("sqlite3.lua"); --数据库模块local corecfg = ICGuiGetLXZCoreCfg(); local dbfullpath = "";if(corecfg.IsEditTool==true) then --如果是lae工具中.dbfullpath = LXZAPIGetWritePath().."Edit"..dbname; --防止产生数据库同名时无法同时打开。elsedbfullpath = LXZAPIGetWritePath()..dbname;end--打开sqlite3local db = sqlite3.open(dbfullpath); db:exec("drop table Test"); --删除存在的表 sql = "create table Test(id INTEGER PRIMARY KEY autoincrement, name VARCHAR(32), userid INTERGER)";local d,err = db:exec(sql); --创建Test表,id作为主键,自动增加,name名字可变长.sql = "insert into Test(id,name,userid) values(100, \"我是个测试名字!\", 1111111)" --插入测试数据.local d,err = db:exec(sql); return db;
end--文件加载时初始化.
local db=DBInitialize("TestData.db");--从数据库读取数据
local function OnSqlite(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口local sql="select * from Test where id=100";local d,err = db:exec(sql); local users = HelperDBSelect(db, sql, true); if users and users[1] thenHelperSetWindowText(wnd, users[1].userid);elseHelperSetWindowText(wnd, "该数据不存在.");end
end--从配置文件读取数据
local function OnCfg(window, msg, sender)local root=HelperGetRoot();--获得根节点local wnd=root:GetLXZWindow("id");--获得id窗口local cfg = ILXZCoreCfg:new_local();cfg:load(LXZAPIGetWritePath().."data.cfg");local id = cfg:GetInt("id");if id thenHelperSetWindowText(wnd, id);elseHelperSetWindowText(wnd, "配置文件错误");endend--事件绑定
local event_callback = {}
event_callback.__index = event_callback;
event_callback ["OnServer"] = OnServer;
event_callback ["OnSqlite"] = OnSqlite;
event_callback ["OnCfg"] = OnCfg;--消息派发接口
function main_dispacher(window, cmd, msg, sender)LXZAPI_OutputDebugStr("cmd 1:"..cmd);if(event_callback[cmd] ~= nil) then --如果已经绑定LXZAPI_OutputDebugStr("cmd 2:"..cmd);event_callback[cmd](window, msg, sender);--则调用绑定的接口end
end
转载于:https://my.oschina.net/u/1030910/blog/725493
lae界面开发工具入门之介绍十三--如何获取数据?相关推荐
- NC运维人员拓展知识 之 开发工具入门(一)
对于NC系统运维人员,通常情况下接触到较多的是NC前端问题处理,问题集中于业务之上.但是有时也会出现系统报错,例如,"****Exception",甚至出现"未知的错误& ...
- Xamarin Anroid开发教程之Anroid开发工具及应用介绍
Xamarin Anroid开发教程之Anroid开发工具及应用介绍 Xamarin开发Anroid应用介绍 如今智能手机已经盛行了好几年,而针对这些智能手机的软件开发也变得异常火热.但是在Andro ...
- Android界面开发工具DroidDraw
用Eclipes开发Android程序设计界面,如果界面的布局需要一行一行输入,那么将会使人很郁闷.现在有个工具可以帮你完成这些操作--Android界面开发工具DroidDraw.DroidDraw ...
- ASP.NET开发工具Web Matrix介绍
ASP.NET开发工具Web Matrix介绍 作者:arui 主页:http://blog.csdn.net/arui319 一.开篇语 通常,一说到ASP.NET编程,我们大多数人都会想到微软的V ...
- python界面开发哪个好用_python界面开发工具哪个好?
俗话说,好刃才能成好刀,找到适合自己的且功能全面的pytho界面开发工具也一样如此,满足项目使用,我们才能有效率,制作完美的项目工程,然而关于界面开发工具有很多,我们要怎么去选择呢?哪个才是最好的呢? ...
- 【无限互联】iOS开发视频教程—2.1 iPhone开发之开发工具安装及介绍
核心内容: 1. iPhone开发工具下载 2. Apple开发者网站如何阅读 3. Xcode的下载,模拟器和内存分析工具的使用 4. windows下如何开发iPhone程序,安装虚拟机 视频地址 ...
- PyQt5可视化编程-图形界面开发工具QtDesigner和PyUIC
一.概述 Qt库是跨平台的 C++库的集合,是最强大的 GUI库之一,可以实现高级 API来访问桌面和移动系统的各种服务.PyQt5是一套 Python绑定 Digia QT5应用的框架.PyQt5实 ...
- 【第3版emWin教程】第34章 emWin6.x的AppWizard界面开发工具使用方法
教程不断更新中:http://www.armbbs.cn/forum.php?mod=viewthread&tid=98429 第34章 emWin6.x的AppWizard界面开 ...
- 1、开发工具IDEA的介绍、安装、配置优化与快捷键
配套讲义.资料或源码等,敬请关注微信公众号"守护之王觉行"后,添加管理员微信获取. <凡人学Java>系列在线阅读地址 <凡人学Java> 一.编码神器-I ...
- python界面开发工具-python图形界面开发用什么
作为Python开发者,你迟早都会用到图形用户界面来开发应用.本文将推荐一些 Python GUI 框架,希望对你有所帮助. Python 的 UI 开发工具包 Kivy(推荐学习:Python视频教 ...
最新文章
- MindSpore技术理解(下)
- centos下查看网卡,主板,CPU,显卡,硬盘型号等硬件信息
- 求组合数的O(n^2)和O(n)解法及模板
- RocketMQ(十)——Consumer消费进度(Offset)的管理
- oracle 返回hashmap,解决:oracle+myBatis ResultMap 类型为 map 时返回结果中存在 timestamp 时使用 jackson 转 json 报错...
- html毕业答辩ppt,毕业答辩ppt
- android 打apk文件怎么打开方式,apk文件怎么打开,详细教您打开apk文件的方法
- puzzle(0921)HueBots
- Minecraft 1.12.2模组开发(十) 食物制作
- uniapp微信授权+获取手机号+解密手机号(带图详解)
- 《仙剑奇侠传4》仙剑问答全答案
- c++ascii码转换为数字_平面设计人员必备Image Ascii,快速将图像转换为Ascii字符画!...
- 智能拼图和魔法寿司-康佳6670
- 腾讯云百万容器镜像安全治理运营实践
- 为什么连续偶函数的原函数之一是奇函数,连续的奇函数的原函数都是偶函数并证明
- 石黑一雄《远山淡影》——读后感
- c语言switch语句最大嵌套数,浅谈C语言中switch 语句的嵌套使用
- properties语言包字数统计
- Excel中逻辑函数和时间日期函数
- 淘宝/天猫店铺oAuth2.0接口:Taobao.user.seller.get 查询淘宝卖家用户信息接口接入说明
热门文章
- es文件浏览器smb服务器,ES文件浏览器怎么连接电脑SMB,可以参考这篇文章
- 麦克纳姆轮(全向轮)
- 【数学】欧拉恒等式:史上最完美的数学公式,没有之一!
- amd显卡风扇调节_解决办法:设置显卡风扇速度的教程方法
- Harbor镜像清理
- 7月书讯(下)| 宝藏新书助你“乘风破浪”
- 使用while循环实现xyz+yzz=532
- [ur_driver-2] process has died
- python symbols函数_Python应用 | 求解微积分!
- marked 用户手册 在线查看