/// <summary>
 /// マウス位置から予約情報を取得する
 /// </summary>
 /// <param name="cursorPos">[IN]マウス位置</param>
 /// <param name="reserve">[OUT]予約情報</param>
 /// <returns>falseで存在しない</returns>
 private bool GetReserveItem(Point cursorPos, ref ReserveData reserve)
 {
     try
     {
         if (timeList.Count > 0)
         {
             int         timeIndex = (int)Math.Floor(cursorPos.Y / (60 * Settings.Instance.MinHeight));
             TimePosInfo time      = timeList.Values[timeIndex];
             foreach (ReserveViewItem resInfo in time.ReserveList)
             {
                 if (resInfo.LeftPos <= cursorPos.X && cursorPos.X < resInfo.LeftPos + resInfo.Width &&
                     resInfo.TopPos <= cursorPos.Y && cursorPos.Y < resInfo.TopPos + resInfo.Height)
                 {
                     reserve = resInfo.ReserveInfo;
                     return(true);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
     }
     return(false);
 }
        /// <summary>
        /// 予約情報の再描画
        /// </summary>
        private void ReloadReserveViewItem()
        {
            tunerReserveView.ClearInfo();
            tunerReserveTimeView.ClearInfo();
            tunerReserveNameView.ClearInfo();
            timeList.Clear();
            tunerList.Clear();
            reserveList.Clear();
            try
            {
                double leftPos = 0;
                for (int i = 0; i < CommonManager.Instance.DB.TunerReserveList.Count; i++)
                {
                    double            width     = 150;
                    TunerReserveInfo  info      = CommonManager.Instance.DB.TunerReserveList.Values.ElementAt(i);
                    TunerNameViewItem tunerInfo = new TunerNameViewItem(info, width);
                    tunerList.Add(tunerInfo);

                    List <ReserveViewItem> tunerAddList = new List <ReserveViewItem>();
                    for (int j = 0; j < info.reserveList.Count; j++)
                    {
                        UInt32 reserveID = (UInt32)info.reserveList[j];
                        if (CommonManager.Instance.DB.ReserveList.ContainsKey(reserveID) == false)
                        {
                            continue;
                        }
                        ReserveData     reserveInfo = CommonManager.Instance.DB.ReserveList[reserveID];
                        ReserveViewItem viewItem    = new ReserveViewItem(CommonManager.Instance.DB.ReserveList[reserveID]);

                        Int32    duration  = (Int32)reserveInfo.DurationSecond;
                        DateTime startTime = reserveInfo.StartTime;
                        if (reserveInfo.RecSetting.UseMargineFlag == 1)
                        {
                            if (reserveInfo.RecSetting.StartMargine < 0)
                            {
                                startTime = reserveInfo.StartTime.AddSeconds(reserveInfo.RecSetting.StartMargine * -1);
                                duration += reserveInfo.RecSetting.StartMargine;
                            }
                            if (reserveInfo.RecSetting.EndMargine < 0)
                            {
                                duration += reserveInfo.RecSetting.EndMargine;
                            }
                        }
                        DateTime EndTime;
                        EndTime = startTime.AddSeconds(duration);
                        //if ((duration / 60) < Settings.Instance.MinHeight)
                        //{
                        //    duration = (int)Settings.Instance.MinHeight;
                        //}

                        viewItem.Height = Math.Floor((duration / 60) * Settings.Instance.MinHeight);
                        if (viewItem.Height < Settings.Instance.MinHeight)
                        {
                            viewItem.Height = Settings.Instance.MinHeight;
                        }
                        viewItem.Width   = 150;
                        viewItem.LeftPos = leftPos;

                        foreach (ReserveViewItem addItem in tunerAddList)
                        {
                            ReserveData addInfo      = addItem.ReserveInfo;
                            Int32       durationAdd  = (Int32)addInfo.DurationSecond;
                            DateTime    startTimeAdd = addInfo.StartTime;
                            if (addInfo.RecSetting.UseMargineFlag == 1)
                            {
                                if (addInfo.RecSetting.StartMargine < 0)
                                {
                                    startTimeAdd = addInfo.StartTime.AddSeconds(addInfo.RecSetting.StartMargine * -1);
                                    durationAdd += addInfo.RecSetting.StartMargine;
                                }
                                if (addInfo.RecSetting.EndMargine < 0)
                                {
                                    durationAdd += addInfo.RecSetting.EndMargine;
                                }
                            }
                            DateTime endTimeAdd;
                            endTimeAdd = startTimeAdd.AddSeconds(durationAdd);

                            if ((startTimeAdd <= startTime && startTime < endTimeAdd) ||
                                (startTimeAdd < EndTime && EndTime <= endTimeAdd) ||
                                (startTime <= startTimeAdd && startTimeAdd < EndTime) ||
                                (startTime < endTimeAdd && endTimeAdd <= EndTime)
                                )
                            {
                                if (addItem.LeftPos >= viewItem.LeftPos)
                                {
                                    viewItem.LeftPos += 150;
                                    if (viewItem.LeftPos - leftPos >= width)
                                    {
                                        width += 150;
                                    }
                                }
                            }
                        }

                        reserveList.Add(viewItem);
                        tunerAddList.Add(viewItem);

                        //必要時間リストと時間と番組の関連づけ

                        DateTime chkStartTime = new DateTime(startTime.Year, startTime.Month, startTime.Day, startTime.Hour, 0, 0);
                        while (chkStartTime <= EndTime)
                        {
                            if (timeList.ContainsKey(chkStartTime) == false)
                            {
                                timeList.Add(chkStartTime, new TimePosInfo(chkStartTime, 0));
                            }
                            TimePosInfo timeInfo = timeList[chkStartTime];
                            timeInfo.ReserveList.Add(viewItem);
                            chkStartTime = chkStartTime.AddHours(1);
                        }
                    }
                    tunerInfo.Width = width;
                    leftPos        += width;
                }

                //表示位置設定
                foreach (ReserveViewItem item in reserveList)
                {
                    DateTime startTime = item.ReserveInfo.StartTime;
                    if (item.ReserveInfo.RecSetting.UseMargineFlag == 1)
                    {
                        if (item.ReserveInfo.RecSetting.StartMargine < 0)
                        {
                            startTime = item.ReserveInfo.StartTime.AddSeconds(item.ReserveInfo.RecSetting.StartMargine * -1);
                        }
                    }

                    DateTime chkStartTime = new DateTime(startTime.Year,
                                                         startTime.Month,
                                                         startTime.Day,
                                                         startTime.Hour,
                                                         0,
                                                         0);
                    if (timeList.ContainsKey(chkStartTime) == true)
                    {
                        int index = timeList.IndexOfKey(chkStartTime);
                        item.TopPos = (index * 60 + (startTime - chkStartTime).TotalMinutes) * Settings.Instance.MinHeight;
                    }
                }

                double topPos = 0;
                foreach (TimePosInfo time in timeList.Values)
                {
                    time.TopPos = topPos;
                    topPos     += 60 * Settings.Instance.MinHeight;
                }

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