using iTextSharp.text.pdf; using iTextSharp.text.pdf.parser; using iTextSharp.text.pdf.qrcode; using iWare_SCADA_BusinessLogical; using iWare_SCADA_BusinessLogical.BLL; using iWare_SCADA_BusinessLogical.Utils; using iWare_SCADA_Model; using iWare_SCADA_Model.TableModelSC; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using static System.Net.WebRequestMethods; using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window; using File = System.IO.File; namespace iWare_SCADA_DataCaptureV3 { public partial class FormMain : Form { #region 信息获取线程 Thread tskSetLableText;//各种lable动态显示 Thread tskSetGridSource;//各种lable动态显示 #endregion public FormMain() { InitializeComponent(); } private void btn_StartUpAllThread_Click(object sender, EventArgs e) { try { #region 数据采集项确定 var dataCaptureConfigslist = DataCaptureConfigManager.GetDataCaptureConfigs(); var columnList = DataCaptureConfigManager.GetDataCaptureColumnConfig(); //var keyvalue = dataCaptureConfigslist.GroupBy(o => o.WorkingProcedure).Select(g => new //{ // keyword = g.Key, // RecordIDs = g.Where(c =>c.WorkingProcedure.Equals(g.Key)).ToList() //}); foreach (var config in dataCaptureConfigslist) { switch (config.DataCapturePointCode) { } } #endregion try { } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "启动线程时----btn_StartUpAllThread_Click报错:", ex); } #region 设置显示UI tskSetLableText = new Thread(DataRead_Label); tskSetLableText.Start(); #endregion } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "启动线程时----btn_StartUpAllThread_Click all报错:", ex); } } private void FormMain_Load(object sender, EventArgs e) { try {//加载需要的数据 } catch (Exception ex) { } } private void LoadItemType() { List itemList = new List(); itemList.Add(new ListItem() { Value = "-1", Text = "请选择" }); itemList.Add(new ListItem() { Text = "PLC", Value = "1" }); itemList.Add(new ListItem() { Text = "数据网关", Value = "2" }); itemList.Add(new ListItem() { Text = "工控机", Value = "3" }); cbox_DataCaptureType.ValueMember = "Value"; cbox_DataCaptureType.DisplayMember = "Text"; cbox_DataCaptureType.DataSource = itemList; cbox_DataCaptureType.SelectedIndex = 0; List itemList2 = new List(); itemList2.Add(new ListItem() { Value = "-1", Text = "请选择" }); itemList2.Add(new ListItem() { Text = "西门子S7", Value = "1" }); itemList2.Add(new ListItem() { Text = "西门子300", Value = "2" }); cbox_DataCapturePLCType.ValueMember = "Value"; cbox_DataCapturePLCType.DisplayMember = "Text"; cbox_DataCapturePLCType.DataSource = itemList2; cbox_DataCapturePLCType.SelectedIndex = 0; } List sourcelist = new List(); /// /// 设置现场告警信息前端显示 /// private void GridRefresh() { //while (true) //{ try { Action action = () => { using (DbModel db = new DbModel()) { sourcelist = db.ThreadStatusMonitor.Where(o => o.IsDeleted == false).ToList(); dataGridView2.DataSource = sourcelist.OrderBy(o => o.Threadcode); dataGridView2.Refresh(); } //dataGridView2.DataSource = null; //dataGridView2.DataSource = SystemValue.MainList; }; Invoke(action); } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "方法GridRefresh出现异常:" + ex.Message, ex); //continue; } //Thread.Sleep(10000); //} } /// /// 设置现场告警信息前端显示 /// private void DataRead_Label() { while (true) { Thread.Sleep(1000); try { var showNowTime = "(" + DateTimeHelper.ConvertToStringForOnlyShowTime(DateTime.Now) + ")"; Action action = () => { //TimeBox.Text = TimeString; ResultBox.Text = hv_Resultstr; //DisplayImageHalconwindow(AcqImage, GrayImage); //DisplayImageHalconwindow(ThresholdImage,MeanImage); //设置堆垛机任务下发和任务确认线程消息 this.lbl_Alter_OP0501.Text = showNowTime + SystemValue.lbl_Alert_OP0501; this.lbl_Alter_OP0502.Text = showNowTime + SystemValue.lbl_Alert_OP0502; this.lbl_Alter_OP0503.Text = showNowTime + SystemValue.lbl_Alert_OP0503; this.lbl_Alter_OP0504.Text = showNowTime + SystemValue.lbl_Alert_OP0504; this.lbl_Alter_OP2001.Text = showNowTime + SystemValue._lbl_Alert_OP2001; this.lbl_Alter_OP2002.Text = showNowTime + SystemValue._lbl_Alert_OP2002; this.lbl_Alter_OP2003.Text = showNowTime + SystemValue._lbl_Alert_OP2003; this.lbl_Alter_OP2004.Text = showNowTime + SystemValue._lbl_Alert_OP2004; this.lbl_Alter_OP2005.Text = showNowTime + SystemValue._lbl_Alert_OP2005; this.lbl_Alter_OP2006.Text = showNowTime + SystemValue._lbl_Alert_OP2006; this.lbl_Alert_HMIOP104001.Text = showNowTime + SystemValue.lbl_Alert_HMIOP104001; this.lbl_Alert_HMIOP104002.Text = showNowTime + SystemValue.lbl_Alert_HMIOP104002; this.lbl_Alert_HMIOP2001.Text = showNowTime + SystemValue.lbl_Alert_HMIOP2001; this.lbl_Alert_HMIOP2002.Text = showNowTime + SystemValue.lbl_Alert_HMIOP2002; this.lbl_Alert_HMIOP303501.Text = showNowTime + SystemValue.lbl_Alert_HMIOP303501; this.lbl_Alert_HMIOP303502.Text = showNowTime + SystemValue.lbl_Alert_HMIOP303502; this.lbl_Alert_HMIOP5001.Text = showNowTime + SystemValue.lbl_Alert_HMIOP5001; this.lbl_Alert_HMIOP5002.Text = showNowTime + SystemValue.lbl_Alert_HMIOP5002; this.lbl_Alert_HMIOP6001.Text = showNowTime + SystemValue.lbl_Alert_HMIOP6001; this.lbl_Alert_HMIOP6002.Text = showNowTime + SystemValue.lbl_Alert_HMIOP6002; }; Invoke(action); } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "方法DataRead_Label出现异常:" + ex.Message, ex); continue; } } } /// /// 通用的checkbox改变事件 /// /// /// private void CommonCheckedChanged(object sender, EventArgs e) { // HMI SystemValue.isAllowRuning_HMIOP104001 = DoCommonCheckedChanged(ckHMIOP1040Reading); SystemValue.isAllowRuning_HMIOP104002 = DoCommonCheckedChanged(HMIOP1040Write); SystemValue.isAllowRuning_HMIOP2001 = DoCommonCheckedChanged(ckHMIOP20Reading); SystemValue.isAllowRuning_HMIOP2002 = DoCommonCheckedChanged(HMIOP20Write); SystemValue.isAllowRuning_HMIOP303501 = DoCommonCheckedChanged(ckHMIOP3035Reading); SystemValue.isAllowRuning_HMIOP303502 = DoCommonCheckedChanged(HMIOP3035Write); SystemValue.isAllowRuning_HMIOP5001 = DoCommonCheckedChanged(ckHMIOP50Reading); SystemValue.isAllowRuning_HMIOP5002 = DoCommonCheckedChanged(HMIOP50Write); SystemValue.isAllowRuning_HMIOP6001 = DoCommonCheckedChanged(ckHMIOP60Reading); SystemValue.isAllowRuning_HMIOP6002 = DoCommonCheckedChanged(HMIOP60Write); //OP05工序监控任务 SystemValue.isAllowRuning_OP0501 = DoCommonCheckedChanged(ckBOP0501); SystemValue.isAllowRuning_OP0502 = DoCommonCheckedChanged(ckBOP0502); SystemValue.isAllowRuning_OP0503 = DoCommonCheckedChanged(ckBOP0503); SystemValue.isAllowRuning_OP0504 = DoCommonCheckedChanged(ckBOP0504); SystemValue.isAllowRuning_OP2001 = DoCommonCheckedChanged(ckBOP2001); SystemValue.isAllowRuning_OP2002 = DoCommonCheckedChanged(ckBOP2002); SystemValue.isAllowRuning_OP2003 = DoCommonCheckedChanged(ckBOP2003); SystemValue.isAllowRuning_OP2004 = DoCommonCheckedChanged(ckBOP2004); } private bool DoCommonCheckedChanged(CheckBox cb) { return cb.Checked ? true : false; } private void button1_Click(object sender, EventArgs e) { try { string Station = "03"; string value_02 = ""; string path = ConfigHelper.GetConfigString("OP30QualityDataForStation");//打码机打码二维码路径 if (string.IsNullOrEmpty(path)) { path = @"Z:\"; } if (Station.Equals("03")) {//工位3 涨断力矩 path = path + "kistler_crack"; } else if (Station.Equals("04")) {//工位4 预拧紧力矩 path = path + "Bosch_Rexroth"; } else if (Station.Equals("05")) {//工位5 拧紧力矩 path = path + "Bosch_Rexroth"; } else if (Station.Equals("06")) {//工位6 衬套压装力矩 path = path + "kistler_bush"; } //扫描共享目录并将新的文件扫描返回 一般节拍在15秒左右(可以确认一下) //扫描修改时间在上次扫描时间之前10秒到当前时间的之间的文件 var startTime = CommonManager.Instance.CheackPath(Environment.CurrentDirectory + $"\\LastModifyTime\\OP30Station{Station}-LastScapTime.txt", 6, -10); var endTime = DateTimeHelper.GetDateTime(); var newFiles = FileHelper.DetectNewFilesCSV(textBox10.Text, 100000000, Convert.ToDateTime(startTime), endTime); var list = newFiles.GetEnumerator(); foreach (System.IO.FileInfo file in newFiles) { } var a = ReadPdfConntent(textBox10.Text, textBox12.Text); //var ccSystem = DataCaptureColumnDictManager.GetEquipmentBaseInfo(); //if (ccSystem == null) //{ // MessageBox.Show("请联系管理员维护系统调度相关的数据!"); // return; //}; //WorkPieceInfoManager.test(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button5_Click(object sender, EventArgs e) { try { var list = DataCaptureConfigManager.GetDataCaptureConfigs(); if (list == null) { MessageBox.Show("请联系管理员维护数据收集点相关的数据!"); return; }; dgv_DataCaptureConfig.DataSource = list; } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void txt_PLCPort_KeyPress(object sender, KeyPressEventArgs e) { if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8) { e.Handled = true; } ///*只能数字键、退格键、负号、小数点*/ //if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && // (int)e.KeyChar != 45 && (int)e.KeyChar != 46) e.Handled = true; ///*输入为负号和小数点时,且只能输入一次(负号只能最前面输入,小数点不可最前面输入)*/ //if (e.KeyChar == 45 && (((TextBox)sender).SelectionStart != 0 || // ((TextBox)sender).Text.IndexOf("-") >= 0)) e.Handled = true; //if (e.KeyChar == 46 && (((TextBox)sender).SelectionStart == 0 || // ((TextBox)sender).Text.IndexOf(".") >= 0)) e.Handled = true; } private void txt_PLCIP_KeyPress(object sender, KeyPressEventArgs e) { if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46) { e.Handled = true; } } private void btn_Insert_Click(object sender, EventArgs e) { btn_Save.Tag = "create"; setControlsVisible(true); setControlsEmpty(); btn_Update.Enabled = false; btn_Delete.Enabled = false; btn_Insert.Enabled = false; } private void setControlsVisible(bool flag) { groupBox7.Visible = flag; } private void setControlsEmpty() { txt_EquipmentID.Text = ""; txt_EquipmentID.Focus(); cbox_WorkingProcedure.SelectedIndex = -1; cbox_DataCaptureColumnType.SelectedIndex = -1; cbox_DataCapturePLCType.SelectedIndex = 0; cbox_DataCaptureType.SelectedIndex = 0; } private void btn_Cancel_Click(object sender, EventArgs e) { setControlsVisible(false); btn_Update.Enabled = true; btn_Delete.Enabled = true; btn_Insert.Enabled = true; } private void btn_Update_Click(object sender, EventArgs e) { try { if (dgv_DataCaptureConfig.CurrentRow == null || dgv_DataCaptureConfig.CurrentRow.Index < 0) { MessageBox.Show("请选择一条需修改的数据!"); return; } btn_Save.Tag = "update"; setControlsVisible(true); btn_Update.Enabled = false; btn_Delete.Enabled = false; btn_Insert.Enabled = false; var model = dgv_DataCaptureConfig.SelectedRows[0].DataBoundItem as DataCaptureConfig; txt_ID.Text = model.Id.ToString(); txt_EquipmentID.Text = model.EquipmentID; cbox_WorkingProcedure.Text = model.WorkingProcedure; txt_DataCapturePointCode.Text = model.DataCapturePointCode; txt_DataCapturePointCname.Text = model.DataCapturePointCname; cbox_DataCaptureType.SelectedValue = model.DataCaptureType.ToString(); cbox_DataCapturePLCType.SelectedValue = model.DataCapturePLCType.ToString(); txt_PLCIP.Text = model.PLCIP; txt_PLCPort.Text = model.PLCPort.ToString(); txt_DbNumber.Text = model.DbNumber; txt_Offset.Text = model.Offset; cbox_DataCaptureColumnType.Text = model.DataCaptureColumnType; } catch (Exception ex) { MessageBox.Show($"修改收集点信息失败! {ex.Message}"); btn_Update.Enabled = true; btn_Delete.Enabled = true; btn_Insert.Enabled = true; } } private void btn_Delete_Click(object sender, EventArgs e) { try { if (dgv_DataCaptureConfig.CurrentRow.Index < 0) { MessageBox.Show("请选择一条收集点!"); return; } if (MessageBox.Show("确认删除此记录?", "删除确认", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } var model = dgv_DataCaptureConfig.SelectedRows[0].DataBoundItem as DataCaptureConfig; var num = DataCaptureConfigManager.DeleteDataCaptureConfig(model); if (num > 0) { MessageBox.Show($"删除成功{num}条"); } else { MessageBox.Show("删除异常,请刷新后重试"); } button5_Click(null, null); //if (service.DeleteAlertRule(ID)) //{ // ShowStatusMsg("删除成功"); // BindDataGrid(); // dgAlertRuleList.Rows[0].Selected = true; // dgAlertRuleList.CurrentCell = dgAlertRuleList.Rows[0].Cells[1]; // dgAlertRuleList_SelectionChanged(null, null); //} //else //{ // ShowErrMsg("删除失败"); //} } catch (Exception ex) { MessageBox.Show($"删除收集点信息异常!{ex.Message}"); } } private DataCaptureConfig GetFormDataCaptureConfigInfo() { ListItem DataCaptureTypeFlag = null; var itemType = ComboBoxHelper.GetComboxSelectValue(cbox_DataCaptureType, ref DataCaptureTypeFlag); ListItem DataCapturePLCTypeFlag = null; var itemType2 = ComboBoxHelper.GetComboxSelectValue(cbox_DataCapturePLCType, ref DataCapturePLCTypeFlag); DataCaptureConfig model = new DataCaptureConfig(); model.Id = string.IsNullOrEmpty(txt_ID.Text.Trim()) ? 0 : Convert.ToInt32(txt_ID.Text.Trim()); model.EquipmentID = txt_EquipmentID.Text.Trim(); model.WorkingProcedure = cbox_WorkingProcedure.Text.Trim(); model.DataCapturePointCode = txt_DataCapturePointCode.Text.Trim(); model.DataCapturePointCname = txt_DataCapturePointCname.Text.Trim(); model.DataCaptureType = Convert.ToInt32(DataCaptureTypeFlag.Value); model.DataCapturePLCType = Convert.ToInt32(DataCapturePLCTypeFlag.Value); model.PLCIP = txt_PLCIP.Text; model.PLCPort = Convert.ToInt32(txt_PLCPort.Text.Trim()); model.DbNumber = txt_DbNumber.Text; model.Offset = txt_Offset.Text; model.DataCaptureColumnType = cbox_DataCaptureColumnType.Text; return model; } private void btn_Save_Click(object sender, EventArgs e) { try { #region 校验格式 if (cbox_WorkingProcedure.SelectedIndex < 0) { MessageBox.Show($"请选择工序"); return; } if (cbox_DataCapturePLCType.SelectedIndex < 0) { MessageBox.Show($"输入PLC型号异常,请选中PLC型号"); return; } if (string.IsNullOrEmpty(txt_PLCIP.Text.Trim())) { MessageBox.Show($"PLC IP不能为空"); return; } if (string.IsNullOrEmpty(txt_PLCPort.Text.Trim())) { MessageBox.Show($"PLC端口不能为空"); return; } if (string.IsNullOrEmpty(txt_DataCapturePointCode.Text.Trim())) { MessageBox.Show($"收集点代码不能为空"); return; } if (string.IsNullOrEmpty(txt_DbNumber.Text.Trim())) { MessageBox.Show($"节点DB块地址不能为空"); return; } if (string.IsNullOrEmpty(txt_Offset.Text.Trim())) { MessageBox.Show($"节点偏移量不能为空"); return; } if (cbox_DataCaptureColumnType.SelectedIndex < 0) { MessageBox.Show($"请选择节点数据类型"); return; } if (cbox_DataCaptureType.SelectedIndex < 1) { MessageBox.Show($"请选择收集方式"); return; } #endregion var data = GetFormDataCaptureConfigInfo(); //data.ID = Convert.ToInt32(dgv_DataCaptureConfig.CurrentRow.Cells["ID"].Value); if (btn_Save.Tag.Equals("update")) {//修改 string message = ""; DataCaptureConfigManager.UpdateDataCaptureConfig(data, out message); if (message.Length == 0) { setControlsVisible(false); btn_Update.Enabled = true; btn_Delete.Enabled = true; btn_Insert.Enabled = true; MessageBox.Show("修改成功!"); button5_Click(null, null); } else { MessageBox.Show($"修改失败!{message}"); } } else if (btn_Save.Tag.Equals("create")) {//新增 DataCaptureConfigManager.InsertDataCaptureConfig(data); setControlsVisible(false); btn_Update.Enabled = true; btn_Delete.Enabled = true; btn_Insert.Enabled = true; MessageBox.Show("新增成功"); button5_Click(null, null); } } catch (Exception ex) { MessageBox.Show($"保存收集点信息异常!{ex.Message}"); } finally { } } private void button8_Click(object sender, EventArgs e) { } private void button10_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button9_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button11_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button12_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button15_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button13_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button14_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button16_Click(object sender, EventArgs e) { try { textBox10.Text = EnumberHelper.GetEnumName(int.Parse(textBox12.Text)).ToString(); var bb = EnumberHelper.GetEnumForString(textBox12.Text); var A = EnumberHelper.GetEnumName(1); WorkingProcedureForHMI t = default(WorkingProcedureForHMI); bool isRight = EnumberHelper.GetEnumObject("OP10", out t); //int workProcedure = 0; //workProcedure = (int)((WorkingProcedureForHMI)"OP10"); //using (DbModel db = new DbModel()) //{ // var qualityData = db.QualityDataInfo.Where(o => o.WorkPieceID == "DZ045L2309210100201A1A").FirstOrDefault(); //} // WorkPieceLog wplog = new WorkPieceLog(); //wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); //wplog.WorkingProcedure = "OP999"; //wplog.EquipmentID = "AA"; //wplog.Remarks = "CES"; //wplog.MonitoringPoint = "AAA"; //wplog.CreatedTime = DateTimeHelper.GetDateTime(); //wplog.CreatedUserName = "BAO"; //wplog.IsDeleted = false; //wplog.GetType().GetProperty("workpieceid").SetValue(wplog, "WorkPieceIDGONGJIANMA");//给动态字段赋值 } catch (Exception ex) { } } /// /// 解析pdf文件 /// /// /// /// public static List ReadPdfConntent(string filePath, string getPdfValue) { List lst = new List(); try { string pdffilename = filePath; PdfReader pdfreader = new PdfReader(pdffilename); int numberOfPages = pdfreader.NumberOfPages; //for (int i = 1; i <= numberOfPages; ++i) //{ // lst.Add(iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(pdfreader,i)); // text.AppendLine(); //} string text = iTextSharp.text.pdf.parser.PdfTextExtractor.GetTextFromPage(pdfreader, 1); string[] words = text.Split('\n'); foreach (var item in words) { string value = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(item)); if (value.Contains(getPdfValue)) { string[] splitValue = value.Split(':'); lst.Add(splitValue[1].Trim()); } } pdfreader.Close(); return lst; } catch (Exception ex) { throw ex; } } private void button22_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button21_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button20_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button19_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button18_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void button17_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } /// /// HMI04读取 /// /// /// private void btnHMI04Reading_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } var dataCaptureConfigslist = DataCaptureConfigManager.GetDataCaptureConfigs(); foreach (var config in dataCaptureConfigslist) { switch (config.DataCapturePointCode) { } } } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } /// /// HMI04写入 /// /// /// private void btnHMIWrite_Click(object sender, EventArgs e) { try { if (!SystemValue.isStartedModel) { MessageBox.Show("请点击调试模式按钮"); return; } var dataCaptureConfigslist = DataCaptureConfigManager.GetDataCaptureConfigs(); foreach (var config in dataCaptureConfigslist) { switch (config.DataCapturePointCode) { } } // DataCaptureHandler.WorkPieceID = textBox10.Text.Trim(); } catch (Exception ex) { MessageBox.Show($"模拟异常:{ex.Message}"); Log4NetHelper.WriteErrorLog(LogType.FormMain, "----button10_Click all报错:", ex); } } private void FormMain_FormClosed(object sender, FormClosedEventArgs e) { Application.Exit(); //强制结束进程并退出 //System.Diagnostics.Process.GetCurrentProcess().Kill(); System.Environment.Exit(0); } private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { //if (MessageBox.Show("将要关闭采集程序,是否继续?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes) //{ // e.Cancel = false; //} //else //{ // e.Cancel = true; //} e.Cancel = false; } private void button24_Click(object sender, EventArgs e) { try { #region 数据采集项确定 var dataCaptureConfigslist = DataCaptureConfigManager.GetDataCaptureConfigs(); var columnList = DataCaptureConfigManager.GetDataCaptureColumnConfig(); //var keyvalue = dataCaptureConfigslist.GroupBy(o => o.WorkingProcedure).Select(g => new //{ // keyword = g.Key, // RecordIDs = g.Where(c =>c.WorkingProcedure.Equals(g.Key)).ToList() //}); foreach (var config in dataCaptureConfigslist) { switch (config.DataCapturePointCode) { } } #endregion try { } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "启动线程时----btn_StartUpAllThread_Click报错:", ex); } #region 设置显示UI tskSetGridSource = new Thread(GridRefresh); tskSetGridSource.Start(); dataGridView2.DataSource = sourcelist; #endregion } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "启动线程时----btn_StartUpAllThread_Click all报错:", ex); } } private void FormMain_Scroll(object sender, ScrollEventArgs e) { Rectangle rect; DataGridView ctrl = (DataGridView)sender; Point pt = PointToScreen(ctrl.Location); if (pt.X < 0) { int left = -pt.X; int top = ctrl.ColumnHeadersHeight; int width = e.OldValue - e.NewValue; int height = ctrl.ClientSize.Height; ctrl.Invalidate(new Rectangle(new Point(left, top), new Size(width, height))); } pt.X += ctrl.Width; rect = Screen.GetBounds(pt); if (pt.X > rect.Right) { int left = ctrl.ClientSize.Width - (pt.X - rect.Right) - (e.NewValue - e.OldValue); int top = ctrl.ColumnHeadersHeight; int width = e.NewValue - e.OldValue; int height = ctrl.ClientSize.Height; ctrl.Invalidate(new Rectangle(new Point(left, top), new Size(width, height))); } pt.Y += ctrl.Height; if (pt.Y > rect.Bottom) { int left = 0; int top = ctrl.ColumnHeadersHeight; int width = ctrl.ClientSize.Width; int height = ctrl.ClientSize.Height - (pt.Y - rect.Bottom) - (e.NewValue - e.OldValue); ctrl.Invalidate(new Rectangle(new Point(left, top), new Size(width, height))); } } private void button23_Click(object sender, EventArgs e) { GridRefresh(); } private void button25_Click(object sender, EventArgs e) { try { var WorkingProcedure = "OP35"; var EquipmentID = "EOP35"; var DataCapturePointCode = "OP3502A"; //var DataCapturePointCode = "OP3002CH3"; WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); wplog.WorkingProcedure = WorkingProcedure; wplog.EquipmentID = EquipmentID; ; wplog.Remarks = WorkingProcedure; wplog.MonitoringPoint = DataCapturePointCode; wplog.WorkPieceID = "DZ045L2309080100181A1A"; wplog.CreatedTime = DateTimeHelper.GetDateTime(); wplog.CreatedUserName = DataCapturePointCode; wplog.UpdatedUserName = Environment.MachineName + "自动" + Thread.CurrentThread.ManagedThreadId.ToString(); wplog.UpdatedTime = DateTimeHelper.GetDateTime(); wplog.IsDeleted = false; wplog.QualityOP10To1 = "-500"; WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //string path = ConfigHelper.GetConfigString("OP30QualityDataForStation");//打码机打码二维码路径 //if (string.IsNullOrEmpty(path)) //{ // path = @"C:\work\003-一汽连杆数据采集\整理文档\设备接口文档\"; //} //path = @"C:\work\003-一汽连杆数据采集\整理文档\设备接口文档\"; //if (DataCapturePointCode.Contains("CH3")) //{//工位3 涨断力矩 // path = path + "kistler_crack"; //} //else if (DataCapturePointCode.Contains("CH4")) //{//工位4 预拧紧力矩 // path = path + "Bosch_Rexroth"; //} //else if (DataCapturePointCode.Contains("CH5")) //{//工位5 拧紧力矩 // path = path + "Bosch_Rexroth"; //} //else if (DataCapturePointCode.Contains("CH6")) //{//工位6 衬套压装力矩 // path = path + "kistler_bush"; //} //wplog.WorkPieceID = "DZ045L2309270100371A1A"; //try //{ // var get = wplog.GetType().GetProperty("WorkPieceID"); // if (get == null) // { // //Log4NetHelper.WriteErrorLog(LogType.DBDataCapture, $" {group.EquipmentNo}设备由于源头字段名{item.DataCaptureColumnTabelColName}没找到,赋值失败{currentlog.Id}"); // //continue; // } // var valuecol = get.GetValue(wplog); //} //catch (Exception setex) //{ // } ////wplog.QualityStateStr = "OK"; ////wplog.QualityOP30To1 = "test0122"; ////wplog.QualityOP30To2 = "test0122"; ////wplog.QualityOP80To1 = "test990222"; //try //{ // if (WorkingProcedure.Equals("OP30")) // { // var time = DateTimeHelper.GetDateTime(); // //获取文件夹名称 // List directorylist = new List(); // string directory = time.ToString("yyyy-MM-dd_HH"); // string directoryOther = time.AddSeconds(-30).ToString("yyyy-MM-dd_HH"); // directorylist.Add(directory); // if (!directory.Equals(directoryOther)) // {//如果30秒前是另一个文件夹 // directorylist.Add(directoryOther); // } // List files = new List(); // foreach (var dir in directorylist) // { // try // { // //扫描当前时间与30秒前出现的文件,一般节拍在15秒左右(两个服务器时间不一样会导致取不到文件) // var newFiles = FileHelper.DetectNewFiles(path + @"\" + dir, "*.pdf", 1000000000, time, time); // foreach (var file in newFiles) // { // files.Add((FileInfo)file); // } // } // catch (Exception ex) // { // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"{DataCapturePointCode}下线完成读取文件{dir}数据时异常,避免工序完成异常1:", ex); // } // } // files = files.OrderByDescending(o => o.LastWriteTime).ToList(); // if (files.Count > 0) // { // switch (DataCapturePointCode) // { // case "OP3002CH3": // wplog.QualityStateStr = FileHelper.ReadPdfConntent(files[0].FullName, "Result"); // wplog.QualityStateStr = FileHelper.ReadPdfConntent(files[1].FullName, "Result"); // wplog.QualityOP30To1 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//涨断力矩 // break; // case "OP3002CH4": // wplog.QualityStateStr = FileHelper.ReadPdfConntent(files[0].FullName, "Result"); // wplog.QualityOP30To2 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//预拧紧力矩 // wplog.QualityOP30To3 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//预拧紧角度 // break; // case "OP3002CH5": // wplog.QualityStateStr = FileHelper.ReadPdfConntent(files[0].FullName, "Result"); // wplog.QualityOP30To4 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//终拧紧力矩 // wplog.QualityOP30To5 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//终拧紧角度 // break; // case "OP3002CH6": // wplog.QualityStateStr = FileHelper.ReadPdfConntent(files[0].FullName, "Result"); // wplog.QualityOP30To6 = FileHelper.ReadPdfConntent(files[0].FullName, "Y-Maximum");//衬套压装力矩 // wplog.QualityOP30To7 = FileHelper.ReadPdfConntent(files[0].FullName, "Block X");//衬套压装位移 // break; // default: // break; // } // } // } //} //catch (Exception ex) //{ // //threadStatusMonitor.ErrorMsg = $" {RandomHelper.GenerateRandomCode(4)} 读取{DataCapturePointCode}下线标记 出现异常,请查看日志!"; // Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"OP80下线完成读取文件数据时异常,避免工序完成异常:", ex); //} ////更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 //WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //threadStatusMonitor.Threadstatue = 1; //WorkPieceInfoManager.WorkPieceSPCPushOff(wplog, LogType.PLCOP10); //WorkPieceInfoManager.WorkPieceSPCPushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //WorkPieceInfoManager.WorkingProcedureComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //WorkPieceInfoManager.ReadQRcode(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), new PLCService(), 1); //if (WorkingProcedure.Equals("OP20") // //|| _dataCaptureConfig.WorkingProcedure.Equals("OP50")|| _dataCaptureConfig.WorkingProcedure.Equals("OP60") // ) //{//op20,op50,op60 会同时推出多件,所以特殊处理 // wplog.WorkPieceID = wplog.WorkPieceIDA; // wplog.Remarks = "NOOK推出工件A"; // WorkPieceInfoManager.WorkPiecePushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); // wplog.WorkPieceID = wplog.WorkPieceIDB; // wplog.Remarks = "NOOK推出工件B"; // WorkPieceInfoManager.WorkPiecePushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); // wplog.WorkPieceID = wplog.WorkPieceIDC; // wplog.Remarks = "NOOK推出工件C"; // WorkPieceInfoManager.WorkPiecePushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); // wplog.WorkPieceID = wplog.WorkPieceIDD; // wplog.Remarks = "NOOK推出工件D"; // WorkPieceInfoManager.WorkPiecePushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //} //else //{ // //更新WorkPieceInfo表以及插入WorkPieceLog表和WorkPieceInfoLog表 // WorkPieceInfoManager.WorkPiecePushOff(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); //} } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void button26_Click(object sender, EventArgs e) { try { MyTest myTest = new MyTest(); Thread tskdataCapture = new Thread(myTest.DataCaptureStart); tskdataCapture.Start(); } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, "启动线程时----btn_StartUpAllThread_Click all报错:", ex); } } public WorkPieceLogMiddle GetCH4Info(string FullName, WorkPieceLogMiddle wplog) { try { string fileContent = File.ReadAllText(FullName); string[] lines2 = fileContent.Split('\n'); bool IDCodeIndex = false; int Mcount = 0; int i = 0; int count = 0; foreach (string line in lines2) { count++; if (count == 4) {//获取质量结果 var list = line.Split(' '); if (list.Count() > 0) { var str = list[list.Count() - 1].ToString().Trim(); wplog.QualityStateStr = str.Equals("OK") ? "OK" : "NG"; } } // 处理每一行的逻辑 if (line.Contains("ID-Code"))//两个拧紧,每个前面都有ID-Code { i++; IDCodeIndex = true; Mcount = 0; } if (IDCodeIndex) { if (line.Contains(" M "))//第三个M行是拧紧数据 {//预拧紧力矩 Mcount++; if (Mcount == 3) { i++; var str = line.Replace("+", "").Replace("-", ""); var list = str.Split('M'); if (list.Count() == 4) { if (i <= 2) {//CH1 wplog.QualityOP30To2 = list[2].ToString().Trim(); } else {//CH2 wplog.QualityOP30To8 = list[2].ToString().Trim(); } } IDCodeIndex = false; } } } } } catch (Exception ex) { //Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读取 {DataCapturePointCode}CH4工位质量数据异常工件号:{(wplog.WorkPieceID == null ? "" : wplog.WorkPieceID)} 文件名:{FullName}:", ex); } return wplog; } public WorkPieceLogMiddle GetCH5Info(string FullName, WorkPieceLogMiddle wplog) { try { string fileContent = File.ReadAllText(FullName); string[] lines2 = fileContent.Split('\n'); bool IDCodeIndex = false; int Mcount = 0; int i = 0; int count = 0; foreach (string line in lines2) { count++; if (count == 4) {//获取质量结果 var list = line.Split(' '); if (list.Count() > 0) { var str = list[list.Count() - 1].ToString().Trim(); wplog.QualityStateStr = str.Equals("OK") ? "OK" : "NG"; } } // 处理每一行的逻辑 if (line.Contains("ID-Code"))//两个拧紧,每个前面都有ID-Code { i++; IDCodeIndex = true; Mcount = 0; } if (IDCodeIndex) { if (line.Contains(" M "))//第三个M行是拧紧数据 {//最终力矩 Mcount++; if (Mcount == 3) { var str = line.Replace("+", "").Replace("-", ""); var list = str.Split('M'); if (list.Count() == 4) { if (i == 1) {//CH3 wplog.QualityOP30To3 = list[2].ToString().Trim(); } else {//CH4 wplog.QualityOP30To9 = list[2].ToString().Trim(); } } IDCodeIndex = false; } } } if (line.Contains(" MWSP ")) {//终拧紧力矩 终拧紧角度 var list = line.Split(new String[] { " MWS " }, StringSplitOptions.None); if (list.Count() == 2) { if (i == 1) {//CH3 wplog.QualityOP30To4 = list[1].ToString().Trim(); } else {//CH4 wplog.QualityOP30To10 = list[1].ToString().Trim(); } var list2 = list[0].Split(new String[] { " W " }, StringSplitOptions.None); if (list2.Count() == 2) { var str = list2[1].ToString(); if (i == 1) {//CH3 wplog.QualityOP30To5 = str.Substring(0, str.IndexOf("MWSP")).Trim(); } else {//CH4 wplog.QualityOP30To11 = str.Substring(0, str.IndexOf("MWSP")).Trim(); } } } } } } catch (Exception ex) { //Log4NetHelper.WriteErrorLog(PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure), $"读取 {DataCapturePointCode}CH5工位质量数据异常工件号:{(wplog.WorkPieceID == null ? "" : wplog.WorkPieceID)} 文件名:{FullName}:", ex); } return wplog; } private void button27_Click(object sender, EventArgs e) { try { #region OP80 ////string str = "#123"; ////str=str?.Replace("#", ""); //WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); //string path = "C:\\Users\\SY-PC\\Desktop\\FO";//OP80的地址 //var time = DateTimeHelper.GetDateTime(); //DateTime? fileFindTime = null; //if (fileFindTime == null) //{ // fileFindTime = time.AddMinutes(-10); //} ////OP80 需要扫描文件读取质量信息 ////扫描修改时间在上次扫描时间之前30秒到当前时间的之间的文件 //List files = new List(); //var newFiles = FileHelper.DetectNewFilesCSV(path, 3000000, fileFindTime.Value, time.AddHours(2)); //foreach (var file in newFiles) //{ // files.Add((FileInfo)file); //} //files = files.OrderByDescending(o => o.LastWriteTime).ToList(); //foreach (var file in files) //{//取倒序匹配的文件名为工件号的文件 // var datatable = CSVHelper.ReadCSVList(file.FullName); // List rowFirst = new List(); // List rowSecond = new List(); // if (datatable.Count == 2) // { // rowFirst = datatable[0].Split(',').ToList(); // rowSecond = datatable[1].Split(',').ToList(); // if (rowSecond.Count < 11) // { // continue; // } // //日期和时间 批号/标识号 嵌套号/主轴号 操作符 文本 测量机 过程参数 测量系统 过程参数值 序列号 零件识别号 1 // OP80Info oP80Info = new OP80Info(); // oP80Info.日期和时间 = rowSecond[0]; // oP80Info.批号 = rowSecond[1]; // oP80Info.嵌套号 = rowSecond[2]; // oP80Info.操作符 = rowSecond[3]; // oP80Info.文本 = rowSecond[4]; // oP80Info.测量机 = rowSecond[5]; // oP80Info.过程参数 = rowSecond[6]; // oP80Info.测量系统 = rowSecond[7]; // oP80Info.过程参数值 = rowSecond[8]; // oP80Info.序列号 = rowSecond[9]; // oP80Info.零件识别号 = rowSecond[10]; // for (int i = 1; i <= (rowSecond.Count - 11) / 10; i++) // { // if (rowSecond.Count < (11 + i * 10)) // { // break; // } // //名称 相对值 相对值单位 绝对值 绝对值单位 名义值 上限 下限 状态/等级 分隔符 // OP80ItemInfo item = new OP80ItemInfo(); // item.分隔符 = rowSecond[1 + i * 10]; // item.名称 = rowSecond[2 + i * 10]; // item.相对值 = rowSecond[3 + i * 10]; // item.相对值单位 = rowSecond[4 + i * 10]; // item.绝对值 = rowSecond[5 + i * 10]; // item.绝对值单位 = rowSecond[6 + i * 10]; // item.名义值 = rowSecond[7 + i * 10]; // item.上限 = rowSecond[8 + i * 10]; // item.下限 = rowSecond[9 + i * 10]; // item.状态 = rowSecond[10 + i * 10]; // oP80Info.OP80ItemInfolist.Add(item); // if (item.名称.Equals("Weight Class") || item.名称.Equals("Weight Small End") // || item.名称.Equals("Weight Big End") || item.名称.Equals("Dime Small_End Class") // || item.名称.Equals("Dime Big_End Class")) // { // } // else // { // if (!string.IsNullOrEmpty(item.状态)) // { // oP80Info.OP80ItemStatusInfolist.Add(item); // } // } // } // if (oP80Info.OP80ItemStatusInfolist.Count > 0) // { // if (oP80Info.OP80ItemStatusInfolist.Any(o => !o.状态.Equals("OK"))) // { // wplog.QualityStateStr = "NG"; // } // else // { // wplog.QualityStateStr = "OK"; // } // } // else // { // wplog.QualityStateStr = "OK"; // } // wplog.OP80NewCode = oP80Info.批号?.Replace("#", ""); // //大头重量 // wplog.QualityOP80To1 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Weight Big End")).FirstOrDefault()?.绝对值; // //小头重量 // wplog.QualityOP80To2 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Weight Small End")).FirstOrDefault()?.绝对值; // //总重 // wplog.QualityOP80To3 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Total Weight")).FirstOrDefault()?.绝对值; // //弯曲 // wplog.QualityOP80To4 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Bend to A")).FirstOrDefault()?.绝对值; // //扭度 // wplog.QualityOP80To5 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Twist to A")).FirstOrDefault()?.绝对值; // //大头垂直度 // wplog.QualityOP80To6 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Big_End_C_Squareness")).FirstOrDefault()?.绝对值; // //小头垂直度 // wplog.QualityOP80To10 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Sma_End_C_Squareness")).FirstOrDefault()?.绝对值; // //大头孔分组级别 // wplog.QualityOP80To7 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Dime Big_End Class")).FirstOrDefault()?.状态; // //小头孔分组级别 // wplog.QualityOP80To8 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Dime Small_End Class")).FirstOrDefault()?.状态; // //重量组别 // wplog.QualityOP80To9 = oP80Info.OP80ItemInfolist.Where(o => o.名称.Equals("Weight Class")).FirstOrDefault()?.状态; // } // else // { // wplog.Remarks = (wplog.Remarks ?? "") + $"OP80下线完成读取文件{file.FullName}异常,行数不是2行"; // } // fileFindTime = files[0].LastWriteTime; // break; //} #endregion #region OP30 //////var QualityStateStr = FileHelper.ReadPdfFileForSpire(textBox10.Text, "Result"); //////var QualityOP30To6 = FileHelper.ReadPdfFileForSpire(textBox10.Text, "Y-Maximum");//衬套压装力矩 //////var QualityOP30To7 = FileHelper.ReadPdfFileForSpire(textBox10.Text, "Block X");//衬套压装位移 ////var dt = CSVHelper.ReadCSV(textBox10.Text); //////var datatable = CSVHelper.ReadCSVList(textBox10.Text); //////List rowFirst = new List(); //////List rowSecond = new List(); //////if(datatable.Count==2) //////{ ////// rowFirst = datatable[0].Split(',').ToList(); ////// rowSecond = datatable[1].Split(',').ToList(); //////} //string d = DateTime.Now.AddHours(-10).ToString("yyyy-MM-dd_HH"); ////扫描共享目录并将新的文件扫描返回 一般节拍在15秒左右(可以确认一下) ////扫描修改时间在上次扫描时间之前10秒到当前时间的之间的文件 //var startTime = DateTimeHelper.GetDateTime().AddYears(-1); //var endTime = DateTimeHelper.GetDateTime(); ////var newFiles = FileHelper.DetectNewFilesCSV(textBox10.Text+@"\"+d, 10, Convert.ToDateTime(startTime), endTime); ////List files = new List(); ////foreach (var file in newFiles) ////{ //// files.Add((FileInfo)file); ////} ////files = files.OrderByDescending(o => o.LastAccessTime).ToList(); ////foreach (var file in files) ////{ //// //var datatable = CSVHelper.ReadCSV(file.FullName); ////} //var newFiles = FileHelper.DetectNewFiles(textBox10.Text, "*.txt", 10, Convert.ToDateTime(startTime), endTime); //List files = new List(); //foreach (var file in newFiles) //{ // files.Add((FileInfo)file); //} //files = files.OrderByDescending(o => o.LastAccessTime).ToList(); //foreach (var file in files) //{ // //string[] lines = File.ReadAllLines(file.FullName); // //foreach (string line in lines) // //{ // // // 处理每一行的逻辑 // //} // ////var datatable = CSVHelper.ReadCSV(file.FullName); // //using (StreamReader reader = new StreamReader(file.FullName)) // //{ // // string line; // // while ((line = reader.ReadLine()) != null) // // { // // // 处理每一行的逻辑 // // } // //} // string fileContent = File.ReadAllText(file.FullName); // string[] lines2 = fileContent.Split('\n'); // bool IDCodeIndex = false; // int Mcount = 0; // foreach (string line in lines2) // { // // 处理每一行的逻辑 // if (line.Contains("ID-Code"))//两个拧紧,每个前面都有ID-Code // { // IDCodeIndex = true; // Mcount = 0; // } // if(IDCodeIndex) // { // if (line.Contains(" M "))//第三个M行是拧紧数据 // { // Mcount++; // if(Mcount==3) // { // var str=line.Replace("+", "").Replace("-", ""); // var list = str.Split('M'); // if(list.Count()==4) // { // } // IDCodeIndex = false; // } // } // } // } //} #endregion #region OP60 WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); string path = "C:\\Users\\SY-PC\\Desktop\\FO";//OP80的地址 var time = DateTimeHelper.GetDateTime(); DateTime? fileFindTime = null; if (fileFindTime == null) { fileFindTime = time.AddMinutes(-100); } //OP60 需要扫描文件读取质量信息 //扫描修改时间在上次扫描时间之前30秒到当前时间的之间的文件 List files = new List(); var newFiles = FileHelper.DetectNewFiles(path, "*.dfq", 300000, fileFindTime.Value, time.AddHours(2)); foreach (var file in newFiles) { files.Add((FileInfo)file); } files = files.OrderByDescending(o => o.LastWriteTime).ToList(); List op60Infos = new List(); foreach (var file in files) {//取倒序匹配的文件名为工件号的文件 string DataCapturePointCode = "OP6002A"; if (file.Name.Contains("SP-" + DataCapturePointCode.Substring(DataCapturePointCode.Length - 1, 1))) { } var datatable = CSVHelper.ReadCSVList(file.FullName); if (datatable.Count < 106) {//质量数据从106行开始 } datatable.Reverse(); System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding(); byte[] byteArray = new byte[] { (byte)15 }; string strCharacter = asciiEncoding.GetString(byteArray); var list = datatable[0].Split(new String[] { strCharacter }, StringSplitOptions.None); byte[] byteArray2 = new byte[] { (byte)20 }; string strCharacter2 = asciiEncoding.GetString(byteArray2); foreach (var item in list) { var listitem = item.Split(new String[] { strCharacter2 }, StringSplitOptions.None); if (listitem.Count() == 3) { OP60Info info = new OP60Info(); info.datetime = listitem[2]; info.col2 = listitem[1]; info.value = listitem[0]; info.datetimeHandle = CommonManager.GetOP60Time(info.datetime); op60Infos.Add(info); } } if (op60Infos.Count() >= 2) { //if (op60QualityTime.HasValue) { //if (op60Infos[0].datetimeHandle > op60QualityTime.Value) { wplog.QualityOP60To1 = op60Infos[0].value; wplog.QualityOP60To2 = op60Infos[1].value; } } //op60QualityTime = op60Infos[0].datetimeHandle; break; } } #endregion #region QITA //var WorkingProcedure = "OP20"; //var EquipmentID = "EOP20"; //var DataCapturePointCode = "OP2002A"; ////var DataCapturePointCode = "OP3002CH3"; //WorkPieceLogMiddle wplog = new WorkPieceLogMiddle(); //wplog.Id = Yitter.IdGenerator.YitIdHelper.NextId(); //wplog.WorkingProcedure = WorkingProcedure; //wplog.EquipmentID = EquipmentID; //wplog.Remarks = WorkingProcedure; //wplog.MonitoringPoint = DataCapturePointCode; //wplog.WorkPieceID = "DZ045L2312150101041CAO"; //wplog.CreatedTime = DateTimeHelper.GetDateTime(); //wplog.CreatedUserName = DataCapturePointCode; //wplog.UpdatedUserName = Environment.MachineName + "自动" + Thread.CurrentThread.ManagedThreadId.ToString(); //wplog.UpdatedTime = DateTimeHelper.GetDateTime(); //wplog.IsDeleted = false; //wplog.QualityStateStr = "OK"; ////try ////{ //// using (DbModel db = new DbModel()) //// { //// var info = db.KnifeToolEquipmentInfo.Where(o => o.EquipmentID.Equals(wplog.EquipmentID)).ToList(); //// foreach (var item in info) //// { //// item.CurrentLife++; //// item.UpdatedTime = DateTime.Now; //// } //// //db.SaveChanges(); //// } ////} ////catch (Exception ex) ////{ ////} ////wplog.Remarks = ""; ////wplog.Remarks = (wplog.Remarks ?? "") + $"质量:{wplog.Remarks ?? "空"}"; ////wplog.Remarks = null; ////wplog.Remarks = (wplog.Remarks ?? "") + $"质量:{wplog.Remarks ?? "空"}"; ////wplog.Remarks = "111"; ////wplog.Remarks = (wplog.Remarks ?? "") + $"质量:{wplog.Remarks ?? "空"}"; ////wplog = GetCH4Info(textBox10.Text, wplog); //WorkPieceInfoManager.QualityInfoComplete(wplog, PLCManger.GetLogTypeForWorkingProcedure(WorkingProcedure)); ////WorkPieceLogMiddle log = new WorkPieceLogMiddle(); ////log = GetCH5Info(textBox10.Text, log); #endregion } catch (Exception ex) { MessageBox.Show(ex.Message); } } } public enum test { test1, test2 = 3, test3 = 4 } }