Fala, galera! Estou tentando realizar data automática. Por exemplo, se eu escolher o ano do campo "Até", no caso ano 2018. O campo "De" calcula automaticamente para ano 2013.
Conforme print abaixo:
Eu consegui automatizar apenas esse. Mas quando eu quiser alterar o campo "Até", de 18/04/2018 para 18/04/2015. O campo "De" permanece o ano 2013.
O que eu quero é calcular cinco anos diferença.
Segue o meu código:
Imports Microsoft.Office.Interop
Public Class FormRelatorio
Dim XcelApp As New Excel.Application()
'Private Sub carregaGrid()
' Try
' Dim dt As New DataTable
' dt.Columns.Add("Codigo", GetType(Integer))
' dt.Columns.Add("Nome", GetType(String))
' dt.Columns.Add("Admissao", GetType(DateTime))
' dt.Columns.Add("Setor", GetType(Integer))
' dt.Columns.Add("Salario", GetType(Double))
' Dim dr As DataRow = dt.NewRow()
' dr("Codigo") = 1
' dr("Nome") = "João Torres"
' dr("Admissao") = DateTime.Now
' dr("Setor") = 20
' dr("Salario") = 20000
' dt.Rows.Add(dr)
' dr = dt.NewRow()
' dr("Codigo") = 2
' dr("Nome") = "Jennifer"
' dr("Admissao") = DateTime.Now
' dr("Setor") = 40
' dr("Salario") = 20000
' dt.Rows.Add(dr)
' dgvDados.DataSource = dt
' Catch ex As Exception
' MessageBox.Show("Erro" + ex.Message)
' End Try
'End Sub
Private Sub Label3_Click(sender As System.Object, e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub gerarBtn_Click(sender As System.Object, e As System.EventArgs) Handles gerarBtn.Click
If dgvDados.Rows.Count > 0 Then
Try
XcelApp.Application.Workbooks.Add(Type.Missing)
For i As Integer = 1 To dgvDados.Columns.Count
XcelApp.Cells(1, i) = dgvDados.Columns(i - 1).HeaderText
Next
'
For i As Integer = 0 To dgvDados.Rows.Count - 2
For j As Integer = 0 To dgvDados.Columns.Count - 1
XcelApp.Cells(i + 2, j + 1) = dgvDados.Rows(i).Cells(j).Value.ToString()
Next
Next
'
XcelApp.Columns.AutoFit()
'
XcelApp.Visible = True
Catch ex As Exception
MessageBox.Show("Erro: " + ex.Message)
XcelApp.Quit()
End Try
End If
End Sub
Private Sub Relatorio_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'AntaqDataSet.T400_ATRACACAO' table. You can move, or remove it, as needed.
Dim dbase As New dBase
Me.T400_ATRACACAOTableAdapter.Fill(Me.AntaqDataSet.T400_ATRACACAO)
' carregaGrid()
dgvDados.DataSource = dbase.GetAllAtracacao()
Dim dtEscolha As DateTime
dtEscolha = dtpAtual.Text
txtBoxDe.Text = dtEscolha.AddYears(-5)
End Sub
Private Sub MaskedTextBox2_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs)
End Sub
Private Sub dgvDados_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvDados.CellContentClick
End Sub
Private Sub dtpAtual_ValueChanged(sender As System.Object, e As System.EventArgs) Handles dtpAtual.ValueChanged
End Sub
Private Sub txtBoxDe_MaskInputRejected(sender As System.Object, e As System.Windows.Forms.MaskInputRejectedEventArgs) Handles txtBoxDe.MaskInputRejected
System.Diagnostics.Debug.Write(dtpAtual.Text)
End Sub
End Class