提交了仪表的模型

This commit is contained in:
2024-07-28 22:59:11 +08:00
parent c9f4e88e04
commit a76546ebe6
59 changed files with 3273 additions and 586 deletions

View File

@@ -0,0 +1,387 @@
using AutoMapper;
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.Dtos;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.Services;
using Microsoft.Extensions.Logging;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Prism.Events;
using Prism.Services.Dialogs;
using Syncfusion.Windows.Shared;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace CapMachine.Wpf.ViewModels
{
public class ActionLogViewModel : NavigationViewModel
{
/// <summary>
/// 实例化
/// </summary>
/// <param name="dialogService"></param>
/// <param name="freeSql"></param>
/// <param name="eventAggregator"></param>
public ActionLogViewModel(IDialogService dialogService, IFreeSql freeSql, IEventAggregator eventAggregator, IMapper mapper, ILogService logger)
{
DialogService = dialogService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
Mapper = mapper;
Logger = logger;
CategoryComboBoxList = new List<ComboBoxModel>()
{
new ComboBoxModel(){Key="0",Text="系统" },
new ComboBoxModel(){Key="1",Text="程序步骤" },
new ComboBoxModel(){Key="2",Text="报警" },
};
}
private string CurrentName = "埋塞敲入螺旋钉安装";
private string CurrentTemplate = "BurPlugInstallTemplate.xlsx";
public IDialogService DialogService { get; }
public IFreeSql FreeSql { get; }
public IEventAggregator EventAggregator { get; }
public IMapper Mapper { get; }
public ILogService Logger { get; }
//ActionLog
private List<ComboBoxModel> _CategoryComboBoxList;
/// <summary>
/// 分类下拉框列表
/// </summary>
public List<ComboBoxModel> CategoryComboBoxList
{
get { return _CategoryComboBoxList; }
set { _CategoryComboBoxList = value; RaisePropertyChanged(); }
}
private string _SearchCategory;
/// <summary>
/// 搜索条件-分类
/// </summary>
public string SearchCategory
{
get
{
return _SearchCategory;
}
set
{
_SearchCategory = value;
RaisePropertyChanged();
}
}
/// <summary>
/// 列表集合
/// </summary>
private ObservableCollection<ActionLogDto> _ListModelDto=new ObservableCollection<ActionLogDto>();
/// <summary>
/// 列表集合
/// </summary>
public ObservableCollection<ActionLogDto> ListModelDto
{
get { return _ListModelDto; }
set { _ListModelDto = value; }
}
#region
/// <summary>
/// 分类
/// </summary>
private string _Category;
public string Category
{
get
{
return _Category;
}
set
{
_Category = value;
RaisePropertyChanged();
}
}
///// <summary>
///// 搜索条件-筒体编号
///// </summary>
//private string searchCylinderNo;
//public string SearchCylinderNo
//{
// get
// {
// return searchCylinderNo;
// }
// set
// {
// searchCylinderNo = value;
// RaisePropertyChanged();
// }
//}
/// <summary>
/// 搜索条件-开始时间
/// </summary>
private string _SearchStartDate;
public string SearchStartDate
{
get
{
return _SearchStartDate;
}
set
{
_SearchStartDate = value;
RaisePropertyChanged();
}
}
/// <summary>
/// 搜索条件-结束时间
/// </summary>
private string _SearchEndDate;
public string SearchEndDate
{
get
{
return _SearchEndDate;
}
set
{
_SearchEndDate = value;
RaisePropertyChanged();
}
}
#endregion
#region
/// <summary>
/// 搜索命令
/// </summary>
private DelegateCommand _SearchCmd;
public DelegateCommand SearchCmd
{
get
{
if (_SearchCmd == null) return new DelegateCommand((a) => Search());
return _SearchCmd;
}
set
{
_SearchCmd = value;
}
}
private void Search()
{
try
{
var MulConQueryable = FreeSql.Select<ActionLog>();
//多条件查询
if (!string.IsNullOrEmpty(SearchCategory))
{
MulConQueryable = MulConQueryable.Where(t => t.Category == SearchCategory);
}
//多条件查询
if (!string.IsNullOrEmpty(SearchStartDate))
{
MulConQueryable = MulConQueryable.Where(t => t.CreateTime.Date >= Convert.ToDateTime(SearchStartDate));
}
//多条件查询
if (!string.IsNullOrEmpty(SearchEndDate))
{
MulConQueryable = MulConQueryable.Where(t => t.CreateTime.Date < Convert.ToDateTime(SearchEndDate).AddDays(1));
}
var ListDpI = MulConQueryable.OrderByDescending(a => a.CreateTime).ToList();//.Where(a => a.CreateTime >= DateTime.Now);
ListModelDto.Clear();
foreach (var item in ListDpI)
{
ListModelDto.Add(Mapper.Map<ActionLogDto>(item));
}
}
catch (Exception ex)
{
Logger.Error(String.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace.ToString(), ex.Message.ToString()));
}
}
#endregion
#region "导出数据"
/// <summary>
/// 搜索命令
/// </summary>
private DelegateCommand _OutputDataCmd;
public DelegateCommand OutputDataCmd
{
set
{
_OutputDataCmd = value;
}
get
{
if (_OutputDataCmd == null)
{
_OutputDataCmd = new DelegateCommand(a => OutputDataAction());
}
return _OutputDataCmd;
}
}
private void OutputDataAction()
{
return;
try
{
if (ListModelDto != null && ListModelDto.Count > 0)
{
string FilePath = string.Empty;
//FolderBrowserDialog dialog = new FolderBrowserDialog();
//dialog.Description = "请选择文件夹";
//dialog.ShowNewFolderButton = true; // 显示 新建文件夹 按钮
// //dialog.SelectedPath = Environment.CurrentDirectory; // 设置 选择的路径 为 当前项目路径
//if (dialog.ShowDialog() == DialogResult.OK)
//{
// // 判空
// if (string.IsNullOrEmpty(dialog.SelectedPath)) { MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information); return; }
// FilePath = dialog.SelectedPath; // 获取 选择的 文件夹 路径
//}
var ListData = ListModelDto.ToList();
/***********************
1.读取excel到workbook中
***********************/
string TemplateFilePath = System.Environment.CurrentDirectory;
string tPath = TemplateFilePath + @"\ReportFile\" + CurrentTemplate;
//string tPath = @"D:\ReportTemplate\注油Template.xlsx";
XSSFWorkbook wk = null;
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
wk = new XSSFWorkbook(fs);
fs.Close(); //把excel里的内容保存到workbook中之后就可以关闭了
}
NPOI.SS.UserModel.ISheet sheet = wk.GetSheetAt(0); //获得wk中第一个sheet,保存到sheet中
/***********************
2.操作数据
***********************/
//2行 5行
IDataFormat dataformat = wk.CreateDataFormat();
ICellStyle style0 = wk.CreateCellStyle();
ICellStyle styleBag = wk.CreateCellStyle();
styleBag.FillForegroundColor = HSSFColor.Red.Index;
styleBag.FillPattern = FillPattern.SolidForeground;
for (int i = 0; i < ListData.Count; i++)// (int i = 2; i < 6; i += 3)
{
IRow row;
row = sheet.CreateRow(i + 1);
//row.CreateCell(0).SetCellValue(ListData[i].StaticDiskNo.ToString());
//row.CreateCell(1).SetCellValue(ListData[i].OpNo.ToString());
//row.CreateCell(2).SetCellValue(ListData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
//row.GetCell(10).CellStyle = style0;
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
row.GetCell(2).CellStyle = style0;
//row.GetCell(26).CellStyle = style0;
//if (ListDat[i].UpperGroupStandDiffResult == "NG")
//{
// row.GetCell(4).CellStyle = styleBag;
//}
//if (ListDat[i].LowerGroupStandDiffResult == "NG")
//{
// row.GetCell(6).CellStyle = styleBag;
//}
//if (ListDat[i].GroupStandDiffResult == "NG")
//{
// row.GetCell(8).CellStyle = styleBag;
//}
//if (ListDat[i].FillReal >= ListDat[i].BeforLow && ListDat[i].FillReal <= ListDat[i].BeforUp)
//{
//}
//else
//{
// row.GetCell(7).CellStyle = styleBag;
//}
}
//DayDailyParameterInfo = null;
//NightDailyParameterInfo = null;
/***********************
3.修改完成,写入到客户端
***********************/
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
//tPath = @"D:\日立报表\";
//判断文件夹是否存在,不存在就创建
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
FilePath = FilePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + CurrentName + ".xlsx";
wk.Write(ms);
using (FileStream fs = new FileStream(FilePath, FileMode.Create, FileAccess.Write))
{
byte[] data = ms.ToArray();
fs.Write(data, 0, data.Length);
fs.Flush();
}
wk = null;
}
System.Windows.MessageBox.Show("生成成功");
}
else
{
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
catch (Exception ex)
{
Logger.Error(String.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace.ToString(), ex.Message.ToString()));
}
}
#endregion
}
}

