Esempio n. 1
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                return(null);
            }

            //  Message:起始杆号可选项删选
            if (values.Length == 4)
            {
                //  Message:起始站
                TyeBaseSiteEntity start = values[0] as TyeBaseSiteEntity;

                //  Message:结束站
                TyeBaseSiteEntity end = values[1] as TyeBaseSiteEntity;

                if (start == null || end == null)
                {
                    return(null);
                }

                if (start.ID != end.ID)
                {
                    return(null);
                }

                string stationID = start.ID;

                //  Message:当前站杆号列表
                List <TyeBasePillarEntity> rods = (values[3] as ObservableCollection <TyeBasePillarEntity>).ToList();

                //  Message:任务列表哦
                ObservableCollection <TaskView4CModel> collection = values[2] as ObservableCollection <TaskView4CModel>;


                //  Message:查找当前站的所有任务信息
                var finds = collection.ToList().FindAll(l => l.StartSite.ID == stationID && l.EndSite.ID == stationID);

                if (finds == null)
                {
                    return(rods);
                }

                foreach (var item in finds)
                {
                    if (item.StartPole == null || item.EndPole == null)
                    {
                        continue;
                    }

                    var startIndex = rods.FindIndex(l => l.PoleCode == item.StartPole.PoleCode);

                    var endIndex = rods.FindIndex(l => l.PoleCode == item.EndPole.PoleCode);

                    if (startIndex < 0 || endIndex < 0)
                    {
                        continue;
                    }

                    if (startIndex == endIndex)
                    {
                        rods.RemoveAt(startIndex);
                    }
                    else
                    {
                        rods.RemoveRange(startIndex, endIndex - startIndex + 1);
                    }
                }

                return(rods);
            }

            //  Message:结束杆号可选项删选
            else if (values.Length == 5)
            {
                //  Message:起始站
                TyeBaseSiteEntity start = values[0] as TyeBaseSiteEntity;

                //  Message:结束站
                TyeBaseSiteEntity end = values[1] as TyeBaseSiteEntity;

                //  Message:上一个杆号
                TyeBasePillarEntity r = values[2] as TyeBasePillarEntity;

                List <TyeBasePillarEntity> lastList = (values[3] as List <TyeBasePillarEntity>);

                if (start == null || end == null)
                {
                    return(null);
                }

                if (lastList == null)
                {
                    return(null);
                }

                if (r == null)
                {
                    return(null);
                }

                if (start.ID != end.ID)
                {
                    return(null);
                }

                if (values[4] == null)
                {
                    return(null);
                }

                string stationID = start.ID;

                //  Message:当前站所有杆号
                List <TyeBasePillarEntity> allrods = (values[4] as ObservableCollection <TyeBasePillarEntity>).Where(l => l.SiteID == stationID).ToList();

                //  Message:上一个杆号可选择列表
                List <TyeBasePillarEntity> rods = lastList.ToList();


                int index = rods.FindIndex(l => l.ID == r.ID);

                //  Message:从当前选择的开始截取
                rods = rods.Skip(index).ToList();

                for (int i = 0; i < rods.Count; i++)
                {
                    if (i == 0)
                    {
                        continue;
                    }

                    int lastIndex = allrods.ToList().FindIndex(l => l.ID == rods[i - 1].ID);

                    int currentIndex = allrods.ToList().FindIndex(l => l.ID == rods[i].ID);

                    if ((currentIndex - lastIndex) > 1)
                    {
                        rods = rods.Take(rods.FindIndex(l => l.ID == rods[i - 1].ID) + 1).ToList();
                        break;
                    }
                }

                //if (r == null) return null;

                ////  Message:当前站所有杆号
                //List<TyeBasePillarEntity> rods = (values[4] as ObservableCollection<TyeBasePillarEntity>).ToList();

                ////  Message:任务列表
                //ObservableCollection<TaskViewModel> collection = values[3] as ObservableCollection<TaskViewModel>;

                //var index = rods.FindIndex(l => l.PoleCode == r.PoleCode);

                ////  Message:查找当前站的所有任务信息
                //var finds = collection.ToList().FindAll(l => l.StartSite.ID == stationID && l.EndSite.ID == stationID);


                //if (finds == null)
                //{
                //    return rods.Skip(index);
                //}

                //rods = rods.Skip(index).ToList();

                //foreach (var item in finds)
                //{
                //    if (item.StartPole == null || item.EndPole == null) continue;

                //    var startIndex = rods.FindIndex(l => l.PoleCode == item.StartPole.PoleCode);

                //    var endIndex = rods.FindIndex(l => l.PoleCode == item.EndPole.PoleCode);

                //    if (startIndex < 0 || endIndex < 0) continue;

                //    if (startIndex == endIndex)
                //    {
                //        rods.RemoveAt(startIndex);
                //    }
                //    else
                //    {
                //        rods.RemoveRange(startIndex, rods.Count - startIndex);
                //    }
                //}

                return(rods);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            if (values == null)
            {
                return(null);
            }

            if (values.Length == 4)
            {
                TyeBaseSiteEntity start = values[0] as TyeBaseSiteEntity;
                TyeBaseSiteEntity end   = values[1] as TyeBaseSiteEntity;

                if (start == null || end == null)
                {
                    return(null);
                }

                if (start.ID != end.ID)
                {
                    return(null);
                }

                string stationName = start.SiteName;

                List <TyeBasePillarEntity> rods = (values[3] as ObservableCollection <TyeBasePillarEntity>).ToList();

                ObservableCollection <TaskModel> collection = values[2] as ObservableCollection <TaskModel>;


                //  Message:查找当前站的所有任务信息
                var finds = collection.ToList().FindAll(l => l.StartSite.SiteName == stationName && l.EndSite.SiteName == stationName);

                if (finds == null)
                {
                    return(rods);
                }

                foreach (var item in finds)
                {
                    var startIndex = rods.FindIndex(l => l.PoleCode == item.StartPole.PoleCode);

                    var endIndex = rods.FindIndex(l => l.PoleCode == item.EndPole.PoleCode);

                    if (startIndex < 0 || endIndex < 0)
                    {
                        continue;
                    }

                    if (startIndex == endIndex)
                    {
                        rods.RemoveAt(startIndex);
                    }
                    else
                    {
                        rods.RemoveRange(startIndex, endIndex - startIndex);
                    }
                }

                return(rods);
            }
            else if (values.Length == 5)
            {
                TyeBaseSiteEntity start = values[0] as TyeBaseSiteEntity;
                TyeBaseSiteEntity end   = values[1] as TyeBaseSiteEntity;

                if (start == null || end == null)
                {
                    return(null);
                }

                if (start.ID != end.ID)
                {
                    return(null);
                }

                string stationName = start.SiteName;

                TyeBasePillarEntity r = values[2] as TyeBasePillarEntity;

                if (r == null)
                {
                    return(null);
                }

                List <TyeBasePillarEntity> rods = (values[4] as ObservableCollection <TyeBasePillarEntity>).ToList();

                ObservableCollection <TaskModel> collection = values[3] as ObservableCollection <TaskModel>;

                var index = rods.FindIndex(l => l.PoleCode == r.PoleCode);

                //  Message:查找当前站的所有任务信息
                var finds = collection.ToList().FindAll(l => l.StartSite.SiteName == stationName && l.EndSite.SiteName == stationName);

                if (finds == null)
                {
                    return(rods.Skip(index));
                }

                rods = rods.Skip(index).ToList();

                foreach (var item in finds)
                {
                    var startIndex = rods.FindIndex(l => l.PoleCode == item.StartPole.PoleCode);
                    var endIndex   = rods.FindIndex(l => l.PoleCode == item.EndPole.PoleCode);

                    if (startIndex < 0 || endIndex < 0)
                    {
                        continue;
                    }

                    if (startIndex == endIndex)
                    {
                        rods.RemoveAt(startIndex);
                    }
                    else
                    {
                        rods.RemoveRange(startIndex, rods.Count - startIndex);
                    }
                }

                return(rods);
            }
            else
            {
                return(null);
            }
        }