Đang chuẩn bị liên kết để tải về tài liệu:
Visual Basic .NET at Work Building 10 Enterprise Projects phần 10
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
một cho các nhà cung cấp các dữ liệu và một cho người tiêu dùng. Các chương trình này, bằng văn bản cho phù hợp với một nhà phân phối đồ chơi hư cấu, có thể dễ dàng được sửa đổi để phù hợp với nhu cầu của riêng bạn. | 446 Project 10 Dim conn As New SqlConnection CONNSTR Dim sSQL As String Make sure we are using a valid date. If calStart.SelectedDate Now Then lblResult.ForeColor System.Drawing.Color.Red lblResult.Text You must select a date equal to or _ later than today. Exit Sub End If Prepare our INSERT statement that will save the request. sSQL INSERT INTO VacationRequest EmpID StartDate _ Hours Approved _ VALUES eID _ calStart.SelectedDate.ToString _ CInt tbHours.Text 0 Attemp the INSERT. Dim cmd As New SqlCommand sSQL conn Try conn.Open cmd.ExecuteNonQuery conn.Close lblResult.ForeColor System.Drawing.Color.RoyalBlue lblResult.Text Vacation request was successfully _ submitted calStart.SelectedDate _ tbHours.Text hours . Catch ex As SqlException conn.Close lblResult.ForeColor System.Drawing.Color.Red lblResult.Text There was a database error ex.Message End Try End Sub If the user changes the selection on the calendar we want to make sure it is today or later. If not tell the user. Private Sub calStart_SelectionChanged ByVal sender As System.Object ByVal e As System.EventArgs Handles calStart.SelectionChanged Make sure we are using a valid date. If calStart.SelectedDate Now.Date Then lblResult.ForeColor System.Drawing.Color.Red lblResult.Text You must select a date equal to or _ later than today. Employee Intranet with .NET 447 Else IblResult.Text End If End Sub End Class We define our connection string as usual but this time we actually have some class data to store. All the class variables are related to saving the various vacation statistics as well as the employee ID once we load it from the database. Then we handle the page load event. We start it out by retrieving some employee information from the database including the employee ID the first and last names and the amount of vacation the employee is allotted for the year. We ll use these shortly because we need them before we can get any work done. We use standard SQL and ADO.NET to get the information back. Once we .