2.2 Setelah Class Koneksi dibuat, maka sekarang masuk ke inti dari program ini. Yaitu koding untuk Form1-nya :
Coding :
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
| Imports System.Data.SqlClient Imports System.Data Public Class Form1 Dim SQL As String Dim SQL2 As String Dim Proses As New ClsKoneksi Dim tblMerk As DataTable 'Dim Da As SqlClient.SqlDataAdapter Sub Data_Record() tblMerk = Proses.ExecuteQuery("Select * From purchasing_order") DataGridView1.DataSource = tblMerk DataGridView1.Columns(1).Width = 130 End Sub 'Kode otomatis untuk buat invoice Sub Kode_Otomatis() Dim date1 As String date1 = Format(Now, "yy") Dim date2 As String date2 = Format(Now, "MM") tblMerk = Proses.ExecuteQuery("Select * From purchasing_order order by no_invoice desc") If tblMerk.Rows.Count = 0 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/00001" Else With tblMerk.Rows(0) TextBox1.Text = .Item("no_invoice") End With TextBox1.Text = Val(Microsoft.VisualBasic.Mid(TextBox1.Text, 15, 5)) + 1 If Len(TextBox1.Text) = 1 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/0000" & TextBox1.Text & "" ElseIf Len(TextBox1.Text) = 2 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/000" & TextBox1.Text & "" ElseIf Len(TextBox1.Text) = 3 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/00" & TextBox1.Text & "" ElseIf Len(TextBox1.Text) = 4 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/0" & TextBox1.Text & "" ElseIf Len(TextBox1.Text) = 5 Then TextBox1.Text = "INV/CMI/" & date2 & "/" & date1 & "/" & TextBox1.Text & "" End If End If End Sub Sub bersih() Call Data_Record() Call Kode_Otomatis() BtnTambah.Enabled = True TextBox1.Enabled = False TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() End Sub Private Sub DGJenisBrg_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick TextBox1.Text = DataGridView1.SelectedCells(0).Value TextBox2.Text = DataGridView1.SelectedCells(1).Value TextBox3.Text = DataGridView1.SelectedCells(2).Value BtnTambah.Enabled = False End Sub Private Sub BtnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTambah.Click Try If (Me.TextBox1.Text = "") Then MsgBox("Data Wajib Diisi Lengkap!", MsgBoxStyle.Information, "Perhatian") Me.TextBox2.Focus() Exit Sub Else SQL = "Insert Into purchasing_order Values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')" Proses.ExecuteNonQuery(SQL) MessageBox.Show("Proses Data Berhasil!", "Sukses saved", MessageBoxButtons.OK, MessageBoxIcon.Information) Call bersih() End If Catch ex As SqlException MsgBox(ex.Message, MsgBoxStyle.Information, "Perhatian") End Try End Sub Private Sub BtnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBatal.Click Call bersih() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Me.WindowState = FormWindowState.Maximized Call bersih() DataGridView1.Columns(0).HeaderText = "No. Invoice" DataGridView1.Columns(1).HeaderText = "Nama Customer" DataGridView1.Columns(2).HeaderText = "Alamat Customer" Me.DataGridView1.DefaultCellStyle.ForeColor = Color.Coral ' Change back color of each row Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.AliceBlue ' Change GridLine Color Me.DataGridView1.GridColor = Color.Blue ' Change Grid Border Style Me.DataGridView1.BorderStyle = BorderStyle.Fixed3D DataGridView1.EnableHeadersVisualStyles = False DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightGray End Sub End Class |
Keterangan properties untuk Form1
Textbox1.Text = Untuk input no.invoice
Textbox2.Text = Untuk input nama customer
Textbox3.Text = Untuk input alamat customer
BtnTambah = Eksekusi data
DatagridView1 = Binding data
BtnBatal = Membersihkan textbox dan refresh data
sumber referensi :http://herosetyanofario.wordpress.com/2011/06/17/membuat-autonumber-menggunakan-kombinasi-bulan-tahun-di-vb-net/
No comments:
Post a Comment