T
Tiago \(MSN\)
How's it going guys ?!
yeah... I'm struggling to code some kind of calendar to a friend o'mine,
it's like an Hour Bank, where he puts his job hours and dates ...
So I came up with some interface, which he decided to accept.
That's fine till now... Okay, now here is the problem:
I'm using a MonthlyCalendar in order to pick up dates.
I need to find a better way to calculate the difference in hour between 2
Hours...
so I came up with this really ugly lines...
Public Sub InsereVariasDatas()
Try
Dim cString As String = "MyConnStr"
Dim Conn As OleDbConnection = New OleDbConnection(cString)
Dim HoraEntrada As Date = frmAddVariosCompromissos.mebEnt.Text
Dim HoraSaida As Date = frmAddVariosCompromissos.mebSaida.Text
Dim HoraBrake As Date = frmAddVariosCompromissos.medBrake.Text
Dim TotHoras As Date
Dim Dif_SemBrake As TimeSpan =
HoraEntrada.Subtract(HoraSaida).Duration
Dim GanhosDia As Double
Dim FatHoras As Double
If frmAddCompromissoUnico.chkBrake.Checked = True Then
Dim Dif_ComBrake As TimeSpan
Dim hB As Date = Dif_SemBrake.ToString
Dif_ComBrake = hB.Subtract(HoraBrake)
FatHoras = Dif_ComBrake.Hours & "," & Dif_ComBrake.Minutes
GanhosDia = My.Settings.sValHora * FatHoras
TotHoras = Dif_ComBrake.ToString
Else
FatHoras = Dif_SemBrake.Hours & "," & Dif_SemBrake.Minutes
GanhosDia = My.Settings.sValHora * FatHoras
TotHoras = Dif_SemBrake.ToString
End If
Conn.Open()
Dim DataA As TimeSpan =
frmCFmain.mcMain.SelectionRange.End.Subtract(frmCFmain.mcMain.SelectionRange.Start)
Dim DifRangeA As Integer = DataA.TotalDays.ToString
Dim DataAtual As String
For i = 0 To DifRangeA
Dim data As Date =
(frmCFmain.mcMain.SelectionRange.Start.Day + i) & _
"/" & _
frmCFmain.mcMain.SelectionRange.Start.Month
& _
"/" & _
frmCFmain.mcMain.SelectionRange.Start.Year
DataAtual = data.ToString("dd/MM/yyyy")
Dim qString As String = "INSERT INTO BancoHoras ([LocalID],
Data, HoraEntrada, HoraSaida, TempoBrake, TotalHoras, GanhosDia)" & _
"VALUES ('" & My.Settings.idLocal &
"', #" & DataAtual & "#, #" & HoraEntrada & "#, #" & HoraSaida & "#, #" & _
HoraBrake & "#, #" & TotHoras
& "#, '" & GanhosDia & "')"
Dim Comm As OleDbCommand = New OleDbCommand(qString, Conn)
Dim iC As Integer = Comm.ExecuteNonQuery()
Next i
Conn.Close()
BoldDatas()
MessageBox.Show("Dados inseridos com sucesso!", "Confirmação",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
And this is the Bold Dates routine:
Public Sub BoldDatas()
Try
Dim cString As String = "MyConnStr"
Dim Conn As OleDbConnection = New OleDbConnection(cString)
Dim qString As String = "SELECT Data FROM BancoHoras"
Dim DataAdapater As OleDbDataAdapter = New
OleDbDataAdapter(qString, Conn)
Dim DS As DataSet = New DataSet()
Dim Table As DataTable
DataAdapater.Fill(DS, "Datas")
Table = DS.Tables("Datas")
Dim totLinha As Integer = Table.Rows.Count
Dim Data As Date
For i As Integer = 0 To (totLinha - 1)
Data = Table.Rows(i).Item("Data")
frmCFmain.mcMain.AddBoldedDate(Data)
'Data = Nothing
Next
frmCFmain.mcMain.UpdateBoldedDates()
Catch ex As Exception
MsgBox(ex.Message)
End Try
If you could help me Bold the dates in the MonthlyCalendar and how to
calculate the time between 2 dates, I need to calculate the diference of two
hours on the same day, so if he goes in at 21:00 and goes out 06:00 then it
would be a 08:00 difference!
Ok ?!
Thank you very much for reading this post and I would really love to be
guided by you people!
Sincerely,
Tiago Trentini
yeah... I'm struggling to code some kind of calendar to a friend o'mine,
it's like an Hour Bank, where he puts his job hours and dates ...
So I came up with some interface, which he decided to accept.
That's fine till now... Okay, now here is the problem:
I'm using a MonthlyCalendar in order to pick up dates.
I need to find a better way to calculate the difference in hour between 2
Hours...
so I came up with this really ugly lines...
Public Sub InsereVariasDatas()
Try
Dim cString As String = "MyConnStr"
Dim Conn As OleDbConnection = New OleDbConnection(cString)
Dim HoraEntrada As Date = frmAddVariosCompromissos.mebEnt.Text
Dim HoraSaida As Date = frmAddVariosCompromissos.mebSaida.Text
Dim HoraBrake As Date = frmAddVariosCompromissos.medBrake.Text
Dim TotHoras As Date
Dim Dif_SemBrake As TimeSpan =
HoraEntrada.Subtract(HoraSaida).Duration
Dim GanhosDia As Double
Dim FatHoras As Double
If frmAddCompromissoUnico.chkBrake.Checked = True Then
Dim Dif_ComBrake As TimeSpan
Dim hB As Date = Dif_SemBrake.ToString
Dif_ComBrake = hB.Subtract(HoraBrake)
FatHoras = Dif_ComBrake.Hours & "," & Dif_ComBrake.Minutes
GanhosDia = My.Settings.sValHora * FatHoras
TotHoras = Dif_ComBrake.ToString
Else
FatHoras = Dif_SemBrake.Hours & "," & Dif_SemBrake.Minutes
GanhosDia = My.Settings.sValHora * FatHoras
TotHoras = Dif_SemBrake.ToString
End If
Conn.Open()
Dim DataA As TimeSpan =
frmCFmain.mcMain.SelectionRange.End.Subtract(frmCFmain.mcMain.SelectionRange.Start)
Dim DifRangeA As Integer = DataA.TotalDays.ToString
Dim DataAtual As String
For i = 0 To DifRangeA
Dim data As Date =
(frmCFmain.mcMain.SelectionRange.Start.Day + i) & _
"/" & _
frmCFmain.mcMain.SelectionRange.Start.Month
& _
"/" & _
frmCFmain.mcMain.SelectionRange.Start.Year
DataAtual = data.ToString("dd/MM/yyyy")
Dim qString As String = "INSERT INTO BancoHoras ([LocalID],
Data, HoraEntrada, HoraSaida, TempoBrake, TotalHoras, GanhosDia)" & _
"VALUES ('" & My.Settings.idLocal &
"', #" & DataAtual & "#, #" & HoraEntrada & "#, #" & HoraSaida & "#, #" & _
HoraBrake & "#, #" & TotHoras
& "#, '" & GanhosDia & "')"
Dim Comm As OleDbCommand = New OleDbCommand(qString, Conn)
Dim iC As Integer = Comm.ExecuteNonQuery()
Next i
Conn.Close()
BoldDatas()
MessageBox.Show("Dados inseridos com sucesso!", "Confirmação",
MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MsgBox(ex.Message)
End Try
And this is the Bold Dates routine:
Public Sub BoldDatas()
Try
Dim cString As String = "MyConnStr"
Dim Conn As OleDbConnection = New OleDbConnection(cString)
Dim qString As String = "SELECT Data FROM BancoHoras"
Dim DataAdapater As OleDbDataAdapter = New
OleDbDataAdapter(qString, Conn)
Dim DS As DataSet = New DataSet()
Dim Table As DataTable
DataAdapater.Fill(DS, "Datas")
Table = DS.Tables("Datas")
Dim totLinha As Integer = Table.Rows.Count
Dim Data As Date
For i As Integer = 0 To (totLinha - 1)
Data = Table.Rows(i).Item("Data")
frmCFmain.mcMain.AddBoldedDate(Data)
'Data = Nothing
Next
frmCFmain.mcMain.UpdateBoldedDates()
Catch ex As Exception
MsgBox(ex.Message)
End Try
If you could help me Bold the dates in the MonthlyCalendar and how to
calculate the time between 2 dates, I need to calculate the diference of two
hours on the same day, so if he goes in at 21:00 and goes out 06:00 then it
would be a 08:00 difference!
Ok ?!
Thank you very much for reading this post and I would really love to be
guided by you people!
Sincerely,
Tiago Trentini