Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 9th, 2012  |  syntax: None  |  size: 4.04 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Imports System.Data
  2. Imports System.Data.OleDb
  3. Imports ADODB
  4.  
  5. Public Class frmChangeDate
  6.  
  7.     Private Sub objCalendar_CloseUp(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCalendar.CloseUp
  8.         Me.Height = 85
  9.     End Sub
  10.  
  11.     Private Sub objCalendar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles objCalendar.MouseDown
  12.         Me.Height = 250
  13.     End Sub
  14.  
  15.     Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  16.         Me.Close()
  17.     End Sub
  18.  
  19.     Private Sub objCalendar_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objCalendar.ValueChanged
  20.         btnChange.Enabled = True
  21.         btnCancel.Enabled = True
  22.     End Sub
  23.  
  24.     Private Sub btnChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChange.Click
  25.         Dim csData As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ICOM\Database\CBOData_s.mdb;Jet OLEDB:Database Password=C0mtrex;"
  26.         Dim strSQL As String = "SELECT SalesDayNumber, SalesDate, BODRunningGT FROM SalesDays ORDER BY SalesDate DESC"
  27.         Dim objDR As OleDbDataReader
  28.         Dim conData As OleDbConnection
  29.         Dim cmdData As OleDbCommand
  30.  
  31.         ' First we must read the current sales day number then increment it by 1
  32.  
  33.         conData = New OleDbConnection(csData)
  34.         conData.Open()
  35.  
  36.         cmdData = New OleDbCommand(strSQL, conData)
  37.  
  38.         objDR = cmdData.ExecuteReader
  39.         objDR.Read()
  40.  
  41.         Dim LastDayNumber As Int32 = objDR(0)
  42.         Dim LastSalesDate As Date = FormatDateTime(objDR(1), DateFormat.GeneralDate)
  43.         Dim BODRunningGT As String = objDR(2)
  44.  
  45.         LastDayNumber += 1
  46.  
  47.         objDR.Close()
  48.  
  49.         ' We now must insert a date in to the database record under SalesDays table.
  50.  
  51.         Dim dtNewDate As Date = FormatDateTime(objCalendar.Value, DateFormat.ShortDate)
  52.         Dim lngResult As Long
  53.  
  54.         lngResult = MessageBox.Show("The current sales date is " & LastSalesDate & vbCrLf & _
  55.                         "and your new date will be set as " & dtNewDate & _
  56.                         vbCrLf & vbCrLf & "Are you sure you want to continue?", "Sales Date Change", MessageBoxButtons.YesNo)
  57.  
  58.         If lngResult = 7 Then Exit Sub
  59.         If lngResult = 6 Then
  60.  
  61.             Dim dtCurrentDate As Date = FormatDateTime(Date.Now, DateFormat.GeneralDate)
  62.  
  63.             Dim strUpdateLastEntry As String = _
  64.                 "UPDATE SalesDays SET ClosedDay = '-1', ClosingUserNumber = '1', ClosingDateTime = #" & dtCurrentDate & "# WHERE SalesDate = #" & LastSalesDate.ToString & "#"
  65.  
  66.             cmdData = New OleDbCommand(strUpdateLastEntry, conData)
  67.             cmdData.ExecuteNonQuery()
  68.  
  69.             Dim strNewEntry As String = _
  70.                 "INSERT INTO SalesDays (SalesDayNumber, SalesDate, ClosedDay, ClosingUserNumber, " & _
  71.                 "BODRunningGT) VALUES (" & _
  72.                 LastDayNumber & ", #" & dtNewDate & "# ," & "0" & "," & "0" & "," & BODRunningGT & ")"
  73.  
  74.             cmdData = New OleDbCommand(strNewEntry, conData)
  75.             cmdData.ExecuteNonQuery()
  76.  
  77.         End If
  78.     End Sub
  79.  
  80.     Private Sub frmChangeDate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  81.  
  82.         ' We need to grab the current date from the database field SalesDays for the
  83.         ' calendar object.
  84.  
  85.         Dim csData As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ICOM\Database\CBOData_s.mdb;Jet OLEDB:Database Password=C0mtrex;"
  86.         Dim strCurrentDate As String = "SELECT SalesDate FROM SalesDays ORDER BY SalesDate DESC"
  87.         Dim objDR As OleDbDataReader
  88.         Dim conData As OleDbConnection
  89.         Dim cmdData As OleDbCommand
  90.  
  91.         conData = New OleDbConnection(csData)
  92.         conData.Open()
  93.  
  94.         cmdData = New OleDbCommand(strCurrentDate, conData)
  95.         objDR = cmdData.ExecuteReader
  96.  
  97.         objDR.Read()
  98.         objCalendar.Value = objDR(0)
  99.         objDR.Close()
  100.     End Sub
  101. End Class