質問編集履歴
1
ソースコード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,174 @@
|
|
26
26
|
|
27
27
|
http://s1.gazo.cc/up/173798.png
|
28
28
|
|
29
|
+
上の3画面のvbソースコードになります↓
|
30
|
+
|
31
|
+
Imports System.Data
|
32
|
+
|
33
|
+
Partial Class Default2
|
34
|
+
|
35
|
+
Inherits System.Web.UI.Page
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
Private Function GetNew_order_no() As Integer
|
40
|
+
|
41
|
+
Dim order_no As Integer = 0 '伝票番号
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
'注文テーブルから伝票番号の最大値を取得
|
46
|
+
|
47
|
+
Dim args As DataSourceSelectArguments = New DataSourceSelectArguments()
|
48
|
+
|
49
|
+
Dim dataview As DataView = CType(SqlDataSource_order1.Select(args), DataView)
|
50
|
+
|
51
|
+
If dataview.Table.Rows(0).ItemArray.GetValue(0) Is DBNull.Value Then
|
52
|
+
|
53
|
+
'存在していないとき
|
54
|
+
|
55
|
+
order_no = 1
|
56
|
+
|
57
|
+
Else
|
58
|
+
|
59
|
+
'存在しているとき
|
60
|
+
|
61
|
+
order_no = dataview.Table.Rows(0).ItemArray.GetValue(0) + 1
|
62
|
+
|
63
|
+
End If
|
64
|
+
|
65
|
+
'伝票番号を返す
|
66
|
+
|
67
|
+
Return order_no
|
68
|
+
|
69
|
+
End Function
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
Protected Sub Button_cart_Click1(sender As Object, e As EventArgs)
|
74
|
+
|
75
|
+
'伝票番号の取得
|
76
|
+
|
77
|
+
Dim order_no As Integer = 0 '伝票番号
|
78
|
+
|
79
|
+
If Session("order_no") Is Nothing Then
|
80
|
+
|
81
|
+
'セッションオブジェクトに存在していないときは伝票番号取得
|
82
|
+
|
83
|
+
order_no = GetNew_order_no()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
'注文テーブルの更新
|
88
|
+
|
89
|
+
SqlDataSource_order1.InsertParameters("order_no").DefaultValue = order_no
|
90
|
+
|
91
|
+
SqlDataSource_order1.InsertParameters("customer_id").DefaultValue = 0
|
92
|
+
|
93
|
+
SqlDataSource_order1.InsertParameters("date").DefaultValue = Now()
|
94
|
+
|
95
|
+
SqlDataSource_order1.InsertParameters("order_sts").DefaultValue = 0
|
96
|
+
|
97
|
+
Try
|
98
|
+
|
99
|
+
SqlDataSource_order1.Insert()
|
100
|
+
|
101
|
+
Catch ex As Exception
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
End Try
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
'注文番号の保存
|
110
|
+
|
111
|
+
Session("order_no") = order_no
|
112
|
+
|
113
|
+
Else
|
114
|
+
|
115
|
+
'セッションオブジェクトから伝票番号を取得
|
116
|
+
|
117
|
+
order_no = CInt(Session("order_no"))
|
118
|
+
|
119
|
+
End If
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
'注文明細テーブルの更新
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
'注文明細に存在するかチェック
|
128
|
+
|
129
|
+
Dim item_id As Label = CType(sender, Button).Parent.FindControl("IDLabel")
|
130
|
+
|
131
|
+
Dim args As DataSourceSelectArguments = New DataSourceSelectArguments() '商品ID
|
132
|
+
|
133
|
+
SqlDataSource_order_detail.SelectParameters("item_id").DefaultValue = item_id.Text '同一伝票No
|
134
|
+
|
135
|
+
Dim dataview As DataView = CType(SqlDataSource_order_detail.Select(args), DataView) '同一商品No
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
If dataview.Table.Rows.Count < 1 Then
|
140
|
+
|
141
|
+
'存在しないときは、レコードの追加
|
142
|
+
|
143
|
+
SqlDataSource_order_detail.InsertParameters("order_no").DefaultValue = order_no
|
144
|
+
|
145
|
+
SqlDataSource_order_detail.InsertParameters("item_id").DefaultValue = item_id.Text
|
146
|
+
|
147
|
+
SqlDataSource_order_detail.InsertParameters("quantity").DefaultValue = 1
|
148
|
+
|
149
|
+
Try
|
150
|
+
|
151
|
+
SqlDataSource_order_detail.Insert()
|
152
|
+
|
153
|
+
Catch ex As Exception
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
End Try
|
158
|
+
|
159
|
+
Else
|
160
|
+
|
161
|
+
'存在する時は、数量更新
|
162
|
+
|
163
|
+
SqlDataSource_order_detail.InsertParameters("order_no").DefaultValue = order_no
|
164
|
+
|
165
|
+
SqlDataSource_order_detail.UpdateParameters("item_id").DefaultValue = item_id.Text
|
166
|
+
|
167
|
+
SqlDataSource_order_detail.UpdateParameters("quantity").DefaultValue = _
|
168
|
+
|
169
|
+
dataview.Table.Rows(0).ItemArray.GetValue(2) + 1
|
170
|
+
|
171
|
+
Try
|
172
|
+
|
173
|
+
SqlDataSource_order_detail.Update()
|
174
|
+
|
175
|
+
Catch ex As Exception
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
End Try
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
End If
|
184
|
+
|
185
|
+
End Sub
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
Protected Sub SqlDataSource_order1_Selecting(sender As Object, e As SqlDataSourceSelectingEventArgs) Handles SqlDataSource_order1.Selecting
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
End Sub
|
194
|
+
|
195
|
+
End Class
|
196
|
+
|
29
197
|
注文テーブルデザイン画面↓
|
30
198
|
|
31
199
|
http://s1.gazo.cc/up/173794.png
|
@@ -38,6 +206,192 @@
|
|
38
206
|
|
39
207
|
http://s1.gazo.cc/up/173789.png
|
40
208
|
|
209
|
+
上の2画面のhtmlソースコードです
|
210
|
+
|
211
|
+
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="1-4cart.aspx.vb" Inherits="_1_4cart" %>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
|
216
|
+
|
217
|
+
</asp:Content>
|
218
|
+
|
219
|
+
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
|
220
|
+
|
221
|
+
<br />
|
222
|
+
|
223
|
+
<span style="font-size: 14pt;"><strong>カートの中身</strong></span><asp:GridView ID="GridView_order" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource_view_order" CellPadding="3" EmptyDataText="カート内に商品がありません。" GridLines="Vertical" Width="790px" Font-Size="11pt" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">
|
224
|
+
|
225
|
+
<Columns>
|
226
|
+
|
227
|
+
<asp:BoundField DataField="order_no" HeaderText="order_no" SortExpression="order_no"
|
228
|
+
|
229
|
+
Visible="False" />
|
230
|
+
|
231
|
+
<asp:BoundField DataField="item_id" HeaderText="商品ID" SortExpression="item_id" >
|
232
|
+
|
233
|
+
<HeaderStyle Width="80px" />
|
234
|
+
|
235
|
+
</asp:BoundField>
|
236
|
+
|
237
|
+
<asp:BoundField DataField="item_name" HeaderText="商品名" SortExpression="item_name" >
|
238
|
+
|
239
|
+
<HeaderStyle Width="300px" />
|
240
|
+
|
241
|
+
</asp:BoundField>
|
242
|
+
|
243
|
+
<asp:BoundField DataField="price_wt" DataFormatString="{0:c}" HeaderText="税込単価" ReadOnly="True"
|
244
|
+
|
245
|
+
SortExpression="price_wt" HtmlEncode="False">
|
246
|
+
|
247
|
+
<HeaderStyle HorizontalAlign="Right" Width="110px" />
|
248
|
+
|
249
|
+
<ItemStyle HorizontalAlign="Right" />
|
250
|
+
|
251
|
+
</asp:BoundField>
|
252
|
+
|
253
|
+
<asp:TemplateField HeaderText="購入数量" SortExpression="quantity">
|
254
|
+
|
255
|
+
<EditItemTemplate>
|
256
|
+
|
257
|
+
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("quantity") %>'></asp:TextBox>
|
258
|
+
|
259
|
+
</EditItemTemplate>
|
260
|
+
|
261
|
+
<ItemTemplate>
|
262
|
+
|
263
|
+
<asp:TextBox ID="TextBox_quantity" runat="server" Style="text-align: right" Text='<%# Bind("quantity") %>'
|
264
|
+
|
265
|
+
Width="50px" MaxLength="7"></asp:TextBox>
|
266
|
+
|
267
|
+
</ItemTemplate>
|
268
|
+
|
269
|
+
<HeaderStyle HorizontalAlign="Right" Width="100px" />
|
270
|
+
|
271
|
+
<ItemStyle HorizontalAlign="Right" />
|
272
|
+
|
273
|
+
</asp:TemplateField>
|
274
|
+
|
275
|
+
<asp:BoundField DataField="total_price_wt" DataFormatString="{0:c}" HeaderText="税込金額"
|
276
|
+
|
277
|
+
ReadOnly="True" SortExpression="total_price_wt" HtmlEncode="False">
|
278
|
+
|
279
|
+
<HeaderStyle HorizontalAlign="Right" Width="110px" />
|
280
|
+
|
281
|
+
<ItemStyle HorizontalAlign="Right" />
|
282
|
+
|
283
|
+
</asp:BoundField>
|
284
|
+
|
285
|
+
<asp:ButtonField ButtonType="Button" CommandName="_upd" HeaderText="更新" ShowHeader="True"
|
286
|
+
|
287
|
+
Text="更新" >
|
288
|
+
|
289
|
+
<HeaderStyle Width="50px" />
|
290
|
+
|
291
|
+
<ItemStyle HorizontalAlign="Center" />
|
292
|
+
|
293
|
+
</asp:ButtonField>
|
294
|
+
|
295
|
+
<asp:ButtonField ButtonType="Button" CommandName="_del" HeaderText="削除" ShowHeader="True"
|
296
|
+
|
297
|
+
Text="削除" >
|
298
|
+
|
299
|
+
<HeaderStyle Width="50px" />
|
300
|
+
|
301
|
+
<ItemStyle HorizontalAlign="Center" />
|
302
|
+
|
303
|
+
</asp:ButtonField>
|
304
|
+
|
305
|
+
</Columns>
|
306
|
+
|
307
|
+
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
|
308
|
+
|
309
|
+
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
|
310
|
+
|
311
|
+
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
|
312
|
+
|
313
|
+
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
|
314
|
+
|
315
|
+
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
|
316
|
+
|
317
|
+
<AlternatingRowStyle BackColor="#DCDCDC" />
|
318
|
+
|
319
|
+
<SortedAscendingCellStyle BackColor="#F1F1F1" />
|
320
|
+
|
321
|
+
<SortedAscendingHeaderStyle BackColor="#0000A9" />
|
322
|
+
|
323
|
+
<SortedDescendingCellStyle BackColor="#CAC9C9" />
|
324
|
+
|
325
|
+
<SortedDescendingHeaderStyle BackColor="#000065" />
|
326
|
+
|
327
|
+
</asp:GridView>
|
328
|
+
|
329
|
+
<asp:Label ID="Label_msg" runat="server"></asp:Label>
|
330
|
+
|
331
|
+
<asp:SqlDataSource ID="SqlDataSource_view_order" runat="server" ConnectionString="<%$ ConnectionStrings:eshopDBConnectionString %>"
|
332
|
+
|
333
|
+
SelectCommand="SELECT order_no, item_id, item_name, price_wt, quantity, total_price_wt FROM view_order_detail WHERE (order_no = @order_no)" InsertCommand="INSERT INTO [order] (order_no, customer_id, date, order_sts) VALUES (@order_no, @customer_id, @date, @order_sts)">
|
334
|
+
|
335
|
+
<InsertParameters>
|
336
|
+
|
337
|
+
<asp:Parameter Name="order_no" />
|
338
|
+
|
339
|
+
<asp:Parameter Name="customer_id" />
|
340
|
+
|
341
|
+
<asp:Parameter Name="date" />
|
342
|
+
|
343
|
+
<asp:Parameter Name="order_sts" />
|
344
|
+
|
345
|
+
</InsertParameters>
|
346
|
+
|
347
|
+
<SelectParameters>
|
348
|
+
|
349
|
+
<asp:SessionParameter Name="order_no" SessionField="order_no" Type="Int32" />
|
350
|
+
|
351
|
+
</SelectParameters>
|
352
|
+
|
353
|
+
</asp:SqlDataSource>
|
354
|
+
|
355
|
+
<asp:SqlDataSource ID="SqlDataSource_order_detail" runat="server" ConnectionString="<%$ ConnectionStrings:eshopDBConnectionString %>"
|
356
|
+
|
357
|
+
DeleteCommand="DELETE FROM order_detail WHERE (order_no = @order_no) AND (item_id = @item_id)"
|
358
|
+
|
359
|
+
SelectCommand="SELECT order_detail.* FROM order_detail" UpdateCommand="UPDATE order_detail SET quantity = @quantity WHERE (order_no = @order_no) AND (item_id = @item_id)" InsertCommand="INSERT INTO view_order_detail(order_no, item_id, item_name, price_wt) VALUES (@order_no, @item_id, @item_name, @price_wt)">
|
360
|
+
|
361
|
+
<DeleteParameters>
|
362
|
+
|
363
|
+
<asp:Parameter Name="order_no" />
|
364
|
+
|
365
|
+
<asp:Parameter Name="item_id" />
|
366
|
+
|
367
|
+
</DeleteParameters>
|
368
|
+
|
369
|
+
<InsertParameters>
|
370
|
+
|
371
|
+
<asp:Parameter Name="order_no" />
|
372
|
+
|
373
|
+
<asp:Parameter Name="item_id" />
|
374
|
+
|
375
|
+
<asp:Parameter Name="item_name" />
|
376
|
+
|
377
|
+
<asp:Parameter Name="price_wt" />
|
378
|
+
|
379
|
+
</InsertParameters>
|
380
|
+
|
381
|
+
<UpdateParameters>
|
382
|
+
|
383
|
+
<asp:Parameter Name="quantity" />
|
384
|
+
|
385
|
+
<asp:Parameter Name="order_no" />
|
386
|
+
|
387
|
+
<asp:Parameter Name="item_id" />
|
388
|
+
|
389
|
+
</UpdateParameters>
|
390
|
+
|
391
|
+
</asp:SqlDataSource>
|
392
|
+
|
393
|
+
</asp:Content>
|
394
|
+
|
41
395
|
注文テーブルvbコード1
|
42
396
|
|
43
397
|
http://s1.gazo.cc/up/173792.png
|