Files
FT479/WPFWCSDemo/Utilities/Table/TaskHistoryManager.cs
2026-06-29 14:46:32 +08:00

83 lines
2.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}