Esempio n. 1
0
        void FindEqualsByData()
        {
            if (_list != null)
            {
                _list.Sort(new TimeRangeComparer());


                _HwgrToWgr first = null, second = null;

                for (int i = 0; i < _list.Count; i++)
                {
                    if (_list[i].IsDeleted)
                    {
                        continue;
                    }

                    if (first == null)
                    {
                        first = _list[i];
                        continue;
                    }
                    if (second == null)
                    {
                        second = _list[i];
                        if (first.IsEqualByData(second))
                        {
                            second.BeginTime = first.BeginTime;
                            first.Delete();
                        }

                        first  = second;
                        second = null;
                    }
                }
            }

            foreach (_HwgrToWgr var in _list)
            {
                if (var.BeginTime >= var.EndTime)
                {
                    var.Delete();
                }
            }

            _list.Sort(new Comparison <_HwgrToWgr>(delegate(_HwgrToWgr a, _HwgrToWgr b)
            {
                return((a.EndTime > b.EndTime) ? 1 : 0);
            }));
            if (_list[0].IsDeleted && _list[0].Entity.Import)
            {
                _list[0].UnDelete();
            }

            _list.Sort(new Comparison <_HwgrToWgr>(delegate(_HwgrToWgr a, _HwgrToWgr b)
            {
                return(a.BeginTime < b.BeginTime ? 1 : 0);
            }));
            if (_list[0].IsDeleted && _list[0].Entity.Import)
            {
                _list[0].UnDelete();
            }

            _list.Sort(new Comparison <_HwgrToWgr>(delegate(_HwgrToWgr a, _HwgrToWgr b)
            {
                return((a.HwgrID == b.HwgrID)
                    ? (a.BeginTime < b.BeginTime ? 1: 0)
                    : (a.HwgrID >= b.HwgrID ? 1 : 0));
            }));

            /*
             * if (_list.Count > 1)
             *  for (int i=1; i < _list.Count; i++)
             *      if (_list[i - 1].HwgrID == _list[i].HwgrID
             *          && (_list[i - 1].EndTime.AddDays(1) == _list[i].BeginTime
             || _list[i-1].BeginTime == _list[i].BeginTime)
             ||         )
             ||     {
             ||         if ((_list[i - 1].IsCreated || !_list[i - 1].IsDeleted) && !_list[i].IsDeleted)
             ||         {
             ||             if (_list[i - 1].EndTime < _list[i].EndTime)
             ||                 _list[i - 1].EndTime = _list[i].EndTime;
             ||             _list[i].Delete();
             ||         }
             ||         else if ((_list[i].IsCreated || !_list[i].IsDeleted) && !_list[i - 1].IsDeleted)
             ||         {
             ||             if (_list[i].EndTime < _list[i - 1].EndTime)
             ||                 _list[i].EndTime = _list[i-1].EndTime;
             ||             _list[i-1].Delete();
             ||         }
             ||     }*/
            _list.Sort(new Comparison <_HwgrToWgr>(delegate(_HwgrToWgr a, _HwgrToWgr b)
            {
                return(a.BeginTime < b.BeginTime ? 1 : 0);
            }));

            if (_list.Count > 1)
            {
                for (int i = 1; i < _list.Count; i++)
                {
                    if (_list[i].IsDeleted && _list[i - 1].EndTime.AddDays(1) == _list[i].BeginTime)
                    {
                        _list[i].UnDelete();
                    }
                }
            }

            /*
             * foreach (_HwgrToWgr var in _list)
             *  if (var.IsCreated && var.IsDeleted)
             *      _list.Remove(var);
             */
        }
Esempio n. 2
0
        public void Execute()
        {
            LoadEntities();

            if (_list.Count > 0)
            {
                _list.Sort(new TimeRangeComparer());
                _HwgrToWgr newItem     = new _HwgrToWgr(_entity);
                _HwgrToWgr currentItem = null;
                for (int i = 0; i < _list.Count; i++)
                {
                    currentItem = _list[i];
                    if (currentItem.IsIntersectRanges(newItem))
                    {
                        if (currentItem.IsIncludeRange(newItem))
                        {
                            _HwgrToWgr n = currentItem.CreateCopy();

                            currentItem.EndTime = newItem.BeginTime.AddDays(-1);
                            n.BeginTime         = newItem.EndTime.AddDays(1);

                            if (!currentItem.IsValid)
                            {
                                currentItem.Delete();
                            }

                            _list.Add(newItem);
                            if (n.IsValid)
                            {
                                _list.Add(n);
                            }

                            break;
                        }
                        else
                        {
                            currentItem.EndTime = newItem.BeginTime.AddDays(-1);

                            if (currentItem.IsValid)
                            {
                                currentItem.Delete();
                            }

                            for (int j = i + 1; j < _list.Count; j++)
                            {
                                currentItem = _list[j];
                                if (currentItem.IsIncludeDate(newItem.EndTime))
                                {
                                    currentItem.BeginTime = newItem.EndTime.AddDays(1);
                                    if (currentItem.IsValid)
                                    {
                                        currentItem.Delete();
                                    }
                                }
                                else
                                {
                                    currentItem.Delete();
                                }
                            }
                            _list.Add(newItem);
                            break;
                        }
                    }
                }


                FindEqualsByData();


                InsertOrUpdateOrDelete();
            }
        }