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
{
///
/// 获取表数据
///
///
public static List ListAll()
{
using (DataTable? dt = SqlHelper.ExecuteTable("SELECT * FROM TASK_HISTORY ORDER BY CREATETIME DESC"))
{
if (dt == null || dt.Rows.Count == 0) return null;
List scheduleHistoryManagers = new List();
foreach (DataRow dr in dt.Rows)
{
scheduleHistoryManagers.Add(ToModels(dr));
}
#region 反射方法
/*
foreach (DataRow dr in dt.Rows)
{
tasks.Add(dr.DataRowToModel());
}
*/
#endregion
return scheduleHistoryManagers;
}
}
///
/// 将表行转换成实体数据
///
///
///
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;
}
}
}