using MuchInfo.Chart.Data.EnumTypes;
using MuchInfo.Chart.Data.Models;
using MuchInfo.Chart.WPF.Helpers;
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Linq;
namespace MuchInfo.Chart.WPF.Controls.QuickTimeSpan
{
///
/// TimeSpanControl.xaml 的交互逻辑
///
public partial class TimeSpanPicker : UserControl
{
#region Constructors
public TimeSpanPicker(Chart chart)
{
this.InitializeComponent();
InitializeButtons(chart);
if (null != chart) UpdateButtonStatus(chart.CycleType);
}
#endregion Constructors
#region Delegates
public delegate void TimeSpanChangedEventHandler(CycleType cycleType);
#endregion Delegates
#region Events
public event TimeSpanPicker.TimeSpanChangedEventHandler ChangeTimeSpan;
#endregion Events
#region Methods
#region Internal Methods
///
/// Adds the custom button.
///
/// The text.
/// The time span.
internal void AddCustomButton(string text, TimeSpan timeSpan)
{
this.stackMain.Children.Add(new TimeSpanButton(text, CycleType.Custom, this));
}
///
/// 添加指标周期。
///
/// 显示名称
/// 周期
/// 插入的索引
internal void InsertCycleTypeBtton(string text, CycleType cycleType, int index)
{
this.stackMain.Children.Insert(index, new TimeSpanButton(text, cycleType, this));
}
///
/// 选择显示区间后执行
///
/// Type of the cycle.
internal void UpdateCyleType(CycleType cycleType)
{
var handler = this.ChangeTimeSpan;
if (handler != null)
{
handler(cycleType);
UpdateButtonStatus(cycleType);
}
}
///
/// Updates the button status.
///
/// Type of the cycle.
private void UpdateButtonStatus(CycleType cycleType)
{
if (this.stackMain == null || this.stackMain.Children == null || this.stackMain.Children.Count == 0) return;
foreach (var button in stackMain.Children)
{
var timeSpanButton = button as TimeSpanButton;
if (timeSpanButton == null) continue;
if (timeSpanButton.CycleType == cycleType)
{
timeSpanButton.Opacity = 1.0;
}
else
{
timeSpanButton.Opacity = 0.5;
}
}
}
#endregion Internal Methods
#region Private Methods
///
/// Initializes the buttons.
///
private void InitializeButtons(Chart chart)
{
this.stackMain.Children.Clear();
if (chart.CycleItems == null || chart.CycleItems.Count() == 0)
{
//chart.CycleItems = new List();
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.TimeSharing });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute5 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute15 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute30 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute60 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute120 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Minute240 });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Day });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Week });
//chart.CycleItems.Add(new CycleModel() { Cycle = CycleType.Month });
}
//foreach (var item in chart.CycleItems)
//{
// switch (item.Cycle)
// {
// case CycleType.TimeSharing:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_TimeSharingLine);
// break;
// case CycleType.Minute:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneMinute);
// break;
// case CycleType.Minute3:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_ThreeMinute);
// break;
// case CycleType.Minute5:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_FiveMinute);
// break;
// case CycleType.Minute10:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_TenMinute);
// break;
// case CycleType.Minute15:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_FifteenMinute);
// break;
// case CycleType.Minute30:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_ThirtyMinute);
// break;
// case CycleType.Minute60:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_SixtyMinute);
// break;
// case CycleType.Minute90:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_NinetyMinute);
// break;
// case CycleType.Minute120:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_Minute120);
// break;
// case CycleType.Minute180:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_Minute180);
// break;
// case CycleType.Minute240:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_Minute240);
// break;
// case CycleType.Hour:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneHour);
// break;
// case CycleType.Day:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneDay);
// break;
// case CycleType.Week:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneWeek);
// break;
// case CycleType.Month:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneMonth);
// break;
// case CycleType.Quarter:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneQuarter);
// break;
// case CycleType.Year:
// item.Btn_Text = LanguageManager.FindResource(LanguageConst.TimeSpanControl_OneYear);
// break;
// case CycleType.Custom:
// item.Btn_Text = Math.Floor(chart.ChartTimeSpan.TotalMinutes).ToString();
// break;
// default:
// item.Btn_Text = Math.Floor(chart.ChartTimeSpan.TotalMinutes).ToString();
// break;
// }
//if (!string.IsNullOrEmpty(item.Btn_Text))
//{
// this.stackMain.Children.Add(new TimeSpanButton(item.Btn_Text, item.Cycle, this));
//}
//}
}
///
/// Updates the buttons.
///
internal void UpdateButtons(Chart chart)
{
this.stackMain.Children.Clear();
InitializeButtons(chart);
}
#endregion Private Methods
private void Border_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
}
#endregion Methods
}
}