XiangTan_DM/DM_Weight/ViewModels/DatetimeDialogViewModel.cs

74 lines
1.9 KiB
C#

using DM_Weight.Models;
using DM_Weight.msg;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.ViewModels
{
internal class DatetimeDialogViewModel : BindableBase, IDialogAware
{
public string Title => throw new NotImplementedException();
public event Action<IDialogResult> RequestClose;
private DateTime? _date = new DateTime();
public DateTime? Date
{
get => _date;
set
{
SetProperty(ref _date, value);
}
}
private DateTime? _time = new DateTime();
public DateTime? Time
{
get => _time;
set
{
SetProperty(ref _time, value);
}
}
public bool CanCloseDialog()
{
return true;
}
public void OnDialogClosed()
{
}
string typeS;
public void OnDialogOpened(IDialogParameters parameters)
{
DateTime o = parameters.GetValue<DateTime>("DateTime");
typeS = parameters.GetValue<string>("Type");
Date = o;
Time = o;
}
public DelegateCommand CloseAction
{
get => new DelegateCommand(() =>
{
var datetime=new DateTime(Date?.Year ?? DateTime.Now.Year, Date?.Month ?? DateTime.Now.Month, Date?.Day ?? DateTime.Now.Day,
Time?.Hour ?? DateTime.Now.Hour, Time?.Minute ?? DateTime.Now.Minute, Time?.Second ?? DateTime.Now.Second);
var result = new DialogResult(ButtonResult.OK, new DialogParameters
{
{ "DateTime", datetime },
{"Type",typeS }
});
RequestClose?.Invoke(result);
});
}
}
}