コード例 #1
0
ファイル: ReserveDataEx.cs プロジェクト: nekopanda/EDCB
        public EpgEventInfo SearchEventInfoLikeThat()
        {
            double       dist = double.MaxValue, dist1;
            EpgEventInfo eventPossible = null;

            UInt64 key = Create64Key();

            if (CommonManager.Instance.DB.ServiceEventList.ContainsKey(key) == true)
            {
                foreach (EpgEventInfo eventChkInfo in CommonManager.Instance.DB.ServiceEventList[key].eventList)
                {
                    dist1 = Math.Abs((StartTime - eventChkInfo.start_time).TotalSeconds);
                    double overlapLength = MenuUtil.CulcOverlapLength(StartTime, DurationSecond,
                                                                      eventChkInfo.start_time, eventChkInfo.durationSec);

                    //開始時間が最も近いものを選ぶ。同じ差なら時間が前のものを選ぶ
                    if (overlapLength >= 0 && (dist > dist1 ||
                                               dist == dist1 && (eventPossible == null || StartTime > eventChkInfo.start_time)))
                    {
                        dist          = dist1;
                        eventPossible = eventChkInfo;
                        if (dist == 0)
                        {
                            break;
                        }
                    }
                }
            }

            return(eventPossible);
        }
コード例 #2
0
        /// <summary>
        /// 予約情報の再描画
        /// </summary>
        private void ReloadReserveViewItem()
        {
            try
            {
                tunerReserveView.ClearInfo();
                tunerReserveTimeView.ClearInfo();
                tunerReserveNameView.ClearInfo();
                reserveList.Clear();

                var tunerList = new List <PanelItem <TunerReserveInfo> >();
                var timeSet   = new HashSet <DateTime>();

                List <TunerReserveInfo> tunerReserveList = CommonManager.Instance.DB.TunerReserveList.Values
                                                           .OrderBy(info => info.tunerID).ToList();//多分大丈夫だけど一応ソートしておく
                if (Settings.Instance.TunerDisplayOffReserve == true)
                {
                    var tuner_off = new TunerReserveInfo();
                    tuner_off.tunerID     = 0xFFFFFFFF;//IDの表示判定に使っている
                    tuner_off.tunerName   = "無効予約";
                    tuner_off.reserveList = CommonManager.Instance.DB.ReserveList.Values
                                            .Where(info => info.IsEnabled == false).Select(info => info.ReserveID).ToList();
                    tunerReserveList.Add(tuner_off);
                }

                //チューナ不足と無効予約はアイテムがなければ非表示
                tunerReserveList.RemoveAll(item => item.tunerID == 0xFFFFFFFF && item.reserveList.Count == 0);

                double singleWidth = Settings.Instance.TunerWidth;
                double leftPos     = 0;
                var    resDic      = CommonManager.Instance.DB.ReserveList;
                tunerReserveList.ForEach(info =>
                {
                    var cols = new List <List <ReserveViewItem> >();
                    foreach (ReserveData resInfo in info.reserveList.Where(id => resDic.ContainsKey(id) == true).Select(id => resDic[id]).OrderBy(res => res.Create64Key()))//.ThenBy(res => res.StartTimeActual))
                    {
                        var newItem = new TunerReserveViewItem(resInfo)
                        {
                            Width = singleWidth
                        };
                        reserveList.Add(newItem);

                        //横位置の設定・列を拡げて表示する処置
                        var addCol = cols.FindIndex(col => col.All(item =>
                                                                   MenuUtil.CulcOverlapLength(resInfo.StartTime, resInfo.DurationSecond, item.Data.StartTime, item.Data.DurationSecond) <= 0));
                        if (addCol < 0)
                        {
                            addCol = cols.Count;
                            cols.Add(new List <ReserveViewItem>());
                        }
                        cols[addCol].Add(newItem);
                        newItem.LeftPos = leftPos + addCol * singleWidth;

                        //マージン込みの時間でリストを構築
                        ViewUtil.AddTimeList(timeSet, resInfo.StartTimeActual, resInfo.DurationActual);
                    }
                    double tunerWidth = singleWidth * Math.Max(1, cols.Count);
                    tunerList.Add(new PanelItem <TunerReserveInfo>(info)
                    {
                        Width = tunerWidth
                    });
                    leftPos += tunerWidth;
                });

                //縦位置の設定
                var timeList = new List <DateTime>(timeSet.OrderBy(time => time));

                reserveList.ForEach(item =>
                {
                    ViewUtil.SetItemVerticalPos(timeList, item, item.Data.StartTimeActual, item.Data.DurationActual, Settings.Instance.TunerMinHeight, true);

                    //ごく小さいマージンの表示を抑制する。
                    item.TopPos = Math.Round(item.TopPos);
                    item.Height = Math.Round(item.Height);
                });

                //最低表示行数を適用。また、最低表示高さを確保して、位置も調整する。
                ViewUtil.ModifierMinimumLine(reserveList, Settings.Instance.TunerMinimumLine, Settings.Instance.TunerFontSizeService, Settings.Instance.TunerBorderTopSize);

                //必要時間リストの修正。最低表示行数の適用で下に溢れた分を追加する。
                ViewUtil.AdjustTimeList(reserveList, timeList, Settings.Instance.TunerMinHeight);

                tunerReserveTimeView.SetTime(timeList, false, true);
                tunerReserveNameView.SetTunerInfo(tunerList);
                tunerReserveView.SetReserveList(reserveList,
                                                leftPos,
                                                timeList.Count * 60 * Settings.Instance.TunerMinHeight);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
        }
コード例 #3
0
        /// <summary>
        /// 予約情報の再描画
        /// </summary>
        private void ReloadReserveViewItem()
        {
            try
            {
                tunerReserveView.ClearInfo();
                tunerReserveTimeView.ClearInfo();
                tunerReserveNameView.ClearInfo();
                List <DateTime> timeList = new List <DateTime>();
                tunerList.Clear();
                reserveList.Clear();

                List <TunerReserveInfo> tunerReserveList = CommonManager.Instance.DB.TunerReserveList.Values
                                                           .OrderBy(info => info.tunerID).ToList();//多分大丈夫だけど一応ソートしておく
                if (Settings.Instance.TunerDisplayOffReserve == true)
                {
                    var tuner_off = new TunerReserveInfo();
                    tuner_off.tunerID     = 0xFFFFFFFF;//IDの表示判定に使っている
                    tuner_off.tunerName   = "無効予約";
                    tuner_off.reserveList = CommonManager.Instance.DB.ReserveList.Values
                                            .Where(info => info.IsEnabled == false).Select(info => info.ReserveID).ToList();
                    tunerReserveList.Add(tuner_off);
                }

                //チューナ不足と無効予約はアイテムがなければ非表示
                var delList = tunerReserveList.Where(item => item.tunerID == 0xFFFFFFFF && item.reserveList.Count == 0).ToList();
                delList.ForEach(item => tunerReserveList.Remove(item));

                double tunerWidthSingle = Settings.Instance.TunerWidth;
                double leftPos          = 0;
                tunerReserveList.ForEach(info =>
                {
                    double tunerWidth = tunerWidthSingle;

                    var tunerAddList = new List <ReserveViewItem>();
                    foreach (UInt32 reserveID in info.reserveList)
                    {
                        ReserveData reserveInfo;
                        if (CommonManager.Instance.DB.ReserveList.TryGetValue(reserveID, out reserveInfo) == false)
                        {
                            continue;
                        }
                        var newItem = new ReserveViewItem(reserveInfo);

                        //マージンを適用
                        DateTime startTime = reserveInfo.StartTime;
                        Int32 duration     = (Int32)reserveInfo.DurationSecond;
                        ViewUtil.ApplyMarginForTunerPanelView(reserveInfo, ref startTime, ref duration);

                        newItem.Height  = duration * Settings.Instance.TunerMinHeight / 60;
                        newItem.Width   = tunerWidthSingle;
                        newItem.LeftPos = leftPos;

                        foreach (ReserveViewItem addedItem in tunerAddList)
                        {
                            ReserveData addedInfo = addedItem.ReserveInfo;

                            //マージンを適用
                            DateTime startTimeAdd = addedInfo.StartTime;
                            Int32 durationAdd     = (Int32)addedInfo.DurationSecond;
                            ViewUtil.ApplyMarginForTunerPanelView(addedInfo, ref startTimeAdd, ref durationAdd);

                            if (MenuUtil.CulcOverlapLength(startTime, (UInt32)duration, startTimeAdd, (UInt32)durationAdd) > 0)
                            {
                                if (newItem.LeftPos <= addedItem.LeftPos)
                                {
                                    if (reserveInfo.Create64Key() == addedInfo.Create64Key())
                                    {
                                        newItem.LeftPos = addedItem.LeftPos;
                                    }
                                    else
                                    {
                                        newItem.LeftPos = addedItem.LeftPos + tunerWidthSingle;
                                        if (newItem.LeftPos - leftPos >= tunerWidth)
                                        {
                                            tunerWidth += tunerWidthSingle;
                                        }
                                    }
                                }
                            }
                        }

                        reserveList.Add(newItem);
                        tunerAddList.Add(newItem);

                        //必要時間リストの構築
                        var chkStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0);
                        DateTime EndTime = startTime.AddSeconds(duration);
                        while (chkStartTime <= EndTime)
                        {
                            int index = timeList.BinarySearch(chkStartTime);
                            if (index < 0)
                            {
                                timeList.Insert(~index, chkStartTime);
                            }
                            chkStartTime = chkStartTime.AddHours(1);
                        }
                    }

                    tunerList.Add(new TunerNameViewItem(info, tunerWidth));
                    leftPos += tunerWidth;
                });

                //表示位置設定
                foreach (ReserveViewItem item in reserveList)
                {
                    //マージンを適用
                    DateTime startTime = item.ReserveInfo.StartTime;
                    Int32    dummy     = 0;
                    ViewUtil.ApplyMarginForTunerPanelView(item.ReserveInfo, ref startTime, ref dummy);

                    var chkStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0);
                    int index        = timeList.BinarySearch(chkStartTime);
                    if (index >= 0)
                    {
                        item.TopPos = (index * 60 + (startTime - chkStartTime).TotalMinutes) * Settings.Instance.TunerMinHeight;
                    }
                }

                //ごく小さいマージンの表示を抑制する。
                reserveList.ForEach(info =>
                {
                    info.TopPos = Math.Round(info.TopPos);
                    info.Height = Math.Round(info.Height);
                });

                //最低表示行数からドット数を計算する。
                // メイリオみたいに行間のあるフォントはフォントの高さをそのまま使う。
                double fontHeight = Math.Max(Settings.Instance.TunerFontHeight, Settings.Instance.TunerFontHeightService);
                // MS P ゴシックみたいな行間のないフォントは 2px あける。
                double fontSize = Math.Max(Settings.Instance.TunerFontSize, Settings.Instance.TunerFontSizeService) + 2;
                // 大きい方をフォントの高さとして採用し、最低表示px数を計算する。
                double lineHeight = Settings.Instance.TunerMinimumLine * Math.Max(fontHeight, fontSize);
                if (Settings.Instance.TunerMinimumLine >= 2)
                {
                    lineHeight += 2;                                                                        // 番組名との間隔は 2px にする
                }
                ViewUtil.ModifierMinimumHeight <ReserveData, ReserveViewItem>(reserveList, lineHeight + 2); //2ドットは枠の分

                //必要時間リストの修正。最低表示行数の適用で下に溢れた分を追加する。
                if (reserveList.Count != 0 && timeList.Count > 0)
                {
                    double bottom = reserveList.Max(info => info.TopPos + info.Height);
                    int    end    = (int)(bottom / (60 * Settings.Instance.TunerMinHeight)) + 1;
                    while (end > timeList.Count)
                    {
                        DateTime time_tail = timeList[timeList.Count - 1].AddHours(1);
                        timeList.Add(time_tail);
                    }
                }

                tunerReserveTimeView.SetTime(timeList);
                tunerReserveNameView.SetTunerInfo(tunerList);
                tunerReserveView.SetReserveList(reserveList,
                                                leftPos,
                                                timeList.Count * 60 * Settings.Instance.TunerMinHeight);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); }
        }