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

744 lines
27 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using gregn6Lib;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.BLL.Mistake243;
using MESClassLibrary.Model;
namespace PurchingMistakeNew
{
public partial class FrmCheck243 : Form
{
public FrmCheck243()
{
InitializeComponent();
}
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
Mistake243BLL mbll = new Mistake243BLL();
RecordBLL rbll = new RecordBLL();
BoxModel md = new BoxModel();
Box243BLL bll = new Box243BLL();
DataTable dt1 = null;
GridppReport report = new GridppReport();
string part = "", box = "", batch = "", newBox = "", newBatch = "", partName = "";
int maxCount = 0, currentCount = 0;
try
{
if (e.KeyCode == Keys.Enter)
{
if (textBox2.Text.Trim() == "")
{
MessageBox.Show("请扫描总成码!", "提示", MessageBoxButtons.OK);
textBox2.Focus();
return;
}
DataTable recorddt = rbll.SearchByPartNo2(textBox2.Text.Trim());
if (recorddt != null && recorddt.Rows.Count > 0)
{
if (recorddt.Rows[0]["BoxNo"].ToString() != "")
{
MessageBox.Show("此总成已入箱!", "提示", MessageBoxButtons.OK);
textBox2.Focus();
return;
}
if (!string.IsNullOrEmpty(recorddt.Rows[0]["Flag"].ToString()))
{
if (Convert.ToInt32(recorddt.Rows[0]["Flag"].ToString()) == 2)
{
MessageBox.Show("此总成已报废!", "提示", MessageBoxButtons.OK);
textBox2.Focus();
return;
}
}
}
else
{
MessageBox.Show("此总成不存在!", "提示", MessageBoxButtons.OK);
textBox2.Focus();
return;
}
#region 颜色
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2438808501")
{
userControl11.BackColor = System.Drawing.Color.Cyan;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2478850222")
{
userControl12.BackColor = System.Drawing.Color.Cyan;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2438808601")
{
userControl13.BackColor = System.Drawing.Color.Cyan;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2478850322")
{
userControl14.BackColor = System.Drawing.Color.Cyan;
}
#endregion
#region 判断是否需要打印箱单
part = textBox2.Text.Substring(0, textBox2.Text.IndexOf("."));
dt1 = mbll.SearchPartName(part);
if (dt1 != null && dt1.Rows.Count > 0)
{
maxCount = Convert.ToInt32(dt1.Rows[0]["PackCount"].ToString());
partName = dt1.Rows[0]["PartName2"].ToString();
}
else
{
maxCount = 0;
}
DataTable boxdt = rbll.SearchBoxByPart(part);
if (boxdt != null && boxdt.Rows.Count > 0)
{
box = boxdt.Rows[0]["BoxNo"].ToString();
}
else
{
box = "";
}
batch = DateTime.Now.ToString("yyyy-MM-dd").Substring(2, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(5, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(8, 2);
if (box != "")
{
#region 判断装箱单是否已满
DataTable indt = rbll.SearchCountByBox(box);
if (indt != null && indt.Rows.Count > 0)
{
currentCount = Convert.ToInt32(indt.Rows[0]["sum"].ToString());
}
else
{
currentCount = 0;
}
if (currentCount == 0 || currentCount >= maxCount)
{
#region 生成装箱单
if (box.Substring(12, 6) == batch)
{
newBox = box.Substring(0, box.Length - 6) + (Convert.ToInt32(box.Substring(box.Length - 6, 6)) + 1).ToString().PadLeft(6, '0');
newBatch = batch;
}
else
{
newBox = textBox2.Text.Substring(0, 11) + "." + batch + "." + "000001";
newBatch = box.Substring(12, 6);
}
#endregion
#region 保存装箱单并打印
md.ID = Guid.NewGuid().ToString();
md.BoxNo = newBox;
md.PartNo = part;
md.PartName = partName;
md.BatchNo = newBatch;
md.Validity = "3个月";
md.ValidityDate = "从" + DateTime.Now.ToString("yyyy-MM-dd") + "到" +
DateTime.Now.AddMonths(3).ToString("yyyy-MM-dd");
bll.AddInfo(md);
#region 打印装箱单
if (part == "A2438808501")
{
report.LoadFromFile(@"D:\X243 前部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2478850222")
{
report.LoadFromFile(@"D:\X243 后部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2438808601")
{
report.LoadFromFile(@"D:\X243 前部右侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
if (part == "A2478850322")
{
report.LoadFromFile(@"D:\X243 后部右侧后轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
#endregion
report.Register("");
report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString();
report.Print(false);
bll.UpdateInfo(md);
#endregion
}
#endregion
}
else
{
DataTable dt = bll.searchBox(part);
if (dt != null && dt.Rows.Count > 0)
{
}
else
{
newBox = textBox2.Text.Substring(0, 11) + "." + batch + "." + "000001";
newBatch = batch;
#region 保存装箱单并打印
md.ID = Guid.NewGuid().ToString();
md.BoxNo = newBox;
md.PartNo = part;
md.PartName = partName;
md.BatchNo = newBatch;
md.Flag = 0;
md.Validity = "3个月";
md.ValidityDate = "从" + DateTime.Now.ToString("yyyy-MM-dd") + "到" +
DateTime.Now.AddMonths(3).ToString("yyyy-MM-dd");
bll.AddInfo(md);
#region 打印装箱单
if (part == "A2438808501")
{
report.LoadFromFile(@"D:\X243 前部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2478850222")
{
report.LoadFromFile(@"D:\X243 后部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2438808601")
{
report.LoadFromFile(@"D:\X243 前部右侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
if (part == "A2478850322")
{
report.LoadFromFile(@"D:\X243 后部右侧后轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
#endregion
report.Register("");
report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString();
report.Print(false);
bll.UpdateInfo(md);
#endregion
}
}
#endregion
textBox1.Enabled = true;
textBox1.Focus();
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
Mistake243BLL mbll = new Mistake243BLL();
RecordBLL rbll = new RecordBLL();
RecordModel md = new RecordModel();
Box243BLL boxBll = new Box243BLL();
int maxCount = 0, currentCount = 0;
bool flag;
try
{
if (e.KeyCode == Keys.Enter)
{
if (textBox1.Text.Trim() == "")
{
MessageBox.Show("请扫描箱单!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
#region 判断箱单是否存在
DataTable IsBoxdt = boxBll.SearchBoxIsExsit(textBox1.Text.Trim());
if (IsBoxdt != null && IsBoxdt.Rows.Count > 0)
{
}
else
{
MessageBox.Show("此箱单不存在!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
#endregion
#region 判断装箱单是否已满
DataTable dt1 = mbll.SearchPartName(textBox1.Text.Substring(0, textBox1.Text.IndexOf(".")));
if (dt1 != null && dt1.Rows.Count > 0)
{
maxCount = Convert.ToInt32(dt1.Rows[0]["PackCount"].ToString());
}
else
{
maxCount = 0;
}
DataTable dt2 = rbll.SearchCountByBox(textBox1.Text.Trim());
if (dt2 != null && dt2.Rows.Count > 0)
{
currentCount = Convert.ToInt32(dt2.Rows[0]["sum"].ToString());
}
else
{
currentCount = 0;
}
if (currentCount >= maxCount)
{
MessageBox.Show("此装箱单已满!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
#endregion
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) !=
textBox1.Text.Substring(0, textBox1.Text.IndexOf(".")))
{
MessageBox.Show("总成和箱子不匹配!", "提示", MessageBoxButtons.OK);
textBox1.Focus();
return;
}
else
{
#region 入箱
md.PartNo2 = textBox2.Text.Trim();
md.BoxNo = textBox1.Text.Trim();
md.Flag = 1;
flag = rbll.updateBoxInfo(md);
#endregion
if (flag == true)
{
#region 颜色
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2438808501")
{
userControl11.BackColor = System.Drawing.Color.Chartreuse;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2478850222")
{
userControl12.BackColor = System.Drawing.Color.Chartreuse;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2438808601")
{
userControl13.BackColor = System.Drawing.Color.Chartreuse;
}
if (textBox2.Text.Substring(0, textBox2.Text.IndexOf(".")) == "A2478850322")
{
userControl14.BackColor = System.Drawing.Color.Chartreuse;
}
#endregion
textBox1.Enabled = false;
textBox2.Focus();
textBox2.Text = "";
textBox1.Text = "";
InitUC();
}
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void InitUC()
{
Mistake243BLL mbll = new Mistake243BLL();
RecordBLL rbll = new RecordBLL();
int[] maxCount = new int[4];
int[] currentCount = new int[4];
string[] part = { "A2438808501", "A2478850222", "A2438808601", "A2478850322" };
string[] box = new string[4];
#region 查找产品的最大包装量、装箱单号
DataTable dt1 = null;
for (int i = 0; i < 4; i++)
{
dt1 = mbll.SearchPartName(part[i]);
if (dt1 != null && dt1.Rows.Count > 0)
{
maxCount[i] = Convert.ToInt32(dt1.Rows[0]["PackCount"].ToString());
}
else
{
maxCount[i] = 0;
}
DataTable boxdt = rbll.SearchBoxByPart(part[i]);
if (boxdt != null && boxdt.Rows.Count > 0)
{
box[i] = boxdt.Rows[0]["BoxNo"].ToString();
}
else
{
box[i] = "";
}
if (box[i] != "")
{
#region 判断装箱单是否已满
DataTable indt = rbll.SearchCountByBox(box[i]);
if (indt != null && indt.Rows.Count > 0)
{
currentCount[i] = Convert.ToInt32(indt.Rows[0]["sum"].ToString());
}
else
{
currentCount[i] = 0;
}
#endregion
}
}
#endregion
#region 前左、后左后
userControl11.Part = "A2438808501 X243 前部左侧轮眉总成";
userControl12.Part = "A2478850222 X243&X247 后部左侧后轮眉总成";
userControl11.Box = box[0];
userControl12.Box = box[1];
if (currentCount[0] == maxCount[0])
{
userControl11.strIn = "0" + "/" + maxCount[0].ToString();
}
else
{
userControl11.strIn = currentCount[0].ToString() + "/" + maxCount[0].ToString();
}
if (currentCount[1] == maxCount[1])
{
userControl12.strIn = "0" + "/" + maxCount[1].ToString();
}
else
{
userControl12.strIn = currentCount[1].ToString() + "/" + maxCount[1].ToString();
}
#endregion
#region 前右、后右后
userControl13.Part = "A2438808601 X243 前部右侧轮眉总成";
userControl13.Box = box[2];
userControl14.Part = "A2478850322 X243&X247 后部右侧后轮眉总成";
userControl14.Box = box[3];
if (currentCount[2] == maxCount[2])
{
userControl13.strIn = "0" + "/" + maxCount[2].ToString();
}
else
{
userControl13.strIn = currentCount[2].ToString() + "/" + maxCount[2].ToString();
}
if (currentCount[3] == maxCount[3])
{
userControl14.strIn = "0" + "/" + maxCount[3].ToString();
}
else
{
userControl14.strIn = currentCount[3].ToString() + "/" + maxCount[3].ToString();
}
#endregion
}
private void button1_Click(object sender, EventArgs e)
{
RecordBLL bll = new RecordBLL();
RecordModel md = new RecordModel();
bool flag;
try
{
DialogResult result = MessageBox.Show("确认报废?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
md.Flag = 2;
md.PartNo2 = textBox2.Text.Trim();
flag = bll.DelInfo(md);
if (flag == false)
{
MessageBox.Show("报废失败!", "提示", MessageBoxButtons.OK);
textBox2.Focus();
return;
}
else
{
MessageBox.Show("报废成功!", "提示", MessageBoxButtons.OK);
}
}
else
{
return;
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void button4_Click(object sender, EventArgs e)
{
panel1.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
Box243BLL bll = new Box243BLL();
BoxModel md = new BoxModel();
string part = "";
GridppReport report = new GridppReport();
try
{
if (textBox3.Text.Trim() == "")
{
MessageBox.Show("请输入箱单!", "提示", MessageBoxButtons.OK);
textBox3.Focus();
return;
}
DataTable dt = bll.SearchBoxIsExsit(textBox3.Text.Trim());
if (dt != null && dt.Rows.Count > 0)
{
#region 补打
md.ID = Guid.NewGuid().ToString();
md.BoxNo = dt.Rows[0]["BoxNo"].ToString();
md.PartNo = dt.Rows[0]["PartNo"].ToString();
part = md.PartNo;
md.PartName = dt.Rows[0]["PartName"].ToString();
md.BatchNo = dt.Rows[0]["BatchNo"].ToString();
md.Flag = 1;
md.Validity = dt.Rows[0]["Validity"].ToString();
md.ValidityDate = dt.Rows[0]["ValidityDate"].ToString();
bll.AddInfo(md);
#endregion
#region 打印装箱单
if (part == "A2438808501")
{
report.LoadFromFile(@"D:\X243 前部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2478850222")
{
report.LoadFromFile(@"D:\X243 后部左侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString();
}
if (part == "A2438808601")
{
report.LoadFromFile(@"D:\X243 前部右侧轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
if (part == "A2478850322")
{
report.LoadFromFile(@"D:\X243 后部右侧后轮眉装箱单.grf");
report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString();
}
#endregion
report.Register("");
report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString();
report.Print(false);
bll.UpdateInfo(md);
}
else
{
MessageBox.Show("箱单不存在!", "提示", MessageBoxButtons.OK);
textBox3.Focus();
return;
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void button3_Click(object sender, EventArgs e)
{
panel1.Visible = false;
textBox3.Text = "";
}
private void button5_Click(object sender, EventArgs e)
{
try
{
panel2.Visible = true;
this.listView1.Columns.Clear();
listView1.Clear();
this.listView1.Columns.Add("总成零件号", 300, HorizontalAlignment.Center);
this.listView1.Columns.Add("总成打印时间", 300, HorizontalAlignment.Center);
RecordBLL bll = new RecordBLL();
DataTable dt = null;
dt = bll.SearchState(3, 4, 5);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(dt.Rows[i]["PartNo2"].ToString());
lvi.SubItems.Add(dt.Rows[i]["CreateTime1"].ToString()); //后面添加的Item都为SubItems ,即为子项
listView1.Items.Add(lvi);
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void button7_Click(object sender, EventArgs e)
{
panel3.Visible = true;
textBox4.Focus();
}
private void button8_Click(object sender, EventArgs e)
{
panel3.Visible = false;
textBox2.Focus();
}
private void button6_Click(object sender, EventArgs e)
{
panel2.Visible = false;
}
private void button9_Click(object sender, EventArgs e)
{
try
{
panel3.Visible = true;
this.listView2.Columns.Clear();
this.listView2.Clear();
this.listView2.Columns.Add("总成零件号", 300, HorizontalAlignment.Center);
this.listView2.Columns.Add("总成打印时间", 300, HorizontalAlignment.Center);
string boxNo = textBox4.Text.Trim();
RecordBLL bll = new RecordBLL();
DataTable dt = bll.GetRecord(boxNo);
if (dt != null && dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem(dt.Rows[i]["PartNo2"].ToString());
lvi.SubItems.Add(dt.Rows[i]["CreateTime1"].ToString()); //后面添加的Item都为SubItems ,即为子项
listView2.Items.Add(lvi);
}
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
}
}
private void FrmCheck243_Load(object sender, EventArgs e)
{
textBox1.Enabled = false;
textBox2.Enabled = true;
textBox2.Focus();
textBox1.Text = "";
textBox2.Text = "";
panel1.Visible = false;
panel2.Visible = false;
panel3.Visible = false;
InitUC();
}
}
}