첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.62MB

▶ OHLCModel.cs

using System;

namespace TestProject
{
    /// <summary>
    /// OHLC 모델
    /// </summary>
    public class OHLCModel
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region ID - ID

        /// <summary>
        /// ID
        /// </summary>
        public string ID { get; set; }

        #endregion
        #region 일자 - DATE

        /// <summary>
        /// 일자
        /// </summary>
        public DateTime DATE {get; set;}

        #endregion
        #region 시가 - OPEN

        /// <summary>
        /// 시가
        /// </summary>
        public decimal OPEN { get; set; }

        #endregion
        #region 고가 - HIGH

        /// <summary>
        /// 고가
        /// </summary>
        public decimal HIGH { get; set; }

        #endregion
        #region 저가 - LOW

        /// <summary>
        /// 저가
        /// </summary>
        public decimal LOW { get; set; }

        #endregion
        #region 종가 - CLOSE

        /// <summary>
        /// 종가
        /// </summary>
        public decimal CLOSE { get; set; }

        #endregion
        #region 거래량 - VOLUME

        /// <summary>
        /// 거래량
        /// </summary>
        public int VOLUME { get; set; }

        #endregion
    }
}

 

728x90

 

▶ MainForm.cs

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
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요