- Imports System.Data
- Imports System.Data.OleDb
- Imports ADODB
- Public Class frmChangeDate
- Private Sub objCalendar_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCalendar.CloseUp
- Me.Height = 85
- End Sub
- Private Sub objCalendar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles objCalendar.MouseDown
- Me.Height = 250
- End Sub
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- Me.Close()
- End Sub
- Private Sub objCalendar_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCalendar.ValueChanged
- btnChange.Enabled = True
- btnCancel.Enabled = True
- End Sub
- Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
- Dim csData As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ICOM\Database\CBOData_s.mdb;Jet OLEDB:Database Password=C0mtrex;"
- Dim strSQL As String = "SELECT SalesDayNumber, SalesDate, BODRunningGT FROM SalesDays ORDER BY SalesDate DESC"
- Dim objDR As OleDbDataReader
- Dim conData As OleDbConnection
- Dim cmdData As OleDbCommand
- ' First we must read the current sales day number then increment it by 1
- conData = New OleDbConnection(csData)
- conData.Open()
- cmdData = New OleDbCommand(strSQL, conData)
- objDR = cmdData.ExecuteReader
- objDR.Read()
- Dim LastDayNumber As Int32 = objDR(0)
- Dim LastSalesDate As Date = FormatDateTime(objDR(1), DateFormat.GeneralDate)
- Dim BODRunningGT As String = objDR(2)
- LastDayNumber += 1
- objDR.Close()
- ' We now must insert a date in to the database record under SalesDays table.
- Dim dtNewDate As Date = FormatDateTime(objCalendar.Value, DateFormat.ShortDate)
- Dim lngResult As Long
- lngResult = MessageBox.Show("The current sales date is " & LastSalesDate & vbCrLf & _
- "and your new date will be set as " & dtNewDate & _
- vbCrLf & vbCrLf & "Are you sure you want to continue?", "Sales Date Change", MessageBoxButtons.YesNo)
- If lngResult = 7 Then Exit Sub
- If lngResult = 6 Then
- Dim dtCurrentDate As Date = FormatDateTime(Date.Now, DateFormat.GeneralDate)
- Dim strUpdateLastEntry As String = _
- "UPDATE SalesDays SET ClosedDay = '-1', ClosingUserNumber = '1', ClosingDateTime = #" & dtCurrentDate & "# WHERE SalesDate = #" & LastSalesDate.ToString & "#"
- cmdData = New OleDbCommand(strUpdateLastEntry, conData)
- cmdData.ExecuteNonQuery()
- Dim strNewEntry As String = _
- "INSERT INTO SalesDays (SalesDayNumber, SalesDate, ClosedDay, ClosingUserNumber, " & _
- "BODRunningGT) VALUES (" & _
- LastDayNumber & ", #" & dtNewDate & "# ," & "0" & "," & "0" & "," & BODRunningGT & ")"
- cmdData = New OleDbCommand(strNewEntry, conData)
- cmdData.ExecuteNonQuery()
- End If
- End Sub
- Private Sub frmChangeDate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- ' We need to grab the current date from the database field SalesDays for the
- ' calendar object.
- Dim csData As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ICOM\Database\CBOData_s.mdb;Jet OLEDB:Database Password=C0mtrex;"
- Dim strCurrentDate As String = "SELECT SalesDate FROM SalesDays ORDER BY SalesDate DESC"
- Dim objDR As OleDbDataReader
- Dim conData As OleDbConnection
- Dim cmdData As OleDbCommand
- conData = New OleDbConnection(csData)
- conData.Open()
- cmdData = New OleDbCommand(strCurrentDate, conData)
- objDR = cmdData.ExecuteReader
- objDR.Read()
- objCalendar.Value = objDR(0)
- objDR.Close()
- End Sub
- End Class