|
本帖最后由 qqmmcc 于 2011-12-15 20:28 编辑
经过重重地困难终于编写成功。高手不要笑我,毕竟我刚刚接触aardio大约半个多月的时间,学习aardio还是只能业余时间学习,上网还不方便。发这个帖子只是希望能给其他跟我一样的新手们一个思路,共同学习。
源程序下载
access抽人.zip
(32.96 KB, 下载次数: 274)
/*_________*/
/*main.aardio */
/*_________*/
import win.ui;
import com;
//import fsys;
//import win
import process;
import winex.key
/*DSG{{*/
var winform = win.form(parent=...; right=335;text="随机抽取";bottom=349 )
winform.add(
button2={ ah=1;bottom=323;right=203;left=128;top=296;z=10;text="名单管理";aw=1;cls="button" };
edit={ ah=1;bottom=83;right=166;left=99;top=63;aw=1;text="0";z=4;edge=1;cls="edit" };
static={ ah=1;bottom=45;text="工序";left=38;right=85;top=28;transparent=1;nWrap=1;aw=1;z=2;cls="static" };
static2={ ah=1;bottom=85;right=93;left=36;top=66;transparent=1;text="抽取人数";aw=1;z=3;cls="static" };
static4={ ah=1;bottom=121;right=92;left=40;top=102;transparent=1;text="人员名单";aw=1;z=8;cls="static" };
static3={ ah=1;bottom=83;right=224;left=176;top=64;transparent=1;text="总人数";aw=1;z=5;cls="static" };
edit2={ ah=1;bottom=82;right=295;left=228;top=63;aw=1;text="0";z=6;edge=1;cls="edit" };
button={ ah=1;bottom=323;right=115;left=40;top=296;z=9;text="抽取人数";aw=1;cls="button" };
button3={ ah=1;bottom=323;right=290;left=216;top=296;z=11;text="导出";aw=1;cls="button" };
listbox={ ah=1;bgcolor=16777215;vscroll=1;right=249;text="listbox";left=100;bottom=266;
items={ };aw=1;top=100;z=7;edge=1;cls="listbox" };
combobox={ ah=1;bottom=44;vscroll=1;right=270;left=98;text="";
items={ };top=24;aw=1;z=1;mode="dropdown";edge=1;cls="combobox" }
)
/*}}*/
winform.button3.oncommand = function(id,event){
//win.msgbox( winform.button3.text );
hwndf=winex.findExists("无标题 - 记事本")
if(!hwndf){
process.execute("notepad.exe");
}
hwnd,hctrl = winex.findActivate( , ,"Notepad","Edit",15 );
win.delay(500)
//设置焦点
winex.attach(hwnd)
win.setFocus(hctrl)
t=winform.combobox.text
winex.key.send(hctrl,'\n'+'\n'+winform.combobox.text +'\n')
winex.key.send(hctrl,"———")
for(i=1;winform.listbox.count){
//winex.key.send(hctrl,enter)
winex.key.down(hctrl,'\n')//"Enter" )
winex.key.send(hctrl,winform.listbox.getItemText(i))
sleep(100)
}
}
math.randomize()
winform.button.oncommand = function(id,event){
//math.randomize()//有兴趣的可以试试种子函数放在这里的效果。结果肯定不是预期的。
winform.listbox.clear()
str=winform.combobox.text
//定义获得符合要求的函数
function matchednm(){
cn=com.CreateObject("adodb.connection")
cn.connectionString="Provider=Microsoft.jet.OLEDB.4.0;Data Source="
+io.fullpath("\accessdb\db.mdb")
//cn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);dbQ=" +io.fullpath("\res\db.mdb")
cn.open()
str=winform.combobox.text
sql="select * from " + str
rs1=com.CreateObject("adodb.recordset")
rs1.open(sql,cn)
t=math.random(1,winform.edit2.text)
// winform.msgbox(t)
n=1
while(!rs1.eof){
if (n=t){
m=rs1("人名").value
return m;
rs1.movefirst()
break;
}
else{
rs1.movenext();
n+=1;
}
}
rs1.close()
cn.close()
}
//定义(判断与列表中项是否重复)函数
function repeated(nm,list={}){
function a(){
for(i=0;#list){
if (nm=list[ i ]){
[ i ]//winform.msgbox(nm)
//winform.msgbox(list[ i ])
return 1//不能返回false,因为如果for结束后都没有重复的a()返回的应该是null.判断失败。
break;
}
//else return true
}
}
b=a()
if(b=1){
return false
}
else return true
}
for(i=1;winform.edit.text;1){
while(1){
nm=matchednm()
//winform.msgbox(nm)
flag=repeated(nm,winform.listbox.items)
//winform.msgbox(flag)
if(flag){
winform.listbox.add(nm)
//for(i=1;#winform.listbox.items)
//winform.msgbox(winform.listbox.items[ i ])
break;
}
else continue
}
}
}
winform.combobox.oncommand = function(id,event){
if (event=0x1/*_CBN_SELCHANGE*/){
num=0
str=winform.combobox.selText
conn.open()
sql="select * from " + str
rs.open(sql,conn)
while(!rs.eof){
num=num+1
rs.movenext()
}
winform.edit2.text=num
rs.close()
conn.close()
}
//无返回值则继续调用默认回调函数
}
winform.button2.oncommand = function(id,event){
//win.msgbox( winform.button2.text );
var child,wb = winform.loadForm("\res\mdgl.aardio",winform /*指定父窗口*/ );
child.show();
}
conn=com.CreateObject("ADODB.Connection")
conn.connectionString="Provider=Microsoft.jet.OLEDB.4.0;Data Source="
+io.fullpath("\accessdb\db.mdb")
//conn.open()
//conn.ConnectionString = "DRIVER=Microsoft Access Driver (*.mdb);dbQ=" +io.fullpath("\res\db.mdb")
conn.Open()
rs=com.CreateObject("ADOdb.recordset")
//rs.ActiveConnection=conn
sql="select * from 工序名"
rs.open(sql,conn)
while(!rs.eof){
//str=rs("工序名").value
winform.combobox.add(rs("工序名").value)
rs.movenext()
}
rs.close()
conn.close()
winform.show()
win.loopMessage();
return winform;
/*_________*/
/*mdgl.aardio */
/*_________*/
import win.ui;
/*DSG{{*/
var winform = win.form(parent=...; text="aardio Form";right=343;bottom=367 )
winform.add(
combogx={ bottom=76;text="";left=128;vscroll=1;top=56;right=248;z=1;
items={ };mode="dropdown";edge=1;cls="combobox" };
bnadd={ bottom=336;right=208;left=152;top=312;z=5;text="添加";cls="button" };
static={ bottom=72;nWrap=1;left=56;top=56;transparent=1;right=104;z=2;text="工序";cls="static" };
bndel={ bottom=336;right=296;left=240;top=312;z=6;text="删除";cls="button" };
static4={ bottom=184;right=48;left=8;text="总数";top=160;transparent=1;z=11;cls="static" };
static3={ bottom=248;nWrap=1;left=8;top=224;transparent=1;right=56;z=10;text="人名";cls="static" };
static2={ bottom=104;nWrap=1;left=56;top=88;transparent=1;right=104;z=7;text="列表";cls="static" };
bncx={ bottom=336;right=112;left=56;top=312;z=4;text="查询";cls="button" };
allnum={ bottom=216;text="0";left=40;top=192;z=8;right=104;edge=1;cls="edit" };
listbox={ bgcolor=16777215;vscroll=1;right=248;left=128;text="listbox";
items={ };z=3;bottom=296;top=88;edge=1;cls="listbox" };
rmedit={ bottom=280;text="";left=40;top=256;z=9;right=104;edge=1;cls="edit" }
)
/*}}*/
function fresh(){
winform.listbox.clear()
fstr=winform.combogx.selText
i=0
cn.open()
sql="select * from "+ fstr
rs.open(sql,cn)
while (!rs.eof){
winform.listbox.add( rs("人名").value)
rs.movenext()
i+=1
}
rs.close()
cn.close()
winform.allnum.text=i
}
winform.listbox.oncommand = function(id,event){
//win.msgbox( winform.listbox.text );
winform.rmedit.text=winform.listbox.selText
}
winform.bndel.oncommand = function(id,event){
//win.msgbox( winform.bndel.text );
f=winform.msgboxTest("确定删除吗?")
if(f){
cn.open()
str=winform.combogx.selText
cn.execute("delete from ["+str+"] where 人名='"+winform.rmedit.text+"';")
//对比cn.exec("del from ["+str+"] where 人名='"+winform.rmedit.text+"';")
winform.msgbox("删除成功","删除")
cn.close()
}
fresh()
}
winform.bnadd.oncommand = function(id,event){
//win.msgbox( winform.bnadd.text );
str=winform.combogx.selText
cn.open()
cn.execute("insert into ["+str+"](人名) values ('"+winform.rmedit.text+"');")
winform.msgbox("添加成功","添加")
cn.close()
/*
cn.exec("insert into ["+str+"] values (?,'"+winform.rmedit.text+"');")
*/
fresh()
}
winform.bncx.oncommand = function(id,event){
//win.msgbox( winform.bncx.text );
winform.listbox.clear()
str=winform.combogx.text
//winform.msgbox(str)
cn.open()
sql="select * from "+ str
rs.open(sql,cn)
while(!rs.eof){
winform.listbox.add(rs("人名").value)
rs.movenext()
}
rs.close()
cn.close()
}
import com;
winform.combogx.oncommand = function(id,event){
if (event=0x1/*_CBN_SELCHANGE*/){
num=0
str=winform.combogx.selText
cn.open()
sql="select * from " + str
rs.open(sql,cn)
while(!rs.eof){
num=num+1
rs.movenext()
}
winform.allnum.text=num
rs.close()
cn.close()
if(winform.combogx.selText){fresh()
}
}
}
cn=com.CreateObject("ADODB.Connection")//com.createobject("adodb.connection")
cn.ConnectionString ="DRIVER=Microsoft Access Driver (*.mdb);dbQ=" +io.fullpath("\accessdb\db.mdb")
cn.open()
rs=com.CreateObject("ADOdb.recordset")
sql="select * from 工序名"
rs.open(sql,cn)
while (!rs.eof){
winform.combogx.add( rs("工序名").value)
rs.movenext()
}
rs.close()
cn.close()
winform.show()
win.loopMessage();
return winform;
|
|