注塑喷涂
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.
 
 
 
 
 

353 lines
12 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using grproLib;
using MESClassLibrary.BLL.BasicInfo;
using MESClassLibrary.BLL.Painting;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
namespace PaintingPrintBarCode
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void intiType()
{
comboBox1.Items.Clear();
ProductBLL bll=new ProductBLL();
DataTable dt = bll.SearchInfoAll();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox1.Items.Add(dt.Rows[i]["StockNo"].ToString() + "-" + dt.Rows[i]["ProductName"].ToString());
}
dt.Dispose();
}
}
private void initColor()
{
comboBox2.Items.Clear();
ColorBLL bll = new ColorBLL();
DataTable dt = bll.SearchAll();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox2.Items.Add(dt.Rows[i]["Des"].ToString() + "," + dt.Rows[i]["ColorCode"].ToString() + "," + dt.Rows[i]["ColorNo"].ToString());
}
dt.Dispose();
}
}
private void initReason()
{
comboBox5.Items.Clear();
PaintReasonBLL bll = new PaintReasonBLL();
DataTable dt = bll.SearchInfo();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox5.Items.Add(dt.Rows[i]["PrintReason"].ToString());
}
dt.Dispose();
}
}
private void initPerson()
{
comboBox6.Items.Clear();
PaintPersonBLL bll = new PaintPersonBLL();
DataTable dt = bll.SearchInfo();
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
comboBox6.Items.Add(dt.Rows[i]["PrintPerson"].ToString());
}
dt.Dispose();
}
}
private void initList()
{
DataRow dr = null;
PaintBarCodeBLL bll=new PaintBarCodeBLL();
DataTable dt = bll.SearchAll(comboBox4.Text.Trim(), Program.ProductDate);
this.listView1.Columns.Clear();
this.listView1.Items.Clear();
this.listView1.Columns.Add("条码", 300, HorizontalAlignment.Center);
this.listView1.Columns.Add("配置", 400, HorizontalAlignment.Center);
this.listView1.Columns.Add("颜色", 300, HorizontalAlignment.Center);
this.listView1.Columns.Add("位置", 100, HorizontalAlignment.Center);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(dt.Rows[i]["OneBarCode"].ToString());
lvi.SubItems.Add(dt.Rows[i]["ProductName"].ToString()); //后面添加的Item都为SubItems ,即为子项
lvi.SubItems.Add(dt.Rows[i]["ColorDes"].ToString());
lvi.SubItems.Add(dt.Rows[i]["Side"].ToString());
this.listView1.Items.Add(lvi);
}
dt.Dispose();
}
}
private void Form1_Load(object sender, EventArgs e)
{
var serverUrl = "http://10.60.101.10:8013/";
var updateXmlFileName = "PaintingPrintBarCodeUpdate.xml";
var updater = new AutoUpdater();
if (updater.CheckUpdateLoad(serverUrl, updateXmlFileName))
{
Environment.Exit(0);
}
intiType();
initColor();
initReason();
initPerson();
comboBox3.Text = "A侧";
comboBox4.Text = "A班";
//Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd");
if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 8)
{
Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
}
else
{
Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd");
}
Program.StationID = ConfigurationManager.AppSettings["StationID"].ToString();
Program.stationNo = ConfigurationManager.AppSettings["StationNo"].ToString();
comboBox6.Text = Program.UserName;
initList();
}
private void comboBox1_TextChanged(object sender, EventArgs e)
{
//comboBox1.Items.Clear();
//ProductBLL bll = new ProductBLL();
//if (comboBox1.Text.Trim() == "")
//{
// DataTable dt1 = bll.SearchInfoAll();
// if (dt1 != null && dt1.Rows.Count > 0)
// {
// for (int i = 0; i < dt1.Rows.Count; i++)
// {
// comboBox1.Items.Add(dt1.Rows[i]["StockNo"].ToString() + "-" + dt1.Rows[i]["ProductName"].ToString());
// }
// }
// dt1.Dispose();
//}
//else
//{
// DataTable dt2 = bll.SearchInfoByType(comboBox1.Text.Trim());
// if (dt2 != null && dt2.Rows.Count > 0)
// {
// for (int i = 0; i < dt2.Rows.Count; i++)
// {
// comboBox1.Items.Add(dt2.Rows[i]["aa"].ToString());
// }
// }
// dt2.Dispose();
//}
}
private void btOK_Click(object sender, EventArgs e)
{
string productID = "", lastCode = "", newCode = "";
PaintBarCodeBLL pbll = new PaintBarCodeBLL();
ProductBLL bll = new ProductBLL();
#region 根据存货代码查找配置
DataTable dt = bll.SearchInfoByStock(comboBox1.Text.Substring(0, 10));
if (dt != null && dt.Rows.Count > 0)
{
productID = dt.Rows[0]["ProductID"].ToString();
dt.Dispose();
}
#endregion
if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 8)
{
Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
}
else
{
Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd");
}
if (string.IsNullOrEmpty(comboBox5.Text))
{
MessageBox.Show("请选择补打原因!");
return;
}
if (string.IsNullOrEmpty(comboBox6.Text))
{
MessageBox.Show("请选择补打人!");
return;
}
//if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour < 20)
//{
// Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd");
//}
//else
//{
// if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 8)
// {
// Program.ProductDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
// }
// else
// {
// Program.ProductDate = DateTime.Now.ToString("yyyy-MM-dd");
// }
//}
#region 生成条码,从9999倒序
//DataTable dt2 = pbll.SearchBarCode(comboBox4.Text.Trim(), Program.ProductDate, productID);
try
{
DataTable dt2 = pbll.SearchBarCode(Program.ProductDate, productID);
if (dt2 != null && dt2.Rows.Count > 0)
{
lastCode = dt2.Rows[0]["OneBarCode"].ToString();
newCode = lastCode.Substring(0, lastCode.Length - 4) + (Convert.ToInt32(lastCode.Substring(lastCode.Length - 4, 4)) - 1).ToString().PadLeft(4, '0');
}
else
{
string batch = Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) +
Program.ProductDate.Substring(8, 2);
newCode = comboBox1.Text.Substring(0, 10) + batch + "9999";
//newCode = comboBox1.Text.Substring(0, 10) + Program.ProductDate.Substring(2, 2) + Program.ProductDate.Substring(5, 2) + Program.ProductDate.Substring(8, 2) + "9999";
}
}
catch (Exception ex)
{
MessageBox.Show("连接数据库失败!","提示", MessageBoxButtons.OK);
return;
}
#endregion
#region 插入数据
PaintBarCodeModel md=new PaintBarCodeModel();
md.ID = Guid.NewGuid().ToString();
md.StationID = Program.StationID;
md.ProductID = productID;
md.OneBarCode = newCode;
md.BarCode = "";
md.StockNo = comboBox1.Text.Substring(0, 10);
md.ColorDes = comboBox2.Text.Trim();
md.workClass = comboBox4.Text.Trim();
md.Side = comboBox3.Text.Trim();
md.CreateTime=DateTime.Now;
md.ProductDate = Program.ProductDate;
md.PrintReason = comboBox5.Text.Trim();
md.PrintPerson = comboBox6.Text.Trim();
pbll.AddInfo(md);
#endregion
#region 打印条码
GridppReport report = new GridppReport();
report.Register("");
report.LoadFromFile(@"D:\Paint.grf");
//report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString();
//report.Initialize += new _IGridppReportEvents_InitializeEventHandler(ReportInitialize);
//report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecord);
//report.DesignPaperSize = 256;
//report.DesignPaperWidth = 5;
//report.DesignPaperLength = 4;
report.DesignPaperOrientation = GRPaperOrientation.grpoLandscape;
//report.PrintPreview(true);
report.Print(false);
#endregion
#region 更新打印时间
md.PrintTime = DateTime.Now;
pbll.UpdatePrintTime(md);
#endregion
#region 将条码标记成一次合格
InspectResultModel imd=new InspectResultModel();
InspectResultBLL ibll=new InspectResultBLL();
imd.ID = Guid.NewGuid().ToString();
imd.barcode = newCode;
imd.side = comboBox3.Text.Trim();
imd.stationNo = Program.stationNo;
imd.workClass = comboBox4.Text.Trim();
imd.inspectResult = "[合格]";
imd.productInfo = comboBox2.Text.Trim() + "," + comboBox1.Text.Substring(11, comboBox1.Text.Length - 11);
imd.productOption = "1";
imd.InspectTimes = "1";
imd.createTime=DateTime.Now;
ibll.AddInfo(imd);
#endregion
initList();
intiType();
initColor();
}
private void btCancel_Click(object sender, EventArgs e)
{
initList();
intiType();
initColor();
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
Environment.Exit(0);
}
}
}