using OrpaonEMS.App.Com;
using OrpaonEMS.App.Models;
using OrpaonEMS.App.Services;
using OrpaonEMS.Core;
using Prism.Commands;
using Prism.Services.Dialogs;
using Syncfusion.UI.Xaml.Controls.DataPager;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace OrpaonEMS.App.ViewModels
{
public class BmsViewModel : NavigationViewModel
{
///
/// 弹窗服务
///
public IDialogService DialogService { get; }
public BmsViewModel(IDialogService dialogService, BmsDataService bmsDataService)
{
DialogService = dialogService;
//分页的默认值
this.PageIndex = 0;
this.PageSize = 20;
NumericButtonCount = 5;
//分页的默认值
this.ConfigPageIndex = 0;
this.ConfigPageSize = 20;
ConfigNumericButtonCount = 5;
this.bmsDataService = bmsDataService;
ListBmsRoCell = bmsDataService.ListBmsRoCell;
ListBmsRwCell= bmsDataService.ListBmsRwCell.ToList();
ListBmsPageRwCell = bmsDataService.ListBmsRwCell;
//分页数据PageSize下拉框
PageSizeComboBoxList = new List() {
new ComboBoxModel(){ Key="1",Text="20"},
new ComboBoxModel(){ Key="2",Text="40"},
new ComboBoxModel(){ Key="3",Text="60"}
};
//分页数据PageSize下拉框
ConfigPageSizeComboBoxList = new List() {
new ComboBoxModel(){ Key="1",Text="20"},
new ComboBoxModel(){ Key="2",Text="40"},
new ComboBoxModel(){ Key="3",Text="60"}
};
this.TotalCount = (int)ListBmsRoCell.Count;
this.PageCount = ((int)Math.Ceiling(this.TotalCount * 1.0 / this.PageSize));
this.ConfigTotalCount = (int)ListBmsRwCell.Count;
this.ConfigPageCount = ((int)Math.Ceiling(this.ConfigTotalCount * 1.0 / this.ConfigPageSize));
LoadGridData(PageIndex, PageSize);
ConfigLoadGridData(ConfigPageIndex, ConfigPageSize);
}
///
/// BMS只读实时数据集合
///
public List ListBmsRoCell { get; set; }
///
/// BMS只读实时数据集合
///
public ObservableCollection ListBMSPageRoCell { get; set; } = new ObservableCollection();
///
/// BMS读写实时数据集合
///
public List ListBmsRwCell { get; set; }
///
/// BMS读写实时数据集合
///
public ObservableCollection ListBmsPageRwCell { get; set; }
///
/// Bms数据服务
///
public BmsDataService bmsDataService { get; set; }
#region 配置值弹窗
private BmsRwCell _BmsSelectedConfig;
///
/// 当前选中的
///
public BmsRwCell BmsSelectedConfig
{
get { return _BmsSelectedConfig; }
set { _BmsSelectedConfig = value; RaisePropertyChanged(); }
}
private DelegateCommand _ConfigBmsSelectedBtnCmd;
///
/// 刷新数据命令
///
public DelegateCommand ConfigBmsSelectedBtnCmd
{
set
{
_ConfigBmsSelectedBtnCmd = value;
}
get
{
if (_ConfigBmsSelectedBtnCmd == null)
{
_ConfigBmsSelectedBtnCmd = new DelegateCommand((par) => ConfigBmsSelectedBtnCmdMethod(par));
}
return _ConfigBmsSelectedBtnCmd;
}
}
private void ConfigBmsSelectedBtnCmdMethod(BmsRwCell par)
{
if (par != null)
{
BmsSelectedConfig = par;
//弹窗
DialogService.ShowDialog("DialogBmsConfigView", new DialogParameters() { { "Model", BmsSelectedConfig } }, (par) =>
{
if (par.Result == ButtonResult.OK)
{
//程序名称
var ReturnValue = par.Parameters.GetValue("Model");
//查询是否重复
var IsSuccess= bmsDataService.WriteValue(ReturnValue);
if (!IsSuccess)
{
MessageBox.Show("写入失败!", "提示", MessageBoxButton.OK, MessageBoxImage.Hand);
}
}
else if (par.Result == ButtonResult.Cancel)
{
//取消
}
});
}
}
private DelegateCommand