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.
311 lines
10 KiB
311 lines
10 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
|
|
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;
|
|
using System.Windows.Forms;
|
|
using MESClassLibrary.BLL.Log;
|
|
using grproLib;
|
|
using InjectionPC;
|
|
using MESClassLibrary.BLL.Injection;
|
|
|
|
namespace PunchingMistake
|
|
{
|
|
public partial class FrmAssemble : Form
|
|
{
|
|
private GridppReport Report = new GridppReport();
|
|
private string oneBarCode = "", _stationNo = "", stationId = "";
|
|
private UniqueBll _uniqueBll = new UniqueBll();
|
|
public FrmAssemble()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FrmAssemble_Load(object sender, EventArgs e)
|
|
{
|
|
_stationNo = ConfigurationManager.AppSettings["Station"];
|
|
//stationId = ProScreenFunc.GetStationId(stationNo);
|
|
lbStation.Text = Function2.GetStation(_stationNo);
|
|
Control.CheckForIllegalCrossThreadCalls = false;
|
|
Thread t = new Thread(new ThreadStart(TimeGo));
|
|
t.Start();
|
|
LoadScreen();
|
|
}
|
|
public void LoadScreen()
|
|
{
|
|
DataTable dt = Function2.GetProScreen(_stationNo);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
SetPage(dt);
|
|
}
|
|
|
|
}
|
|
public void SetPage(DataTable dt)
|
|
{
|
|
ClearPage();
|
|
if (dt.Rows.Count > 0)
|
|
{
|
|
this.Tag = dt.Rows[0]["ID"].ToString();
|
|
txtBarCode.Tag = dt.Rows[0]["PartNo1"].ToString();
|
|
txtBarCode.Text = "";
|
|
lbPlan.Text = dt.Rows[0]["OrderNo"].ToString();
|
|
lbPart.Text = dt.Rows[0]["PartNo1"].ToString();
|
|
lbPartDesc.Text = dt.Rows[0]["Des"].ToString();
|
|
lbPlanQty.Text = dt.Rows[0]["OrderCount"].ToString();
|
|
lbCompleteQty.Text = dt.Rows[0]["OKCount"].ToString();
|
|
lbBadQty.Text = dt.Rows[0]["BadCount"].ToString();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
void ClearPage()
|
|
{
|
|
lbStation.Text = "";
|
|
lbPlan.Text = "";
|
|
lbPart.Text = "";
|
|
lbPartDesc.Text = "";
|
|
}
|
|
|
|
private void btnPlanUp_Click(object sender, EventArgs e)
|
|
{
|
|
LoadPlanScreen(this.Tag?.ToString(), "上一计划");
|
|
txtBarCode.Select();
|
|
txtBarCode.Focus();
|
|
}
|
|
|
|
private void btnPlanDown_Click(object sender, EventArgs e)
|
|
{
|
|
LoadPlanScreen(this.Tag?.ToString(), "下一计划");
|
|
txtBarCode.Select();
|
|
txtBarCode.Focus();
|
|
}
|
|
public void LoadPlanScreen(string id, string plan)
|
|
{
|
|
|
|
DataTable dt = Function2.GetProScreenPlan(id, _stationNo, plan);
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
{
|
|
SetPage(dt);
|
|
}
|
|
else
|
|
{
|
|
if (plan == "下一计划")
|
|
{
|
|
MessageBox.Show("无下一计划");
|
|
txtBarCode.SelectAll();
|
|
txtBarCode.Focus();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("无上一计划");
|
|
txtBarCode.SelectAll();
|
|
txtBarCode.Focus();
|
|
}
|
|
}
|
|
txtBarCode.SelectAll();
|
|
txtBarCode.Focus();
|
|
}
|
|
|
|
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
WriteHint("", true);
|
|
if (string.IsNullOrEmpty(this.Tag?.ToString()))
|
|
{
|
|
throw new Exception("当前没有生产计划.");
|
|
}
|
|
ScanBarCode();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
WriteHint(ex.Message,false);
|
|
}
|
|
}
|
|
private void ScanBarCode()
|
|
{
|
|
string barCode = txtBarCode.Text?.Trim();
|
|
if (string.IsNullOrEmpty(barCode))
|
|
{
|
|
throw new Exception("扫描条码为空!");
|
|
}
|
|
if (barCode.Length != 20)
|
|
{
|
|
throw new Exception("扫描条码格式不正确,请扫描20位塑件条码!");
|
|
}
|
|
|
|
DataTable stockInTable = Function2.SearchStockIn(barCode);
|
|
if (stockInTable.Rows.Count == 0)
|
|
{
|
|
throw new Exception("扫描半成品码没有喷涂完工记录,无法使用.");
|
|
}
|
|
DataTable punchTable = Function2.SearchPunchCodeRecord(barCode);
|
|
if (punchTable.Rows.Count > 0)
|
|
{
|
|
if (punchTable.Rows[0]["Flag"].ToString() == "0" || punchTable.Rows[0]["Flag"].ToString() == "1")
|
|
{
|
|
throw new Exception("扫描半成品码已存在装配记录,无法使用.");
|
|
}
|
|
}
|
|
DataTable productTable = Function2.GetProductInfo(barCode.Substring(0, 10));
|
|
if (productTable.Rows.Count == 0)
|
|
{
|
|
throw new Exception($"扫描半成品码的存货代码[{barCode.Substring(0, 10)}]在零件表找不对对应零件号,请检查系统维护.");
|
|
}
|
|
string partNo2 = productTable.Rows[0]["PartNo"].ToString();
|
|
string partNo1 = Function2.GetAssemblePartCode(partNo2, _stationNo);
|
|
|
|
if (lbPart.Text?.ToLower() != partNo1?.ToLower())
|
|
{
|
|
throw new Exception($"扫描半成品码在BOM中对应的总成零件号[{partNo1}]与当前计划的零件号[{lbPart.Text}]不匹配.");
|
|
|
|
}
|
|
DataTable bomTable = Function2.GetBomTable(partNo1, _stationNo);
|
|
|
|
List<DataRow> list = bomTable.AsEnumerable().Where(p => p.Field<int>("IsChecked") == 1).ToList();
|
|
if (list.Count > 0)
|
|
{
|
|
//需要校验关键件
|
|
|
|
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
SaveScanRecord(barCode,partNo1, partNo2);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void SaveScanRecord(string barcode,string partNo1,string partNo2)
|
|
{
|
|
//保存装配记录
|
|
//更新计划完成数量
|
|
//
|
|
string serailNo = "0001";
|
|
string assembleBarCode = _uniqueBll.GetPunchSerialNo(partNo1, 4,ref serailNo);
|
|
int res = Function2.SavePartAndProduct_New(barcode, partNo2, partNo1,
|
|
lbPlan.Text.Trim(), lbClass.Text, this.Tag?.ToString(), assembleBarCode,
|
|
ScanAll.barCode1, ScanAll.barCode2, ScanAll.barCode3,
|
|
ScanAll.barCode4, ScanAll.barCode5, ScanAll.barCode6, stationId, ConfigurationManager.AppSettings["StationDescription"]);
|
|
|
|
Function2.SaveZcCode(barcode, partNo1);
|
|
Function2.AddCompleteCount(this.Tag?.ToString());
|
|
|
|
PrintAssembleBarCode(assembleBarCode, partNo1, lbPartDesc.Text, serailNo);
|
|
|
|
if (Function2.CheckPlanCompleted(this.Tag.ToString().Trim()))
|
|
{
|
|
LoadScreen();
|
|
}
|
|
else
|
|
{
|
|
lbCompleteQty.Text = (Tools.NumericParse.StringToInt(lbCompleteQty.Text.Trim()) + 1).ToString();
|
|
}
|
|
|
|
}
|
|
private void PrintAssembleBarCode(string BarCode, string PartNo, string PartName, string SerialNo )
|
|
{
|
|
string filename = GetPrintFileName();
|
|
DataTable headTable = new DataTable();
|
|
headTable.Columns.Add("BarCode");
|
|
headTable.Columns.Add("PartName");
|
|
headTable.Columns.Add("PartNo");
|
|
headTable.Columns.Add("BatchNo");
|
|
headTable.Columns.Add("SerialNo");
|
|
headTable.Columns.Add("Line");
|
|
DataRow row = headTable.NewRow();
|
|
|
|
row["BarCode"] = BarCode;
|
|
row["PartNo"] = PartNo;
|
|
row["PartName"] = PartName;
|
|
row["BatchNo"] = DateTime.Now.ToString("yyMMdd");
|
|
row["SerialNo"] = SerialNo;
|
|
row["Line"] = ConfigurationManager.AppSettings["Line"];
|
|
string printBoxName = "Printer1";
|
|
|
|
string reportName = ConfigurationManager.AppSettings[printBoxName].ToString();
|
|
headTable.Rows.Add(row);
|
|
|
|
ReportHelper rp = new ReportHelper(filename, headTable, null, (int)GRPaperOrientation.grpoLandscape, 1, reportName);
|
|
|
|
rp.Report.Print(false);
|
|
}
|
|
string GetPrintFileName()
|
|
{
|
|
if(Program.station == "F01")
|
|
{
|
|
return System.AppDomain.CurrentDomain.BaseDirectory + "/Report/总成条码MI.grf";
|
|
}
|
|
|
|
return System.AppDomain.CurrentDomain.BaseDirectory + "/Report/总成条码MI.grf";
|
|
}
|
|
|
|
string GetSerialNo(string partNo1)
|
|
{
|
|
DateTime time = DateTime.Now;
|
|
string tmp = Function2.SerialNo(partNo1, time.ToString("yyMMdd"));
|
|
string sn = "";
|
|
if (tmp == "")
|
|
{
|
|
sn = GetFullBarCode(partNo1, "0001");
|
|
}
|
|
else
|
|
{
|
|
sn = tmp.Substring(0, tmp.Length - 4) +
|
|
(int.Parse(tmp.Substring(tmp.Length - 4, 4)) + 1).ToString()
|
|
.PadLeft(4, '0');
|
|
}
|
|
return sn;
|
|
}
|
|
string GetFullBarCode(string partNo,string serialNo)
|
|
{
|
|
DateTime time = DateTime.Now;
|
|
return partNo + "." + time.ToString("yyMMdd") + ";" + serialNo + ";S104;;.1;" + time.ToString("yyyy/MM/dd") + ";";
|
|
}
|
|
|
|
void WriteHint(string txt,bool isOk)
|
|
{
|
|
lbHint.ForeColor = Color.LimeGreen;
|
|
if (!isOk)
|
|
{
|
|
lbHint.ForeColor = Color.Red;
|
|
}
|
|
lbHint.Text = txt;
|
|
}
|
|
private void TimeGo()
|
|
{
|
|
System.Timers.Timer timer = new System.Timers.Timer();
|
|
timer.Interval = 10;
|
|
timer.Enabled = true;
|
|
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
|
|
}
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
lbPartDesc.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
Thread.Sleep(500);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|