private void WorkSchedule_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'detroitDataSet.Product' table. You can move, or remove it, as needed. this.productTableAdapter.Fill(this.detroitDataSet.Product); // TODO: This line of code loads data into the 'detroitDataSet.AssembLine' table. You can move, or remove it, as needed. this.assembLineTableAdapter.Fill(this.detroitDataSet.AssembLine); // this.table = new DetroitDataSet.WorkScheduleDataTable(); this.table.DefaultView.Sort = "StartTime ASC"; //this.table.DefaultView.Sort = "StartTime ASC"; this.productPlanTable = new DetroitDataSet.ProductDataTable(); this.dgrWorkSched.DataSource = this.productPlanTable; //this.btnRecalc_Click(sender, e); this.lineId = Convert.ToInt32(this.cbLine.SelectedValue); if (fsModule.AccessMode == FormAssessMode.Write) { this.setFormWriteMode(); } else if (fsModule.AccessMode == FormAssessMode.Read) { this.setFormReadMode(); } }
private void recalcWorkSchedule(DateTime start_time, DetroitDataSet.WorkScheduleDataTable table) { table.Clear(); DetroitDataSetTableAdapters.LineQueueTableAdapter lineQueueAdapter = new DetroitDataSetTableAdapters.LineQueueTableAdapter(); DetroitDataSetTableAdapters.SchedulerFrameTableAdapter framesAdapter = new DetroitDataSetTableAdapters.SchedulerFrameTableAdapter(); DetroitDataSet.LineQueueDataTable lineQueueTable = new DetroitDataSet.LineQueueDataTable(); DetroitDataSet.SchedulerFrameDataTable framesTable = new DetroitDataSet.SchedulerFrameDataTable(); lineQueueAdapter.FillBy(lineQueueTable, this.lineId); framesAdapter.FillByFutureFrames(framesTable, start_time); const int NON_WORKING_FRAME = 0; const int WORKING_FRAME = 1; DataRow frame = null; int current_batch = 0; // bath rows counter if (lineQueueTable.Rows.Count > 0) { DataRow batchInQueue = lineQueueTable.Rows[current_batch]; int lineId = Convert.ToInt32(batchInQueue["LineId"]); //------------------------------------------------------------------------------- // Update start time for batches where it's empty //------------------------------------------------------------------------------- // get "BusyTill" time when the line will become free DateTime lineBusyTill = Convert.ToDateTime(lineQueueAdapter.GetLineBusyTill(lineId)); DateTime prev_batchFinishTime = lineBusyTill; // set batches times from "BusyTill" and further for (int i = 0; i < lineQueueTable.Rows.Count; i++) { batchInQueue = lineQueueTable.Rows[i]; if (batchInQueue["StartTime"].ToString() == "" || (Convert.ToDateTime(batchInQueue["StartTime"])).CompareTo(prev_batchFinishTime) < 0) { batchInQueue["StartTime"] = prev_batchFinishTime; batchInQueue["FinishTime"] = DBNull.Value; } if (batchInQueue["FinishTime"].ToString() == "") { batchInQueue["FinishTime"] = ((DateTime)batchInQueue["StartTime"]).AddMinutes( Convert.ToInt32(batchInQueue["Length"]) ); } prev_batchFinishTime = ((DateTime)batchInQueue["FinishTime"]); } //------------------------------------------------------------------------------- // Create table WorkScheduleDataTable //------------------------------------------------------------------------------- // initialize "batchFinishTime" batchInQueue = lineQueueTable.Rows[current_batch]; DateTime batchStartTime = Convert.ToDateTime(batchInQueue["StartTime"]); DateTime batchFinishTime = batchStartTime.AddMinutes(Convert.ToInt32(batchInQueue["Length"])); for ( int current_frame = 0; (current_frame < framesTable.Rows.Count) & (current_batch < (lineQueueTable.Rows.Count)); current_frame++ ) { frame = framesTable.Rows[current_frame]; if (Convert.ToInt32(frame["Type"]) == WORKING_FRAME) { if (Convert.ToDateTime(frame["Start"]).CompareTo(batchStartTime) >= 0) { // shift batch long shift = Convert.ToDateTime(frame["Start"]).Ticks - batchStartTime.Ticks; batchStartTime = Convert.ToDateTime(frame["Start"]); batchFinishTime = batchFinishTime.AddTicks(shift); // save real batch start time // check if its full batch or a part of it DateTime fullLengthFinishTime = batchStartTime.AddMinutes(Convert.ToInt32(batchInQueue["Length"])); if (batchFinishTime.CompareTo(fullLengthFinishTime) == 0) { batchInQueue["StartTime"] = batchStartTime; } string ws_name = "Batch No." + batchInQueue["Nummer"].ToString(); int ws_BatchId = Convert.ToInt32(batchInQueue["BatchId"]); DateTime ws_start = batchStartTime; DateTime ws_finish = new DateTime(0); if (Convert.ToDateTime(frame["Finish"]).CompareTo(batchFinishTime) >= 0) { // batch finish time is = real. It the last part of the batch. ws_finish = batchFinishTime; // save real batch finish time batchInQueue["FinishTime"] = ws_finish; frame["Start"] = batchFinishTime; current_frame--; current_batch++; if (current_batch < (lineQueueTable.Rows.Count)) { batchInQueue = lineQueueTable.Rows[current_batch]; batchStartTime = Convert.ToDateTime(batchInQueue["StartTime"]); batchFinishTime = batchStartTime.AddMinutes( Convert.ToInt32(batchInQueue["Length"]) ); } } else { ws_finish = Convert.ToDateTime(frame["Finish"]); batchStartTime = ws_finish; // frame dequeue automaticaly // batchInQueue["StartTime"] = ws_finish; } // add batch table.AddWorkScheduleRow(ws_name, ws_start, ws_finish, ws_BatchId); } else { DateTime ws_start = Convert.ToDateTime(frame["Start"]); string ws_name = frame["Name"].ToString() + " // свободно"; int ws_BatchId = 0; DateTime ws_finish = new DateTime(0); if (Convert.ToDateTime(frame["Finish"]).CompareTo(batchStartTime) > 0) { ws_finish = batchStartTime; frame["Start"] = ws_finish; current_frame--; } else { ws_finish = Convert.ToDateTime(frame["Finish"]); // frame dequeue automaticaly } // add work frame "свободно" table.AddWorkScheduleRow(ws_name, ws_start, ws_finish, ws_BatchId); } } else { // next row } } // fill NON-WORKING FRAMES into table for (int i = 0; i < framesTable.Rows.Count; i++) { frame = framesTable.Rows[i]; int ws_BatchId = 0; if (Convert.ToInt32(frame["Type"]) == NON_WORKING_FRAME & Convert.ToDateTime(frame["Finish"]) < batchFinishTime) { table.AddWorkScheduleRow( frame["Name"].ToString(), Convert.ToDateTime(frame["Start"]), Convert.ToDateTime(frame["Finish"]), ws_BatchId ); } } // save start and finish times for LineQueue lineQueueAdapter.Update(lineQueueTable); } }