/webccr/src/com/emis/caesarui/webccr/ui/table/PromotionTable.java

https://bitbucket.org/sanliou/synccr · Java · 187 lines · 154 code · 22 blank · 11 comment · 21 complexity · 6c7b0f61e62dcf6945b47c3585088931 MD5 · raw file

  1. package com.emis.caesarui.webccr.ui.table;
  2. import com.emis.caesar.emisLog;
  3. import com.emis.caesar.senao.unit.sale.TSaleItem;
  4. import com.emis.caesar.senao.util.CcrUtil;
  5. import com.emis.caesarui.webccr.core.PromotionInfoList;
  6. import com.emis.caesarui.webccr.core.promote.MG;
  7. import com.emis.caesarui.webccr.core.promote.MM;
  8. import com.emis.caesarui.webccr.core.promote.PMBase;
  9. import com.emis.caesarui.webccr.webccr;
  10. import com.emis.util.emisUtil;
  11. import com.vaadin.data.Property;
  12. import com.vaadin.event.ItemClickEvent;
  13. import com.vaadin.shared.MouseEventDetails;
  14. import com.vaadin.ui.*;
  15. import java.util.ArrayList;
  16. import java.util.HashMap;
  17. /**
  18. * 促銷選單
  19. */
  20. public class PromotionTable extends BaseTable {
  21. PromoTableD1 promoTableD1 = null;
  22. PromoTableD2 promoTableD2 = null;
  23. ArrayList<TSaleItem> SaleItemPool = new ArrayList();
  24. private TextField tRemark;
  25. private TextField tPno;
  26. private Label SP_COMMENT;
  27. public static final int INDEX_CHK_1 = 0;
  28. public static final int INDEX_CHK_2 = 1;
  29. public static final int INDEX_SHM_CNT = 2;
  30. public static final int INDEX_MM_NO = 3;
  31. public static final int INDEX_MM_AMT = 4;
  32. public static final int INDEX_MM_NAME = 5;
  33. public static final int INDEX_TIME = 6;
  34. public static final String COLUMN_CHK_1 = "累點";
  35. public static final String COLUMN_CHK_2 = "分期";
  36. public static final String COLUMN_SHM_CNT = "適用二手機";
  37. public static final String COLUMN_MM_NO = "活動單號";
  38. public static final String COLUMN_MM_AMT = "促銷總金額";
  39. public static final String COLUMN_MM_NAME = "活動說明";
  40. public static final String COLUMN_TIME = "活動時間";
  41. /**
  42. * 列頭
  43. */
  44. public static final String[] sColumns = new String[] { COLUMN_CHK_1, COLUMN_CHK_2,
  45. COLUMN_SHM_CNT, COLUMN_MM_NO,
  46. COLUMN_MM_AMT, COLUMN_MM_NAME,
  47. COLUMN_TIME};
  48. public static final Class[] oClss = new Class[] { CheckBox.class, CheckBox.class,
  49. String.class, String.class,
  50. Integer.class, String.class,
  51. String.class, String.class};
  52. public PromotionTable() {
  53. super(sColumns,oClss);
  54. // 設定表格中表頭的字居中
  55. for (int i = 0; i < sColumns.length; i++) {
  56. this.setColumnAlignment(sColumns[i], Align.CENTER);
  57. }
  58. // 設定表格寬度
  59. this.setColumnWidth(COLUMN_CHK_1, 60);
  60. this.setColumnWidth(COLUMN_CHK_2, 60);
  61. this.setColumnWidth(COLUMN_SHM_CNT, 110);
  62. this.setColumnWidth(COLUMN_TIME, 110);
  63. this.setNullSelectionAllowed(false); // 選後 不能不選
  64. // 監控選取的促銷單
  65. this.addValueChangeListener(new ValueChangeListener() {
  66. @Override
  67. public void valueChange(Property.ValueChangeEvent event) {
  68. PMBase pmb = (PMBase) event.getProperty().getValue();
  69. try {
  70. if (promoTableD1 != null && promoTableD2 != null) {
  71. promoTableD1.removeAllItems();
  72. promoTableD2.removeAllItems();
  73. if (pmb != null) {
  74. promoTableD1.query(pmb, SaleItemPool);
  75. promoTableD2.query(pmb, SaleItemPool);
  76. SP_COMMENT.setValue(((MM) pmb).getGEN_SP_COMMENT());
  77. tPno.focus();
  78. }
  79. }
  80. } catch (Exception e) {
  81. // ((webccr) UI.getCurrent()).getlog().error(webccr.class, e);
  82. CcrUtil.setMessage(emisUtil.getStackTrace(e));
  83. }
  84. }
  85. });
  86. }
  87. public Object query(PromotionInfoList pmList) {
  88. Object _oItem = null;
  89. int _iCnt =0;
  90. removeAllItems();
  91. try {
  92. this.setPageLength(999);
  93. for (int i = 0; i < pmList.size(); i++) {
  94. PMBase pmb = (PMBase) pmList.get(i);
  95. Object[] _oRow = null; // 欄位
  96. if (pmb instanceof MM) {
  97. _iCnt++;
  98. MM mm = (MM) pmb;
  99. CheckBox _oChkBox_1 = new CheckBox("");
  100. _oChkBox_1.setData(mm.getM_ADD_POINT());
  101. _oChkBox_1.setEnabled(false);
  102. if ("Y".equals(mm.getM_ADD_POINT())) {
  103. _oChkBox_1.setValue(true);
  104. } else {
  105. _oChkBox_1.setValue(false);
  106. }
  107. CheckBox _oChkBox_2 = new CheckBox("");
  108. _oChkBox_2.setData(mm.getINSP_NO());
  109. _oChkBox_2.setEnabled(false);
  110. if (("".equals(emisUtil.parseString(mm.getINSP_NO())))) {
  111. _oChkBox_2.setValue(false);
  112. } else {
  113. _oChkBox_2.setValue(true);
  114. }
  115. String SHM_CNT = "不限";
  116. if ("1".equals(mm.getSHM_CNT())) {
  117. SHM_CNT = "一次";
  118. } else if ("2".equals(mm.getSHM_CNT())) {
  119. SHM_CNT = "多次";
  120. }
  121. int PM_TOTAL = emisUtil.parseInt(mm.getPM_TOTAL());
  122. int iPM_TOTAL = CcrUtil.getStorePrice(
  123. ((webccr) UI.getCurrent()).getFoCCR().getStore().getFLDxS_TAX(), "1", "", PM_TOTAL);
  124. _oRow = new Object[sColumns.length];
  125. _oRow[INDEX_CHK_1] = _oChkBox_1;
  126. _oRow[INDEX_CHK_2] = _oChkBox_2;
  127. _oRow[INDEX_SHM_CNT] = SHM_CNT;
  128. _oRow[INDEX_MM_NO] = mm.getPM_NO();
  129. _oRow[INDEX_MM_AMT] = iPM_TOTAL; // W_MM_H.PM_TOTAL
  130. _oRow[INDEX_MM_NAME] = mm.getName();
  131. _oRow[INDEX_TIME] = mm.getTIME_S() + "-" + mm.getTIME_E();
  132. }
  133. if (_oRow != null) {
  134. if (_iCnt == 1) {
  135. _oItem = addItem(_oRow, pmb);
  136. } else {
  137. addItem(_oRow, pmb);
  138. }
  139. }
  140. }
  141. } catch (Exception e) {
  142. // ((webccr) UI.getCurrent()).getlog().error(webccr.class, e);
  143. CcrUtil.setMessage(emisUtil.getStackTrace(e));
  144. }
  145. return _oItem;
  146. }
  147. public void setPromoTabD1(PromoTableD1 promoTableD1_) {
  148. promoTableD1 = promoTableD1_;
  149. }
  150. public void setPromoTabD2(PromoTableD2 promoTableD2_) {
  151. this.promoTableD2 = promoTableD2_;
  152. }
  153. public void setTSaleItemPoll(ArrayList<TSaleItem> saleItemPool) {
  154. this.SaleItemPool = saleItemPool;
  155. }
  156. public void settRemark(TextField tRemark) {
  157. this.tRemark = tRemark;
  158. }
  159. public void settPno(TextField tPno) {
  160. this.tPno = tPno;
  161. }
  162. public void setSP_COMMENT(Label SP_COMMENT) {
  163. this.SP_COMMENT = SP_COMMENT;
  164. }
  165. }