Sunteți pe pagina 1din 9

Imports MySql.Data.MySqlClient Imports System.Math Imports System.Object Imports System.Windows.

Forms Public Class result_temp Dim conn As New koneksi Dim conf, sup As Double Private Sub result_temp_Load(ByVal sender As System.Object, ByVal e As Syste m.EventArgs) Handles MyBase.Load Me.Show() tampilresult() tampilrescount() tampilrescount2() End Sub Sub tampilresult() Dim tampilnode As String = "select item1, item_buy, group_itembuy from r es_temp" DTtable.Clear() DTtable = New DataTable DTadapter = New MySqlDataAdapter(tampilnode, conn.konek) DTadapter.Fill(DTtable) With Me.dgvrestemp .DataSource = DTtable .SelectionMode = DataGridViewSelectionMode.FullRowSelect .AllowUserToAddRows = False .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells End With DTtable.Dispose() DTadapter.Dispose() conn.konek.Close() End Sub Sub tampilrescount() Dim tampilrc1 As String = "select * from res_count" DTtable.Clear() DTtable = New DataTable DTadapter = New MySqlDataAdapter(tampilrc1, conn.konek) DTadapter.Fill(DTtable) With Me.dgvrescount .DataSource = DTtable .SelectionMode = DataGridViewSelectionMode.FullRowSelect .AllowUserToAddRows = False .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells End With DTtable.Dispose() DTadapter.Dispose() conn.konek.Close() End Sub Sub tampilrescount2() Dim tampilrc2 As String = "select * from res_count2" DTtable.Clear() DTtable = New DataTable DTadapter = New MySqlDataAdapter(tampilrc2, conn.konek) DTadapter.Fill(DTtable) With Me.dgvrescount2 .DataSource = DTtable .SelectionMode = DataGridViewSelectionMode.FullRowSelect .AllowUserToAddRows = False

.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells End With DTtable.Dispose() DTadapter.Dispose() conn.konek.Close() End Sub Sub pattern() 'DEKLARASI Dim id, ii, i, n As Integer Dim restemp As MySqlDataReader Dim arayPola() As String 'FILL MAX ID Dim getmaxid As String = "select max(indeks_rules) from local" Dim maxid As Int32 Dim CMD_maxid = New MySqlCommand(getmaxid, conn.konek) maxid = Convert.ToInt32(CMD_maxid.ExecuteScalar()) CMD_maxid.Connection.Close() 'looping For id = 1 To maxid Dim get_restemp As String = "select rules, indeks_rules from local w here indeks_rules = '" & id & "' " CMD_restemp = New MySqlCommand(get_restemp, conn.konek) restemp = CMD_restemp.ExecuteReader() Dim get_frekid As String = "select count(indeks_rules) from local wh ere indeks_rules = '" & id & "' " CMD_frekid = New MySqlCommand(get_frekid, conn.konek) Dim frekid As Int32 frekid = Convert.ToInt32(CMD_frekid.ExecuteScalar()) CMD_frekid.Connection.Close() ReDim arayPola(frekid) Dim itemA As String Dim itemB As String Dim freks As Integer freks = frekid - 1 If restemp.HasRows Then For ii = 0 To freks restemp.Read() arayPola(ii) = restemp("rules") Next ii End If CMD_restemp.Connection.Close() n = freks 'MsgBox(n) For i = 0 To n - 1 itemA = arayPola(i) itemB = arayPola(freks) Dim insrestemp As String = "insert into res_temp (item1, item_bu y, group_itembuy) values('" & itemA & "', '" & itemB & "', '" & id & "' ) "

CMD_insrestemp = New MySqlCommand(insrestemp, conn.konek) CMD_insrestemp.ExecuteNonQuery() CMD_insrestemp.Connection.Close() Next Next End Sub Sub pattern2() 'DEKLARASI Dim id, ii, i, j, n, o As Integer Dim restemp As MySqlDataReader Dim arayPola() As String 'FILL MAX ID Dim getmaxid As String = "select max(indeks_rules) from local" Dim maxid As Int32 Dim CMD_maxid = New MySqlCommand(getmaxid, conn.konek) maxid = Convert.ToInt32(CMD_maxid.ExecuteScalar()) CMD_maxid.Connection.Dispose() 'looping For id = 2 To maxid Dim get_restemp As String = "select rules, indeks_rules from local w here indeks_rules = '" & id & "' " CMD_restemp = New MySqlCommand(get_restemp, conn.konek) restemp = CMD_restemp.ExecuteReader() Dim get_frekid As String = "select count(indeks_rules) from local wh ere indeks_rules = '" & id & "' " CMD_frekid = New MySqlCommand(get_frekid, conn.konek) Dim frekid As Int32 frekid = Convert.ToInt32(CMD_frekid.ExecuteScalar()) CMD_frekid.Connection.Close() If frekid >= 3 Then ReDim arayPola(frekid) Dim Dim Dim Dim itemA As String itemB As String itemAB As String itemC As String

