本帖最后由 善小而为_ 于 2024-2-20 17:08 编辑
[AAuto] 纯文本查看 复制代码 //sqlite用户登录
import win.ui;
/*DSG{{*/
var winform = win.form(text="用户登录";right=530;bottom=275)
winform.add(
button={cls="button";text="登录";left=206;top=201;right=294;bottom=236;db=1;dl=1;z=5};
editPass={cls="edit";left=206;top=125;right=345;bottom=155;db=1;dl=1;dr=1;dt=1;edge=1;password=1;z=4};
editUser={cls="edit";left=206;top=50;right=345;bottom=79;dl=1;dr=1;dt=1;edge=1;multiline=1;z=2};
static={cls="static";text="用户名";left=82;top=50;right=162;bottom=79;align="center";center=1;dl=1;dt=1;transparent=1;z=1};
static2={cls="static";text="密码";left=82;top=125;right=173;bottom=155;align="center";center=1;db=1;dl=1;dt=1;transparent=1;z=3}
)
/*}}*/
import sqlite
import console
var dbName = io.joinpath(io._exedir,"mydb.db");
var db = sqlite(dbName)
//初始化
var userTbl = "user"
if !db.existsTable(userTbl){
db.exec("create table ??(id,name,pass) ",{userTbl})
var dataTab = {
{1, 'admin', '123456'},
{2, 'user', '123456'},
}
db.beginTrans(); //事务开始
for(i=1;#dataTab;1){
db.exec("INSERT INTO ?? VALUES (?) ",{userTbl,dataTab[i]});
}
db.commitTrans(); //事务结束
//var dt = db.getTable("select * from ?? ",{userTbl});
//console.dump(dt)
}
winform.button.oncommand = function(id,event){
name = winform.editUser.text;
pass = winform.editPass.text;
//winform.msgbox("用户名:"+name+",密码:"+pass)
var dt = db.getTable("select count(*) as count from ?? where name=@name and pass=@pass ",
{"user", name=name, pass=pass});
//console.dump(dt)
if !dt[1].count {
winform.msgbox("用户登录失败!");
return ;
} else {
winform.msgbox("用户登录成功!")
}
}
winform.onClose = function(hwnd,message,wParam,lParam){
if db db.close()
}
winform.show();
win.loopMessage();
|