pb 制作登陆界面连接数据库

pb 制作登陆界面连接数据库一、app.demolearn1>GlobalVariables《全局定义》stringls_inifile                     =”j:/demo/db.ini”stringls_language_inifile    =”j:/demo/language.ini”stringg_language=””stringas_server,as_

一、app.demolearn
1>Global Variables《全局定义》
string ls_inifile                      =”j:/demo/db.ini”

string ls_language_inifile     =”j:/demo/language.ini”

string g_language=””

string as_server,as_dbms,as_database,as_logid,as_logpass
2>close()returns(none)
disconnect using SQLCA;
3>open(string commandline)return(none)
  /*多国语言(英文/简体/繁体)数据库应用模型(PB+sql server 2000实现)
   1.连接数据库的方法定义

     string connect_method=”inifile”

     string connect_method=”script”

  */

 

     string connect_method=”inifile”
   /* 2. 连接方式选择(ini文件/脚本)  */

 

  Choose Case connect_method
   /* 以ini配置文件连接数据库*/

 

  case “INIFILE”

       if FileExists (ls_inifile) then

       as_server    =profilestring (ls_inifile,”DATABASE”,”Servername”,””)

       as_dbms      =profilestring (ls_inifile,”DATABASE”,”DBMS”,””)

       as_database  =profilestring (ls_inifile,”DATABASE”,”database”,””)

       as_logid     =profilestring (ls_inifile,”DATABASE”,”LogID”,””)

       as_logpass   =profilestring (ls-inifile,”DATABASE”,”LogPass”,””)

       end if

  /*以脚本直接连接数据库*/

 

  Case “SCRIPT”

       as_server       =”dxxo”

       as_dbms         =”MSS Microsoft SQL Server 6.x”

       as_database     =”erp”

       as_logid        =”sa”

       as_logpass      =”*******”
  End Choose
  SQLCA.DBMS           =as_dbms

  SQLCA.database       =as_database

  SQLCA.logpass        =as_logpass

  SQLCA.servername     =as_server

  SQLCA.logid          =as_logid

  SQLCA.AutoCommit     =false

  SQLCA.DBParm         =””
  /* 3.打开连接 */

    connect using SQLCA;

    if SQLCA.Code <> 0 then

       MessageBox (“Cannot Connect to Database”,SQLCA.SQLErrText)

    end if

 

  /* 4.打开窗口 */

     open(w_login)
二、 w_login 窗口
1>  w_login:open(string commandline)return(none)

   

   /* 1.得到用户清单*/

    

     dw_user.visible=false

     dw_user.settransobject(sqlca)

     dw_user.retrieve()

  

   /* 2.添加用户ID到下拉表中*/
     int ii,ti

     ti=dw_user.rowcount()

     for ii=1 to ti

         ddlb_user.additem(dw_user.object.userid[ii])

     next

  

   /* 3.装载默认的语言配置 */
     g_language=profilestring(g_language_inifile,”default”,”language”,””)

     if FileExists (g_language_inifile) then

     Choose case g_language

            case “english”           /*读取英文字母*/

              g_language=”english”  

            case “Simplified”        /*读取简体字母*/

              g_language=”Simplified”

            case “Traditional”       /*读取繁体字母*/

              g_language=”Traditional”

     end choose

   

     w_login.title      =profileString (g_language_inifile,g_language,”appname”,””)

     st_language.text   =profileString (g_language_inifile,g_language,”language”,””)

     cb_db.text         =profilestring (g_language_inifile,g_language,”connect”,””)

     st_userid.text     =profilestring (g_language_inifile,g_language,”userid”,””)

     st_username.text   =profilestring (g_language_inifile,g_language,”username”,””)

     st_pwd.text        =profilestring (g_language_inifile,g_language,”pwd”,””)

     cb_login.text      =profilestring (g_language_inifile,g_language,”login”,””)

     cb_exit.text       =profilestring (g_language_inifile,g_language,text,””)
   end if
  2>  cb_db:clicked() returns long[pbm_bnclicked]

     

    /*打开窗口*/

    

      open(w_db_option_check)

      close(w_login) 

  3>  cb_exit:clicked() returns long[pbm_bnclicked]

     

    /*关闭父窗口*/

    close(parent)
  4>  cb_login:clicked() returns long[pbm_bnclicked]

     /* 1.读取用户与密码*/

      string c_user,c_pwd,right_pwd

      c_user=””

      c_pwd=””

      right_pwd=””

      c_user=trim(ddlb_user.text)

      c_pwd=trim(sle_pwd.text)

     /* 2.判断用户与密码*/

       select password into:right_pwd

       from erp_baisc_users

       where userid=:c_user using sqlca;

      

       if right_pwd <> c_pwd then

      /* 3.密码错误翻译*/   

        string s_warning,s_password_error

        s_warning=profilestring (g_language_inifile,g_language,”warning”,””)

        s_password_error=profilestring(g_language_inifile,g_language,”password_error”,””)
        messagebox(s_warning,s_password_error)

        sle_pwd.text=””

        sle_pwd.setfocus()

        right_pwd=””

      /* 4. 密码正确*/

        /*打开主窗口*/

         open(w_mian)

         close(parent)

    end if
  4> ddlb_language    selectionchanged[integer index] returns long[pbm_bnclicked]

     /* 1.全局变量定义

        string g_language

        string g_language_inifile=”j:/my learn/demo/language.ini”

     */

    

     /* 2.读取用户选择的语言*/

        g_language=trim(ddlb_language.text)

     

     /* 3.判断配置文件是否存在?*/

        if not FileExists (g_language_inifile) then

           return

        end if

     /* 4.设置用户语言选择结果*/

        choose case g_language

           case “english”      /*读取英文字母*/ 

        choose case g_language

           case “simplified”   /*读取简体字母*/

        choose case g_language

           case “traditional”  /*读取繁体字母*/

        end choose

     /* 5.改变当前窗口控件的语言*/

        w_login.title      =profilestring (g_language_inifile,g_language,”appname”,””)

        st_language.text   =profilestring (g_language_inifile,g_language,”language”,””)

        cb_db.text         =profilestring (g_language_inifile,g_language,”connect”,””)

        st_userid.text     =profilestring (g_language_inifile,g_language,”userid”,””)

        st_username.text   =profilestring (g_language_inifile,g_language,”username”,””)

        st_pwd.text        =profilestring (g_language_inifile,g_language,”pwssword”,””)

        cb_login.text      =profilestring (g_language_inifile,g_language,”login”,””)

        cb_exit.text       =profilestring (g_language_inifile,g_language,”exit”,””)

 

   5>ddlb_user       selectionchanged [integer index] returns long [pbm_bnclicked]

    

       string c_userid,c_username

       c_userid=trim(ddlb_user.text)

       sle_username.text=c_username

       select username into:c_username

       from erp_basic_users

       where userid=:c_userid using sqlca;

  