Dim freks As Integer Dim freks2 As Integer freks = frekid - 1 freks2 = frekid - 2 If restemp.HasRows Then For ii = 0 To freks restemp.Read() arayPola(ii) = restemp("rules") Next ii End If CMD_restemp.Connection.Close()

n = freks o = freks2 'MsgBox(n) For i = 0 To n - 2 For j = i + 1 To n - 1 itemA = arayPola(i) itemB = arayPola(j) itemAB = arayPola(i) & arayPola(j) itemC = arayPola(freks) Dim insrestemp As String = "insert into res_temp (item1, item_buy, group_itembuy) values('" & itemAB & "', '" & itemC & "', '" & id & " ' ) " CMD_insrestemp = New MySqlCommand(insrestemp, conn.konek ) CMD_insrestemp.ExecuteNonQuery() CMD_insrestemp.Connection.Close() 'MsgBox(itemA) 'MsgBox(itemB) 'MsgBox(itemAB) 'MsgBox(itemC) Next j Next Else Continue For End If Next End Sub Sub pattern3() Dim get_pisah As String = "insert into res_count (item_related, item_buy , group_item) select item1, item_buy, group_itembuy from res_temp where char_len gth(item1)=2 " CMD_pisahtemp = New MySqlCommand(get_pisah, conn.konek) CMD_pisahtemp.ExecuteNonQuery() CMD_pisahtemp.Connection.Dispose() End Sub Sub pattern4() Dim conf1 As Integer Dim res_supconf As MySqlDataReader Dim araySup() As String Dim arayConf() As String Dim conf, sup As Double Dim nama, nama2 As String '----GET TOTAL TID Dim gettid As String = "select count(kode_faktur) from faktur" Dim totaltid As Int32 Dim CMD_totaltid = New MySqlCommand(gettid, conn.konek) totaltid = Convert.ToInt32(CMD_totaltid.ExecuteScalar()) CMD_totaltid.Connection.Dispose() 'FILL MAX ID

Dim getconf1 As String = "select max(pk_rescount) from res_count" Dim maxconf1 As Int32 Dim CMD_getconf1 = New MySqlCommand(getconf1, conn.konek) maxconf1 = Convert.ToInt32(CMD_getconf1.ExecuteScalar()) CMD_getconf1.Connection.Dispose() 'looping For conf1 = 1 To maxconf1 Dim get_supconf As String = "select item_related, item_buy from res_ count where pk_rescount = '" & conf1 & "' " CMD_res_supconf = New MySqlCommand(get_supconf, conn.konek) res_supconf = CMD_res_supconf.ExecuteReader() ReDim arayConf(maxconf1) ReDim araySup(maxconf1) res_supconf.Read() arayConf(conf1) = res_supconf("item_related") araySup(conf1) = res_supconf("item_buy") 'ambil nilai count dari 2 item Dim getcombo As String = "SELECT COUNT(x.freq) from(SELECT kode_fakt ur, COUNT(DISTINCT a.kode_brg) as freq FROM detail a WHERE a.kode_brg IN ('" & a rayConf(conf1) & "' , '" & araySup(conf1) & "') GROUP BY kode_faktur HAVING COUN T(DISTINCT a.kode_brg) = 2)x" Dim combo2 As Int32 Dim CMD_getCombo = New MySqlCommand(getcombo, conn.konek) combo2 = Convert.ToInt32(CMD_getCombo.ExecuteScalar()) CMD_getCombo.Connection.Dispose() 'ambil nilai count dari item buy Dim hitsup1 As String = "select count(kode_brg) from detail where ko de_brg = '" & araySup(conf1) & "' " Dim hitsup As Int32 CMD_hitsup = New MySqlCommand(hitsup1, conn.konek) hitsup = Convert.ToInt32(CMD_hitsup.ExecuteScalar()) CMD_hitsup.Connection.Dispose() 'hitung nilai support 2 itemset sup = (combo2 / totaltid) * 100 sup = Round(sup, 0) 'hitung nilai confidence 2 itemset conf = (combo2 / hitsup) * 100 conf = Round(conf, 0) 'Dim hitconf1 As String = "select count(kode_brg) from detail where kode_brg = '" & arayConf(conf1) & "' " 'Dim hitconf As Int32 'Dim CMD_hitsup = New MySqlCommand(hitconf1, conn.konek) 'hitconf = Convert.ToInt32(CMD_hitsup.ExecuteScalar()) 'CMD_hitsup.Connection.Dispose() 'ambil nama untuk item related Dim getnama As String = "select nama from brg where kode_brg = '" & arayConf(conf1) & "' " Dim CMD_nama = New MySqlCommand(getnama, conn.konek) nama = CMD_nama.ExecuteScalar() CMD_nama.Connection.Dispose()

