frmNewDB.frm
上传用户:yexiandon
上传日期:2022-07-12
资源大小:895k
文件大小:12k
- VERSION 5.00
- Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
- Begin VB.Form frmNewDB
- BorderStyle = 3 'Fixed Dialog
- Caption = "新建帐套"
- ClientHeight = 1710
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 4980
- Icon = "frmNewDB.frx":0000
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 1710
- ScaleWidth = 4980
- ShowInTaskbar = 0 'False
- StartUpPosition = 1 '所有者中心
- Begin MSComDlg.CommonDialog Dialog
- Left = 3960
- Top = 1080
- _ExtentX = 847
- _ExtentY = 847
- _Version = 393216
- End
- Begin VB.Frame Frame1
- Height = 1455
- Left = 120
- TabIndex = 2
- Top = 120
- Width = 3615
- Begin VB.CommandButton Command3
- Cancel = -1 'True
- Caption = "…"
- Height = 300
- Left = 3120
- TabIndex = 9
- Top = 960
- Width = 300
- End
- Begin VB.TextBox Text3
- Height = 270
- Left = 960
- Locked = -1 'True
- TabIndex = 7
- Top = 960
- Width = 2175
- End
- Begin VB.TextBox Text1
- Height = 270
- Left = 960
- TabIndex = 4
- Top = 240
- Width = 2415
- End
- Begin VB.TextBox Text2
- Height = 270
- Left = 960
- TabIndex = 3
- Top = 600
- Width = 2415
- End
- Begin VB.Label Label3
- AutoSize = -1 'True
- Caption = "注意:数据库名请不要用汉字!"
- ForeColor = &H000000FF&
- Height = 180
- Left = 120
- TabIndex = 10
- Top = 0
- Width = 2520
- End
- Begin VB.Label Label4
- AutoSize = -1 'True
- Caption = "保 存 到"
- Height = 180
- Left = 120
- TabIndex = 8
- Top = 1005
- Width = 720
- End
- Begin VB.Label Label1
- AutoSize = -1 'True
- Caption = "帐 套 名"
- Height = 180
- Left = 120
- TabIndex = 6
- Top = 285
- Width = 720
- End
- Begin VB.Label Label2
- AutoSize = -1 'True
- Caption = "数据库名"
- Height = 180
- Left = 120
- TabIndex = 5
- Top = 630
- Width = 720
- End
- End
- Begin VB.CommandButton Command1
- Caption = "确定"
- Default = -1 'True
- Height = 300
- Left = 3960
- TabIndex = 0
- Top = 240
- Width = 900
- End
- Begin VB.CommandButton Command2
- Caption = "取消"
- Height = 300
- Left = 3960
- TabIndex = 1
- Top = 630
- Width = 900
- End
- End
- Attribute VB_Name = "frmNewDB"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- '****************************************************************************
- '人人为我,我为人人
- '枕善居收藏整理
- '发布日期:2008/01/21
- '描 述:汽车维修管理系统SQL2000版
- '网 站:http://www.Mndsoft.com/ (VB6源码博客)
- '网 站:http://www.VbDnet.com/ (VB.NET源码博客,主要基于.NET2005)
- 'e-mail :Mndsoft@163.com
- 'e-mail :Mndsoft@126.com
- 'OICQ :88382850
- ' 如果您有新的好的代码别忘记给枕善居哦!
- '****************************************************************************
- Option Explicit
- Private Sub Command1_Click()
- NewDbCreate
- End Sub
-
- Private Sub NewDbCreate()
- Dim cnn As New ADODB.Connection
- Dim Rs As New ADODB.Recordset
- Dim NewZT, NewDB, s, DBpath As String
- ' Dim prgPath As String
- Dim i, ii As Integer
- NewZT = Trim(Text1.Text)
- NewDB = Trim(Text2.Text)
- DBpath = Text3.Text
- If NewZT = "" Then MsgBox "帐套名不能为空!": Exit Sub
- If NewDB = "" Then MsgBox "数据库名不能为空!": Exit Sub
- If DBpath = "" Then MsgBox "请选择数据存放路径!": Exit Sub
- ' prgPath = IIf(Right(App.Path, 1) = "", App.Path, App.Path & "")
- '数据库名必须是字母
- For ii = 1 To Len(Text2.Text)
- s = Mid(Me.Text2.Text, ii, 1)
- If Asc(s) > 64 And Asc(s) < 91 Or Asc(s) > 96 And Asc(s) < 123 Then
- Else
- MsgBox "输入错误,请输入英文字母!", , "提示:"
- Text2.SetFocus
- Text2.SelStart = 0
- Text2.SelLength = Len(Text2.Text)
- Exit Sub
- End If
- Next
-
- Screen.MousePointer = vbHourglass
- g_CnStr = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
- "User ID=" & frmConnData.txtSa & _
- ";Data Source=" & frmConnData.txtServer & _
- ";pwd=" & frmConnData.txtSaPass & _
- ";Initial Catalog="
- '创建数据库
- 'On Error Resume Next
- cnn.ConnectionString = g_CnStr
- cnn.Open
- cnn.BeginTrans
- cnn.Execute ("CREATE DATABASE [" & NewDB & "] ON (NAME = N'" & _
- NewDB & "', FILENAME = N'" & _
- DBpath & NewDB & ".mdf' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'" & _
- NewDB & "_log', FILENAME = N'" & _
- DBpath & NewDB & "_log.LDF' , FILEGROWTH = 10%) COLLATE Chinese_PRC_CI_AS")
-
- cnn.Execute ("INSERT INTO t_Account_qxzt(DBNM,ZTNM) VALUES ('" & NewDB & "','" & NewZT & "')")
- If Err.Number = 0 Then cnn.CommitTrans Else cnn.RollbackTrans: GoTo ErrHdl
- cnn.Close
-
- '创建表
- cnn.ConnectionString = g_CnStr & NewDB
- cnn.Open
- cnn.BeginTrans
-
-
- cnn.Execute "CREATE TABLE [dbo].[Clerk] (" & _
- "[clkID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[clkName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[clkSex] [bit] NOT NULL ," & _
- "[clkDepart] [int] NULL ," & _
- "[clkZw] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[clkInDate] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[clkTel] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[Client] (" & _
- "[ID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[IDN] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[CarNo] [varchar] (15) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[CarType] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[MotoNo] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[MainNo] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[inDate] [smalldatetime] NOT NULL ," & _
- "[stID] [int] NOT NULL ," & _
- "[clkID] [int] NOT NULL ," & _
- "[cName] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[cTel] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[Demo] [varchar] (160) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[fpnr] [varchar] (20) DEFAULT '' COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[fpje] [money] DEFAULT 0 NOT NULL ," & _
- "[jsfs] [varchar] (12) DEFAULT '' COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[jsje] [money] DEFAULT 0 NOT NULL ," & _
- "[isfns] [bit] DEFAULT 0 NOT NULL ," & _
- "[jsr] [varchar] (10) DEFAULT '' COLLATE Chinese_PRC_CI_AS NOT NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[Depart] (" & _
- "[DepartId] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[DName] [nvarchar] (30) COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[Dbak] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[PeiJian] (" & _
- "[ID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[pName] [varchar] (30) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[pType] [varchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[pCID] [int] NOT NULL ," & _
- "[pUnit] [varchar] (12) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[pDemo] [smalldatetime] NOT NULL ," & _
- "[pNum] [Numeric](18, 0)) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[State] (" & _
- "[ID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[SuperID] [int] NOT NULL ," & _
- "[State] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[Store] (" & _
- "[ID] [int] NOT NULL ," & _
- "[Type] [smallint] NOT NULL ," & _
- "[FDate] [datetime] NOT NULL ," & _
- "[cID] [int] NOT NULL ," & _
- "[carID] [Int]) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[SubStore] (" & _
- "[ID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[sID] [int] NOT NULL ," & _
- "[Line] [int] NOT NULL ," & _
- "[pID] [int] NOT NULL ," & _
- "[pNum] [decimal](18, 0) NOT NULL ," & _
- "[pPrice] [money] NOT NULL ," & _
- "[pDemo] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[Users] (" & _
- "[UserId] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[UserName] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[Upass] [nvarchar] (50) DEFAULT '' COLLATE Chinese_PRC_CI_AS NULL ," & _
- "[IsSys] [bit] DEFAULT 0 NOT NULL ," & _
- "[QuanXian] [int] DEFAULT 0 NULL ," & _
- "[LastLogin] [smalldatetime] DEFAULT '' NULL) ON [PRIMARY]"
- cnn.Execute "CREATE TABLE [dbo].[WeiXiu] (" & _
- "[ID] [int] IDENTITY (1, 1) NOT NULL ," & _
- "[wName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
- "[wFdate] [smalldatetime] NOT NULL ," & _
- "[wTdate] [smalldatetime] NOT NULL ," & _
- "[wMin] [int] NOT NULL ," & _
- "[carID] [int] NOT NULL ," & _
- "[cID] [int] NOT NULL ," & _
- "[wPrice] [money] NOT NULL ," & _
- "[wDemo] [varchar] (150) COLLATE Chinese_PRC_CI_AS NOT NULL) ON [PRIMARY]"
- cnn.Execute "INSERT INTO Users " & _
- "(UserName, Upass, IsSys, QuanXian, LastLogin) " & _
- "VALUES ('管理员', '', 1, 65535, '" & Now() & "')"
- cnn.Execute "CREATE VIEW dbo.V_Store AS " & _
- "SELECT dbo.SubStore.sID, dbo.SubStore.pID, dbo.SubStore.pNum, dbo.SubStore.pPrice," & _
- "dbo.Store.Type , dbo.Store.FDate, dbo.Store.cID, dbo.SubStore.pDemo " & _
- "FROM dbo.Store INNER JOIN " & _
- "dbo.SubStore ON dbo.Store.ID = dbo.SubStore.sID AND dbo.Store.Type = 1 "
- cnn.Execute "CREATE VIEW dbo.V_Serch AS " & _
- "SELECT C.CarNo, C.inDate, P.pName, P.pDemo AS pDate, P.pNum, S.pNum AS sNum, " & _
- "S.pPrice, S.pDemo AS pBak, S.FDate " & _
- "FROM dbo.PeiJian P LEFT OUTER JOIN " & _
- "dbo.Client C ON C.ID = P.pCID LEFT OUTER JOIN " & _
- "dbo.V_Store S ON S.pID = P.ID "
-
-
- If Err.Number = 0 Then cnn.CommitTrans Else cnn.RollbackTrans: GoTo ErrHdl
- cnn.Close
- Set cnn = Nothing
- Screen.MousePointer = vbDefault
- If Err.Number = 0 Then MsgBox "新帐套创建成功!", , "恭喜!" Else GoTo ErrHdl
- Unload Me
- Exit Sub
- ErrHdl:
- MsgBox Err.Description
- If cnn.State = 1 Then cnn.Close
- Screen.MousePointer = vbDefault
- End Sub
- Private Sub Command2_Click()
- Unload Me
- End Sub
- Private Sub Command3_Click()
- Text3.Text = BrowseForFolder(hwnd, "请选择数据库保存路径。")
- Text3.Text = IIf(Right(Text3.Text, 1) = "", Text3.Text, Text3.Text & "")
- End Sub
- Private Sub Form_Activate()
- Text1.SetFocus
- End Sub