我需要创建一个调度应用程序,它将从Access查询中提取信息,该查询按降序优先级和升序日期排序以获取要添加的订单,然后按行然后按列遍历查询(向下第一步然后向下第二步)然后下来第三步)并将它们添加到单个ArrayList
。
字段是
Priority DueDate JobsSequence1 ProcTime JobsSequence2 ProcTime ... 1 4/28/2015 Job1Milling1 1 Job1CNC2 1 Job1Drilling3 1 1 4/28/2015 Job2Milling1 1 Job2Drilling2 1 Job2Milling3 1 0 4/29/2015 Job3Drilling1 1 Job3CNC2 1 Job3Milling3 1
我需要将它们添加到ArrayList
或ConsoleApp
中的Windows Form
来计算时间表。我想使用。的逻辑。
ArrayList
。想出:
此列表是ArrayList
在已运行逻辑时的样子的示例。
Job EndTime Job1Milling1 1 Job2Milling1 2 Job3Drilling1 1 Job1CNC2 2 Job2Drilling2 3 Job3CNC2 3 Job1Drilling3 4 Job2Milling3 4 Job3Milling3 5 Job1Finish4 5 Job2Finish4 6 Job3Finish4 7
新ArrayList
的数字将在当天早上8点添加。所以第一份工作将在上午9点结束。第二份工作将在上午10点结束。第三个将在上午9点结束。
我的问题是,如何将查询添加到arraylist,就像我在示例中的方式一样?然后我如何通过从上面运行我的逻辑来计算结束时间?最后,如何将其导出回报告,该报告显示上面的列表,包括开始时间(结束时间减去过程时间)和结束时间。
更新 我尝试了它的一部分,我能够使用一点linq。
我不确定如何使用.AddRange()将Job中的特定字段添加到JobListOrder。我想将所有工作站放在一列中,并引用JobNum和ProcTime来计算EndTime。如上表所示。
接下来,我不确定如何检查Max(当前Jobnum的最大值(JobListOrder.EndTime)和当前工作站的最大值(JobListOrder.EndTime))然后添加ProcTime
示例,取所有Job1并取max,然后取全部铣削并取最大值。取这两个中的最大值并添加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();
}