Form_RestoreDatabase.frm
上传用户:zhpu1995
上传日期:2013-09-06
资源大小:61151k
文件大小:12k
源码类别:

企业管理

开发平台:

Visual Basic

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Frm_RestoerDatabase 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "套帐恢复"
  6.    ClientHeight    =   4215
  7.    ClientLeft      =   3165
  8.    ClientTop       =   1890
  9.    ClientWidth     =   7830
  10.    HelpContextID   =   1018
  11.    Icon            =   "Form_RestoreDatabase.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   4215
  16.    ScaleWidth      =   7830
  17.    StartUpPosition =   2  '屏幕中心
  18.    Begin VB.CommandButton Command3 
  19.       Caption         =   "删除"
  20.       Height          =   285
  21.       Left            =   6300
  22.       TabIndex        =   13
  23.       ToolTipText     =   "删除备份文件"
  24.       Top             =   3330
  25.       Width           =   1245
  26.    End
  27.    Begin VB.TextBox Text1 
  28.       Height          =   285
  29.       Index           =   3
  30.       Left            =   5850
  31.       Locked          =   -1  'True
  32.       TabIndex        =   12
  33.       Top             =   2460
  34.       Width           =   1635
  35.    End
  36.    Begin VB.CommandButton Command2 
  37.       Height          =   315
  38.       Left            =   7470
  39.       Picture         =   "Form_RestoreDatabase.frx":038A
  40.       Style           =   1  'Graphical
  41.       TabIndex        =   10
  42.       Top             =   2460
  43.       Width           =   315
  44.    End
  45.    Begin VB.CommandButton Command1 
  46.       Caption         =   "取消&C"
  47.       Height          =   285
  48.       Index           =   1
  49.       Left            =   6300
  50.       TabIndex        =   9
  51.       Top             =   3750
  52.       Width           =   1245
  53.    End
  54.    Begin VB.CommandButton Command1 
  55.       Caption         =   "恢复"
  56.       Height          =   285
  57.       Index           =   0
  58.       Left            =   6300
  59.       TabIndex        =   8
  60.       ToolTipText     =   "恢复套帐"
  61.       Top             =   2910
  62.       Width           =   1245
  63.    End
  64.    Begin VB.TextBox Text1 
  65.       Height          =   285
  66.       Index           =   2
  67.       Left            =   5850
  68.       TabIndex        =   7
  69.       Top             =   1740
  70.       Width           =   1635
  71.    End
  72.    Begin VB.TextBox Text1 
  73.       Height          =   285
  74.       Index           =   1
  75.       Left            =   5850
  76.       TabIndex        =   6
  77.       Top             =   1020
  78.       Width           =   1635
  79.    End
  80.    Begin VB.TextBox Text1 
  81.       Height          =   285
  82.       Index           =   0
  83.       Left            =   5850
  84.       TabIndex        =   3
  85.       Top             =   360
  86.       Width           =   1635
  87.    End
  88.    Begin VB.Frame Frame1 
  89.       Caption         =   "备份文件"
  90.       Height          =   4155
  91.       Left            =   30
  92.       TabIndex        =   0
  93.       Top             =   30
  94.       Width           =   5685
  95.       Begin MSComctlLib.ListView List_data 
  96.          Height          =   3915
  97.          Left            =   60
  98.          TabIndex        =   1
  99.          Top             =   180
  100.          Width           =   5565
  101.          _ExtentX        =   9816
  102.          _ExtentY        =   6906
  103.          View            =   3
  104.          LabelEdit       =   1
  105.          LabelWrap       =   -1  'True
  106.          HideSelection   =   0   'False
  107.          FullRowSelect   =   -1  'True
  108.          _Version        =   393217
  109.          ForeColor       =   -2147483640
  110.          BackColor       =   -2147483643
  111.          BorderStyle     =   1
  112.          Appearance      =   1
  113.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  114.             Name            =   "宋体"
  115.             Size            =   9
  116.             Charset         =   134
  117.             Weight          =   400
  118.             Underline       =   0   'False
  119.             Italic          =   0   'False
  120.             Strikethrough   =   0   'False
  121.          EndProperty
  122.          NumItems        =   4
  123.          BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  124.             Text            =   "数据库名"
  125.             Object.Width           =   2540
  126.          EndProperty
  127.          BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  128.             SubItemIndex    =   1
  129.             Text            =   "备份文件名"
  130.             Object.Width           =   2540
  131.          EndProperty
  132.          BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  133.             SubItemIndex    =   2
  134.             Text            =   "备份时间"
  135.             Object.Width           =   3881
  136.          EndProperty
  137.          BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  138.             SubItemIndex    =   3
  139.             Text            =   "备份路径"
  140.             Object.Width           =   8819
  141.          EndProperty
  142.       End
  143.    End
  144.    Begin VB.Label Label1 
  145.       Caption         =   "路径:"
  146.       Height          =   165
  147.       Index           =   3
  148.       Left            =   5850
  149.       TabIndex        =   11
  150.       Top             =   2250
  151.       Width           =   795
  152.    End
  153.    Begin VB.Label Label1 
  154.       Caption         =   "数据库名:"
  155.       Height          =   165
  156.       Index           =   2
  157.       Left            =   5850
  158.       TabIndex        =   5
  159.       Top             =   1500
  160.       Width           =   795
  161.    End
  162.    Begin VB.Label Label1 
  163.       AutoSize        =   -1  'True
  164.       Caption         =   "套帐名称:"
  165.       Height          =   180
  166.       Index           =   1
  167.       Left            =   5850
  168.       TabIndex        =   4
  169.       Top             =   840
  170.       Width           =   810
  171.    End
  172.    Begin VB.Label Label1 
  173.       Caption         =   "编号:"
  174.       Height          =   255
  175.       Index           =   0
  176.       Left            =   5850
  177.       TabIndex        =   2
  178.       Top             =   150
  179.       Width           =   795
  180.    End
  181. End
  182. Attribute VB_Name = "Frm_RestoerDatabase"
  183. Attribute VB_GlobalNameSpace = False
  184. Attribute VB_Creatable = False
  185. Attribute VB_PredeclaredId = True
  186. Attribute VB_Exposed = False
  187. Dim mitem As ListItem
  188. Dim R_SQLSERVER As String
  189. Dim R_USERID As String
  190. Dim R_PASSWORD As String
  191. Private Sub Command1_Click(Index As Integer)
  192.     If Index = 1 Then Unload Me: Exit Sub
  193.     
  194.     If List_data.ListItems.Count < 1 Then MsgBox "没有可恢复的数据库! ", 16: Exit Sub
  195.     
  196.     YesNoStr = MsgBox("你是否要恢复数据库名为(" & List_data.SelectedItem.Text & ")和数据库备份文件名为(" & List_data.SelectedItem.SubItems(1) & ")的套帐?  ", vbYesNo + 32)
  197.     If YesNoStr = vbNo Then Exit Sub
  198.     
  199.     If Trim(Text1(0).Text) = "" Then MsgBox "套帐编码不能为空! ", 16: Text1(0).SetFocus: Exit Sub
  200.     If Trim(Text1(1).Text) = "" Then MsgBox "套帐名称不能为空! ", 16: Text1(1).SetFocus: Exit Sub
  201.     If Trim(Text1(2).Text) = "" Then MsgBox "数据库名不能为空! ", 16: Text1(2).SetFocus: Exit Sub
  202.     If IsNumeric(Text1(2).Text) Then MsgBox "数据库名不能为数值! ", 16: Text1(2).SetFocus: Exit Sub
  203.     If Trim(Text1(3).Text) = "" Then MsgBox "数据库路径不能为空! ", 16: Text1(3).SetFocus: Exit Sub
  204.     '--------------------------
  205.     
  206.     Dim Data_Error As Integer
  207.     Dim Data_ErrorName As String
  208.     On Error GoTo Exit_error
  209.     
  210.     TextFile
  211.     Class.StatusBar "正在检测数据库信息...", False
  212.     Me.MousePointer = 12
  213.     If Conn_System1.State = 1 Then Conn_System1.Close
  214.     Conn_System1.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=" & R_SQLSERVER & "; Initial Catalog=master;", R_USERID, R_PASSWORD
  215.     Class.StatusBar "", True
  216.     Me.MousePointer = 0
  217.     Class.StatusBar "正在恢复套帐信息...", False
  218.     Me.MousePointer = 12
  219.     
  220.     If Cw_DataEnvi.Connection2.State = 1 Then Cw_DataEnvi.Connection2.Close
  221.     Cw_DataEnvi.Connection2.Open "Provider=SQLOLEDB.1;Persist Security Info=False;Data Source=" & R_SQLSERVER & "; Initial Catalog=master;", R_USERID, R_PASSWORD
  222.     
  223.     '-----------------
  224.     Cw_DataEnvi.dbo_HD_AddDatabase Trim(Text1(2).Text), Trim(Text1(3).Text) _
  225.                   , Text1(1).Tag, "Erp5Data", List_data.SelectedItem.SubItems(3), Trim(Text1(1).Text), Trim(Text1(0).Text) _
  226.                   , R_SQLSERVER, "SQL Server 7.0", Data_Error, Data_ErrorName
  227.                   
  228.     Class.StatusBar "", True
  229.     Me.MousePointer = 0
  230.     
  231.     If Cw_DataEnvi.Connection2.State = 1 Then Cw_DataEnvi.Connection2.Close
  232.     If Data_Error = 1 Then
  233.        Form_main.Form_Load
  234.        MsgBox "套帐恢复成功! ", 48
  235.        Unload Me
  236.       Else
  237.         MsgBox "套帐恢复失败! ", 16
  238.     End If
  239.     Exit Sub
  240.     
  241.     '-----------------
  242. Exit_error:
  243.     Class.StatusBar "", True
  244.     Me.MousePointer = 0
  245.     Select Case Err.Number
  246.            Case -2147467259
  247.                  MsgBox "数据服务器错误!", 16
  248.            Case -2147217843
  249.                 MsgBox "用户名或口令错误!", 16
  250.            Case Else
  251.                 MsgBox Err.Description & "(" & Err.Number & ")", 16
  252.     End Select
  253. End Sub
  254. Private Sub Command2_Click()
  255. Frm_Path.Show 1
  256. If PathStr <> "" Then Text1(3).Text = PathStr
  257. End Sub
  258. Private Sub Command3_Click()
  259. On Error GoTo Exit_error
  260.     Dim DiskFile As String
  261.     If List_data.ListItems.Count < 1 Then MsgBox "没有可删除的备份文件! ", 16: Exit Sub
  262.     
  263.     YesNoStr = MsgBox("你是否要删除文件名为(" & List_data.SelectedItem.SubItems(1) & ")的数据库备份文件?  ", vbYesNo + 32)
  264.     If YesNoStr = vbNo Then Exit Sub
  265.     DiskFile = Trim(List_data.SelectedItem.SubItems(3)) + "" + Trim(List_data.SelectedItem.SubItems(1)) + ".Bak"
  266.     If Len(Dir$(DiskFile)) > 0 Then
  267.         Kill DiskFile
  268.     End If
  269.     Conn_System.Execute "delete  HDSystem_BakDataBases where Number=" & Mid(List_data.SelectedItem.Key, 2, Len(List_data.SelectedItem.Key))
  270.     Form_Load
  271.     Exit Sub
  272.     
  273. Exit_error:
  274.     
  275.        MsgBox Err.Description & "(" & Err.Number & ")", 16
  276.  
  277. End Sub
  278. Private Sub Form_Load()
  279.     Dim aDo_Bakdatabase As New Recordset
  280.     Set aDo_Bakdatabase = Conn_System.Execute("select * from HDSystem_BakDataBases")
  281.     With aDo_Bakdatabase
  282.     List_data.ListItems.Clear
  283.     Do While Not .EOF
  284.         Set mitem = List_data.ListItems.Add()
  285.         mitem.Text = !DataBaseName
  286.         mitem.SubItems(1) = !BakName
  287.         mitem.SubItems(2) = !BakDate
  288.         mitem.SubItems(3) = !BakPath
  289.         mitem.Key = "T" & !Number
  290.        
  291.         .MoveNext
  292.     Loop
  293.     .Close
  294.     Set aDo_Bakdatabase = Nothing
  295.     End With
  296.     
  297.     If List_data.ListItems.Count > 0 Then
  298.        Text1(3).Text = App.Path
  299.        Text1(1).Text = List_data.SelectedItem.Text
  300.        Text1(1).Tag = List_data.SelectedItem.SubItems(1)
  301.        Text1(2).Text = List_data.SelectedItem.Text
  302.     End If
  303. End Sub
  304. Private Sub List_data_ItemClick(ByVal Item As MSComctlLib.ListItem)
  305.    Text1(1).Text = List_data.SelectedItem.Text
  306.    Text1(1).Tag = List_data.SelectedItem.SubItems(1)
  307.    Text1(2).Text = List_data.SelectedItem.Text
  308. End Sub
  309. Private Sub TextFile()
  310.     On Error Resume Next
  311.     Dim Fsote As Variant
  312.     Dim Tste As Variant
  313.       Dim Dqhs As Integer, Dqnr As String
  314.       Dim i As Integer
  315.       Set Fsote = CreateObject("Scripting.FileSystemObject")
  316.       Set Tste = Fsote.OpenTextFile(App.Path + "System_Erp.txt", 1)
  317.       For i = 1 To 4
  318.           Dqnr = Trim(Tste.ReadLine)
  319.           If InStr(1, UCase(Dqnr), "SQLSERVER=") <> 0 Then
  320.              R_SQLSERVER = Mid(Dqnr, InStr(1, UCase(Dqnr), "SQLSERVER=") + 10, Len(Dqnr))
  321.           End If
  322.           If InStr(1, UCase(Dqnr), "USERID=") <> 0 Then
  323.              R_USERID = Mid(Dqnr, InStr(1, UCase(Dqnr), "USERID=") + 7, Len(Dqnr))
  324.           End If
  325.           If InStr(1, UCase(Dqnr), "PASSWORD=") <> 0 Then
  326.              R_PASSWORD = Mmjm2(Mid(Dqnr, InStr(1, UCase(Dqnr), "PASSWORD=") + 9, Len(Dqnr)))
  327.           End If
  328.       Next i
  329.       Exit Sub
  330. End Sub
  331. Private Function Mmjm2(Srmm As String) As String                  '密码解密模块
  332.    Dim Zfcte As Integer
  333.    Mmjm2 = ""
  334.    For jsqte = 1 To Int(Len(Srmm) / 3)
  335.        Zfcte = Val(Mid(Srmm, (jsqte - 1) * 3 + 1, 3)) - Int(Len(Srmm) / 3) - jsqte
  336.        Mmjm2 = Mmjm2 + Chr(Zfcte)
  337.    Next jsqte
  338. End Function
  339. Private Sub Text1_Change(Index As Integer)
  340.     If Index = 3 Then
  341.        If Len(Trim(Text1(3).Text)) = 3 Then Text1(3).Text = Mid(Trim(Text1(3)), 1, 2)
  342.     End If
  343. End Sub