Q语言 数据库操作实例

sub 判断帐号存在否() Dim sqloledb_string,AA sqloledb_string = "Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Mydbase;Data Source=xxx.xxx.xxx.xxx,1433" select_from = "SQ_USER" select_user = "UserId" USER_NAME=TRIM(FORM1.InputbS_ZH.Text) AA=Plugin.user_login.F_user(sqloledb_string, select_from, select_user, USER_NAME) If aa = 1 Then MsgBox user_name & " 该帐号已存在,请另选帐号!!" End If end sub

// 本例中连接数据库为SQLserver2008
// 插件:Plugin.user_login.F_user执行SQL操作:
// select count(*) from SQ_USER where UserId= USER_NAME
// AA为返回记录数

sub 修改登录密码()
    Dim sqloledb_string,YY,M1,M2
    //   原密码
    M1 = TRIM(FORM1.Inputbx_m1.Text)
    // 新密码
    M2 = TRIM(FORM1.Inputbx_m2.Text)
    //   表名
    select_from = "SQ_USER"
    //  列名  用户帐号
    select_user = "UserId"
    //   列名  密码 
    select_password = "userpassword"
    //   列名  操作时间
    select_passdate = "id_date"
    //   列名 终端号
    select_userterm = "termcode"
    //   返回终端序列号值
    GetSN = Plugin.Sys.GetHDDSN()
    //     数据库连接字符串
    sqloledb_string = "Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=xxxxxxxx;Initial Catalog=Mydbase;Data Source=xxx.xxx.xxx.xxx,1433"
    YY = Plugin.user_login.F_login(sqloledb_string, select_from, select_user, select_password, select_passdate, select_userterm, USER_NAME, M1, id_date, GetSN)
    //     找到附合条件记录后写入记录
    If YY = 1 Then  
        // ‘写入表记录成功
        If Plugin.user_login.F_update(sqloledb_string, select_from, "UserId", "userpassword", USER_NAME, M2) = 1 Then  
            MsgBox  "密码修改成功,请牢记新密码!!"       
        Else 
            MsgBox  "密码修改错误,请重新操作!!"       
        End If              
    Else 
        MsgBox  "帐号密码认证不正确,请填写正确信息!!"      
    End if
End Sub
Event form1.Button_z.Click
    Dim USER_NAME,DHHM
    USER_NAME = TRIM(FORM1.Inputbz_ZH.Text)
    DHHM = TRIM(FORM1.Inputbz_dh.Text)    
    If USER_NAME<>"注册帐号" and USER_NAME<>"" and  DHHM<>"" and DHHM<>"电话号码"
        Dim sqloledb_string,select_from,select_user,AA
        sqloledb_string = "Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=xxxxxx;Initial Catalog=Mydbase;Data Source=xxx.xxx.xxx.xx,1433"
        select_from = "SQ_USER"
        select_user = "UserId"
        aa = Plugin.user_login.F_select(sqloledb_string, select_from, select_user, "Userphone", USER_NAME)
        If aa<>"" then
            If trim(left(aa,len(aa)-1))=dhhm then
                bb = Plugin.user_login.F_select(sqloledb_string, select_from, select_user,"UserPassword",USER_NAME)
                If bb <>"" Then 
                    MsgBox trim(left(bb,len(bb)-1))
                End If
            Else 
                MsgBox  "电话号码不正确,请填写正确信息!!"       
            End If
        Else 
            MsgBox  "帐号不存在,请填写正确信息!!"      
        End if
    Else 
        MsgBox  "注册信息不完整,请填写完整信息!!"           
    End if
End Event

Event form1.Button_S.Click
    Dim USER_NAME, PASS1, PASS2, DHHM
    USER_NAME = TRIM(FORM1.InputbS_ZH.Text)
    PASS1 = TRIM(FORM1.InputbS_M1.Text)
    PASS2 = TRIM(FORM1.InputbS_M2.Text)
    DHHM  = TRIM(FORM1.InputbS_DH.Text)
    If USER_NAME<>"注册帐号" and USER_NAME<>"" and PASS1<>"" AND PASS1=PASS2 AND DHHM<>"" and DHHM<>"电话号码"
        Dim sqloledb_string, select_from, select_user, GetSN, aa, BB, cc
        sqloledb_string = "Provider=SQLOLEDB.1;Password=xxxxxxxx;Persist Security Info=True;User ID=xxxxxx;Initial Catalog=Mydbase;Data Source=xx.xx.xx.xx,1433"
        select_from = "SQ_USER"
        select_user = "UserId"
        GetSN = Plugin.Sys.GetHDDSN()
        If Plugin.user_login.F_user(sqloledb_string, select_from, select_user, USER_NAME) = 0 Then 
            bb = Plugin.user_login.F_select(sqloledb_string, select_from, "termcode","termcode",getsn)
            cc = UBound(split( bb,"|"))+1
            TracePrint " 终端注册号个数 :"&cc
            If cc <= 3 Then 
                aa = Plugin.user_login.F_insert(sqloledb_string, select_from, select_user, USER_NAME)
                TracePrint "写入帐号: " & aa
                If  aa= 1 Then 
                    TracePrint "写入密码: " & Plugin.user_login.F_update(sqloledb_string, select_from, select_user, "UserPassword", USER_NAME, PASS1)
                    TracePrint "写入号码: " & Plugin.user_login.F_update(sqloledb_string, select_from, select_user, "Userphone", USER_NAME, DHHM)
                    TracePrint "写入机码: " & Plugin.user_login.F_update(sqloledb_string, select_from, select_user, "Termcode", USER_NAME, GetSN)
                    MsgBox USER_NAME & " 帐号注册成功!"
                Else 
                    MsgBox  "数据写入错误,注册不成功!!"        
                End If
            Else 
                MsgBox "当日注册号限于3个!!!"
            End if
        Else 
            MsgBox  USER_NAME &"该帐号已存在,请另选帐号!!"     
        End If
    Else 
        MsgBox  "注册信息不完整,请填写完整信息!!"
    End IF
End Event

//注:
//Plugin.user_login.F_select
//Plugin.user_login.F_user;
//Plugin.user_login.F_login;
//Plugin.user_login.F_update 为自定义数据库操作插件 原代码后续整理附上

Q语言 数据库操作实例

上一篇:关于linux7下编写crontab任务执行mysqldump备份无效


下一篇:mycat中间件进行MySQL数据表的水平拆分