<%@ Page Language="VB" MasterPageFile="~/day02/MyMaster.master" Title="ObjectDataSourceコントロール" Theme="Spring" %>

<script runat="server">
    Dim sum As Integer = 0
    Protected Sub grid_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
        Select Case e.Row.RowType
            Case DataControlRowType.DataRow
                Dim crt As Cart = DirectCast(e.Row.DataItem, Cart)
                sum += crt.SubTotal
            Case DataControlRowType.Footer
                Dim sumstr As String = sum.ToString("#,####円")
                e.Row.Cells(3).Controls.Add(New LiteralControl(sumstr))
        End Select
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            txtName.Text = Profile.CustomerName
            txtAddress.Text = Profile.UserAddress
        End If
    End Sub

    Protected Sub btnOrder_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Profile.CustomerName = txtName.Text
        Profile.UserAddress = txtAddress.Text
        Dim crt As New Cart()
        crt.InsertCartInfo()
        Session.Abandon()
        Response.Redirect("DataList.aspx")
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="cph" Runat="Server">
    <asp:GridView ID="grid" runat="server" Caption="カート精算" DataSourceID="ods"
        EmptyDataText="カートの中身は空です。" ShowFooter="True" OnRowDataBound="grid_RowDataBound" AutoGenerateColumns="False" DataKeyNames="isbn">
        <Columns>
            <asp:BoundField DataField="title" HeaderText="書名" />
            <asp:BoundField DataField="price" DataFormatString="{0:#,###円}" HeaderText="単価" HtmlEncode="False" />
            <asp:BoundField DataField="Quantity" HeaderText="購入数" />
            <asp:BoundField DataField="SubTotal" DataFormatString="{0:#,###円}" HeaderText="小計"
                HtmlEncode="False" />
            <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
        </Columns>
    </asp:GridView>
    <asp:ObjectDataSource ID="ods" runat="server" DataObjectTypeName="Cart" DeleteMethod="DeleteCartInfo"
        SelectMethod="GetCartInfo" TypeName="Cart"></asp:ObjectDataSource>
    <br />
    お名前：<br />
    <asp:TextBox ID="txtName" runat="server" Columns="15"></asp:TextBox><br />
    お届け先（都道府県から）：<br />
    <asp:TextBox ID="txtAddress" runat="server" Columns="50"></asp:TextBox><br />
    <br />
    <asp:Button ID="btnOrder" runat="server" Text="注文を確定" OnClick="btnOrder_Click" />
</asp:Content>