'ambil nama untuk item buy Dim getnama2 As String = "select nama from brg where kode_brg = '" & araySup(conf1) & "' " Dim CMD_nama2 = New MySqlCommand(getnama2, conn.konek) nama2 = CMD_nama2.ExecuteScalar() CMD_nama2.Connection.Dispose() 'update nilai support, confidence, item related, item buy Dim inssup1 As String = "update res_count set nama ='" & nama & "', nama2= '" & nama2 & "', sup = '" & sup & "', conf = '" & conf & "' where pk_resc ount = '" & conf1 & "' " CMD_inssup1 = New MySqlCommand(inssup1, conn.konek) CMD_inssup1.ExecuteNonQuery() CMD_inssup1.Connection.Dispose() CMD_res_supconf.Connection.Dispose() Next End Sub Sub pattern5() Dim get_pisah As String = "insert into res_count2 (item_related, item_bu y, group_item) select item1, item_buy, group_itembuy from res_temp where char_le ngth(item1)=4 " CMD_pisahtemp = New MySqlCommand(get_pisah, conn.konek) CMD_pisahtemp.ExecuteNonQuery() CMD_pisahtemp.Connection.Dispose() End Sub Sub pattern6() Dim conf1 As Integer Dim res_supconf As MySqlDataReader Dim araySup() As String Dim arayConf() As String Dim nama, nama2, namaA, namaB As String '----GET TOTAL TID Dim gettid As String = "select count(kode_faktur) from faktur" Dim totaltid As Int32 Dim CMD_totaltid = New MySqlCommand(gettid, conn.konek) totaltid = Convert.ToInt32(CMD_totaltid.ExecuteScalar()) CMD_totaltid.Connection.Dispose() 'FILL MAX ID Dim getconf1 As String = "select max(pk_rescount) from res_count2" Dim maxconf1 As Int32 Dim CMD_getconf1 = New MySqlCommand(getconf1, conn.konek) maxconf1 = Convert.ToInt32(CMD_getconf1.ExecuteScalar()) CMD_getconf1.Connection.Dispose() 'looping For conf1 = 1 To maxconf1 Dim get_supconf As String = "select item_related, item_buy from res_ count2 where pk_rescount = '" & conf1 & "' " CMD_res_supconf = New MySqlCommand(get_supconf, conn.konek) res_supconf = CMD_res_supconf.ExecuteReader() ReDim arayConf(maxconf1)

ReDim araySup(maxconf1) res_supconf.Read() arayConf(conf1) = res_supconf("item_related") araySup(conf1) = res_supconf("item_buy") 'pisahin item related Dim subConf, subConf2 As String subConf = arayConf(conf1).Substring(0, 1) subConf2 = arayConf(conf1).Substring(1, 1) 'MsgBox("A: " & subConf) 'MsgBox("B: " & subConf2) 'ambil nilai count dari 3 item Dim getcombo As String = "SELECT COUNT(x.freq) from(SELECT kode_fakt ur, COUNT(DISTINCT a.kode_brg) as freq FROM detail a WHERE a.kode_brg IN ('" & s ubConf & "' , '" & subConf2 & "' , '" & araySup(conf1) & "' ) GROUP BY kode_fakt ur HAVING COUNT(DISTINCT a.kode_brg) = 3)x" Dim combo3 As Int32 Dim CMD_getCombo = New MySqlCommand(getcombo, conn.konek) combo3 = Convert.ToInt32(CMD_getCombo.ExecuteScalar()) CMD_getCombo.Connection.Dispose() 'MsgBox("COMBO " & combo3) 'ambil nilai count dari item buy Dim hitsup1 As String = "select count(kode_brg) from detail where ko de_brg = '" & araySup(conf1) & "' " Dim hitsup As Int32 Dim CMD_hitsup = New MySqlCommand(hitsup1, conn.konek) hitsup = Convert.ToInt32(CMD_hitsup.ExecuteScalar()) CMD_hitsup.Connection.Dispose() 'hitung nilai support 3 itemset sup = (combo3 / totaltid) * 100 sup = Round(sup, 0) 'hitung nilai confidence 3 itemset conf = (combo3 / hitsup) * 100 conf = Round(conf, 0) 'ambil nama untuk item related Dim getA As String = "select nama from brg where kode_brg = '" & sub Conf & "' " Dim CMD_nama = New MySqlCommand(getA, conn.konek) namaA = CMD_nama.ExecuteScalar() CMD_nama.Connection.Dispose() Dim getB As String = "select nama from brg where kode_brg = '" & sub Conf2 & "' " CMD_nama = New MySqlCommand(getB, conn.konek) namaB = CMD_nama.ExecuteScalar() CMD_nama.Connection.Dispose() nama = String.Concat(namaA, ",", " ", namaB) 'ambil nama untuk item buy Dim getnama2 As String = "select nama from brg where kode_brg = '" & araySup(conf1) & "' " Dim CMD_nama2 = New MySqlCommand(getnama2, conn.konek) nama2 = CMD_nama2.ExecuteScalar()

