1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| 'import datagridview
Private Sub ShowdDataGView()
cn.Open()
cmd.CommandText =
<sql>
SELECT
*
FROM
EmpCcp;
</sql>.Value
Dtr = cmd.ExecuteReader
Dim I As Integer
For I = 0 To MyTbl.Rows.Count - 1
Dtr.Read()
Next
MyTbl.Load(Dtr)
DGView.DataSource = MyTbl
ImportDG()
DGView.Refresh()
Dtr.Close()
cn.Close()
End Sub
Private Function GetFormatNumber(ByVal Nombre As String, ByVal Longueur As Integer) As String 'Longueur = nombre de caractère de la chaine renvoyée
Dim s As String
s = String.Format("{0:###,.##}", (CType(Nombre, Single) * 100).ToString)
Return s.PadLeft(Longueur, "0"c)
End Function
'creation du fichiers texte
Using Savefile As New SaveFileDialog
Dim nowYear As Integer = Date.Now.Year
Dim Nconting, RIB, CDord, NMondat, nowmonth As String
nowmonth = (maTextBox.Text.ToString().PadLeft(2, "0"))
NMondat = (TextBox3.Text.ToString().PadLeft(6, "0"))
CDord = (TextBox2.Text.ToString().PadLeft(8, "0"))
RIB = (TextBox1.Text.ToString().PadLeft(20, "0"))
Nconting = (DGView.RowCount.ToString().PadLeft(7, "0"))
Savefile.FileName = (CDord & "_" & NMondat & "_" & nowYear.ToString & ".txt")
Savefile.Filter = "fichier TXT (*.txt)|*.txt|Tous les fichier (*.*)|*.*"
If Savefile.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim SW As New System.IO.StreamWriter(Savefile.FileName)
Dim total = (From x As DataGridViewRow In DGView.Rows Select CDbl(x.Cells(4).Value)).Sum
SW.WriteLine(RIB & "" & GetFormatNumber(total, 13) & "" & Nconting & "" & nowmonth.ToString & "" & nowYear.ToString & "" & CDord & "" & NMondat)
Dim C1, C2, C3, C4 As String
For i As Integer = 0 To DGView.Rows.Count - 1
C2 = (DGView.Rows(i).Cells(2).Value.ToString().PadLeft(8, "0") & "")
C3 = (DGView.Rows(i).Cells(3).Value.ToString() & "")
C4 = (DGView.Rows(i).Cells(4).Value.ToString() & "")
C1 = (DGView.Rows(i).Cells(1).Value.ToString().PadRight(27))
SW.Write(C2 & "" & C3 & "" & GetFormatNumber(C4, 13) & "" & C1)
SW.WriteLine("")
Next
SW.Close()
MessageBox.Show("avec succes")
End If
End Using |
Partager