PageRenderTime 44ms CodeModel.GetById 16ms app.highlight 22ms RepoModel.GetById 2ms app.codeStats 0ms

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