package com.gx.obe.evaluation.step.composite.boq;

import java.util.List;

import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;

import com.gx.obe.ColorConstants;
import com.gx.obe.components.core.Constants;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.NumberFormatUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.boq.ConstructProject;
import com.gx.obe.web.entity.tender.TenderProjectEntity;

/**
 * @Description: 单项工程汇总界面
 * @author guoyr
 */
public class DxgcSummaryComposite extends Composite {
	
	private Grid projectSumGrid;
	private DxgcSelectListener listener;
	
	{
		LogUtils.logClass(DxgcSummaryComposite.class);
	}
	
	/**
	 * Create the composite.
	 * 
	 * @param parent
	 * @param style
	 */
	public DxgcSummaryComposite(Composite parent, int style) {
		super(parent, style);
		setLayout(new FillLayout(SWT.HORIZONTAL));
		projectSumGrid = new Grid(this, SWT.H_SCROLL | SWT.V_SCROLL);
		projectSumGrid.setHeaderVisible(true);
		
		GridColumn sortNumColumn = new GridColumn(projectSumGrid, SWT.CENTER);
//		sortNumColumn.setTree(true);
		sortNumColumn.setText("序号");
		sortNumColumn.setWidth(50);
		sortNumColumn.setMaxmumWidth(60);
		
		GridColumn gridColumn = new GridColumn(projectSumGrid, SWT.NONE);
		gridColumn.setText("名称");
		gridColumn.setWidth(200);
		gridColumn.setWordWrap(true);
		
		GridColumn gridColumn_1 = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_1.setText("总价(元)");
		gridColumn_1.setWidth(50);
		
		GridColumn gridColumn_2 = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_2.setText("安全文明施工费(元)");
		gridColumn_2.setWidth(80);
		
		GridColumn gridColumn_3 = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_3.setText("规费(元)");
		gridColumn_3.setWidth(50);
		
		GridColumn gridColumn_tax = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_tax.setText("税金(元)");
		gridColumn_tax.setWidth(60);
		gridColumn_tax.setWordWrap(true);
		
		GridColumn gridColumn_equipmentFee = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_equipmentFee.setText("设备费(元)");
		gridColumn_equipmentFee.setWidth(60);
		
		GridColumn gridColumn_selfSupplyFee = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_selfSupplyFee.setText("甲供材料设备费(元)");
		gridColumn_selfSupplyFee.setWidth(80);
		
		GridColumn gridColumn_4 = new GridColumn(projectSumGrid, SWT.RIGHT);
		gridColumn_4.setText("暂估价(元)");
		gridColumn_4.setWidth(50);
		
		GridItem gridItem = new GridItem(projectSumGrid, SWT.NONE);
		gridItem.setText("New Row");
		
		init();
	}
	
	/**
	 * @Description: 初始化界面
	 * @author guoyr
	 */
	private void init() {
		projectSumGrid.setItemHeight(Constants.ROW_HIGHT);
		projectSumGrid.setEvenBackground(ColorConstants.ENENT_LINE_COLOR);
		projectSumGrid.setShowEvenBackground(true);
		projectSumGrid.setAutoHeight(true);
		listener = new DxgcSelectListener() {
			public void select(TenderProjectEntity tenderProject, Supplier supplier, ConstructProject singleConstruction) {
				refreshProjectSumGrid(tenderProject, supplier, singleConstruction);
			}
			
		};
	}
	
	/**
	 * @Description: 刷新项目汇总Grid
	 * @author guoyr
	 * @param tenderProject
	 * @param supplier
	 * @param singleConstruction 单项工程
	 */
	private void refreshProjectSumGrid(TenderProjectEntity tenderProject, Supplier supplier, ConstructProject singleConstruction) {
		projectSumGrid.removeAll();
		
		if (null != singleConstruction) {
			
			GridItem dxgcItem = new GridItem(projectSumGrid, SWT.NONE);
			dxgcItem.setExpanded(true);
			dxgcItem.setText(0, "一");
			dxgcItem.setText(1, ObjectUtils.getObjString(singleConstruction.getProjectName()) + "汇总");// 单项工程名称
//			dxgcSumItem.setText(1, "单项工程费汇总");
			dxgcItem.setText(2, ObjectUtils.getObjString(singleConstruction.getTotal()));// 单项工程金额
			dxgcItem.setText(3, ObjectUtils.getObjString(singleConstruction.getSafeFee()));// 安全文明施工费
			dxgcItem.setText(4, ObjectUtils.getObjString(singleConstruction.getLawFee()));// 规费
			dxgcItem.setText(5, NumberFormatUtils.format(singleConstruction.getTaxes()));// 税金
			dxgcItem.setText(6, NumberFormatUtils.format(singleConstruction.getEquipmentFee()));// 设备费
			dxgcItem.setText(7, NumberFormatUtils.format(singleConstruction.getSelfSupplyFee()));// 甲供材料设备费
			dxgcItem.setText(8, NumberFormatUtils.format(singleConstruction.getAppraisal()));// 暂估价
			
			// 获得单位工程列表
			List<ConstructProject> unitConstructionList = singleConstruction.getChildProjectList();
			if (null != unitConstructionList) {
				int index = 1;
				for (ConstructProject unitConstruction : unitConstructionList) {
					GridItem dwgcItem = new GridItem(dxgcItem, SWT.NONE);
					dwgcItem.setText(0, (index++) + "");
					dwgcItem.setText(1, ObjectUtils.getObjString(unitConstruction.getProjectName()));// 单位工程名称
					dwgcItem.setText(2, ObjectUtils.getObjString(unitConstruction.getTotal()));// 单位工程金额
					dwgcItem.setText(3, ObjectUtils.getObjString(unitConstruction.getSafeFee()));// 安全文明施工费
					dwgcItem.setText(4, ObjectUtils.getObjString(unitConstruction.getLawFee()));// 规费
					dwgcItem.setText(5, NumberFormatUtils.format(unitConstruction.getTaxes()));// 税金
					dxgcItem.setText(6, NumberFormatUtils.format(unitConstruction.getEquipmentFee()));// 设备费
					dxgcItem.setText(7, NumberFormatUtils.format(unitConstruction.getSelfSupplyFee()));// 甲供材料设备费
					dxgcItem.setText(8, NumberFormatUtils.format(unitConstruction.getAppraisal()));// 暂估价
				}
			}
			projectSumGrid.resizeColumnWidth(0);
		}
	}
	
	public interface DxgcSelectListener {
		
		public void select(TenderProjectEntity tenderProject, Supplier supplier, ConstructProject constructProject);
		
	}
	
	public DxgcSelectListener getListener() {
		return listener;
	}
	
	public void setListener(DxgcSelectListener listener) {
		this.listener = listener;
	}
	
	protected void checkSubclass() {}
}
