<%@ Page Language="VB" MasterPageFile="~/HalamanMaster.master" AutoEventWireup="false" CodeFile="Pembayaran.aspx.vb" Inherits="Pembayaran" title="Pembayaran" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table border="1" style="font-size: 10pt; font-family: Tahoma" width="100%">
<tr>
<td colspan="2" style="text-align: center">
<strong>FORM PEMBAYARAN</strong></td>
</tr>
<tr>
<td align="left" colspan="2" valign="top">
<asp:SqlDataSource ID="SdsHeader" runat="server" ConnectionString="<%$ ConnectionStrings:ShoppingCartConnectionString %>"
DeleteCommand="DELETE FROM [TBLOrderHeader] WHERE [NoOrder] = @NoOrder" InsertCommand="INSERT INTO [TBLOrderHeader] ([NoOrder], [Tanggal], [NamaCustomer], [Email], [AlamatKirim], [TipeBayar], [NoRef], [TotalItem], [TotalHarga]) VALUES (@NoOrder, @Tanggal, @NamaCustomer, @Email, @AlamatKirim, @TipeBayar, @NoRef, @TotalItem, @TotalHarga)"
SelectCommand="SELECT * FROM [TBLOrderHeader]" UpdateCommand="UPDATE [TBLOrderHeader] SET [Tanggal] = @Tanggal, [NamaCustomer] = @NamaCustomer, [Email] = @Email, [AlamatKirim] = @AlamatKirim, [TipeBayar] = @TipeBayar, [NoRef] = @NoRef, [TotalItem] = @TotalItem, [TotalHarga] = @TotalHarga WHERE [NoOrder] = @NoOrder">
<DeleteParameters>
<asp:Parameter Name="NoOrder" Type="Decimal" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Tanggal" Type="DateTime" />
<asp:Parameter Name="NamaCustomer" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="AlamatKirim" Type="String" />
<asp:Parameter Name="TipeBayar" Type="String" />
<asp:Parameter Name="NoRef" Type="String" />
<asp:Parameter Name="TotalItem" Type="Decimal" />
<asp:Parameter Name="TotalHarga" Type="Decimal" />
<asp:Parameter Name="NoOrder" Type="Decimal" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="NoOrder" Type="Decimal" />
<asp:ControlParameter ControlID="Tanggal" Name="Tanggal" PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="NamaCustomer" Name="NamaCustomer" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="Email" Name="Email" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="AlamatKirim" Name="AlamatKirim" PropertyName="Text"
Type="String" />
<asp:ControlParameter ControlID="TipeBayar" Name="TipeBayar" PropertyName="SelectedValue"
Type="String" />
<asp:ControlParameter ControlID="NoRef" Name="NoRef" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="TotalItem" Name="TotalItem" PropertyName="Text"
Type="Decimal" />
<asp:ControlParameter ControlID="TotalHarga" Name="TotalHarga" PropertyName="Text"
Type="Decimal" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SdsDetail" runat="server" ConnectionString="<%$ ConnectionStrings:ShoppingCartConnectionString %>"
SelectCommand="SELECT * FROM [TBLOrderDetail]" InsertCommand="INSERT INTO TBLOrderDetail(NoOrder, NoBaris, KodeBarang, JumlahItem, HargaSatuan, TotalHarga) VALUES (@NoOrder, @NoBaris, @KodeBarang, @JumlahItem, @HargaSatuan, @TotalHarga)">
<InsertParameters>
<asp:Parameter Name="NoOrder" />
<asp:Parameter Name="NoBaris" />
<asp:Parameter Name="KodeBarang" />
<asp:Parameter Name="JumlahItem" />
<asp:Parameter Name="HargaSatuan" />
<asp:Parameter Name="TotalHarga" />
</InsertParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Tanggal</td>
<td align="left" style="width: 80%" valign="top">
<asp:Label ID="Tanggal" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Nama Customer</td>
<td align="left" style="width: 80%" valign="top">
<asp:TextBox ID="NamaCustomer" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Email</td>
<td align="left" style="width: 80%" valign="top">
<asp:TextBox ID="Email" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Alamat</td>
<td align="left" style="width: 80%" valign="top">
<asp:TextBox ID="AlamatKirim" runat="server" Height="61px" TextMode="MultiLine" Width="388px"></asp:TextBox></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Tipe Bayar</td>
<td align="left" style="width: 80%" valign="top">
<asp:DropDownList ID="TipeBayar" runat="server">
<asp:ListItem Selected="True">Credit Card</asp:ListItem>
<asp:ListItem>Transfer</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
No Referensi</td>
<td align="left" style="width: 80%" valign="top">
<asp:TextBox ID="NoRef" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Jumlah Barang</td>
<td align="left" style="width: 80%" valign="top">
<asp:Label ID="TotalItem" runat="server" Text="Label"></asp:Label></td>
</tr>
<tr>
<td align="left" style="width: 20%" valign="top">
Total Pembayaran</td>
<td align="left" style="width: 80%" valign="top">
<asp:Label ID="TotalHarga" runat="server" Visible="false" Text="Label"></asp:Label>
<asp:Label ID="TotalFormat" runat="server" Text="Label"></asp:Label></td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Simpan" />
</asp:Content>
PEMBAYARAN.ASPX.VB
Imports DSShoppingCartTableAdapters
Partial Class Pembayaran
Inherits System.Web.UI.Page
Dim NomorOrder As Integer
Private Function dapatkanNoOrderbaru() As Integer
' Fungsi untuk mendapatkan No Order Terbaru
Dim NoOrderBaru As DtNoOrderTableAdapter = New DtNoOrderTableAdapter
Dim dt As Data.DataTable
dt = NoOrderBaru.NoOrderBaru()
Dim NoBaru As Integer
If (dt.Rows(0)(0).ToString() = Nothing) Then
NoBaru = 1
Else
NoBaru = CInt(dt.Rows(0)(0))
End If
dapatkanNoOrderbaru = NoBaru
End Function
Private Sub simpanDetailOrder()
' Fungsi untuk menyimpan Detail Order
Dim i As Integer
Dim itemBeli As Integer
itemBeli = Session("ItemBeli")
For i = 0 To itemBeli - 1
Me.SdsDetail.InsertParameters(0).DefaultValue = NomorOrder
Me.SdsDetail.InsertParameters(1).DefaultValue = i + 1
Me.SdsDetail.InsertParameters(2).DefaultValue = Session("Kode_" & i)
Me.SdsDetail.InsertParameters(3).DefaultValue = Session("Jumlah_" & i)
Me.SdsDetail.InsertParameters(4).DefaultValue = Session("Harga_" & i)
Me.SdsDetail.InsertParameters(5).DefaultValue = Session("Total_" & i)
Me.SdsDetail.Insert()
Next
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Deklarasi Variabel
Dim i As Integer
Dim totalItem As Integer = 0
Dim totalHarga As Double = 0
Dim itemBeli As Integer
Me.Tanggal.Text = DateTime.Now
itemBeli = Session("ItemBeli")
' Meghitung Total Barang dan Total Harga
For i = 0 To itemBeli - 1
totalItem += Session("Jumlah_" & i)
totalHarga += Session("Total_" & i)
Next
Me.TotalHarga.Text = totalHarga
Me.TotalFormat.Text = Format(totalHarga, "#,##00.00")
Me.TotalItem.Text = totalItem
NomorOrder = 0
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
' Cek apakah input telah lengkap
If (Me.NamaCustomer.Text <> "" And Me.AlamatKirim.Text <> "" _
And CDbl(Me.TotalHarga.Text) <> 0 And Me.NoRef.Text <> "") Then
' Panggil fungsi dapatkanNoOrderbaru
NomorOrder = dapatkanNoOrderbaru()
' Simpan Header Order
Me.SdsHeader.Insert()
' Panggil fungsi simpanDetailOrder
simpanDetailOrder()
' Tampilkan Halaman Terimakasih
Response.Redirect("~/Terimakasih.aspx")
Else
MsgBox("Input Belum Lengkap", MsgBoxStyle.Information, "Simpan")
End If
End Sub
Protected Sub SdsHeader_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SdsHeader.Inserting
' Masukan Parameter NoOrder
e.Command.Parameters(0).Value = NomorOrder
End Sub
End Class
Tidak ada komentar:
Posting Komentar