|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Collections.ObjectModel;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Windows.Input;
|
|
|
using GummingCommon;
|
|
|
using GummingEntity;
|
|
|
using GummingSupport;
|
|
|
using GummingControl;
|
|
|
using System.Text;
|
|
|
using GummingBusiness;
|
|
|
using Newtonsoft.Json;
|
|
|
using GummingLine;
|
|
|
|
|
|
namespace Gumming
|
|
|
{
|
|
|
public class OperationViewModule : ViewModelBase
|
|
|
{
|
|
|
#region base parameters
|
|
|
private int rows = 20;
|
|
|
private int pagenumber = 1;
|
|
|
public OperationView View { get; set; }
|
|
|
private bool IsConfirm;
|
|
|
private bool isLoading;
|
|
|
private AppEnum.PathType _CurrentPathType;
|
|
|
public AppEnum.PathType CurrentPathType
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _CurrentPathType;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_CurrentPathType = value;
|
|
|
OnPropertyChanged("CurrentPathType");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region constructor
|
|
|
public OperationViewModule()
|
|
|
{
|
|
|
View = new OperationView();
|
|
|
View.DataContext = this;
|
|
|
|
|
|
InitializeCommands();
|
|
|
InitializeParameters();
|
|
|
}
|
|
|
|
|
|
private void InitializeCommands()
|
|
|
{
|
|
|
ExportCommand = new DelegateCommand(OnExportCommand);
|
|
|
QueryCommand = new DelegateCommand(OnQueryCommand);
|
|
|
}
|
|
|
|
|
|
public override void InitializeParameters(object content = null)
|
|
|
{
|
|
|
IsConfirm = false;
|
|
|
WindowTitle = "";
|
|
|
StartDate = DateTime.Now.AddDays(-1);
|
|
|
EndDate = DateTime.Now;
|
|
|
|
|
|
PagerControlViewer = new PagerControlViewModule();
|
|
|
PagerControlViewer.OnPager += new PagerControlViewModule.PagerHandler(PagerControlView_OnPager);
|
|
|
|
|
|
var thread = new Thread(new ParameterizedThreadStart(StartLoadTestItem)) { IsBackground = true };
|
|
|
thread.Start();
|
|
|
}
|
|
|
|
|
|
~OperationViewModule()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Properties
|
|
|
public string WindowTitle { get; private set; }
|
|
|
private string _TotalRecords;
|
|
|
public string TotalRecords
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _TotalRecords;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_TotalRecords = value;
|
|
|
OnPropertyChanged("TotalRecords");
|
|
|
}
|
|
|
}
|
|
|
private int _Warnings;
|
|
|
public int Warnings
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _Warnings;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_Warnings = value;
|
|
|
OnPropertyChanged("Warnings");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private int _Alarms;
|
|
|
public int Alarms
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _Alarms;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_Alarms = value;
|
|
|
OnPropertyChanged("Alarms");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private int _Totals;
|
|
|
public int Totals
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _Totals;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_Totals = value;
|
|
|
OnPropertyChanged("Totals");
|
|
|
}
|
|
|
}
|
|
|
private DateTime _StartDate;
|
|
|
public DateTime StartDate
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _StartDate;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_StartDate = value;
|
|
|
OnPropertyChanged("StartDate");
|
|
|
}
|
|
|
}
|
|
|
private DateTime _EndDate;
|
|
|
public DateTime EndDate
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _EndDate;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_EndDate = value;
|
|
|
OnPropertyChanged("EndDate");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private string _KeyWord;
|
|
|
public string KeyWord
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _KeyWord;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_KeyWord = value;
|
|
|
OnPropertyChanged("KeyWord");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ObservableCollection<SysOperationEntity> _SysOperations;
|
|
|
public ObservableCollection<SysOperationEntity> SysOperations
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _SysOperations;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_SysOperations = value;
|
|
|
OnPropertyChanged("SysOperations");
|
|
|
}
|
|
|
}
|
|
|
private PagerControlViewModule _PagerControlViewer;
|
|
|
public PagerControlViewModule PagerControlViewer
|
|
|
{
|
|
|
get { return _PagerControlViewer; }
|
|
|
set
|
|
|
{
|
|
|
_PagerControlViewer = value;
|
|
|
OnPropertyChanged("PagerControlViewer");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Binding Commands
|
|
|
private ICommand _QueryCommand;
|
|
|
public ICommand QueryCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _QueryCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_QueryCommand = value;
|
|
|
OnPropertyChanged("QueryCommand");
|
|
|
}
|
|
|
}
|
|
|
private ICommand _ExportCommand;
|
|
|
public ICommand ExportCommand
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return _ExportCommand;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
_ExportCommand = value;
|
|
|
OnPropertyChanged("ExportCommand");
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region Private Methods
|
|
|
private void PagerControlView_OnPager(int currentpagenumber, int currentrows)
|
|
|
{
|
|
|
pagenumber = currentpagenumber;
|
|
|
rows = currentrows;
|
|
|
|
|
|
if (!isLoading)
|
|
|
{
|
|
|
Thread t = new Thread(StartLoadTestItem);
|
|
|
t.IsBackground = true;
|
|
|
t.Start();
|
|
|
}
|
|
|
}
|
|
|
private void StartLoadTestItem(object key)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
isLoading = true;
|
|
|
|
|
|
SysOperations = new ObservableCollection<SysOperationEntity>();
|
|
|
string keycheck = " and 1= 1";
|
|
|
if (!string.IsNullOrWhiteSpace(KeyWord))
|
|
|
{
|
|
|
keycheck = " and (LogPage like '%"+ KeyWord.Trim() + "%' or CreateBy like '%" + KeyWord.Trim() + "%' or LogDetail like '%" + KeyWord.Trim() + "%') ";
|
|
|
}
|
|
|
var record = SysOperationDA.Load(new PagerEntity() { PageIndex = pagenumber, Rows = rows, Conditions
|
|
|
= " and CreateTime >='"+StartDate.ToString("yyyy-MM-dd 00:00:00")+ "' and CreateTime <='" + EndDate.ToString("yyyy-MM-dd 23:59:59") + "' " + keycheck
|
|
|
});
|
|
|
List<SysOperationEntity> logs = (List<SysOperationEntity>)record.rows;
|
|
|
|
|
|
View.Dispatcher.Invoke((Action)(() =>
|
|
|
{
|
|
|
foreach (var s in logs)
|
|
|
{
|
|
|
SysOperations.Add(s);
|
|
|
}
|
|
|
OnPropertyChanged("HartLog");
|
|
|
TotalRecords = string.Format("<22><><EFBFBD>ü<EFBFBD>¼<EFBFBD><C2BC>: {0}", record.records);//.ToString("D5"));
|
|
|
PagerControlViewer.SetPager(rows, record.page, record.total, record.Count, record.records);
|
|
|
isLoading = false;
|
|
|
}));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogService.WriteErrorLog(ex);
|
|
|
ShowErrorBox("Error:" + ex.Message);
|
|
|
return;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
CloseProgressView();
|
|
|
}
|
|
|
}
|
|
|
private void OnQueryCommand(Object sender)
|
|
|
{
|
|
|
var thread = new Thread(new ParameterizedThreadStart(StartLoadTestItem)) { IsBackground = true };
|
|
|
thread.Start();
|
|
|
}
|
|
|
private void OnExportCommand(Object sender)
|
|
|
{
|
|
|
SaveFileDialog saveDialog = new SaveFileDialog();
|
|
|
saveDialog.Filter = "*.xlsx|*.xlsx";
|
|
|
DialogResult dr = saveDialog.ShowDialog();
|
|
|
if (dr == DialogResult.OK && saveDialog.FileName.Length > 0)
|
|
|
{
|
|
|
string targetFile = saveDialog.FileName;
|
|
|
if (File.Exists(targetFile))
|
|
|
{
|
|
|
File.Delete(targetFile);
|
|
|
}
|
|
|
SysOperationExport.Export(SysOperations, targetFile);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|