package com.gx.obe.management.composite;

import java.text.MessageFormat;
import java.util.Date;
import java.util.List;

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.ImageResolver;
import org.eclipse.swt.core.MessageDialog;
import org.eclipse.swt.core.calendar.CalendarUtil;
import org.eclipse.swt.core.listener.PaintImageListener;
import org.eclipse.swt.core.listener.VerifyMaxEqListener;
import org.eclipse.swt.core.listener.VerifyMinEqListener;
import org.eclipse.swt.core.listener.VerifyNumberListener;
import org.eclipse.swt.core.listener.VerifyRequiredListener;
import org.eclipse.swt.core.utils.ValidateUtils;
import org.eclipse.swt.core.utils.WidgetUtils;
import org.eclipse.swt.core.widgets.BigButton;
import org.eclipse.swt.core.widgets.ESepator;
import org.eclipse.swt.core.widgets.ImageButton;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
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.utils.MenuFunctionUtils;
import com.gx.obe.components.core.enumeration.BidPriceEnum;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.message.Messages;
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.price.Currency;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.BaseDictionaryValueService;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.utils.ActionLogUtils;
import com.swtdesigner.ResourceManager;
import com.swtdesigner.SWTResourceManager;

/** 
 * @Description: 开标评标规则
 * @author guoyr 
 */
public class ProjectRuleComposite extends Composite {
	
//	public EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	
	private BaseDictionaryValueService dictionaryValueService = new BaseDictionaryValueService();
	
	private ProjectRuleService projectRuleService;
	
// 	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectEntity tenderProjectEntity;
//	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private ImageResolver imageResolver = new ImageResolver();
//	private Composite price_utin;
	private Composite view_bid_price;
	private Composite view_bid_price_score;
	private Composite composite_1;
	private Text bid_evaluation_start_time;
	private Label view_bid_price_help;
	private Label view_bid_price_score_help;
	private BigButton save_btn;
//	private Text kvalue_items;
//	private Text rvalue_items;
	private Text scoreRound;
	private Action projectAction;

	private Combo currencyCombo;

	private Combo unitCombo;
	private Menu menu;
	private MenuFunctionUtils menuFunctionUtils = new MenuFunctionUtils();
	
	{
		LogUtils.logClass(ProjectRuleComposite.class);
	}
	
	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ProjectRuleComposite(Composite parent, Action projectAction, int style) {
		super(parent, style);
		this.projectAction= projectAction;
		GridLayout gridLayout = new GridLayout(1, false);
		gridLayout.verticalSpacing = 1;
		gridLayout.horizontalSpacing = 1;
		gridLayout.marginHeight = 1;
		gridLayout.marginWidth = 1;
		setLayout(gridLayout);
		addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent e) {
				imageResolver.disposite();
			}
		});
		
		Composite parentComposite = new Composite(this, SWT.NONE);
		GridLayout gl_parentComposite = new GridLayout(1, false);
		gl_parentComposite.verticalSpacing = 0;
		gl_parentComposite.horizontalSpacing = 0;
		gl_parentComposite.marginHeight = 0;
		gl_parentComposite.marginWidth = 0;
		parentComposite.setLayout(gl_parentComposite);
		parentComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		parentComposite. setBackground(SWTResourceManager.getColor(211, 211, 211));
		
		Composite childComposite = new Composite(parentComposite, SWT.NONE);
		GridLayout gl_childComposite = new GridLayout(1, false);
		gl_childComposite.marginWidth = 0;
		gl_childComposite.verticalSpacing = 0;
		gl_childComposite.horizontalSpacing = 0;
		gl_childComposite.marginHeight = 0;
		gl_parentComposite.marginWidth = 0;
		childComposite.setLayout(gl_childComposite);
		childComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		childComposite.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		ScrolledComposite scrolledComposite = new ScrolledComposite(childComposite, SWT.H_SCROLL | SWT.V_SCROLL);
		scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		scrolledComposite.setExpandHorizontal(true);
		scrolledComposite.setExpandVertical(true);
		
		composite_1 = new Composite(scrolledComposite, SWT.NONE);
		GridLayout gl_composite_1 = new GridLayout(1, false);
		gl_composite_1.verticalSpacing = 0;
		gl_composite_1.marginHeight = 0;
		gl_composite_1.marginWidth = 0;
		composite_1.setLayout(gl_composite_1);
		
		Composite composite_5 = new Composite(composite_1, SWT.NONE);
		GridLayout gl_composite_5 = new GridLayout(1, false);
		gl_composite_5.verticalSpacing = 0;
		composite_5.setLayout(gl_composite_5);
		composite_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		composite_5.setBackground(ResourceManager.getColor(SWT.COLOR_WHITE));