三、  w_db_option_check  窗口
    1>  w_db_option_check   open[] returns long [pbm_bnclicked]

       /* 1.判断配置文件是否存在*/

          if not FileExists (g_language_inifile) then

             return

          end if

       /* 2.改变当前窗口控件的语言*/

          this.title        =profilestring (g_language_inifile,g_language,”warning”,””)

          st_username.text  =profilestring (g_language_inifile,g_language,”username”,””)

          st_pwd.text       =profilestring (g_language_inifile,g_language,”password”,””)

          cb_checkpwd.text  =profilestring (g_language_inifile,g_language,”checkpwd”,””)

   

    2>  cb_checkpwd  click[] returns long [pbm_bnclicked]

       /* 1.警告框信息文字翻译*/

          string s_waring, s_password_error

          s_warning         =profilestring (g_language_inifile,g_language,”warning”,””)

          s_password_error  =profilestring (g_language_inifile,g_language,”password_error”,””)

       /* 2.密码输入检查*/

          if sle_pwd.text=”123″ then

             open(w_db_option)

          else

             messagebox(s_warning,s_password_error)

          end if

          close(parent)

    

四、 w_db_option    窗口
    1> w_db_option   open[] returns long [pbm_bnclicked]

       /* 1.判断配置文件是否存在?*/

          if not FileExists (g_language_inifile) then

             return

          end if

       /* 2.改变当前窗口控件的语言*/

          this.title         =profilestring (g_language_inifile,g_language,”db_connect_mangae”,””)

          st_servername.text =profilestring (g_language_inifile,g_language,”servername”,””)

          st_database.text   =profilestring (g_language_inifile,g_language,”database”,””)

          st_userid.text     =profilestring (g_language_inifile,g_language,”userid”,””)

          st_password.text   =profilestring (g_language_inifile,g_language,”password”,””)

         

          cb_default.text    =profilestring (g_language_inifile,g_language,”default”,””)

          cb_read.text       =profilestring (g_language_inifile,g_language,”read”,””)

          cb_write.text   =profilestring (g_language_inifile,g_language,”write”,””)

   

    2> cb_default   clicked [] returns long[pbm_bnclicked]   

       /* 1.设置默认连接参数到5个全局变量*/

          as_server               =”dxxo”

          as_dbms                 =”MSS Microsoft SQL Server 6.x”

          as_database             =”erp”

          as_logid                =”sa”

          as_logpass              =”lidengzhi”

       /* 2.五个全局变量到五个文本框*/

          sle_servername.text     =as_server

          sle_dbms.text           =as_dbms

          sle_database.text       =database

          sle_logpassword.text    =as_logpass

          sle_logid.text          =as_logid

       /* 3.设置默认连接参数更新到db.ini文件中*/

          if FileExists (ls_inifile) then

             setprofilestring (ls_inifile,”database”,”servername”,as_server)

             setprofilestring (ls_inifile,”database”,”DBMS”,as_dbms)

             setprofilestring (ls_inifile,”database”,”database”,as_database)

             setprofilestring (ls_inifile,”database”,”logpassword”,as_logpass)

             setprofilestring (ls_inifile,”database”,”userid”,as_logid)

          end if

    3> cb_read clicked [] returns long[pbm_bnclicked]

       /*读取db.ini文件设置值到文本框*/

       if FileExists (ls_inifile) then

          sle_servername.text    =profilestring (ls_inifile,”database”,”servername”,””)

          sle_dbms.text          =profilestring (ls_inifile,”database”,”dbms”,””)

          sle_database.text      =profilestring (ls_inifile,”database”,”database”,””)  

          sle_logid.text         =profilestring (ls_inifile,”database”,”logid”,””)

          sle_logid.text         =profilestring (ls_inifile,”database”,”logpassword”,””)

       end if
    4> cb_write clicked [] returns long[pbm_bnclicked]

       /* 1.设置参数值存入5个全局变量*/

        as_server       =trim(sle_servername.text)

        as_dbms         =trim(sle_dbms.text)

        as_database     =trim(sle_database.text)

        as_logid        =trim(sle_logid.text)

        as_logpass      =trim(sle_logpassword.text)

       /* 2.检查参数是否都输入完毕?*/

        if len(as_server)=0 or len(as_dbms)=0 or

           len(as_database)=0 or len(as_logid)=0 or len(as_logpass)=0 then

           messagebox(“warning!”,”can’t be null,pls check server,dbms,database,logid,logpass!”)

           return

        end if

       /* 3.设置参数写入db.ini文件中*/

       if FileExists(ls_inifile) then

          SetProfileString (ls_inifile,”Database”,”servername”,as_server)

          SetProfileString (ls_inifile,”Database”,”DBMS”,as_dbms)

          SetProfileString (ls_inifile,”Database”,”Database”,as_database)

          SetProfileString (ls_inifile,”Database”,”LogId”,as_logid)

          SetProfileString (ls_inifile,”Database”,”LogPassWord”,as_logpass)

       end if

       /* 4.重新连接数据库,关闭此窗口*/

        disconnect using SQLCA;

        connect using SQLCA;

        if SQLCA.SQLCode <> 0 then

           MessageBox (“Cannot Connect to Database”,SQLCA.SQLErrText)
        end if

        close(parent)