View File

@@ -0,0 +1,17 @@
using CapMachine.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.ViewModels
{
public class FooterViewModel : NavigationViewModel
{
public FooterViewModel()
{
var dd = 1;
}
}
}

View File

@@ -1,6 +1,7 @@
using CapMachine.Core;
using CapMachine.Core.IService;
using CapMachine.Wpf.Models;
using CapMachine.Wpf.Services;
using Prism.Commands;
using Prism.Regions;
@@ -8,15 +9,16 @@ namespace CapMachine.Wpf.ViewModels
{
public class MainViewModel : NavigationViewModel
{
public MainViewModel(IRegionManager region, INavigationMenuService menuService)
public MainViewModel(IRegionManager region, INavigationMenuService menuService, SysService sysService)
{
this.region = region;
MenuService = menuService;
SysService = sysService;
NavigateCommand = new DelegateCommand<NavigationItem>(Navigate);
}
public INavigationMenuService MenuService { get; }
public SysService SysService { get; }
public DelegateCommand<NavigationItem> NavigateCommand { get; private set; }
private int selectedIndex = -1;
@@ -46,7 +48,7 @@ namespace CapMachine.Wpf.ViewModels
{
if (item == null) return;
if (item.Name.Equals("全部"))
if (item.Name.Equals("系统"))
{
IsTopDrawerOpen = true;
return;

View File

@@ -1,6 +1,11 @@
using CapMachine.Core;
using CapMachine.Model;
using CapMachine.Wpf.PrismEvent;
using CapMachine.Wpf.Views;
using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.ObjectModel;
using System.Text;
@@ -10,10 +15,13 @@ namespace CapMachine.Wpf.ViewModels
{
public class ProConfigViewModel : NavigationViewModel
{
public ProConfigViewModel(IDialogService dialogService, IFreeSql freeSql)
public ProConfigViewModel(IDialogService dialogService, IFreeSql freeSql,IEventAggregator eventAggregator, IRegionManager regionManager)
{
//LogService = logService;
FreeSql = freeSql;
EventAggregator = eventAggregator;
RegionManager = regionManager;
//MachineDataService = machineDataService;
DialogService = dialogService;
@@ -29,12 +37,16 @@ namespace CapMachine.Wpf.ViewModels
//各个单独仪表的初始化
SelectedMeterSpeed = new MeterSpeed();
SelectedPs = new MeterPs();
}
/// <summary>
/// FreeSQL 实例函数
/// </summary>
public IFreeSql FreeSql { get; }
public IEventAggregator EventAggregator { get; }
public IRegionManager RegionManager { get; }
/// <summary>
/// 弹窗服务
@@ -276,6 +288,37 @@ namespace CapMachine.Wpf.ViewModels
#endregion
private DelegateCommand _ProStepPsCmd;
/// <summary>
/// 新增PS命令
/// </summary>
public DelegateCommand ProStepPsCmd
{
set
{
_ProStepPsCmd = value;
}
get
{
if (_ProStepPsCmd == null)
{
_ProStepPsCmd = new DelegateCommand(() => ProStepPsCmdCmdMethod());
}
return _ProStepPsCmd;
}
}
private void ProStepPsCmdCmdMethod()
{
//var openDrawerCommand = MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand;
RegionManager.RequestNavigate("ProStepDrawerContentRegion", nameof(ProStepConfigPsView));
//EventAggregator.GetEvent<ProStepDrawerEvent>().Publish("Right");
}
#region Ps表
private ObservableCollection<MeterPs> _ListMeterPsItems;

View File

@@ -0,0 +1,19 @@
using CapMachine.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.ViewModels
{
public class ProStepConfigMainViewModel : NavigationViewModel
{
public ProStepConfigMainViewModel()
{
}
}
}

View File

@@ -0,0 +1,14 @@
using CapMachine.Core;
namespace CapMachine.Wpf.ViewModels
{
public class ProStepConfigPsViewModel : NavigationViewModel
{
public ProStepConfigPsViewModel()
{
}
}
}

View File

@@ -0,0 +1,20 @@
using CapMachine.Core;
using Prism.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.ViewModels
{
public class UserManageViewModel : NavigationViewModel
{
public UserManageViewModel(IEventAggregator eventAggregator)
{
//事件服务
_EventAggregator = eventAggregator;
}
private IEventAggregator _EventAggregator { get; set; }
}
}