//		composite_5.setBackgroundMode(SWT.INHERIT_FORCE);
		
		ImageButton openingRuleTitle = new ImageButton(composite_5, SWT.NONE);
		openingRuleTitle.setBottomMargin(5);
		openingRuleTitle.setTopMargin(5);
		openingRuleTitle.setLeftMargin(10);
		openingRuleTitle.setRightMargin(10);
		openingRuleTitle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		openingRuleTitle.setBackground(ColorConstants.SKIN_BG);
		openingRuleTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		openingRuleTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		openingRuleTitle.setText(Messages.Title_basicRules);
		
		ESepator openingRuleSep = new ESepator(composite_5, SWT.NONE);
		openingRuleSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		openingRuleSep.setBackground(ColorConstants.SKIN_BG);
		openingRuleSep.setLineWidth(2);
		
		
		Group baseRoleComposite = new Group(composite_1, SWT.NONE);
		baseRoleComposite.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.BOLD));
		GridLayout gl_group = new GridLayout(2, false);
		gl_group.marginLeft = 30;
		gl_group.marginWidth = 0;
		gl_group.marginHeight = 20;
		baseRoleComposite.setLayout(gl_group);
		baseRoleComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		baseRoleComposite.setText(Messages.EvaluationPrice);
		
		CLabel currencyLabel = new CLabel(baseRoleComposite, SWT.NONE);
		currencyLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		currencyLabel.setText(Messages.Currency + "：");
		
		currencyCombo = new Combo(baseRoleComposite, SWT.READ_ONLY);
		currencyCombo.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				currencySelectAction();
			}
		});
		GridData gd_currencyCombo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_currencyCombo.widthHint = 100;
		currencyCombo.setLayoutData(gd_currencyCombo);
		currencyCombo.addVerifyListener(new VerifyRequiredListener(currencyCombo, MessageFormat.format(Messages.Tips_pleaseSelect, Messages.Currency)));
		
		CLabel unitLabel = new CLabel(baseRoleComposite, SWT.NONE);
		unitLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		unitLabel.setText(Messages.Unit + "：");
		
		unitCombo = new Combo(baseRoleComposite, SWT.READ_ONLY);
		GridData gd_combo_1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_combo_1.widthHint = 100;
		unitCombo.setLayoutData(gd_combo_1);
		unitCombo.addVerifyListener(new VerifyRequiredListener(unitCombo, MessageFormat.format(Messages.Tips_pleaseSelect, Messages.Unit)));
		
		
