
///////////////////////////////////////////////////////////////////////////////
//文件名称: VmPolicyEnsure.cs
//文件描述: VmPolicyEnsure.cs
//创 建 者: xls
//创建日期: 2018/9/17 23:40:48
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Com.FirmLib.UI.BllCommon;
using Com.FirmLib.UI.Common;
using Com.FirmLib.UI.Insuer.Model;
using FWindSoft.MVVM;
using FWindSoft.Wpf;
using FWindSoft.Wpf.Common;

namespace Com.FirmLib.UI.Insuer
{
    public class VmPolicyEnsure : BaseViewModel
    {
        public VmPolicyEnsure()
        {
            Init();
        }

        private void Init()
        {
            this.EditType = EditType.Update;
            CorrectEndDate = DateTimeManager.ConvertDateTime(DateTime.Now);
        }       
        public void Init(LoadParameter parameter)
        {
            PolicyUpdateContext context = parameter.Parameter as PolicyUpdateContext;
            if (context == null)
                return;
            Context = context;
        }
        #region 属性相关
        private PolicyUpdateContext Context { get; set; }
        private EditType m_EditType;
        /// <summary>
        /// 编辑类型\修改还是更正
        /// </summary>
        public EditType EditType
        {
            get { return this.m_EditType; }
            set
            {
                this.m_EditType = value;
                RaisePropertyChanged(nameof(this.EditType));
            }
        }

        private string m_CorrectDate;
        /// <summary>
        /// 改正日期
        /// </summary>
        public string CorrectEndDate
        {
            get { return this.m_CorrectDate; }
            set
            {
                this.m_CorrectDate = value;
                RaisePropertyChanged(() => this.CorrectEndDate);
            }
        }
        #endregion

        #region 命令相关

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="parameter"></param>
        [Command]
        public void EnsureCommand(object parameter)
        {
            try
            {
                Window window = parameter as Window;
                if (window == null)
                {
                    return;
                }
                PolicyUpdateContext context = Context;
                context.CanExecute = true;
                context.EditType = this.EditType;
                context.EffectiveTime = this.CorrectEndDate;
                window.SetRealResult(context);
                window.DialogResult = true;
            }
            catch (Exception ex)
            {

                MessageTipEx.Show(ex);
            }
        }
        public bool CanEnsureCommand(object parameter)
        {
            return true;
        }

        #endregion
    }

}
