package com.gx.obe.management.composite;

import java.math.BigDecimal;
import java.text.MessageFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.nebula.widgets.grid.Grid;
import org.eclipse.nebula.widgets.grid.GridColumn;
import org.eclipse.nebula.widgets.grid.GridItem;
import org.eclipse.nebula.widgets.grid.listener.GridSelectionListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.listener.FloatInputListener;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.BigButton;
import org.eclipse.swt.core.widgets.ConfirmDialog;
import org.eclipse.swt.core.widgets.ELink;
import org.eclipse.swt.core.widgets.EMenu;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.gx.obe.ColorConstants;
import com.gx.obe.action.bean.Action;
import com.gx.obe.business.entity.MenuFunction;
import com.gx.obe.common.icons.IconsActivator;
import com.gx.obe.common.widget.thread.SyncThread;
import com.gx.obe.common.widget.utils.MenuFunctionUtils;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.I18NEnum;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationFactorEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.components.core.enumeration.TenderProjectEnum;
import com.gx.obe.formula.PriceParam;
import com.gx.obe.management.dialog.ApplyToOtherFactorComputerDialog;
import com.gx.obe.management.dialog.ApplyToOtherTenderPackPriceComputerDialog;
import com.gx.obe.management.dialog.PriceFormulaConfigDialog;
import com.gx.obe.management.shell.BidPriceSelectShell;
import com.gx.obe.management.shell.BidPriceSelectShell.BidPriceSelection;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.LogUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.price.BidPrice;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.BidPriceService;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.utils.ActionLogUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/**
 * @Description: 价格指标管理
 * @author guoyr
 */
public class PriceFactorsManagerComposite extends Composite {
	
	private Text factor_name_text;
	private Text factor_memo_text;
	private ELink add_btn;
	private ELink add_sub_btn;
	private ELink import_bid_price_factor;
	private ELink del_btn;
	private BigButton save_btn;
	private Grid factors_grid;
	private GridColumn gridColumn;
	private ImageResolver imageResolver = new ImageResolver();
	private Image menuOpenImage;
	private Image menuImage;
	private Text factor_score_text;
	private Text min_score_text;
	private Text max_score_text;
	private Text weight_text;
	private Composite weightComposite;
	private EvaluationFactor curFactor;
	private ScrolledComposite scrolledComposite;
	private Composite scroContentComposite;
	private Composite composite_1;
	private ELink upFactorBtn;
	private Composite composite_4;
	private ELink downFactorBtn;
	private boolean isInEvaluationProgress = false;
	private boolean isExistEvaluationStep = false;
	private boolean isFactorCategory = false;
	private Composite composite_6;
	private Composite composite_11;
	private Composite composite_12;
	private Text formula_text;
	private ELink del_bid_price;
	private ELink config_formula;
	private Composite composite_3;
	private Text bid_price_text;
	private ELink config_bid_price;
	private Map<String, String> bidPriceMap;
	private Composite composite_7;
	private ELink del_formula;
	private ELink applyToOtherPackBtn;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	private Label weightTitle;
	private TenderProjectEntity tenderProject;
	private TenderProjectRuleEntity	projectRule;
	private BidPriceService bidPriceService; 
	private TenderProjectService tenderProjectService ;
	private EvaluationStepService evaluationStepService;
	private EvaluationFactorService evaluationFactorService;
	private ProjectRuleService projectRuleService;
	private Action projectAction;
	private ELink applyToOtherFactorBtn;
	{
		LogUtils.logClass(PriceFactorsManagerComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public PriceFactorsManagerComposite(Composite parent, Action projectAction, int style) {
		super(parent, style);
		GridLayout gridLayout = new GridLayout(2, false);
		gridLayout.horizontalSpacing = 10;
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		setLayout(gridLayout);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		this.projectAction = projectAction;
	
		composite_1 = new Composite(this, SWT.NONE);
		GridData gd_composite_1 = new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1);
		gd_composite_1.widthHint = 300;
		composite_1.setLayoutData(gd_composite_1);
		composite_1.setBackground(ColorConstants.BORDER_LINE_COLOR);
		GridLayout gl_composite_1 = new GridLayout(1, false);
		gl_composite_1.marginWidth = 1;
		gl_composite_1.marginHeight = 1;
		gl_composite_1.verticalSpacing = 1;
		composite_1.setLayout(gl_composite_1);
		composite_4 = new Composite(composite_1, SWT.NONE);
		composite_4.setBackgroundMode(SWT.INHERIT_FORCE);
		composite_4.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_4.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		GridLayout gl_composite_4 = new GridLayout(6, false);
		gl_composite_4.horizontalSpacing = 0;
		composite_4.setLayout(gl_composite_4);
		
		upFactorBtn = new ELink(composite_4, SWT.NONE);
		upFactorBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				moveEvaluationFactorAction(-1);
			}
		});
		upFactorBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/up.png"));
		upFactorBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
		upFactorBtn.setText(Messages.Button_moveUp);
		
		downFactorBtn = new ELink(composite_4, SWT.NONE);
		downFactorBtn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		downFactorBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				moveEvaluationFactorAction(1);
			}
		});
		downFactorBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/down.png"));
		downFactorBtn.setText(Messages.Button_moveDown);
		
		add_btn = new ELink(composite_4, SWT.NONE);
		add_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add.png"));
		add_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				addFctorAction();
			}
		});
		add_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		add_btn.setText(Messages.Button_add);
		add_btn.setToolTipText(Messages.Button_addSibling);
		menuFunctionUtils.addFunction(add_btn, "ADD");
		
		add_sub_btn = new ELink(composite_4, SWT.NONE);
		add_sub_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add_sub.png"));
		add_sub_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				addSubFctorAction();
			}
		});
		add_sub_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		add_sub_btn.setText(Messages.Button_add);
		add_sub_btn.setToolTipText(Messages.Button_addChildSibling);
		menuFunctionUtils.addFunction(add_sub_btn, "ADD_SUB");
		
		import_bid_price_factor = new ELink(composite_4, SWT.NONE);
		import_bid_price_factor.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/add_sub.png"));
		import_bid_price_factor.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		import_bid_price_factor.setText(Messages.Price);
		import_bid_price_factor.setToolTipText(Messages.Tips_createFactorByBidPrice);
		import_bid_price_factor.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				importBidPriceFactorAction();
			}
		});
		menuFunctionUtils.addFunction(import_bid_price_factor, "ADD_PRICE_FACTOR");
		
		del_btn = new ELink(composite_4, SWT.NONE);
		del_btn.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		del_btn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		del_btn.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				delEvaluationFactorAction();
			}
		});
		del_btn.setText(Messages.Button_delete);
		menuFunctionUtils.addFunction(del_btn, "DELETE");
		
		composite_7 = new Composite(composite_1, SWT.NONE);
		composite_7.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		composite_7.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_7 = new GridLayout(1, false);
		gl_composite_7.marginHeight = 0;
		gl_composite_7.marginWidth = 0;
		composite_7.setLayout(gl_composite_7);
		
		
		factors_grid = new Grid(composite_7, SWT.V_SCROLL);
		factors_grid.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		gridColumn = new GridColumn(factors_grid, SWT.NONE);
		gridColumn.setText(Messages.Factor_price);
		gridColumn.setWidth(200);
		
		Composite composite = new Composite(this, SWT.NONE);
		GridLayout gl_composite = new GridLayout(1, false);
		gl_composite.verticalSpacing = 0;
		gl_composite.horizontalSpacing = 0;
		gl_composite.marginWidth = 0;
		gl_composite.marginHeight = 0;
		composite.setLayout(gl_composite);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		scrolledComposite = new ScrolledComposite(composite, SWT.V_SCROLL);
		scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		scroContentComposite = new Composite(scrolledComposite, SWT.NONE);
		GridLayout gl_scroContentComposite = new GridLayout(1, false);
		gl_scroContentComposite.horizontalSpacing = 0;
		gl_scroContentComposite.verticalSpacing = 0;
		gl_scroContentComposite.marginHeight = 0;
		gl_scroContentComposite.marginWidth = 0;
		scroContentComposite.setLayout(gl_scroContentComposite);
		
		Composite composite_5 = new Composite(scroContentComposite, SWT.NONE);
		composite_5.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_5 = new GridLayout(2, false);
		gl_composite_5.verticalSpacing = 10;
		gl_composite_5.marginWidth = 10;
		gl_composite_5.marginTop = 5;
		composite_5.setLayout(gl_composite_5);
		
		Label label = new Label(composite_5, SWT.RIGHT);
		label.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
