新增设备更改
This commit is contained in:
222
GroupLine.App/ViewModel/KPBarrelShrinkFitViewModel.cs
Normal file
222
GroupLine.App/ViewModel/KPBarrelShrinkFitViewModel.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using AutoMapper;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GroupLine.App.ModelDto;
|
||||
using GroupLine.Model;
|
||||
using NLog;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace GroupLine.App.ViewModel
|
||||
{
|
||||
public class KPBarrelShrinkFitViewModel : ViewModelBase
|
||||
{
|
||||
private static Logger _Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string CurrentMachineName = "KP型筒体烧嵌";
|
||||
|
||||
private string CurrentMachineNameTemplate = "KPBarrelShrinkFitTemplate.xlsx";
|
||||
|
||||
private IMapper autoMapper;
|
||||
|
||||
public KPBarrelShrinkFitViewModel()
|
||||
{
|
||||
ListModelDto = new ObservableCollection<KPBarrelShrinkFitDto>();
|
||||
SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString();
|
||||
SearchEndDate = DateTime.Now.AddDays(2).ToShortDateString();
|
||||
MachineName = CurrentMachineName + " - 搜索条件";
|
||||
|
||||
var config = new MapperConfiguration(cfg => cfg.CreateMap<KPBarrelShrinkFit, KPBarrelShrinkFitDto>());
|
||||
autoMapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
private ObservableCollection<KPBarrelShrinkFitDto> _ListModelDto;
|
||||
|
||||
public ObservableCollection<KPBarrelShrinkFitDto> ListModelDto
|
||||
{
|
||||
get { return _ListModelDto; }
|
||||
set { _ListModelDto = value; }
|
||||
}
|
||||
|
||||
private string machineName;
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get { return machineName; }
|
||||
set { machineName = value; RaisePropertyChanged(() => MachineName); }
|
||||
}
|
||||
|
||||
private string searchBarrelNo;
|
||||
|
||||
public string SearchBarrelNo
|
||||
{
|
||||
get { return searchBarrelNo; }
|
||||
set { searchBarrelNo = value; RaisePropertyChanged(() => SearchBarrelNo); }
|
||||
}
|
||||
|
||||
private string searchStartDate;
|
||||
|
||||
public string SearchStartDate
|
||||
{
|
||||
get { return searchStartDate; }
|
||||
set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); }
|
||||
}
|
||||
|
||||
private string searchEndDate;
|
||||
|
||||
public string SearchEndDate
|
||||
{
|
||||
get { return searchEndDate; }
|
||||
set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); }
|
||||
}
|
||||
|
||||
private RelayCommand searchCmd;
|
||||
|
||||
public RelayCommand SearchCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCmd == null) return new RelayCommand(() => Search());
|
||||
return searchCmd;
|
||||
}
|
||||
set { searchCmd = value; }
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mulConQueryable = FSqlContext.FDb.Select<KPBarrelShrinkFit>();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchBarrelNo))
|
||||
{
|
||||
mulConQueryable = mulConQueryable.Where(t => t.BarrelNo.Contains(SearchBarrelNo));
|
||||
}
|
||||
|
||||
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 listData = mulConQueryable.OrderByDescending(a => a.CreateTime).ToList();
|
||||
ListModelDto.Clear();
|
||||
foreach (var item in listData)
|
||||
{
|
||||
ListModelDto.Add(autoMapper.Map<KPBarrelShrinkFitDto>(item));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private RelayCommand _OutputDataCmd;
|
||||
|
||||
public RelayCommand OutputDataCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OutputDataCmd == null) return new RelayCommand(() => OutputDataAction());
|
||||
return _OutputDataCmd;
|
||||
}
|
||||
set { _OutputDataCmd = value; }
|
||||
}
|
||||
|
||||
private void OutputDataAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListModelDto != null && ListModelDto.Count > 0)
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "请选择文件夹";
|
||||
dialog.ShowNewFolderButton = true;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialog.SelectedPath))
|
||||
{
|
||||
MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
var listData = ListModelDto.ToList();
|
||||
string templateFilePath = Environment.CurrentDirectory;
|
||||
string tPath = templateFilePath + @"\ReportFile\" + CurrentMachineNameTemplate;
|
||||
|
||||
XSSFWorkbook wk;
|
||||
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
wk = new XSSFWorkbook(fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
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++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(listData[i].BarrelNo.ToString());
|
||||
row.CreateCell(1).SetCellValue(listData[i].StatorNo.ToString());
|
||||
row.CreateCell(2).SetCellValue(listData[i].OperatorNo.ToString());
|
||||
row.CreateCell(3).SetCellValue(listData[i].BarrelTemp.ToString());
|
||||
row.CreateCell(4).SetCellValue(listData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
|
||||
row.GetCell(4).CellStyle = style0;
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath = filePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchEndDate).ToString("yyyy-MM-dd") + "-" + CurrentMachineName + ".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();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
250
GroupLine.App/ViewModel/KPExhCoverSealTestViewModel.cs
Normal file
250
GroupLine.App/ViewModel/KPExhCoverSealTestViewModel.cs
Normal file
@@ -0,0 +1,250 @@
|
||||
using AutoMapper;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GroupLine.App.ModelDto;
|
||||
using GroupLine.Model;
|
||||
using NLog;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace GroupLine.App.ViewModel
|
||||
{
|
||||
public class KPExhCoverSealTestViewModel : ViewModelBase
|
||||
{
|
||||
private static Logger _Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string CurrentMachineName = "KP排气盖板安装气密检测";
|
||||
|
||||
private string CurrentMachineNameTemplate = "KPExhCoverSealTestTemplate.xlsx";
|
||||
|
||||
private IMapper autoMapper;
|
||||
|
||||
public KPExhCoverSealTestViewModel()
|
||||
{
|
||||
ListModelDto = new ObservableCollection<KPExhCoverSealTestDto>();
|
||||
SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString();
|
||||
SearchEndDate = DateTime.Now.AddDays(2).ToShortDateString();
|
||||
MachineName = CurrentMachineName + " - 搜索条件";
|
||||
|
||||
var config = new MapperConfiguration(cfg => cfg.CreateMap<KPExhCoverSealTest, KPExhCoverSealTestDto>()
|
||||
.ForMember(dest => dest.Result, opt => opt.MapFrom(src => src.Result.ToString())));
|
||||
autoMapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
private ObservableCollection<KPExhCoverSealTestDto> _ListModelDto;
|
||||
|
||||
public ObservableCollection<KPExhCoverSealTestDto> ListModelDto
|
||||
{
|
||||
get { return _ListModelDto; }
|
||||
set { _ListModelDto = value; }
|
||||
}
|
||||
|
||||
private string machineName;
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get { return machineName; }
|
||||
set { machineName = value; RaisePropertyChanged(() => MachineName); }
|
||||
}
|
||||
|
||||
private string searchMvDiscNo;
|
||||
|
||||
public string SearchMvDiscNo
|
||||
{
|
||||
get { return searchMvDiscNo; }
|
||||
set { searchMvDiscNo = value; RaisePropertyChanged(() => SearchMvDiscNo); }
|
||||
}
|
||||
|
||||
private string searchStartDate;
|
||||
|
||||
public string SearchStartDate
|
||||
{
|
||||
get { return searchStartDate; }
|
||||
set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); }
|
||||
}
|
||||
|
||||
private string searchEndDate;
|
||||
|
||||
public string SearchEndDate
|
||||
{
|
||||
get { return searchEndDate; }
|
||||
set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); }
|
||||
}
|
||||
|
||||
private RelayCommand searchCmd;
|
||||
|
||||
public RelayCommand SearchCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCmd == null) return new RelayCommand(() => Search());
|
||||
return searchCmd;
|
||||
}
|
||||
set { searchCmd = value; }
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mulConQueryable = FSqlContext.FDb.Select<KPExhCoverSealTest>();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchMvDiscNo))
|
||||
{
|
||||
mulConQueryable = mulConQueryable.Where(t => t.MvDiscNo.Contains(SearchMvDiscNo));
|
||||
}
|
||||
|
||||
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 listData = mulConQueryable.OrderByDescending(a => a.CreateTime).ToList();
|
||||
ListModelDto.Clear();
|
||||
foreach (var item in listData)
|
||||
{
|
||||
ListModelDto.Add(autoMapper.Map<KPExhCoverSealTestDto>(item));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private RelayCommand _OutputDataCmd;
|
||||
|
||||
public RelayCommand OutputDataCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OutputDataCmd == null) return new RelayCommand(() => OutputDataAction());
|
||||
return _OutputDataCmd;
|
||||
}
|
||||
set { _OutputDataCmd = value; }
|
||||
}
|
||||
|
||||
private void OutputDataAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListModelDto != null && ListModelDto.Count > 0)
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "请选择文件夹";
|
||||
dialog.ShowNewFolderButton = true;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialog.SelectedPath))
|
||||
{
|
||||
MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
var listData = ListModelDto.ToList();
|
||||
string templateFilePath = Environment.CurrentDirectory;
|
||||
string tPath = templateFilePath + @"\ReportFile\" + CurrentMachineNameTemplate;
|
||||
|
||||
XSSFWorkbook wk;
|
||||
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
wk = new XSSFWorkbook(fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
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++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(listData[i].ModelName.ToString());
|
||||
row.CreateCell(1).SetCellValue(listData[i].MvDiscNo.ToString());
|
||||
row.CreateCell(2).SetCellValue(listData[i].StDiscNo.ToString());
|
||||
row.CreateCell(3).SetCellValue(listData[i].CycleTime.ToString());
|
||||
row.CreateCell(4).SetCellValue(listData[i].ScrewCount.ToString());
|
||||
row.CreateCell(5).SetCellValue(listData[i].Result.ToString());
|
||||
row.CreateCell(6).SetCellValue(listData[i].FinalTorque1.ToString());
|
||||
row.CreateCell(7).SetCellValue(listData[i].FinalAngle1.ToString());
|
||||
row.CreateCell(8).SetCellValue(listData[i].FinalTorque2.ToString());
|
||||
row.CreateCell(9).SetCellValue(listData[i].FinalAngle2.ToString());
|
||||
row.CreateCell(10).SetCellValue(listData[i].FinalTorque3.ToString());
|
||||
row.CreateCell(11).SetCellValue(listData[i].FinalAngle3.ToString());
|
||||
row.CreateCell(12).SetCellValue(listData[i].FinalTorque4.ToString());
|
||||
row.CreateCell(13).SetCellValue(listData[i].FinalAngle4.ToString());
|
||||
row.CreateCell(14).SetCellValue(listData[i].FinalTorque5.ToString());
|
||||
row.CreateCell(15).SetCellValue(listData[i].FinalAngle5.ToString());
|
||||
row.CreateCell(16).SetCellValue(listData[i].FinalTorque6.ToString());
|
||||
row.CreateCell(17).SetCellValue(listData[i].FinalAngle6.ToString());
|
||||
row.CreateCell(18).SetCellValue(listData[i].FinalTorque7.ToString());
|
||||
row.CreateCell(19).SetCellValue(listData[i].FinalAngle7.ToString());
|
||||
row.CreateCell(20).SetCellValue(listData[i].FinalTorque8.ToString());
|
||||
row.CreateCell(21).SetCellValue(listData[i].FinalAngle8.ToString());
|
||||
row.CreateCell(22).SetCellValue(listData[i].FinalTorque9.ToString());
|
||||
row.CreateCell(23).SetCellValue(listData[i].FinalAngle9.ToString());
|
||||
row.CreateCell(24).SetCellValue(listData[i].FinalTorque10.ToString());
|
||||
row.CreateCell(25).SetCellValue(listData[i].FinalAngle10.ToString());
|
||||
row.CreateCell(26).SetCellValue(listData[i].FinalTorque11.ToString());
|
||||
row.CreateCell(27).SetCellValue(listData[i].FinalAngle11.ToString());
|
||||
row.CreateCell(28).SetCellValue(listData[i].FinalTorque12.ToString());
|
||||
row.CreateCell(29).SetCellValue(listData[i].FinalAngle12.ToString());
|
||||
row.CreateCell(30).SetCellValue(listData[i].OperatorNo.ToString());
|
||||
row.CreateCell(31).SetCellValue(listData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
|
||||
row.GetCell(31).CellStyle = style0;
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath = filePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchEndDate).ToString("yyyy-MM-dd") + "-" + CurrentMachineName + ".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();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
234
GroupLine.App/ViewModel/KPReliefValveAsmViewModel.cs
Normal file
234
GroupLine.App/ViewModel/KPReliefValveAsmViewModel.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using AutoMapper;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GroupLine.App.ModelDto;
|
||||
using GroupLine.Model;
|
||||
using NLog;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace GroupLine.App.ViewModel
|
||||
{
|
||||
public class KPReliefValveAsmViewModel : ViewModelBase
|
||||
{
|
||||
private static Logger _Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string CurrentMachineName = "KP溢流阀组装机";
|
||||
|
||||
private string CurrentMachineNameTemplate = "KPReliefValveAsmTemplate.xlsx";
|
||||
|
||||
private IMapper autoMapper;
|
||||
|
||||
public KPReliefValveAsmViewModel()
|
||||
{
|
||||
ListModelDto = new ObservableCollection<KPReliefValveAsmDto>();
|
||||
SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString();
|
||||
SearchEndDate = DateTime.Now.AddDays(2).ToShortDateString();
|
||||
MachineName = CurrentMachineName + " - 搜索条件";
|
||||
|
||||
var config = new MapperConfiguration(cfg => cfg.CreateMap<KPReliefValveAsm, KPReliefValveAsmDto>()
|
||||
.ForMember(dest => dest.Result, opt => opt.MapFrom(src => src.Result.ToString())));
|
||||
autoMapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
private ObservableCollection<KPReliefValveAsmDto> _ListModelDto;
|
||||
|
||||
public ObservableCollection<KPReliefValveAsmDto> ListModelDto
|
||||
{
|
||||
get { return _ListModelDto; }
|
||||
set { _ListModelDto = value; }
|
||||
}
|
||||
|
||||
private string machineName;
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get { return machineName; }
|
||||
set { machineName = value; RaisePropertyChanged(() => MachineName); }
|
||||
}
|
||||
|
||||
private string searchMvDiscNo;
|
||||
|
||||
public string SearchMvDiscNo
|
||||
{
|
||||
get { return searchMvDiscNo; }
|
||||
set { searchMvDiscNo = value; RaisePropertyChanged(() => SearchMvDiscNo); }
|
||||
}
|
||||
|
||||
private string searchStartDate;
|
||||
|
||||
public string SearchStartDate
|
||||
{
|
||||
get { return searchStartDate; }
|
||||
set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); }
|
||||
}
|
||||
|
||||
private string searchEndDate;
|
||||
|
||||
public string SearchEndDate
|
||||
{
|
||||
get { return searchEndDate; }
|
||||
set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); }
|
||||
}
|
||||
|
||||
private RelayCommand searchCmd;
|
||||
|
||||
public RelayCommand SearchCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCmd == null) return new RelayCommand(() => Search());
|
||||
return searchCmd;
|
||||
}
|
||||
set { searchCmd = value; }
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mulConQueryable = FSqlContext.FDb.Select<KPReliefValveAsm>();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchMvDiscNo))
|
||||
{
|
||||
mulConQueryable = mulConQueryable.Where(t => t.MvDiscNo.Contains(SearchMvDiscNo));
|
||||
}
|
||||
|
||||
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 listData = mulConQueryable.OrderByDescending(a => a.CreateTime).ToList();
|
||||
ListModelDto.Clear();
|
||||
foreach (var item in listData)
|
||||
{
|
||||
ListModelDto.Add(autoMapper.Map<KPReliefValveAsmDto>(item));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private RelayCommand _OutputDataCmd;
|
||||
|
||||
public RelayCommand OutputDataCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OutputDataCmd == null) return new RelayCommand(() => OutputDataAction());
|
||||
return _OutputDataCmd;
|
||||
}
|
||||
set { _OutputDataCmd = value; }
|
||||
}
|
||||
|
||||
private void OutputDataAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListModelDto != null && ListModelDto.Count > 0)
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "请选择文件夹";
|
||||
dialog.ShowNewFolderButton = true;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialog.SelectedPath))
|
||||
{
|
||||
MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
var listData = ListModelDto.ToList();
|
||||
string templateFilePath = Environment.CurrentDirectory;
|
||||
string tPath = templateFilePath + @"\ReportFile\" + CurrentMachineNameTemplate;
|
||||
|
||||
XSSFWorkbook wk;
|
||||
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
wk = new XSSFWorkbook(fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
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++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(listData[i].ModelName.ToString());
|
||||
row.CreateCell(1).SetCellValue(listData[i].MvDiscNo.ToString());
|
||||
row.CreateCell(2).SetCellValue(listData[i].StDiscNo.ToString());
|
||||
row.CreateCell(3).SetCellValue(listData[i].CycleTime.ToString());
|
||||
row.CreateCell(4).SetCellValue(listData[i].ScrewCount.ToString());
|
||||
row.CreateCell(5).SetCellValue(listData[i].Result.ToString());
|
||||
row.CreateCell(6).SetCellValue(listData[i].FinalTorque1.ToString());
|
||||
row.CreateCell(7).SetCellValue(listData[i].FinalAngle1.ToString());
|
||||
row.CreateCell(8).SetCellValue(listData[i].FinalTorque2.ToString());
|
||||
row.CreateCell(9).SetCellValue(listData[i].FinalAngle2.ToString());
|
||||
row.CreateCell(10).SetCellValue(listData[i].FinalTorque3.ToString());
|
||||
row.CreateCell(11).SetCellValue(listData[i].FinalAngle3.ToString());
|
||||
row.CreateCell(12).SetCellValue(listData[i].FinalTorque4.ToString());
|
||||
row.CreateCell(13).SetCellValue(listData[i].FinalAngle4.ToString());
|
||||
row.CreateCell(14).SetCellValue(listData[i].OperatorNo.ToString());
|
||||
row.CreateCell(15).SetCellValue(listData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
|
||||
row.GetCell(15).CellStyle = style0;
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath = filePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchEndDate).ToString("yyyy-MM-dd") + "-" + CurrentMachineName + ".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();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
263
GroupLine.App/ViewModel/OilGuideMountViewModel.cs
Normal file
263
GroupLine.App/ViewModel/OilGuideMountViewModel.cs
Normal file
@@ -0,0 +1,263 @@
|
||||
using AutoMapper;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GroupLine.App.ModelDto;
|
||||
using GroupLine.Model;
|
||||
using NLog;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace GroupLine.App.ViewModel
|
||||
{
|
||||
public class OilGuideMountViewModel : ViewModelBase
|
||||
{
|
||||
private static Logger _Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string CurrentMachineName = "导油板敲入";
|
||||
|
||||
private string CurrentMachineNameTemplate = "OilGuideMountTemplate.xlsx";
|
||||
|
||||
private IMapper autoMapper;
|
||||
|
||||
/// <summary>
|
||||
/// 实例化函数
|
||||
/// </summary>
|
||||
public OilGuideMountViewModel()
|
||||
{
|
||||
ListModelDto = new ObservableCollection<OilGuideMountDto>();
|
||||
SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString();
|
||||
SearchEndDate = DateTime.Now.AddDays(2).ToShortDateString();
|
||||
|
||||
MachineName = CurrentMachineName + " - 搜索条件";
|
||||
|
||||
var config = new MapperConfiguration(cfg => cfg.CreateMap<OilGuideMount, OilGuideMountDto>()
|
||||
.ForMember(dest => dest.PlaceNoDamage, opt => opt.MapFrom(src => src.PlaceNoDamage.ToString())));
|
||||
autoMapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表集合
|
||||
/// </summary>
|
||||
private ObservableCollection<OilGuideMountDto> _ListModelDto;
|
||||
|
||||
/// <summary>
|
||||
/// 列表集合
|
||||
/// </summary>
|
||||
public ObservableCollection<OilGuideMountDto> ListModelDto
|
||||
{
|
||||
get { return _ListModelDto; }
|
||||
set { _ListModelDto = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 机器设备名称
|
||||
/// </summary>
|
||||
private string machineName;
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get { return machineName; }
|
||||
set { machineName = value; RaisePropertyChanged(() => MachineName); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索条件-曲轴编号
|
||||
/// </summary>
|
||||
private string searchCrankshaftNo;
|
||||
|
||||
public string SearchCrankshaftNo
|
||||
{
|
||||
get { return searchCrankshaftNo; }
|
||||
set { searchCrankshaftNo = value; RaisePropertyChanged(() => SearchCrankshaftNo); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索条件-开始时间
|
||||
/// </summary>
|
||||
private string searchStartDate;
|
||||
|
||||
public string SearchStartDate
|
||||
{
|
||||
get { return searchStartDate; }
|
||||
set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索条件-结束时间
|
||||
/// </summary>
|
||||
private string searchEndDate;
|
||||
|
||||
public string SearchEndDate
|
||||
{
|
||||
get { return searchEndDate; }
|
||||
set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索命令
|
||||
/// </summary>
|
||||
private RelayCommand searchCmd;
|
||||
|
||||
public RelayCommand SearchCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCmd == null) return new RelayCommand(() => Search());
|
||||
return searchCmd;
|
||||
}
|
||||
set { searchCmd = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索数据。
|
||||
/// </summary>
|
||||
private void Search()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mulConQueryable = FSqlContext.FDb.Select<OilGuideMount>();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchCrankshaftNo))
|
||||
{
|
||||
mulConQueryable = mulConQueryable.Where(t => t.CrankshaftNo.Contains(SearchCrankshaftNo));
|
||||
}
|
||||
|
||||
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 listData = mulConQueryable.OrderByDescending(a => a.CreateTime).ToList();
|
||||
ListModelDto.Clear();
|
||||
foreach (var item in listData)
|
||||
{
|
||||
ListModelDto.Add(autoMapper.Map<OilGuideMountDto>(item));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private RelayCommand _OutputDataCmd;
|
||||
|
||||
/// <summary>
|
||||
/// 导出命令
|
||||
/// </summary>
|
||||
public RelayCommand OutputDataCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OutputDataCmd == null) return new RelayCommand(() => OutputDataAction());
|
||||
return _OutputDataCmd;
|
||||
}
|
||||
set { _OutputDataCmd = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导出数据。
|
||||
/// </summary>
|
||||
private void OutputDataAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListModelDto != null && ListModelDto.Count > 0)
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "请选择文件夹";
|
||||
dialog.ShowNewFolderButton = true;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialog.SelectedPath))
|
||||
{
|
||||
MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
var listData = ListModelDto.ToList();
|
||||
string templateFilePath = Environment.CurrentDirectory;
|
||||
string tPath = templateFilePath + @"\ReportFile\" + CurrentMachineNameTemplate;
|
||||
|
||||
XSSFWorkbook wk;
|
||||
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
wk = new XSSFWorkbook(fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
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++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(listData[i].CrankshaftNo.ToString());
|
||||
row.CreateCell(1).SetCellValue(listData[i].BracketNo.ToString());
|
||||
row.CreateCell(2).SetCellValue(listData[i].BracketCastingNo.ToString());
|
||||
row.CreateCell(3).SetCellValue(listData[i].OperatorNo.ToString());
|
||||
row.CreateCell(4).SetCellValue(listData[i].PlaceNoDamage.ToString());
|
||||
row.CreateCell(5).SetCellValue(listData[i].OilGuidePlate.ToString());
|
||||
row.CreateCell(6).SetCellValue(listData[i].FeelerGaugeCheck.ToString());
|
||||
row.CreateCell(7).SetCellValue(listData[i].BuriedPlug.ToString());
|
||||
row.CreateCell(8).SetCellValue(listData[i].HelicalScrew.ToString());
|
||||
row.CreateCell(9).SetCellValue(listData[i].AirTightCheck.ToString());
|
||||
row.CreateCell(10).SetCellValue(listData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
|
||||
row.GetCell(10).CellStyle = style0;
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath = filePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchEndDate).ToString("yyyy-MM-dd") + "-" + CurrentMachineName + ".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();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -291,13 +291,15 @@ namespace GroupLine.App.ViewModel
|
||||
row.CreateCell(6).SetCellValue(ListData[i].FelerGgeResult.ToString());
|
||||
row.CreateCell(7).SetCellValue(ListData[i].MagnetResult.ToString());
|
||||
row.CreateCell(8).SetCellValue(ListData[i].OpNo.ToString());
|
||||
row.CreateCell(9).SetCellValue(ListData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
row.CreateCell(9).SetCellValue(ListData[i].GapblockDepth.ToString());
|
||||
row.CreateCell(10).SetCellValue(ListData[i].PalletNo.ToString());
|
||||
row.CreateCell(11).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(9).CellStyle = style0;
|
||||
row.GetCell(11).CellStyle = style0;
|
||||
//row.GetCell(26).CellStyle = style0;
|
||||
//if (ListDat[i].UpperGroupStandDiffResult == "NG")
|
||||
//{
|
||||
|
||||
221
GroupLine.App/ViewModel/RotorShrinkFitViewModel.cs
Normal file
221
GroupLine.App/ViewModel/RotorShrinkFitViewModel.cs
Normal file
@@ -0,0 +1,221 @@
|
||||
using AutoMapper;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using GroupLine.App.ModelDto;
|
||||
using GroupLine.Model;
|
||||
using NLog;
|
||||
using NPOI.HSSF.Util;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace GroupLine.App.ViewModel
|
||||
{
|
||||
public class RotorShrinkFitViewModel : ViewModelBase
|
||||
{
|
||||
private static Logger _Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private string CurrentMachineName = "转子烧嵌";
|
||||
|
||||
private string CurrentMachineNameTemplate = "RotorShrinkFitTemplate.xlsx";
|
||||
|
||||
private IMapper autoMapper;
|
||||
|
||||
public RotorShrinkFitViewModel()
|
||||
{
|
||||
ListModelDto = new ObservableCollection<RotorShrinkFitDto>();
|
||||
SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString();
|
||||
SearchEndDate = DateTime.Now.AddDays(2).ToShortDateString();
|
||||
MachineName = CurrentMachineName + " - 搜索条件";
|
||||
|
||||
var config = new MapperConfiguration(cfg => cfg.CreateMap<RotorShrinkFit, RotorShrinkFitDto>());
|
||||
autoMapper = config.CreateMapper();
|
||||
}
|
||||
|
||||
private ObservableCollection<RotorShrinkFitDto> _ListModelDto;
|
||||
|
||||
public ObservableCollection<RotorShrinkFitDto> ListModelDto
|
||||
{
|
||||
get { return _ListModelDto; }
|
||||
set { _ListModelDto = value; }
|
||||
}
|
||||
|
||||
private string machineName;
|
||||
|
||||
public string MachineName
|
||||
{
|
||||
get { return machineName; }
|
||||
set { machineName = value; RaisePropertyChanged(() => MachineName); }
|
||||
}
|
||||
|
||||
private string searchRotorNo;
|
||||
|
||||
public string SearchRotorNo
|
||||
{
|
||||
get { return searchRotorNo; }
|
||||
set { searchRotorNo = value; RaisePropertyChanged(() => SearchRotorNo); }
|
||||
}
|
||||
|
||||
private string searchStartDate;
|
||||
|
||||
public string SearchStartDate
|
||||
{
|
||||
get { return searchStartDate; }
|
||||
set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); }
|
||||
}
|
||||
|
||||
private string searchEndDate;
|
||||
|
||||
public string SearchEndDate
|
||||
{
|
||||
get { return searchEndDate; }
|
||||
set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); }
|
||||
}
|
||||
|
||||
private RelayCommand searchCmd;
|
||||
|
||||
public RelayCommand SearchCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (searchCmd == null) return new RelayCommand(() => Search());
|
||||
return searchCmd;
|
||||
}
|
||||
set { searchCmd = value; }
|
||||
}
|
||||
|
||||
private void Search()
|
||||
{
|
||||
try
|
||||
{
|
||||
var mulConQueryable = FSqlContext.FDb.Select<RotorShrinkFit>();
|
||||
|
||||
if (!string.IsNullOrEmpty(SearchRotorNo))
|
||||
{
|
||||
mulConQueryable = mulConQueryable.Where(t => t.RotorNo.Contains(SearchRotorNo));
|
||||
}
|
||||
|
||||
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 listData = mulConQueryable.OrderByDescending(a => a.CreateTime).ToList();
|
||||
ListModelDto.Clear();
|
||||
foreach (var item in listData)
|
||||
{
|
||||
ListModelDto.Add(autoMapper.Map<RotorShrinkFitDto>(item));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
|
||||
private RelayCommand _OutputDataCmd;
|
||||
|
||||
public RelayCommand OutputDataCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_OutputDataCmd == null) return new RelayCommand(() => OutputDataAction());
|
||||
return _OutputDataCmd;
|
||||
}
|
||||
set { _OutputDataCmd = value; }
|
||||
}
|
||||
|
||||
private void OutputDataAction()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ListModelDto != null && ListModelDto.Count > 0)
|
||||
{
|
||||
string filePath = string.Empty;
|
||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
||||
dialog.Description = "请选择文件夹";
|
||||
dialog.ShowNewFolderButton = true;
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialog.SelectedPath))
|
||||
{
|
||||
MessageBox.Show("文件夹路径不能为空", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
filePath = dialog.SelectedPath;
|
||||
}
|
||||
|
||||
var listData = ListModelDto.ToList();
|
||||
string templateFilePath = Environment.CurrentDirectory;
|
||||
string tPath = templateFilePath + @"\ReportFile\" + CurrentMachineNameTemplate;
|
||||
|
||||
XSSFWorkbook wk;
|
||||
using (FileStream fs = File.Open(tPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
{
|
||||
wk = new XSSFWorkbook(fs);
|
||||
fs.Close();
|
||||
}
|
||||
|
||||
ISheet sheet = wk.GetSheetAt(0);
|
||||
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++)
|
||||
{
|
||||
IRow row = sheet.CreateRow(i + 1);
|
||||
row.CreateCell(0).SetCellValue(listData[i].RotorNo.ToString());
|
||||
row.CreateCell(1).SetCellValue(listData[i].BracketNo.ToString());
|
||||
row.CreateCell(2).SetCellValue(listData[i].OperatorNo.ToString());
|
||||
row.CreateCell(3).SetCellValue(listData[i].CreateTime.ToString("yyyy-MM-dd HH:mm"));
|
||||
|
||||
style0.DataFormat = dataformat.GetFormat("yyyy-MM-dd HH:mm:ss");
|
||||
row.GetCell(3).CellStyle = style0;
|
||||
}
|
||||
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
if (!Directory.Exists(filePath))
|
||||
{
|
||||
Directory.CreateDirectory(filePath);
|
||||
}
|
||||
|
||||
filePath = filePath + @"\" + Convert.ToDateTime(SearchStartDate).ToString("yyyy-MM-dd") + "-" + Convert.ToDateTime(SearchEndDate).ToString("yyyy-MM-dd") + "-" + CurrentMachineName + ".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();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("生成成功");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请先搜索数据后再导出", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_Logger.Error(string.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace, ex.Message));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,11 @@ namespace GroupLine.App.ViewModel
|
||||
SimpleIoc.Default.Register<KPRingWeldMachDwViewModel>();
|
||||
SimpleIoc.Default.Register<KPRingWeldMachUpViewModel>();
|
||||
SimpleIoc.Default.Register<KPShrinkTubViewModel>();
|
||||
SimpleIoc.Default.Register<OilGuideMountViewModel>();
|
||||
SimpleIoc.Default.Register<RotorShrinkFitViewModel>();
|
||||
SimpleIoc.Default.Register<KPBarrelShrinkFitViewModel>();
|
||||
SimpleIoc.Default.Register<KPReliefValveAsmViewModel>();
|
||||
SimpleIoc.Default.Register<KPExhCoverSealTestViewModel>();
|
||||
|
||||
|
||||
////if (ViewModelBase.IsInDesignModeStatic)
|
||||
@@ -472,6 +477,46 @@ namespace GroupLine.App.ViewModel
|
||||
}
|
||||
}
|
||||
|
||||
public OilGuideMountViewModel OilGuideMount
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<OilGuideMountViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public RotorShrinkFitViewModel RotorShrinkFit
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<RotorShrinkFitViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public KPBarrelShrinkFitViewModel KPBarrelShrinkFit
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<KPBarrelShrinkFitViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public KPReliefValveAsmViewModel KPReliefValveAsm
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<KPReliefValveAsmViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public KPExhCoverSealTestViewModel KPExhCoverSealTest
|
||||
{
|
||||
get
|
||||
{
|
||||
return ServiceLocator.Current.GetInstance<KPExhCoverSealTestViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
public static void Cleanup()
|
||||
{
|
||||
// TODO Clear the ViewModels
|
||||
|
||||
Reference in New Issue
Block a user