一厂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.
 
 
 
 
 

265 lines
9.0 KiB

using PaintingPC;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;
namespace PunchingMistake
{
public partial class FrmQuality : Form
{
int count = 0; //缺陷图选择个数
private static string position = "", reason = "";
private string _isTest = "false";
public FrmQuality()
{
InitializeComponent();
InitPage();
this.Size = new Size(1280, 1020);
}
public void InitPage()
{
try
{
string title = ConfigurationManager.AppSettings["Display"].ToString();
string station = ConfigurationManager.AppSettings["Station"].ToString();
labTitle.Text = title;
}
catch (Exception ex)
{
}
}
private void dateTimer_Tick(object sender, EventArgs e)
{
labTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
try
{
LoadPage();
}
catch (Exception ex)
{
MessageBox.Show("请查看网络是否与服务器连通,无法连通请联系网络管理员。" + ex);
}
}
}
private void LoadPage()
{
try
{
string barcode = txtBarCode.Text.Trim();
if (barcode.Contains("."))
{
barcode = Function.TransToBarCodeOne(barcode);
}
//根据条码查询,加载图片及原因
int row = 0, col = 0;
string picture = "";
#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, 15, 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;
panel2.Controls.Add(dLb[i]);
dLb[i].Click += new EventHandler(dLbRoom_Click);
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
#endregion
#region 加载图片
try
{
DataTable dt = Function.SearchInfoByBarCode(barcode);
if (dt != null && dt.Rows.Count > 0)
{
row = Convert.ToInt32(dt.Rows[0]["Rows"].ToString());
col = Convert.ToInt32(dt.Rows[0]["Cols"].ToString());
picture = dt.Rows[0]["PicturePath"].ToString();
}
dt.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
}
catch (Exception ex)
{
MessageBox.Show("请查看网络是否与服务器连通,无法连通请联系网络管理员。" + ex.ToString());
}
}
/// <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 + ";", "");
}
}
/// <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--;
}
}
}
}