maxscript编写带有登录功能的插件

踩到的坑:

1.在rollout里面关闭当前dialog 直接写在里面无效

rollout floater2 "登录"
(

label lbl_username "用户名:" align:#left across:2
edittext txt_username "" 100 height:20 align:#right arcoss:2

label lbl_password "密码:" align:#left across:2
edittext txt_password "" 100 align:#right across:2 


global objectUsername = ""
global objectPassword = ""

on txt_username entered txt do(
objectUsername = txt
txt_username.text = txt
DestroyDialog floater
)
on txt_password entered txt do (
objectPassword = txt
txt_password.text = txt
)


)

2..连接数据库 无法连接,老是说不能访问

TestConn=createOLEObject "ADODB.Connection"
TestConn.Open "driver={MySQL ODBC 3.51 Driver}; server=serverName; database=databaseName;user=userName;password=password"
recordSet = createOLEObject "ADODB.Recordset"
selectString = "SELECT * from tableName where username='"+username+"' and password='"+password+"'"
recordSet.Open selectString TestConn -- Standard SQL Request in ""
recordset.GetRows()

解决方案:

问题1:将dialog的创建放到函数中去

fn makeDialog =
(
rollout floater "登录信息"
(
label lbl_username "用户名:" align:#left across:2
edittext txt_username "" 100 height:20 align:#right arcoss:2

label lbl_password "密码:" align:#left across:2
edittext txt_password "" 100 align:#right across:2

button btn_loginBottom "登录" 60 align:#center
global objectUsername = ""
global objectPassword = ""

on txt_username entered txt do(
objectUsername = txt
txt_username.text = txt
)
on txt_password entered txt do (
objectPassword = txt
txt_password.text = txt
)
on btn_loginBottom pressed do
(
--验证登录信息是否正确

result = fn_validateUser objectUsername objectPassword
print 2222
print result
print (result == "fail")
if result =="success" then (DestroyDialog floater) else (print "fail")
)
)
createdialog floater 200 height:100
setFocus floater.txt_username
)

问题2:参考http://forums.cgsociety.org/archive/index.php?t-384588.html

  1. 根据自己的电脑(32位还是64位)选择安装mysql-connector-odbc-3.51.30
  2. 单击开始-控制面板-管理工具
  3. 双击数据源(ODBC)
  4. 单击切换到系统DSN选项卡,单击添加
  5. 双击MySQL ODBC 3.51 Driver,如图2所示,填写Data Source Name,TCP/IP Server:,User:,Password: ,Database: .点击ok保存,确定.   
每天进步一点点
原文地址:https://www.cnblogs.com/miraclesakura/p/9366570.html