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

1081 lines
38 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 System.Windows.Forms.VisualStyles;
using grdes6Lib;
using gregn6Lib;
using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.BLL.Inspection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.TruckBox;
using MESClassLibrary.BLL.ZPPlan;
using MESClassLibrary.DAL;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using ContentAlignment = System.Drawing.ContentAlignment;
namespace InjectionPC
{
public partial class FrmQuality_new : Form
{
private static string position = "", reason = "";
int count = 0; //缺陷图选择个数
static int qty = 0;
public FrmQuality_new()
{
InitializeComponent();
this.Size = new Size(1280, 1024);
}
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;
textBox3.TabIndex = 0;
textBox3.Focus();
panel44.Visible = false;
GetClass();
GetPrintCount();
GetBadCount();
Thread t = new Thread(new ThreadStart(TimeGo));
t.Start();
Thread t3 = new Thread(new ThreadStart(TimeGo3));
t3.Start();
timer2.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal2"]);
timer2.Enabled = false;
#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
textBox3.Text = Program.strBarCode;
textBox3.SelectAll();
}
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 TimeGo3()
{
System.Timers.Timer timer = new System.Timers.Timer();
timer.Interval = 60000;
timer.Enabled = true;
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer3_Tick);
}
private void timer_Tick(object sender, EventArgs e)
{
label2.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Thread.Sleep(500);
}
private void timer3_Tick(object sender, EventArgs e)
{
GetClass();
GetPrintCount();
Thread.Sleep(500);
}
/// <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>
/// 保存缺陷
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
timer2.Enabled = false;
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;
}
BadInjectionBLL badBLL = new BadInjectionBLL();
BadInjectionModel badmd = new BadInjectionModel();
InjectionBoxBLL ibll=new InjectionBoxBLL();
BarCodeBLL barbll=new BarCodeBLL();
InspectionBLL bll = new InspectionBLL();
tb_Inspection_tx md = new tb_Inspection_tx();
if (string.IsNullOrWhiteSpace(textBox3.Text ))
{
MessageBox.Show("条码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
#region 大件报废
if (!string.IsNullOrWhiteSpace(textBox3.Text))
{
#region 判断是否已做过报废
DataTable baddt = badBLL.SearchByCode(textBox3.Text.Trim());
if (baddt != null && baddt.Rows.Count > 0)
{
MessageBox.Show("该产品已做过报废处理!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
reason = "";
textBox3.Text = "";
textBox3.TabIndex = 0;
textBox3.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
return;
}
#endregion
#region 保存报废详细信息和是否装过箱,装过箱子的不允许报废
badmd.ID = Guid.NewGuid().ToString();
if (textBox3.Text.Trim().Contains('.'))
{
badmd.BarCode = textBox3.Text.Trim();
DataTable dt = barbll.SeachInfoByOne(textBox3.Text.Trim(), Program.tableName, 2);
if (dt != null && dt.Rows.Count > 0)
{
badmd.OneBarCode = dt.Rows[0]["OneBarCode"].ToString();
}
else
{
MessageBox.Show("条码不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
else
{
badmd.OneBarCode = textBox3.Text.Trim();
}
badmd.StationID = "ab38fdad-28ba-4711-8e49-3669d1abaad8";
badmd.BadPosition = position;
badmd.BadReason = reason.Trim();
badBLL.Add_Info(badmd);
#endregion
#region 更新BarCode表标志位
barbll.UpdateIsBad(Program.tableName, badmd.OneBarCode, badmd.BarCode);
#endregion
}
#endregion
#region 插入质检总表
md.BarCode = badmd.OneBarCode;
md.IsOK = 0;
md.Station = 6;
bll.AddInfo(md);
#endregion
reason = "";
textBox3.Text = "";
textBox3.SelectAll();
textBox3.TabIndex = 0;
textBox3.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
position = "";
GetBadCount();
}
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 button2_Click(object sender, EventArgs e)
{
try
{
ZPRecordBLL bll = new ZPRecordBLL();
InspectionBLL ibll = new InspectionBLL();
#region
if (string.IsNullOrWhiteSpace(textBox3.Text))
{
MessageBox.Show("条码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox3.SelectAll();
textBox3.Focus();
return;
}
//DataTable dtx = bll.SearchInfo(textBox3.Text.Trim());
//if (dtx != null && dtx.Rows.Count > 0)
//{
// MessageBox.Show("该产品已打印总成标签!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
// textBox3.SelectAll();
// textBox3.Focus();
// return;
//}
#endregion
var list = ibll.SearchInfoByBarCode(textBox3.Text.Trim());
if (list.Count > 0)
{
foreach (var x in list)
{
if (x.IsOK == 0)
{
MessageBox.Show("该产品为不合格件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox3.SelectAll();
textBox3.Focus();
return;
}
}
}
timer2.Enabled = false;
Print();
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void textBox3_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string code = "";
string[] barcode=new string[3];
int row = 0, col = 0;
string picture = "";
string LineID = "";
ProductBLL bll = new ProductBLL();
BarCodeBLL barbll=new BarCodeBLL();
string aa = textBox3.Text.Trim();
if (textBox3.Text.Contains('.') == false && textBox3.Text.Contains('#') == false)
{
DataTable xdt=barbll.SeachInfoByOne(textBox3.Text.Trim(), Program.tableName, 1);
if (xdt != null && xdt.Rows.Count > 0)
{
code = xdt.Rows[0]["BarCode"].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(textBox3.Text.Trim(), Program.tableName, 2);
if (xdt != null && xdt.Rows.Count > 0)
{
code = xdt.Rows[0]["BarCode"].ToString();
}
else
{
MessageBox.Show("条码有误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (textBox3.Text.Contains('#') == false)
{
barcode = textBox3.Text.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 = textBox3.Text.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();
}
}
}
#region 判断质检是否合格
InspectionBLL ibll = new InspectionBLL();
var list = ibll.SearchInfoByBarCode(textBox3.Text.Trim());
if (list.Count > 0)
{
foreach (var x in list)
{
if (x.IsOK == 0)
{
MessageBox.Show("该产品前面工序不合格!", "提示", MessageBoxButtons.OK);
textBox3.SelectAll();
textBox3.Focus();
return;
}
}
}
#endregion
#region 是否打印过
ZPRecordBLL zpBll=new ZPRecordBLL();
tb_ZPRecord md = new tb_ZPRecord();
DataTable zpDt = zpBll.SearchInfobyone(textBox3.Text.Trim());
if (zpDt != null && zpDt.Rows.Count > 0)
{
DialogResult result = MessageBox.Show("已打印过总成,是否补打标签!", "提示", MessageBoxButtons.YesNo,
MessageBoxIcon.Information);
if (result == DialogResult.Yes)
{
#region 补打标签
string path = "", reportName = "", zcCode = "", batchNo = "", newCode = "";
path = Application.StartupPath + @"\zc.grf";
batchNo = DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Month.ToString().PadLeft(2, '0') +
DateTime.Now.Year;
DataTable headTable = new DataTable();
headTable.Columns.Add("barCode");
DataRow brow = headTable.NewRow();
brow["barCode"] = zpDt.Rows[0]["BarCode"];
reportName = ConfigurationManager.AppSettings["PrinterName"];
headTable.Rows.Add(brow);
ReportHelper rp = new ReportHelper(path, headTable, null,
(int)GRPaperOrientation.grpoDefault, 1, reportName);
rp.Report.Print(false);
#region 保存记录
md.OneBarCode = textBox3.Text.Trim();
md.IsOK = 1;
md.PrintType = 1;
md.BarCode = zpDt.Rows[0]["BarCode"].ToString();
zpBll.AddZcInfo(md);
#endregion
reason = "";
textBox3.Text = "";
textBox3.SelectAll();
textBox3.TabIndex = 0;
textBox3.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
position = "";
#endregion
return;
}
else
{
return;
}
}
#endregion
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);
DataTable sdt = sbll.SearchInfoByNo("ZP17");
if (sdt != null && sdt.Rows.Count > 0)
{
LineID = sdt.Rows[0]["LineID"].ToString();
}
sdt.Dispose();
int drow = 0, dcol = 4;
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(170, 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")
{
button2.Enabled = true;
//timer2.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["InterVal2"]);
timer2.Enabled = true;
}
}
}
private void label2_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void timer2_Tick(object sender, EventArgs e)
{
try
{
Print();
timer2.Enabled = false;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
}
}
private void Print()
{
string path = "", reportName = "", zcCode = "", batchNo = "", newCode = "";
ZPRecordBLL bll = new ZPRecordBLL();
tb_ZPRecord md = new tb_ZPRecord();
path = Application.StartupPath + @"\zc.grf";
batchNo = DateTime.Now.Day.ToString().PadLeft(2, '0') + DateTime.Now.Month.ToString().PadLeft(2, '0') +
DateTime.Now.Year;
DataTable headTable = new DataTable();
headTable.Columns.Add("barCode");
DataRow row = headTable.NewRow();
//row["barCode"] = textBox1.Text.Trim() + "/" + textBox2.Text.Trim() + "/" + textBox3.Text.Trim();
DataTable dt = bll.SearchZcInfo("2146103301" + batchNo);
if (dt != null && dt.Rows.Count > 0)
{
zcCode = dt.Rows[0]["BarCode"].ToString();
}
if (string.IsNullOrWhiteSpace(zcCode))
{
newCode = "2146103301" + batchNo + "0001";
}
else
{
newCode = "2146103301" + batchNo + (Convert.ToInt32(zcCode.Substring(zcCode.Length - 4, 4)) + 1)
.ToString().PadLeft(4, '0');
}
row["barCode"] = newCode;
reportName = ConfigurationManager.AppSettings["PrinterName"];
headTable.Rows.Add(row);
ReportHelper rp = new ReportHelper(path, headTable, null,
(int)GRPaperOrientation.grpoDefault, 1, reportName);
rp.Report.Print(false);
#region 保存记录
md.OneBarCode = textBox3.Text.Trim();
md.IsOK = 1;
md.PrintType = 0;
md.BarCode = newCode;
bll.AddZcInfo(md);
#endregion
GetPrintCount();
reason = "";
textBox3.Text = "";
textBox3.SelectAll();
textBox3.TabIndex = 0;
textBox3.Focus();
textBox4.Text = "";
pictureBox2.Image = null;
pictureBox2.Controls.Clear();
panel2.Controls.Clear();
position = "";
qty++;
if (qty>=10)
{
PrintBox(10);
}
}
private void PrintBox(int x)
{
try
{
string path = "", reportName = "",barCode="",tmp="", batchNo="";
string oldNo = "";
BoxBLL bll=new BoxBLL();
tb_Box_tx md=new tb_Box_tx();
path = Application.StartupPath + @"\Box.grf";
batchNo = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + Program.ProductDate.Substring(8, 2);
tmp = "A2146103301." + batchNo;
oldNo = bll.OldNo(tmp);
if (string.IsNullOrEmpty(oldNo))
{
barCode = tmp + ".000001";
}
else
{
barCode= oldNo.Substring(0,oldNo.Length-6)+ (int.Parse(oldNo.Substring(oldNo.Length - 6, 6))+1).ToString().PadLeft(6,'0');
}
DataTable headTable = new DataTable();
headTable.Columns.Add("BarCode");
headTable.Columns.Add("BatchNo");
headTable.Columns.Add("Qty");
DataRow row = headTable.NewRow();
row["BarCode"] = barCode;
row["BatchNo"] = batchNo;
row["Qty"] = x;
reportName = ConfigurationManager.AppSettings["PrinterName1"];
headTable.Rows.Add(row);
ReportHelper rp = new ReportHelper(path, headTable, null,
(int)GRPaperOrientation.grpoDefault, 1, reportName);
rp.Report.Print(false);
md.BoxNo = barCode;
bll.AddInfo(md);
qty = 0;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
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 = "白班";
Program.ProductDate = aa.ToString("yyyy-MM-dd");
}
else
{
Program.Shift = "夜班";
if (GetDateTime().Hour >= 0 && GetDateTime().Hour < 8)
{
Program.ProductDate = aa.AddDays(-1).ToString("yyyy-MM-dd");
}
else if (GetDateTime().Hour >= 20 && GetDateTime().Hour <= 23)
{
Program.ProductDate = aa.ToString("yyyy-MM-dd");
}
}
comboBox1.Text = Program.Shift;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void GetPrintCount()
{
ZPRecordBLL bll=new ZPRecordBLL();
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";
}
}
label9.Text = bll.GetPrintCount(startTime, endTime);
}
private void button3_Click(object sender, EventArgs e)
{
panel44.Visible = true;
textBox1.Focus();
}
private void button5_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(textBox1.Text))
{
MessageBox.Show("请输入数量!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Focus() ;
return;
}
if (!IsNumeric(textBox1.Text))
{
MessageBox.Show("数量必须为整数!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.SelectAll();
textBox1.Focus();
return;
}
else
{
if (int.Parse(textBox1.Text)>10)
{
MessageBox.Show("数量应小于10!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.SelectAll();
textBox1.Focus();
return;
}
}
PrintBox(int.Parse(textBox1.Text));
panel44.Visible = false;
textBox1.Text="";
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
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";
}
}
label13.Text = bll.BadCount(startTime, endTime, "ab38fdad-28ba-4711-8e49-3669d1abaad8");
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void button4_Click(object sender, EventArgs e)
{
panel44.Visible = false;
textBox1.Text = "";
}
}
}