402 lines
14 KiB
C#
402 lines
14 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
|
|
using INT_PT002.DataStore;
|
|
|
|
namespace INT_PT002
|
|
{
|
|
public class Helper
|
|
{
|
|
/// <summary>
|
|
/// Double형을 String형으로 변환하여 리턴(소수점 자릿수에 맞춰 0을 채워서 리턴)
|
|
/// </summary>
|
|
/// <param name="value">Double형 데이터</param>
|
|
/// <param name="decimalPlaces">소수점 자릿수</param>
|
|
/// <returns>String형 데이터</returns>
|
|
public static string DoubleToString(double value, int decimalPlaces)
|
|
{
|
|
if (decimalPlaces == 0)
|
|
return string.Format("{0:F0}", value);
|
|
else if (decimalPlaces == 1)
|
|
return string.Format("{0:F1}", value);
|
|
else if (decimalPlaces == 2)
|
|
return string.Format("{0:F2}", value);
|
|
else if (decimalPlaces == 3)
|
|
return string.Format("{0:F3}", value);
|
|
else if (decimalPlaces == 4)
|
|
return string.Format("{0:F4}", value);
|
|
else if (decimalPlaces == 5)
|
|
return string.Format("{0:F5}", value);
|
|
else if (decimalPlaces == 6)
|
|
return string.Format("{0:F6}", value);
|
|
else if (decimalPlaces == 7)
|
|
return string.Format("{0:F7}", value);
|
|
else
|
|
return "0";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 소수점 없는 String 값을 소수점 추가 후 String 값으로 리턴
|
|
/// </summary>
|
|
/// <param name="value">소수점이 없는 값</param>
|
|
/// <param name="decimalPlaces">소수점 자릿수</param>
|
|
/// <returns>소수점 자리 추가 데이터</returns>
|
|
public static string StringToDecimalPlaces(string value, int decimalPlaces)
|
|
{
|
|
string ret = "";
|
|
double dValue = 0.0;
|
|
|
|
dValue = StringToDouble(value, decimalPlaces);
|
|
ret = DoubleToString(dValue, decimalPlaces);
|
|
|
|
return ret;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 소수점 없는 String형 값을 소수점 추가후 Double형으로 리턴(부호가 포함된 String형값)
|
|
/// </summary>
|
|
/// <param name="value">소수점이 없는 값</param>
|
|
/// <param name="decimalPlaces">소수점 자릿수</param>
|
|
/// <returns>Double형 소수점 추가 데이터</returns>
|
|
public static double StringToDouble(string value, int decimalPlaces)
|
|
{
|
|
double dValue = 0.0;
|
|
string str = "", code = "";
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(value);
|
|
|
|
try
|
|
{
|
|
if (sb.Length > 8)
|
|
return 0.0;
|
|
if (sb[0] == '-')
|
|
{
|
|
code = "-";
|
|
sb.Remove(0, 1);
|
|
}
|
|
|
|
str = sb.ToString();
|
|
str = str.Trim();
|
|
sb.Remove(0, sb.Length);
|
|
sb.Append(str);
|
|
|
|
for (int i = 0; i < decimalPlaces; i++)
|
|
{
|
|
if (sb.Length > decimalPlaces)
|
|
break;
|
|
|
|
sb.Insert(0, "0");
|
|
}
|
|
|
|
sb.Insert(sb.Length - decimalPlaces, ".");
|
|
str = sb.ToString();
|
|
str = code + str;
|
|
dValue = double.Parse(str);
|
|
|
|
return dValue;
|
|
|
|
}
|
|
catch
|
|
{
|
|
return 0.0;
|
|
}
|
|
}
|
|
|
|
public static Define.E_ProcessStatus StringToProcessStatus(string value)
|
|
{
|
|
int iValue = 0;
|
|
Define.E_ProcessStatus status;
|
|
|
|
if (value.Length != 2)
|
|
return Define.E_ProcessStatus._0_None;
|
|
|
|
iValue = int.Parse(value);
|
|
|
|
switch (iValue)
|
|
{
|
|
case 0:
|
|
status = Define.E_ProcessStatus._1_Ready;
|
|
break;
|
|
case 1:
|
|
status = Define.E_ProcessStatus._2_ProductEntry;
|
|
break;
|
|
case 2:
|
|
status = Define.E_ProcessStatus._3_MoveToLeak;
|
|
break;
|
|
case 3:
|
|
status = Define.E_ProcessStatus._4_MoveToCheck;
|
|
break;
|
|
case 4:
|
|
status = Define.E_ProcessStatus._5_ChamberMerge;
|
|
break;
|
|
case 5:
|
|
status = Define.E_ProcessStatus._6_VacuumStart;
|
|
break;
|
|
case 6:
|
|
status = Define.E_ProcessStatus._7_VacuumHold;
|
|
break;
|
|
case 7:
|
|
status = Define.E_ProcessStatus._8_Judgment;
|
|
break;
|
|
case 8:
|
|
status = Define.E_ProcessStatus._9_VacuumBreak;
|
|
break;
|
|
case 9:
|
|
status = Define.E_ProcessStatus._10_ChamberRelease;
|
|
break;
|
|
case 10:
|
|
status = Define.E_ProcessStatus._11_MoveToReady;
|
|
break;
|
|
default:
|
|
status = Define.E_ProcessStatus._0_None;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
public static Define.E_JudgmentStatus StringToJudgmentStatus(string value)
|
|
{
|
|
Define.E_JudgmentStatus status;
|
|
|
|
if (value.Length != 1)
|
|
return Define.E_JudgmentStatus.None;
|
|
|
|
switch (value)
|
|
{
|
|
case "0":
|
|
status = Define.E_JudgmentStatus.None;
|
|
break;
|
|
case "1":
|
|
status = Define.E_JudgmentStatus.Pass;
|
|
break;
|
|
case "2":
|
|
status = Define.E_JudgmentStatus.Ng;
|
|
break;
|
|
case "3":
|
|
status = Define.E_JudgmentStatus.Error;
|
|
break;
|
|
default:
|
|
status = Define.E_JudgmentStatus.None;
|
|
break;
|
|
}
|
|
|
|
return status;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 2자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits2(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
/// <summary>
|
|
/// 4자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits4(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 4)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
/// <summary>
|
|
/// 5자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits5(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 4)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 5)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
/// <summary>
|
|
/// 6자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits6(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 4)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 5)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 6)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
/// <summary>
|
|
/// 7자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits7(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 4)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 5)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 6)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 7)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
/// <summary>
|
|
/// 8자리에 마춰 공백으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringBlankFillDigits8(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 4)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 5)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 6)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 7)
|
|
return string.Format(" {0}", value);
|
|
else if (value.Length == 8)
|
|
return value;
|
|
else
|
|
return " ";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 4자리에 마춰 공백을 0으로 채움
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
public static string StringZeroFillDigits4(string value)
|
|
{
|
|
if (value.Length == 1)
|
|
return string.Format("000{0}", value);
|
|
else if (value.Length == 2)
|
|
return string.Format("00{0}", value);
|
|
else if (value.Length == 3)
|
|
return string.Format("0{0}", value);
|
|
else if (value.Length == 4)
|
|
return value;
|
|
else
|
|
return "0000";
|
|
}
|
|
|
|
public static string ByteToHexString(byte[] array)
|
|
{
|
|
string resultHex = "";
|
|
|
|
foreach (byte byteStr in array)
|
|
resultHex += string.Format("{0:X2}", byteStr);
|
|
|
|
return resultHex;
|
|
}
|
|
}
|
|
|
|
public static class FindByNameUtil
|
|
{
|
|
public static T FindByName<T>(this object targetClass, string name) where T : class
|
|
{
|
|
System.Reflection.FieldInfo fi = targetClass.GetType().GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
|
return fi.GetValue(targetClass) as T;
|
|
}
|
|
public static T FindByName<T>(this string name, object targetClass) where T : class
|
|
{
|
|
System.Reflection.FieldInfo fi = targetClass.GetType().GetField(name, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
|
return fi.GetValue(targetClass) as T;
|
|
}
|
|
public static System.Windows.Forms.Label Is_Label_From(this string name, object targetClass)
|
|
{
|
|
return FindByName<System.Windows.Forms.Label>(targetClass, name);
|
|
}
|
|
public static System.Windows.Forms.TextBox Is_TextBox_From(this string name, object targetClass)
|
|
{
|
|
return FindByName<System.Windows.Forms.TextBox>(targetClass, name);
|
|
}
|
|
public static System.Windows.Forms.TextBox TextBox(string name, object targetClass)
|
|
{
|
|
return FindByName<System.Windows.Forms.TextBox>(targetClass, name);
|
|
}
|
|
public static System.Windows.Forms.Label Label(string name, object targetClass)
|
|
{
|
|
return FindByName<System.Windows.Forms.Label>(targetClass, name);
|
|
}
|
|
public static System.Windows.Forms.PictureBox PictureBox(string name, object targetClass)
|
|
{
|
|
return FindByName<System.Windows.Forms.PictureBox>(targetClass, name);
|
|
}
|
|
|
|
public static SmartX.SmartLabel SmartLabel(string name, object targetClass)
|
|
{
|
|
return FindByName<SmartX.SmartLabel>(targetClass, name);
|
|
}
|
|
public static SmartX.SmartProgressBar SmartProgressBar(string name, object targetClass)
|
|
{
|
|
return FindByName<SmartX.SmartProgressBar>(targetClass, name);
|
|
}
|
|
public static SmartX.SmartButton SmartButton(string name, object targetClass)
|
|
{
|
|
return FindByName<SmartX.SmartButton>(targetClass, name);
|
|
}
|
|
public static SmartX.SmartDraw SmartDraw(string name, object targetClass)
|
|
{
|
|
return FindByName<SmartX.SmartDraw>(targetClass, name);
|
|
}
|
|
public static SmartX.SmartListBox SmartListBox(string name, object targetClass)
|
|
{
|
|
return FindByName<SmartX.SmartListBox>(targetClass, name);
|
|
}
|
|
}
|
|
}
|