一厂MES,含注塑,喷涂,冲孔
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

869 lines
29 KiB

using PaintingPC.Model;
using PaintingPC.WebReference;
using System;
using System.Linq;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
using MESClassLibrary.BLL.BasicInfo;
using static System.Windows.Forms.AxHost;
namespace PaintingPC
{
public partial class FrmQualityOnLine : Form
{
int count = 0; //缺陷图选择个数
public static string paintId = "";
private static string position = "", reason = "", responsible = "";
private string _stationType = "上线前质检";
private string _isTest = "false";
//责任方
private List<string> _selectResponsibles = new List<string>();
//扫描的喷涂行数据
private DataRow _scanPaintRow = null;
public FrmQualityOnLine()
{
InitializeComponent();
//WindowState = FormWindowState.Normal;
this.Size = new Size(1280, 1020);
_isTest = ConfigurationManager.AppSettings["测试"]?.ToString();
labProPosition.Text = Program.station;
}
private void FrmSecondCheck_Load(object sender, EventArgs e)
{
try
{
Control.CheckForIllegalCrossThreadCalls = false;
UpdateSoftware();
InitPage();
}
catch (Exception ex)
{
MessageBox.Show("网络故障,请联系网络管理员");
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
}
public void InitPage()
{
try
{
string title = ConfigurationManager.AppSettings["Display"].ToString(); ;
string workClass = Function.GetWorkClass2();
string station = ConfigurationManager.AppSettings["Station"].ToString();
labTitle.Text = title;
Program.IP = ConfigurationManager.AppSettings["IP"].ToString();
Thread t = new Thread(new ThreadStart(TimeGo));
t.Start();
}
catch (Exception ex)
{ }
}
/// <summary>
/// 初始化颜色选择框列表
/// </summary>
/// <param name="stockNo"></param>
public void InitColor(string stockNo)
{
try
{
DataTable dt = Function.GetColorByStockNo(stockNo);
if(dt.Rows.Count == 0)
{
lbForeig.Text = $"基础数据-产品颜色菜单未配置[{stockNo}]的颜色信息";
}
DataRow dr = dt.NewRow();
dr["Color"] = "";
dt.Rows.InsertAt(dr, 0);
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
throw ex;
}
}
private void TimeGo()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 10;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
}
private void timer_Tick(object sender, EventArgs e)
{
try
{
labTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Thread.Sleep(500);
}
catch
{
}
}
/// <summary>
/// 缺陷图点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void lblRoom_Click(object sender, EventArgs e)
{
Label a = (Label)sender;
string aa = a.Text;
if (a.BackColor == Color.Transparent)
{
a.BackColor = Color.FromArgb(150, System.Drawing.Color.Chartreuse);
position += aa;
count++;
}
else
{
a.BackColor = Color.Transparent;
count--;
}
if(!string.IsNullOrEmpty(position) && position.EndsWith(";"))
{
position = position.Substring(0, position.Length - 1);
}
}
/// <summary>
/// 缺陷原因点击
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void dLbRoom_Click(object sender, EventArgs e)
{
if (count == 0)
{
MessageBox.Show("请选择缺陷区域!");
return;
}
Label a = (Label)sender;
string aa = a.Text;
if (a.BackColor == Color.Transparent)
{
a.BackColor = Color.Chartreuse;
reason += a.Text + ";";
}
else
{
a.BackColor = Color.Transparent;
reason = reason.Replace(a.Text + ";", "");
}
}
private Control[] SetControlGroup()
{
Control[] controls = { };
return controls;
}
/// <summary>
/// 清除控件选中
/// </summary>
/// <param name="controls"></param>
public void ClearControlColor(Control[] controls)
{
foreach (Control c in controls)
{
c.BackColor = Color.LightGray;
}
}
/// <summary>
/// 合格
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnOk_Click(object sender, EventArgs e)
{
try
{
if (_scanPaintRow == null)
{
MessageBox.Show("请先扫描数据,然后操作.");
return;
}
ShowHint("");
SaveRst("合格", _scanPaintRow);
}
catch(Exception ex)
{
ShowHint("执行合格判定发生异常,异常原因:" + ex.Message);
MessageBox.Show("执行合格判定发生异常,异常原因:" + ex.Message);
Clear();
}
}
void Clear()
{
ClearPage();
ClearTxtBarcode();
txtBarCode.TabIndex = 0;
}
/// <summary>
/// 点修补按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRepair_Click(object sender, EventArgs e)
{
try
{
if (_scanPaintRow == null)
{
MessageBox.Show("请先扫描数据,然后操作.");
return;
}
ShowHint("");
#region 必须选择缺陷位置与缺陷原因,否则无法保存
if (CheckDefect() == false) return;
#endregion
btnRepair.BackColor = Color.Yellow;
SaveRst("点修补", _scanPaintRow);
}
catch (Exception ex)
{
ShowHint("判定点修补操作发生异常,异常原因:" + ex.Message);
MessageBox.Show("判定点修补操作发生异常,异常原因:" + ex.Message);
Clear();
}
}
private void btnPG_Click(object sender, EventArgs e)
{
try
{
if (_scanPaintRow == null)
{
MessageBox.Show("请先扫描数据,然后操作.");
return;
}
ShowHint("");
#region 必须选择缺陷位置与缺陷原因,否则无法保存
if (CheckDefect() == false) return;
#endregion
SaveRst("抛光", _scanPaintRow);
}
catch (Exception ex)
{
ShowHint("执行报废操作发生异常,异常原因:" + ex.Message);
MessageBox.Show("执行报废操作发生异常,异常原因:" + ex.Message);
Clear();
}
}
/// <summary>
/// 报废按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAbt_Click(object sender, EventArgs e)
{
try
{
if (_scanPaintRow == null)
{
MessageBox.Show("请先扫描数据,然后操作.");
return;
}
ShowHint("");
#region 必须选择缺陷位置与缺陷原因,否则无法保存
if (CheckDefect() == false) return;
#endregion
SaveRst("报废", _scanPaintRow);
}
catch(Exception ex)
{
ShowHint("执行报废操作发生异常,异常原因:" + ex.Message);
MessageBox.Show("执行报废操作发生异常,异常原因:" + ex.Message);
Clear();
}
}
/// <summary>
///
/// </summary>
/// <param name="state"></param>
/// <param name="colorName"></param>
/// <param name="partName"></param>
/// <param name="isOK">0-不合格;1-合格;9-返喷 8-其他 </param>
void SaveRst(string state, DataRow paintRow, string userName="")
{
if (string.IsNullOrEmpty(userName))
{
userName = Program.UserName;
}
string bcode = txtBarCode.Text.Trim();
//保存
string id = SaveInspect(state, _scanPaintRow, userName);
if (!string.IsNullOrEmpty(id))
{
_scanPaintRow = null;
ShowHint("操作成功", true);
ClearPage();
}
}
/// <summary>
/// 必须选择缺陷位置与缺陷原因,否则无法保存
/// </summary>
/// <returns></returns>
bool CheckDefect()
{
string damnPositionTemp = "";
string reasonTemp = "";
string responsibTemp = "";
//缺陷位置
foreach (Control c in pictureBox2.Controls)
{
Label lab = c as Label;
if (lab.BackColor != Color.Transparent)
{
damnPositionTemp += lab.Text + ";";
position = damnPositionTemp;
}
}
//缺陷原因
foreach (Control c in panel2.Controls)
{
Label lab = c as Label;
if (lab.BackColor != Color.Transparent)
{
reasonTemp += lab.Text + ";";
reason = reasonTemp;
}
}
foreach (Control c in panelResponsibility.Controls)
{
Label lab = c as Label;
if (lab.BackColor != Color.Transparent)
{
responsibTemp += lab.Text + ";";
responsible = responsibTemp;
}
}
if (string.IsNullOrWhiteSpace(damnPositionTemp) || string.IsNullOrWhiteSpace(reasonTemp))
{
MessageBox.Show("必须选择缺陷位置与缺陷原因,否则无法保存!");
return false;
}
if (_selectResponsibles.Count == 0)
{
MessageBox.Show("必须选择责任部门,否则无法保存!");
return false;
}
return true;
}
/// <summary>
/// 保存质检记录 tb_InspectResult
/// </summary>
/// <param name="inspectResult"></param>
/// <param name="colorName"></param>
/// <param name="partName"></param>
/// <returns> 返回插入记录的ID</returns>
public string SaveInspect(string inspectResult,DataRow scanPaintRow,string userName)
{
try
{
if (!string.IsNullOrWhiteSpace(txtBarCode.Text.Trim()))
{
InspectModel model1 = new InspectModel();
model1.barcode = scanPaintRow["BarCode"].ToString();
model1.position = _stationType;
model1.stationNo = Program.station;
model1.inspectResult =inspectResult;
model1.damnPosition = position;
model1.reason = reason;
model1.Responsible = responsible;// string.Join(",", _selectResponsibles);
model1.remark3 = scanPaintRow["remark3"].ToString();
model1.ForeignPartCode = scanPaintRow["ForeignPartCode"].ToString();
model1.CarType = scanPaintRow["CarType"].ToString();
if (inspectResult != "合格")
{
if (string.IsNullOrWhiteSpace(model1.damnPosition) || string.IsNullOrWhiteSpace(model1.reason) || string.IsNullOrWhiteSpace(model1.Responsible))
{
MessageBox.Show("必须选择缺陷位置,缺陷原因与责任部门,否则无法保存!");
return "";
}
}
model1.productInfo = scanPaintRow["productInfo"].ToString();
model1.side = scanPaintRow["side"].ToString();
model1.InspectTimes = "1";
model1.remark1 = scanPaintRow["remark1"].ToString();
model1.remark2 = scanPaintRow["remark2"].ToString();
model1.remark3 = scanPaintRow["remark3"].ToString();
model1.AddMan = userName;
return Function.InsertInspect3(model1);
}
return "";
}
catch (Exception ex)
{
ShowHint("质检提交异常,原因:" + ex.Message);
LogHelper.WriteErrLogBase("质检提交:" + ex.ToString(), MethodBase.GetCurrentMethod().Name);
MessageBox.Show("质检提交异常,原因:" + ex.Message);
return null;
}
}
void ShowHint(string txt,bool isOk =false)
{
lbForeig.ForeColor = Color.Red;
lbForeig.Text = txt;
if(isOk == true)
{
lbForeig.ForeColor = Color.Green;
}
}
public void ClearInspect()
{
//缺陷位置
foreach (Control c in pictureBox2.Controls)
{
Label lab = c as Label;
lab.BackColor = Color.Transparent;
}
//缺陷原因
foreach (Control c in panel2.Controls)
{
Label lab = c as Label;
lab.BackColor = Color.Transparent;
}
foreach (var cont in panelResponsibility.Controls)
{
if (cont is Label)
{
if ((cont as Label).Tag != null && (cont as Label).Tag.ToString() == "Response")
(cont as Label).BackColor = Color.Transparent;
}
}
}
/// <summary>
/// 扫码-根据条码查询信息(产品信息、加载图片及缺陷原因、三次检验信息)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
try
{
btnOk.Enabled = true;
btnRepair.Enabled = true;
lbForeig.Text = "";
ClearPage();
ScanBarCode();
timer1.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show("请查看网络是否与服务器连通,无法连通请联系网络管理员。"+ ex);
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
}
}
private void ScanBarCode()
{
try
{
ButtonEnable(SetControlGroup());
//ClearPage();
//测试条码:11111111112222222222
string barcode = txtBarCode.Text.Trim();
if (barcode.Contains("."))
{
barcode = Function.TransToBarCodeOne(barcode);
}
#region 判断条码有效性
if (! Function.BarCodeValid(barcode))
{
MessageBox.Show("扫描的条码号:"+barcode+"无效,请重新扫描!");
txtBarCode.Text = "";
return;
}
#endregion
_scanPaintRow = GetRecentRstInfo(barcode);
if(_scanPaintRow["inspectResult"].ToString().Contains("合格") == false)
{
MessageBox.Show("扫描的条码号:" + barcode + "喷涂线不是合格状态,请重新扫描!");
txtBarCode.Text = "";
return;
}
labProductInfo.Text = _scanPaintRow["productInfo"].ToString();
//根据条码查询,加载图片及原因
int row = 0, col = 0;
string picture = "";
foreach (var cont in panelResponsibility.Controls)
{
if (cont is Label)
{
if ((cont as Label).Tag != null && (cont as Label).Tag.ToString() == "Response")
(cont as Label).BackColor = Color.Transparent;
}
}
#region 缺陷原因
try
{
int drow = 0, dcol = 5; //行,列
DataTable dt3 = Function.SearchDefectInfo(ConfigurationManager.AppSettings["Station"].Trim());
if (dt3 != null && dt3.Rows.Count > 0)
{
drow = Convert.ToInt32(Math.Ceiling((double)dt3.Rows.Count / dcol));
Label[] dLb = new Label[7];
string[] dstr = new string[dt3.Rows.Count];
for (int i = 0; i < dt3.Rows.Count; i++)
{
dstr[i] = dt3.Rows[i]["DefectName"].ToString();
}
for (int i = 0; i < dcol; i++) //列
{
for (int j = 0; j < drow; j++) //行
{
dLb[i] = new Label();
if ((i + dcol * j) < dstr.Length)
{
dLb[i].Text = dstr[i + dcol * j].ToString();
dLb[i].Font = new Font(dLb[i].Font.FontFamily, 24, FontStyle.Bold);
dLb[i].Size = new Size(150, 50);
dLb[i].Location = new Point(20 + i * (dLb[i].Size.Width + 25), 5 + j * (dLb[i].Size.Height + 20));
dLb[i].BorderStyle = BorderStyle.FixedSingle;
dLb[i].BackColor = Color.Transparent;
dLb[i].TextAlign = ContentAlignment.MiddleCenter;
if (dLb[i].Text.Contains("点修补"))
{
dLb[i].Font = new Font(dLb[i].Font.FontFamily, 36, FontStyle.Bold);
dLb[i].Size = new Size(170, 60);
dLb[i].ForeColor = Color.Red;
//dLb[i].BackColor = Color.Red;
}
panel2.Controls.Add(dLb[i]);
dLb[i].Click += new EventHandler(dLbRoom_Click);
}
}
}
}
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
LogHelper.WriteErrLogBase("缺陷项-"+ex.ToString(), MethodBase.GetCurrentMethod().Name);
throw ex;
}
#endregion
#region 加载图片
try
{
DataTable dt2 = Function.SearchInfoByBarCode(barcode);
if (dt2 != null && dt2.Rows.Count > 0)
{
row = Convert.ToInt32(dt2.Rows[0]["Rows"].ToString());
col = Convert.ToInt32(dt2.Rows[0]["Cols"].ToString());
picture = dt2.Rows[0]["PicturePath"].ToString();
}
dt2.Dispose();
if (!string.IsNullOrEmpty(picture))
{
if (!File.Exists(System.IO.Directory.GetCurrentDirectory() + @"\" + picture))
{
string strImageURL = Function.GetImgPath() + picture;
if(_isTest != "true")
{
System.Net.WebClient webClient = new System.Net.WebClient();
webClient.DownloadFile(strImageURL, Directory.GetCurrentDirectory() + @"\" + picture);
}
}
FileStream fs = new FileStream(Directory.GetCurrentDirectory() + "\\" + picture, FileMode.Open,
FileAccess.Read);//获取图片文件流
Image img = Image.FromStream(fs); // 文件流转换成Image格式
pictureBox2.Image = img; //给 图片框设置要显示的图片
fs.Close(); // 关闭流,释放图片资源
}
}
catch (Exception ex)
{
LogHelper.WriteLogManager(ex);
LogHelper.WriteErrLogBase("图片项-" + ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
#endregion
#region 缺陷图划分区域
Label[] lb = new Label[5];
string[] str = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
for (int i = 0; i < col; i++)
{
for (int j = 0; j < row; j++)
{
lb[i] = new Label();
lb[i].Text = str[i + col * j].ToString();
lb[i].Font = new Font(lb[i].Font.FontFamily, 32, FontStyle.Bold);
lb[i].Size = new Size(pictureBox2.Width / col, pictureBox2.Height / row);
lb[i].Location = new Point(0 + i * lb[i].Size.Width, 0 + j * lb[i].Size.Height);
lb[i].BorderStyle = BorderStyle.FixedSingle;
lb[i].BackColor = Color.Transparent;
lb[i].TextAlign = ContentAlignment.MiddleCenter;
pictureBox2.Controls.Add(lb[i]);
lb[i].Click += new EventHandler(lblRoom_Click);
}
}
#endregion
txtBarCode.SelectAll();
}
catch (Exception ex)
{
MessageBox.Show("请查看网络是否与服务器连通,无法连通请联系网络管理员。" + ex.ToString());
LogHelper.WriteLogManager(ex);
LogHelper.WriteErrLogBase("整体项-" + ex.ToString(), MethodBase.GetCurrentMethod().Name);
}
}
/// <summary>
/// 喷涂库最新质检记录
/// </summary>
/// <param name="barcode"></param>
/// <returns></returns>
private DataRow GetRecentRstInfo(string barcode)
{
//tb_InspectResult 中最新质检结果
DataTable dt = Function.GetLastResult(barcode);
if(dt.Rows.Count == 0)
{
throw new Exception("塑件条码没有喷涂质检记录");
}
DataRow dr = dt.Rows[0];
if(_isTest == "false")
{
string errorMsg = string.Empty;
//wms是否喷涂下线
bool isExsit = Function.GetPointRepairFrWms(barcode, ref errorMsg);
if (isExsit == false)
{
if (!string.IsNullOrEmpty(errorMsg))
{
throw new Exception("在wms系统的查询返修入库记录时发生错误,错误原因:" + errorMsg);
}
else
{
throw new Exception("没有在wms系统的返修入库记录,无法进行点修补.");
}
}
}
return dr;
}
/// <summary>
/// 设置按钮可用
/// </summary>
/// <param name="controls"></param>
private void ButtonEnable(Control[] controls)
{
foreach (Control c in controls)
{
Button btn = c as Button;
btn.Enabled = true;
}
}
/// <summary>
/// 点击退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void labTime_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
/// <summary>
/// 清空页面
/// </summary>
private void ClearPage()
{
labProductInfo.Tag = null;
labProductInfo.Text = "";
//btnAbt.BackColor = Color.LightGray;
//btnRepair.BackColor = Color.LightGray;
//ClearRadioButton();
ClearInspect();
ClearControlColor(SetControlGroup());
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
pictureBox2.Image = null;
txtBarCode.TabIndex = 0;
txtBarCode.Select();
position = "";
reason = "";
}
public void ClearTxtBarcode()
{
txtBarCode.Text = "";
labProPosition.Text = "";
}
/// <summary>
/// 其他按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//private void button1_Click(object sender, EventArgs e)
//{
// ClearControlColor(SetControlGroup());
// //btnPass.BackColor = Color.GreenYellow;
// //保存
// SaveInspect("其他");
// ClearPage();
// ClearTxtBarcode();
// txtBarCode.TabIndex = 0;
//}
private void UpdateSoftware()
{
return;
}
private void txtBarCode_DoubleClick(object sender, EventArgs e)
{
txtBarCode.SelectAll();
}
private void panelResponsibility_Paint(object sender, PaintEventArgs e)
{
}
private void Responsibility_Click(object sender, EventArgs e)
{
Label a = (Label)sender;
foreach (var cont in panelResponsibility.Controls)
{
if (cont is Label)
{
if ((cont as Label).Tag != null && (cont as Label).Tag.ToString() == "Response")
(cont as Label).BackColor = Color.Transparent;
}
}
if (a.BackColor == Color.Transparent)
{
a.BackColor = Color.Chartreuse;
_selectResponsibles.Clear();
_selectResponsibles.Add(a.Text);
}
else
{
a.BackColor = Color.Transparent;
_selectResponsibles.Clear();
}
}
}
}