CMD_nama2.Connection.Dispose() 'update nilai sup dan confidence 3 itemset Dim inssup1 As String = "update res_count2 set nama = '" & nama & "' , nama2 = '" & nama2 & "', conf = '" & conf & "', sup = '" & sup & "' where pk_r escount = '" & conf1 & "' " CMD_inssup1 = New MySqlCommand(inssup1, conn.konek) CMD_inssup1.ExecuteNonQuery() CMD_inssup1.Connection.Dispose() CMD_res_supconf.Connection.Dispose() Next End Sub Sub final() Dim insfinal As String = "insert into result(item_related, item_buy, gro up_item, nama, nama2, conf, sup) select item_related, item_buy, group_item, nama , nama2, conf, sup from res_count " CMD = New MySqlCommand(insfinal, conn.konek) CMD.ExecuteNonQuery() CMD.Connection.Dispose() Dim insfinal2 As String = "insert into result(item_related, item_buy, gr oup_item, nama, nama2, conf, sup) select item_related, item_buy, group_item, nam a, nama2, conf, sup from res_count2 " CMD = New MySqlCommand(insfinal2, conn.konek) CMD.ExecuteNonQuery() CMD.Connection.Dispose() End Sub Private Sub ButtonX4_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX4.Click Dim trunc As String = "TRUNCATE res_temp" CMD_trunc = New MySqlCommand(trunc, conn.konek) CMD_trunc.ExecuteNonQuery() CMD_trunc.Connection.Dispose() MsgBox("Data Has Been Cleared") tampilresult() End Sub Private Sub ButtonX3_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX3.Click pattern() pattern2() tampilresult() End Sub Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX1.Click Dim trunc2 As String = "TRUNCATE res_count" CMD_trunc2 = New MySqlCommand(trunc2, conn.konek) CMD_trunc2.ExecuteNonQuery() CMD_trunc2.Connection.Dispose() MsgBox("Data Has Been Cleared") tampilrescount() End Sub

Private Sub ButtonX2_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX2.Click pattern3() tampilrescount() End Sub Private Sub ButtonX5_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX5.Click pattern4() tampilrescount() End Sub Private Sub ButtonX6_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Dim trunc2 As String = "TRUNCATE res_count" CMD_trunc2 = New MySqlCommand(trunc2, conn.konek) CMD_trunc2.ExecuteNonQuery() CMD_trunc2.Connection.Dispose() MsgBox("Data Has Been Cleared") End Sub Private Sub ButtonX7_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX7.Click pattern5() tampilrescount2() End Sub Private Sub ButtonX8_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX8.Click Dim trunc2 As String = "TRUNCATE res_count2" CMD_trunc2 = New MySqlCommand(trunc2, conn.konek) CMD_trunc2.ExecuteNonQuery() CMD_trunc2.Connection.Dispose() MsgBox("Data Has Been Cleared") tampilrescount2() End Sub Private Sub ButtonX6_Click_1(ByVal sender As System.Object, ByVal e As Syste m.EventArgs) Handles ButtonX6.Click pattern6() tampilrescount2() End Sub Private Sub ButtonX9_Click(ByVal sender As System.Object, ByVal e As System. EventArgs) Handles ButtonX9.Click final() End Sub End Class

S-ar putea să vă placă și