package com.topsun.posclient.sales.ui.table; import java.math.BigDecimal; import org.eclipse.jface.viewers.ICellModifier; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.swt.widgets.TableItem; import com.topsun.posclient.common.ProjectUtil; import com.topsun.posclient.common.ui.utils.FormatUtils; import com.topsun.posclient.datamodel.OldGold; import com.topsun.posclient.sales.ui.gold.OldGoldIndentifyFacade; /** * 旧金鉴定表格编辑处理 * * @author Dong * */ public class OldGoldIdentifyCellModify implements ICellModifier { public TableViewer tableViewer; public OldGoldIdentifyCellModify(TableViewer tableViewer){ this.tableViewer = tableViewer; } public boolean canModify(Object element, String property) { if ("name".equals(property) || "Neatness".equals(property) || "Weight_G".equals(property) || "Loss".equals(property) || "Service".equals(property) ) { return true; } return false; } public Object getValue(Object element, String property) { if(element instanceof OldGold){ OldGold og = (OldGold)element; if("mtart".equals(property)){//物料编码 return String.valueOf(og.getMtartCode()); } if("name".equals(property)){//旧金名称 if(og.getName() == null){ return ""; } return og.getName(); } if("num".equals(property)){//件数 return "1"; } if("Neatness".equals(property)){//成色 return ProjectUtil.formatNetnessAmount(null, og.getNeatness()); } if("Weight_G".equals(property)){//称重 return ProjectUtil.formatNetnessAmount(null, og.getWeight_G()); } if("Weight".equals(property)){//纯金重 return ProjectUtil.formatNetnessAmount(null, og.getWeight()); } if("Loss".equals(property)){//耗损比 return og.getT_Loss(); } if("Weight_R".equals(property)){//耗损重 return ProjectUtil.formatAmount(null, og.getWeight_R()); } if("Weight_F".equals(property)){//折金重 return ProjectUtil.formatAmount(null, og.getWeight_F()); } if("Price_G".equals(property)){//单价 return ProjectUtil.formatAmount(null, og.getPrice_G()).toString(); } if("Service".equals(property)){//服务费 return og.getT_ServiceFee(); // ProjectUtil.formatAmount(null, og.getService()).toString(); } if("Sum".equals(property)){//抵扣金额 BigDecimal sum = og.getSum().setScale(2, BigDecimal.ROUND_HALF_UP); return ProjectUtil.formatAmount(null, sum); } } return ""; } public void modify(Object element, String property, Object value) { if(element instanceof TableItem){ TableItem titem = (TableItem)element; OldGold og = (OldGold)titem.getData(); if("mtart".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ og.setMtartCode(value.toString()); } tableViewer.update(og, null); } if("name".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ og.setName(value.toString()); } tableViewer.update(og, null); } if("num".equals(property)){ tableViewer.update(og, null); } if("Neatness".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ boolean flag = FormatUtils.checkNeatnessFormat(tableViewer.getTable(), value.toString(),"【成色】格式不正确"); if(!flag){ return; } og.setNeatness(new BigDecimal(value.toString())); } BigDecimal weightValue = og.getWeight_G().multiply(og.getNeatness()); og.setWeight(weightValue.setScale(3, BigDecimal.ROUND_HALF_UP)); BigDecimal weight_F = og.getWeight().multiply(new BigDecimal(1).subtract(og.getLoss())); og.setWeight_F(weight_F.setScale(3, BigDecimal.ROUND_HALF_UP)); og.setWeight_R(og.getWeight().subtract(og.getWeight_F())); int t_ServiceFee = og.getT_ServiceFee(); BigDecimal serviceFeeBigDecimal = new BigDecimal(0); if(0 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(6)); } if(1 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(10)); } if(2 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(12)); } if(3 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(0)); } og.setService(serviceFeeBigDecimal); BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); } if("Weight_G".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ boolean flag = FormatUtils.oldGoldcheckWeightG(tableViewer.getTable(), value.toString(), "【称重】格式错误"); if(!flag){ return; } og.setWeight_G(new BigDecimal(value.toString())); } BigDecimal weightValue = og.getWeight_G().multiply(og.getNeatness()); og.setWeight(weightValue.setScale(3, BigDecimal.ROUND_HALF_UP)); BigDecimal weight_F = og.getWeight().multiply(new BigDecimal(1).subtract(og.getLoss())); og.setWeight_F(weight_F.setScale(3, BigDecimal.ROUND_HALF_UP)); og.setWeight_R(og.getWeight().subtract(og.getWeight_F())); int t_ServiceFee = og.getT_ServiceFee(); BigDecimal serviceFeeBigDecimal = new BigDecimal(0); if(0 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(6)); } if(1 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(10)); } if(2 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(12)); } if(3 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(0)); } og.setService(serviceFeeBigDecimal); BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); } if("Loss".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ if(0 == (Integer)value){ og.setT_Loss(0); og.setLoss(new BigDecimal(0.01)); }else if(1 == (Integer)value){ og.setT_Loss(1); og.setLoss(new BigDecimal(0.12)); }else if(2 == (Integer)value){ og.setT_Loss(2); og.setLoss(new BigDecimal(0.15)); }else{ og.setT_Loss(3); og.setLoss(new BigDecimal(0.00)); } } BigDecimal weightValue = og.getWeight_G().multiply(og.getNeatness()); og.setWeight(weightValue.setScale(3, BigDecimal.ROUND_HALF_UP)); BigDecimal weight_F = og.getWeight().multiply(new BigDecimal(1).subtract(og.getLoss())); og.setWeight_F(weight_F.setScale(3, BigDecimal.ROUND_HALF_UP)); og.setWeight_R(og.getWeight().subtract(og.getWeight_F())); int t_ServiceFee = og.getT_ServiceFee(); BigDecimal serviceFeeBigDecimal = new BigDecimal(0); if(0 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(6)); } if(1 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(10)); } if(2 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(12)); } if(3 == t_ServiceFee){ serviceFeeBigDecimal = og.getWeight_G().multiply(new BigDecimal(0)); } og.setService(serviceFeeBigDecimal); BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); tableViewer.update(og, null); } if("Weight_F".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ og.setWeight_F(new BigDecimal(value.toString())); } tableViewer.update(og, null); } if("Weight_R".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ og.setWeight_R(new BigDecimal(value.toString())); } tableViewer.update(og, null); } if("Weight".equals(property)){ if("".equals(value.toString().trim())){ og.setWeight(new BigDecimal(0.000)); }else{ og.setWeight(new BigDecimal(value.toString())); } BigDecimal weight_F = og.getWeight().multiply(new BigDecimal(1).subtract(og.getLoss())); og.setWeight_F(weight_F.setScale(3, BigDecimal.ROUND_HALF_UP)); BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); tableViewer.refresh(); } if("Price_G".equals(property)){ if("".equals(value.toString().trim())){ og.setPrice_G(new BigDecimal(0.00)); }else{ og.setPrice_G(new BigDecimal(value.toString())); } BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); tableViewer.refresh(); } if("Service".equals(property)){ if("".equals(value.toString().trim())){ og.setService(new BigDecimal(0.00)); }else{ if(0 == (Integer)value){ og.setT_ServiceFee(0); og.setService(new BigDecimal(6).multiply(og.getWeight_G())); }else if(1 == (Integer)value){ og.setT_ServiceFee(1); og.setService(new BigDecimal(10).multiply(og.getWeight_G())); }else if(2 == (Integer)value){ og.setT_ServiceFee(2); og.setService(new BigDecimal(12).multiply(og.getWeight_G())); }else{ og.setT_ServiceFee(3); og.setService(new BigDecimal(0).multiply(og.getWeight_G())); } } BigDecimal sum = og.getWeight_F().multiply(og.getPrice_G()).add(og.getService()); og.setSum(sum.setScale(2, BigDecimal.ROUND_HALF_UP)); tableViewer.update(og, null); OldGoldIndentifyFacade.caculatorOldGoldTotalPrice(); tableViewer.refresh(); } if("Sum".equals(property)){ if("".equals(value.toString().trim())){ return; }else{ og.setSum(new BigDecimal(value.toString())); } tableViewer.update(og, null); } } } }