添加项目文件。
This commit is contained in:
139
WPFWCSDemo/Utilities/Table/AlarmManager.cs
Normal file
139
WPFWCSDemo/Utilities/Table/AlarmManager.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.Data;
|
||||
|
||||
namespace WPFWCSDemo.Utilities.Table
|
||||
{
|
||||
public class AlarmManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取【实时报警】表所有行数据集合
|
||||
/// </summary>
|
||||
/// <returns>返回所有行的数据</returns>
|
||||
public static List<Alarm> ListAll()
|
||||
{
|
||||
|
||||
using (DataTable? dt = SqlHelper.ExecuteTable("SELECT * FROM ALARM ORDER BY GEN_TIME DESC"))
|
||||
{
|
||||
if (dt == null) return null;
|
||||
|
||||
List<Alarm> alarms = new List<Alarm>();
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
alarms.Add(ToModels(dr));
|
||||
}
|
||||
#region 反射方法
|
||||
/*
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
tasks.Add(dr.DataRowToModel<ScheduleManager>());
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
return alarms;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将【调度管理】表的单行转换为实体数据对象
|
||||
/// </summary>
|
||||
/// <param name="dr">获取表的某行数据</param>
|
||||
/// <returns>当前行所有字段的集合</returns>
|
||||
public static Alarm ToModels(DataRow dr)
|
||||
{
|
||||
Alarm alarm = new Alarm();
|
||||
alarm.Point_Id = dr["Point_Id"].ToString();
|
||||
alarm.Description = dr["Description"].ToString();
|
||||
alarm.Priority = dr["Priority"].ToString();
|
||||
alarm.Device_Id = dr["Device_Id"].ToString();
|
||||
alarm.Gen_Time = Convert.ToDateTime(dr["Generation_Time"]);
|
||||
|
||||
|
||||
return alarm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 向【实时报警】表中插入数据
|
||||
/// </summary>
|
||||
/// <param name="alarm"></param>
|
||||
/// <returns>返回受影响的行数</returns>
|
||||
public static int Insert(Alarm alarm)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
int count = context.Set<Alarm>()
|
||||
.Where(a => a.Point_Id == alarm.Point_Id)
|
||||
.Count();
|
||||
|
||||
if (count > 0) return 0;
|
||||
|
||||
alarm.Gen_Time = DateTime.Now;
|
||||
context.Set<Alarm>()
|
||||
.Add(alarm);
|
||||
|
||||
if (context.SaveChanges() == 1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从【实时报警】表中移除数据记入历史表
|
||||
/// </summary>
|
||||
/// <param name="alarm">当前已结束的报警</param>
|
||||
/// <returns>执行后受影响的行数</returns>
|
||||
public static int Delete(Alarm alarm)
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
int count = context.Set<Alarm>()
|
||||
.Where(a => a.Point_Id == alarm.Point_Id)
|
||||
.Count();
|
||||
|
||||
if(count == 0) return 0;
|
||||
|
||||
AlarmHistory alarmHistory = new AlarmHistory()
|
||||
{
|
||||
Point_Id = alarm.Point_Id,
|
||||
Description = alarm.Description,
|
||||
Priority = alarm.Priority,
|
||||
Device_Id = alarm.Device_Id,
|
||||
Gen_Time = alarm.Gen_Time,
|
||||
End_Time = DateTime.Now,
|
||||
};
|
||||
|
||||
context.Set<AlarmHistory>()
|
||||
.Add(alarmHistory);
|
||||
|
||||
context.Set<Alarm>()
|
||||
.Remove(alarm);
|
||||
|
||||
return context.SaveChanges();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
82
WPFWCSDemo/Utilities/Table/TaskHistoryManager.cs
Normal file
82
WPFWCSDemo/Utilities/Table/TaskHistoryManager.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
|
||||
namespace WPFWCSDemo.Utilities.Table
|
||||
{
|
||||
public class TaskHistoryManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取表数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<TaskHistory> ListAll()
|
||||
{
|
||||
|
||||
using (DataTable? dt = SqlHelper.ExecuteTable("SELECT * FROM TASK_HISTORY ORDER BY CREATETIME DESC"))
|
||||
{
|
||||
if (dt == null || dt.Rows.Count == 0) return null;
|
||||
|
||||
List<TaskHistory> scheduleHistoryManagers = new List<TaskHistory>();
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
scheduleHistoryManagers.Add(ToModels(dr));
|
||||
}
|
||||
|
||||
#region 反射方法
|
||||
/*
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
tasks.Add(dr.DataRowToModel<ScheduleManager>());
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
|
||||
return scheduleHistoryManagers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将表行转换成实体数据
|
||||
/// </summary>
|
||||
/// <param name="dr"></param>
|
||||
/// <returns></returns>
|
||||
public static TaskHistory ToModels(DataRow dr)
|
||||
{
|
||||
if (dr == null) return null;
|
||||
|
||||
TaskHistory taskHistory = new TaskHistory();
|
||||
|
||||
taskHistory.JobId = dr["jobId"].ToString();
|
||||
taskHistory.TaskId = dr["TaskId"].ToString();
|
||||
taskHistory.PalletId = dr["PalletId"].ToString();
|
||||
taskHistory.SourceLocation = dr["SourceLocation"].ToString();
|
||||
taskHistory.TargetLocation = dr["TargetLocation"].ToString();
|
||||
taskHistory.TaskType = dr["TaskType"].ToString();
|
||||
taskHistory.TaskState = dr["TaskState"].ToString();
|
||||
//scheduleHistoryManager.ReportState = (int)dr["ReportResult"];
|
||||
taskHistory.ScheduleState = dr["ScheduleState"].ToString();
|
||||
taskHistory.CreateTime = Convert.ToDateTime(dr["ScheduleTime"]);
|
||||
taskHistory.FinishTime = Convert.ToDateTime(dr["FinishTime"]);
|
||||
//try
|
||||
//{
|
||||
// taskHistory.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
|
||||
// taskHistory.FinishTime = Convert.ToDateTime(dr["FinishTime"]);
|
||||
//}
|
||||
//catch (Exception)
|
||||
//{
|
||||
// //MessageBox.Show("查询的时间内容不能为空!(错误代码:3001)");
|
||||
//}
|
||||
|
||||
|
||||
return taskHistory;
|
||||
}
|
||||
}
|
||||
}
|
||||
184
WPFWCSDemo/Utilities/Table/TaskManager.cs
Normal file
184
WPFWCSDemo/Utilities/Table/TaskManager.cs
Normal file
@@ -0,0 +1,184 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WPFWCSDemo.Data;
|
||||
using WPFWCSDemo.Models.Tables;
|
||||
using WPFWCSDemo.StateCode;
|
||||
|
||||
namespace WPFWCSDemo.Utilities.Table
|
||||
{
|
||||
public class TaskManager
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取【调度管理】表所有行数据集合
|
||||
/// </summary>
|
||||
/// <returns>返回所有行的数据</returns>
|
||||
public static List<TaskRT> ListAll()
|
||||
{
|
||||
|
||||
using (DataTable? dt = SqlHelper.ExecuteTable("SELECT * FROM TASK ORDER BY CREATETIME DESC"))
|
||||
{
|
||||
if (dt == null || dt.Rows.Count == 0) return null;
|
||||
|
||||
List<TaskRT> taskRTs = new List<TaskRT>();
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
taskRTs.Add(ToModels(dr));
|
||||
}
|
||||
|
||||
#region 反射方法
|
||||
/*
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
tasks.Add(dr.DataRowToModel<ScheduleManager>());
|
||||
}
|
||||
*/
|
||||
#endregion
|
||||
|
||||
return taskRTs;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将【调度管理】表的单行转换为实体数据对象
|
||||
/// </summary>
|
||||
/// <param name="dr">获取表的某行数据</param>
|
||||
/// <returns>当前行所有字段的集合</returns>
|
||||
public static TaskRT? ToModels(DataRow dr)
|
||||
{
|
||||
TaskRT taskRT = new TaskRT();
|
||||
|
||||
try
|
||||
{
|
||||
taskRT.JobId = dr["jobId"].ToString();
|
||||
taskRT.TaskId = dr["TaskId"].ToString();
|
||||
//taskRT.PalletId = dr["PalletId"].ToString();
|
||||
//taskRT.Priority = (int)dr["Priority"];
|
||||
taskRT.SourceLocation = dr["SourceLocation"].ToString();
|
||||
taskRT.TargetLocation = dr["TargetLocation"].ToString();
|
||||
taskRT.TaskType = (int)dr["TaskType"];
|
||||
taskRT.TaskState = dr["TaskState"].ToString();
|
||||
taskRT.ScheduleState = dr["ScheduleState"].ToString();
|
||||
taskRT.CreateTime = Convert.ToDateTime(dr["CreateTime"]);
|
||||
taskRT.ScheduleTime = Convert.ToDateTime(dr["ScheduleTime"]);
|
||||
//taskRT.ReportState = (int)dr["ReportState"];
|
||||
|
||||
return taskRT;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Warning($"【TaskManager】实体类型转换失败:{e.Message}");
|
||||
Log.Warning($"【TaskManager】{JsonConvert.SerializeObject(taskRT)}");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 向【调度管理】表中插入数据
|
||||
/// </summary>
|
||||
/// <param name="scheduleManager"></param>
|
||||
/// <returns>返回受影响的行数</returns>
|
||||
public static int Insert(TaskRT taskRT, int type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case 1:
|
||||
return SqlHelper.ExecuteNonQuery("INSERT INTO TASK(TASKID,PalletId,SourceLocation,TARGET,TASKTYPE)" +
|
||||
"VALUES(@TaskId,@PalletId,@SourceLocation,@Target,@TaskType)",
|
||||
new SqlParameter("@TaskId", taskRT.TaskId),
|
||||
new SqlParameter("@PalletId", taskRT.PalletId),
|
||||
new SqlParameter("@SourceLocation", taskRT.SourceLocation),
|
||||
new SqlParameter("@TargetLocation", taskRT.TargetLocation),
|
||||
new SqlParameter("@TaskType", taskRT.TaskType)
|
||||
);
|
||||
|
||||
case 2:
|
||||
return SqlHelper.ExecuteNonQuery("INSERT INTO TASK(TASKID,SourceLocation,TARGETLOCATION,TASKTYPE)" +
|
||||
"VALUES(@TaskId,@Origin,@Target,@TaskType)",
|
||||
new SqlParameter("@TaskId", taskRT.TaskId),
|
||||
new SqlParameter("@SourceLocation", taskRT.SourceLocation),
|
||||
new SqlParameter("@TargetLocation", taskRT.TargetLocation),
|
||||
new SqlParameter("@TaskType", taskRT.TaskType)
|
||||
);
|
||||
|
||||
case 3:
|
||||
return SqlHelper.ExecuteNonQuery("INSERT INTO TASK(TASKID,SourceLocation,TARGETLOCATION,TASKTYPE)" +
|
||||
"VALUES(@TaskId,@Origin,@Target,@TaskType)",
|
||||
new SqlParameter("@TaskId", taskRT.TaskId),
|
||||
new SqlParameter("@SourceLocation", taskRT.SourceLocation),
|
||||
new SqlParameter("@TargetLocation", taskRT.TargetLocation),
|
||||
new SqlParameter("@TaskType", taskRT.TaskType)
|
||||
);
|
||||
default:
|
||||
Log.Error("[Schedule]下发任务错误[Schedule]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 从【调度管理】表中移除数据记入历史表
|
||||
/// </summary>
|
||||
/// <param name="scheduleManager">当前已完成的任务</param>
|
||||
/// <returns>执行后受影响的行数</returns>
|
||||
public static int Delete(TaskRT taskRT)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var context = new AppDbContext();
|
||||
|
||||
TaskHistory taskHistory = new TaskHistory()
|
||||
{
|
||||
JobId = taskRT.JobId,
|
||||
TaskId = taskRT.TaskId,
|
||||
//PalletId = taskRT.PalletId,
|
||||
TaskType = taskRT.TaskType.ToString(),
|
||||
TaskState = taskRT.TaskState,
|
||||
ScheduleState = taskRT.ScheduleState,
|
||||
SourceLocation = taskRT.SourceLocation,
|
||||
TargetLocation = taskRT.TargetLocation,
|
||||
CreateTime = taskRT.CreateTime,
|
||||
ScheduleTime = taskRT.ScheduleTime,
|
||||
FinishTime = DateTime.Now,
|
||||
Id = Guid.NewGuid(),
|
||||
};
|
||||
|
||||
//1--------------向【调度历史】表添加数据
|
||||
context.TaskHistories.Add(taskHistory);
|
||||
|
||||
//2--------------移除【调度管理】表数据
|
||||
context.Remove(taskRT);
|
||||
|
||||
context.SaveChanges();
|
||||
|
||||
return 1;
|
||||
}
|
||||
catch (DBConcurrencyException e)
|
||||
{
|
||||
Log.Error($"【WCS移除已完成任务<异常>】任务号:{taskRT.TaskId},{e.Message}");
|
||||
Log.Error($"【WCS移除已完成任务<异常>】任务号:{taskRT.TaskId},{e.InnerException}");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user