You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

380 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Mesnac.Compressor.Data;
using Mesnac.Action.Default.Purview;
using SocketProcess;
using System.Threading;
using Mesnac.Compressor.Entity;
namespace DisassemblyTable
{
public partial class Disassembly : Form
{
SerialEquip Com;
SocketServer socket;
string Port= System.Configuration.ConfigurationManager.AppSettings["para"];
string connType= System.Configuration.ConfigurationManager.AppSettings["Type"];
public delegate void Transit(string data);
public string NGStationID = "";
public Disassembly()
{
InitializeComponent();
//FrmSysLogin frmlogin = new FrmSysLogin();
//frmlogin.ShowDialog();
//if (!UserInfo.Instance.islogin)
//{
// this.Close();
//}
InitPort();
//initCombox();
}
public void InitPort()
{
if (connType.ToLower() == "socket")
{
socket = new SocketServer();
ThreadPool.QueueUserWorkItem(new WaitCallback(Thread), Port);
socket.ReciveEvent += socketRecieve;
}
else if (connType.ToLower() == "com")
{
// string Port = "COM3";
Com = new SerialEquip(connType+Port);
Com.OpenCom(null);
Com.SerialData += Receive;
}
else
{
MessageBox.Show("未找到通信类型:"+ connType);
}
}
public void Thread(object o)
{
int port=Convert.ToInt32(o);
socket.StartService(port);
}
public void socketRecieve(string barcode, object o)
{
Receive(barcode);
}
public void Receive(string Data)
{
if (this.InvokeRequired)
{
this.Invoke(new Transit(Receive), Data);
return;
}
try
{
Console.WriteLine("扫描数据" + Data + "数据完成");
ClearAllControl();
if (!Data.Trim().Contains("E") && Data.Length < 10)
{
return;
}
textBox1.Text = Data.Trim();
DbHandler db = new DbHandler();
DataSet ds = db.Select(Data.Trim());
if (ds == null || ds.Tables.Count < 1)
{
MessageBox.Show("未查询到当前条码生产NG信息");
//this.tb_ngstation.Text = "140氦气检漏";
//DataTable dt = GetNewDatatable();
//dataGridView1.DataSource = dt;
return;
}
DataTable dt1 = ds.Tables[0];
if (dt1 != null && dt1.Rows.Count > 0)
{
DataRow dr = dt1.Rows[0];
string NGstation = dr["StationName"].ToString();
this.tb_ngstation.Text = NGstation;
}
else
{
//MessageBox.Show("未查询到当前条码生产NG信息");
this.tb_ngstation.Text = "140氦气检漏";
DataTable dt = GetNewDatatable();
dataGridView1.DataSource = dt;
return;
}
if (ds.Tables.Count > 1)
{
dataGridView1.DataSource = ds.Tables[1];
}
}
catch
{
}
} //cb_qiangai.Enabled = false; cb_zhuanzi.Enabled = false; cb_allRestart.Enabled = false;
//private void button1_Click(object sender, EventArgs e)
//{
// try
// {
// if (string.IsNullOrEmpty(textBox1.Text))
// {
// MessageBox.Show("条码为空!", "提示!");
// return;
// }
// DbHandler db = new DbHandler();
// int state1 = 0, state2 = 0, state3 = 0, state4 = 0;
// string RestartStation = "";
// string checker = UserInfo.Instance.UserName;
// if (cb_qiangai.Enabled == true)
// {
// if (cb_qiangai.CheckState == CheckState.Checked)
// {
// state1 = 1;
// }
// else
// {
// state1 = 0;
// }
// }
// if (cb_zhuanzi.Enabled == true)
// {
// if (cb_zhuanzi.CheckState == CheckState.Checked)
// {
// state2 = 1;
// }
// else
// {
// state2 = 0;
// }
// }
// if (cb_allRestart.Enabled == true)
// {
// if (cb_allRestart.CheckState == CheckState.Checked)
// {
// state3 = 1;
// RestartStation = comboBox1.SelectedValue.ToString();
// //RestartStation = NGStationID;
// }
// else
// {
// state3 = 0;
// }
// }
// if (cb_AllScrapped.Checked)
// {
// state4 = 1;
// }
// if (db.Test(textBox1.Text, state1, state2, state3, state4, RestartStation, checker))
// {
// MessageBox.Show("拆解成功!", "提示!");
// ClearAllControl();
// }
// else
// {
// MessageBox.Show("拆解失败!", "提示!");
// }
// }
// catch(Exception ex)
// {
// //MessageBox.Show(ex.ToString());
// }
//}
private void ClearAllControl()
{
this.textBox1.Text = "";
dataGridView1.DataSource = null;
this.tb_ngstation.Text = "";
}
private void Disassembly_FormClosing(object sender, FormClosingEventArgs e)
{
if (connType.ToLower() == "socket")
{
//socket.StopService();
socket.ReciveEvent -= socketRecieve;
}
else if (connType.ToLower() == "com")
{
Com.Close();
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private DataTable GetNewDatatable()
{
DataTable dt = new DataTable();
dt.Columns.Add("NG工位",typeof(string));
dt.Columns.Add("记录时间", typeof(string));
dt.Columns.Add("漏率显示", typeof(string));
dt.Columns.Add("漏率显示最小值", typeof(string));
dt.Columns.Add("漏率显示最大值", typeof(string));
dt.Columns.Add("漏率显示状态", typeof(string));
dt.Columns.Add("漏率显示幂值", typeof(string));
dt.Columns.Add("漏率显示幂值最小值", typeof(string));
dt.Columns.Add("漏率显示幂值最大值", typeof(string));
dt.Columns.Add("漏率显示幂值状态", typeof(string));
dt.Columns.Add("真空压力", typeof(string));
dt.Columns.Add("真空压力最小值", typeof(string));
dt.Columns.Add("真空压力最大值", typeof(string));
dt.Columns.Add("真空压力状态", typeof(string));
DataRow dataRow = dt.NewRow();
dataRow["NG工位"] = "140氦气检漏";
dataRow["记录时间"] = DateTime.Now.ToString("yyyy/MM/dd");
dataRow["漏率显示"] = "0.0000";
dataRow["漏率显示最小值"] = "0.0000";
dataRow["漏率显示最大值"] = "0.0000";
dataRow["漏率显示状态"] = "不合格";
dataRow["漏率显示幂值"] = "0.0000";
dataRow["漏率显示幂值最小值"] = "0.0000";
dataRow["漏率显示幂值最大值"] = "0.0000";
dataRow["漏率显示幂值状态"] = "不合格";
dataRow["真空压力"] = "0.0000";
dataRow["真空压力最小值"] = "0.0000";
dataRow["真空压力最大值"] = "0.0000";
dataRow["真空压力状态"] = "不合格";
dt.Rows.Add(dataRow);
return dt;
}
private void button1_Click(object sender, EventArgs e)
{
string Data = "";
//ClearAllControl();
Data=textBox1.Text.Trim();
//Data = "SJ1811020005";
Console.WriteLine("扫描数据"+ Data);
DbHandler db = new DbHandler();
DataSet ds = db.Select(Data);
if (ds==null||ds.Tables.Count < 1)
{
//MessageBox.Show("未查询到当前条码生产NG信息");
this.tb_ngstation.Text = "140氦气检漏";
DataTable dt = GetNewDatatable();
dataGridView1.DataSource = dt;
return;
}
DataTable dt1 = ds.Tables[0];
if (dt1 != null && dt1.Rows.Count > 0)
{
DataRow dr = dt1.Rows[0];
string NGstation = dr["StationName"].ToString();
this.tb_ngstation.Text = NGstation;
}
else
{
//MessageBox.Show("未查询到当前条码生产NG信息");
this.tb_ngstation.Text = "140氦气检漏";
DataTable dt = GetNewDatatable();
dataGridView1.DataSource = dt;
return;
}
if (ds.Tables.Count > 1)
{
dataGridView1.DataSource = ds.Tables[1];
}
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1.Columns[i].Frozen = false;
}
}
private void BindReStartStationInfo()
{
try
{
DbHandler db = new DbHandler();
cbReStartStation.DisplayMember = "StationName";
cbReStartStation.ValueMember = "StationID";
cbReStartStation.DataSource = db.GetReStartStationList();
}
catch (Exception ex)
{
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text.Trim() == "")
{
MessageBox.Show("条码为空!", "提示!");
return;
}
DbHandler dbHandler = new DbHandler();
//这里要判断下是否存在条码
bool isHaveData = dbHandler.IsHaveTraceState(textBox1.Text.Trim());
//数据库里不存在该记录,有可能转盘上线工位没绑定
if (!isHaveData)
{
//手动插入一条记录
tb_ngstation.Text = "未查询到当前条码生产信息!";
//生成M码A码
string Asemibacode = dbHandler.CreatNewSemibarcode();
string MBarCode = dbHandler.GetLastMainBarcode("M");
string machineID = dbHandler.GetNowProductionInfo();
dbHandler.InsertTrace(MBarCode, Asemibacode, textBox1.Text.Trim(), machineID);
}
//修改重投字段为2
//更新重投工位字段
bool iflag = dbHandler.UpdateTraceReStartStation("2", cbReStartStation.SelectedValue.ToString(), textBox1.Text.Trim());
if (iflag)
{
//修改重投状态T_RP_SemiProInfo
textBox1.Text = "";
MessageBox.Show("重投工位设定成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("重投工位设定失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
}
}
private void Disassembly_Load(object sender, EventArgs e)
{
BindReStartStationInfo();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
}
}