//		gd_label.widthHint = 80;
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText(Messages.FactorName + "：");
		
		composite_11 = new Composite(composite_5, SWT.NONE);
		GridData gd_composite_11 = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
		gd_composite_11.widthHint = 200;
		composite_11.setLayoutData(gd_composite_11);
		GridLayout gl_composite_11 = new GridLayout(1, false);
		gl_composite_11.marginWidth = 0;
		gl_composite_11.marginHeight = 0;
		gl_composite_11.verticalSpacing = 0;
		composite_11.setLayout(gl_composite_11);
		
		factor_name_text = new Text(composite_11, SWT.WRAP | SWT.MULTI);
		factor_name_text.setTopIndex(5);
		factor_name_text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		factor_name_text.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.NORMAL));
		factor_name_text.setTextLimit(500);
		
		ESepator label_2 = new ESepator(composite_11, SWT.HORIZONTAL);
		label_2.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		label_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		
		Label label_4 = new Label(composite_5, SWT.RIGHT);
		label_4.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_4.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_4.setText(Messages.FactorScore + "：");
		
		composite_12 = new Composite(composite_5, SWT.NONE);
		composite_12.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		GridLayout gl_composite_12 = new GridLayout(6, false);
		gl_composite_12.verticalSpacing = 0;
		gl_composite_12.horizontalSpacing = 0;
		gl_composite_12.marginWidth = 0;
		gl_composite_12.marginHeight = 0;
		composite_12.setLayout(gl_composite_12);
		
		factor_score_text = new Text(composite_12, SWT.NONE | SWT.CENTER);
		factor_score_text.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent arg0) {
				modifyFactorScoreAction(this);
			}
		});
		GridData gd_score_text = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
		gd_score_text.widthHint = 50;
		factor_score_text.setLayoutData(gd_score_text);
		
		Label label_19 = new Label(composite_12, SWT.NONE);
		label_19.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		label_19.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_19.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));
		label_19.setText(Messages.TextScore + "（");
		
		min_score_text = new Text(composite_12, SWT.NONE | SWT.CENTER);
		
		GridData gd_min_score_text = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
		gd_min_score_text.widthHint = 50;
		min_score_text.setLayoutData(gd_min_score_text);
		
		ESepator label_6 = new ESepator(composite_12, SWT.SEPARATOR | SWT.HORIZONTAL);
		GridData gd_label_6 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2);
		gd_label_6.widthHint = 20;
		label_6.setLayoutData(gd_label_6);
		label_6.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		max_score_text = new Text(composite_12, SWT.NONE | SWT.CENTER);
		GridData gd_max_score_text = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
		gd_max_score_text.widthHint = 50;
		max_score_text.setLayoutData(gd_max_score_text);
		
		Label label_21 = new Label(composite_12, SWT.NONE);
		label_21.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		label_21.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		label_21.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));
		label_21.setText("）");
		
		ESepator label_3 = new ESepator(composite_12, SWT.HORIZONTAL);
		label_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label_3.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		ESepator label_23 = new ESepator(composite_12, SWT.HORIZONTAL);
		label_23.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label_23.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		ESepator label_22 = new ESepator(composite_12, SWT.HORIZONTAL);
		label_22.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label_22.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		weightTitle = new Label(composite_5, SWT.NONE);
		weightTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		weightTitle.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		weightTitle.setText(Messages.FactorWeight + "：");
		{
			weightComposite = new Composite(composite_5, SWT.NONE);
			GridData gd_weightComposite = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
			gd_weightComposite.widthHint = 300;
			weightComposite.setLayoutData(gd_weightComposite);
			GridLayout gl_weightComposite = new GridLayout(3, false);
			gl_weightComposite.verticalSpacing = 0;
			gl_weightComposite.marginHeight = 0;
			gl_weightComposite.marginWidth = 0;
			weightComposite.setLayout(gl_weightComposite);
			
			weight_text = new Text(weightComposite, SWT.CENTER);
			GridData gd_weightText = new GridData(SWT.FILL, SWT.BOTTOM, false, true, 1, 1);
			gd_weightText.widthHint = 50;
			weight_text.setLayoutData(gd_weightText);
			
			Label label_9 = new Label(weightComposite, SWT.NONE);
			label_9.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));
			label_9.setText("%");
			
			Label wieght_tips = new Label(weightComposite, SWT.WRAP);
			wieght_tips.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2));
			wieght_tips.setForeground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
			wieght_tips.setText(Messages.Tips_weight);
			
			ESepator label_5 = new ESepator(weightComposite, SWT.HORIZONTAL);
			label_5.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true, 1, 1));
			label_5.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		}
		
		Label label_8 = new Label(composite_5, SWT.NONE);
		label_8.setAlignment(SWT.RIGHT);
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_8.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_8.setText(Messages.BidPrice+"：");
		
		composite_3 = new Composite(composite_5, SWT.NONE);
		composite_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		GridLayout gl_composite_3 = new GridLayout(4, false);
		gl_composite_3.verticalSpacing = 0;
		gl_composite_3.marginWidth = 0;
		gl_composite_3.marginHeight = 0;
		composite_3.setLayout(gl_composite_3);
		
		bid_price_text = new Text(composite_3, SWT.READ_ONLY);
		bid_price_text.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		GridData gd_bid_price_label = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_bid_price_label.widthHint = 200;
		gd_bid_price_label.minimumWidth = 200;
		bid_price_text.setLayoutData(gd_bid_price_label);
		bid_price_text.setText(Messages.BidPrice);
		
		config_bid_price = new ELink(composite_3, SWT.NONE);
		config_bid_price.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 2));
		config_bid_price.setText("");
		config_bid_price.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/link.png"));
		config_bid_price.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				configBidPriceAction();
			}
		});
		
		del_bid_price = new ELink(composite_3, SWT.NONE);
		del_bid_price.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		del_bid_price.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 2));
		del_bid_price.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				delBidPriceAction();
			}
		});
		
		Label label_11 = new Label(composite_3, SWT.WRAP);
		label_11.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 2));
		label_11.setText(Messages.Tips_linkBidPrice);
		label_11.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		
		ESepator label_7 = new ESepator(composite_3, SWT.HORIZONTAL);
		label_7.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
		label_7.setBackground(ColorConstants.SEP_LIGHT_COLOR);
		
		Label label_10 = new Label(composite_5, SWT.RIGHT);
		label_10.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_10.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_10.setText(Messages.ScoreFormula + "：");
		
		composite_6 = new Composite(composite_5, SWT.NONE);
		composite_6.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		GridLayout gl_composite_6 = new GridLayout(1, false);
		gl_composite_6.verticalSpacing = 0;
		gl_composite_6.marginHeight = 0;
		gl_composite_6.marginWidth = 0;
		composite_6.setLayout(gl_composite_6);
		
		Composite composite_8 = new Composite(composite_6, SWT.NONE);
		composite_8.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		GridLayout gl_composite_8 = new GridLayout(4, false);
		gl_composite_8.marginHeight = 0;
		gl_composite_8.marginWidth = 0;
		composite_8.setLayout(gl_composite_8);
		
		config_formula = new ELink(composite_8, SWT.NONE);
		config_formula.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/formula.png"));
		config_formula.setText(Messages.Button_configScoreFormula);
		config_formula.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				configFormulaAction();
			}
		});
		
		del_formula = new ELink(composite_8, SWT.NONE);
		del_formula.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/delete.png"));
		del_formula.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				delFormulaAction();
			}
		});
		del_formula.setText(Messages.Button_delete);
		
		applyToOtherPackBtn = new ELink(composite_8, SWT.NONE);
		applyToOtherPackBtn.setText(MessageFormat.format(Messages.Button_applyToOthers, Messages.TenderPackage));
		applyToOtherPackBtn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				applyToOtherPackAction();
			}
		});
		
		applyToOtherPackBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/copy.png"));
		menuFunctionUtils.addFunction(applyToOtherPackBtn, "APPLY_FORMULA");
		
		applyToOtherFactorBtn = new ELink(composite_8, SWT.NONE);
		applyToOtherFactorBtn.setText(MessageFormat.format(Messages.Button_applyToOthers, Messages.Factor_factor));
		applyToOtherFactorBtn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				applyToOtherFactorAction();
			}
		});
		
		applyToOtherFactorBtn.setImage(ResourceManager.getPluginImage(IconsActivator.PLUGIN_ID, "icons/btn/blue/copy.png"));
		menuFunctionUtils.addFunction(applyToOtherFactorBtn, "APPLY_FORMULA_TO_FACTOR");
		
		formula_text = new Text(composite_6, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		GridData gd_formula_text = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
		gd_formula_text.heightHint = 100;
		gd_formula_text.widthHint = 200;
		formula_text.setLayoutData(gd_formula_text);
		
		Label label_1 = new Label(composite_5, SWT.RIGHT);
		label_1.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.NORMAL));
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
		label_1.setText(Messages.EvalExplain + "：");
		
		factor_memo_text = new Text(composite_5, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		GridData gd_factorMemoText = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
		gd_factorMemoText.widthHint = 200;
		gd_factorMemoText.heightHint = 50;
		factor_memo_text.setLayoutData(gd_factorMemoText);
		factor_memo_text.setTextLimit(1000);
		
		scrolledComposite.setContent(scroContentComposite);
		scrolledComposite.setMinSize(scroContentComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		
		Composite composite_2 = new Composite(composite, SWT.NONE);
		composite_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		composite_2.setLayout(new GridLayout(1, false));
		menuFunctionUtils.addFunction(composite_2, "SAVE");
		
		save_btn = new BigButton(composite_2, SWT.NONE);
		save_btn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				saveEvaluationFactorAction();
			}
		});
		save_btn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		save_btn.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, true, 1, 1));
		save_btn.setText(Messages.Button_save);	
		init();
	}
	
	/**
	 * @Description: 初始化
	 * @author guoyr 
	 */
	private void init(){
		this.tenderProject = projectAction.getTenderProject();
		this.menu = projectAction.getMenu();
		this.projectRule = projectAction.getTenderProjectRule();
		
		applyToOtherPackBtn.setText(MessageFormat.format(Messages.Button_applyToOthers, com.gx.obe.components.core.I18N.getString(I18NEnum.SUBPACKAGE, tenderProject.getTenderType())));
		bidPriceService = new BidPriceService();
		tenderProjectService = new TenderProjectService();
		evaluationFactorService = new EvaluationFactorService();
		
		factors_grid.setItemHeight(Constants.ROW_HIGHT);
		factors_grid.setLinesVisible(false);
//		factors_grid.setAutoHeight(true);
		gridColumn.setShowTreeTogglePic(true);
//		gridColumn.setWordWrap(true);
		gridColumn.setTreeTogglePic(ImageResolver.RESOLVER_INSTANCE.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_expend.png"), ImageResolver.RESOLVER_INSTANCE.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_close.png"));
		gridColumn.setTree(true);

		WidgetUtils.setControlVisible(applyToOtherPackBtn, null != tenderProject.getParentId());
		
		menuOpenImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_parent.png");
		menuImage = imageResolver.loadImage(IconsActivator.PLUGIN_ID,"icons/tree_item.png");
		initInputListener();
		// 添选中事件和右键菜单事件
		factors_grid.addListener(SWT.Selection, new GridSelectionListener(){
			@Override
			public void leftMouseButtonDown(GridItem item) {
				selectionFactorAction();
			}
			@Override
			public void rightMouseButtonDown(GridItem item) {
				mouseRightClickAction();
			}
		});
		
		menuFunctionUtils.initFunctionAuthority(menu);
		bidPriceMap = new HashMap<String, String>();
		List<BidPrice> bidPriceList = bidPriceService.getTenderBidPriceList(tenderProject.getId());
		if(null != bidPriceList){
			for(BidPrice bidPrice : bidPriceList){
				bidPriceMap.put(bidPrice.getBidPriceCode(), bidPrice.getBidPriceName());
			}
			if(bidPriceList.size() > 1){
				bidPriceMap.put(BidPrice.BID_PRICE_TOTAL_CODE, Messages.BidPriceTotal);
			}
		}
		
		if (TenderProjectEnum.REMOTE.equals(tenderProject.getRemoteStatus())) {
//			WidgetUtils.setControlVisible(add_btn, false);
//			WidgetUtils.setControlVisible(add_sub_btn, false);
//			WidgetUtils.setControlVisible(del_btn, false);
		}else if (TenderProjectEnum.LOCAL.equals(tenderProject.getRemoteStatus())) {
			WidgetUtils.setControlVisible(add_btn, true);
			WidgetUtils.setControlVisible(add_sub_btn, true);
			WidgetUtils.setControlVisible(del_btn, true);
		}
		
		refreshFactorTree(null);
	}
	
	/**
	 * @Description: 初始化输入框的输入监听
	 * @author guoyr 
	 */
	private void initInputListener(){
		// 权重检查
		FloatInputListener factorWeightListener = new FloatInputListener();
		factorWeightListener.addMinCheck(0, Messages.Tips_pleaseEnterValidWeight);
		factorWeightListener.addMaxCheck(100, Messages.Tips_pleaseEnterValidWeight);
		weight_text.addKeyListener(factorWeightListener);
		
		// 最小分值检查
		FloatInputListener factorMinScoreListener = new FloatInputListener();
		factorMinScoreListener.addMaxCheck(max_score_text, Messages.Tips_pleaseEnterValidRange);
		factorMinScoreListener.addMinCheck(-100, Messages.Tips_pleaseEnterValidRange);
		min_score_text.addKeyListener(factorMinScoreListener);
		
		// 最大值检查
		FloatInputListener factorMaxScoreListener = new FloatInputListener();
		factorMaxScoreListener.addMinCheck(min_score_text, Messages.Tips_pleaseEnterValidRange);
		factorMaxScoreListener.addMaxCheck(factor_score_text, Messages.Tips_pleaseEnterValidRange);
		max_score_text.addKeyListener(factorMaxScoreListener);
	}
	
	/**
	 * @Description: 设置投标报价
	 * @author guoyr 
	 */
	private void configBidPriceAction(){
		if(null != curFactor && config_bid_price.getEnabled()){
			if(isInEvaluationProgress()){return;}
// 			if(evaluationFactorService.hasTotalBidPriceFactor(tenderProject.getId(), curFactor.getId())){
//				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_hasConfigTotalPrice);
//				return;
//			}
 			List<BidPrice> bidPriceList = bidPriceService.getBidPriceFactorList(tenderProject.getId());
// 			String id = null;
//			if(null != curFactor.getId()){
//				id = curFactor.getId();
//			}
			// 如果没有添加过其他分项报价，则可以添加投标总报价
//			if(evaluationFactorService.findItemizedPriceSize(tenderProject.getId(),EvaluationFactorEnum.AUDIT_PRICE,id) == 0){
				if(null == bidPriceList){
					bidPriceList = new ArrayList<BidPrice>();
				}
				// 只有存在多个报价时，才显示总报价
//				if(bidPriceMap.keySet().size() > 1){
					BidPrice bidPriceTotal = new BidPrice();
					bidPriceTotal.setBidPriceCode(BidPrice.BID_PRICE_TOTAL_CODE);
					bidPriceTotal.setBidPriceName(Messages.BidPriceTotal);
					if(null != bidPriceList && bidPriceList.size() > 1){
						bidPriceTotal.setBidPriceName(bidPriceList.get(0).getBidPriceName());
					}
					bidPriceList.add(0, bidPriceTotal);
//				}
//			}
			if(null != bidPriceList && bidPriceList.size() > 0){
				BidPriceSelectShell shell = new BidPriceSelectShell(getShell(), bidPriceList);
				shell.addBidPriceSelectionListener(new BidPriceSelection(){
					public void select(String bidPriceCode, String bidPriceName) {
						curFactor.setBidPriceCode(bidPriceCode);
						bid_price_text.setText(bidPriceName);
						del_bid_price.setVisible(true);
						bid_price_text.getParent().layout();
						if(null != curFactor.getId()){
							evaluationFactorService.updateAssignProperty(curFactor, new String[]{"id","bidPriceCode"});
							MessageDialog.openShortMessage(Messages.Tips_operateSuccess);
							ActionLogUtils.addServerLog(tenderProject.getId(),"价格指标关联报价", curFactor.getId() + curFactor.getFactorName(), "bidPriceCode:"+bidPriceCode + "\tbidPriceName:"+bidPriceName);
							
						}
					}
				});
				shell.setLocation(config_bid_price.toDisplay(0,config_bid_price.getBounds().height));
				shell.open();
			}else {
				MessageDialog.openShortMessage(Messages.Tips_noConfigBidPrice);
			}
		}
	}
	/**
	 * @Description: 删除投标报价
	 * @author guoyr 
	 */
	private void delBidPriceAction(){
		if(null != curFactor){
			if(isInEvaluationProgress()){return;}
			curFactor.setBidPriceCode(null);
			bid_price_text.setText("");
			bid_price_text.getParent().layout();
			del_bid_price.setVisible(false);
			if(null != curFactor.getId()){
 				evaluationFactorService.updateAssignProperty(curFactor, new String[]{"id","bidPriceCode"});
			}
		}
	}
	/**
	 * @Description: 配置价格公式
	 * @author guoyr 
	 */
	private void configFormulaAction(){
		if(factors_grid.getItemCount() > 1 && (null == curFactor.getBidPriceCode() || "".equals(curFactor.getBidPriceCode()))){
			MessageDialog.openShortMessage(Messages.Tips_linkBidPrice);
			return;
		}
		curFactor.setFactorScore(ObjectUtils.getObjBigDecimal(factor_score_text.getText().trim(), Constants.SCORE_SCALE));
		if(null == curFactor.getFactorScore()){
			MessageDialog.openShortMessage(Messages.Tips_configScoreFirst);
			return;
		}
		
		PriceFormulaConfigDialog priceFormulaConfigDialog = new PriceFormulaConfigDialog(getShell(), tenderProject, projectRule, curFactor);
		priceFormulaConfigDialog.open();
		if(priceFormulaConfigDialog.isSave()){
			if(null != curFactor.getId()){
				final int priceFactorCount = factors_grid.getItemCount();
				final Integer priceScorePoint = priceFormulaConfigDialog.getPriceParam().getPriceScorePoint();
				new SyncThread(new SyncThread.Runnable() {
					public void run(){
						savePriceFormlua(priceScorePoint, priceFactorCount);
						Display.getDefault().syncExec(new Runnable(){
							public void run(){
								if(formula_text.isDisposed())return;
								MessageDialog.openShortMessage(Messages.Tips_operateSuccess); 		
								showFormulaInfo();
							} 
						});
					}
				}).start();
			}
		}
		showFormulaInfo();
	}
	
	private void savePriceFormlua(Integer scoreRound, int factorCount) {
		String[] params = new String[]{"id","computerParams"};
		if(null == curFactor.getBidPriceCode() || "".equals(curFactor.getBidPriceCode())){
			if(factorCount == 1){
				params = new String[]{"id","computerParams", "bidPriceCode"};
				curFactor.setBidPriceCode(BidPrice.BID_PRICE_TOTAL_CODE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						refreshFactorInfo(curFactor);							
					} 
				});
			}
		}
		if (!evaluationFactorService.updateAssignProperty(curFactor, params)) {
			MessageDialog.openError(getShell(), Messages.Tips_saveFail);
			return;
		}
		ActionLogUtils.addServerLog(tenderProject.getId(),"修改价格公式", "");
		if(null != scoreRound && scoreRound  > projectRule.getScoreRoundIntVal()){
			projectRule.setScoreRound(scoreRound);
			if(null == projectRuleService){
				projectRuleService = new ProjectRuleService();
			}
			projectRuleService.updateAssignProperty(projectRule, new String[]{"id","scoreRound"});
		}
	}	
	
	
	/**
	 * @Description: 删除价格公式
	 * @author guoyr 
	 */
	private void delFormulaAction(){
		if(isInEvaluationProgress()){return;}
		curFactor.setComputerParams(null);
		if(evaluationFactorService.updateAssignProperty(curFactor, new String[]{"computerParams"})) {
			MessageDialog.openShortMessage(Messages.Tips_deleteSuccess);
			ActionLogUtils.addServerLog(tenderProject.getId(),"删除价格公式", "");
		}
		showFormulaInfo();
	}
	
	/**
	 * @Description: 应用到其他标段
	 * @author chenxw 
	 */
	private void applyToOtherPackAction() {
		if (null == curFactor.getComputerParams()) {
			MessageDialog.openShortMessage(Messages.Tips_configScoreFormulaFirst);
			return;
		}
		new ApplyToOtherTenderPackPriceComputerDialog(getShell(), tenderProject, curFactor).open();
	}
	/**
	 * @Description: 应用到其他指标
	 * @author chenxw 
	 */
	private void applyToOtherFactorAction() {
		if (null == curFactor.getComputerParams()) {
			MessageDialog.openShortMessage(Messages.Tips_configScoreFormulaFirst);
			return;
		}
		if(isInEvaluationProgress()){return;}
		new ApplyToOtherFactorComputerDialog(getShell(), tenderProject, curFactor).open();
	}
	
	/**
	 * @Description: 显示公式说明
	 * @author guoyr
	 */
	private void showFormulaInfo() {
		String formula = null;
		PriceParam priceParam = PriceParam.deserializePriceParam(curFactor.getComputerParams());
		if (priceParam != null) {
			formula = priceParam.getFormula();
		}
		if (StringUtils.isEmpty(formula)) {
			formula_text.setForeground(SWTResourceManager.getColor(255, 0, 0));
			formula_text.setText(Messages.Tips_noScoreFormula);
		} else {
			formula_text.setForeground(SWTResourceManager.getColor(10, 10, 10));
			formula_text.setText(formula);
		}
	}
	/**
	 * @Description: 刷新指标树
	 * @author guoyr
	 * @param factorId 
	 */
	public void refreshFactorTree(final String factorId){
		factors_grid.removeAll();
		new SyncThread(new SyncThread.Runnable() {
			public void run(){
				
				final List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProject.getId(), EvaluationFactorEnum.AUDIT_PRICE);
				Display.getDefault().syncExec(new Runnable(){
					public void run(){
						if(factors_grid.isDisposed())return;
						boolean showApplyToOtherFactor = false;
						if(null != evaluationFactorList && evaluationFactorList.size() > 0){
							if(evaluationFactorList.size() > 1) {
								showApplyToOtherFactor = true;
							}
							for(EvaluationFactor factor : evaluationFactorList){
								if(null != factor.getFactorType() && factor.getFactorType().equals(EvaluationFactorEnum.FACTOR_FLOAT)){
									continue;
								}
								GridItem gridItem = new GridItem(factors_grid, SWT.NONE);
								initChildGridItem(factor, gridItem, factorId);
								if(!showApplyToOtherFactor && null != factor.getChildFactorList() && factor.getChildFactorList().size() > 1) {
									showApplyToOtherFactor = true;
								}
							}
						}
						if(!MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority("APPLY_FORMULA_TO_FACTOR"))){
							WidgetUtils.setControlVisible(applyToOtherFactorBtn, showApplyToOtherFactor);
						}
						if(factors_grid.getSelectionCount() == 0){
							if(factors_grid.getItemCount() > 0){
								factors_grid.select(0);
							}
						}
						selectionFactorAction();
						Rectangle rectangle = factors_grid.getBounds();
						factors_grid.scroll(0, 0, 0, 0, rectangle.width, rectangle.height, true);
						factors_grid.getVerticalBar().setSelection(factors_grid.getSelectionIndex() -5);
						factors_grid.getVerticalBar().notifyListeners(SWT.Selection, null);
					}
				});
			}
		}).start();
		
		
	}
	/**
	 * @Description: 递归实现指标树
	 * @author guoyr
	 * @param factor
	 * @param parentGridItem
	 * @param selectId 
	 */
	private void initChildGridItem(EvaluationFactor factor, GridItem parentGridItem, String selectId){
		if(null != factor.getChildFactorList() && factor.getChildFactorList().size() > 0){
			for(EvaluationFactor childFactor : factor.getChildFactorList()){
				if(null != childFactor.getFactorType() && childFactor.getFactorType().equals(EvaluationFactorEnum.FACTOR_FLOAT)){
					continue;
				}
				GridItem gridItem = new GridItem(parentGridItem, SWT.NONE);
				initChildGridItem(childFactor, gridItem, selectId);
			}
			parentGridItem.setExpanded(true);
			parentGridItem.setImage(0, menuOpenImage);
		}else {
			parentGridItem.setImage(0, menuImage);
		}
		setFactorItemContent(factor, parentGridItem, false);
		parentGridItem.setToolTipText(0, parentGridItem.getText());
		if(null != selectId && selectId.equals(factor.getId())){
			factors_grid.setSelection(new GridItem[]{parentGridItem});
		}
	}
	
	/**
	 * @Description: 选中指标事件
	 * @author guoyr
	 */
	private void selectionFactorAction(){
		
		EvaluationFactor factor = getSelectionEvaluationFactor();
		add_btn.setEnabled(true);
		import_bid_price_factor.setEnabled(true);
		add_sub_btn.setEnabled(false);
		config_bid_price.setEnabled(true);
		if(null != factor){
			add_sub_btn.setEnabled(true);
			if(null != factor.getParentId()){
				add_sub_btn.setEnabled(false);
			}
			del_btn.setEnabled(true);
			// 如果选中的是父级
			if(factors_grid.getSelectionCount() > 0 && factors_grid.getSelection()[0].getItemCount() > 0){
				del_btn.setEnabled(false);
				config_bid_price.setEnabled(false);
			}
		}else {
			del_btn.setEnabled(false);
		}
		refreshFactorTreeBtn();
		refreshFactorInfo(factor);
	}

	/**
	 * @Description: 刷新指标表单
	 * @author guoyr
	 * @param factor
	 */
	private void refreshFactorInfo(EvaluationFactor factor){
		if(factor_name_text.isDisposed()){
			return;
		}
		if(null == factor){
			factor = new EvaluationFactor();
			factor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
		}
		curFactor = factor;
		factor_name_text.forceFocus();
		// 设置当前指标的信息
		factor_name_text.setText(ObjectUtils.getObjString(factor.getFactorName()));
		factor_score_text.setText(null != factor.getFactorScore()?NumberFormat.getInstance().format(factor.getFactorScore()):"");
		min_score_text.setText(null != factor.getFactorMinScore()?NumberFormat.getInstance().format(factor.getFactorMinScore()):"");
		max_score_text.setText(null != factor.getFactorMaxScore() ? NumberFormat.getInstance().format(factor.getFactorMaxScore()):"");
		factor_memo_text.setText(ObjectUtils.getObjString(factor.getMemo()));
		// 默认为非客观项
		if(null == factor.getObjective() || !factor.getObjective().equals(EvaluationFactorEnum.OBJECTIVE_YES)){
			curFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
		}
		
		// 设置有效的权重权重
		if(null != factor.getFactorWeight() && factor.getFactorWeight().doubleValue() > 0 && factor.getFactorWeight().doubleValue() < 100){
			// 如果有权重，则不隐藏
			weight_text.setText(NumberFormat.getInstance().format(factor.getFactorWeight()));
		}else {
			weight_text.setText("");
			curFactor.setFactorWeight(null);
		}
		if(MenuFunction.HIDE.equals(menuFunctionUtils.getAuthority("SUB_WEIGHT"))){
			WidgetUtils.setControlVisible(weightTitle, null == curFactor.getParentId());
			WidgetUtils.setControlVisible(weightComposite, null == curFactor.getParentId());
			
			if(null != curFactor.getParentId() && weight_text.getText().length() > 0){
				WidgetUtils.setControlVisible(weightTitle, true);
				WidgetUtils.setControlVisible(weightComposite, true);
			}
		}
		bid_price_text.setText("");
		del_bid_price.setVisible(false);
		if(null != curFactor.getBidPriceCode()){
			if(null != bidPriceMap.get(curFactor.getBidPriceCode())){
				bid_price_text.setText(bidPriceMap.get(curFactor.getBidPriceCode()));
				del_bid_price.setVisible(true);
			}else if(curFactor.getBidPriceCode().equals(BidPrice.BID_PRICE_TOTAL_CODE)){
				bid_price_text.setText(Messages.BidPriceTotal);
				del_bid_price.setVisible(true);
			}else {
				curFactor.setBidPriceCode(null);
				if(null != curFactor.getId()){
					evaluationFactorService.updateAssignProperty(curFactor, new String[]{"id","bidPriceCode"});
				}
			}
		}
		showFormulaInfo();
		bid_price_text.getParent().layout();
		scroContentComposite.layout();
		scrolledComposite.setMinSize(scroContentComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}
	
	/**
	 * @Description: 添加新指标
	 * @author guoyr
	 */
	private void addFctorAction(){
		if(add_btn.getEnabled()){
			if(isInEvaluationProgress()){return;}
			EvaluationFactor newFactor = new EvaluationFactor();
			newFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
			EvaluationFactor selectFactor = getSelectionEvaluationFactor();
			if(null != selectFactor){
				newFactor.setParentId(selectFactor.getParentId());
			}
			refreshFactorInfo(newFactor);	
			
		}
	}
	
	/**
	 * @Description: 新增下级指标
	 * @author guoyr 
	 */
	private void addSubFctorAction(){
		final EvaluationFactor selectFactor = getSelectionEvaluationFactor();
		if(add_sub_btn.getEnabled() && null != selectFactor){
			if(isInEvaluationProgress()){return;}
			EvaluationFactor newFactor = new EvaluationFactor();
			newFactor.setObjective(EvaluationFactorEnum.OBJECTIVE_NO);
			newFactor.setParentId(selectFactor.getId());
			refreshFactorInfo(newFactor);
		
		}
	}
	/**
	 * @Description: 导入报价或分项报价指标
	 * @author guoyr
	 */
	private void importBidPriceFactorAction(){
		if(import_bid_price_factor.getEnabled()){
			if(isInEvaluationProgress()){return;}
			EvaluationFactor selectFactor = getSelectionEvaluationFactor();
//			if(evaluationFactorService.hasTotalBidPriceFactor(tenderProject.getId(), null != selectFactor?selectFactor.getId():null)){
//				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_hasConfigTotalPrice);
//				return;
//			}
			int count = evaluationFactorService.importBidPriceFactor(tenderProject.getId(), selectFactor);
			refreshFactorTree(null != selectFactor? selectFactor.getId():null);
			if(count > 0) {
				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_pleateConfigPriceFactorInfo, count));
			}
		
		}
	}
	
	/**
	 * @Description: 右键菜单
	 * @author guoyr
	 */
	private void mouseRightClickAction(){

		final EMenu gmenu = new EMenu(getShell());
		gmenu.addMenuItem(upFactorBtn);
		gmenu.addMenuItem(downFactorBtn);
		gmenu.addSeparator();
		gmenu.addMenuItem(import_bid_price_factor);
		gmenu.addMenuItem(add_btn);
		gmenu.addMenuItem(add_sub_btn);
		gmenu.addMenuItem(del_btn);
		if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority("DELETE_ALL"))) {
			gmenu.addMenuItem(Messages.Button_deleteAll, del_btn.getImage(), factors_grid.getItemCount() > 1,  new EMenu.ClickListener() {
				public void click() { 
					delAllEvaluationFactorAction();
				}
			});
		}
		gmenu.open();
	
	}
	
	/**
	 * @Description: 获得选中的指标
	 * @author guoyr
	 * @return
	 */
	private EvaluationFactor getSelectionEvaluationFactor(){
		EvaluationFactor factor = null;
		if(factors_grid.getSelectionCount() > 0){
			factor = (EvaluationFactor)factors_grid.getSelection()[0].getData("evaluationFactor");
		}
		return factor;
	}
		
	/**
	 * @Description: 保存或修改指标
	 * @author guoyr
	 */
	private void saveEvaluationFactorAction(){
		if(!save_btn.getEnabled())return;
		if(factor_name_text.getText().trim().length() == 0){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_required, Messages.FactorName));
			return;
		}
		if(factor_score_text.getText().trim().length() == 0){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_required, Messages.FactorScore));
			return;
		}
		boolean isNew = StringUtils.isEmpty(curFactor.getId());
		if(isNew){
			if(isInEvaluationProgress()){return;}
		}else {
			if(isInEvaluationStepProgress(curFactor.getId())){return;}
		}
		if(null != curFactor.getParentId() && (null == curFactor.getBidPriceCode() || "".equals(curFactor.getBidPriceCode()))){
			if(!MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, Messages.Tips_noScoreFormula, new String[]{Messages.Button_continueSave, Messages.Button_cancel})){
				return;
			}
		}
		boolean changeWeight = false;
		BigDecimal factorWeight = ObjectUtils.getObjBigDecimal(weight_text.getText().trim(), Constants.SCORE_SCALE);
		if(null != factorWeight){
			if(factorWeight.compareTo(BigDecimal.ZERO) == 0){
				factorWeight = null;
			}
			changeWeight = true;
			curFactor.setFactorWeight(factorWeight);
		}else {
			if(null != curFactor.getFactorWeight()){
				changeWeight = true;
			}
			curFactor.setFactorWeight(null);
		}
		curFactor.setContainFactor(null);
		curFactor.setTenderId(tenderProject.getId());
		curFactor.setFactorName(factor_name_text.getText().trim());
		curFactor.setMemo(factor_memo_text.getText().trim());
		curFactor.setAuditType(EvaluationFactorEnum.AUDIT_PRICE);
