質問編集履歴
3
RecordManager.javaの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,10 +30,6 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
33
|
add.jsp
|
38
34
|
|
39
35
|
```ここに言語を入力
|
@@ -614,25 +610,33 @@
|
|
614
610
|
|
615
611
|
list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
|
616
612
|
|
617
|
-
|
613
|
+
|
618
|
-
|
619
|
-
|
614
|
+
|
620
|
-
|
621
|
-
list.add(new Item("B00301", "領収書", 350, 0, 0));
|
622
|
-
|
623
|
-
list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
|
624
|
-
|
625
|
-
list.add(new Item("C00201", "ステープラー", 338, 0, 0));
|
626
|
-
|
627
|
-
list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
|
628
|
-
|
629
|
-
list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
|
630
|
-
|
631
|
-
list.add(new Item("C00501", "消しゴム", 58, 0, 0));
|
632
|
-
|
633
|
-
}
|
615
|
+
}
|
616
|
+
|
617
|
+
|
618
|
+
|
634
|
-
|
619
|
+
/**
|
620
|
+
|
635
|
-
|
621
|
+
* 更新した商品データ
|
622
|
+
|
623
|
+
* 確認ボタンを押すとlistに書き込む。
|
624
|
+
|
625
|
+
*/
|
626
|
+
|
627
|
+
private static Item newItem;
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
/**
|
632
|
+
|
633
|
+
* 引数で指定された商品名に一致する商品データを返却
|
634
|
+
|
635
|
+
* @param name 検索キーとなる商品名
|
636
|
+
|
637
|
+
* @return 検索結果の商品データ
|
638
|
+
|
639
|
+
*/
|
636
640
|
|
637
641
|
public static Item findItem(String goodsName) {
|
638
642
|
|
@@ -692,28 +696,22 @@
|
|
692
696
|
|
693
697
|
|
694
698
|
|
699
|
+
public static void removeToAllList(Item newItem) {
|
700
|
+
|
701
|
+
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
702
|
+
|
703
|
+
allList.remove(item);
|
704
|
+
|
705
|
+
}
|
706
|
+
|
707
|
+
|
708
|
+
|
695
709
|
/**
|
696
710
|
|
697
|
-
*
|
711
|
+
* newItemを商品データlistに書き込む。
|
698
712
|
|
699
713
|
*/
|
700
714
|
|
701
|
-
public static void removeToAllList(Item newItem) {
|
702
|
-
|
703
|
-
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
704
|
-
|
705
|
-
allList.remove(item);
|
706
|
-
|
707
|
-
}
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
/**
|
712
|
-
|
713
|
-
* newItemを商品データlistに書き込む。
|
714
|
-
|
715
|
-
*/
|
716
|
-
|
717
715
|
public static void updateItem() {
|
718
716
|
|
719
717
|
list.set(list.indexOf(newItem), newItem);
|
@@ -738,6 +736,48 @@
|
|
738
736
|
|
739
737
|
|
740
738
|
|
739
|
+
public static Item getNewItem() {
|
740
|
+
|
741
|
+
return newItem;
|
742
|
+
|
743
|
+
}
|
744
|
+
|
745
|
+
public static String[] makeNameList() {
|
746
|
+
|
747
|
+
String[] nameList = new String[list.size()];
|
748
|
+
|
749
|
+
for (int i = 0; i < list.size(); i++) {
|
750
|
+
|
751
|
+
nameList[i] = (list.get(i)).getName();
|
752
|
+
|
753
|
+
}
|
754
|
+
|
755
|
+
return nameList;
|
756
|
+
|
757
|
+
}
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
public static Item selectItem(String name) {
|
762
|
+
|
763
|
+
|
764
|
+
|
765
|
+
for(Item item:list) {
|
766
|
+
|
767
|
+
if (item.getName().equals(name)) {
|
768
|
+
|
769
|
+
return item;
|
770
|
+
|
771
|
+
}
|
772
|
+
|
773
|
+
}
|
774
|
+
|
775
|
+
return null;
|
776
|
+
|
777
|
+
}
|
778
|
+
|
779
|
+
|
780
|
+
|
741
781
|
public static int calTotal(int subtotal) {
|
742
782
|
|
743
783
|
int total = 0;
|
@@ -750,9 +790,11 @@
|
|
750
790
|
|
751
791
|
return total;
|
752
792
|
|
753
|
-
//return 0;
|
754
|
-
|
755
|
-
}
|
793
|
+
}
|
794
|
+
|
795
|
+
}
|
796
|
+
|
797
|
+
|
756
798
|
|
757
799
|
```
|
758
800
|
|
2
誤字の修正、内容の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
}
|
28
28
|
|
29
|
-
|
29
|
+
```
|
30
30
|
|
31
31
|
|
32
32
|
|
@@ -36,7 +36,7 @@
|
|
36
36
|
|
37
37
|
add.jsp
|
38
38
|
|
39
|
-
```
|
39
|
+
```ここに言語を入力
|
40
40
|
|
41
41
|
<%@ page session="false" language="java"
|
42
42
|
|
@@ -152,10 +152,16 @@
|
|
152
152
|
|
153
153
|
</html>
|
154
154
|
|
155
|
+
|
156
|
+
|
155
157
|
```
|
156
158
|
|
157
159
|
|
158
160
|
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
159
165
|
SalesSystemController.java
|
160
166
|
|
161
167
|
```java
|
@@ -218,668 +224,682 @@
|
|
218
224
|
|
219
225
|
newItem.setSubtotal(sb);
|
220
226
|
|
221
|
-
|
227
|
+
RecordManager.addToAllList(newItem);
|
222
|
-
|
228
|
+
|
223
|
-
|
229
|
+
model.addAttribute("total", RecordManager.calTotal(sb));
|
224
|
-
|
230
|
+
|
225
|
-
|
231
|
+
model.addAttribute("nameList", RecordManager.makeNameList());
|
226
|
-
|
232
|
+
|
227
|
-
|
233
|
+
model.addAttribute("allList", RecordManager.getallList());
|
234
|
+
|
235
|
+
|
236
|
+
|
228
|
-
|
237
|
+
if (1 <= form.getQuantity() && form.getQuantity() <= 100) {
|
238
|
+
|
239
|
+
model.addAttribute("message2", ADDMSG);
|
240
|
+
|
229
|
-
|
241
|
+
return "add";
|
242
|
+
|
243
|
+
} else {
|
244
|
+
|
245
|
+
model.addAttribute("message", ERRMSG);
|
246
|
+
|
247
|
+
return "add";
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
/**
|
256
|
+
|
257
|
+
* 確認画面で登録を押した時に呼ばれる。データを登録して初期画面表示へ遷移する。
|
258
|
+
|
259
|
+
* @param form フォームオブジェクト
|
260
|
+
|
261
|
+
* @param model モデルオブジェクト
|
262
|
+
|
263
|
+
* @return initメソッドへのリンクを指定
|
264
|
+
|
265
|
+
*/
|
266
|
+
|
267
|
+
@RequestMapping(params = "toInit")
|
268
|
+
|
269
|
+
public String toInit(SalesForm form, Model model) {
|
270
|
+
|
271
|
+
//RecordManager.findItem(name);
|
272
|
+
|
273
|
+
return init(form, model);
|
230
274
|
|
231
275
|
}
|
232
276
|
|
277
|
+
}
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
```
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
SalesForm.java
|
288
|
+
|
289
|
+
```java
|
290
|
+
|
291
|
+
package jp.practice.sales;
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
import java.util.ArrayList;
|
296
|
+
|
297
|
+
import java.util.List;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
public class SalesForm {
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
/** 商品ID */
|
306
|
+
|
307
|
+
private String id;
|
308
|
+
|
309
|
+
/** 商品名 */
|
310
|
+
|
311
|
+
private String goodsName;
|
312
|
+
|
313
|
+
/** 単価 */
|
314
|
+
|
315
|
+
private int price;
|
316
|
+
|
317
|
+
/** 売上点数 */
|
318
|
+
|
319
|
+
private int quantity;
|
320
|
+
|
321
|
+
/** 小景 */
|
322
|
+
|
323
|
+
private int subtotal;
|
324
|
+
|
325
|
+
/** 商品点数 */
|
326
|
+
|
327
|
+
private int point;
|
328
|
+
|
329
|
+
/** 削除番号 */
|
330
|
+
|
331
|
+
private int delNumber;
|
332
|
+
|
333
|
+
/** 合計 */
|
334
|
+
|
335
|
+
private int total;
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
List<Item> allList = new ArrayList<>();
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
public SalesForm() {
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
|
355
|
+
* @return id
|
356
|
+
|
357
|
+
*/
|
358
|
+
|
359
|
+
public String getId() {
|
360
|
+
|
361
|
+
return id;
|
362
|
+
|
363
|
+
}
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
/**
|
368
|
+
|
369
|
+
* @param id セットする id
|
370
|
+
|
371
|
+
*/
|
372
|
+
|
373
|
+
public void setId(String id) {
|
374
|
+
|
375
|
+
this.id = id;
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
/**
|
380
|
+
|
381
|
+
* @return price
|
382
|
+
|
383
|
+
*/
|
384
|
+
|
385
|
+
public int getPrice() {
|
386
|
+
|
387
|
+
return price;
|
388
|
+
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
/**
|
394
|
+
|
395
|
+
* @param price セットする price
|
396
|
+
|
397
|
+
*/
|
398
|
+
|
399
|
+
public void setPrice(int price) {
|
400
|
+
|
401
|
+
this.price = price;
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
/**
|
408
|
+
|
409
|
+
* @return quantity
|
410
|
+
|
411
|
+
*/
|
412
|
+
|
413
|
+
public int getQuantity() {
|
414
|
+
|
415
|
+
return quantity;
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
/**
|
422
|
+
|
423
|
+
* @param quantity セットする quantity
|
424
|
+
|
425
|
+
*/
|
426
|
+
|
427
|
+
public void setQuantity(int quantity) {
|
428
|
+
|
429
|
+
this.quantity = quantity;
|
430
|
+
|
431
|
+
}
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
/**
|
436
|
+
|
437
|
+
* @return subtotal
|
438
|
+
|
439
|
+
*/
|
440
|
+
|
441
|
+
public int getSubtotal() {
|
442
|
+
|
443
|
+
return subtotal;
|
444
|
+
|
445
|
+
}
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
public void setSubtotal(int subtotal) {
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
this.subtotal = subtotal;
|
454
|
+
|
455
|
+
}
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
/**
|
460
|
+
|
461
|
+
* @return goodsName
|
462
|
+
|
463
|
+
*/
|
464
|
+
|
465
|
+
public String getGoodsName() {
|
466
|
+
|
467
|
+
return goodsName;
|
468
|
+
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
/**
|
474
|
+
|
475
|
+
* @param goodsName セットする goodsName
|
476
|
+
|
477
|
+
*/
|
478
|
+
|
479
|
+
public void setGoodsName(String goodsName) {
|
480
|
+
|
481
|
+
this.goodsName = goodsName;
|
482
|
+
|
483
|
+
}
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
/**
|
488
|
+
|
489
|
+
* @return point
|
490
|
+
|
491
|
+
*/
|
492
|
+
|
493
|
+
public int getPoint() {
|
494
|
+
|
495
|
+
return point;
|
496
|
+
|
497
|
+
}
|
498
|
+
|
499
|
+
|
500
|
+
|
501
|
+
/**
|
502
|
+
|
503
|
+
* @param point セットする point
|
504
|
+
|
505
|
+
*/
|
506
|
+
|
507
|
+
public void setPoint(int point) {
|
508
|
+
|
509
|
+
this.point = point;
|
510
|
+
|
511
|
+
}
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
public int getDelNumber() {
|
518
|
+
|
519
|
+
return delNumber;
|
520
|
+
|
521
|
+
}
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
public void setDelNumber(int delNumber) {
|
526
|
+
|
527
|
+
this.delNumber = delNumber;
|
528
|
+
|
529
|
+
}
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
public int getTotal() {
|
536
|
+
|
537
|
+
return total;
|
538
|
+
|
539
|
+
}
|
540
|
+
|
541
|
+
|
542
|
+
|
543
|
+
public void setTotal(int total) {
|
544
|
+
|
545
|
+
this.total = total;
|
546
|
+
|
547
|
+
}
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
/**
|
552
|
+
|
553
|
+
* @return allList
|
554
|
+
|
555
|
+
*/
|
556
|
+
|
557
|
+
public List<Item> getAllList() {
|
558
|
+
|
559
|
+
return allList;
|
560
|
+
|
561
|
+
}
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
}
|
566
|
+
|
567
|
+
```
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
RecordManager.java
|
572
|
+
|
573
|
+
```java
|
574
|
+
|
575
|
+
package jp.practice.sales;
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
import java.util.ArrayList;
|
580
|
+
|
581
|
+
import java.util.List;
|
582
|
+
|
583
|
+
|
584
|
+
|
585
|
+
/**
|
586
|
+
|
587
|
+
* 商品データ全体を保持するクラス
|
588
|
+
|
589
|
+
*/
|
590
|
+
|
591
|
+
public final class RecordManager {
|
592
|
+
|
593
|
+
|
594
|
+
|
595
|
+
/** 明細データ */
|
596
|
+
|
597
|
+
static List<Item> allList = new ArrayList<>();
|
598
|
+
|
599
|
+
|
600
|
+
|
601
|
+
/** 商品データ */
|
602
|
+
|
603
|
+
private static final List<Item> list = new ArrayList<Item>();
|
604
|
+
|
605
|
+
static {
|
606
|
+
|
607
|
+
list.add(new Item("A00101", "油性ボールペン", 60, 0, 0));
|
608
|
+
|
609
|
+
list.add(new Item("A00201", "極細ボールペン", 120, 0, 0));
|
610
|
+
|
611
|
+
list.add(new Item("A00301", "蛍光ペン6色セット", 420, 0, 0));
|
612
|
+
|
613
|
+
list.add(new Item("A00401", "シャープペンシル", 100, 0, 0));
|
614
|
+
|
615
|
+
list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
|
616
|
+
|
617
|
+
list.add(new Item("B00101", "無線綴ノートA4", 100, 0, 0));
|
618
|
+
|
619
|
+
list.add(new Item("B00201", "リングノートA4", 120, 0, 0));
|
620
|
+
|
621
|
+
list.add(new Item("B00301", "領収書", 350, 0, 0));
|
622
|
+
|
623
|
+
list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
|
624
|
+
|
625
|
+
list.add(new Item("C00201", "ステープラー", 338, 0, 0));
|
626
|
+
|
627
|
+
list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
|
628
|
+
|
629
|
+
list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
|
630
|
+
|
631
|
+
list.add(new Item("C00501", "消しゴム", 58, 0, 0));
|
632
|
+
|
633
|
+
}
|
634
|
+
|
635
|
+
|
636
|
+
|
637
|
+
public static Item findItem(String goodsName) {
|
638
|
+
|
639
|
+
int index = list.indexOf(new Item("", goodsName, 0,0,0));
|
640
|
+
|
641
|
+
return list.get(index);
|
642
|
+
|
643
|
+
}
|
644
|
+
|
233
645
|
|
234
646
|
|
235
647
|
/**
|
236
648
|
|
237
|
-
* 確認画面で登録を押した時に呼ばれる。データを登録して初期画面表示へ遷移する。
|
238
|
-
|
239
|
-
*
|
649
|
+
* 商品データを返す。
|
240
|
-
|
241
|
-
|
650
|
+
|
242
|
-
|
243
|
-
* @return
|
651
|
+
* @return 商品データ
|
244
652
|
|
245
653
|
*/
|
246
654
|
|
247
|
-
@RequestMapping(params = "toInit")
|
248
|
-
|
249
|
-
public
|
655
|
+
public static List<Item> getNameist() {
|
250
|
-
|
251
|
-
|
656
|
+
|
252
|
-
|
253
|
-
return i
|
657
|
+
return list;
|
254
658
|
|
255
659
|
}
|
256
660
|
|
661
|
+
|
662
|
+
|
663
|
+
/**
|
664
|
+
|
665
|
+
* 明細データを返す。
|
666
|
+
|
667
|
+
* @return 明細データ
|
668
|
+
|
669
|
+
*/
|
670
|
+
|
671
|
+
public static List<Item> getallList() {
|
672
|
+
|
673
|
+
return allList;
|
674
|
+
|
675
|
+
}
|
676
|
+
|
677
|
+
|
678
|
+
|
679
|
+
/**
|
680
|
+
|
681
|
+
* リストに商品情報を 1 件追加する
|
682
|
+
|
683
|
+
*/
|
684
|
+
|
685
|
+
public static void addToAllList(Item newItem) {
|
686
|
+
|
687
|
+
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
688
|
+
|
689
|
+
allList.add(item);
|
690
|
+
|
691
|
+
}
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
/**
|
696
|
+
|
697
|
+
* リストに商品情報を 1 件削除する
|
698
|
+
|
699
|
+
*/
|
700
|
+
|
701
|
+
public static void removeToAllList(Item newItem) {
|
702
|
+
|
703
|
+
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
704
|
+
|
705
|
+
allList.remove(item);
|
706
|
+
|
707
|
+
}
|
708
|
+
|
709
|
+
|
710
|
+
|
711
|
+
/**
|
712
|
+
|
713
|
+
* newItemを商品データlistに書き込む。
|
714
|
+
|
715
|
+
*/
|
716
|
+
|
717
|
+
public static void updateItem() {
|
718
|
+
|
719
|
+
list.set(list.indexOf(newItem), newItem);
|
720
|
+
|
721
|
+
}
|
722
|
+
|
723
|
+
|
724
|
+
|
725
|
+
/**
|
726
|
+
|
727
|
+
* newItemにデータを書き込む
|
728
|
+
|
729
|
+
* @param ni セットする item
|
730
|
+
|
731
|
+
*/
|
732
|
+
|
733
|
+
public static void setNewItem(Item ni) {
|
734
|
+
|
735
|
+
newItem = ni;
|
736
|
+
|
737
|
+
}
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
public static int calTotal(int subtotal) {
|
742
|
+
|
743
|
+
int total = 0;
|
744
|
+
|
745
|
+
for(Item item:list) {
|
746
|
+
|
747
|
+
total += item.getSubtotal();
|
748
|
+
|
749
|
+
}
|
750
|
+
|
751
|
+
return total;
|
752
|
+
|
753
|
+
//return 0;
|
754
|
+
|
755
|
+
}
|
756
|
+
|
757
|
+
```
|
758
|
+
|
759
|
+
|
760
|
+
|
761
|
+
Item.java
|
762
|
+
|
763
|
+
```java
|
764
|
+
|
765
|
+
package jp.practice.sales;
|
766
|
+
|
767
|
+
|
768
|
+
|
769
|
+
public class Item {
|
770
|
+
|
771
|
+
|
772
|
+
|
773
|
+
/** 商品ID */
|
774
|
+
|
775
|
+
private String id;
|
776
|
+
|
777
|
+
/** 商品名 */
|
778
|
+
|
779
|
+
private String name;
|
780
|
+
|
781
|
+
/** 単価 */
|
782
|
+
|
783
|
+
private int price;
|
784
|
+
|
785
|
+
/** 売上点数 */
|
786
|
+
|
787
|
+
private int quantity;
|
788
|
+
|
789
|
+
/** 小景 */
|
790
|
+
|
791
|
+
private int subtotal;
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
public Item(String id, String name, int price, int quantity, int subtotal) {
|
796
|
+
|
797
|
+
this.id = id;
|
798
|
+
|
799
|
+
this.name = name;
|
800
|
+
|
801
|
+
this.price = price;
|
802
|
+
|
803
|
+
this.quantity = quantity;
|
804
|
+
|
805
|
+
this.subtotal = subtotal;
|
806
|
+
|
807
|
+
}
|
808
|
+
|
809
|
+
|
810
|
+
|
811
|
+
public String getId() {
|
812
|
+
|
813
|
+
return id;
|
814
|
+
|
815
|
+
}
|
816
|
+
|
817
|
+
|
818
|
+
|
819
|
+
public void setId(String id) {
|
820
|
+
|
821
|
+
this.id = id;
|
822
|
+
|
823
|
+
}
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
public String getName() {
|
828
|
+
|
829
|
+
return name;
|
830
|
+
|
831
|
+
}
|
832
|
+
|
833
|
+
|
834
|
+
|
835
|
+
public void setName(String name) {
|
836
|
+
|
837
|
+
this.name = name;
|
838
|
+
|
839
|
+
}
|
840
|
+
|
841
|
+
|
842
|
+
|
843
|
+
public int getPrice() {
|
844
|
+
|
845
|
+
return price;
|
846
|
+
|
847
|
+
}
|
848
|
+
|
849
|
+
|
850
|
+
|
851
|
+
public void setPrice(int price) {
|
852
|
+
|
853
|
+
this.price = price;
|
854
|
+
|
855
|
+
}
|
856
|
+
|
857
|
+
|
858
|
+
|
859
|
+
public int getQuantity() {
|
860
|
+
|
861
|
+
return quantity;
|
862
|
+
|
863
|
+
}
|
864
|
+
|
865
|
+
|
866
|
+
|
867
|
+
public void setQuantity(int quantity) {
|
868
|
+
|
869
|
+
this.quantity = quantity;
|
870
|
+
|
871
|
+
}
|
872
|
+
|
873
|
+
|
874
|
+
|
875
|
+
public int getSubtotal() {
|
876
|
+
|
877
|
+
return subtotal;
|
878
|
+
|
879
|
+
}
|
880
|
+
|
881
|
+
|
882
|
+
|
883
|
+
/**
|
884
|
+
|
885
|
+
* @param subtotal セットする subtotal
|
886
|
+
|
887
|
+
*/
|
888
|
+
|
889
|
+
public void setSubtotal(int subtotal) {
|
890
|
+
|
891
|
+
this.subtotal = subtotal;
|
892
|
+
|
893
|
+
}
|
894
|
+
|
895
|
+
|
896
|
+
|
897
|
+
|
898
|
+
|
899
|
+
|
900
|
+
|
901
|
+
|
902
|
+
|
257
903
|
}
|
258
904
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
905
|
```
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
SalesForm.java
|
268
|
-
|
269
|
-
```java
|
270
|
-
|
271
|
-
package jp.practice.sales;
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
import java.util.ArrayList;
|
276
|
-
|
277
|
-
import java.util.List;
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
public class SalesForm {
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
/** 商品ID */
|
286
|
-
|
287
|
-
private String id;
|
288
|
-
|
289
|
-
/** 商品名 */
|
290
|
-
|
291
|
-
private String goodsName;
|
292
|
-
|
293
|
-
/** 単価 */
|
294
|
-
|
295
|
-
private int price;
|
296
|
-
|
297
|
-
/** 売上点数 */
|
298
|
-
|
299
|
-
private int quantity;
|
300
|
-
|
301
|
-
/** 小景 */
|
302
|
-
|
303
|
-
private int subtotal;
|
304
|
-
|
305
|
-
/** 商品点数 */
|
306
|
-
|
307
|
-
private int point;
|
308
|
-
|
309
|
-
/** 削除番号 */
|
310
|
-
|
311
|
-
private int delNumber;
|
312
|
-
|
313
|
-
/** 合計 */
|
314
|
-
|
315
|
-
private int total;
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
List<Item> allList = new ArrayList<>();
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
public SalesForm() {
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
/**
|
334
|
-
|
335
|
-
* @return id
|
336
|
-
|
337
|
-
*/
|
338
|
-
|
339
|
-
public String getId() {
|
340
|
-
|
341
|
-
return id;
|
342
|
-
|
343
|
-
}
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
/**
|
348
|
-
|
349
|
-
* @param id セットする id
|
350
|
-
|
351
|
-
*/
|
352
|
-
|
353
|
-
public void setId(String id) {
|
354
|
-
|
355
|
-
this.id = id;
|
356
|
-
|
357
|
-
}
|
358
|
-
|
359
|
-
/**
|
360
|
-
|
361
|
-
* @return price
|
362
|
-
|
363
|
-
*/
|
364
|
-
|
365
|
-
public int getPrice() {
|
366
|
-
|
367
|
-
return price;
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
/**
|
374
|
-
|
375
|
-
* @param price セットする price
|
376
|
-
|
377
|
-
*/
|
378
|
-
|
379
|
-
public void setPrice(int price) {
|
380
|
-
|
381
|
-
this.price = price;
|
382
|
-
|
383
|
-
}
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
/**
|
388
|
-
|
389
|
-
* @return quantity
|
390
|
-
|
391
|
-
*/
|
392
|
-
|
393
|
-
public int getQuantity() {
|
394
|
-
|
395
|
-
return quantity;
|
396
|
-
|
397
|
-
}
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
/**
|
402
|
-
|
403
|
-
* @param quantity セットする quantity
|
404
|
-
|
405
|
-
*/
|
406
|
-
|
407
|
-
public void setQuantity(int quantity) {
|
408
|
-
|
409
|
-
this.quantity = quantity;
|
410
|
-
|
411
|
-
}
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
/**
|
416
|
-
|
417
|
-
* @return subtotal
|
418
|
-
|
419
|
-
*/
|
420
|
-
|
421
|
-
public int getSubtotal() {
|
422
|
-
|
423
|
-
return subtotal;
|
424
|
-
|
425
|
-
}
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
public void setSubtotal(int subtotal) {
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
this.subtotal = subtotal;
|
434
|
-
|
435
|
-
}
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
/**
|
440
|
-
|
441
|
-
* @return goodsName
|
442
|
-
|
443
|
-
*/
|
444
|
-
|
445
|
-
public String getGoodsName() {
|
446
|
-
|
447
|
-
return goodsName;
|
448
|
-
|
449
|
-
}
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
/**
|
454
|
-
|
455
|
-
* @param goodsName セットする goodsName
|
456
|
-
|
457
|
-
*/
|
458
|
-
|
459
|
-
public void setGoodsName(String goodsName) {
|
460
|
-
|
461
|
-
this.goodsName = goodsName;
|
462
|
-
|
463
|
-
}
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
/**
|
468
|
-
|
469
|
-
* @return point
|
470
|
-
|
471
|
-
*/
|
472
|
-
|
473
|
-
public int getPoint() {
|
474
|
-
|
475
|
-
return point;
|
476
|
-
|
477
|
-
}
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
/**
|
482
|
-
|
483
|
-
* @param point セットする point
|
484
|
-
|
485
|
-
*/
|
486
|
-
|
487
|
-
public void setPoint(int point) {
|
488
|
-
|
489
|
-
this.point = point;
|
490
|
-
|
491
|
-
}
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
public int getDelNumber() {
|
498
|
-
|
499
|
-
return delNumber;
|
500
|
-
|
501
|
-
}
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
public void setDelNumber(int delNumber) {
|
506
|
-
|
507
|
-
this.delNumber = delNumber;
|
508
|
-
|
509
|
-
}
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
public int getTotal() {
|
516
|
-
|
517
|
-
return total;
|
518
|
-
|
519
|
-
}
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
public void setTotal(int total) {
|
524
|
-
|
525
|
-
this.total = total;
|
526
|
-
|
527
|
-
}
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
/**
|
532
|
-
|
533
|
-
* @return allList
|
534
|
-
|
535
|
-
*/
|
536
|
-
|
537
|
-
public List<Item> getAllList() {
|
538
|
-
|
539
|
-
return allList;
|
540
|
-
|
541
|
-
}
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
}
|
546
|
-
|
547
|
-
```
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
RecordManager.java
|
552
|
-
|
553
|
-
```java
|
554
|
-
|
555
|
-
package jp.practice.sales;
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
import java.util.ArrayList;
|
560
|
-
|
561
|
-
import java.util.List;
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
/**
|
566
|
-
|
567
|
-
* 商品データ全体を保持するクラス
|
568
|
-
|
569
|
-
*/
|
570
|
-
|
571
|
-
public final class RecordManager {
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
/** 明細データ */
|
576
|
-
|
577
|
-
static List<Item> allList = new ArrayList<>();
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
/** 商品データ */
|
582
|
-
|
583
|
-
private static final List<Item> list = new ArrayList<Item>();
|
584
|
-
|
585
|
-
static {
|
586
|
-
|
587
|
-
list.add(new Item("A00101", "油性ボールペン", 60, 0, 0));
|
588
|
-
|
589
|
-
list.add(new Item("A00201", "極細ボールペン", 120, 0, 0));
|
590
|
-
|
591
|
-
list.add(new Item("A00301", "蛍光ペン6色セット", 420, 0, 0));
|
592
|
-
|
593
|
-
list.add(new Item("A00401", "シャープペンシル", 100, 0, 0));
|
594
|
-
|
595
|
-
list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
|
596
|
-
|
597
|
-
list.add(new Item("B00101", "無線綴ノートA4", 100, 0, 0));
|
598
|
-
|
599
|
-
list.add(new Item("B00201", "リングノートA4", 120, 0, 0));
|
600
|
-
|
601
|
-
list.add(new Item("B00301", "領収書", 350, 0, 0));
|
602
|
-
|
603
|
-
list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
|
604
|
-
|
605
|
-
list.add(new Item("C00201", "ステープラー", 338, 0, 0));
|
606
|
-
|
607
|
-
list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
|
608
|
-
|
609
|
-
list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
|
610
|
-
|
611
|
-
list.add(new Item("C00501", "消しゴム", 58, 0, 0));
|
612
|
-
|
613
|
-
}
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
public static Item findItem(String goodsName) {
|
618
|
-
|
619
|
-
int index = list.indexOf(new Item("", goodsName, 0,0,0));
|
620
|
-
|
621
|
-
return list.get(index);
|
622
|
-
|
623
|
-
}
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
/**
|
628
|
-
|
629
|
-
* 商品データを返す。
|
630
|
-
|
631
|
-
* @return 商品データ
|
632
|
-
|
633
|
-
*/
|
634
|
-
|
635
|
-
public static List<Item> getNameist() {
|
636
|
-
|
637
|
-
return list;
|
638
|
-
|
639
|
-
}
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
/**
|
644
|
-
|
645
|
-
* 明細データを返す。
|
646
|
-
|
647
|
-
* @return 明細データ
|
648
|
-
|
649
|
-
*/
|
650
|
-
|
651
|
-
public static List<Item> getallList() {
|
652
|
-
|
653
|
-
return allList;
|
654
|
-
|
655
|
-
}
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
/**
|
660
|
-
|
661
|
-
* リストに商品情報を 1 件追加する
|
662
|
-
|
663
|
-
*/
|
664
|
-
|
665
|
-
public static void addToAllList(Item newItem) {
|
666
|
-
|
667
|
-
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
668
|
-
|
669
|
-
allList.add(item);
|
670
|
-
|
671
|
-
}
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
/**
|
676
|
-
|
677
|
-
* リストに商品情報を 1 件削除する
|
678
|
-
|
679
|
-
*/
|
680
|
-
|
681
|
-
public static void removeToAllList(Item newItem) {
|
682
|
-
|
683
|
-
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
684
|
-
|
685
|
-
allList.remove(item);
|
686
|
-
|
687
|
-
}
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
/**
|
692
|
-
|
693
|
-
* newItemを商品データlistに書き込む。
|
694
|
-
|
695
|
-
*/
|
696
|
-
|
697
|
-
public static void updateItem() {
|
698
|
-
|
699
|
-
list.set(list.indexOf(newItem), newItem);
|
700
|
-
|
701
|
-
}
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
/**
|
706
|
-
|
707
|
-
* newItemにデータを書き込む
|
708
|
-
|
709
|
-
* @param ni セットする item
|
710
|
-
|
711
|
-
*/
|
712
|
-
|
713
|
-
public static void setNewItem(Item ni) {
|
714
|
-
|
715
|
-
newItem = ni;
|
716
|
-
|
717
|
-
}
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
public static int calTotal(int subtotal) {
|
722
|
-
|
723
|
-
int total = 0;
|
724
|
-
|
725
|
-
for(Item item:list) {
|
726
|
-
|
727
|
-
total += item.getSubtotal();
|
728
|
-
|
729
|
-
}
|
730
|
-
|
731
|
-
return total;
|
732
|
-
|
733
|
-
//return 0;
|
734
|
-
|
735
|
-
}
|
736
|
-
|
737
|
-
```
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
Item.java
|
742
|
-
|
743
|
-
```java
|
744
|
-
|
745
|
-
package jp.practice.sales;
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
public class Item {
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
/** 商品ID */
|
754
|
-
|
755
|
-
private String id;
|
756
|
-
|
757
|
-
/** 商品名 */
|
758
|
-
|
759
|
-
private String name;
|
760
|
-
|
761
|
-
/** 単価 */
|
762
|
-
|
763
|
-
private int price;
|
764
|
-
|
765
|
-
/** 売上点数 */
|
766
|
-
|
767
|
-
private int quantity;
|
768
|
-
|
769
|
-
/** 小景 */
|
770
|
-
|
771
|
-
private int subtotal;
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
public Item(String id, String name, int price, int quantity, int subtotal) {
|
776
|
-
|
777
|
-
this.id = id;
|
778
|
-
|
779
|
-
this.name = name;
|
780
|
-
|
781
|
-
this.price = price;
|
782
|
-
|
783
|
-
this.quantity = quantity;
|
784
|
-
|
785
|
-
this.subtotal = subtotal;
|
786
|
-
|
787
|
-
}
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
public String getId() {
|
792
|
-
|
793
|
-
return id;
|
794
|
-
|
795
|
-
}
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
public void setId(String id) {
|
800
|
-
|
801
|
-
this.id = id;
|
802
|
-
|
803
|
-
}
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
public String getName() {
|
808
|
-
|
809
|
-
return name;
|
810
|
-
|
811
|
-
}
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
public void setName(String name) {
|
816
|
-
|
817
|
-
this.name = name;
|
818
|
-
|
819
|
-
}
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
public int getPrice() {
|
824
|
-
|
825
|
-
return price;
|
826
|
-
|
827
|
-
}
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
public void setPrice(int price) {
|
832
|
-
|
833
|
-
this.price = price;
|
834
|
-
|
835
|
-
}
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
public int getQuantity() {
|
840
|
-
|
841
|
-
return quantity;
|
842
|
-
|
843
|
-
}
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
public void setQuantity(int quantity) {
|
848
|
-
|
849
|
-
this.quantity = quantity;
|
850
|
-
|
851
|
-
}
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
public int getSubtotal() {
|
856
|
-
|
857
|
-
return subtotal;
|
858
|
-
|
859
|
-
}
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
/**
|
864
|
-
|
865
|
-
* @param subtotal セットする subtotal
|
866
|
-
|
867
|
-
*/
|
868
|
-
|
869
|
-
public void setSubtotal(int subtotal) {
|
870
|
-
|
871
|
-
this.subtotal = subtotal;
|
872
|
-
|
873
|
-
}
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
}
|
884
|
-
|
885
|
-
```
|
1
calTotalメソッドの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,147 +18,253 @@
|
|
18
18
|
|
19
19
|
total += item.getSubtotal();
|
20
20
|
|
21
|
-
return total;
|
22
|
-
|
23
21
|
}
|
24
22
|
|
25
|
-
return
|
23
|
+
return total;
|
24
|
+
|
26
|
-
|
25
|
+
//return 0;
|
26
|
+
|
27
|
-
}
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
add.jsp
|
38
|
+
|
39
|
+
```jsp
|
40
|
+
|
41
|
+
<%@ page session="false" language="java"
|
42
|
+
|
43
|
+
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
|
44
|
+
|
45
|
+
<%@ page import="java.time.LocalDate"%>
|
46
|
+
|
47
|
+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
48
|
+
|
49
|
+
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
|
50
|
+
|
51
|
+
<!DOCTYPE html>
|
52
|
+
|
53
|
+
<html>
|
54
|
+
|
55
|
+
<head>
|
56
|
+
|
57
|
+
<link rel="stylesheet" type="text/css"
|
58
|
+
|
59
|
+
href="/sales/resources/css/common.css" />
|
60
|
+
|
61
|
+
<title>売上システム(初期画面)</title>
|
62
|
+
|
63
|
+
</head>
|
64
|
+
|
65
|
+
<body>
|
66
|
+
|
67
|
+
<form:form modelAttribute="salesForm" action="/sales/system" var="list">
|
68
|
+
|
69
|
+
<div class="header">
|
70
|
+
|
71
|
+
<span class="titleName">オンラインショップ</span>
|
72
|
+
|
73
|
+
<div class="date"><%=LocalDate.now()%></div>
|
74
|
+
|
75
|
+
</div>
|
76
|
+
|
77
|
+
<div class="main"></div>
|
78
|
+
|
79
|
+
<div>明細追加画面</div>
|
80
|
+
|
81
|
+
商品:
|
82
|
+
|
83
|
+
<form:select path="goodsName" items="${nameList}" />
|
84
|
+
|
85
|
+
<div>
|
86
|
+
|
87
|
+
点数:
|
88
|
+
|
89
|
+
<form:input path="quantity" items="${allList}"/>
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
<div>
|
94
|
+
|
95
|
+
<input type="submit" name="add" value="明細追加" />
|
96
|
+
|
97
|
+
</div>
|
98
|
+
|
99
|
+
<table>
|
100
|
+
|
101
|
+
<tr>
|
102
|
+
|
103
|
+
<th>削除</th>
|
104
|
+
|
105
|
+
<th>商品ID</th>
|
106
|
+
|
107
|
+
<th>商品名</th>
|
108
|
+
|
109
|
+
<th>単価</th>
|
110
|
+
|
111
|
+
<th>点数</th>
|
112
|
+
|
113
|
+
<th>小計</th>
|
114
|
+
|
115
|
+
</tr>
|
116
|
+
|
117
|
+
<c:forEach items="${allList}" var="item" varStatus="status">
|
118
|
+
|
119
|
+
<tr class="even">
|
120
|
+
|
121
|
+
<form:hidden path="quantity" />
|
122
|
+
|
123
|
+
<td><input type="radio" name="remove"/></td>
|
124
|
+
|
125
|
+
<td><c:out value="${item.id}" /></td>
|
126
|
+
|
127
|
+
<td><c:out value="${item.name}" /></td>
|
128
|
+
|
129
|
+
<td><c:out value="${item.price}" /></td>
|
130
|
+
|
131
|
+
<td><c:out value="${item.quantity}" /></td>
|
132
|
+
|
133
|
+
<td><c:out value="${item.subtotal}" /></td>
|
134
|
+
|
135
|
+
</tr>
|
136
|
+
|
137
|
+
</c:forEach>
|
138
|
+
|
139
|
+
</table>
|
140
|
+
|
141
|
+
合計:
|
142
|
+
|
143
|
+
<c:out value="${salesForm.total}" />
|
144
|
+
|
145
|
+
<input type="submit" name="firm" value="確定" />
|
146
|
+
|
147
|
+
<input type="submit" name="remove" value="削除" />
|
148
|
+
|
149
|
+
</form:form>
|
150
|
+
|
151
|
+
</body>
|
152
|
+
|
153
|
+
</html>
|
28
154
|
|
29
155
|
```
|
30
156
|
|
31
157
|
|
32
158
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
</tr>
|
138
|
-
|
139
|
-
</c:forEach>
|
140
|
-
|
141
|
-
</table>
|
142
|
-
|
143
|
-
合計:
|
144
|
-
|
145
|
-
<c:out value="${salesForm.total}" />
|
146
|
-
|
147
|
-
<input type="submit" name="firm" value="確定" />
|
148
|
-
|
149
|
-
<input type="submit" name="remove" value="削除" />
|
150
|
-
|
151
|
-
</form:form>
|
152
|
-
|
153
|
-
</body>
|
154
|
-
|
155
|
-
</html>
|
159
|
+
SalesSystemController.java
|
160
|
+
|
161
|
+
```java
|
162
|
+
|
163
|
+
package jp.practice.sales;
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
import org.springframework.stereotype.Controller;
|
168
|
+
|
169
|
+
import org.springframework.ui.Model;
|
170
|
+
|
171
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
172
|
+
|
173
|
+
import org.springframework.web.bind.annotation.SessionAttributes;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
/**
|
178
|
+
|
179
|
+
* Handles requests for the application home page.
|
180
|
+
|
181
|
+
*/
|
182
|
+
|
183
|
+
@Controller
|
184
|
+
|
185
|
+
@RequestMapping(value = "/system")
|
186
|
+
|
187
|
+
@SessionAttributes
|
188
|
+
|
189
|
+
public class SalesSystemController {
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
/**
|
196
|
+
|
197
|
+
* 初期画面から呼ばれる。選択した商品の明細追加画面を表示する。
|
198
|
+
|
199
|
+
* @param form フォームオブジェクト
|
200
|
+
|
201
|
+
* @param model モデルオブジェクト
|
202
|
+
|
203
|
+
* @return Viewとしてadd.jspを指定
|
204
|
+
|
205
|
+
*/
|
206
|
+
|
207
|
+
@RequestMapping(params = "add")
|
208
|
+
|
209
|
+
public String add(SalesForm form, Model model) {
|
210
|
+
|
211
|
+
Item item = RecordManager.findItem(form.getGoodsName());
|
212
|
+
|
213
|
+
RecordManager.setNewItem(new Item(item.getId(), form.getGoodsName(), item.getPrice(), form.getQuantity(), item.getSubtotal()));
|
214
|
+
|
215
|
+
Item newItem = RecordManager.getNewItem();
|
216
|
+
|
217
|
+
int sb = newItem.getPrice() * newItem.getQuantity();
|
218
|
+
|
219
|
+
newItem.setSubtotal(sb);
|
220
|
+
|
221
|
+
RecordManager.addToAllList(newItem);
|
222
|
+
|
223
|
+
RecordManager.calTotal(newItem.getSubtotal());
|
224
|
+
|
225
|
+
model.addAttribute("nameList", RecordManager.makeNameList());
|
226
|
+
|
227
|
+
model.addAttribute("allList", RecordManager.getallList());
|
228
|
+
|
229
|
+
return "add";
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
/**
|
236
|
+
|
237
|
+
* 確認画面で登録を押した時に呼ばれる。データを登録して初期画面表示へ遷移する。
|
238
|
+
|
239
|
+
* @param form フォームオブジェクト
|
240
|
+
|
241
|
+
* @param model モデルオブジェクト
|
242
|
+
|
243
|
+
* @return initメソッドへのリンクを指定
|
244
|
+
|
245
|
+
*/
|
246
|
+
|
247
|
+
@RequestMapping(params = "toInit")
|
248
|
+
|
249
|
+
public String toInit(SalesForm form, Model model) {
|
250
|
+
|
251
|
+
//RecordManager.findItem(name);
|
252
|
+
|
253
|
+
return init(form, model);
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
156
262
|
|
157
263
|
```
|
158
264
|
|
159
265
|
|
160
266
|
|
161
|
-
Sales
|
267
|
+
SalesForm.java
|
162
268
|
|
163
269
|
```java
|
164
270
|
|
@@ -166,69 +272,369 @@
|
|
166
272
|
|
167
273
|
|
168
274
|
|
169
|
-
import org.springframework.stereotype.Controller;
|
170
|
-
|
171
|
-
import
|
275
|
+
import java.util.ArrayList;
|
276
|
+
|
172
|
-
|
277
|
+
import java.util.List;
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
public class SalesForm {
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
/** 商品ID */
|
286
|
+
|
287
|
+
private String id;
|
288
|
+
|
289
|
+
/** 商品名 */
|
290
|
+
|
291
|
+
private String goodsName;
|
292
|
+
|
293
|
+
/** 単価 */
|
294
|
+
|
295
|
+
private int price;
|
296
|
+
|
297
|
+
/** 売上点数 */
|
298
|
+
|
299
|
+
private int quantity;
|
300
|
+
|
301
|
+
/** 小景 */
|
302
|
+
|
303
|
+
private int subtotal;
|
304
|
+
|
305
|
+
/** 商品点数 */
|
306
|
+
|
307
|
+
private int point;
|
308
|
+
|
309
|
+
/** 削除番号 */
|
310
|
+
|
311
|
+
private int delNumber;
|
312
|
+
|
313
|
+
/** 合計 */
|
314
|
+
|
315
|
+
private int total;
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
List<Item> allList = new ArrayList<>();
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
public SalesForm() {
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
/**
|
334
|
+
|
335
|
+
* @return id
|
336
|
+
|
337
|
+
*/
|
338
|
+
|
339
|
+
public String getId() {
|
340
|
+
|
341
|
+
return id;
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
/**
|
348
|
+
|
349
|
+
* @param id セットする id
|
350
|
+
|
351
|
+
*/
|
352
|
+
|
353
|
+
public void setId(String id) {
|
354
|
+
|
355
|
+
this.id = id;
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
/**
|
360
|
+
|
361
|
+
* @return price
|
362
|
+
|
363
|
+
*/
|
364
|
+
|
365
|
+
public int getPrice() {
|
366
|
+
|
367
|
+
return price;
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
/**
|
374
|
+
|
375
|
+
* @param price セットする price
|
376
|
+
|
377
|
+
*/
|
378
|
+
|
379
|
+
public void setPrice(int price) {
|
380
|
+
|
381
|
+
this.price = price;
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
/**
|
388
|
+
|
389
|
+
* @return quantity
|
390
|
+
|
391
|
+
*/
|
392
|
+
|
393
|
+
public int getQuantity() {
|
394
|
+
|
395
|
+
return quantity;
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
/**
|
402
|
+
|
403
|
+
* @param quantity セットする quantity
|
404
|
+
|
405
|
+
*/
|
406
|
+
|
407
|
+
public void setQuantity(int quantity) {
|
408
|
+
|
409
|
+
this.quantity = quantity;
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
/**
|
416
|
+
|
417
|
+
* @return subtotal
|
418
|
+
|
419
|
+
*/
|
420
|
+
|
421
|
+
public int getSubtotal() {
|
422
|
+
|
423
|
+
return subtotal;
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
public void setSubtotal(int subtotal) {
|
430
|
+
|
431
|
+
|
432
|
+
|
433
|
+
this.subtotal = subtotal;
|
434
|
+
|
435
|
+
}
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
/**
|
440
|
+
|
441
|
+
* @return goodsName
|
442
|
+
|
443
|
+
*/
|
444
|
+
|
445
|
+
public String getGoodsName() {
|
446
|
+
|
447
|
+
return goodsName;
|
448
|
+
|
449
|
+
}
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
/**
|
454
|
+
|
455
|
+
* @param goodsName セットする goodsName
|
456
|
+
|
457
|
+
*/
|
458
|
+
|
173
|
-
i
|
459
|
+
public void setGoodsName(String goodsName) {
|
460
|
+
|
174
|
-
|
461
|
+
this.goodsName = goodsName;
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
/**
|
468
|
+
|
469
|
+
* @return point
|
470
|
+
|
471
|
+
*/
|
472
|
+
|
473
|
+
public int getPoint() {
|
474
|
+
|
475
|
+
return point;
|
476
|
+
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
/**
|
482
|
+
|
483
|
+
* @param point セットする point
|
484
|
+
|
485
|
+
*/
|
486
|
+
|
487
|
+
public void setPoint(int point) {
|
488
|
+
|
489
|
+
this.point = point;
|
490
|
+
|
491
|
+
}
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
public int getDelNumber() {
|
498
|
+
|
499
|
+
return delNumber;
|
500
|
+
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
|
175
|
-
i
|
505
|
+
public void setDelNumber(int delNumber) {
|
506
|
+
|
507
|
+
this.delNumber = delNumber;
|
508
|
+
|
509
|
+
}
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
public int getTotal() {
|
516
|
+
|
517
|
+
return total;
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
public void setTotal(int total) {
|
524
|
+
|
525
|
+
this.total = total;
|
526
|
+
|
527
|
+
}
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
/**
|
532
|
+
|
533
|
+
* @return allList
|
534
|
+
|
535
|
+
*/
|
536
|
+
|
537
|
+
public List<Item> getAllList() {
|
538
|
+
|
539
|
+
return allList;
|
540
|
+
|
541
|
+
}
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
}
|
546
|
+
|
547
|
+
```
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
RecordManager.java
|
552
|
+
|
553
|
+
```java
|
554
|
+
|
555
|
+
package jp.practice.sales;
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
import java.util.ArrayList;
|
560
|
+
|
561
|
+
import java.util.List;
|
176
562
|
|
177
563
|
|
178
564
|
|
179
565
|
/**
|
180
566
|
|
181
|
-
*
|
567
|
+
* 商品データ全体を保持するクラス
|
182
568
|
|
183
569
|
*/
|
184
570
|
|
185
|
-
@Controller
|
186
|
-
|
187
|
-
@RequestMapping(value = "/system")
|
188
|
-
|
189
|
-
@SessionAttributes
|
190
|
-
|
191
|
-
public class
|
571
|
+
public final class RecordManager {
|
572
|
+
|
573
|
+
|
574
|
+
|
192
|
-
|
575
|
+
/** 明細データ */
|
576
|
+
|
193
|
-
|
577
|
+
static List<Item> allList = new ArrayList<>();
|
578
|
+
|
579
|
+
|
580
|
+
|
581
|
+
/** 商品データ */
|
582
|
+
|
583
|
+
private static final List<Item> list = new ArrayList<Item>();
|
584
|
+
|
585
|
+
static {
|
586
|
+
|
587
|
+
list.add(new Item("A00101", "油性ボールペン", 60, 0, 0));
|
588
|
+
|
589
|
+
list.add(new Item("A00201", "極細ボールペン", 120, 0, 0));
|
590
|
+
|
591
|
+
list.add(new Item("A00301", "蛍光ペン6色セット", 420, 0, 0));
|
592
|
+
|
593
|
+
list.add(new Item("A00401", "シャープペンシル", 100, 0, 0));
|
594
|
+
|
595
|
+
list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
|
596
|
+
|
597
|
+
list.add(new Item("B00101", "無線綴ノートA4", 100, 0, 0));
|
598
|
+
|
599
|
+
list.add(new Item("B00201", "リングノートA4", 120, 0, 0));
|
600
|
+
|
601
|
+
list.add(new Item("B00301", "領収書", 350, 0, 0));
|
602
|
+
|
603
|
+
list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
|
604
|
+
|
605
|
+
list.add(new Item("C00201", "ステープラー", 338, 0, 0));
|
606
|
+
|
607
|
+
list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
|
608
|
+
|
609
|
+
list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
|
610
|
+
|
611
|
+
list.add(new Item("C00501", "消しゴム", 58, 0, 0));
|
612
|
+
|
613
|
+
}
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
public static Item findItem(String goodsName) {
|
618
|
+
|
619
|
+
int index = list.indexOf(new Item("", goodsName, 0,0,0));
|
620
|
+
|
621
|
+
return list.get(index);
|
622
|
+
|
623
|
+
}
|
194
624
|
|
195
625
|
|
196
626
|
|
197
627
|
/**
|
198
628
|
|
199
|
-
*
|
629
|
+
* 商品データを返す。
|
200
|
-
|
201
|
-
|
630
|
+
|
202
|
-
|
203
|
-
* @param model モデルオブジェクト
|
204
|
-
|
205
|
-
* @return
|
631
|
+
* @return 商品データ
|
206
632
|
|
207
633
|
*/
|
208
634
|
|
209
|
-
@RequestMapping(params = "add")
|
210
|
-
|
211
|
-
public
|
635
|
+
public static List<Item> getNameist() {
|
212
|
-
|
213
|
-
|
636
|
+
|
214
|
-
|
215
|
-
RecordManager.setNewItem(new Item(item.getId(), form.getGoodsName(), item.getPrice(), form.getQuantity(), item.getSubtotal()));
|
216
|
-
|
217
|
-
Item newItem = RecordManager.getNewItem();
|
218
|
-
|
219
|
-
int sb = newItem.getPrice() * newItem.getQuantity();
|
220
|
-
|
221
|
-
newItem.setSubtotal(sb);
|
222
|
-
|
223
|
-
RecordManager.addToAllList(newItem);
|
224
|
-
|
225
|
-
RecordManager.calTotal(newItem.getSubtotal());
|
226
|
-
|
227
|
-
model.addAttribute("nameList", RecordManager.makeNameList());
|
228
|
-
|
229
|
-
model.addAttribute("allList", RecordManager.getallList());
|
230
|
-
|
231
|
-
return
|
637
|
+
return list;
|
232
638
|
|
233
639
|
}
|
234
640
|
|
@@ -236,652 +642,244 @@
|
|
236
642
|
|
237
643
|
/**
|
238
644
|
|
239
|
-
* 確認画面で登録を押した時に呼ばれる。データを登録して初期画面表示へ遷移する。
|
240
|
-
|
241
|
-
*
|
645
|
+
* 明細データを返す。
|
242
|
-
|
243
|
-
|
646
|
+
|
244
|
-
|
245
|
-
* @return
|
647
|
+
* @return 明細データ
|
246
648
|
|
247
649
|
*/
|
248
650
|
|
249
|
-
@RequestMapping(params = "toInit")
|
250
|
-
|
251
|
-
public
|
651
|
+
public static List<Item> getallList() {
|
252
|
-
|
253
|
-
|
652
|
+
|
254
|
-
|
255
|
-
return i
|
653
|
+
return allList;
|
256
|
-
|
654
|
+
|
257
|
-
}
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
|
659
|
+
/**
|
660
|
+
|
661
|
+
* リストに商品情報を 1 件追加する
|
662
|
+
|
663
|
+
*/
|
664
|
+
|
665
|
+
public static void addToAllList(Item newItem) {
|
666
|
+
|
667
|
+
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
668
|
+
|
669
|
+
allList.add(item);
|
670
|
+
|
671
|
+
}
|
672
|
+
|
673
|
+
|
674
|
+
|
675
|
+
/**
|
676
|
+
|
677
|
+
* リストに商品情報を 1 件削除する
|
678
|
+
|
679
|
+
*/
|
680
|
+
|
681
|
+
public static void removeToAllList(Item newItem) {
|
682
|
+
|
683
|
+
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
684
|
+
|
685
|
+
allList.remove(item);
|
686
|
+
|
687
|
+
}
|
688
|
+
|
689
|
+
|
690
|
+
|
691
|
+
/**
|
692
|
+
|
693
|
+
* newItemを商品データlistに書き込む。
|
694
|
+
|
695
|
+
*/
|
696
|
+
|
697
|
+
public static void updateItem() {
|
698
|
+
|
699
|
+
list.set(list.indexOf(newItem), newItem);
|
700
|
+
|
701
|
+
}
|
702
|
+
|
703
|
+
|
704
|
+
|
705
|
+
/**
|
706
|
+
|
707
|
+
* newItemにデータを書き込む
|
708
|
+
|
709
|
+
* @param ni セットする item
|
710
|
+
|
711
|
+
*/
|
712
|
+
|
713
|
+
public static void setNewItem(Item ni) {
|
714
|
+
|
715
|
+
newItem = ni;
|
716
|
+
|
717
|
+
}
|
718
|
+
|
719
|
+
|
720
|
+
|
721
|
+
public static int calTotal(int subtotal) {
|
722
|
+
|
723
|
+
int total = 0;
|
724
|
+
|
725
|
+
for(Item item:list) {
|
726
|
+
|
727
|
+
total += item.getSubtotal();
|
728
|
+
|
729
|
+
}
|
730
|
+
|
731
|
+
return total;
|
732
|
+
|
733
|
+
//return 0;
|
734
|
+
|
735
|
+
}
|
736
|
+
|
737
|
+
```
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
Item.java
|
742
|
+
|
743
|
+
```java
|
744
|
+
|
745
|
+
package jp.practice.sales;
|
746
|
+
|
747
|
+
|
748
|
+
|
749
|
+
public class Item {
|
750
|
+
|
751
|
+
|
752
|
+
|
753
|
+
/** 商品ID */
|
754
|
+
|
755
|
+
private String id;
|
756
|
+
|
757
|
+
/** 商品名 */
|
758
|
+
|
759
|
+
private String name;
|
760
|
+
|
761
|
+
/** 単価 */
|
762
|
+
|
763
|
+
private int price;
|
764
|
+
|
765
|
+
/** 売上点数 */
|
766
|
+
|
767
|
+
private int quantity;
|
768
|
+
|
769
|
+
/** 小景 */
|
770
|
+
|
771
|
+
private int subtotal;
|
772
|
+
|
773
|
+
|
774
|
+
|
775
|
+
public Item(String id, String name, int price, int quantity, int subtotal) {
|
776
|
+
|
777
|
+
this.id = id;
|
778
|
+
|
779
|
+
this.name = name;
|
780
|
+
|
781
|
+
this.price = price;
|
782
|
+
|
783
|
+
this.quantity = quantity;
|
784
|
+
|
785
|
+
this.subtotal = subtotal;
|
786
|
+
|
787
|
+
}
|
788
|
+
|
789
|
+
|
790
|
+
|
791
|
+
public String getId() {
|
792
|
+
|
793
|
+
return id;
|
794
|
+
|
795
|
+
}
|
796
|
+
|
797
|
+
|
798
|
+
|
799
|
+
public void setId(String id) {
|
800
|
+
|
801
|
+
this.id = id;
|
802
|
+
|
803
|
+
}
|
804
|
+
|
805
|
+
|
806
|
+
|
807
|
+
public String getName() {
|
808
|
+
|
809
|
+
return name;
|
810
|
+
|
811
|
+
}
|
812
|
+
|
813
|
+
|
814
|
+
|
815
|
+
public void setName(String name) {
|
816
|
+
|
817
|
+
this.name = name;
|
818
|
+
|
819
|
+
}
|
820
|
+
|
821
|
+
|
822
|
+
|
823
|
+
public int getPrice() {
|
824
|
+
|
825
|
+
return price;
|
826
|
+
|
827
|
+
}
|
828
|
+
|
829
|
+
|
830
|
+
|
831
|
+
public void setPrice(int price) {
|
832
|
+
|
833
|
+
this.price = price;
|
834
|
+
|
835
|
+
}
|
836
|
+
|
837
|
+
|
838
|
+
|
839
|
+
public int getQuantity() {
|
840
|
+
|
841
|
+
return quantity;
|
842
|
+
|
843
|
+
}
|
844
|
+
|
845
|
+
|
846
|
+
|
847
|
+
public void setQuantity(int quantity) {
|
848
|
+
|
849
|
+
this.quantity = quantity;
|
850
|
+
|
851
|
+
}
|
852
|
+
|
853
|
+
|
854
|
+
|
855
|
+
public int getSubtotal() {
|
856
|
+
|
857
|
+
return subtotal;
|
858
|
+
|
859
|
+
}
|
860
|
+
|
861
|
+
|
862
|
+
|
863
|
+
/**
|
864
|
+
|
865
|
+
* @param subtotal セットする subtotal
|
866
|
+
|
867
|
+
*/
|
868
|
+
|
869
|
+
public void setSubtotal(int subtotal) {
|
870
|
+
|
871
|
+
this.subtotal = subtotal;
|
872
|
+
|
873
|
+
}
|
874
|
+
|
875
|
+
|
876
|
+
|
877
|
+
|
878
|
+
|
879
|
+
|
880
|
+
|
881
|
+
|
258
882
|
|
259
883
|
}
|
260
884
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
885
|
```
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
SalesForm.java
|
270
|
-
|
271
|
-
```java
|
272
|
-
|
273
|
-
package jp.practice.sales;
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
import java.util.ArrayList;
|
278
|
-
|
279
|
-
import java.util.List;
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
public class SalesForm {
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
/** 商品ID */
|
288
|
-
|
289
|
-
private String id;
|
290
|
-
|
291
|
-
/** 商品名 */
|
292
|
-
|
293
|
-
private String goodsName;
|
294
|
-
|
295
|
-
/** 単価 */
|
296
|
-
|
297
|
-
private int price;
|
298
|
-
|
299
|
-
/** 売上点数 */
|
300
|
-
|
301
|
-
private int quantity;
|
302
|
-
|
303
|
-
/** 小景 */
|
304
|
-
|
305
|
-
private int subtotal;
|
306
|
-
|
307
|
-
/** 商品点数 */
|
308
|
-
|
309
|
-
private int point;
|
310
|
-
|
311
|
-
/** 削除番号 */
|
312
|
-
|
313
|
-
private int delNumber;
|
314
|
-
|
315
|
-
/** 合計 */
|
316
|
-
|
317
|
-
private int total;
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
List<Item> allList = new ArrayList<>();
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
public SalesForm() {
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
|
-
/**
|
336
|
-
|
337
|
-
* @return id
|
338
|
-
|
339
|
-
*/
|
340
|
-
|
341
|
-
public String getId() {
|
342
|
-
|
343
|
-
return id;
|
344
|
-
|
345
|
-
}
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
/**
|
350
|
-
|
351
|
-
* @param id セットする id
|
352
|
-
|
353
|
-
*/
|
354
|
-
|
355
|
-
public void setId(String id) {
|
356
|
-
|
357
|
-
this.id = id;
|
358
|
-
|
359
|
-
}
|
360
|
-
|
361
|
-
/**
|
362
|
-
|
363
|
-
* @return price
|
364
|
-
|
365
|
-
*/
|
366
|
-
|
367
|
-
public int getPrice() {
|
368
|
-
|
369
|
-
return price;
|
370
|
-
|
371
|
-
}
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
/**
|
376
|
-
|
377
|
-
* @param price セットする price
|
378
|
-
|
379
|
-
*/
|
380
|
-
|
381
|
-
public void setPrice(int price) {
|
382
|
-
|
383
|
-
this.price = price;
|
384
|
-
|
385
|
-
}
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
/**
|
390
|
-
|
391
|
-
* @return quantity
|
392
|
-
|
393
|
-
*/
|
394
|
-
|
395
|
-
public int getQuantity() {
|
396
|
-
|
397
|
-
return quantity;
|
398
|
-
|
399
|
-
}
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
/**
|
404
|
-
|
405
|
-
* @param quantity セットする quantity
|
406
|
-
|
407
|
-
*/
|
408
|
-
|
409
|
-
public void setQuantity(int quantity) {
|
410
|
-
|
411
|
-
this.quantity = quantity;
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
/**
|
418
|
-
|
419
|
-
* @return subtotal
|
420
|
-
|
421
|
-
*/
|
422
|
-
|
423
|
-
public int getSubtotal() {
|
424
|
-
|
425
|
-
return subtotal;
|
426
|
-
|
427
|
-
}
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
public void setSubtotal(int subtotal) {
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
this.subtotal = subtotal;
|
436
|
-
|
437
|
-
}
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
/**
|
442
|
-
|
443
|
-
* @return goodsName
|
444
|
-
|
445
|
-
*/
|
446
|
-
|
447
|
-
public String getGoodsName() {
|
448
|
-
|
449
|
-
return goodsName;
|
450
|
-
|
451
|
-
}
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
/**
|
456
|
-
|
457
|
-
* @param goodsName セットする goodsName
|
458
|
-
|
459
|
-
*/
|
460
|
-
|
461
|
-
public void setGoodsName(String goodsName) {
|
462
|
-
|
463
|
-
this.goodsName = goodsName;
|
464
|
-
|
465
|
-
}
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
/**
|
470
|
-
|
471
|
-
* @return point
|
472
|
-
|
473
|
-
*/
|
474
|
-
|
475
|
-
public int getPoint() {
|
476
|
-
|
477
|
-
return point;
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
/**
|
484
|
-
|
485
|
-
* @param point セットする point
|
486
|
-
|
487
|
-
*/
|
488
|
-
|
489
|
-
public void setPoint(int point) {
|
490
|
-
|
491
|
-
this.point = point;
|
492
|
-
|
493
|
-
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
public int getDelNumber() {
|
500
|
-
|
501
|
-
return delNumber;
|
502
|
-
|
503
|
-
}
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
public void setDelNumber(int delNumber) {
|
508
|
-
|
509
|
-
this.delNumber = delNumber;
|
510
|
-
|
511
|
-
}
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
public int getTotal() {
|
518
|
-
|
519
|
-
return total;
|
520
|
-
|
521
|
-
}
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
public void setTotal(int total) {
|
526
|
-
|
527
|
-
this.total = total;
|
528
|
-
|
529
|
-
}
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
/**
|
534
|
-
|
535
|
-
* @return allList
|
536
|
-
|
537
|
-
*/
|
538
|
-
|
539
|
-
public List<Item> getAllList() {
|
540
|
-
|
541
|
-
return allList;
|
542
|
-
|
543
|
-
}
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
}
|
548
|
-
|
549
|
-
```
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
RecordManager.java
|
554
|
-
|
555
|
-
```java
|
556
|
-
|
557
|
-
package jp.practice.sales;
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
import java.util.ArrayList;
|
562
|
-
|
563
|
-
import java.util.List;
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
/**
|
568
|
-
|
569
|
-
* 商品データ全体を保持するクラス
|
570
|
-
|
571
|
-
*/
|
572
|
-
|
573
|
-
public final class RecordManager {
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
/** 明細データ */
|
578
|
-
|
579
|
-
static List<Item> allList = new ArrayList<>();
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
/** 商品データ */
|
584
|
-
|
585
|
-
private static final List<Item> list = new ArrayList<Item>();
|
586
|
-
|
587
|
-
static {
|
588
|
-
|
589
|
-
list.add(new Item("A00101", "油性ボールペン", 60, 0, 0));
|
590
|
-
|
591
|
-
list.add(new Item("A00201", "極細ボールペン", 120, 0, 0));
|
592
|
-
|
593
|
-
list.add(new Item("A00301", "蛍光ペン6色セット", 420, 0, 0));
|
594
|
-
|
595
|
-
list.add(new Item("A00401", "シャープペンシル", 100, 0, 0));
|
596
|
-
|
597
|
-
list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
|
598
|
-
|
599
|
-
list.add(new Item("B00101", "無線綴ノートA4", 100, 0, 0));
|
600
|
-
|
601
|
-
list.add(new Item("B00201", "リングノートA4", 120, 0, 0));
|
602
|
-
|
603
|
-
list.add(new Item("B00301", "領収書", 350, 0, 0));
|
604
|
-
|
605
|
-
list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
|
606
|
-
|
607
|
-
list.add(new Item("C00201", "ステープラー", 338, 0, 0));
|
608
|
-
|
609
|
-
list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
|
610
|
-
|
611
|
-
list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
|
612
|
-
|
613
|
-
list.add(new Item("C00501", "消しゴム", 58, 0, 0));
|
614
|
-
|
615
|
-
}
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
public static Item findItem(String goodsName) {
|
620
|
-
|
621
|
-
int index = list.indexOf(new Item("", goodsName, 0,0,0));
|
622
|
-
|
623
|
-
return list.get(index);
|
624
|
-
|
625
|
-
}
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
/**
|
630
|
-
|
631
|
-
* 商品データを返す。
|
632
|
-
|
633
|
-
* @return 商品データ
|
634
|
-
|
635
|
-
*/
|
636
|
-
|
637
|
-
public static List<Item> getNameist() {
|
638
|
-
|
639
|
-
return list;
|
640
|
-
|
641
|
-
}
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
/**
|
646
|
-
|
647
|
-
* 明細データを返す。
|
648
|
-
|
649
|
-
* @return 明細データ
|
650
|
-
|
651
|
-
*/
|
652
|
-
|
653
|
-
public static List<Item> getallList() {
|
654
|
-
|
655
|
-
return allList;
|
656
|
-
|
657
|
-
}
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
/**
|
662
|
-
|
663
|
-
* リストに商品情報を 1 件追加する
|
664
|
-
|
665
|
-
*/
|
666
|
-
|
667
|
-
public static void addToAllList(Item newItem) {
|
668
|
-
|
669
|
-
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
670
|
-
|
671
|
-
allList.add(item);
|
672
|
-
|
673
|
-
}
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
/**
|
678
|
-
|
679
|
-
* リストに商品情報を 1 件削除する
|
680
|
-
|
681
|
-
*/
|
682
|
-
|
683
|
-
public static void removeToAllList(Item newItem) {
|
684
|
-
|
685
|
-
Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
|
686
|
-
|
687
|
-
allList.remove(item);
|
688
|
-
|
689
|
-
}
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
/**
|
694
|
-
|
695
|
-
* newItemを商品データlistに書き込む。
|
696
|
-
|
697
|
-
*/
|
698
|
-
|
699
|
-
public static void updateItem() {
|
700
|
-
|
701
|
-
list.set(list.indexOf(newItem), newItem);
|
702
|
-
|
703
|
-
}
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
/**
|
708
|
-
|
709
|
-
* newItemにデータを書き込む
|
710
|
-
|
711
|
-
* @param ni セットする item
|
712
|
-
|
713
|
-
*/
|
714
|
-
|
715
|
-
public static void setNewItem(Item ni) {
|
716
|
-
|
717
|
-
newItem = ni;
|
718
|
-
|
719
|
-
}
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
public static int calTotal(int subtotal) {
|
724
|
-
|
725
|
-
int total = 0;
|
726
|
-
|
727
|
-
for(Item item:list) {
|
728
|
-
|
729
|
-
total += item.getSubtotal();
|
730
|
-
|
731
|
-
return total;
|
732
|
-
|
733
|
-
}
|
734
|
-
|
735
|
-
return 0;
|
736
|
-
|
737
|
-
}
|
738
|
-
|
739
|
-
```
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
Item.java
|
744
|
-
|
745
|
-
```java
|
746
|
-
|
747
|
-
package jp.practice.sales;
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
public class Item {
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
/** 商品ID */
|
756
|
-
|
757
|
-
private String id;
|
758
|
-
|
759
|
-
/** 商品名 */
|
760
|
-
|
761
|
-
private String name;
|
762
|
-
|
763
|
-
/** 単価 */
|
764
|
-
|
765
|
-
private int price;
|
766
|
-
|
767
|
-
/** 売上点数 */
|
768
|
-
|
769
|
-
private int quantity;
|
770
|
-
|
771
|
-
/** 小景 */
|
772
|
-
|
773
|
-
private int subtotal;
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
public Item(String id, String name, int price, int quantity, int subtotal) {
|
778
|
-
|
779
|
-
this.id = id;
|
780
|
-
|
781
|
-
this.name = name;
|
782
|
-
|
783
|
-
this.price = price;
|
784
|
-
|
785
|
-
this.quantity = quantity;
|
786
|
-
|
787
|
-
this.subtotal = subtotal;
|
788
|
-
|
789
|
-
}
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
public String getId() {
|
794
|
-
|
795
|
-
return id;
|
796
|
-
|
797
|
-
}
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
public void setId(String id) {
|
802
|
-
|
803
|
-
this.id = id;
|
804
|
-
|
805
|
-
}
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
public String getName() {
|
810
|
-
|
811
|
-
return name;
|
812
|
-
|
813
|
-
}
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
public void setName(String name) {
|
818
|
-
|
819
|
-
this.name = name;
|
820
|
-
|
821
|
-
}
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
public int getPrice() {
|
826
|
-
|
827
|
-
return price;
|
828
|
-
|
829
|
-
}
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
public void setPrice(int price) {
|
834
|
-
|
835
|
-
this.price = price;
|
836
|
-
|
837
|
-
}
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
public int getQuantity() {
|
842
|
-
|
843
|
-
return quantity;
|
844
|
-
|
845
|
-
}
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
public void setQuantity(int quantity) {
|
850
|
-
|
851
|
-
this.quantity = quantity;
|
852
|
-
|
853
|
-
}
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
public int getSubtotal() {
|
858
|
-
|
859
|
-
return subtotal;
|
860
|
-
|
861
|
-
}
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
/**
|
866
|
-
|
867
|
-
* @param subtotal セットする subtotal
|
868
|
-
|
869
|
-
*/
|
870
|
-
|
871
|
-
public void setSubtotal(int subtotal) {
|
872
|
-
|
873
|
-
this.subtotal = subtotal;
|
874
|
-
|
875
|
-
}
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
}
|
886
|
-
|
887
|
-
```
|