
///////////////////////////////////////////////////////////////////////////////
//文件名称: VmMaintainerSaveEnsure.cs
//文件描述: VmMaintainerSaveEnsure.cs
//创 建 者: xls
//创建日期: 2018/9/18 17:09:45
//版 本 号：1.0.0.0
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
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.Common.Model;
using Com.FirmLib.UI.Insuer.Model;
using FWindSoft.MVVM;
using FWindSoft.Wpf;
using FWindSoft.Wpf.Common;

namespace Com.FirmLib.UI.Maintainer
{
    public class VmMaintainerSaveEnsure : BaseViewModel
    {
        public VmMaintainerSaveEnsure()
        {
            Init();
        }

        private void Init()
        {
            this.EditType = EditType.Update;
            CorrectEndDate = DateTimeManager.ConvertDateTime(DateTime.Now);
        }
        public void Init(LoadParameter parameter)
        {
            EditTypeSelectorContext context = parameter.Parameter as EditTypeSelectorContext;
            if (context == null)
                return;
            this.EditType = context.EditType;
        }
        #region 属性相关

        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);
            }
        }



        private ObservableCollection<AssetShowItem> m_ChangedAssetItems;
        /// <summary>
        /// 信息点发生变化的资产
        /// </summary>
        public ObservableCollection<AssetShowItem> ChangedAssetItems
        {
            get { return this.m_ChangedAssetItems; }
            set
            {
                this.m_ChangedAssetItems = value;
                RaisePropertyChanged(nameof(this.ChangedAssetItems));
            }
        }
        #endregion

        #region 命令相关

        /// <summary>
        /// 确认完成
        /// </summary>
        /// <param name="parameter"></param>
        [Command]
        public void EnsureCommand(object parameter)
        {
            try
            {
                Window window = parameter as Window;
                if (window != null)
                {
                    EditTypeSelectorContext context =new EditTypeSelectorContext();
                    context.EditType = this.EditType;
                    context.CorrectEndDate = this.CorrectEndDate;
                    context.ChangedItems = ChangedAssetItems?.ToList() ?? new List<AssetShowItem>();

                    //设置需要处理的值
                    window.SetRealResult<EditTypeSelectorContext>(context);


                    window.DialogResult = true;
                }
            }
            catch (Exception ex)
            {

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

        #endregion
    }
}