//		curFactor.setObjective(ObjectUtils.getObjString(WidgetUtils.getRadioVal(kgxParentComposite)));
		curFactor.setFactorScore(ObjectUtils.getObjBigDecimal(factor_score_text.getText().trim(), Constants.SCORE_SCALE));
		curFactor.setFactorMinScore(ObjectUtils.getObjBigDecimal(min_score_text.getText().trim(), Constants.SCORE_SCALE));
		if(null == curFactor.getFactorMinScore()){
			curFactor.setFactorMinScore(BigDecimal.ZERO);
		}
		curFactor.setFactorMaxScore(ObjectUtils.getObjBigDecimal(max_score_text.getText().trim(), Constants.SCORE_SCALE));
		if(null == curFactor.getFactorMaxScore()){
			curFactor.setFactorMaxScore(curFactor.getFactorScore());
		}
		if(!valuateScore(curFactor)){
			return;
		}
		if(curFactor.getSortNo() == 0){
				int sortNo = evaluationFactorService.getMaxEvaluationFactorSortNo(tenderProject.getId(), EvaluationFactorEnum.AUDIT_PRICE, curFactor.getParentId());
			curFactor.setSortNo(sortNo + 1);
		}
		curFactor = evaluationFactorService.saveEvaluationFactor(curFactor, changeWeight);
		
		if(null != curFactor){
			MessageDialog.openShortMessage(Messages.Tips_saveSuccess);
			refreshFactorTree(curFactor.getId());
			if(isNew){
				checkEvaluationStepAfterChangeFactor();
			}
		}else{
			MessageDialog.openError(getShell(), Messages.Dialog_warmTips, Messages.Tips_saveFail);
		}
	}
	
	/**
	 * @Description: 设置指标树的内容
	 * @author guoyr
	 * @param factor
	 * @param gridItem
	 * @param refresh
	 */
	private void setFactorItemContent(EvaluationFactor factor, GridItem gridItem, boolean refresh){
		gridItem.setData("evaluationFactor", factor);
		gridItem.setText(0, factor.getFactorName());
		// 如果是客观项指标
		if(ObjectUtils.equals(factor.getObjective(), EvaluationFactorEnum.OBJECTIVE_YES)){
			// 如果即是客观项指标，又是浮动指标
			if(null != factor.getContainFactor()){
				gridItem.setForeground(0,SWTResourceManager.getColor(SWT.COLOR_DARK_RED));
			}else {
				gridItem.setForeground(0,SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN));
			}
		}else if(null != factor.getContainFactor()){
			// 如果是浮动指标
			gridItem.setForeground(0,SWTResourceManager.getColor(SWT.COLOR_DARK_MAGENTA));
		}else if(refresh){
			gridItem.setForeground(0,null);
		}
	}

	/**
	 * @Description: 删除指标
	 * @author guoyr
	 */
	private void delEvaluationFactorAction(){
		if(!del_btn.getEnabled())return;
		if(isInEvaluationProgress()){return;}
		EvaluationFactor factor = getSelectionEvaluationFactor();
		if(null != factor){
			if(MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteObj, ObjectUtils.getObjString(factor.getFactorName())))){
				int selectIndex = factors_grid.getSelectionIndex();
				String preFactorId = null;
				if(selectIndex > 1){
					EvaluationFactor preFactor = (EvaluationFactor)factors_grid.getItem(selectIndex-1).getData("evaluationFactor");
					if(null != preFactor){
						preFactorId = preFactor.getId();
					}
				}
				int delCount = evaluationFactorService.deleteEvaluationFactor(factor);
				if(delCount > 0){
					refreshFactorTree(preFactorId);
					checkEvaluationStepAfterChangeFactor();
				}
			}
		}
	
	}
	
	/**
	 * @Description: 全部删除
	 * @author guoyr
	 */
	private void delAllEvaluationFactorAction(){
		
		if(isInEvaluationProgress()){return;}
		if(MessageDialog.openConfirm(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_deleteAllObject, Messages.Factor_price))){
			
			new SyncThread(new SyncThread.Runnable() {
				public void run() {
					evaluationFactorService.delEvaluationFactorByType(tenderProject.getId(), EvaluationFactorEnum.AUDIT_PRICE);
					Display.getDefault().syncExec(new Runnable(){
						public void run(){
							if (!factors_grid.isDisposed()) {
								refreshFactorTree(null);
								checkEvaluationStepAfterChangeFactor();
							} 
						} 
					});
				}
			}).start();
		}
	}
	
	/**
	 * @Description: 提示如果已经设置评标步骤，且又新增或删除过指标
	 * @author guoyr
	 * @param opName
	 */
	private void checkEvaluationStepAfterChangeFactor(){
		if(!isFactorCategory){
			if(null == evaluationStepService){
				evaluationStepService = new EvaluationStepService();
//				evaluationStepService = new EvaluationStepService();
//				QueryWrapper queryWrapper = new QueryWrapper(EvaluationStep.class);
//				queryWrapper.setQueryParm("id");
//				queryWrapper.setWhereParam("tenderId", tenderProjectEntity.getId());
				List<String>nodeList = evaluationStepService.getIdByTenderIdCount(tenderProject.getId());
				if(null != nodeList && nodeList.size() > 0){
					isExistEvaluationStep = true;
				}
			}
			if(isExistEvaluationStep){
				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_pleaseResetEvalStep);
			}
		}
	}
	
	/**
	 * @Description: 修改分值
	 * @author guoyr
	 */
	private void modifyFactorScoreAction(ModifyListener listener){
		BigDecimal factorScore = ObjectUtils.getObjBigDecimal(factor_score_text.getText().trim());
		boolean valFlag = true;
		if(null != factorScore){
			if(factorScore.doubleValue() < 0|| factorScore.doubleValue() > 100){
				MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_pleaseEnterValidScore);
				valFlag = false;
			}
		}else {
			valFlag = false;
		}
		if(valFlag){
			min_score_text.setText("0");
			max_score_text.setText(factor_score_text.getText());
			max_score_text.setEditable(true);
			min_score_text.setEditable(true);
		}else {
			factor_score_text.removeModifyListener(listener);
			factor_score_text.setText("");
			min_score_text.setText("");
			max_score_text.setText("");
			max_score_text.setEditable(false);
			min_score_text.setEditable(false);
			factor_score_text.addModifyListener(listener);
		}
	}
	
	/**
	 * @Description: 移动指标
	 * @author guoyr
	 * @param upOrDown upOrDown -1：上移；1：下移
	 */
	private void moveEvaluationFactorAction(int upOrDown){
		if(upOrDown == 1 && !downFactorBtn.getEnabled()){
			return;
		}else if(upOrDown == -1 && !upFactorBtn.getEnabled()){
			return;
		}
		if(factors_grid.getSelectionCount() > 0){
			GridItem selectGridItem = factors_grid.getSelection()[0];
			if(null != selectGridItem.getData("evaluationFactor")){
				EvaluationFactor selectFactor = (EvaluationFactor)selectGridItem.getData("evaluationFactor");
				GridItem selectParentGridItem = selectGridItem.getParentItem();
				GridItem targetItem =  null;
				if(null == selectParentGridItem){
					int index = factors_grid.indexOf(selectGridItem);
					if(upOrDown == 1){
						targetItem = factors_grid.getItem(index + findNextItemIndex(selectGridItem));
					}else{
						targetItem = findRootItem(factors_grid.getItem(index + upOrDown));
					}
				}else{
					int index = selectParentGridItem.indexOf(selectGridItem);
					// 获取目标资源
					targetItem = selectParentGridItem.getItem(index + upOrDown);
				}
				GridItem[] tempGridItems = selectGridItem.getItems();
				boolean tempExpanded = selectGridItem.isExpanded();
				// 获取目标资源
				EvaluationFactor targetFactor = (EvaluationFactor)targetItem.getData("evaluationFactor");
				
				// 将目录资源换到当前资源
				selectGridItem.setText(targetItem.getText());
				selectGridItem.setData("evaluationFactor", targetItem.getData("evaluationFactor"));
				// 递归将目录的下级资源移动到当前资源
				moveSubResourceItem(targetItem.getItems(), targetItem.isExpanded(), selectGridItem);
				
				// 将当前资源换到目录资源
				targetItem.setText(selectFactor.getFactorName());
				targetItem.setData("evaluationFactor", selectFactor);
				// 递归将当前的下级资源移动目标资源
				moveSubResourceItem(tempGridItems, tempExpanded, targetItem);
				factors_grid.setSelection(new GridItem[]{targetItem});
				refreshFactorTreeBtn();
	 			evaluationFactorService.changeEvaluationFactorSortNo(selectFactor, targetFactor);
	 			int targetSortNO = targetFactor.getSortNo();
	 			targetFactor.setSortNo(selectFactor.getSortNo());
	 			selectFactor.setSortNo(targetSortNO);
	 			if(null != curFactor) {
		  	 		curFactor.setSortNo(selectFactor.getSortNo());
		  	 	}
			}
		
		}
	}
	/**
	 * @Description: 获取目标节点
	 * @author guoyr
	 * @param item
	 * @return 
	 */
	private GridItem findRootItem(GridItem item){
		if(null != item.getParentItem()){
			return findRootItem(item.getParentItem());
		}else{
			return item;
		}
	}
	
	/**
	 * @Description: 下移：统计当前节点的子节点个数
	 * @author guoyr
	 * @param gridItem
	 * @param num
	 * @return 
	 */
	private int findNextItemIndex(GridItem gridItem){
		int num = 1;
		GridItem[] gridItems = gridItem.getItems();
		for(GridItem  item : gridItems){
			num += findNextItemIndex(item);
		}
		return num;
	}
	
	
	/**
	 * @Description: 递归移动下级资源
	 * @author guoyr
	 * @param items
	 * @param parentItem
	 */
	private void moveSubResourceItem(GridItem[] items, boolean isExpanded, GridItem parentItem){
		if(items.length > 0){
			for(GridItem item : items){
				GridItem newItem = new GridItem(parentItem, SWT.NONE);
				newItem.setText(0, item.getText());
				newItem.setData("evaluationFactor", item.getData("evaluationFactor"));
				moveSubResourceItem(item.getItems(),item.isExpanded(), newItem);
				item.dispose();
			}
			parentItem.setImage(0, menuOpenImage);
			parentItem.setExpanded(isExpanded);
		}else {
			parentItem.setImage(0, menuImage);
		}
	}

	/**
	 * @Description: 刷新指标树的移动按钮
	 * @author guoyr
	 */
	private void refreshFactorTreeBtn(){
		
		if (factors_grid.getSelectionCount() > 0) {
			GridItem selectGridItem = factors_grid.getSelection()[0];
			GridItem selectParentGridItem = selectGridItem.getParentItem();
			if (null != selectParentGridItem) {
				if(selectParentGridItem.getItemCount() > 0 ){
					int index =selectParentGridItem.indexOf(selectGridItem);
					if(index > 0){
						upFactorBtn.setEnabled(true);
					}else {
						upFactorBtn.setEnabled(false);
					}
					if(index < selectParentGridItem.getItemCount()-1){
						downFactorBtn.setEnabled(true);
					}else {
						downFactorBtn.setEnabled(false);
					}
				}else {
					upFactorBtn.setEnabled(false);
					downFactorBtn.setEnabled(false);
				}
			}else{
				int index = factors_grid.indexOf(selectGridItem);
				if((index + findNextItemIndex(selectGridItem) >= factors_grid.getItemCount())){
					downFactorBtn.setEnabled(false);
				}else{
					downFactorBtn.setEnabled(true);
				}
				if(index -1 < 0){
					upFactorBtn.setEnabled(false);
				}else{
					upFactorBtn.setEnabled(true);
				}
			}
		}else {
			upFactorBtn.setEnabled(false);
			downFactorBtn.setEnabled(false);
		}
	}

	/**
	 * @Description: 验证分值
	 * @author guoyr
	 * @return 
	 */
	private boolean valuateScore(EvaluationFactor evaluationFactor){
		// 验证同级
//		QueryWrapper queryWrapper = new QueryWrapper(EvaluationFactor.class);
//		queryWrapper.setQueryParm("id");
//		queryWrapper.setQueryParm("factorName");
//		queryWrapper.setQueryParm("factorScore");
//		queryWrapper.setQueryParm("factorWeight");
//		queryWrapper.setWhereParam("tenderId", tenderProjectEntity.getId());
//		queryWrapper.setWhereParam("parentId", evaluationFactor.getParentId());
//		if(null == evaluationFactor.getParentId()){
//			queryWrapper.setWhereParam("auditType", new String[]{EvaluationFactorEnum.AUDIT_SCORE, EvaluationFactorEnum.AUDIT_PRICE}, WhereParam.OP_IN);
//		}
		String[] auditType = null;
		if(null == evaluationFactor.getParentId()){
			auditType = new String[]{EvaluationFactorEnum.AUDIT_SCORE, EvaluationFactorEnum.AUDIT_PRICE };
		}
		
 		List<EvaluationFactor> evaluationFactorList = evaluationFactorService.findTenderAndParentId(tenderProject.getId(),evaluationFactor.getParentId(),auditType);
		BigDecimal totalScore = BigDecimal.ZERO;
		if(null != evaluationFactorList){
			for(EvaluationFactor queryEvaluationFactor : evaluationFactorList){
				// 排除当前指标
				if(null != evaluationFactor.getId() && evaluationFactor.getId().equals(queryEvaluationFactor.getId())){
					continue;
				}
				if(null != queryEvaluationFactor.getFactorWeight()){
					totalScore = BigDecimalUtils.add(totalScore, BigDecimalUtils.div(BigDecimalUtils.mul(queryEvaluationFactor.getFactorScore(), queryEvaluationFactor.getFactorWeight()), new BigDecimal(100)));
				}else {
					totalScore = BigDecimalUtils.add(totalScore, queryEvaluationFactor.getFactorScore());
				}
			}
		}
		BigDecimal topFullScore = new BigDecimal(100);
		if(null != evaluationFactor.getParentId()){
			topFullScore = new BigDecimal(100);
 			EvaluationFactor parentEvaluationFactor = evaluationFactorService.findById(evaluationFactor.getParentId());
			topFullScore = parentEvaluationFactor.getFactorScore();
			if(null == topFullScore){
				topFullScore = BigDecimal.ZERO;
			}
			
		}
		// 如果不含该指标的分值时已经超过上级分值，则认为不能设置有效的分值
		if(totalScore.compareTo(topFullScore) >= 0){
//			MessageDialog.openInformation(getShell(), "不能为["+curFactor.getFactorName()+"]设置有效的分值！");
			ConfirmDialog confirmDialog = new ConfirmDialog(getShell(), Messages.Dialog_warmTips, Messages.Tips_overParentLevalScore, null);
			confirmDialog.addButton(Messages.Button_reInput, "01", SWTResourceManager.getColor(77, 163, 19));
//			confirmDialog.addButton(Messages.Button_forceSave, "force", SWTResourceManager.getColor(255, 0, 0));
			confirmDialog.open();
//			if(!"force".equals(confirmDialog.getClickStatus())){
//			}
			factor_score_text.setText("");
			return false;
		}
		if(null != evaluationFactor.getFactorWeight()){
			totalScore = totalScore.add(BigDecimalUtils.div(BigDecimalUtils.mul(evaluationFactor.getFactorScore(), evaluationFactor.getFactorWeight()), new BigDecimal(100)));
		}else {
			totalScore = totalScore.add(evaluationFactor.getFactorScore());
		}
		BigDecimal dValue = totalScore.subtract(topFullScore);
		if(dValue.compareTo(BigDecimal.ZERO) > 0){
			String score_value = "";
			if(null != evaluationFactor.getFactorWeight()){
//				dValue = dValue.multiply(new BigDecimal(100)).divide(evaluationFactor.getFactorWeight(), 2, RoundingMode.UP);
//				score_value = NumberFormat.getInstance().format(evaluationFactor.getFactorScore().subtract(dValue));
//				MessageDialog.openInformation(getShell(), "["+curFactor.getFactorName()+"]分值为"+score_value+"！");
				
//				MessageDialog.openInformation(getShell(), "请为["+curFactor.getFactorName()+"]设置有效的权重！");
				ConfirmDialog confirmDialog = new ConfirmDialog(getShell(), Messages.Dialog_warmTips, Messages.Tips_cantSetValidWeight, null);
				confirmDialog.addButton(Messages.Button_reInput, "01", SWTResourceManager.getColor(77, 163, 19));
//				confirmDialog.addButton(Messages.Button_forceSave, "force", SWTResourceManager.getColor(255, 0, 0));
				if(null == evaluationFactor.getParentId()) {
					confirmDialog.setTips("提示：评标总分超过100分！" );
					confirmDialog.setTipsColor(SWTResourceManager.getColor(255, 0, 0));
				}
				confirmDialog.open();
//				if(!"force".equals(confirmDialog.getClickStatus())){
					weight_text.setText("");
					weight_text.forceFocus();
					return false;
//				}
			}else {
				score_value = NumberFormat.getInstance().format(evaluationFactor.getFactorScore().subtract(dValue));
//				MessageDialog.openInformation(getShell(), "["+curFactor.getFactorName()+"]最大分值只能为"+score_value+"！");
				ConfirmDialog confirmDialog = new ConfirmDialog(getShell(), Messages.Dialog_warmTips, MessageFormat.format(Messages.Tips_canOnlySetScore, score_value), null);
				confirmDialog.addButton(Messages.Button_reInput, "01", SWTResourceManager.getColor(77, 163, 19));
//				confirmDialog.addButton(Messages.Button_forceSave, "force", SWTResourceManager.getColor(255, 0, 0));
				if(null == evaluationFactor.getParentId()) {
					confirmDialog.setTips("提示：评标总分超过100分！" );
					confirmDialog.setTipsColor(SWTResourceManager.getColor(255, 0, 0));
				}
				confirmDialog.open();
//				if(!"force".equals(confirmDialog.getClickStatus())){
					factor_score_text.setText(score_value);
					factor_score_text.forceFocus();
					return false;
//				}
			}
		}
		
		// 验证当前指标的分值设置是否比下级的小
		if(null != evaluationFactor.getId()){
//			queryWrapper.clear();
//			queryWrapper.setQueryParm("id");
//			queryWrapper.setQueryParm("factorScore");
//			queryWrapper.setQueryParm("factorWeight");
//			queryWrapper.setWhereParam("tenderId", tenderProjectEntity.getId());
//			queryWrapper.setWhereParam("parentId", evaluationFactor.getId());
 			evaluationFactorList = evaluationFactorService.findTenderAndParentId(tenderProject.getId(),evaluationFactor.getId(),null);
			totalScore = BigDecimal.ZERO;
			if(null != evaluationFactorList){
				for(EvaluationFactor queryEvaluationFactor : evaluationFactorList){
					if(null != queryEvaluationFactor.getFactorWeight()){
						totalScore = BigDecimalUtils.add(totalScore, BigDecimalUtils.div(BigDecimalUtils.mul(queryEvaluationFactor.getFactorScore(), queryEvaluationFactor.getFactorWeight()), new BigDecimal(100)));
					}else {
						totalScore = BigDecimalUtils.add(totalScore, queryEvaluationFactor.getFactorScore());
					}
				}
			}
			dValue = totalScore.subtract(curFactor.getFactorScore());
			// 如果下级指标的分值超过当前指标的分值
			if(dValue.compareTo(BigDecimal.ZERO) > 0){
				String score_value = NumberFormat.getInstance().format(totalScore);
//				MessageDialog.openWarning(getShell(), "["+curFactor.getFactorName()+"]的分值小于其下级指标的分值之和，最小分值应为"+score_value +" ！");
				ConfirmDialog confirmDialog = new ConfirmDialog(getShell(), Messages.Dialog_warmTips, Messages.Tips_lessThanChildLevalScore, null);
				confirmDialog.addButton(Messages.Button_reInput, "01", SWTResourceManager.getColor(77, 163, 19));
//				confirmDialog.addButton(Messages.Button_forceSave, "force", SWTResourceManager.getColor(255, 0, 0));
				confirmDialog.open();
//				if(!"force".equals(confirmDialog.getClickStatus())){
					factor_score_text.setText(score_value);
					factor_score_text.forceFocus();
					return false;
//				}
			}
		}
		return true;
	}
	
	
	/**
	 * @Description: 验证是否已经进入评分环节
	 * @author guoyr
	 * @return
	 */
	private boolean isInEvaluationProgress(){
		if(isFactorCategory)return false;
		isInEvaluationProgress = tenderProjectService.isInProgress(tenderProject.getId(), EvaluationStepEnum.PRICE);
		if(isInEvaluationProgress){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredPriceEvaluation);
		}
		return isInEvaluationProgress;
	}
	
	
	
	
	/**
	 * @Description: 验证当前评审指标的是不是已经在评审中的评标步骤中
	 * @author guoyr
	 * @param factorId
	 * @return
	 */
	private boolean isInEvaluationStepProgress(String factorId){
		if(isFactorCategory)return false;
		if(null == evaluationStepService){
			evaluationStepService = new EvaluationStepService();
		}
		EvaluationStep evaluatoinNode = evaluationStepService.getEvaluationStepByFactor(tenderProject.getId(), factorId);
		if(null != evaluatoinNode && (ObjectUtils.equals(evaluatoinNode.getStepStatus(), CommonEnum.IN_PROGRESS) || ObjectUtils.equals(evaluatoinNode.getStepStatus(), CommonEnum.COMPLETE))){
			MessageDialog.openInformation(getShell(), Messages.Dialog_warmTips, Messages.Tips_enteredPriceEvaluation);
			return true;
		}else {
			return false;
		}
	}
	
	@Override
	protected void checkSubclass() {
	}
	
}
