ASP.Net
Web Program
Rancangan Interfacenya :
Saat di jalankan (run) di browser :
Kode Program (listing kode) nya :
Form_Barang.aspx
<%@ Page Debug="true"
%>
<%@ Import Namespace="System.Data"
%>
<%@ Import Namespace="MySql.Data.MySqlClient"
%>
<%@ Import Namespace="System.Data.Dataset"
%>
<%@ Import Namespace="System.Web.Ui.Control"
%>
<%@ Import Namespace="System.IO"
%>
<%@ Import Namespace="System"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#apDiv1 {
position:absolute;
width:900px;
height:675px;
z-index:1;
left: 4px;
top: 2px;
}
#apDiv2 {
position:absolute;
width:309px;
height:247px;
z-index:1;
left: 46px;
top: 82px;
}
#l1 {
position:absolute;
left: 15px;
}
#t1 {
position:absolute;
left: 116px;
top: -1px;
}
#t2 {
position:absolute;
left: 116px;
top: 34px;
}
#t3 {
position:absolute;
left: 116px;
top: 73px;
}
#t4 {
position:absolute;
left: 116px;
top: 110px;
}
#t5 {
position:absolute;
left: 116px;
top: 148px;
}
#t6 {
position:absolute;
left: 116px;
top: 173px;
}
#pf {
position:absolute;
left: 116px;
top: 193px;
}
#t7 {
position:absolute;
left: 30px;
top: 37px;
}
#t8 {
position:absolute;
left: 24px;
top: 37px;
}
#b1 {
position:absolute;
left: 20px;
top: 10px;
width: 54px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b2 {
position:absolute;
left: 89px;
top: 10px;
width: 54px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b3 {
position:absolute;
left: 156px;
top: 10px;
width: 52px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b4 {
position:absolute;
left: 222px;
top: 10px;
width: 53px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b5 {
position:absolute;
left: 22px;
top: 48px;
width: 51px;
}
#b6 {
position:absolute;
left: 89px;
top: 48px;
width: 53px;
}
#b7 {
position:absolute;
left: 159px;
top: 48px;
width: 49px;
}
#b8 {
position:absolute;
left: 223px;
top: 48px;
width: 51px;
}
#b9 {
position:absolute;
left: 365px;
top: 48px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b10 {
position:absolute;
left: 364px;
top: 12px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#b11 {
position:absolute;
left: 30px;
top: 76px;
width: 54px;
border: 1px
solid black;
background: whitesmoke;
}
#b12 {
position:absolute;
left: 100px;
top: 76px;
border: 1px
solid black;
background: whitesmoke;
}
#b13 {
position:absolute;
left: 24px;
top: 74px;
width: 57px;
}
#b14 {
position:absolute;
left: 90px;
top: 74px;
}
#b15 {
position:absolute;
left: 474px;
top: 12px;
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#bc {
color: black;
border: 1px
solid black;
background: whitesmoke;
}
#im1 {
position:absolute;
left: 0px;
top: 212px;
width: 95px;
height: 95px;
border: 2px
solid silver;
}
#tr1 {
background-color: #99CCFF;
border-style: solid;
}
#apDiv3 {
position:absolute;
width:179px;
height:26px;
z-index:2;
left: 367px;
top: 18px;
}
.style1 {
font-size: 24px;
font-weight: bold;
}
#apDiv4 {
position:absolute;
left:40px;
top:340px;
width:443px;
height:80px;
z-index:2;
}
#apDiv5 {
position:absolute;
width:200px;
height:120px;
z-index:3;
left: 460px;
top: 80px;
background-color: #99CCFF;
border: 2px
solid silver;
}
#apDiv6 {
position:absolute;
left:685px;
top:80px;
width:190px;
height:120px;
z-index:3;
background-color: #99CCFF;
border: 2px
solid silver;
}
.style4 {font-size: 14px}
#apDiv7 {
position:absolute;
left:47px;
top:408px;
width:700px;
height:132px;
z-index:4;
}
#apDiv8 {
position:absolute;
left:126px;
top:310px;
width:95px;
height:24px;
z-index:5;
}
#apDiv9 {
position:absolute;
left:223px;
top:310px;
width:29px;
height:24px;
z-index:6;
}
#apDiv10 {
position:absolute;
left:254px;
top:310px;
width:88px;
height:24px;
z-index:7;
}
#apDiv11 {
position:absolute;
left:750px;
top:236px;
width:141px;
height:358px;
z-index:9;
}
#apDiv12 {
position:absolute;
left:50px;
top:420px;
}
-->
</style>
</head>
<script language="VB" runat="server">
Dim cnn As
MySqlConnection
Dim saveFile, boldis,
ppf, tk7, tk8, pesanfilter, jrt, caricur, pimage As
String
Dim iis
As Integer
Dim tt1,
tt2, tt3, tt4, tt5, tt6 As String
Dim sc,
scari As String
Dim countstring As String =""
Dim count As Integer = 1
Dim n, nn As Integer
Public Sub connect()
cnn = New
MySqlConnection("User
Id=root;Password=awsm;Host=localhost;Database=ptun")
cnn.Open()
End Sub
Sub
tampildata()
countstring = Request("h1")
If
countstring = "" Then
countstring = "1"
End If
count = CInt(countstring)
connect()
n = count - 1
If n
<= 0 Then
n = 0
End If
Dim ns As String = CStr(n)
Dim
strselect As String
= ""
If
pesanfilter = "" Then
strselect = "select * from brgptun limit " + ns + ",1"
Else
Dim
mm1k As String
= Request("t8")
strselect = "select * from brgptun where nmbrgptun = '" + mm1k + "' limit " + ns + ",1"
End If
Dim da As MySqlDataAdapter = New
MySqlDataAdapter(strselect, cnn)
Dim
myReader As DataSet
myReader = New
DataSet
da.Fill(myReader, "brgptun")
For Each MyRows In
myReader.Tables("brgptun").Rows
Me.t1.Text
= MyRows(0).ToString
Me.t2.Text
= MyRows(1).ToString
Me.t3.Text
= MyRows(2).ToString
Me.t4.Text
= MyRows(3).ToString
Me.t5.Text
= MyRows(4).ToString
Me.t6.Text
= MyRows(5).ToString
Next
cnn.Close()
End Sub
Function
CreateDataSource() As ICollection
' Create
sample data for the DataList control.
Dim dt As DataTable = New
DataTable()
Dim dr As DataRow
' Define the
columns of the table.
dt.Columns.Add(New
DataColumn("no", GetType(Int32)))
dt.Columns.Add(New
DataColumn("nos", GetType(String)))
dt.Columns.Add(New
DataColumn("kbrgptun", GetType(String)))
dt.Columns.Add(New
DataColumn("nmbrgptun", GetType(String)))
dt.Columns.Add(New
DataColumn("typebrgptun", GetType(String)))
dt.Columns.Add(New
DataColumn("pictfilebrgptun", GetType(String)))
dt.Columns.Add(New
DataColumn("vabrgptun", GetType(String)))
dt.Columns.Add(New
DataColumn("pictfilewebbrgptun", GetType(String)))
' Populate
the table with sample values.
countstring = Request("h1")
If
countstring = "" Then
countstring = "1"
End If
count = CInt(countstring)
connect()
Dim nno
As Integer =
count - 2
Dim
nno2 As Integer
= nno / 3
nn = nno2 * 3
If nn
<= 0 Then
nn = 0
End If
Dim nss
As String = CStr(nn)
Dim
strselect As String
= ""
If
pesanfilter = "" Then
strselect = "select * from brgptun limit " + nss + ", 3"
Else
Dim
mm1k As String
= Request("t8")
strselect = "select * from brgptun where nmbrgptun = '" + mm1k + "' limit " + nss + ", 3"
End If
Dim da As MySqlDataAdapter = New
MySqlDataAdapter(strselect, cnn)
Dim
myReader As DataSet
myReader = New
DataSet
da.Fill(myReader, "brgptun")
Dim i As Integer = 0
Dim iss
As Integer = 0
Dim
caricur As String
= ""
For Each MyRows In
myReader.Tables("brgptun").Rows
i = i + 1
iss = i + nn
If
iss = count Then
caricur = " ->"
Else
caricur = CStr(iss)
End
If
dr = dt.NewRow()
dr(0) = iss
dr(1) = caricur
dr(2) = MyRows(0).ToString
dr(3) = MyRows(1).ToString
dr(4) = MyRows(2).ToString
dr(5) = MyRows(3).ToString
dr(6) = MyRows(4).ToString
dr(7) = MyRows(5).ToString
dt.Rows.Add(dr)
Next
cnn.Close()
Dim dv As DataView = New
DataView(dt)
Return
dv
End Function
Sub
tampildata2()
DataList1.DataSource =
CreateDataSource()
DataList1.DataBind()
End Sub
Sub sumc()
connect()
Dim
strselect As String
= ""
If
pesanfilter = "" Then
strselect = "select count(*) as co from brgptun"
Else
Dim
mm1k As String
= Request("t8")
strselect = "select count(*) as co from brgptun where nmbrgptun = '"
+ mm1k + "'"
End If
Dim da As MySqlDataAdapter = New
MySqlDataAdapter(strselect, cnn)
Dim
myReader As DataSet
myReader = New
DataSet
da.Fill(myReader, "brgptun")
For Each MyRows In
myReader.Tables("brgptun").Rows
sc = MyRows(0).ToString
Next
cnn.Close()
End Sub
Sub
page_load(ByVal sender As
Object, ByVal e
As System.EventArgs)
tt1 = ""
tt2 = ""
tt3 = ""
tt4 = ""
tt5 = ""
tt6 = ""
count = 1
Me.tampildata()
Me.tampildata2()
sumc()
Me.Label2.Text
= sc
Me.Label1.Text
= count
If
count <= 0 Then
count = 1
MsgBox("Sudah
diawal record !", MsgBoxStyle.Information, "Perhatian")
Me.Label1.Text
= 1
ElseIf
count >= sc + 1 Then
MsgBox("Sudah
diakhir record !", MsgBoxStyle.Information, "Perhatian")
count = sc
End If
End Sub
Sub bt5()
Me.t1.Text
= ""
Me.t2.Text
= ""
Me.t3.Text
= ""
Me.t4.Text
= ""
Me.t5.Text
= ""
Me.t6.Text
= ""
End Sub
Sub bt6()
Try
Me.connect()
Dim
mm1 As String =
Request("t1")
Dim
mm2 As String =
Request("t2")
Dim
mm3 As String =
Request("t3")
Dim
mm4 As String =
Request("t4")
Dim
mm5 As String =
Request("t5")
Dim
mm6 As String =
Request("t6")
Dim
strselect As String
If
mm4 = "" Then
strselect = "insert into
brgptun(kbrgptun,nmbrgptun,typebrgptun,pictfilebrgptun,vabrgptun,pictfilewebbrgptun)values('"
+ mm1 + "','" + mm2 + "','" + mm3 + "','"
+ mm4 + "','" + mm5 + "','" + mm6 + "')"
Dim
sqlku As MySqlCommand = New MySqlCommand(strselect, cnn)
sqlku.ExecuteNonQuery()
Else
Dim
mbytes() As Byte
= System.IO.File.ReadAllBytes(mm4)
strselect = "insert into brgptun(kbrgptun,nmbrgptun,typebrgptun,pictfilebrgptun,vabrgptun,pictfilewebbrgptun,pictbrgptun)values('"
+ mm1 + "','" + mm2 + "','" + mm3 + "','"
+ mm4 + "','" + mm5 + "','" + mm6 + "',@ss)"
Dim
sqlku As MySqlCommand = New MySqlCommand(strselect, cnn)
sqlku.Parameters.Add("@ss", MySqlDbType.Binary,
mbytes.Length).Value = mbytes
sqlku.ExecuteNonQuery()
End
If
cnn.Close()
Catch
ex As Exception
MsgBox("Error:
" & ex.Source & ": "
& ex.Message, _
MsgBoxStyle.OkOnly, "Button6_Click")
Me.t1.Focus()
'Me.b6.Enabled
= True
'Me.b5.Enabled
= False
End Try
End Sub
Sub bt7()
Try
Me.connect()
Dim
mm1 As String =
Request("t1")
Dim
mm2 As String =
Request("t2")
Dim
mm3 As String =
Request("t3")
Dim
mm4 As String =
Request("t4").Replace("null", "")
Dim
mm5 As String =
Request("t5")
Dim
mm6 As String =
Request("t6")
Dim
mm1k As String
= Request("t1")
Dim
strselect As String
If
mm4 = "" Or
mm4 = "null" Then
strselect = "update
brgptun set kbrgptun='" + mm1 + "',nmbrgptun='"
+ mm2 + "',typebrgptun='" + mm3 + "',pictfilebrgptun ='" + mm4 + "',vabrgptun='" + mm5 + "',pictfilewebbrgptun ='" + mm6 + "' where
kbrgptun='" + mm1k + "' "
Dim
sqlku As MySqlCommand = New MySqlCommand(strselect, cnn)
sqlku.ExecuteNonQuery()
Else
Dim
mbytes() As Byte
= System.IO.File.ReadAllBytes(mm4)
strselect = "update
brgptun set kbrgptun='" + mm1 + "',nmbrgptun='"
+ mm2 + "',typebrgptun='" + mm3 + "',pictfilebrgptun ='" + mm4 + "',vabrgptun='" + mm5 + "',pictfilewebbrgptun ='" + mm6 + "',pictbrgptun =@ss
where kbrgptun='" + mm1k + "' "
Dim
sqlku As MySqlCommand = New MySqlCommand(strselect, cnn)
sqlku.Parameters.Add("@ss", MySqlDbType.Binary,
mbytes.Length).Value = mbytes
sqlku.ExecuteNonQuery()
End
If
cnn.Close()
Catch
ex As Exception
MsgBox("Error:
" & ex.Source & ": "
& ex.Message, _
MsgBoxStyle.OkOnly, "Button7_Click")
MsgBox("Ada
kesalahan yang mendasar dalam hal penulisan File Gambar Barangnya atau ada
kesalahan lainnya", MsgBoxStyle.Critical, "Perhatian")
Me.t4.Focus()
End Try
End Sub
Sub bt8()
Dim pp As String
pp = MsgBox("Apakah
Data ini yakin akan dihapus", MsgBoxStyle.YesNo, "Perhatian")
If pp =
6 Then
Try
Me.connect()
Dim
mm1k As String
= Request("t1")
Dim
strselect As String
= "delete from brgptun where kbrgptun =
'" + mm1k + "'"
Dim
sqlku As MySqlCommand = New MySqlCommand(strselect, cnn)
sqlku.ExecuteNonQuery()
cnn.Close()
Catch
ex As Exception
MsgBox("Error:
" & ex.Source & ": "
& ex.Message, _
MsgBoxStyle.OkOnly, "Button8_Click")
End
Try
End If
End Sub
Sub bcari()
Try
Me.connect()
Dim
mm1k As String
= Request("t7")
Dim
strselect As String
= "select count(*) as co from brgptun where
kbrgptun <= '" + mm1k + "'"
Dim
da As MySqlDataAdapter = New MySqlDataAdapter(strselect, cnn)
Dim
myReader As DataSet
myReader = New
DataSet
da.Fill(myReader, "brgptun")
For
Each MyRows In
myReader.Tables("brgptun").Rows
scari = MyRows(0).ToString
Next
cnn.Close()
Me.b11.NavigateUrl
= "http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1="
+ scari + ""
Catch
ex As Exception
MsgBox("Error:
" & ex.Source & ": "
& ex.Message, _
MsgBoxStyle.OkOnly, "Perhatian")
End Try
End Sub
Sub
bfilter()
Me.Label3.Text
= "Data sedang keadaan sedang di filter, Perhatian
!"
pesanfilter = "Data
sedang keadaan sedang di filter, Perhatian !"
tampildata()
tampildata2()
'sumc()
End Sub
Sub
bendfilter()
Me.Label3.Text
= ""
pesanfilter = ""
tampildata()
tampildata2()
'sumc()
End Sub
</script>
<body>
<form runat='server'
name='f1' id='f1' method='POST' enctype='multipart/form-data'
>
<div id='apDiv1'>
<div id='apDiv2'>
<label>Kode
Barang</label>
<p>
<asp:TextBox ID="t1" runat="server"></asp:TextBox>
<label>Nama
Barang</label>
<asp:TextBox ID="t2" runat="server"></asp:TextBox>
</p>
<p><label>Type
Barang</label>
<asp:TextBox ID="t3" runat="server"></asp:TextBox>
</p>
<p><label>Picture
File</label>
<asp:TextBox ID="t4" runat="server"></asp:TextBox>
</p>
<p><label>VA Barang</label>
<asp:TextBox ID="t5" runat="server"></asp:TextBox>
</p>
<p><label>Picture
Web</label><br/><label>(Upload(.jpeg))</label>
<asp:TextBox ID="t6" runat="server"></asp:TextBox>
<input type='file' name='pf' id='pf' />
</p>
<asp:HiddenField ID="h1" runat="server" Value="1" />
<asp:HiddenField ID="hpf" runat="server" />
</div
<div class='style1' id='apDiv3'>DATA BARANG</div>
<div id='apDiv5'>
<asp:TextBox ID="t7"
OnTextChanged="bcari"
ToolTip="Input
data lalu enter, kemudian klik Find" runat="server"></asp:TextBox>
<asp:HyperLink ID="b11"
runat="server"><center>Find</center></asp:HyperLink>
<a id="b12" href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=0"><center>End Find</center></a>
<label id='l1'><span class='style4'>Untuk
Cari Kode Barang disini</span></label>
</div>
<div id='apDiv4'>
<a id='b1' href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=1"><center><<</center></a>
<a id='b2' href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=<%=count-1%>"><center><</center></a>
<a id='b3' href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=<%=count+1%>"><center>></center></a>
<a id='b4' href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=<%=me.label2.text%>"><center>>></center></a>
<asp:Button ID="b5" runat="server" OnClick="bt5" Text="Add" />
<asp:Button ID="b6" runat="server" OnClick="bt6" Text="Save" />
<asp:Button ID="b7" runat="server" OnClick="bt7" Text="Edit" />
<asp:Button ID="b8" runat="server" OnClick="bt8" Text="Delete" />
<a id='b9' href='http://localhost'>_Exit_</a>
<a id='b10' href='http://localhost/reportbarang.php?t8=$tk8' target='blank'>_Report_</a>
<a id='b15' href='http://localhost/exportexcelbarang.php?t8=$tk8'>_Export(excel)_</a>
</div>
<div id='apDiv6'>
<asp:TextBox ID="t8" runat="server"></asp:TextBox>
<asp:Button ID="b13" OnClick="bfilter" runat="server" Text="Filter" />
<asp:Button ID="b14" OnClick="bendfilter" runat="server" Text="End Filter" />
<label>U<span class='style4'>ntuk
Filter berdasarkan
Nama Barang disini ...</span></label>
</div>
<div id='apDiv7'>
<table id='tb1' width='700' border='1' cellspacing='0' cellspading='0'>
<tr id='tr1'>
<td>*</td>
<td>Kode Barang</td>
<td>Nama Barang</td>
<td>Type Barang</td>
<td>Picture
File</td>
<td>VA Barang</td>
<td>Picture Web</td>
<asp:DataList ID="DataList1" runat="server" CellPadding="0" CellSpacing="0" RepeatLayout="Flow">
<ItemTemplate>
</tr>
<td><a id='bc' href="http://localhost:1035/WebSitePtun/Form_Barang.aspx?h1=<%#DataBinder.Eval(Container,
"DataItem.no")%>">_<%#DataBinder.Eval(Container,
"DataItem.nos")%>_</a></td>
<td><%#DataBinder.Eval(Container, "DataItem.kbrgptun")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.nmbrgptun")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.typebrgptun")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.pictfilebrgptun")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.vabrgptun")%></td>
<td><%#DataBinder.Eval(Container, "DataItem.pictfilewebbrgptun")%></td>
</tr>
</ItemTemplate>
</asp:DataList>
</table>
</div>
<div id="apDiv8"><asp:Label ID="Label1" runat="server" Text="1"></asp:Label></div>
<div class="style4"
id="apDiv9">Dari</div>
<div id="apDiv10"><asp:Label ID="Label2" runat="server" Text="0"></asp:Label></div>
<div id='apDiv11'>
<input type='image' name='im1' id='im1' src="http://localhost:1035/WebSitePtun/imgfile.aspx?id=<%=me.t1.text %>" alt='(Gambar/ foto
kosong) Ket: Gambar harus berekstensi
(.jpeg/.jpg)'/>
</div>
<div id="apDiv12"><b><asp:Label ID="Label3" runat="server" Text=""></asp:Label></b></div>
</form>
</div>
</body>
</html>
imgfile.aspx
<%@ Import Namespace="System.Data"
%>
<%@ Import Namespace="MySql.Data.MySqlClient"
%>
<%@ Import Namespace="System.Data.Dataset"
%>
<%@ Import Namespace="System.Web.Ui.Control"
%>
<%@ Import Namespace="System"
%>
<script runat="server">
Sub
Page_load(ByVal sender As
Object, ByVal e
As System.EventArgs) Handles
Me.Load
try
Dim cnn
As MySqlConnection
cnn = New
MySqlConnection("User Id=root;Password=awsm;Host=localhost;Database=ptun")
cnn.Open()
Dim ss As String = Request("id")
Const
SQL As String =
"SELECT
pictbrgptun FROM brgptun where kbrgptun=@ii"
Dim
myCommand As New
MySqlCommand(SQL, cnn)
myCommand.Parameters.AddWithValue("@ii", ss)
Dim
myReader As MySqlDataReader =
myCommand.ExecuteReader
If
myReader.Read Then
Response.BinaryWrite(myReader("pictbrgptun"))
End If
myReader.Close()
cnn.Close()
Catch
ex As Exception
End Try
End Sub
</script>
Tidak ada komentar:
Posting Komentar