private void LoadTrainList(string pStrPriority) { HashSet<double> lvTrainSet = new HashSet<double>(); DataTable lvDataTrains = null; DataTable lvDataPlans = null; Gene lvGene = null; Segment lvSegment = null; StopLocation lvCurrentStopSegment = null; StopLocation lvNextStopLocation = null; StopLocation lvEndStopLocation = null; double lvMeanSpeed = 0.0; int lvIndex; string lvKey; string lvStrTrainName = ""; int lvCoordinate; int lvDirection; int lvLocation; string lvStrUD; DateTime lvOcupTime; DateTime lvCreationtime; bool lvLogEnable = DebugLog.mEnable; if (pStrPriority.Length > 0) { LoadPriority(pStrPriority); } mTrainList = new List<Gene>(); DebugLog.mEnable = true; DebugLog.Logar(" "); DebugLog.Logar("Listando trens a serem considerados:"); lvDataTrains = TrainmovsegmentDataAccess.GetCurrentTrainsData(mInitialDate, mFinalDate).Tables[0]; foreach (DataRow row in lvDataTrains.Rows) { lvStrTrainName = ((row["name"] == DBNull.Value) ? "" : row["name"].ToString()); if (mTrainAllowed.Contains(lvStrTrainName.Substring(0, 1)) || (mTrainAllowed.Count == 0)) { lvGene = new Gene(mDateRef); lvGene.TrainName = lvStrTrainName; lvGene.TrainId = ((row["train_id"] == DBNull.Value) ? ConnectionManager.DOUBLE_REF_VALUE : (double)row["train_id"]); lvGene.Time = ((row["data_ocup"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["data_ocup"].ToString())); lvGene.Location = ((row["location"] == DBNull.Value) ? Int16.MinValue : Convert.ToInt16(row["location"])); lvGene.UD = ((row["ud"] == DBNull.Value) ? "" : row["ud"].ToString()); lvGene.Direction = ((row["direction"] == DBNull.Value) ? Int16.MinValue : Convert.ToInt16(row["direction"])); lvGene.Track = ((row["track"] == DBNull.Value) ? Int16.MinValue : Convert.ToInt16(row["track"])); lvGene.Coordinate = ((row["coordinate"] == DBNull.Value) ? Int32.MinValue : (int)row["coordinate"]); lvGene.Start = ((row["origem"] == DBNull.Value) ? Int32.MinValue : (int)row["origem"]); lvGene.End = ((row["destino"] == DBNull.Value) ? Int32.MinValue : (int)row["destino"]); lvGene.DepartureTime = ((row["departure_time"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["departure_time"].ToString())); lvCreationtime = ((row["creation_tm"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["creation_tm"].ToString())); if (lvGene.DepartureTime.AddYears(1) < lvCreationtime) { lvGene.DepartureTime = lvCreationtime; } if (lvGene.DepartureTime == DateTime.MinValue) { lvGene.DepartureTime = ((row["plan_departure_time"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["plan_departure_time"].ToString())); } if (lvGene.Start == -99999999) { lvGene.Start = Int32.MinValue; } if (lvGene.End == -99999999) { lvGene.End = Int32.MinValue; } if (!mAllowNoDestinationTrain) { if (lvGene.End == Int32.MinValue) { continue; } } lvCurrentStopSegment = StopLocation.GetCurrentStopSegment(lvGene.Coordinate, lvGene.Direction, out lvIndex); lvGene.StopLocation = lvCurrentStopSegment; lvNextStopLocation = StopLocation.GetNextStopSegment(lvGene.Coordinate, lvGene.Direction); lvEndStopLocation = StopLocation.GetCurrentStopSegment(lvGene.End, lvGene.Direction, out lvIndex); if (lvEndStopLocation == null) { lvEndStopLocation = lvNextStopLocation; } if (lvNextStopLocation == null) { continue; } else if ((lvCurrentStopSegment == lvEndStopLocation) && (lvCurrentStopSegment != null)) { continue; } else if (lvEndStopLocation != null) { if (lvGene.Direction > 0) { if (lvGene.Coordinate >= lvEndStopLocation.Start_coordinate) { continue; } if (lvGene.Coordinate < mInitialValidCoordinate) { continue; } if (lvGene.End > mEndValidCoordinate) { continue; } } else { if (lvGene.Coordinate <= lvEndStopLocation.End_coordinate) { continue; } if (lvGene.Coordinate > mEndValidCoordinate) { continue; } if (lvGene.End < mInitialValidCoordinate) { continue; } } } if (mPriority.Keys.Count > 0) { lvKey = lvGene.TrainName.Substring(0, 1) + lvGene.Direction; if (mPriority.ContainsKey(lvKey)) { lvGene.ValueWeight = mPriority[lvKey]; lvGene.ReloadValue(mDateRef); } } lvMeanSpeed = TrainmovsegmentDataAccess.GetMeanSpeed(lvGene.TrainId, mFinalDate, out lvCoordinate, out lvDirection, out lvLocation, out lvStrUD, out lvOcupTime); lvGene.Speed = lvMeanSpeed; if (lvGene.StopLocation != null) { if (mStopLocationOcupation.ContainsKey(lvCurrentStopSegment)) { //DebugLog.Logar("GetTrainList => Adicionando Gene (" + lvGene + ") na Stop Location (" + lvCurrentStopSegment + ")"); mStopLocationOcupation[lvCurrentStopSegment].Add(lvGene); } if ((lvGene.UD.Equals("CV03B") && (lvGene.Direction == -1)) || (lvGene.UD.Equals("CV03C") && (lvGene.Direction == 1)) || lvGene.UD.StartsWith("SW") || lvGene.UD.Equals("WT")) { if (lvGene.Track <= lvCurrentStopSegment.Capacity) { mStopLocationDeparture[lvCurrentStopSegment][lvGene.Track - 1] = lvGene; } lvGene.StopLocation = null; if (lvGene.Track != 0) { mTrainList.Insert(0, lvGene); lvTrainSet.Add(lvGene.TrainId); DebugLog.Logar("Trem " + lvGene.TrainId + " - " + lvGene.TrainName + " (Partida: " + lvGene.DepartureTime + "; Valor: " + lvGene.Value + "; End: " + lvGene.End + ". Location: " + lvGene.Location + "." + lvGene.UD + ")"); } } else { if (lvGene.Track != 0) { mTrainList.Add(lvGene); lvTrainSet.Add(lvGene.TrainId); DebugLog.Logar("Trem " + lvGene.TrainId + " - " + lvGene.TrainName + " (Partida: " + lvGene.DepartureTime + "; Valor: " + lvGene.Value + "; End: " + lvGene.End + ". Location: " + lvGene.Location + "." + lvGene.UD + ")"); } } } else { if (lvGene.Track != 0) { mTrainList.Insert(0, lvGene); lvTrainSet.Add(lvGene.TrainId); DebugLog.Logar("Trem " + lvGene.TrainId + " - " + lvGene.TrainName + " (Partida: " + lvGene.DepartureTime + "; Valor: " + lvGene.Value + "; End: " + lvGene.End + ". Location: " + lvGene.Location + "." + lvGene.UD + ")"); } } } } mPlanList = new List<Gene>(); DebugLog.Logar(" ------------------------------------------------------------------------------------------------------ "); DebugLog.Logar(" "); DebugLog.Logar("Listando Planos a serem considerados:"); if (DateTime.Now.Date == mInitialDate.Date) { lvDataPlans = PlanDataAccess.GetCurrentPlans(DateTime.Now, mFinalDate.AddDays(1)).Tables[0]; } else { lvDataPlans = PlanDataAccess.GetCurrentPlans(mFinalDate, mFinalDate.AddDays(1)).Tables[0]; } foreach (DataRow row in lvDataPlans.Rows) { lvGene = new Gene(mDateRef); lvGene.TrainId = ((row["plan_id"] == DBNull.Value) ? ConnectionManager.DOUBLE_REF_VALUE : (double)row["plan_id"]); if (!lvTrainSet.Contains(lvGene.TrainId)) { lvGene.TrainName = ((row["train_name"] == DBNull.Value) ? "" : row["train_name"].ToString()); if (mTrainAllowed.Contains(lvGene.TrainName.Substring(0, 1)) || (mTrainAllowed.Count == 0)) { if (lvGene.TrainName.Trim().Length == 0) continue; lvGene.Start = ((row["origem"] == DBNull.Value) ? Int32.MinValue : (int)row["origem"]); lvGene.End = ((row["destino"] == DBNull.Value) ? Int32.MinValue : (int)row["destino"]); lvGene.DepartureTime = ((row["departure_time"] == DBNull.Value) ? DateTime.MinValue : DateTime.Parse(row["departure_time"].ToString())); lvGene.Time = DateTime.MinValue; lvGene.Coordinate = lvGene.Start; lvGene.Direction = Int16.Parse(lvGene.TrainName.Substring(1)); lvGene.Value = 1; if ((lvGene.Direction % 2) == 0) { lvGene.Direction = -1; } else { lvGene.Direction = 1; } if (lvGene.Direction > 0) { if (lvGene.Start < mInitialValidCoordinate) { lvGene.Start = mInitialValidCoordinate; lvGene.Coordinate = lvGene.Start; } if (lvGene.End > mEndValidCoordinate) { lvGene.End = mEndValidCoordinate; } } else { if (lvGene.Start > mEndValidCoordinate) { lvGene.Start = mEndValidCoordinate; lvGene.Coordinate = lvGene.Start; } if (lvGene.End < mInitialValidCoordinate) { lvGene.End = mInitialValidCoordinate; } } lvSegment = Segment.GetCurrentSegment(lvGene.Coordinate, lvGene.Direction, 1, out lvIndex); if (lvSegment != null) { lvGene.Location = (short)lvSegment.Location; lvGene.UD = lvSegment.SegmentValue; lvGene.Track = 1; lvCurrentStopSegment = StopLocation.GetCurrentStopSegment(lvGene.Coordinate, lvGene.Direction, out lvIndex); lvGene.StopLocation = lvCurrentStopSegment; } else { DebugLog.Logar("Não tem segment !"); } if (mPriority.Keys.Count > 0) { lvKey = lvGene.TrainName.Substring(0, 1) + lvGene.Direction; if (mPriority.ContainsKey(lvKey)) { lvGene.ValueWeight = mPriority[lvKey]; } } if (mTrainAllowed.Count == 0) { mPlanList.Add(lvGene); DebugLog.Logar("Plano " + lvGene.TrainId + " - " + lvGene.TrainName + " (Partida: " + lvGene.DepartureTime + ", Track: " + lvGene.Track + ")"); } else if (mTrainAllowed.Contains(lvGene.TrainName.Substring(0, 1))) { mPlanList.Add(lvGene); DebugLog.Logar("Plano " + lvGene.TrainId + " - " + lvGene.TrainName + " (Partida: " + lvGene.DepartureTime + ", Track: " + lvGene.Track + ")"); } } } } DebugLog.Logar(" --------------------------------------------------------------------------------------------- "); DebugLog.Logar(" "); DebugLog.mEnable = lvLogEnable; }