390 lines
14 KiB
C#
390 lines
14 KiB
C#
using CommunityToolkit.Mvvm.ComponentModel;
|
||
using CommunityToolkit.Mvvm.Input;
|
||
using MaterialDesignThemes.Wpf;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data.SqlClient;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows;
|
||
using System.Windows.Controls;
|
||
using WPFWCSDemo.Models;
|
||
using WPFWCSDemo.Schedules;
|
||
using WPFWCSDemo.StateCode;
|
||
using WPFWCSDemo.Utilities;
|
||
using WPFWCSDemo.Views;
|
||
|
||
namespace WPFWCSDemo.ViewModels.Settings
|
||
{
|
||
public partial class SystemViewModel:ObservableObject
|
||
{
|
||
|
||
/// <summary>
|
||
/// 选中删除任务数据
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _isTaskDataDelete;
|
||
|
||
/// <summary>
|
||
/// 选中删除报警数据
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _isAlarmDataDelete;
|
||
|
||
/// <summary>
|
||
/// 实垛A线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineAStr = "重置A线请求标志";
|
||
/// <summary>
|
||
/// 实垛B线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineBStr = "重置B线请求标志";
|
||
/// <summary>
|
||
/// 实垛C线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineCStr = "重置C线请求标志";
|
||
/// <summary>
|
||
/// 实垛D线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineDStr = "重置D线请求标志";
|
||
/// <summary>
|
||
/// 实垛AB线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineABStr = "重置AB线请求标志";
|
||
/// <summary>
|
||
/// 实垛CD线显示文本
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
string _lineCDStr = "重置CD线请求标志";
|
||
|
||
|
||
/// <summary>
|
||
/// 是否限制实垛A线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineAIsEnable = true;
|
||
/// <summary>
|
||
/// 是否限制实垛B线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineBIsEnable = true;
|
||
/// <summary>
|
||
/// 是否限制实垛C线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineCIsEnable = true;
|
||
/// <summary>
|
||
/// 是否限制实垛D线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineDIsEnable = true;
|
||
/// <summary>
|
||
/// 是否限制空托AB线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineABIsEnable = true;
|
||
/// <summary>
|
||
/// 是否限制空托CD线生成任务 0-解禁 1-禁止
|
||
/// </summary>
|
||
[ObservableProperty]
|
||
bool _lineCDIsEnable = true;
|
||
|
||
/// <summary>
|
||
/// A手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineAIsEnable = true;
|
||
/// <summary>
|
||
/// B手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineBIsEnable = true;
|
||
/// <summary>
|
||
/// C手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineCIsEnable = true;
|
||
/// <summary>
|
||
/// D手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineDIsEnable = true;
|
||
/// <summary>
|
||
/// AB手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineABIsEnable = true;
|
||
/// <summary>
|
||
/// CD手动允许下发标志
|
||
/// </summary>
|
||
public static bool lineCDIsEnable = true;
|
||
|
||
|
||
/// <summary>
|
||
/// 手动备份当前数据库
|
||
/// </summary>
|
||
[RelayCommand]
|
||
void GetSqlDBBackup()
|
||
{
|
||
if (MessageBox.Show("确定创建备份文件吗(此操作会生成一份备份文件)?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
SqlDatabaseMaintenance.SQLBackup();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("操作已取消");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清除近3个月之外所有任务记录(保留最近3个月内数据)
|
||
/// </summary>
|
||
[RelayCommand]
|
||
void DeleteDataOutOfTreeMouths()
|
||
{
|
||
if (MessageBox.Show("确定删除数据吗(此操作会保留最近3个月内的数据,且删除最近3个月之外的数据)?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
SqlHelper.ExecuteNonQuery("DELETE FROM TASK_HISTORY WHERE FINISHTIME<@FinishTime",
|
||
new SqlParameter("@FinishTime", DateTime.Now.AddMonths(-3).ToString("yyyy-MM"))
|
||
);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 调度任务备份
|
||
/// </summary>
|
||
[RelayCommand]
|
||
void TaskBackup()
|
||
{
|
||
if (MessageBox.Show("确定创建备份文件吗?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
if (IsTaskDataDelete)
|
||
{
|
||
if (MessageBox.Show("将删除已备份的【调度任务历史记录】数据,是否继续?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
SqlDatabaseMaintenance.SQLTaskBackup("Month", -6, IsTaskDataDelete);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("备份操作已取消");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//选择仅备份不删除数据
|
||
SqlDatabaseMaintenance.SQLTaskBackup("Month", -6, false);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 历史报警备份
|
||
/// </summary>
|
||
[RelayCommand]
|
||
void AlarmBackup()
|
||
{
|
||
if (MessageBox.Show("确定创建备份文件吗?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
if (IsAlarmDataDelete)
|
||
{
|
||
if (MessageBox.Show("将删除已备份的【报警历史记录】数据,是否继续?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||
{
|
||
SqlDatabaseMaintenance.SQLAlarmBackup("Month", -6, IsAlarmDataDelete);
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("备份操作已取消");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//选择仅备份不删除数据
|
||
SqlDatabaseMaintenance.SQLAlarmBackup("Month", -6, false);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 货位初始化
|
||
/// </summary>
|
||
[RelayCommand]
|
||
void CargoInitialize()
|
||
{
|
||
string result = Microsoft.VisualBasic.Interaction.InputBox("Enter something:", "Input Dialog", "");
|
||
MessageBox.Show("You entered: " + result);
|
||
CargoTableInitialize.CargoSpaceInit(10,50,5);
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 手动控制输送线是否允许下发任务 true-允许 false-禁止
|
||
/// </summary>
|
||
/// <param name="lineName">实垛:A,B,C,D 空托:AB,CD</param>
|
||
[RelayCommand]
|
||
void LineIsEnabled(string lineName)
|
||
{
|
||
switch (lineName)
|
||
{
|
||
case "A":
|
||
if (LineAIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止A线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineAIsEnable = false;
|
||
lineAIsEnable = false;
|
||
LineAStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineAStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许A线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineAIsEnable = true;
|
||
lineAIsEnable = true;
|
||
LineAStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineAStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
case "B":
|
||
if (LineBIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止B线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineBIsEnable = false;
|
||
lineBIsEnable = false;
|
||
LineBStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineBStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许B线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineBIsEnable = true;
|
||
lineBIsEnable = true;
|
||
LineBStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineBStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
case "C":
|
||
if (LineCIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止C线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineCIsEnable = false;
|
||
lineCIsEnable = false;
|
||
LineCStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineCStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许C线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineCIsEnable = true;
|
||
lineCIsEnable = true;
|
||
LineCStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineCStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
case "D":
|
||
if (LineDIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止D线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineDIsEnable = false;
|
||
lineDIsEnable = false;
|
||
LineDStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineDStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许D线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineDIsEnable = true;
|
||
lineDIsEnable = true;
|
||
LineDStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineDStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
case "AB":
|
||
if (LineABIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止AB线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineABIsEnable = false;
|
||
lineABIsEnable = false;
|
||
LineABStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineABStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许AB线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineABIsEnable = true;
|
||
lineABIsEnable = true;
|
||
LineABStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineABStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
case "CD":
|
||
if (LineCDIsEnable)
|
||
{
|
||
if (MessageBox.Show("是否禁止CD线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineCDIsEnable = false;
|
||
lineCDIsEnable = false;
|
||
LineCDStr = "禁止下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineCDStr}】", "USER");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MessageBox.Show("是否允许CD线生成任务?", "警告", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
|
||
{
|
||
LineCDIsEnable = true;
|
||
lineCDIsEnable = true;
|
||
LineCDStr = "允许下发";
|
||
|
||
SqlHelper.NewEventLog($"人工完成任务:{lineName}线切换为【{LineCDStr}】", "USER");
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|