14 September 2011
KASIR
<%@ Page Language="VB" MasterPageFile="~/HalamanMaster.master" AutoEventWireup="false" CodeFile="Kasir.aspx.vb" Inherits="Kasir" title="Halaman Kasir" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="font-size: 10pt; width: 100%; font-family: Tahoma">
<strong>
Daftar Barang yang dibeli</strong></td>
</tr>
<tr>
<td style="font-size: 10pt; width: 100%; font-family: Tahoma">
</td>
</tr>
<tr>
<td style="font-size: 10pt; width: 100%; font-family: Tahoma">
<table border="1" width="100%">
<tr>
<td style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma;
background-color: gainsboro">
Kode</td>
<td style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma;
background-color: gainsboro">
Nama Barang</td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma;
background-color: gainsboro">
Jumlah</td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma;
background-color: gainsboro">
Harga</td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma;
background-color: gainsboro">
Total</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td style="font-size: 10pt; width: 10%; font-family: Tahoma">
<asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Kode")%>'></asp:Label></td>
<td style="font-size: 10pt; width: 40%; font-family: Tahoma">
<asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Nama")%>'></asp:Label></td>
<td align="right" style="font-size: 10pt; width: 10%; font-family: Tahoma">
<asp:TextBox ID="txtJumlah" runat="server" Width="20px" Text='<%#DataBinder.Eval(Container.DataItem, "Jumlah")%>'></asp:TextBox></td>
<td align="right" style="font-size: 10pt; width: 20%; font-family: Tahoma">
<asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Harga", "{0:n}")%>'></asp:Label></td>
<td align="right" style="font-size: 10pt; width: 20%; font-family: Tahoma">
<asp:Label ID="Label4" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Total", "{0:n}")%>'></asp:Label></td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr>
<td align="right" colspan="2" style="font-weight: bold; font-size: 10pt; width: 100px;
font-family: Tahoma">
Grand Total :
</td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma">
<asp:Label ID="Jumlah" runat="server" Text="0"></asp:Label></td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma">
</td>
<td align="right" style="font-weight: bold; font-size: 10pt; width: 100px; font-family: Tahoma">
<asp:Label ID="Total" runat="server" Text="0"></asp:Label></td>
</tr>
</table>
</td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Refresh" />
<asp:Button ID="Button2" runat="server" Text="Lanjut" PostBackUrl="~/Pembayaran.aspx" />
</asp:Content>
KASIR.ASPX.VB
Partial Class Kasir
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not PreviousPage Is Nothing AndAlso PreviousPage.IsCrossPagePostBack Then
Dim itemBeli As Integer
Dim itemPilihan As ArrayList = New ArrayList()
' Cek apakah pembelian dari Halaman Default atau Produk
If (Request.QueryString("from") = "produk") Then
itemPilihan = CType(Me.PreviousPage, _Produk).dataList()
Else
itemPilihan = CType(Me.PreviousPage, _Default).dataList()
End If
' Dapatkan jumlah Barang yang telah dibeli
itemBeli = Session("ItemBeli")
' Cek apakah Kodebarang yang sama telah terdapat pada Session
If Not cekItemSama(itemPilihan(0)) Then
' Simpan Barang ke Session
Session("Kode_" & itemBeli) = itemPilihan(0)
Session("Nama_" & itemBeli) = itemPilihan(1)
Session("Jumlah_" & itemBeli) = itemPilihan(2)
Session("Harga_" & itemBeli) = itemPilihan(3)
Session("Total_" & itemBeli) = itemPilihan(2) * itemPilihan(3)
' Jumlah barang ditamba 1
itemBeli += 1
' Simpan jumlah barang dalam session
Session("ItemBeli") = itemBeli
End If
' Tampilkan daftar barang pada halaman Kasir
tampilkanData()
End If
End Sub
Private Sub tampilkanData()
' Tampilkan daftar barang
Dim a As ArrayList = New ArrayList()
Dim itemBeli As Integer
Dim i As Integer
Dim totalItem As Integer = 0
Dim totalHarga As Double = 0
itemBeli = Session("ItemBeli")
For i = 0 To itemBeli - 1
a.Add(New DataKasir(Session("Kode_" & i), Session("Nama_" & i), Session("Jumlah_" & i), Session("Harga_" & i), Session("Total_" & i)))
totalItem += Session("Jumlah_" & i)
totalHarga += Session("Total_" & i)
Next
Me.Jumlah.Text = totalItem
Me.Total.Text = Format(totalHarga, "#,##0.00")
Repeater1.DataSource = a
Repeater1.DataBind()
End Sub
Private Function cekItemSama(ByVal kode As String) As Boolean
' Mengecek apakan barang telah ada didalam session
Dim totalItem As Integer = Session("ItemBeli")
Dim i As Integer
Dim status As Boolean = False
For i = 0 To totalItem
If (Session("Kode_" & i) = kode) Then
status = True
End If
Next
cekItemSama = status
End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' Cek ulang jumlah barang yang dibeli
Dim totItem As Integer = Repeater1.Items.Count
Dim jumlahBarang As Integer
Dim hargaBarang As Double
Dim i As Integer
For i = 0 To totItem - 1
jumlahBarang = IIf(CType(Repeater1.Items(i).FindControl("txtJumlah"), TextBox).Text = "", 0, _
CType(Repeater1.Items(i).FindControl("txtJumlah"), TextBox).Text)
hargaBarang = CDbl(Session("Harga_" & i))
Session("Jumlah_" & i) = jumlahBarang
Session("Total_" & i) = jumlahBarang * hargaBarang
Next
tampilkanData()
End Sub
End Class
' Class untuk Data Kasir
Public Class DataKasir
Private myKode As String
Private myNama As String
Private myJumlah As Integer
Private myHarga As Double
Private myTotal As Double
Public Sub New(ByVal nKode As String, ByVal nNama As String, ByVal nJumlah As Integer, ByVal nHarga As Double, ByVal nTotal As Double)
Me.myKode = nKode
Me.myNama = nNama
Me.myJumlah = nJumlah
Me.myHarga = nHarga
Me.myTotal = nTotal
End Sub
Public ReadOnly Property Kode() As String
Get
Return myKode
End Get
End Property
Public ReadOnly Property Nama() As String
Get
Return myNama
End Get
End Property
Public ReadOnly Property Jumlah() As Integer
Get
Return myJumlah
End Get
End Property
Public ReadOnly Property Harga() As Double
Get
Return myHarga
End Get
End Property
Public ReadOnly Property Total() As Double
Get
Return myTotal
End Get
End Property
End Class
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar