97 lines
3.1 KiB
C#
97 lines
3.1 KiB
C#
|
|
using Prism.Commands;
|
|||
|
|
using Prism.Mvvm;
|
|||
|
|
using Prism.Regions;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using System.Windows;
|
|||
|
|
using Unity;
|
|||
|
|
|
|||
|
|
namespace Cowain.Bake.Common
|
|||
|
|
{
|
|||
|
|
public abstract class ViewModelBase : BindableBase
|
|||
|
|
{
|
|||
|
|
// * 未保存
|
|||
|
|
public string PageTitle { get; set; } = "标签标题";
|
|||
|
|
public bool IsCanClose { get; set; } = true;
|
|||
|
|
|
|||
|
|
private string NavUri { get; set; }
|
|||
|
|
|
|||
|
|
private DateTime date = DateTime.Now.Date;
|
|||
|
|
public DateTime Date
|
|||
|
|
{
|
|||
|
|
get { return date; }
|
|||
|
|
set { SetProperty(ref date, value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private DateTime _startTime = DateTime.Now;
|
|||
|
|
public DateTime StartTime
|
|||
|
|
{
|
|||
|
|
get { return _startTime; }
|
|||
|
|
set { SetProperty(ref _startTime, DateTime.Parse(Date.ToString("yyyy-MM-dd") + " " + value.ToString("HH:mm:ss"))); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private DateTime _endTime = DateTime.Now;
|
|||
|
|
public DateTime EndTime
|
|||
|
|
{
|
|||
|
|
get { return _endTime; }
|
|||
|
|
set { SetProperty(ref _endTime, DateTime.Parse(Date.ToString("yyyy-MM-dd") + " " + value.ToString("HH:mm:ss"))); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private DateTime _startDateTime = DateTime.Now;
|
|||
|
|
public DateTime StartDateTime
|
|||
|
|
{
|
|||
|
|
get { return _startDateTime; }
|
|||
|
|
set { SetProperty(ref _startDateTime, value); }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private DateTime _endDateTime = DateTime.Now;
|
|||
|
|
public DateTime EndDateTime
|
|||
|
|
{
|
|||
|
|
get { return _endDateTime; }
|
|||
|
|
set { SetProperty(ref _endDateTime, value); }
|
|||
|
|
}
|
|||
|
|
//条码
|
|||
|
|
private string code = string.Empty;
|
|||
|
|
public string Code
|
|||
|
|
{
|
|||
|
|
get { return code; }
|
|||
|
|
set { SetProperty(ref code, value); }
|
|||
|
|
}
|
|||
|
|
public DelegateCommand CloseCommand
|
|||
|
|
{
|
|||
|
|
get => new DelegateCommand(() =>
|
|||
|
|
{
|
|||
|
|
// 关闭操作
|
|||
|
|
// 根据URI获取对应的已注册对象名称
|
|||
|
|
var obj = _unityContainer.Registrations.FirstOrDefault(v => v.Name == NavUri);
|
|||
|
|
string name = obj.MappedToType.Name;
|
|||
|
|
// 根据对象名称再从Region的Views里面找到对象
|
|||
|
|
if (!string.IsNullOrEmpty(name))
|
|||
|
|
{
|
|||
|
|
var region = _regionManager.Regions["MainContentRegion"];
|
|||
|
|
var view = region.Views.FirstOrDefault(v => v.GetType().Name == name);
|
|||
|
|
// 把这个对象从Region的Views里移除
|
|||
|
|
if (view != null)
|
|||
|
|
region.Remove(view);
|
|||
|
|
}
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public DelegateCommand RefreshCommand { get => new DelegateCommand(Refresh); }
|
|||
|
|
|
|||
|
|
protected IUnityContainer _unityContainer;
|
|||
|
|
protected IRegionManager _regionManager;
|
|||
|
|
public ViewModelBase(IUnityContainer unityContainer, IRegionManager regionManager)
|
|||
|
|
{
|
|||
|
|
_unityContainer = unityContainer;
|
|||
|
|
_regionManager = regionManager;
|
|||
|
|
Refresh();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public virtual void Refresh() { }
|
|||
|
|
}
|
|||
|
|
}
|