87 lines
3.2 KiB
VB.net
Executable File
87 lines
3.2 KiB
VB.net
Executable File
Imports System.IO
|
|
Imports Microsoft.Data.SqlClient
|
|
Imports System.Data.DataTable
|
|
|
|
|
|
|
|
Public Class Form7
|
|
|
|
Dim DataString As String = My.Settings.subnet
|
|
Dim surce As String = My.Settings.serverName
|
|
Dim catalog As String = My.Settings.serverdatabase
|
|
Dim user As String = My.Settings.serverUser
|
|
Dim pass As String = My.Settings.serverUserpass
|
|
Dim timeout As String = My.Settings.timeout
|
|
Dim encrypt As String = My.Settings.encrypt
|
|
Dim trust As String = My.Settings.cert
|
|
Dim reason As String = My.Settings.reason
|
|
Dim subnet As String = My.Settings.subnet
|
|
|
|
|
|
|
|
|
|
|
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
|
Dim con As New SqlConnection("Data Source=" & surce & "; Initial Catalog=" & catalog & "; User ID=" & user &
|
|
"; Password=" & pass & "; Connect Timeout=" & timeout & "; Encrypt=" & encrypt &
|
|
"; TrustServerCertificate=" & trust & "; ApplicationIntent=" & reason & "; MultiSubnetFailover=" & subnet & "")
|
|
|
|
Dim command As New SqlCommand("select * from calitate.dbo.pregatit where [date] between @date1 and @date2", con)
|
|
command.Parameters.Add("date1", SqlDbType.Date).Value = DateTimePicker1.Value
|
|
command.Parameters.Add("date2", SqlDbType.Date).Value = DateTimePicker3.Value
|
|
Dim da As New SqlDataAdapter
|
|
da.SelectCommand = command
|
|
Dim dt As New DataTable
|
|
dt.Clear()
|
|
da.Fill(dt)
|
|
DataGridView1.DataSource = dt
|
|
con.Close()
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
|
|
|
|
Dim saveFileDialog As New SaveFileDialog()
|
|
saveFileDialog.Filter = "CSV (.csv)|.csv"
|
|
Dim dta As String 'string pentru SQL data
|
|
dta = Date.Now.ToString("yyyy.MM.dd") ' format string
|
|
saveFileDialog.FileName = "Pregatit" & "-" & dta & ".csv"
|
|
If (saveFileDialog.ShowDialog() = DialogResult.OK) Then
|
|
Using sw As New StreamWriter(saveFileDialog.FileName)
|
|
Dim columnCount As Integer = DataGridView1.ColumnCount
|
|
For i As Integer = 0 To columnCount - 1
|
|
sw.Write(DataGridView1.Columns(i).HeaderText)
|
|
If (i < columnCount - 1) Then
|
|
sw.Write(","c)
|
|
End If
|
|
Next
|
|
sw.Write(sw.NewLine)
|
|
For Each row As DataGridViewRow In DataGridView1.Rows
|
|
For i As Integer = 0 To row.Cells.Count - 1
|
|
If Not row.IsNewRow Then
|
|
sw.Write(row.Cells(i).Value.ToString())
|
|
End If
|
|
If (i < row.Cells.Count - 1) Then
|
|
sw.Write(","c)
|
|
End If
|
|
Next
|
|
sw.Write(sw.NewLine)
|
|
Next
|
|
sw.Close()
|
|
End Using
|
|
MessageBox.Show("CSV file saved.")
|
|
End If
|
|
|
|
|
|
|
|
End Sub
|
|
|
|
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
|
|
Form1.Show()
|
|
Me.Close()
|
|
End Sub
|
|
End Class
|
|
|
|
|