File name
Commit message
Commit date
File name
Commit message
Commit date
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
namespace KHSCALE_TP
{
public partial class FormScale : Form
{
// 전자 저울 변수 선언
private SerialBase m_ser = null;
private string m_strip = "";
private string m_strTouchid = "";
private DateTime m_updTime = DateTime.Now;
public FormScale()
{
InitializeComponent();
}
private void FormScale_Load(object sender, EventArgs e)
{
m_updTime = DateTime.Now;
this.WindowState = FormWindowState.Minimized;
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
m_strip = ip.ToString();
}
//m_strip = "192.168.1.121";
U3Database db = new U3Database();
try
{
DataTable dt = db.OpenSQL("select * from T_STD_MACH where MACH_TYPE = 'TP'");
foreach (DataRow dr in dt.Rows)
{
if (dr["REMARK01"].ToString() == m_strip)
{
m_strTouchid = dr["MACH_CD"].ToString();
this.textEdit_tpid.Text = m_strTouchid;
break;
}
}
}
catch
{
}
SetScale();
this.textEdit_ipaddr.Text = m_strip;
if (m_ser != null)
this.textEdit_com.Text = m_ser.GetComSetting();
else
this.textEdit_com.Text = "통신설정 실패";
timer_min.Enabled = true;
timer_min.Interval = 20000;
timer_save.Enabled = true;
timer_save.Interval = 1000;
}
private void SetScale()
{
//CAS 501/600
if (m_strip == "192.168.1.121" || m_strip == "192.168.1.124")
{
m_ser = new ComCasCi501();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
//ICS9000
else if (m_strip == "192.168.1.125")
{
m_ser = new ComIcs9000();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
//FS-1020C
else if (m_strip == "192.168.1.126" || m_strip == "192.168.1.127" || m_strip == "192.168.1.128" || m_strip == "192.168.1.122" || m_strip == "192.168.1.123")
{
m_ser = new ComFs1020c();
m_ser.Init("COM1", 9600, 0, 8, 1);
}
else if (m_strip == "192.168.1.129")
{
m_ser = new ComFs1020c();
// 구리스는 COM2 / 그 외는 COM1
m_ser.Init("COM2", 9600, 0, 8, 1);
}
else
{
m_ser = null;
}
}
private void timer_min_Tick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void timer_save_Tick(object sender, EventArgs e)
{
if (m_ser != null)
{
this.m_updTime = m_ser.GetUpdTime();
this.textEdit_value.Text = m_ser.GetValue().ToString();
this.textEdit_rxcount.Text = m_ser.GetRecvCount().ToString();
this.textEdit_updtime.Text = m_updTime.ToString("yyyy-MM-dd HH:mm:ss");
string strSQL = "";
strSQL += " update T_HT_REAL_SCALE set ";
strSQL += " SCALE_VALUE = " + m_ser.GetValue().ToString() + ",";
strSQL += " REG_IP = '" + m_strip + "',";
strSQL += " REG_DT = getdate() ";
strSQL += " where COMP_CD = '0001' and TOUCH_CD = '" + m_strTouchid + "'";
U3Database db = new U3Database();
int nResult = db.ExcuteSql(strSQL);
if (nResult == 0)
{
string strSQL2 = "";
strSQL2 += " insert into T_HT_REAL_SCALE (COMP_CD, TOUCH_CD) values ('0001', ";
strSQL2 += " '" + m_strTouchid + "') ";
db.ExcuteSql(strSQL2);
db.ExcuteSql(strSQL);
}
}
else
{
this.textEdit_value.Text = "";
this.textEdit_rxcount.Text = "";
this.textEdit_updtime.Text = "";
}
// 5분 이상 저울 값이 갱신이 안되고 있으면 프로그램 재 시작
if ((DateTime.Now - m_updTime).TotalMinutes >= 5)
{
timer_save.Enabled = false;
Application.Restart();
}
}
private void button_test_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
//Application.Restart();
}
private void FormScale_FormClosing(object sender, FormClosingEventArgs e)
{
// 윈도우 종료가 아닐때만 프로그램 종료 안되게
if (e.CloseReason != CloseReason.WindowsShutDown)
{
this.WindowState = FormWindowState.Minimized;
e.Cancel = true;
}
}
}
}