using System;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 라인 1 시리즈
/// </summary>
private Line line1;
/// <summary>
/// 라인 2 시리즈
/// </summary>
private Line line2;
/// <summary>
/// 색상 라인 1 도구
/// </summary>
private ColorLine colorLine1;
/// <summary>
/// 색상 라인 2 도구
/// </summary>
private ColorLine colorLine2;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 라인 1 시리즈를 생성한다.
this.line1 = new Line();
this.line1.Title = "Good";
this.line1.Color = Color.Blue;
this.line1.Pointer.Visible = true;
#endregion
#region 라인 2 시리즈를 생성한다.
this.line2 = new Line();
this.line2.Title = "Bad";
this.line2.Color = Color.Red;
this.line2.Pointer.Visible = true;
this.line2.VertAxis = VerticalAxis.Right;
#endregion
#region 색상 라인 1 도구를 생성한다.
this.colorLine1 = new ColorLine();
this.colorLine1.Pen.Width = 2;
this.colorLine1.Pen.Color = Color.Red;
this.colorLine1.Axis = this.tChart.Axes.Right;
#endregion
#region 색상 라인 2 도구를 생성한다.
this.colorLine2 = new ColorLine();
this.colorLine2.Pen.Width = 2;
this.colorLine2.Pen.Color = Color.Blue;
this.colorLine2.Axis = this.tChart.Axes.Right;
#endregion
#region 티차트를 설정한다.
this.tChart.Axes.Left.Title.Caption = "Production (number of pieces)";
this.tChart.Axes.Left.Automatic = false;
this.tChart.Axes.Left.AutomaticMaximum = false;
this.tChart.Axes.Left.AutomaticMinimum = false;
this.tChart.Axes.Left.Minimum = 0d;
this.tChart.Axes.Left.Maximum = 1200d;
this.tChart.Axes.Right.Title.Caption = "SPC (%)";
this.tChart.Axes.Right.Automatic = false;
this.tChart.Axes.Right.AutomaticMaximum = false;
this.tChart.Axes.Right.AutomaticMinimum = false;
this.tChart.Axes.Right.Maximum = 10d;
this.tChart.Axes.Right.Minimum = 0d;
this.tChart.Axes.Bottom.Grid.Color = Color.FromArgb(130, 130, 130);
this.tChart.Axes.Bottom.Grid.Visible = true;
this.tChart.Tools.Add(this.colorLine1);
this.tChart.Tools.Add(this.colorLine2);
this.tChart.Series.Add(this.line1);
this.tChart.Series.Add(this.line2);
#endregion
Random random = new Random(DateTime.Now.Millisecond);
for(int i = 1 ; i < 19; i++)
{
this.line1.Add(800 + random.Next(200));
this.line2.Add(4 + random.Next(4 ));
}
CalculateLimits(this.line1, this.line2);
this.upperLimitTextBox.Text = this.colorLine1.Value.ToString();
this.lowerLimitTextBox.Text = this.colorLine2.Value.ToString();
this.colorLine1.DragLine += colorLine1_DragLine;
this.colorLine2.DragLine += colorLine2_DragLine;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 색상 라인 1 도구 라인 드래그시 처리하기 - colorLine1_DragLine(sender, e)
/// <summary>
/// 색상 라인 1 도구 라인 드래그시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void colorLine1_DragLine(object sender, EventArgs e)
{
this.upperLimitTextBox.Text = this.colorLine1.Value.ToString("#.00");
}
#endregion
#region 색상 라인 2 도구 라인 드래그시 처리하기 - colorLine2_DragLine(sender, e)
/// <summary>
/// 색상 라인 2 도구 라인 드래그시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void colorLine2_DragLine(object sender, EventArgs e)
{
this.lowerLimitTextBox.Text = this.colorLine2.Value.ToString("#.00");
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 제한 계산하기 - CalculateLimits(goodSeries, badSeries)
/// <summary>
/// 제한 계산하기
/// </summary>
/// <param name="goodSeries">양품 시리즈</param>
/// <param name="badSeries">불량 시리즈</param>
private void CalculateLimits(Series goodSeries, Series badSeries)
{
double sum1 = 0d;
double sum2 = 0d;
double temporaryValue1;
double temporaryValue2;
double lcp; // Likelihood of Correct Prediction
double lcn; // Likelihood of Correct Non-prediction
double temporaryValue3;
double percent;
int n = 0;
this.colorLine1.Value = 0.0;
this.colorLine2.Value = 0.0;
for(int i = 0; i < goodSeries.Count; i++)
{
percent = badSeries.YValues[i] * goodSeries.YValues[i] / 100.0;
temporaryValue3 = goodSeries.YValues[i] + percent;
if(temporaryValue3 > 0)
{
sum1 += percent / temporaryValue3;
sum2 += temporaryValue3;
n++;
}
}
lcp = sum1 / n;
lcn = sum2 / n;
temporaryValue1 = (lcp * (1.0 - lcp)) / lcn;
if(temporaryValue1 > 0)
{
temporaryValue2 = 3 * Math.Sqrt(temporaryValue1);
this.colorLine1.Value = 100.0 * (lcp + temporaryValue2);
this.colorLine2.Value = 100.0 * (lcp - temporaryValue2);
}
}
#endregion
}
}