我需要创建一个调度应用程序,该应用程序将从 Access 查询中提取信息,该查询以递减优先级和升序日期进行排序,以获取要添加的顺序,然后按行和列遍历查询(第一步向下,然后向下第二步,然后向下第三步步骤)并将它们添加到单个ArrayList
.
字段是
优先 DueDate JobsSequence1 ProcTime JobsSequence2 ProcTime ... 1 2015 年 4 月 28 日 Job1Milling1 1 Job1CNC2 1 Job1Drilling3 1 1 2015 年 4 月 28 日 Job2Milling1 1 Job2Drilling2 1 Job2Milling3 1 0 2015 年 4 月 29 日 Job3Drilling1 1 Job3CNC2 1 Job3Milling3 1
我需要将它们添加到ArrayList
一个ConsoleApp
或Windows Form
计算一个时间表。我想用的逻辑。
- 使用处理时间进行初始化
ArrayList
。 - 检查上一个作业步骤
- 检查上一个工作站步骤
- 采取最大工作步骤和工作站步骤并增加处理时间
想出:这个列表是ArrayList
已经运行的逻辑的示例。
作业结束时间 工作1铣削1 1 工作2铣削1 2 Job3Drilling1 1 工作1CNC2 2 Job2Drilling2 3 工作3CNC2 3 工作1钻孔3 4 工作2铣削3 4 工作3铣削3 5 工作1完成4 5 工作2完成4 6 工作3完成4 7
新的数字ArrayList
将在早上 8 点添加到一天的开始。所以第一份工作将在上午 9 点结束。第二份工作将在上午 10 点结束。第三次将在上午 9 点结束。
我的问题是,如何像示例中那样将查询添加到数组列表中?然后如何通过从上面运行我的逻辑来计算结束时间?最后,我如何将其导出回显示上述列表的报告,其中包含开始时间(结束时间减去过程时间)和结束时间。
更新 我尝试了其中的一部分,并且能够使用一点 linq。
我不确定如何使用 .AddRange() 将 Jobs 中的特定字段添加到 JobListOrder。我想将所有工作站放在一列中并引用 JobNum 和 ProcTime 以便能够计算 EndTime。如上表。
接下来,我不确定如何检查 Max(Max of Current Jobnum (JobListOrder.EndTime) && Max of Current Workstation (JobListOrder.EndTime)) 然后添加 ProcTime
例如,取所有 Job1 并取最大值,然后取所有 Milling 并取最大值。取这两个中的最大值并添加 ProcTime。
class Program
{
//Add class
public class Jobs
{
public int JobNum { get; set; }
public int Priority { get; set; }
public DateTime DueDate { get; set; }
public string WS1 { get; set; }
public int Seq1 { get; set; }
public string WS2 { get; set; }
public int Seq2 { get; set; }
public string WS3 { get; set; }
public int Seq3 { get; set; }
public string WS4 { get; set; }
public int Seq4 { get; set; }
}
public class JobListOrder
{
public int JobNum { get; set; }
public string Workstation { get; set; }
public int Sequence { get; set; }
public int ProcTime { get; set; }
public int EndHour { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
}
// Create data source for testing
static List<Jobs> jobs = new List<Jobs>
{
new Jobs {JobNum = 1, Priority = 0, DueDate = DateTime.Today, WS1 = "Milling", Seq1 = 1, WS2 = "CNC", Seq2 = 1, WS3 = "Drilling", Seq3 = 1, WS4 = "Finish", Seq4 = 1 },
new Jobs {JobNum = 2, Priority = 0, DueDate = DateTime.Today, WS1 = "Milling", Seq1 = 2, WS2 = "Drilling", Seq2 = 1, WS3 = "Milling", Seq3 = 1, WS4 = "Finish", Seq4 = 1 },
new Jobs {JobNum = 3, Priority = 1, DueDate = DateTime.Today, WS1 = "Drilling", Seq1 = 1, WS2 = "CNC", Seq2 = 1, WS3 = "Milling", Seq3 = 1, WS4 = "Finish", Seq4 = 1 }
};
static void Main(string[] args)
{
//Sort by Priority then Due Date
IEnumerable<Jobs> jobquery =
from jobnum in jobs
orderby jobnum.Priority descending
orderby jobnum.DueDate ascending
select jobnum;
//Write to new list that sorts in job order
List<Jobs> JobORder = new List<Jobs>;
foreach ()
//Calculate the EndTime in JobsOrder
// ****Take Max(Max of Current Jobnum (JobListOrder.EndTime) && Max of Current Workstation (JobListOrder.EndTime)) then add ProcTime****
//Select Jobs with "Milling" in JobListOrder
IEnumerable<JobListOrder> MillingQuery =
from jobnum1 in jobquery
where jobnum1.Workstation == "Milling"
select jobnum1;
//Select Jobs with "Drilling" in JobListOrder
IEnumerable<JobListOrder> DrillingQuery =
from jobnum2 in jobquery
where jobnum2.Workstation == "Drilling"
select jobnum2;
//Select Jobs with "CNC" in JobListOrder
IEnumerable<JobListOrder> CNCQuery =
from jobnum3 in jobquery
where jobnum3.Workstation == "CNC"
select jobnum3;
//Select Jobs with "Finish" in JobListOrder
IEnumerable<JobListOrder> FinishQuery =
from jobnum4 in jobquery
where jobnum4.Workstation == "Finish"
select jobnum4;
//foreach (Jobs jobnum1 in FinishQuery)
//{
// Console.WriteLine("Job number is {0}, Station ID is {1}, Proc Time is {2}, Date is {3}", jobnum1.JobNum, jobnum1.WS1, jobnum1.Seq1, jobnum1.DueDate.AddHours(jobnum1.Seq1));
//}
Console.ReadLine();
}