//		price_utin = new Composite(baseRoleComposite, SWT.NONE);
//		GridLayout gl_priceUtinComposite = new GridLayout(3, false);
//		gl_priceUtinComposite.marginHeight = 0;
//		gl_priceUtinComposite.marginWidth = 0;
//		price_utin.setLayout(gl_priceUtinComposite);
//		price_utin.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
//		
//		Button button_2 = new Button(price_utin, SWT.RADIO);
//		button_2.setSelection(true);
//		button_2.setText(Messages.Money_yuan);
//		button_2.setData(CommonEnum.YUAN);
//		
//		Button button_3 = new Button(price_utin, SWT.RADIO);
//		button_3.setText(Messages.Money_wanYuan);
//		button_3.setData(CommonEnum.WAN_YUAN);
//		
//		Button button_4 = new Button(price_utin, SWT.RADIO);
//		button_4.setText("%");
//		button_4.setData(CommonEnum.PRICE_PERENT);
		
		Composite compositeeval = new Composite(composite_1, SWT.NONE);
		GridLayout gl_compositeeval = new GridLayout(1, false);
		gl_compositeeval.verticalSpacing = 0;
		compositeeval.setLayout(gl_compositeeval);
		compositeeval.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		compositeeval.setBackgroundMode(SWT.INHERIT_FORCE);
		
		
		ImageButton evaluationRuleTitle = new ImageButton(compositeeval, SWT.NONE);
		evaluationRuleTitle.setBottomMargin(5);
		evaluationRuleTitle.setTopMargin(5);
		evaluationRuleTitle.setLeftMargin(10);
		evaluationRuleTitle.setRightMargin(10);
		evaluationRuleTitle.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
		evaluationRuleTitle.setBackground(ColorConstants.SKIN_BG);
		evaluationRuleTitle.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		evaluationRuleTitle.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		evaluationRuleTitle.setText(Messages.Title_bidEvaluationRules);
		
		ESepator evaluationRuleSep = new ESepator(compositeeval, SWT.NONE);
		evaluationRuleSep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		evaluationRuleSep.setBackground(ColorConstants.SKIN_BG);
		evaluationRuleSep.setLineWidth(2);
		
		Composite evalRoleComposite = new Composite(composite_1, SWT.NONE);
		evalRoleComposite.setFont(SWTResourceManager.getFont("微软雅黑", 11, SWT.BOLD));
		GridLayout gl_group_1 = new GridLayout(4, false);
		gl_group_1.verticalSpacing = 20;
		gl_group_1.marginLeft = 20;
		gl_group_1.marginHeight = 8;
		gl_group_1.marginWidth = 0;
		evalRoleComposite.setLayout(gl_group_1);
		evalRoleComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
		
		CLabel label_5 = new CLabel(evalRoleComposite, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_5.setText(Messages.EvaluationTime +"：");
		
		bid_evaluation_start_time = new Text(evalRoleComposite, SWT.BORDER | SWT.READ_ONLY);
		GridData gd_bidEvaluationStartTimeText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
		gd_bidEvaluationStartTimeText.widthHint = 175;
		bid_evaluation_start_time.setLayoutData(gd_bidEvaluationStartTimeText);
		bid_evaluation_start_time.addPaintListener(new PaintImageListener(imageResolver.loadImage(IconsActivator.PLUGIN_ID, "icons/data.png")));
		bid_evaluation_start_time.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				CalendarUtil.getDates(bid_evaluation_start_time,null != bid_evaluation_start_time.getData("date")?(Date)bid_evaluation_start_time.getData("date"):null,tenderProjectRuleEntity.getBidOpeningStartTime(),null, "yyyy-MM-dd HH:mm:00");
			}
		});
		
		new Label(evalRoleComposite, SWT.NONE);
		new Label(evalRoleComposite, SWT.NONE);
		
		Label label = new Label(evalRoleComposite, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label.setText(Messages.ScoreDecimalDigits + "：");
		
		Composite composite = new Composite(evalRoleComposite, SWT.NONE);
		composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
		composite.setLayout(new GridLayout(3, false));
		
		Label label_round = new Label(composite, SWT.NONE);
		label_round.setText(Messages.AppendTips_scoreDecimalDigits_1);
		
		scoreRound = new Text(composite, SWT.BORDER | SWT.CENTER);
		GridData gd_scoreRound = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
		gd_scoreRound.widthHint = 30;
		scoreRound.setLayoutData(gd_scoreRound);
		scoreRound.addVerifyListener(new VerifyNumberListener(MessageFormat.format(Messages.Tips_pleaseEnterTheCorrect, Messages.ScoreDecimalDigits)));
		scoreRound.addVerifyListener(new VerifyMaxEqListener(5, MessageFormat.format(Messages.Tips_scoreDecimalDigitsMax, 5)));
		scoreRound.addVerifyListener(new VerifyMinEqListener(0, MessageFormat.format(Messages.Tips_pleaseEnterTheCorrect, Messages.ScoreDecimalDigits)));
		
		Label label_2 = new Label(composite, SWT.NONE);
		label_2.setText(Messages.AppendTips_scoreDecimalDigits_2);
		new Label(evalRoleComposite, SWT.NONE);
		new Label(evalRoleComposite, SWT.NONE);
		
		CLabel label_13 = new CLabel(evalRoleComposite, SWT.NONE);
		label_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_13.setText(Messages.BidPrice + "：");
		
		view_bid_price = new Composite(evalRoleComposite, SWT.NONE);
		GridLayout gl_viewBidPriceComposite = new GridLayout(3, false);
		gl_viewBidPriceComposite.marginHeight = 0;
		gl_viewBidPriceComposite.marginWidth = 0;
		view_bid_price.setLayout(gl_viewBidPriceComposite);
		view_bid_price.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		
		Button button_14 = new Button(view_bid_price, SWT.RADIO);
		button_14.setSelection(true);
		button_14.setText(Messages.Button_allowView);
		button_14.setData(CommonEnum.YES);
		
		Button button_15 = new Button(view_bid_price, SWT.RADIO);
		button_15.setText(Messages.Button_notAllowView);
		button_15.setData(CommonEnum.NO);
		
		view_bid_price_help = new Label(view_bid_price, SWT.WRAP);
		view_bid_price_help.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		view_bid_price_help.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		view_bid_price_help.setText(Messages.Tips_allowViewBidPrice);
		
		CLabel label_14 = new CLabel(evalRoleComposite, SWT.NONE);
		label_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		label_14.setText(Messages.BidPriceScore + "：");
		
		view_bid_price_score = new Composite(evalRoleComposite, SWT.NONE);
		view_bid_price_score.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
		GridLayout gl_viewPriceScoreComposite = new GridLayout(3, false);
		gl_viewPriceScoreComposite.marginHeight = 0;
		gl_viewPriceScoreComposite.marginWidth = 0;
		view_bid_price_score.setLayout(gl_viewPriceScoreComposite);
		
		Button button6 = new Button(view_bid_price_score, SWT.RADIO);
		button6.setText(Messages.Button_allowView);
		button6.setData(CommonEnum.YES);
		
		Button price_view_no = new Button(view_bid_price_score, SWT.RADIO);
		price_view_no.setSelection(true);
		price_view_no.setText(Messages.Button_notAllowView);
		price_view_no.setData(CommonEnum.NO);
		
		view_bid_price_score_help = new Label(view_bid_price_score, SWT.WRAP);
		view_bid_price_score_help.setForeground(ColorConstants.NOTE_TIPS_COLOR);
		view_bid_price_score_help.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		view_bid_price_score_help.setText(Messages.Tips_allowViewBidPriceScore);
		
		Composite composite_2 = new Composite(childComposite, SWT.NONE);
		GridLayout gl_composite_2 = new GridLayout(1, false);
		gl_composite_2.marginHeight = 4;
		composite_2.setLayout(gl_composite_2);
		composite_2.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, false, 1, 1));
		
		save_btn = new BigButton(composite_2, SWT.NONE);
		save_btn.addMouseListener(new MouseAdapter() {
			public void mouseUp(MouseEvent e) {
				saveProjectRuleAction();
			}
		});
		save_btn.setFont(SWTResourceManager.getFont("微软雅黑", 10, SWT.BOLD));
		save_btn.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		save_btn.setText(Messages.Button_save);
		
		scrolledComposite.setContent(composite_1);
		scrolledComposite.setMinSize(composite_1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		init();
	}

	/**
	 * @Description: 初始化
	 * @author guoyr 
	 */
	private void init(){
		projectRuleService = new ProjectRuleService();
		tenderProjectEntity = projectAction.getTenderProject();
		tenderProjectRuleEntity = projectAction.refreshTenderProjectRule();
		// 默认以按所有评标专家的自由进度进行控制
		if(StringUtils.isEmpty(tenderProjectRuleEntity.getOrderReview())){
			tenderProjectRuleEntity.setOrderReview(EvaluationStepEnum.ORDER_REVIEW_NO);
		}
		tenderProjectEntity.setProjectRule(tenderProjectRuleEntity);
		menuFunctionUtils.initFunctionAuthority(menu);
		initCurrencyCombo();
		
		refreshProjectRuleForm();
	}
	
	/**
	 * @Description: 初始化币种下拉框
	 * @author chenxw 
	 */
	private void initCurrencyCombo() {
		List<Currency> currencyList = dictionaryValueService.getCurrencyDictionaryList();
		int index = 0;
		for (Currency currency : currencyList) {
			if(MenuFunction.SHOW.equals(menuFunctionUtils.getAuthority(currency.getCurrencyCode()))){
				currencyCombo.setData(index + "", currency.getCurrencyCode());
				currencyCombo.add(currency.getCurrencyName(), index);
				currencyCombo.setData(index + "currency", currency);
				if(currency.getCurrencyCode().equals(tenderProjectRuleEntity.getEvalCurrencyCode()) || currency.getCurrencyName().equals(tenderProjectRuleEntity.getEvalCurrencyName())){
					currencyCombo.select(index);
				}
				index++;
			}
		}
		if(currencyCombo.getSelectionIndex() < 0){
			WidgetUtils.setComboSelection(currencyCombo, BidPriceEnum.CNY_CODE);
		}
		if(currencyCombo.getItemCount() == 0){
			Currency currency = new Currency();
			currency.setCurrencyCode(BidPriceEnum.CNY_CODE);
			currency.setCurrencyName(BidPriceEnum.CNY_NAME);
			currency.addPriceUnit(CommonEnum.getPriceUintCN(CommonEnum.YUAN));
			currency.addPriceUnit(CommonEnum.getPriceUintCN(CommonEnum.WAN_YUAN));
			currencyCombo.setData(index + "", currency.getCurrencyCode());
			currencyCombo.add(currency.getCurrencyName(), index);
			currencyCombo.setData(index + "currency", currency);
			currencyCombo.select(0);
		}
		currencySelectAction();
	}
	
	/**
	 * @Description: 币种下拉框选择事件
	 * @author chenxw 
	 */
	protected void currencySelectAction() {
		unitCombo.removeAll();
		Currency currency  = (Currency) currencyCombo.getData(currencyCombo.getSelectionIndex()+"currency");
		if (null == currency) {
			return;
		}
		List<String> unitList = currency.getPriceUnitList();
		for(int i = 0; i < unitList.size(); i++){
			String unit = unitList.get(i);
			unitCombo.add(unit, i);
			unitCombo.setData(i+"", unit);
		}
		WidgetUtils.setComboSelection(unitCombo, tenderProjectRuleEntity.getEvalPriceUnit());
		if(unitCombo.getSelectionIndex() < 0){
			unitCombo.select(0);
		}
	}
	
	/**
	 * @Description: 刷新表单
	 * @author guoyr 
	 */
	private void refreshProjectRuleForm(){
		CalendarUtil.setDate(bid_evaluation_start_time, tenderProjectRuleEntity.getBidEvaluationStartTime(), null);
		
//		WidgetUtils.setRadioChecked(price_utin, null != tenderProjectRuleEntity.getPriceUnitType()?tenderProjectRuleEntity.getPriceUnitType():CommonEnum.YUAN);
		WidgetUtils.setRadioChecked(view_bid_price, StringUtils.isEmpty(tenderProjectRuleEntity.getViewBidPrice())?PropertiesUtils.getProperty(ConfigConstants.VIEW_BID_PRICE, CommonEnum.YES):tenderProjectRuleEntity.getViewBidPrice());
		WidgetUtils.setRadioChecked(view_bid_price_score, StringUtils.isEmpty(tenderProjectRuleEntity.getViewPriceScore())?PropertiesUtils.getProperty(ConfigConstants.VIEW_PRICE_SCORE, CommonEnum.YES):tenderProjectRuleEntity.getViewPriceScore());
//		kvalue_items.setText(ObjectUtils.getObjString(tenderProjectRuleEntity.getKItems()));
//		rvalue_items.setText(ObjectUtils.getObjString(tenderProjectRuleEntity.getRItems()));
		int scoreRoundCount = tenderProjectRuleEntity.getScoreRoundIntVal();
		if(scoreRoundCount > 0){
			scoreRound.setText(scoreRoundCount+"");
		}else {
			scoreRound.setText("2");
		}
		if(null == tenderProjectRuleEntity.getScoreRound() || tenderProjectRuleEntity.getScoreRound() == 0) {
			scoreRound.setForeground(ColorConstants.FONT_RED_COLOR);
		}
	}
	
	/**
	 * @Description: 保存
	 * @author guoyr 
	 */
	private void saveProjectRuleAction(){
		if(!save_btn.getEnabled())return;
		if(!ValidateUtils.checkInput(composite_1)){
			return;
		}
//		if(!valModulus(kvalue_items, "K"))return;
//		if(!valModulus(rvalue_items, "R"))return;
		
		getProjectRule();
		
		save_btn.setEnabled(false);
//		tenderProjectRuleEntity = 
//		 projectRuleService.saveOrUpdateReturn(tenderProjectRuleEntity);
		String[] properties = new String[] {"scoreRound", "viewPriceScore", "viewBidPrice", "evalPriceUnit", "evalCurrencyCode", "evalCurrencyName", "bidEvaluationStartTime"};
		boolean isUpdate = projectRuleService.updateAssignProperty(tenderProjectRuleEntity, properties);
		ActionLogUtils.addServerLog(tenderProjectRuleEntity.getTenderId(), "更新项目评标规则", "", "");
		
//		boolean isUpdate = projectRuleService.updataRule(tenderProjectRuleEntity);
//		if(null == tenderProjectRuleEntity){
		if(!isUpdate){
			MessageDialog.openError(getShell(), Messages.Dialog_warmTips, Messages.Tips_saveFail);
			return;
		}
		MessageDialog.openShortMessage(Messages.Tips_saveSuccess);
		save_btn.setEnabled(true);
	}
	
