package com.topsun.posclient.sales.ui.view; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ComboBoxCellEditor; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TextCellEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.part.ViewPart; import com.topsun.posclient.common.AppConstants; import com.topsun.posclient.common.POSClientApp; import com.topsun.posclient.common.POSException; import com.topsun.posclient.common.ProjectUtil; import com.topsun.posclient.common.core.BarcodeListenetManager; import com.topsun.posclient.common.core.IBarcodeListener; import com.topsun.posclient.common.core.keyboard.SoftKeyUtil; import com.topsun.posclient.common.listener.IKeyListener; import com.topsun.posclient.common.listener.KeyListenerManager; import com.topsun.posclient.common.ui.style.CommonCss; import com.topsun.posclient.common.ui.utils.TableUtils; import com.topsun.posclient.common.ui.utils.ThemeUtils; import com.topsun.posclient.datamodel.Item; import com.topsun.posclient.datamodel.PartSales; import com.topsun.posclient.datamodel.User; import com.topsun.posclient.sales.MessageResources; import com.topsun.posclient.sales.core.service.IReturnedService; import com.topsun.posclient.sales.core.service.impl.ReturnedServiceImpl; import com.topsun.posclient.sales.dialog.AuthDialog; import com.topsun.posclient.sales.dialog.ExechangePayDialog; import com.topsun.posclient.sales.dialog.ReturnedPayDialog; import com.topsun.posclient.sales.ui.gold.ReturnedFacade; import com.topsun.posclient.sales.ui.gold.ReturnedManager; import com.topsun.posclient.sales.ui.table.ReturnedCellModify; import com.topsun.posclient.sales.ui.table.ReturnedTableContentProvider; import com.topsun.posclient.sales.ui.table.ReturnedTableLableProvider; /** * 退换货 * * @author Dong * */ public class ReturnedView extends ViewPart implements IKeyListener,IBarcodeListener { public IReturnedService returnedService = new ReturnedServiceImpl(); List<Item> itemsList = new ArrayList<Item>(); public PartSales partSales; public Text docNum;//单据编号 public Text salesDate;//销售日期 public Text oldInvoiceCode;//原发票daima public Text oldInvoiceNumber;//原发票 public Text barCode;//条形 public TableViewer tableViewer; public Text numberTotal; public Text priceTotal; public int controlVerticalAlignment = 3; public Button cleanAll; //全部清空 private Label totlePrice; //合计金额 private TableColumn last; private TableColumn first; private StringBuffer currentDocNum = new StringBuffer();//保存当前列表中存在的销售数据对应的发票号,多张发票,号分隔 public final StringBuffer getCurrentDocNum() { return currentDocNum; } public final void setCurrentDocNum(StringBuffer currentDocNum) { this.currentDocNum = currentDocNum; } public Text getNumberTotal() { return numberTotal; } public void setNumberTotal(Text numberTotal) { this.numberTotal = numberTotal; } public Text getPriceTotal() { return priceTotal; } public void setPriceTotal(Text priceTotal) { this.priceTotal = priceTotal; } public ReturnedView() { } /** * 商品信息 * @param parent */ private void buildProductInfo(Composite parent){ KeyListenerManager.getInstance().addKeyListener(this); BarcodeListenetManager.getInstance().addKeyListener(this); Group productInfo = new Group(parent, SWT.NONE); productInfo.setText("退/换货列表"); productInfo.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridLayout gridLayout = new GridLayout(1,false); productInfo.setLayout(gridLayout); GridData data = new GridData(GridData.FILL_BOTH); productInfo.setLayoutData(data); buildPrintInfo(productInfo); tableViewer = new TableViewer(productInfo,SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER|SWT.FULL_SELECTION); tableViewer.setContentProvider(new ReturnedTableContentProvider()); tableViewer.setLabelProvider(new ReturnedTableLableProvider()); String[] cloumsProperties = new String[]{"MATNR","itemCode","itemName","num","ZDPZL","price","salesAmount","factAmount","payAmount","cashier","hasGiveaway","isOldGold","invoiceCode"}; tableViewer.setColumnProperties(cloumsProperties); final Table table = tableViewer.getTable(); TableUtils.setTabelHeight(table); table.setBackground(ThemeUtils.getCurrent().getTableBackGround()); table.setFont(CommonCss.getTableHeaderFont(parent.getDisplay())); CellEditor[] editors = new CellEditor[13]; editors[0] = new TextCellEditor(table); editors[1] = new TextCellEditor(table); editors[2] = new TextCellEditor(table); editors[3] = new TextCellEditor(table); editors[4] = new TextCellEditor(table); editors[5] = new TextCellEditor(table); editors[6] = new TextCellEditor(table); editors[7] = new TextCellEditor(table); editors[8] = new TextCellEditor(table); List<String> userNames = new ArrayList<String>(); Map<Integer,User> map = POSClientApp.get().getUserRelation(); Iterator<Entry<Integer, User>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, User> e = (Map.Entry<Integer, User>) it.next(); userNames.add(e.getValue().getUserName()); } // editors[8] = new ComboBoxCellEditor(table, userNames.toArray(new String[]{}),SWT.READ_ONLY) ; editors[9] = new TextCellEditor(table); editors[10] = new ComboBoxCellEditor(table,new String[]{"无赠品","有赠品"},SWT.READ_ONLY); editors[11] = new ComboBoxCellEditor(table,new String[]{"否","是"},SWT.READ_ONLY); editors[12] = new TextCellEditor(table); tableViewer.setCellEditors(editors); tableViewer.setCellModifier(new ReturnedCellModify(tableViewer)); table.setLinesVisible(false); table.setHeaderVisible(true); { GridData tableData = new GridData(GridData.FILL_HORIZONTAL); tableData.heightHint = 270; tableData.horizontalSpan = 4; table.setLayoutData(tableData); } { first = new TableColumn(table, SWT.NONE); first.setWidth(80); first.setText("物料编码"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(180); column.setText("商品编号"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(150); column.setText("商品名称"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(50); column.setText("件数"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(100); column.setText("金重(g)"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(130); column.setText("单价"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(130); column.setText("应售"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(130); column.setText("实售"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(130); column.setText("实付款"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(80); column.setText("营业员"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(80); column.setText("赠品"); } { TableColumn column = new TableColumn(table, SWT.NONE); column.setWidth(80); column.setText("贴金贴换"); } { last = new TableColumn(table, SWT.NONE); last.setWidth(150); last.setText("发票号码"); } { last = new TableColumn(table, SWT.NONE); last.setWidth(150); last.setText("发票代码"); } } private void buildPrintInfo(Composite parent){ Composite operationComposite = new Composite(parent, SWT.NONE); operationComposite.setLayout(new GridLayout(4,false)); { Button button = new Button(operationComposite, SWT.NONE); button.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data1 = new GridData(); data1.heightHint = 45; data1.widthHint = 80; button.setLayoutData(data1); button.setText("删除"); ReturnedFacade.delGoldSaleItemListener(button); } { cleanAll = new Button(operationComposite, SWT.NONE); cleanAll.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data1 = new GridData(); data1.heightHint = 45; data1.widthHint = 80; cleanAll.setLayoutData(data1); cleanAll.setText("清空"); cleanAll.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { tableViewer.setInput(null); ReturnedManager.getInstance().setCurrentDocNum(new StringBuffer()); ReturnedFacade.caculatorReturnedPrice(); } public void widgetDefaultSelected(SelectionEvent e) { } }); } } public void onChange(String operationType) { Display.getDefault().asyncExec(new Runnable() { public void run() { if(tableViewer.getInput() != null){ List<Item> items = (List<Item>)tableViewer.getInput() ; Item addItem = new Item(); items.add(addItem); tableViewer.setInput(items); tableViewer.editElement(addItem, 0); tableViewer.setSelection(new StructuredSelection(addItem)); }else{ List<Item> items = new ArrayList<Item>(); Item addItem = new Item(); items.add(addItem); tableViewer.setInput(items); tableViewer.editElement(addItem, 0); } caculatorNumAndPrice(); } }); } public void createPartControl(Composite parent) { parent.setLayout(new GridLayout(1,false)); parent.setBackground(ThemeUtils.getCurrent().getBackGroundColor()); parent.setBackgroundMode(SWT.INHERIT_FORCE); buildBaseInfo(parent); buildProductInfo(parent); buildOperation(parent); ReturnedManager.getInstance().setReturnedTableView(tableViewer); ReturnedManager.getInstance().setReturnedTotlePrice(totlePrice); ReturnedManager.getInstance().setBarCode(barCode); ReturnedManager.getInstance().setDocNum(docNum); ReturnedManager.getInstance().setOldDocNum(oldInvoiceNumber); ReturnedManager.getInstance().setCurrentDocNum(currentDocNum); ReturnedManager.getInstance().setPartSales(partSales); ReturnedFacade.addSalesItemListener(barCode); ReturnedFacade.addDocNumListener(oldInvoiceNumber,oldInvoiceCode, barCode,tableViewer); } private void buildOperation(final Composite parent){ Composite operation = new Composite(parent, SWT.NONE); operation.setLayout(new GridLayout(6,false)); operation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); { Label label = new Label(operation, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data1 = new GridData(); label.setLayoutData(data1); label.setText("金额合计:"); } { totlePrice = new Label(operation, SWT.BORDER); totlePrice.setText("0.00"); totlePrice.setFont(CommonCss.getDefaultFont(parent.getDisplay())); totlePrice.setLayoutData(CommonCss.getDefaultTextData()); } { Button button = new Button(operation, SWT.NONE); button.setFont(CommonCss.getDefaultFont(parent.getDisplay())); button.setText("结算"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 80; button.setLayoutData(data); button.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button saveButton = (Button)e.getSource(); { if(tableViewer.getInput() == null){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "【商品信息】不能为空"); return; } List<Item> list = (List<Item>)tableViewer.getInput() ; if(list.size() == 0){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "【商品信息】不能为空"); return; } for (Item item : list) { if(item.getItemName() == null || item.getItemName().equals("")){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "【商品名称】不能为空"); return; } if(item.getItemCode() == null || item.getItemCode().equals("")){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "【商品编号】不能为空"); return; } if(item.getMATNR() == null || item.getMATNR().equals("")){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "【物料编码】不能为空"); return; } } } partSales = ReturnedManager.getInstance().getPartSales(); if(null == partSales){ partSales = new PartSales(); } String price = totlePrice.getText(); List<Item> itemList = ReturnedFacade.getCurrentItemList(); partSales.setItemList(itemList); partSales.setDocNum(docNum.getText()); partSales.setSalesType(AppConstants.SALES_TYPE_RETURNED); for(Item item : itemList){ //如果item的类型,为退换货时添加的新品则这是销售类型为换货,如果没有新品设置销售类型为退货 if(item.getItemType().equals(AppConstants.ITEM_TYPE_RETURNED_NEW)){ partSales.setSalesType(AppConstants.SALES_TYPE_EXECHANGE); } } if(partSales.getSalesType() == AppConstants.SALES_TYPE_EXECHANGE){//换货 AuthDialog authDialog = new AuthDialog(saveButton.getShell()); authDialog.setDoFlag(2); try{ int retrunType =authDialog.open(); if(retrunType == 1){ return; } }catch(Exception eeee){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "系统错误"); return; } ExechangePayDialog dialog = new ExechangePayDialog(saveButton.getShell()); try{ // dialog.setPrice(returnedService.addTotalAmountForReturn(partSales, price)); dialog.setPrice(price); dialog.setPartSales(partSales); partSales.setCashierModelList(null); partSales.setInvoiceNumber(oldInvoiceNumber.getText()); int retrunType =dialog.open(); if(retrunType == 1){ return; } }catch(Exception eeee){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, eeee.getMessage()); return; } }else{//退货 boolean isUnSources = false; for(Item item : itemList){ if(item.getItemType().equals(AppConstants.ITEM_TYPE_UNRETURNED)){ isUnSources = true; } } //如果是无源退货,合计金额必须小于0 if(isUnSources){ BigDecimal total = ProjectUtil.formatString(totlePrice.getText()); if(null == total || total.compareTo(BigDecimal.ZERO) != -1){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "金额合计必须小于零"); return; } } AuthDialog authDialog = new AuthDialog(saveButton.getShell()); authDialog.setDoFlag(2); try{ int retrunType =authDialog.open(); if(retrunType == 1){ return; } }catch(Exception eeee){ MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, "系统错误"); return; } ReturnedPayDialog dialog = new ReturnedPayDialog(saveButton.getShell()); try{ dialog.setPrice(price); dialog.setPartSales(partSales); if(!isUnSources){//不是无源退货 if(null == partSales.getCashierModelList() || partSales.getCashierModelList().size() == 0){ partSales.setCashierModelList(returnedService.getAllCashierMode().getCashierModeList()); } }else{ partSales.setCashierModelList(returnedService.getAllCashierMode().getCashierModeList()); } int retrunType =dialog.open(); if(retrunType == 1){ return; } } catch (POSException ee) { MessageDialog.openInformation(saveButton.getShell(), MessageResources.message_ui_tips, ee.getErrorMessage()); return; } } } public void widgetDefaultSelected(SelectionEvent e) { } }); } { Label label = new Label(operation, SWT.NONE); GridData data1 = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data1); } { Button button = new Button(operation, SWT.NONE); button.setFont(CommonCss.getDefaultFont(parent.getDisplay())); button.setText("<"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 80; button.setLayoutData(data); button.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { tableViewer.getTable().showColumn(first); } @Override public void widgetDefaultSelected(SelectionEvent e) { // TODO Auto-generated method stub } }); } { Button button = new Button(operation, SWT.NONE); button.setFont(CommonCss.getDefaultFont(parent.getDisplay())); button.setText(">"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 80; button.setLayoutData(data); button.addSelectionListener(new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { tableViewer.getTable().showColumn(last); } @Override public void widgetDefaultSelected(SelectionEvent e) { } }); } } private void caculatorNumAndPrice() { int totalNum = 0; double totalPrice = 0; for (Item item : (List<Item>)tableViewer.getInput()) { totalNum = 0; } numberTotal.setText(String.valueOf(totalNum)); for (Item item : (List<Item>)tableViewer.getInput()) { totalPrice = 0; } priceTotal.setText(String.valueOf(totalPrice)); } private void buildBaseInfo(Composite parent) { Group baseInfo = new Group(parent, SWT.NONE); baseInfo.setText(MessageResources.message_ui_group_baseinfo); GridLayout gridLayout = new GridLayout(3,false); gridLayout.marginLeft = 5; baseInfo.setLayout(gridLayout); baseInfo.setLayoutData(new GridData(GridData.FILL_BOTH)); Composite leftComposite = new Composite(baseInfo,SWT.NONE); leftComposite.setLayout(new GridLayout(22,false)); leftComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); { Label label = new Label(leftComposite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 1; label.setLayoutData(data); label.setText("单据编号:"); } { docNum = new Text(leftComposite, SWT.BORDER); GridData data = CommonCss.getTextData(165); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 3; docNum.setLayoutData(data); docNum.setFont(CommonCss.getDefaultFont(parent.getDisplay())); docNum.setEditable(false); try { docNum.setText(returnedService.createNo(AppConstants.DOC_TYPE_RETURNED)); } catch (POSException e) { e.printStackTrace(); MessageDialog.openError(parent.getShell(), MessageResources.message_ui_tips, e.getErrorMessage()); } } { Label label = new Label(leftComposite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 1; label.setLayoutData(data); label.setText("发票代码:"); } { oldInvoiceCode = new Text(leftComposite, SWT.BORDER); GridData data = CommonCss.getTextData(140); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 3; oldInvoiceCode.setFont(CommonCss.getDefaultFont(parent.getDisplay())); oldInvoiceCode.setLayoutData(data); SoftKeyUtil.showSoftKey(oldInvoiceCode); } { Label label = new Label(leftComposite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 1; label.setLayoutData(data); label.setText("原发票号:"); } { oldInvoiceNumber = new Text(leftComposite, SWT.BORDER); GridData data = CommonCss.getTextData(140); data.verticalIndent = controlVerticalAlignment; data.horizontalSpan = 3; oldInvoiceNumber.setFont(CommonCss.getDefaultFont(parent.getDisplay())); oldInvoiceNumber.setLayoutData(data); SoftKeyUtil.showSoftKey(oldInvoiceNumber); } { Label lable = new Label(leftComposite, SWT.NONE); lable.setFont(CommonCss.getDefaultFont(parent.getDisplay())); lable.setText("条形码:"); GridData data = new GridData(); data.horizontalSpan = 1; data.verticalIndent = controlVerticalAlignment; lable.setLayoutData(data); } { barCode = new Text(leftComposite, SWT.BORDER); GridData data = CommonCss.getTextData(140); data.horizontalSpan = 3; data.verticalIndent = controlVerticalAlignment; barCode.setLayoutData(data); barCode.setFont(CommonCss.getDefaultFont(parent.getDisplay())); barCode.setFocus(); SoftKeyUtil.showSoftKey(barCode); } { Button btn1 = new Button(leftComposite, SWT.NONE); btn1.setFont(CommonCss.getDefaultFont(parent.getDisplay())); btn1.setText("确定"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 80; data.horizontalSpan = 1; btn1.setLayoutData(data); btn1.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button sureBtn = (Button)e.getSource(); String inputBarCode = barCode.getText(); String inputOldDocNum = oldInvoiceNumber.getText(); String inputoldInvoiceCode = oldInvoiceCode.getText(); if(null != inputBarCode && !"".equals(inputBarCode)){ try { ReturnedFacade.addTableItem(inputOldDocNum, inputBarCode, tableViewer); barCode.setFocus(); barCode.setText(""); } catch (POSException e2) { MessageDialog.openError(sureBtn.getShell(), MessageResources.message_ui_tips, e2.getErrorMessage()); barCode.setText(""); oldInvoiceNumber.setText(""); oldInvoiceCode.setText(""); return; } //点击确定,如果原发票代码和发票号码都不为空,还需要添加原始销售信息 if(null != inputoldInvoiceCode && !"".equals(inputoldInvoiceCode) && null != inputOldDocNum && !"".equals(inputOldDocNum)){ doAddOldItem(inputoldInvoiceCode, inputOldDocNum, sureBtn); } }else{ doAddOldItem(inputoldInvoiceCode, inputOldDocNum, sureBtn); } } public void widgetDefaultSelected(SelectionEvent e) { } private void doAddOldItem(String inputoldInvoiceCode, String inputOldDocNum, Button sureBtn){ if(null == inputoldInvoiceCode || "".equals(inputoldInvoiceCode)){ MessageDialog.openInformation(sureBtn.getShell(), MessageResources.message_ui_tips, "请输入【发票代码】"); oldInvoiceCode.setFocus(); return; } if(null == inputOldDocNum || "".equals(inputOldDocNum)){ MessageDialog.openInformation(sureBtn.getShell(), MessageResources.message_ui_tips, "请输入【发票号码】"); oldInvoiceNumber.setFocus(); return; } if(isExitsInvoiceNumData(inputOldDocNum)){ MessageDialog.openError(sureBtn.getShell(), MessageResources.message_ui_tips, "发票号码【"+inputOldDocNum+"】不存在!或者对应的数据已在列表中"); barCode.setText(""); oldInvoiceNumber.setText(""); oldInvoiceCode.setText(""); return; } try { partSales = returnedService.queryReturnedItemsByInvoiceNum(inputOldDocNum, inputoldInvoiceCode); } catch (POSException e1) { MessageDialog.openError(sureBtn.getShell(), MessageResources.message_ui_tips, e1.getErrorMessage()); oldInvoiceNumber.setText(""); oldInvoiceCode.setText(""); return; } Object obj = tableViewer.getInput(); if (obj == null) { List<Item> list = new ArrayList<Item>(); if(null != partSales){ list.addAll(partSales.getItemList()); tableViewer.setInput(list); } } else { if (obj instanceof List) { List list = (List) obj; if(null != partSales.getItemList() && partSales.getItemList().size() > 0){ list.addAll(partSales.getItemList()); tableViewer.setInput(list); } } } ReturnedManager.getInstance().setPartSales(partSales); ReturnedManager.getInstance().getCurrentDocNum().append(inputOldDocNum+","); ReturnedFacade.caculatorReturnedPrice(); tableViewer.refresh(); barCode.setText(""); oldInvoiceNumber.setText(""); oldInvoiceCode.setText(""); } }); } { Button btn1 = new Button(leftComposite, SWT.NONE); btn1.setFont(CommonCss.getDefaultFont(parent.getDisplay())); btn1.setText("无源退货"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 100; data.horizontalSpan = 1; btn1.setLayoutData(data); btn1.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { Button sureBtn = (Button)e.getSource(); try { ReturnedFacade.addUnSourcesTableItem(tableViewer); } catch (POSException e1) { MessageDialog.openError(sureBtn.getShell(), MessageResources.message_ui_tips, e1.getErrorMessage()); return; } } public void widgetDefaultSelected(SelectionEvent e) { } }); } { Button btn1 = new Button(leftComposite, SWT.NONE); btn1.setFont(CommonCss.getDefaultFont(parent.getDisplay())); btn1.setText("重置"); GridData data = new GridData(); data.heightHint = 45; data.widthHint = 80; data.horizontalSpan = 1; btn1.setLayoutData(data); btn1.addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { oldInvoiceNumber.setText(""); barCode.setText(""); barCode.setFocus(); } public void widgetDefaultSelected(SelectionEvent e) { } }); } } /** * 判断当前输入的发票号码对应的销售数据是否在列表中已经存在 * @param invoiceNum 输入的发票号码 * @return */ private boolean isExitsInvoiceNumData(String invoiceNum){ TableViewer tableViewer = ReturnedManager.getInstance().getReturnedTableView(); List<Item> list = (List<Item>)tableViewer.getInput(); if(list == null){ return false; } if(list.size() == 0){ return false; } List<Item> returnedItem = new ArrayList<Item>(); List<Item> returnedNewItem = new ArrayList<Item>(); for (Item item : list) { if(item.getItemType().equals(AppConstants.ITEM_TYPE_RETURNED)){ returnedItem.add(item); } // if(item.getItemType().equals(AppConstants.ITEM_TYPE_RETURNED_NEW)){ // returnedNewItem.add(item); // } } for (Item item : returnedItem) { String docNum = item.getDocNum(); if(invoiceNum.equals(docNum)){ return true; } } if(returnedItem.size() == 0){ return false; } // boolean ret = false; // String currentDocNumStr = ReturnedManager.getInstance().getCurrentDocNum().toString(); // if(null == currentDocNumStr || currentDocNumStr.length() <= 0){ // return ret; // } // String[] currentInvoiceNumArray = currentDocNumStr.toString().split(","); // if(null == currentInvoiceNumArray || currentInvoiceNumArray.length == 0){ // return ret; // } // for(int i=0; i<currentInvoiceNumArray.length; i++){ // if(currentInvoiceNumArray[i].equals(invoiceNum)){ // ret = true; // } // } return true; } public void setFocus() { } @Override public void onChangeBarcode(final String operationType) { IWorkbenchWindow window = PlatformUI.getWorkbench().getWorkbenchWindows()[0]; IWorkbenchPage page = window.getActivePage(); String viewid = page.getActivePartReference().getId(); if(!"com.topsun.posclient.sales.ui.menu.ReturnedView".equals(viewid)){ return; } Display.getDefault().asyncExec(new Runnable() { public void run() { try { if(tableViewer.getInput() != null){ List<Item> items = (List<Item>)tableViewer.getInput() ; List<String> nameList = new ArrayList<String>(); for (Item item : items) { String itemCode = item.getItemCode(); nameList.add(itemCode); } if(nameList.contains(operationType)){ Item selectedItem = null; for (Item t_item : items) { String itemCode = t_item.getItemCode(); if(itemCode.equals(operationType)){ selectedItem = t_item; } } tableViewer.refresh(); tableViewer.setSelection(new StructuredSelection(selectedItem)); tableViewer.editElement(selectedItem, 2); }else{ try { Item addItem = returnedService.getItemByBarCode(operationType); items.add(addItem); tableViewer.setInput(items); tableViewer.editElement(addItem, 2); tableViewer.setSelection(new StructuredSelection(addItem)); } catch (POSException e) { e.printStackTrace(); } } }else{ List<Item> items = new ArrayList<Item>(); Item addItem = new Item(); addItem.setItemCode(operationType); items.add(addItem); tableViewer.setInput(items); tableViewer.editElement(addItem, 2); } caculatorNumAndPrice(); } catch (Exception e) { e.printStackTrace(); } } }); } }