using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// OHLC 리스트
/// </summary>
private List<OHLCModel> ohlcList;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 폼 로드시 처리하기 - Form_Load(sender, e)
/// <summary>
/// 폼 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Form_Load(object sender, EventArgs e)
{
this.ohlcList = GetOHLCList();
this.idComboBoxEdit1.Properties.Items.AddRange(ohlcList.Select(olhc => olhc.ID).Distinct().ToArray());
this.idComboBoxEdit1.SelectedIndex = 1;
}
#endregion
#region ID 콤보 박스 에디터 선택 인덱스 변경시 처리하기 - idComboBoxEdit_SelectedIndexChanged(sender, e)
/// <summary>
/// ID 콤보 박스 에디터 선택 인덱스 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void idComboBoxEdit_SelectedIndexChanged(object sender, EventArgs e)
{
List<OHLCModel> targetList = this.ohlcList.Where
(
ohlc => ohlc.ID == (string)this.idComboBoxEdit1.SelectedItem
).OrderBy(ohlc => ohlc.DATE).Reverse().Take(150).ToList();
this.chartControl.DataSource = targetList;
DateTime maximumDate = targetList.Max(ohlc => ohlc.DATE);
XYDiagram diagram = this.chartControl.Diagram as XYDiagram;
diagram.AxisX.VisualRange.SetMinMaxValues(maximumDate.AddDays(-60), maximumDate);
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region OHLC 리스트 구하기 - GetOHLCList()
/// <summary>
/// OHLC 리스트 구하기
/// </summary>
/// <returns>OHLC 리스트</returns>
private List<OHLCModel> GetOHLCList()
{
IEnumerable<string[]> itemArrayEnumerable = File.ReadAllLines("Source.csv").Select(line => line.Split('\t'));
IEnumerable<OHLCModel> ohlcEnumerable = from line in itemArrayEnumerable
select new OHLCModel()
{
ID = line[6],
DATE = Convert.ToDateTime(line[0]),
OPEN = Convert.ToDecimal(line[1]),
HIGH = Convert.ToDecimal(line[2]),
LOW = Convert.ToDecimal(line[3]),
CLOSE = Convert.ToDecimal(line[4]),
VOLUME = Convert.ToInt32(line[5])
};
return ohlcEnumerable.ToList();
}
#endregion
}
}