//	/**
//	 * @Description: 验证K、R值的效性
//	 * @author guoyr
//	 * @param valueItemsText
//	 * @param K
//	 * @return 
//	 */
//	private boolean valModulus(Text valueItemsText, String K){
//		String kValues = valueItemsText.getText().trim();
//		if(!"".equals(kValues)){
//			kValues = kValues.replaceAll("，", ",");
//			boolean valKValue = true;
//			for(String k : kValues.split(TenderProjectEnum.MODULUS_SEP)){
//				if(!"".equals(k)){
//					try {
//						float kValue = Float.parseFloat(k);
//						if(kValue > 1 || kValue < 0){
//							valKValue = false;
//						}
//					} catch (NumberFormatException e) {
//						valKValue = false;
//					}finally{
//						if(!valKValue){
//							MessageDialog.openWarning(getShell(), "请输入有效的"+K+"候选值！");
//							return false;
//						}
//					}
//				}
//			}
//			valueItemsText.setText(kValues);
//		}
//		return true;
//	}
	
	/**
	 * @Description: 封装项目规则
	 * @author guoyr 
	 */
	private void getProjectRule(){
		tenderProjectRuleEntity.setBidEvaluationStartTime((Date)bid_evaluation_start_time.getData("date"));
		
		Currency currency = (Currency) currencyCombo.getData(currencyCombo.getSelectionIndex() + "currency");
		if (null != currency) {
			tenderProjectRuleEntity.setEvalCurrencyCode(currency.getCurrencyCode());
			tenderProjectRuleEntity.setEvalCurrencyName(currency.getCurrencyName());
		}
		tenderProjectRuleEntity.setEvalPriceUnit((String) WidgetUtils.getComboSelection(unitCombo));
		
//		tenderProjectRuleEntity.setPriceUintType(ObjectUtils.getObjString(WidgetUtils.getRadioVal(price_utin)));
		tenderProjectRuleEntity.setViewBidPrice(ObjectUtils.getObjString(WidgetUtils.getRadioVal(view_bid_price)));
		if(StringUtils.isEmpty(tenderProjectRuleEntity.getViewBidPrice())){
			tenderProjectRuleEntity.setViewBidPrice(PropertiesUtils.getProperty(ConfigConstants.VIEW_BID_PRICE, CommonEnum.YES));
		}
		tenderProjectRuleEntity.setViewPriceScore(ObjectUtils.getObjString(WidgetUtils.getRadioVal(view_bid_price_score)));
		if(StringUtils.isEmpty(tenderProjectRuleEntity.getViewPriceScore())){
			tenderProjectRuleEntity.setViewPriceScore(PropertiesUtils.getProperty(ConfigConstants.VIEW_PRICE_SCORE, CommonEnum.YES));
		}
//		tenderProjectRuleEntity.setKItems(kvalue_items.getText().trim());
//		tenderProjectRuleEntity.setRItems(rvalue_items.getText().trim());
		int scoreRoundValue = ObjectUtils.getIntValue(scoreRound.getText().trim(), 2);
		tenderProjectRuleEntity.setScoreRound(scoreRoundValue);
	}
	
	@Override
	protected void checkSubclass() {
	}
}