五、  数据库的设置
     .数据库表erp_baisc_users

     table sql

      create  table erp_baisc_users(

            userid     char(20) NOT NULL,

            username char(30) NOT NULL,

            password char(12) NULL default ‘654321’,

            userofsite     char(4) NULL default ”,

            department varchar(20) NULL default ”,

            statusflag char(1) NULL default ‘0’, )
       alter table erp_baisc_users

       add constraint erp_baisc_users_pk PRIMARY KEY (userid)

       create index erp_baisc_users_ik on erp_baisc_users(userid)
插入试验记录

userid    username    password    userofsite    department    statusflag

DDG01    JORLIN    654321    HK    IT    0

DDG03    DOREN    654321    HK    QA    0

GZ-01    HAWEEN    654321    GZ    QA    0

GZ-02    JESSE    J    GZ    IT    0

六、ini的配置文件
1.数据库连接文件db.ini
db.ini file

[DataBase]

ServerName    =db

DBMS          =MSS Microsoft SQL Server 6.x

Database      =erp

LogId         =sa

LogPassword   =db11
/*———————————————————————————-*/

2.语言配置文件language.ini
[default]

language=Simplified
[english]

appname=PB demo program

language=language

Connect=&Connect DataBase

db_connect_manage=Database Connect Manage

servername=ServerName

database=Database

default=&Default

read    =&Read

write    =&Write

userid    =UserID

username=UserName

PassWord=PassWord

login    =&Login

exit    =&Exit

checkpwd=Check Password

warning =Warning

password_error=password error

insert    =&Insert

delete    =&Delete

modify    =&Modify

save    =&Save
[Simplified]

appname=PB演示程序

language=语言选择

Connect=&C连接数据库

db_connect_manage=数据库连接参数管理

servername=服务器名称

database=数据库

default =&D缺省

read    =&R读取

write    =&W写入
userid    =用户ID

username=用户名称

PassWord=用户密码

login    =&L登录

exit    =&E退出

checkpwd=&C检查密码

warning =警告

password_error=密码错误

insert    =&I插入

delete    =&D删除

modify    =&M修改

save    =&S保存
[Traditional]

appname=PB演示程式

language=語言選擇

Connect=&C連接資料庫

db_connect_manage=資料庫連接參數管理

servername=伺服器名稱

database=資料庫

default =&D缺省

read    =&R讀取

write    =&W寫入
userid    =用戶ID

username=用戶名稱

PassWord=用戶密碼

login    =&L登錄

exit    =&E退出

checkpwd=&C檢查密碼

warning =警告

password_error=密碼錯誤
insert    =&I插入

delete    =&D刪除

modify    =&M修改

save    =&S保存

/*———————————————————————————-*/
七、里面的数据源与窗口
1.应用程序对象清单

   应用程序名称:demo

   登陆窗口名称:w_login

   密码验证窗口:w_db_option_check

   数据库连接参数管理:w_db_option

   主窗口:w_main

   数据窗口:dw_userlist

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/36025.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注