using System;
using System.Collections;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using OTSModelSharp.ServiceCenter;
namespace OTSSysMgrApp
{
public partial class SemTestForms : Form
{
#region 全部变量声明
//连接状态
bool ConnectionState = false;
static string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFilePath"].ConnectionString;
static NLog.Logger log = NLog.LogManager.GetCurrentClassLogger();
ISemController m_SemHardwareMgr = null;
//国际化
Language lan;
//国际化存储信息
Hashtable table;
#endregion
#region 构造方法
public SemTestForms()
{
InitializeComponent();
//控制类对象初始化
m_SemHardwareMgr = SemController.GetSEMController();
//国际化
lan = new Language(this);
table = lan.GetNameTable(this.Name);
}
#endregion
#region 保存设置
///
/// 保存设置
///
/// 节点名称
/// 节点参数值
public void SaveSetting(string Name, string Value)
{
try
{
//判断XML文件中是否存在
if (!XMLOperationClass.ExistsXmlInfo(Name))
{
//调用添加XML节点功能
XMLOperationClass.AddXmlInfo(Name, Value);
}
else
{
//调用修改XML节点功能
XMLOperationClass.EditXmlInfo(Name, Value);
}
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
#endregion
#region 修改设置
public void EditSetting(string Name, string Value)
{
try
{
//调用修改XML节点功能
XMLOperationClass.EditXmlInfo(Name, Value);
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
#endregion
#region 判断文件路径
///
/// 判断文件路径
///
///
///
public bool CreateFile(string path)
{
Directory.CreateDirectory(path);
return false;
}
#endregion
#region 判断文件是否存在
///
/// 判断文件是否存在
///
/// 文件路径
///
public bool ExistsFile(string path)
{
try
{
if (File.Exists(path))
{
return true;
}
return false;
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
return false;
}
}
#endregion
public void GetBtnState(bool btnState)
{
foreach (Control item in gbGetMethods.Controls)
{
if (item is Button)
{
((Button)item).Enabled = btnState;
}
}
foreach (Control item in gbSetMethods.Controls)
{
if (item is Button)
{
((Button)item).Enabled = btnState;
}
}
}
#region 用户信息提示
///
/// 提示
///
///
private void ShowMessage(int MessageType)
{
string message1 = table["message1"].ToString();
string message2 = table["message2"].ToString();
string message3 = table["message3"].ToString();
string message4 = table["message4"].ToString();
string message5 = table["message5"].ToString();
string message6 = table["message6"].ToString();
string message7 = table["message7"].ToString();
string message8 = table["message8"].ToString();
string message9 = table["message9"].ToString();
string message10 = table["message10"].ToString();
string MessageInfo = string.Empty;
switch (MessageType)
{
case 0:
MessageInfo = message1;
break;
case 1:
MessageInfo = message2;
break;
case 2:
MessageInfo = message3;
break;
case 3:
MessageInfo = message4;
break;
case 4:
MessageInfo = message5;
break;
case 5:
MessageInfo = message6;
break;
case 6:
MessageInfo = message7;
break;
case 7:
MessageInfo = message8;
break;
case 8:
MessageInfo = message9;
break;
case 9:
MessageInfo = message10;
break;
}
MessageBox.Show(MessageInfo, "Tip");
}
#endregion
#region 判断控制内容是否为空 与 判断输入的格式是否正确
///
/// 判断控制内容是否为空
///
///
///
public bool IsNull(TextBox tbContent)
{
if (tbContent.Text.Trim().Equals(""))
{
//为空提示
ShowMessage(0);
//获取焦点
tbContent.Focus();
return false;
}
return true;
}
///
///
///
///
///
///
public bool IsType(object ObjValue, int ObjType)
{
try
{
switch (ObjType)
{
case 1:
int intValue = Convert.ToInt32(ObjValue);
break;
case 2:
double douValue = Convert.ToDouble(ObjValue);
break;
case 3:
float floValue = Convert.ToSingle(ObjValue);
break;
}
return true;
}
catch (Exception)
{
//为空提示
ShowMessage(7);
return false;
}
}
///
/// 判断是否连接
///
///
public bool IsConnection()
{
try
{
if (ConnectionState)
{
return true;
}
return false;
}
catch (Exception)
{
//为空提示
ShowMessage(7);
return false;
}
}
#endregion
#region 窗体控制的事件汇总
private void SemTestForms_Load(object sender, EventArgs e)
{
////循环窗体中
foreach (Control item in gbGetMethods.Controls)
{
if (item is Button)
{
//绑定按钮点击事件
//item.Click += new System.EventHandler(btnGetInfo_Click);
((Button)item).Enabled = false;
}
}
foreach (Control item in gbSetMethods.Controls)
{
if (item is Button)
{
//绑定按钮点击事件
//item.Click += new System.EventHandler(btnSetInfo_Click);
((Button)item).Enabled = false;
}
}
}
private void btnDone_Click(object sender, EventArgs e)
{
//返回关闭窗口返回值
this.DialogResult = DialogResult.OK;
}
private void btnGetInfo_Click(object sender, EventArgs e)
{
if (!IsConnection())
{
return;
}
//获取响应按钮
Button btnTest = (Button)sender;
try
{
//节点名称与节点参数值
string Name = string.Empty;
string Value = string.Empty;
//判断本地中是否存在文件路径
if (ExistsFile(xmlFilePath))
{
//遍历tabHardwareSet标签中所有的ComboBox控件
foreach (Control control in this.gbGetMethods.Controls)
{
//判断类型名称
if (control is TextBox)
{
Name = (control as TextBox).Name.Substring(2);
if (btnTest.Name.Contains(Name))
{
//获取节点名称与节点参数值
System.Xml.XmlNode xmlNode = XMLOperationClass.GetXMLInformationValue("S" + Name);
(control as TextBox).Text = ((XmlElement)xmlNode).GetAttribute("Value");
}
}
//判断类型名称
if (control is CheckBox)
{
Name = (control as CheckBox).Name.Substring(2);
if (btnTest.Name.Contains(Name))
{
//获取节点名称与节点参数值
System.Xml.XmlNode xmlNode = XMLOperationClass.GetXMLInformationValue(Name);
(control as CheckBox).Checked = ((XmlElement)xmlNode).GetAttribute("Value").Equals("true") ? true : false;
}
}
}
}
else
{
//如果文件不存在,则创建文件
CreateFile(xmlFilePath);
}
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
private void btnSetInfo_Click(object sender, EventArgs e)
{
if (!IsConnection())
{
return;
}
//获取响应按钮
Button btnTest = (Button)sender;
try
{
//节点名称与节点参数值
string Name = string.Empty;
string Value = string.Empty;
//判断本地中是否存在文件路径
if (ExistsFile(xmlFilePath))
{
//遍历tabHardwareSet标签中所有的TextBox控件
foreach (Control control in this.gbSetMethods.Controls)
{
//判断类型名称
if (control is TextBox)
{
Name = (control as TextBox).Name.Substring(2);
if (btnTest.Name.Contains(Name))
{
//获取节点名称与节点参数值
Value = (control as TextBox).Text;
SaveSetting(Name, Value);
}
}
//判断类型名称
if (control is CheckBox)
{
Name = (control as CheckBox).Name.Substring(2);
if (btnTest.Name.Contains(Name))
{
//获取节点名称与节点参数值
Value = (control as CheckBox).Checked ? "true" : "false";
SaveSetting(Name, Value);
}
}
}
}
else
{
//如果文件不存在,则创建文件
CreateFile(xmlFilePath);
}
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
private void btnGetAll_Click(object sender, EventArgs e)
{
}
private void BtnConnect_Click(object sender, EventArgs e)
{
if (!ConnectionState)
{
//和电镜建立通讯连接
ConnectionState = m_SemHardwareMgr.Connect();
///获取当前电镜的ID号
//SemType = cfun.GetSemType();
if (!ConnectionState)
{
ShowMessage(2);
log.Error(table["message3"].ToString());
}
else
{
string str = table["str1"].ToString();
BtnConnect.Text = str;
GetBtnState(true);
log.Info("The energy spectrum is connected");
}
}
else
{
string str = table["str2"].ToString();
BtnConnect.Text = str;
ConnectionState = false;
GetBtnState(false);
}
}
private void SemTestForms_FormClosing(object sender, FormClosingEventArgs e)
{
//m_SemHardwareMgr.DisConnect();
}
private void btnGPositionXYR_Click(object sender, EventArgs e)
{
try
{
//赋值
double PositionX = 0;
double PositionY = 0;
double PositionR = 0;
//获取参数
bool result = m_SemHardwareMgr.GetSemPositionXY(ref PositionX, ref PositionY, ref PositionR);
if (result)
{
//赋值 显示
tbPositionX.Text = Convert.ToDouble(PositionX).ToString();
tbPositionY.Text = Convert.ToDouble(PositionY).ToString();
tbPositionR.Text = Convert.ToDouble(PositionR).ToString();
log.Info("X,Y-axis coordinates:(" + tbPositionX.Text + "," + tbPositionY.Text+")");
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Failed to obtain the X and Y coordinates");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSPositionXYR_Click(object sender, EventArgs e)
{
try
{
//判断是否为空
if (!IsNull(tbSPositionX))
{
this.Focus();
return;
}
if (!IsType(tbSPositionX.Text, 2))
{
this.Focus();
return;
}
if (!IsNull(tbSPositionY))
{
this.Focus();
return;
}
if (!IsType(tbSPositionY.Text, 2))
{
this.Focus();
return;
}
//if (!IsNull(tbSPositionR))
//{
// this.Focus();
// return;
//}
//if (!IsType(tbSPositionR.Text, 2))
//{
// this.Focus();
// return;
//}
//赋值
double PositionX = Convert.ToDouble(tbSPositionX.Text);
double PositionY = Convert.ToDouble(tbSPositionY.Text);
//double PositionR = Convert.ToDouble(tbSPositionR.Text);
bool result = m_SemHardwareMgr.MoveSEMToPoint(PositionX, PositionY);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Set successfully, current X and Y coordinates should be:(" + PositionX.ToString() + "," + PositionY.ToString() + ")");
}
else
{
ShowMessage(4);
log.Error("Failed to set X and Y coordinates!");
}
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
private void btnMoveSEMToPoint_Click(object sender, EventArgs e)
{
try
{
//判断是否为空
if (!IsNull(tbSPositionX))
{
this.Focus();
return;
}
if (!IsType(tbSPositionX.Text, 2))
{
this.Focus();
return;
}
if (!IsNull(tbSPositionY))
{
this.Focus();
return;
}
if (!IsType(tbSPositionY.Text, 2))
{
this.Focus();
return;
}
if (!IsNull(tbSPositionR))
{
this.Focus();
return;
}
if (!IsType(tbSPositionR.Text, 2))
{
this.Focus();
return;
}
//赋值
double PositionX = Convert.ToDouble(tbSPositionX.Text);
double PositionY = Convert.ToDouble(tbSPositionY.Text);
double PositionR = Convert.ToDouble(tbSPositionR.Text);
bool result = m_SemHardwareMgr.MoveSEMToPoint(PositionX, PositionY, PositionR);
}
catch (Exception ex)
{
//记录日志信息
log.Error(ex.Message.ToString());
}
}
private void btnGBeamBlank_Click(object sender, EventArgs e)
{
try
{
int a_nBeamBlank = 0;
bool result = m_SemHardwareMgr.GetSemBeamBlank(ref a_nBeamBlank);
if (result)
{
//赋值 显示
tbBeamBlank.Text = Convert.ToString(a_nBeamBlank);
log.Info("Beam baffle:" + a_nBeamBlank.ToString());
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Failed to obtain the Beam baffle!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSBeamBlank_Click(object sender, EventArgs e)
{
try
{
bool a_nBeamBlank = false;
//判断是否为空与类型
if (!IsNull(tbSBeamBlank))
{
tbSBeamBlank.Focus();
return;
}
if (!IsType(tbSBeamBlank.Text, 1))
{
tbSBeamBlank.Focus();
return;
}
bool result = m_SemHardwareMgr.SetSemBeamBlank(true);
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGBrightness_Click(object sender, EventArgs e)
{
try
{
double a_dBrightness = 0;
//获取参数
bool result = m_SemHardwareMgr.GetSemBrightness(ref a_dBrightness);
if (result)
{
//赋值 显示
tbBrightness.Text = Convert.ToString(a_dBrightness);
log.Info("Brightness:" + tbBrightness.Text);
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Failed to obtain the Brightness");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSBrightness_Click(object sender, EventArgs e)
{
try
{
double a_dBrightness = 0;
//判断是否为空与类型
if (!IsNull(tbSBrightness))
{
tbSBrightness.Focus();
return;
}
if (!IsType(tbSBrightness.Text, 2))
{
tbSBrightness.Focus();
return;
}
//获取参数与设置参数
a_dBrightness = Convert.ToInt32(tbSBrightness.Text);
//获取参数
bool result = m_SemHardwareMgr.SetSemBrightness(a_dBrightness);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Setting successful!, the current brightness should be:" + tbSBrightness.Text);
}
else
{
ShowMessage(4);
log.Error("Brightness setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGContrast_Click(object sender, EventArgs e)
{
try
{
double a_dContrast = 0;
//获取参数
bool result = m_SemHardwareMgr.GetSemContrast(ref a_dContrast);
if (result)
{
//赋值 显示
tbContrast.Text = Convert.ToString(a_dContrast);
log.Info("Contrast:" + tbContrast.Text);
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Failed to obtain contrast!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSContrast_Click(object sender, EventArgs e)
{
try
{
double a_dContrast = 0;
//判断是否为空与类型
if (!IsNull(tbSContrast))
{
tbSContrast.Focus();
return;
}
if (!IsType(tbSContrast.Text, 2))
{
tbSContrast.Focus();
return;
}
//赋值
a_dContrast = Convert.ToInt32(tbSContrast.Text);
//获取结果参数
bool result = m_SemHardwareMgr.SetSemContrast(a_dContrast);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Set successfully, the current contrast should be:" + tbSContrast.Text);
}
else
{
ShowMessage(4);
log.Error("Contrast setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGFWD_Click(object sender, EventArgs e)
{
try
{
double a_dWorkingDistance = 0;
//获取参数
bool result = m_SemHardwareMgr.GetWorkingDistance(ref a_dWorkingDistance);
if (result)
{
//赋值 显示
tbFWD.Text = Convert.ToString(a_dWorkingDistance);
log.Info("WorkingDistance:" + tbFWD.Text);
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Fail to obtain the WorkingDistance!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSFWD_Click(object sender, EventArgs e)
{
try
{
double a_dWorkingDistance = 0;
//判断是否为空与类型
if (!IsNull(tbSFWD))
{
tbSFWD.Focus();
return;
}
if (!IsType(tbSFWD.Text, 2))
{
tbSFWD.Focus();
return;
}
//赋值
a_dWorkingDistance = Convert.ToDouble(tbSFWD.Text);
//获取结果参数
bool result = m_SemHardwareMgr.SetWorkingDistance(a_dWorkingDistance);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Setting successful!, the current working distance should be:"+ tbSFWD.Text);
}
else
{
ShowMessage(4);
log.Error("Working distance setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGKV_Click(object sender, EventArgs e)
{
try
{
double a_dKV = 0;
//获取参数
bool result = m_SemHardwareMgr.GetSemHighTension(ref a_dKV);
if (result)
{
//赋值 显示
tbKV.Text = Convert.ToString(a_dKV);
log.Info("Electron microscope voltage:" + tbKV.Text);
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Failed to obtain electron microscope voltage value!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSKV_Click(object sender, EventArgs e)
{
try
{
double a_dKV = 0;
//判断是否为空与类型
if (!IsNull(tbSKV))
{
tbSKV.Focus();
return;
}
if (!IsType(tbSKV.Text, 2))
{
tbSKV.Focus();
return;
}
//赋值
a_dKV = Convert.ToInt32(tbSKV.Text);
//获取结果参数
bool result = m_SemHardwareMgr.SetSemHighTension(a_dKV);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Setting successful!, the current voltage value should be:" + tbSKV.Text);
}
else
{
ShowMessage(4);
log.Error("Voltage setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGMagnification_Click(object sender, EventArgs e)
{
try
{
double a_dMagnification = 0;
//获取参数
bool result = m_SemHardwareMgr.GetMagnification(ref a_dMagnification);
if (result)
{
//赋值 显示
tbMagnification.Text = Convert.ToString(a_dMagnification);
log.Info("SemMagnification:" + tbMagnification.Text);
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Fail to obtain the SemMagnification!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSMagnification_Click(object sender, EventArgs e)
{
try
{
double a_dMagnification = 0;
//判断是否为空与类型
if (!IsNull(tbSMagnification))
{
tbSMagnification.Focus();
return;
}
if (!IsType(tbSMagnification.Text, 2))
{
tbSMagnification.Focus();
return;
}
//赋值
a_dMagnification = Convert.ToInt32(tbSMagnification.Text);
//获取结果参数
bool result = m_SemHardwareMgr.SetMagnification(a_dMagnification);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Setting successful!, the current magnification should be:");
}
else
{
ShowMessage(4);
log.Error("Magnification setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGSpotSize_Click(object sender, EventArgs e)
{
}
private void btnSSpotSize_Click(object sender, EventArgs e)
{
}
private void btnHT_Click(object sender, EventArgs e)
{
try
{
double a_bHTValue = 0;
//获取参数
bool result = m_SemHardwareMgr.GetSemHighTension(ref a_bHTValue);
if (a_bHTValue > 0)
{
//赋值 显示
cbHT.Checked = true;
log.Info("HT:" + cbHT.Checked.ToString());
}
else
{
//配置结果提示
ShowMessage(6);
log.Error("Fail to obtain the HT!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnSHT_Click(object sender, EventArgs e)
{
try
{
bool a_bHTValue = false;
//判断是否为空与类型
//赋值
a_bHTValue = cbSHT.Checked;
//获取结果参数
bool result = m_SemHardwareMgr.SetSemBeamBlank(a_bHTValue);
if (result)
{
//配置结果提示
ShowMessage(3);
log.Info("Setting successful!, the current voltage should be:" + cbSHT.Checked.ToString());
}
else
{
ShowMessage(4);
log.Error("Voltage setting failed!");
}
}
catch (Exception ex)
{
//记录日志信息(异常日志)
log.Error(ex.Message.ToString());
}
}
private void btnGScanMode_Click(object sender, EventArgs e)
{
}
private void btnScanMode_Click(object sender, EventArgs e)
{
}
#endregion
private void btnGLienTime_Click(object sender, EventArgs e)
{
}
private void bVoltageClose_Click(object sender, EventArgs e)
{
bool a_HTValue = false;
bool result = m_SemHardwareMgr.SetSemBeamCurrentOff(a_HTValue);
}
private void bVoltageStatus_Click(object sender, EventArgs e)
{
bool a_HTValue = false;
bool result = m_SemHardwareMgr.SetSemBeamBlank(a_HTValue);
}
private void button1_Click(object sender, EventArgs e)
{
bool result = m_SemHardwareMgr.SetScanExternal(true);
if (!result)
{
MessageBox.Show("SetExternalOn failed!");
}
}
private void button2_Click(object sender, EventArgs e)
{
bool result = m_SemHardwareMgr.SetScanExternal(false);
if (!result)
{
MessageBox.Show("SetExternalOn failed!");
}
}
private void label17_Click(object sender, EventArgs e)
{
}
private void button3_Click_1(object sender, EventArgs e)
{
bool result = m_SemHardwareMgr.SetSemHTOff(false);
}
private void btn_HIGH_VACUUM_Click(object sender, EventArgs e)
{
m_SemHardwareMgr.RunHIGH_VACUUM();
}
private void btn_StopImageAcquisition_Click(object sender, EventArgs e)
{
m_SemHardwareMgr.StopImageAcquisition();
}
private void btn_FullFrame_Click(object sender, EventArgs e)
{
m_SemHardwareMgr.SetFullFrame();
}
private void btn_SetReducedArea_Click(object sender, EventArgs e)
{
m_SemHardwareMgr.SetReducedArea();
}
}
}