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

1165 lines
41 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.BLL.Injection;
using MESClassLibrary.BLL.Inspection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.TruckBox;
using MESClassLibrary.DAL;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
namespace InjectionPC
{
public partial class FrmQuality : Form
{
private static string position = "", reason = "";
private bool _isScanBarCode = true;
int count = 0; //缺陷图选择个数
private InjectionBoxBLL _injectionBoxBLL = new InjectionBoxBLL();
private BadInjectionBLL badBLL = new BadInjectionBLL();
private BadInjectionModel badmd = new BadInjectionModel();
private BarCodeBLL barbll = new BarCodeBLL();
private WmsBLL _wmsBll = new WmsBLL();
private string stationId = "";
private DataTable _boxDetailTable = null;
private List<string> _boxDelList = new List<string>();
internal event Action<List<string>> QualityViewClosed = null;
public FrmQuality(bool isSingle = false)
{
InitializeComponent();
this.Size = new Size(1280, 1024);
if(isSingle == true)
{
txtBoxCode.Enabled = false;
txtBoxCode.KeyDown -= textBox1_KeyDown;
}
}
private void label9_Click(object sender, EventArgs e)
{
this.Close();
//OnVisibleChanged()
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
if (!IsHandleCreated)
{
this.Close();
}
}
private void FrmQuality_Load(object sender, EventArgs e)
{
Control.CheckForIllegalCrossThreadCalls = false;
string LineID = "";
label6.Text = Program.station;
label8.Text = Program.OperatorName;
comboBox1.Text = Program.Shift;
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
txtBoxCode.Enabled = false;
GetClass();
comboBox1.Enabled = false;
txtBoxCode.Text = "";
textBox2.Text = "";
Thread t = new Thread(new ThreadStart(TimeGo));
t.Start();
timer2.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal2"]);
timer2.Enabled = false;
StationBLL bll=new StationBLL();
DataTable dt = bll.SearchInfoByNo(Program.station);
if (dt != null && dt.Rows.Count > 0)
{
stationId = dt.Rows[0]["StationID"].ToString();
}
#region 测试
//获取服务器上图片
//Ping p1 = new Ping();
//bool status = false;
//PingReply reply = p1.Send(Program.IP); //发送主机名或Ip地址
//StringBuilder sbuilder;
//if (reply.Status == IPStatus.Success)
//{
// status = Upload.DoConnComputer(Program.IP, "aa", "Administrator", "Wff775168+");
// if (status == true)
// {
// //共享文件夹的目录
// DirectoryInfo theFolder = new DirectoryInfo(@"\\" + Program.IP + "\\aa\\");
// string filename = theFolder.ToString();
// //执行方法
// TransportRemoteToLocal(@"D:\车间.png", filename, "车间.png"); //实现将远程服务器文件写入到本地
// }
//}
//FileStream fs = new FileStream("D:\\2.jpg", FileMode.Open,
// FileAccess.Read);//获取图片文件流
//Image img = Image.FromStream(fs); // 文件流转换成Image格式
//pictureBox2.Image = img; //给 图片框设置要显示的图片
//fs.Close(); // 关闭流,释放图片资源
//Label[] lb = new Label[5];
//string[] str = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O" };
//for (int i = 0; i < 5; i++)
//{
// for (int j = 0; j < 3; j++)
// {
// lb[i] = new Label();
// lb[i].Text = str[i].ToString();
// lb[i].Font = new Font(lb[i].Font.FontFamily, 32, FontStyle.Bold);
// lb[i].Size = new Size(pictureBox2.Width / 5, pictureBox2.Height / 3);
// 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);
// }
//}
//StationBLL sbll = new StationBLL();
//DataTable sdt = sbll.SearchInfoByNo(Program.station);
//if (sdt != null && sdt.Rows.Count > 0)
//{
// LineID = sdt.Rows[0]["LineID"].ToString();
//}
//sdt.Dispose();
//int row = 0, col = 6;
//DefectBLL dbll = new DefectBLL();
//DataTable dt3 = dbll.SearchInfo(LineID);
//if (dt3 != null && dt3.Rows.Count > 0)
//{
// row = Convert.ToInt32(Math.Ceiling((double)dt3.Rows.Count / 6));
// 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 < 6; i++) //列
// {
// for (int j = 0; j < row;j++) //行
// {
// dLb[i] = new Label();
// if ((i + 6 * j) < dstr.Length)
// {
// dLb[i].Text = dstr[i + 6 * 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;
// panel2.Controls.Add(dLb[i]);
// }
// }
// }
//}
#endregion
txtScanBarCode.Text = Program.strBarCode;
lbBoxCode.Text = Program.strBoxCode;
txtScanBarCode.SelectAll();
if (ConfigurationManager.AppSettings["IsLast"] == "1")
{
label9.Visible = true;
}
else if (ConfigurationManager.AppSettings["IsLast"] == "0")
{
label9.Visible = false;
}
GetBadCount();
if (!string.IsNullOrEmpty(txtScanBarCode.Text))
{
textBox3_KeyDown(null, new KeyEventArgs( Keys.Enter));
}
}
private void TimeGo()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 1000;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
}
private void timer_Tick(object sender, EventArgs e)
{
try
{
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Thread.Sleep(500);
}
catch
{
}
}
/// <summary>
/// 从远程服务器下载文件到本地
/// </summary>
/// <param name="src">下载到本地后的文件路径,包含文件的扩展名</param>
/// <param name="dst">远程服务器路径(共享文件夹路径)</param>
/// <param name="fileName">远程服务器(共享文件夹)中的文件名称,包含扩展名</param>
public static void TransportRemoteToLocal(string src, string dst, string fileName) //src:下载到本地后的文件路径 dst:远程服务器路径 fileName:远程服务器dst路径下的文件名
{
try
{
FileStream inFileStream = new FileStream(src, FileMode.Open); //远程服务器文件 此处假定远程服务器共享文件夹下确实包含本文件,否则程序报错
if (!Directory.Exists(dst))
{
Directory.CreateDirectory(dst);
}
dst = dst + fileName;
FileStream outFileStream = new FileStream(dst, FileMode.OpenOrCreate); //从远程服务器下载到本地的文件
byte[] buf = new byte[inFileStream.Length];
int byteCount;
while ((byteCount = inFileStream.Read(buf, 0, buf.Length)) > 0)
{
outFileStream.Write(buf, 0, byteCount);
}
inFileStream.Flush();
inFileStream.Close();
outFileStream.Flush();
outFileStream.Close();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
void lblRoom_Click(object sender, EventArgs e)
{
Label a = (Label) sender;
//foreach (Control c in pictureBox2.Controls)
//{
// c.BackColor = Color.Transparent;
//}
if (a.BackColor == Color.Transparent)
{
a.BackColor = Color.FromArgb(150, System.Drawing.Color.Chartreuse);
count++;
}
else
{
a.BackColor = Color.Transparent;
count--;
}
//position +=a.Text+",";
}
void dLbRoom_Click(object sender, EventArgs e)
{
Label a = (Label)sender;
string aa = a.Text;
if (a.BackColor == Color.Transparent)
{
a.BackColor = Color.FromArgb(150, Color.Chartreuse);
reason += a.Text+";";
}
else
{
reason = reason.Replace(a.Text+";","");
a.BackColor = Color.Transparent;
}
}
/// <summary>
/// 保存缺陷 1.tb_Bad_Injection 增加记录 2.tb_Injection_BoxRecord表减一条数据 3. tb_BarCode1表 IsBad=1 4.[tb_Injectionn_Interface]表增加一条QaRst=1的数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
//string stockNo = "",batchNo="",partNo="",isbox="";
foreach (Control c in pictureBox2.Controls)
{
Label lab = c as Label;
if (lab.BackColor != Color.Transparent)
{
position += lab.Text + ";";
}
}
if (position == "")
{
MessageBox.Show("请选择缺陷位置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (reason == "")
{
MessageBox.Show("请选择缺陷原因!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
InjectionBoxBLL ibll=new InjectionBoxBLL();
InspectionBLL bll = new InspectionBLL();
tb_Inspection_tx md = new tb_Inspection_tx();
if (txtBoxCode.Text != "" && txtScanBarCode.Text != "")
{
MessageBox.Show("箱单和条码只能输入一个!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#region 大件报废
if (txtBoxCode.Text == "" && txtScanBarCode.Text != "")
{
SingleBadSave();
}
#endregion
#region 小件报废,直接修改产量,如果是开机报废减产量,否则产量不变增加报废数
if (txtBoxCode.Text != "" && txtScanBarCode.Text == "")
{
FullBoxBadSave(_boxDetailTable);
if (!_boxDelList.Contains(txtBoxCode.Text?.Trim()))
{
_boxDelList.Add(txtBoxCode.Text?.Trim());
}
}
#endregion
#region 插入质检总表
md.BarCode = badmd.OneBarCode;
md.IsOK = 0;
md.Station = 2;
bll.AddInfo(md);
#endregion
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.SelectAll();
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
txtBoxCode.Text = "";
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
position = "";
reason = "";
}
/// <summary>
/// 单个报废
/// </summary>
private void SingleBadSave()
{
string isbox = "";
#region 判断是否已做过报废
DataTable baddt = badBLL.SearchByCode(txtScanBarCode.Text.Trim()); //bad 表
if (baddt != null && baddt.Rows.Count > 0)
{
MessageBox.Show("请产品已做过报废处理!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return;
}
#endregion
#region 保存报废详细信息和是否装过箱,装过箱子的不允许报废
badmd.ID = Guid.NewGuid().ToString();
badmd.StationID = stationId;
badmd.BadPosition = position;
badmd.BadReason = reason.Trim();
badmd.code = _scanPartNo;
badmd.Desc = textBox4.Text?.Trim();
//直供件条码
if (txtScanBarCode.Text.Trim().Contains("#"))
{
badmd.BarCode = txtScanBarCode.Text.Trim();
//tb_barCode找到记录
DataTable dt1 = barbll.SeachInfoByOne(txtScanBarCode.Text.Trim(), Program.tableName, 2);
if (dt1 != null && dt1.Rows.Count > 0)
{
badmd.OneBarCode = dt1.Rows[0]["OneBarCode"].ToString();
isbox = dt1.Rows[0]["BoxNo"].ToString();
//扣减装箱表boxRecord中箱码对应的数量
//if (SubtrBoxCount(isbox) == false)
// return;
if (SaveBad(badmd,isbox) == false)
{
return;
}
}
else
{
MessageBox.Show("条码不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
//普通条码
if (txtScanBarCode.Text.Trim().Contains('.'))
{
badmd.BarCode = txtScanBarCode.Text.Trim();
//tb_barCode找到记录
DataTable dt = barbll.SeachInfoByOne(txtScanBarCode.Text.Trim(), Program.tableName, 2);
if (dt != null && dt.Rows.Count > 0)
{
badmd.OneBarCode = dt.Rows[0]["OneBarCode"].ToString();
isbox = dt.Rows[0]["BoxNo"].ToString();
if (SaveBad(badmd, isbox) == false)
{
return;
}
}
else
{
MessageBox.Show("条码不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
//20位注塑码
else
{
badmd.OneBarCode = txtScanBarCode.Text.Trim();
DataTable dt1 = barbll.SeachInfoByOne(txtScanBarCode.Text.Trim(), Program.tableName, 1);
if (dt1 != null && dt1.Rows.Count > 0)
{
badmd.BarCode = dt1.Rows[0]["BarCode"].ToString();
isbox = dt1.Rows[0]["BoxNo"].ToString();
if (SaveBad(badmd, isbox) == false)
{
return;
}
}
else
{
MessageBox.Show("条码不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
//badBLL.Add_Info(badmd);
#endregion
#region 更新BarCode表标志位
//barbll.UpdateIsBad(Program.tableName, badmd.OneBarCode, badmd.BarCode);
#endregion
GetBadCount();
}
bool SaveBad(BadInjectionModel badmd ,string boxCode)
{
if (!string.IsNullOrEmpty(boxCode))
{
DataTable boxTable = _injectionBoxBLL.SearchBox(boxCode);
if (boxTable.Rows.Count > 0)
{
if (boxTable.Rows[0]["IsPrint"].ToString() == "1")
{
MessageBox.Show("请产品已做装箱,不能做报废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return false;
}
else
{
bool exsitInWms = _wmsBll.IsReadBarCodeInWms(badmd.BarCode);
if(exsitInWms == true)
{
MessageBox.Show($"条码[{badmd.BarCode}]在WMS已处理,无法在MES进行报废操作.");
return false;
}
string msg = badBLL.SaveBad(badmd,boxCode, Program.tableName);
if (!string.IsNullOrEmpty(msg))
{
MessageBox.Show("报废操作失败,失败原因:" + msg);
return false;
}
else
{
MessageBox.Show(badmd.OneBarCode +"报废操作成功");
}
}
}
}
return true;
}
bool SaveBadByBatch(DataTable boxDetailTable, string boxCode)
{
if (!string.IsNullOrEmpty(boxCode))
{
badmd.Desc = textBox4.Text?.Trim();
string msg = badBLL.SaveBadByBatch(boxDetailTable, stationId, position, reason, boxCode, Program.tableName, textBox4.Text?.Trim());
if (!string.IsNullOrEmpty(msg))
{
MessageBox.Show($"整箱报废失败:" + msg);
return false;
}
}
return true;
}
/// <summary>
/// 按箱码报废
/// </summary>
private void FullBoxBadSave(DataTable boxDetailTable)
{
if (MessageBox.Show($"确认对箱码[{txtBoxCode.Text}]所含[{boxDetailTable.Rows.Count}]条数据做报废处理?", "", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
return;
string boxCode = boxDetailTable.Rows[0]["BoxNo"].ToString();
if (string.IsNullOrEmpty(boxCode))
return;
#region 扣减箱码数量
bool isRead = _wmsBll.IsReadBoxInWms(boxCode);
if (isRead == true)
{
MessageBox.Show($"箱码[{boxCode}]已报工,不能做报废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return;
}
else
{
SaveBadByBatch(boxDetailTable, boxCode);
}
#endregion
GetBadCount();
}
/// <summary>
/// 扣减箱码数量
/// </summary>
/// <param name="boxCode"></param>
/// <returns></returns>
bool SubtrBoxCount(string boxCode)
{
if (!string.IsNullOrEmpty(boxCode))
{
DataTable boxTable = _injectionBoxBLL.SearchBox(boxCode);
if (boxTable.Rows.Count > 0)
{
if (boxTable.Rows[0]["IsPrint"].ToString() == "1")
{
MessageBox.Show("请产品已做装箱,不能做报废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return false;
}
else
{
_injectionBoxBLL.UpdateBoxCount(boxCode, -1);
}
}
}
return true;
}
/// <summary>
/// 扣减箱码数量为0,同时撤回WMS报工数据, 如果wms已读取,返回false
/// </summary>
/// <param name="boxCode"></param>
/// <returns></returns>
bool ClearBoxCount(string boxCode)
{
if (!string.IsNullOrEmpty(boxCode))
{
bool isRead = _wmsBll.IsReadBoxInWms(boxCode);
if (isRead == true)
{
MessageBox.Show($"箱码[{boxCode}]已报工,不能做报废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
txtScanBarCode.Text = "";
txtScanBarCode.TabIndex = 0;
txtScanBarCode.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return false;
}
else
{
bool isDel = _wmsBll.DelRecordByBox(boxCode);
if(isDel)
{
_injectionBoxBLL.UpdateBoxCount(boxCode, 100, true);
}
else
{
MessageBox.Show($"整箱报废失败,可能箱码[{boxCode}]在操作时已被wms接收");
return false;
}
}
}
return true;
}
private static bool IsNumeric(string str)
{
System.Text.RegularExpressions.Regex reg1 = new System.Text.RegularExpressions.Regex(@"^[0-9]\d*$");
return reg1.IsMatch(str);
}
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
textBox2.Text = "1";
_boxDetailTable = null;
BarCodeScan(txtScanBarCode.Text.Trim());
}
}
private string _scanPartNo = string.Empty;
/// <summary>
/// 扫描标签质检
/// </summary>
/// <param name="scanBarCode"></param>
void BarCodeScan(string scanBarCode)
{
_isScanBarCode = true;
string code = "";
string[] barcode = new string[3];
int row = 0, col = 0;
string picture = "";
string LineID = "";
ProductBLL bll = new ProductBLL();
BarCodeBLL barbll = new BarCodeBLL();
if (scanBarCode.Contains('.') == false && scanBarCode.Contains('#') == false)
{
DataTable xdt = barbll.SeachInfoByOne(scanBarCode.Trim(), Program.tableName, 1);
if (xdt != null && xdt.Rows.Count > 0)
{
code = xdt.Rows[0]["BarCode"].ToString();
_scanPartNo = xdt.Rows[0]["PartNo"].ToString();
}
else
{
MessageBox.Show("条码有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
barcode = code.Split('.');
DataTable dt = bll.SearchInfoByPartNo(barcode[0]);
if (dt != null && dt.Rows.Count > 0)
{
textBox4.Text = dt.Rows[0]["ProductName"].ToString();
row = Convert.ToInt32(dt.Rows[0]["Rows"].ToString());
col = Convert.ToInt32(dt.Rows[0]["Cols"].ToString());
picture = dt.Rows[0]["PicturePath"].ToString();
}
}
else
{
DataTable xdt = barbll.SeachInfoByOne(scanBarCode.Trim(), Program.tableName, 2);
if (xdt != null && xdt.Rows.Count > 0)
{
code = xdt.Rows[0]["BarCode"].ToString();
_scanPartNo = xdt.Rows[0]["PartNo"].ToString();
}
else
{
MessageBox.Show("条码有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (scanBarCode.Contains('#') == false)
{
barcode = scanBarCode.Trim().Split('.');
DataTable dt = bll.SearchInfoByPartNo(barcode[0]);
if (dt != null && dt.Rows.Count > 0)
{
textBox4.Text = dt.Rows[0]["ProductName"].ToString();
row = Convert.ToInt32(dt.Rows[0]["Rows"].ToString());
col = Convert.ToInt32(dt.Rows[0]["Cols"].ToString());
picture = dt.Rows[0]["PicturePath"].ToString();
}
}
else
{
barcode = scanBarCode.Trim().Split('#');
DataTable dt = bll.SearchInfoByPartNo(barcode[0]);
if (dt != null && dt.Rows.Count > 0)
{
textBox4.Text = dt.Rows[0]["ProductName"].ToString();
row = Convert.ToInt32(dt.Rows[0]["Rows"].ToString());
col = Convert.ToInt32(dt.Rows[0]["Cols"].ToString());
picture = dt.Rows[0]["PicturePath"].ToString();
}
}
}
try
{
#region Load PictureBox
if (!string.IsNullOrEmpty(picture))
{
if (!File.Exists(System.IO.Directory.GetCurrentDirectory() + @"\" + picture))
{
//string strImageURL = ConfigurationManager.AppSettings["PicturePath"] + picture;
string strImageURL = "http://10.60.101.59:8001/PDF/" + picture;
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(); // 关闭流,释放图片资源
}
#endregion
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
#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
#region 缺陷原因
StationBLL sbll = new StationBLL();
DataTable sdt = sbll.SearchInfoByNo(Program.station);
if (sdt != null && sdt.Rows.Count > 0)
{
LineID = sdt.Rows[0]["LineID"].ToString();
}
int drow = 0, dcol = 6;
DefectBLL dbll = new DefectBLL();
DataTable dt3 = dbll.SearchInfo(LineID);
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, 20, FontStyle.Bold);
dLb[i].Size = new Size(130, 50);
dLb[i].Location = new Point(50 + i * (dLb[i].Size.Width + 25),
50 + 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);
}
}
}
}
#endregion
if (ConfigurationManager.AppSettings["IsLast"] == "1")
{
timer2.Enabled = true;
}
else if (ConfigurationManager.AppSettings["IsLast"] == "0")
{
timer2.Enabled = false;
label9.Visible = false;
}
}
private void label2_Click(object sender, EventArgs e)
{
this.Close();
if(QualityViewClosed != null)
{
QualityViewClosed(_boxDelList);
}
//Environment.Exit(0);
}
/// <summary>
/// 扫描箱码,整箱报废
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
try
{
InjectionBoxBLL bll=new InjectionBoxBLL();
BarCodeBLL pbll =new BarCodeBLL();
if (e.KeyCode == Keys.Enter)
{
string packageCode = txtBoxCode.Text.Trim();
if (string.IsNullOrEmpty(packageCode)) return;
DataTable packageTable = pbll.SearchBarCode(packageCode, Program.tableName, "100");
if(packageTable.Rows.Count == 0)
{
//MessageBox.Show($"扫描箱单[{packageCode}]在系统中不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtBoxCode.Focus();
return;
}
_boxDetailTable = packageTable;
DataRow dr = packageTable.Rows[0];
textBox2.Text = packageTable.Rows.Count.ToString();
BarCodeScan(dr["OneBarCode"].ToString());
//if (textBox1.Text.Trim() == "")
//{
// MessageBox.Show("请扫描或输入箱单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox1.Focus();
// return;
//}
//if (textBox1.Text.Contains('.')==false)
//{
// MessageBox.Show("箱单格式有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox1.Focus();
// return;
//}
//#region 判断箱单是否为小件,即看零件号是否需要打印单个条码
//string[] aa = textBox1.Text.Split('.');
//string partNo = aa[0].ToString().Trim();
//DataTable dt = pbll.SearchInfoByPartNo(partNo);
//if (dt != null && dt.Rows.Count > 0)
//{
// if (dt.Rows[0]["IsPrintOneTag"].ToString() == "1")
// {
// MessageBox.Show("该零件有单个条码,不能扫描箱单!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox1.Focus();
// return;
// }
//}
//else
//{
// MessageBox.Show("该箱单有误,请重新扫描或输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox1.Focus();
// return;
//}
//#endregion
//_isScanBarCode = false;
//DataTable dt1 = bll.SearchBox(textBox1.Text);
//if (dt1 != null && dt1.Rows.Count > 0)
//{
// textBox2.Text = dt1.Rows[0]["BoxCount"].ToString();
//}
//else
//{
// MessageBox.Show("该箱单不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox1.Focus();
// return;
//}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void timer2_Tick(object sender, EventArgs e)
{
GetClass();
}
private DateTime GetDateTime()
{
string sql = "";
DateTime time;
DataTable dt;
try
{
sql = @"select convert(char(23),getdate(),121) as time";
dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
time = DateTime.ParseExact(dt.Rows[0]["time"].ToString(), "yyyy-MM-dd HH:mm:ss.fff",
System.Globalization.CultureInfo.CurrentCulture);
}
else
{
time = DateTime.Now;
}
return time;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return DateTime.Now;
}
}
private void GetClass()
{
try
{
DateTime aa = GetDateTime();
if (GetDateTime().Hour >= 8 && GetDateTime().Hour < 20)
{
Program.Shift = "白班";
}
else
{
Program.Shift = "夜班";
}
comboBox1.Text = Program.Shift;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void rbtn1_CheckedChanged(object sender, EventArgs e)
{
if (rbtn1.Checked)
{
txtBoxCode.Enabled = true;
txtScanBarCode.Text = "";
txtBoxCode.Focus();
}
else
{
txtBoxCode.Enabled = false;
}
}
private void rbtn2_CheckedChanged(object sender, EventArgs e)
{
if (rbtn2.Checked)
{
txtScanBarCode.Enabled = true;
txtBoxCode.Text = "";
txtScanBarCode.Focus();
}
else
{
txtScanBarCode.Enabled = false;
}
}
private void GetBadCount()
{
try
{
BadInjectionBLL bll = new BadInjectionBLL();
string startTime = "", endTime = "";
if (comboBox1.Text == "白班")
{
startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00";
endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00";
}
else
{
if (DateTime.Now.Hour <= 7)
{
startTime = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 20:00:00";
endTime = DateTime.Now.ToString("yyyy-MM-dd") + " 08:00:00";
}
else
{
startTime = DateTime.Now.ToString("yyyy-MM-dd") + " 20:00:00";
endTime = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") + " 08:00:00";
}
}
textBox2.Text = bll.BadCount(startTime, endTime, stationId);
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
}
}
}
}