www.pudn.com > vb-sql-server.rar > Module1.bas, change:2009-06-07,size:3415b


Attribute VB_Name = "Module1" 
Public UserName As String 
Public fMainForm As frmMain 
Public gintWZSmode As Integer 'for WZ setup 
Public gintSSmode As Integer 'for Service setup 
Public gintGFSmode As Integer 'for GF setup 
Public gintKHSmode As Integer 'for KH setup 
Public gintYWYLBSmode As Integer 'for YWYLB setup 
Public gintYWYSmode As Integer 'for YWY setup 
Public gintCKSmode As Integer 'for CK setup 
Public gintWZLBSmode As Integer 'for WZLB setup 
Public gintWZYSSmode As Integer 'for WZYS setup 
 
Public gintDHmode As Integer 'for din huo 
Public gintINHmode As Integer 'for ruku huo 
Public gintXSDHmode As Integer 'for xiao shou ding dan 
Public gintOUTHmode As Integer 'for xiao shou ding dan 
Public gintZCmode As Integer 'for shang pin zhuan cang 
Public gintGETmode As Integer 'for ying shou 
Public gintOFFERmode As Integer 'for YING FU 
Public gintPLLISTmode As Integer 'for PEI LIAO LIST 
Public gintPLmode As Integer 'for PEI LIAO 
Public gintPLANGLISTmode As Integer 'for plan list 
Public gintPLANGmode As Integer 'for plan 
Public aa As String 
     
Sub Main() 
    Dim fLogin As New frmLogin 
    fLogin.Show vbModal 
    If Not fLogin.OK Then 
        'Login Failed so exit app 
        End 
    End If 
    Unload fLogin 
 
 
    Set fMainForm = New frmMain 
    fMainForm.Show 
End Sub 
 
Public Function ConnectString() _ 
   As String 
'returns a DB ConnectString 
' ConnectString = "FileDSN=my_mobile_data.dsn;UID=sa;PWD=sa"  '用DSN方式打开数据库 
   '直接打开数据库  ???????? 
   ConnectString = "DRIVER=SQL Server;SERVER=" & "NCWU-XQ\XQ" & _ 
        ";UID=" & "sa" & ";PWD=" & "sa" & ";DATABASE=my_mobile" 
    
    
End Function 
Public Function ExecuteSQL(ByVal SQL _ 
   As String, MsgString As String) _ 
   As ADODB.Recordset 
'executes SQL and returns Recordset 
   Dim cnn As ADODB.Connection 
   Dim rst As ADODB.Recordset 
   Dim sTokens() As String 
    
  ' On Error GoTo ExecuteSQL_Error 
    
   sTokens = Split(SQL) 
   Set cnn = New ADODB.Connection 
    
    
    'cn.ConnectionString = "DSN=" & _ 
        ";DATABASE=pubs;UID=" & sLoginID & _ 
        ";PWD=" & sPassword 
         
    
    
    
   cnn.Open ConnectString 
 '  cnn.ConnectionString = ConnectString  '非dsn 
  '    cnn.Properties("Prompt") = adPromptComplete 
    
    'MsgBox cnn.ConnectionString 
  '  cnn.Open 
    
    
   If InStr("INSERT,DELETE,UPDATE,EXECUTE", UCase$(sTokens(0))) Then 
      cnn.Execute (SQL) 
      MsgString = sTokens(0) & _ 
         " query successful" 
   Else 
      Set rst = New ADODB.Recordset 
      rst.Open Trim$(SQL), cnn, _ 
         adOpenKeyset, _ 
         adLockOptimistic 
      'rst.MoveLast     'get RecordCount 
      Set ExecuteSQL = rst 
      MsgString = "查询到" & rst.RecordCount & _ 
         " 条记录 " 
   End If 
ExecuteSQL_Exit: 
   Set rst = Nothing 
   Set cnn = Nothing 
   Exit Function 
    
    
ExecuteSQL_Error: 
   MsgString = "查询错误: " & _ 
      Err.Description 
   Resume ExecuteSQL_Exit 
End Function 
Public Sub EnterToTab(Keyasc As Integer) 
    If Keyasc = 13 Then 
        SendKeys "{TAB}" 
    End If 
End Sub 
Public Function GetRkno() As String 
    GetRkno = Format(Now, "yymmddhhmmss") 
    Randomize 
    GetRkno = GetRkno & Int((99 - 10 + 1) * Rnd + 10) 
End Function 
 
 
Public Function GetRkno1() As String 
    Randomize 
    GetRkno1 = Int((99999999 - 10000000 + 1) * Rnd + 10000000) 
End Function