/// <summary> /// 网络发送数据 /// </summary> /// <param name="socket"></param> /// <param name="bytes"></param>发送数据 /// <returns></returns> private bool Send(Socket socket, byte[] bytes) { if (bytes.Length == 0) { return(false); } int nRemain = bytes.Length; int nSentByte; int nOffset = 0; while (nRemain > 0) { try { nSentByte = socket.Send(bytes, nOffset, bytes.Length, 0);//发送数据 if (nSentByte > 0) { nRemain -= nSentByte; nOffset += nSentByte; } } catch (Exception e) { Trace.WriteLine("网络发送失败" + e); #if REALEASE GlobalDataInterface.WriteErrorInfo("网络发送失败" + e); #endif break; } } if (nRemain == 0) { return(true); } else { return(false); } }
//光谱仪信息 - 默认 private void ButtonSetSpectrumDefault_Click(object sender, EventArgs e) { try { this.EditInfoProductID.Text = "100001"; this.EditInfoProductSerial.Text = "200001"; this.EditInfoSpectoroSerial.Text = "300001"; this.EditCcdInfoCoeffA0.Text = "6.268700224E+002"; this.EditCcdInfoCoeffA1.Text = "1.968955472E+000"; this.EditCcdInfoCoeffA2.Text = "-7.581370116E-004"; this.EditCcdInfoCoeffA3.Text = "-1.322739500E-006"; this.EditCcdInfoCoeffA4.Text = "1.224827478E-009"; this.EditCcdInfoCoeffA5.Text = "-2.040336664E-012"; } catch (Exception ex) { Trace.WriteLine("ProjectSetForm-InnerQuality中函数ButtonSetSpectrumDefault_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm-InnerQuality中函数ButtonSetSpectrumDefault_Click出错" + ex); #endif } }
/// <summary> /// Channel /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ChannelcomboBox_SelectedIndexChanged(object sender, EventArgs e) { try { int tempChannelIndex = this.ChannelcomboBox.SelectedIndex; int tempCurrentIPMIndex = Commonfunction.GetIPMIndex(m_ChannelIDList[tempChannelIndex]); int tempCurrentSysIndex = Commonfunction.GetSubsysIndex(m_ChannelIDList[tempChannelIndex]); if (GlobalDataInterface.global_IsTestMode) { //if (GlobalDataInterface.nVer == 1) //版本号判断 add by xcw 20200604 //{ // GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPMChannel(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null); // //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); // GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPMChannel(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); //} //else if (GlobalDataInterface.nVer == 0) //{ // GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null); // //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); // GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); //} GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(m_CurrentSysIndex, m_CurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null); //GlobalDataInterface.TransmitParam(m_IPMIDList[this.IPMcomboBox.SelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); GlobalDataInterface.TransmitParam(Commonfunction.EncodeIPM(tempCurrentSysIndex, tempCurrentIPMIndex), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_ON, null); } m_CurrentChannelIndex = this.ChannelcomboBox.SelectedIndex; m_CurrentIPMIndex = Commonfunction.GetIPMIndex(m_ChannelIDList[m_CurrentChannelIndex]); m_CurrentSysIndex = Commonfunction.GetSubsysIndex(m_ChannelIDList[m_CurrentChannelIndex]); } catch (Exception ex) { Trace.WriteLine("FruitParamForm中函数ChannelcomboBox_SelectedIndexChanged出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("FruitParamForm中函数ChannelcomboBox_SelectedIndexChanged出错" + ex); #endif } }
private void Start_Click(object sender, EventArgs e) { try { if (m_VolveTest.ExitId != 255) { if (m_VolveTest.ExitId <= 100) { this.ExitlistViewEx.Items[m_VolveTest.ExitId].BackColor = Color.White; this.ExitlistViewEx.Items[m_VolveTest.ExitId].Font = new Font("宋体", 9, FontStyle.Regular); } } m_VolveTest.ExitId = (byte)(m_CurrentItemIndex); this.ExitlistViewEx.Items[m_CurrentItemIndex].BackColor = Color.Red; this.ExitlistViewEx.Items[m_CurrentItemIndex].Font = new Font("黑体", 9, FontStyle.Italic | FontStyle.Bold); if (GlobalDataInterface.global_IsTestMode) { if (this.chkSidebySideTest.Checked) //Modify by ChengSk - 20190726 { GlobalDataInterface.TransmitParam(m_ChanelIDList[m_ChannelSeleccomboBoxSelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_TEST_ALL_LANE_VOLVE, m_VolveTest); } else { GlobalDataInterface.TransmitParam(m_ChanelIDList[m_ChannelSeleccomboBoxSelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_TEST_VOLVE, m_VolveTest); } } m_IsVolveTesting = true; m_CurrentItemIndex = -1; } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数Start_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数Start_Click出错" + ex); #endif } }
/// <summary> /// 关闭窗口事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TestCupForm_FormClosed(object sender, FormClosedEventArgs e) { try { if (this.Testbutton.Text == m_resourceManager.GetString("StopTestlabel.Text")) { this.Testbutton.Text = m_resourceManager.GetString("Testbutton.Text"); this.Infolabel.Text = m_resourceManager.GetString("PrepareInfolabel.Text"); if (GlobalDataInterface.global_IsTestMode) { GlobalDataInterface.TransmitParam(-1, (int)HC_FSM_COMMAND_TYPE.HC_CMD_TEST_CUP_OFF, null); } } } catch (Exception ex) { Trace.WriteLine("TestCupForm中函数TestCupForm_FormClosed出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("TestCupForm中函数TestCupForm_FormClosed出错" + ex); #endif } }
/// <summary> /// 上传图像显示刷新 /// </summary> /// <param name="imageInfo"></param> public void OnUpSpotImageData(stSpliceImageData spotImageData) { try { if (this == Form.ActiveForm) { if (this.InvokeRequired) { this.BeginInvoke(new GlobalDataInterface.SpotImageDataEventHandler(OnUpSpotImageData), spotImageData); } else { if (spotImageData.imageInfo.nRouteId != 272 || spotImageData.imageInfo.width != m_srcBitamp.Width)//|| spotImageData.imageInfo.height != 20* m_srcBitamp.Height) { return; } this.DstpictureBox.Width = m_srcBitamp.Width; this.DstpictureBox.Height = spotImageData.imageInfo.height; m_spotimageData = new stSpliceImageData(spotImageData.imagedataC.Length); m_spotimageData.ToCopy(spotImageData); byte[] tempImagedata = new byte[spotImageData.imageInfo.width * spotImageData.imageInfo.height * 2]; m_SpotDetectRGBImage = new byte[spotImageData.imageInfo.width * spotImageData.imageInfo.height * 4]; Array.Copy(m_spotimageData.imagedataC, 0, tempImagedata, 0, m_spotimageData.imageInfo.width * m_spotimageData.imageInfo.height * 2); Commonfunction.YUV422ChangeToRGB(tempImagedata, ref m_SpotDetectRGBImage, m_spotimageData.imageInfo.width, m_spotimageData.imageInfo.height); this.FlawAreatextBox.Text = m_spotimageData.imageInfo.unFlawArea.ToString(); this.FlawNumtextBox.Text = m_spotimageData.imageInfo.unFlawNum.ToString(); this.DstpictureBox.Invalidate(); } } } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-ColorSetForm中函数OnUpImageInfo出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-ColorSetForm中函数OnUpImageInfo出错" + ex); #endif } }
private Control[] DensitySetEditors;//密度列表点击显示控件 /// <summary> /// 初始化 /// </summary> private void DensitySetInitial() { try { if (GlobalDataInterface.DensityGradeNum == 0) { GlobalDataInterface.DensityGradeNum = ConstPreDefine.MAX_DENSITY_GRADE_NUM; } this.DensitycomboBox.SelectedIndex = GlobalDataInterface.DensityGradeNum - 1; GlobalDataInterface.globalOut_GradeInfo.stDensityGradeName.CopyTo(m_DensityGradeName, 0); GlobalDataInterface.globalOut_GradeInfo.fDensityFactor.CopyTo(m_fDensityFactor, 0); SetDensityListView(); DensitySetEditors = new Control[] { this.DensityNametextBox, this.DensityNumnumericUpDown }; } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-DensitySeFormt中函数DensitySetInitial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-DensitySeFormt中函数DensitySetInitial出错" + ex); #endif } }
/// <summary> /// 创建主服务套接字 /// </summary> /// <param name="nTimeout">发送和接收超时时间</param> /// <returns>socket</returns> private Socket CreateMasterSocket(int nTimeout) { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建Socket IPAddress IP = IPAddress.Parse(ConstPreDefine.HC_IP_ADDR); try { socket.Bind(new IPEndPoint(IP, m_nPort));//绑定IP地址和端口 socket.SendTimeout = nTimeout; socket.ReceiveTimeout = nTimeout; socket.Listen(10); } catch (Exception e) { Trace.WriteLine("TcpServer中函数CreateMasterSocket错误" + e); #if REALEASE GlobalDataInterface.WriteErrorInfo("TcpServer中函数CreateMasterSocket错误" + e); #endif socket.Close(); return(null); } return(socket); }
/// <summary> /// 含水率 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void WatercheckBox_Click(object sender, EventArgs e) { try { CheckBox checkBox = (CheckBox)sender; if (checkBox.Checked) { this.WatercomboBox.Enabled = true; this.WatercomboBox.SelectedIndex = GlobalDataInterface.WaterGradeNum - 1; } else { this.WatercomboBox.Enabled = false; } } catch (Exception ex) { Trace.WriteLine("QualitySetForm中函数WatercheckBox_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualitySetForm中函数WatercheckBox_Click出错" + ex); #endif } }
private Control[] WaterSetEditors;//含水率列表点击显示控件 /// <summary> /// 初始化 /// </summary> private void WaterSetInitial() { try { if (GlobalDataInterface.WaterGradeNum == 0) { GlobalDataInterface.WaterGradeNum = ConstPreDefine.MAX_WATER_GRADE_NUM; } this.WatercomboBox.SelectedIndex = GlobalDataInterface.WaterGradeNum - 1; GlobalDataInterface.globalOut_GradeInfo.stWaterGradeName.CopyTo(m_WaterGradeName, 0); GlobalDataInterface.globalOut_GradeInfo.fWaterFactor.CopyTo(m_fWaterFactor, 0); SetWaterListView(); WaterSetEditors = new Control[] { this.WaterNametextBox, this.WaterNumnumericUpDown }; } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-WaterSeForm中函数WaterSetInitial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-WaterSeForm中函数WaterSetInitial出错" + ex); #endif } }
private Control[] SkinSetEditors;//浮皮列表点击显示控件 /// <summary> /// 初始化 /// </summary> private void SkinSetInitial() { try { if (GlobalDataInterface.SkinGradeNum == 0) { GlobalDataInterface.SkinGradeNum = ConstPreDefine.MAX_SKIN_GRADE_NUM; } this.SkincomboBox.SelectedIndex = GlobalDataInterface.SkinGradeNum - 1; GlobalDataInterface.globalOut_GradeInfo.stSkinGradeName.CopyTo(m_SkinGradeName, 0); GlobalDataInterface.globalOut_GradeInfo.fSkinFactor.CopyTo(m_fSkinFactor, 0); SetSkinListView(); SkinSetEditors = new Control[] { this.SkinNametextBox, this.SkinNumnumericUpDown }; } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-SkinSetForm中函数SkinSetInitial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-SkinSetForm中函数SkinSetInitial出错" + ex); #endif } }
private void ExitInfoSendbutton_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; //等待 tempGlobalExitInfo.CopyTo(GlobalDataInterface.globalOut_GlobalExitInfo, 0); //add by xcw -20191209 if (GlobalDataInterface.global_IsTestMode) { for (int i = 0; i < GlobalDataInterface.globalOut_SysConfig.nSubsysNum; i++) { GlobalDataInterface.TransmitParam(Commonfunction.EncodeSubsys(i), (int)HC_FSM_COMMAND_TYPE.HC_CMD_GLOBAL_EXIT_INFO, null); } } this.Cursor = Cursors.Default;//正常状态 } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数ExitInfoSendbutton_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数ExitInfoSendbutton_Click出错" + ex); #endif } }
private Control[] HollowSetEditors;//空心列表点击显示控件 /// <summary> /// 初始化 /// </summary> private void HollowSetInitial() { try { if (GlobalDataInterface.HollowGradeNum == 0) { GlobalDataInterface.HollowGradeNum = ConstPreDefine.MAX_HOLLOW_GRADE_NUM; } this.HollowcomboBox.SelectedIndex = GlobalDataInterface.HollowGradeNum - 1; GlobalDataInterface.globalOut_GradeInfo.stHollowGradeName.CopyTo(m_HollowGradeName, 0); GlobalDataInterface.globalOut_GradeInfo.fHollowFactor.CopyTo(m_fHollowFactor, 0); SetHollowListView(); HollowSetEditors = new Control[] { this.HollowNametextBox, this.HollowNumnumericUpDown }; } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-HollowSetForm中函数HollowSetInitial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-HollowSetForm中函数HollowSetInitial出错" + ex); #endif } }
private void FlawSaveSrcImagebutton_Click(object sender, EventArgs e) //瑕疵界面保存原图 Add by ChengSk - 20190508 { try { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "位图(*.bmp)|*.bmp|JPG格式(*.jpg)|*.jpg|GIF格式(*.gif)|*.gif|PNG格式(*.png)|*.png"; // dlg.FilterIndex = 1; dlg.RestoreDirectory = true; if (dlg.ShowDialog() == DialogResult.OK) { Rectangle rect = new Rectangle(0, 0, m_FruitImage.Width, m_FruitImage.Height / 2); Bitmap SrcImage = m_FruitImage.Clone(rect, System.Drawing.Imaging.PixelFormat.Format24bppRgb); SrcImage.Save(dlg.FileName); } } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-FlawSeFormt中函数FlawSaveSrcImagebutton_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-FlawSeFormt中函数FlawSaveSrcImagebutton_Click出错" + ex); #endif } }
/// <summary> /// 窗口加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ElectromagnetictestForm_Load(object sender, EventArgs e) { try { m_ChanelIDList.Clear(); Commonfunction.GetAllChannelID(GlobalDataInterface.globalOut_SysConfig.nChannelInfo, ref m_ChanelIDList); //for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM * ConstPreDefine.MAX_CHANNEL_NUM; i++) //{ // tempExitInfo[i] = new stExitInfo(true); //} //for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM; i++) //{ // tempGlobalExitInfo[i] = new stGlobalExitInfo(true); //} //for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM * ConstPreDefine.MAX_CHANNEL_NUM; i++) //{ // tempExitInfo[i].ToCopy(GlobalDataInterface.globalOut_ExitInfo[i]); //} for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM; i++) { tempGlobalExitInfo[i].ToCopy(GlobalDataInterface.globalOut_GlobalExitInfo[i]); } //GlobalDataInterface.globalOut_GlobalExitInfo.CopyTo(tempGlobalExitInfo, 0); //this.AllEnablingbutton.Text = m_resourceManager.GetString("StartTestbutton.Text"); ExitEditors = new Control[] { OffsetnumericUpDown, DistancenumericUpDown }; //Modify by ChengSk - 20180402 SetExitlistViewEx(); } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数VolveTestForm_Load出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数VolveTestForm_Load出错" + ex); #endif } }
/// <summary> /// 个数 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NumcheckBox_Click(object sender, EventArgs e) { try { CheckBox checkBox = (CheckBox)sender; if (checkBox.Checked) { m_bSwitchNumber = true; m_bSwitchWeight = false; m_bSwitchVolume = false; this.WeightcheckBox.Checked = false; this.VolumecheckBox.Checked = false; this.NumnumericUpDown.Enabled = m_bSwitchNumber; this.WeightnumericUpDown.Enabled = m_bSwitchWeight; this.VolumenumericUpDown.Enabled = m_bSwitchVolume; this.NumnumericUpDown.Focus(); this.NumnumericUpDown.Text = "0"; //this.NumnumericUpDown.Text = GlobalDataInterface.globalOut_GradeInfo.nCheckNum.ToString(); if (tempMotorInfo.bMotorSwitch == 2) { this.MotorEnableSwitchNumnumericUpDown.Text = this.NumnumericUpDown.Text; } } else { m_bSwitchNumber = false; this.NumnumericUpDown.Enabled = m_bSwitchNumber; } } catch (Exception ex) { Trace.WriteLine("ExitSwitchForm中函数NumcheckBox_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ExitSwitchForm中函数NumcheckBox_Click出错" + ex); #endif } }
/// <summary> /// 设置浮皮列表参数 /// </summary> private void SetSkinListView() { try { this.SkinlistViewEx.Items.Clear(); ListViewItem item; for (int i = 0; i < this.SkincomboBox.SelectedIndex + 1; i++) { byte[] temp = new byte[ConstPreDefine.MAX_TEXT_LENGTH]; Array.Copy(m_SkinGradeName, i * ConstPreDefine.MAX_TEXT_LENGTH, temp, 0, ConstPreDefine.MAX_TEXT_LENGTH); item = new ListViewItem(Encoding.Default.GetString(temp).TrimEnd('\0')); if (i == this.SkincomboBox.SelectedIndex) { m_fSkinFactor[i] = 0.000000f; } if (m_fSkinFactor[i] == 0.000000f) { item.SubItems.Add("0.000000"); } else { item.SubItems.Add(m_fSkinFactor[i].ToString("#0.000000")); } this.SkinlistViewEx.Items.Add(item); } } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm-SkinSetForm中函数SetSkinListView出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm-SkinSetForm中函数SetSkinListView出错" + ex); #endif } }
/// <summary> /// 单元格双击 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ExitSwitchdataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (e.ColumnIndex >= 0 && e.RowIndex >= 0) { if (m_bIsExitGrade[e.ColumnIndex, e.RowIndex]) { this.ExitSwitchdataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; this.ExitSwitchdataGridView[e.ColumnIndex, e.RowIndex].Value = this.OrangeimageList.Images[1]; m_bIsExitGrade[e.ColumnIndex, e.RowIndex] = false; } else //准备选中阶段 { if (GlobalDataInterface.nSampleOutlet == m_nCurrentExitIndex + 1) //抽检出口 { if (CheckSampleOutletGradeInfo(1) == true) { return; //抽检出口最多只能放一个等级 } } this.ExitSwitchdataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; this.ExitSwitchdataGridView[e.ColumnIndex, e.RowIndex].Value = this.OrangeimageList.Images[0]; m_bIsExitGrade[e.ColumnIndex, e.RowIndex] = true; } UpdateProductNameText(); //更新产品名称 } } catch (Exception ex) { Trace.WriteLine("ExitSwitchForm中函数ExitSwitchdataGridView_CellContentDoubleClick出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ExitSwitchForm中函数ExitSwitchdataGridView_CellContentDoubleClick出错" + ex); #endif } }
/// <summary> /// 瑕疵参数设置子界面快捷键事件 /// </summary> /// <param name="selectchannelNo"></param> private void TabControlSelectedIndex2Event(int selectchannelNo) { int SelectChannelNo = selectchannelNo; if (SelectChannelNo > 0 && SelectChannelNo <= ChannelNum) { try { m_CurrentChannelIndex = SelectChannelNo - 1; if (GlobalDataInterface.nVer == 1) { //m_CurrentIPM_ID = Commonfunction.EncodeIPMChannel(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex])); m_FlawCurrentIPM_ID = m_ChanelIDList[m_CurrentChannelIndex]; } else if (GlobalDataInterface.nVer == 0) { m_FlawCurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex])); } //m_CurrentIPM_ID = Commonfunction.EncodeIPM(Commonfunction.GetSubsysIndex(m_ChanelIDList[m_CurrentChannelIndex]), Commonfunction.GetIPMIndex(m_ChanelIDList[m_CurrentChannelIndex])); if (GlobalDataInterface.global_IsTestMode) { //GlobalDataInterface.TransmitParam(m_CurrentIPM_ID, (int)HC_FSM_COMMAND_TYPE.HC_CMD_GRADEINFO_OFF, null); //GlobalDataInterface.TransmitParam(m_CurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE, null); //新增 Add by ChengSk - 20190508 GlobalDataInterface.TransmitParam(m_FlawCurrentIPM_ID, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SINGLE_SAMPLE_SPOT, null); } } catch (Exception ex) { Trace.WriteLine("QualityParamSetForm中函数TabControlSelectedIndex2Event出错" + ex + "\n" + ex.StackTrace); #if REALEASE GlobalDataInterface.WriteErrorInfo("QualityParamSetForm中函数TabControlSelectedIndex2Event出错" + ex + "\n" + ex.StackTrace); #endif } } }
/// <summary> /// 开始测试按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartTestbutton_Click(object sender, EventArgs e) { try { if (m_ChannelcomboBoxSelectedIndex >= 0) { if (this.StartTestbutton.Text == m_resourceManager.GetString("StartTestbutton.Text")) { if (GlobalDataInterface.global_IsTestMode) { stVolveTest VolveTest = new stVolveTest(true);//电磁阀测试参数 VolveTest.ExitId = 254; GlobalDataInterface.TransmitParam(m_ChanelIDList[m_ChannelcomboBoxSelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_TEST_VOLVE, VolveTest); } this.StartTestbutton.Text = m_resourceManager.GetString("StopTestlabel.Text"); } else { if (GlobalDataInterface.global_IsTestMode) { stVolveTest VolveTest = new stVolveTest(true);//电磁阀测试参数 VolveTest.ExitId = 255; GlobalDataInterface.TransmitParam(m_ChanelIDList[m_ChannelcomboBoxSelectedIndex], (int)HC_FSM_COMMAND_TYPE.HC_CMD_TEST_VOLVE, VolveTest); } this.StartTestbutton.Text = m_resourceManager.GetString("StartTestbutton.Text"); } } } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数StartTestbutton_Click出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数StartTestbutton_Click出错" + ex); #endif } }
/// <summary> /// 注销主服务套接字 /// </summary> void DestroyMarsterSocket() { LingerOption linger = new LingerOption(true, 0); try { Lock(Timeout.Infinite); if (m_MasterSocket != null) { m_MasterSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, linger); m_MasterSocket.Shutdown(SocketShutdown.Both); m_MasterSocket.Close(); m_MasterSocket = null; } UnLock(); } catch (Exception e) { Trace.WriteLine("TcpServer中函数DestroyMarsterSocket错误" + e); #if REALEASE GlobalDataInterface.WriteErrorInfo("TcpServer中函数DestroyMarsterSocket错误" + e); #endif } }
private void ExitlistViewEx_SubItemClicked(object sender, ListViewEx.SubItemEventArgs e) { try { if (m_ChannelExitMouseDownType == 1)//左键 { if (e.SubItem > 0 && e.Item.Index >= 0) { this.ExitlistViewEx.StartEditing(ExitEditors[e.SubItem - 1], e.Item, e.SubItem); } } else if (m_ChannelExitMouseDownType == 2)//右键 { m_CurrentItemIndex = e.Item.Index; //if (e.Item.BackColor == Color.Red) //测试中 //{ // this.VolveTestcontextMenuStrip.Items[1].Enabled = true; // this.VolveTestcontextMenuStrip.Items[0].Enabled = false; //} //else//未测试 //{ // this.VolveTestcontextMenuStrip.Items[0].Enabled = true; // this.VolveTestcontextMenuStrip.Items[1].Enabled = false; //} Point point = this.ExitlistViewEx.PointToClient(Control.MousePosition); this.VolveTestcontextMenuStrip.Show(this.ExitlistViewEx, point); } } catch (Exception ex) { Trace.WriteLine("VolveTestForm中函数ExitlistViewEx_SubItemClicked出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("VolveTestForm中函数ExitlistViewEx_SubItemClicked出错" + ex); #endif } }
/// <summary> /// 双击表格(选定水果品种) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FruitTypedataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if ((e.ColumnIndex != 0) && (this.FruitTypedataGridView[e.ColumnIndex, e.RowIndex].Value != null)) { if (this.FruitTypedataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor == Color.Pink) { this.FruitTypedataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.White; } else { this.FruitTypedataGridView[e.ColumnIndex, e.RowIndex].Style.BackColor = Color.Pink; } } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm-FruitSet中函数FruitTypedataGridView_CellDoubleClick出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm-FruitSet中函数FruitTypedataGridView_CellDoubleClick出错" + ex); #endif } }
/// <summary> /// 执行下载事件 /// </summary> /// <returns>0-失败,1-成功,2-停止,3-异常</returns> private int OnDownLoadDataEvent() { try { DataSet dst1 = databaseOperation.GetFruitTop1NoEndProcessing(); string strLog = ""; if (dst1.Tables[0].Rows.Count > 0) { #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "正在加工进行中,无法请求下载,请结束加工后再试......"; UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return(2); //还有未结束加工的信息,无法执行下载任务 } #region 比较时间,选择最近时间 //DataSet dst2 = databaseOperation.GetFruitTop1(); //string DownloadStartTime; //string dbNewEndTime = ""; //if (dst2.Tables[0].Rows.Count > 0) //{ // dbNewEndTime = dst2.Tables[0].Rows[0]["EndTime"].ToString(); //} //if (GlobalDataInterface.DownloadStartTime.CompareTo(dbNewEndTime) == -1) //{ // DownloadStartTime = dbNewEndTime; //} //else{ // DownloadStartTime = GlobalDataInterface.DownloadStartTime; //} #endregion #region 配置时间,选择配置时间 string DownloadStartTime = GlobalDataInterface.DownloadStartTime; #endregion #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "当前download开始时间:" + DownloadStartTime + ",正在请求下载......"; UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion #region 数据请求 string strDeviceSearchCondition = GlobalDataInterface.DeviceNumber + "|" + DownloadStartTime; string strUrl = GlobalDataInterface.ServerURL + "DownLoadFruitProcessingInfo?DeviceSearchCondition="; string result = HttpHelper.OpenReadWithHttps(strUrl, strDeviceSearchCondition, 10000, new IPEndPoint(IPAddress.Parse(GlobalDataInterface.ServerBindLocalIP), 0)); JObject jo = (JObject)JsonConvert.DeserializeObject(result); string reMessage = jo["message"].ToString(); //string reResult = jo["result"].ToString(); string reStatus = jo["status"].ToString(); string reStatusCode = jo["statusCode"].ToString(); JObject jsResult = (JObject)jo["result"]; #endregion #region 数据解析,以及数据存储 if (reMessage.Contains("下传成功") && reMessage.Contains(GlobalDataInterface.DeviceNumber) && reStatusCode.Contains("SUCCESS")) { JObject jsFPInfo = (JObject)jsResult["pInfo"]; //加工信息 int RemainNumber = int.Parse(jsResult["RemainNumber"].ToString()); //待传数量 if (RemainNumber == 0) //没有待下载的数据 { #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "当前剩余待下载数量:0"; UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return(2); } FruitProcessingInfo fpInfo = new FruitProcessingInfo(); fpInfo.DeviceNumber = jsFPInfo["DeviceNumber"].ToString(); fpInfo.t1_CustomerID = jsFPInfo["t1_CustomerID"].ToString(); fpInfo.t1_CustomerName = jsFPInfo["t1_CustomerName"].ToString(); fpInfo.t1_FarmName = jsFPInfo["t1_FarmName"].ToString(); fpInfo.t1_FruitName = jsFPInfo["t1_FruitName"].ToString(); fpInfo.t1_StartTime = jsFPInfo["t1_StartTime"].ToString(); fpInfo.t1_EndTime = jsFPInfo["t1_EndTime"].ToString(); fpInfo.t1_StartedState = jsFPInfo["t1_StartedState"].ToString(); fpInfo.t1_CompletedState = jsFPInfo["t1_CompletedState"].ToString(); fpInfo.t1_BatchWeight = jsFPInfo["t1_BatchWeight"].ToString(); fpInfo.t1_BatchNumber = jsFPInfo["t1_BatchNumber"].ToString(); fpInfo.t1_QualityGradeSum = jsFPInfo["t1_QualityGradeSum"].ToString(); fpInfo.t1_WeightOrSizeGradeNum = jsFPInfo["t1_WeightOrSizeGradeNum"].ToString(); fpInfo.t1_ExportSum = jsFPInfo["t1_ExportSum"].ToString(); fpInfo.t1_ColorGradeName = jsFPInfo["t1_ColorGradeName"].ToString(); fpInfo.t1_ShapeGradeName = jsFPInfo["t1_ShapeGradeName"].ToString(); fpInfo.t1_FlawGradeName = jsFPInfo["t1_FlawGradeName"].ToString(); fpInfo.t1_HardGradeName = jsFPInfo["t1_HardGradeName"].ToString(); fpInfo.t1_DensityGradeName = jsFPInfo["t1_DensityGradeName"].ToString(); fpInfo.t1_SugarDegreeGradeName = jsFPInfo["t1_SugarDegreeGradeName"].ToString(); fpInfo.t1_ProgramName = jsFPInfo["t1_ProgramName"].ToString(); JArray ja_t2_GradeID = (JArray)jsFPInfo["t2_GradeID"]; fpInfo.t2_GradeID = ja_t2_GradeID.ToObject <List <string> >(); JArray ja_t2_BoxNumber = (JArray)jsFPInfo["t2_BoxNumber"]; fpInfo.t2_BoxNumber = ja_t2_BoxNumber.ToObject <List <string> >(); JArray ja_t2_FruitNumber = (JArray)jsFPInfo["t2_FruitNumber"]; fpInfo.t2_FruitNumber = ja_t2_FruitNumber.ToObject <List <string> >(); JArray ja_t2_FruitWeight = (JArray)jsFPInfo["t2_FruitWeight"]; fpInfo.t2_FruitWeight = ja_t2_FruitWeight.ToObject <List <string> >(); JArray ja_t2_QualityName = (JArray)jsFPInfo["t2_QualityName"]; fpInfo.t2_QualityName = ja_t2_QualityName.ToObject <List <string> >(); JArray ja_t2_WeightOrSizeName = (JArray)jsFPInfo["t2_WeightOrSizeName"]; fpInfo.t2_WeightOrSizeName = ja_t2_WeightOrSizeName.ToObject <List <string> >(); JArray ja_t2_WeightOrSizeLimit = (JArray)jsFPInfo["t2_WeightOrSizeLimit"]; fpInfo.t2_WeightOrSizeLimit = ja_t2_WeightOrSizeLimit.ToObject <List <string> >(); JArray ja_t2_SelectWeightOrSize = (JArray)jsFPInfo["t2_SelectWeightOrSize"]; fpInfo.t2_SelectWeightOrSize = ja_t2_SelectWeightOrSize.ToObject <List <string> >(); JArray ja_t2_TraitWeightOrSize = (JArray)jsFPInfo["t2_TraitWeightOrSize"]; fpInfo.t2_TraitWeightOrSize = ja_t2_TraitWeightOrSize.ToObject <List <string> >(); JArray ja_t2_TraitColor = (JArray)jsFPInfo["t2_TraitColor"]; fpInfo.t2_TraitColor = ja_t2_TraitColor.ToObject <List <string> >(); JArray ja_t2_TraitShape = (JArray)jsFPInfo["t2_TraitShape"]; fpInfo.t2_TraitShape = ja_t2_TraitShape.ToObject <List <string> >(); JArray ja_t2_TraitFlaw = (JArray)jsFPInfo["t2_TraitFlaw"]; fpInfo.t2_TraitFlaw = ja_t2_TraitFlaw.ToObject <List <string> >(); JArray ja_t2_TraitHard = (JArray)jsFPInfo["t2_TraitHard"]; fpInfo.t2_TraitHard = ja_t2_TraitHard.ToObject <List <string> >(); JArray ja_t2_TraitDensity = (JArray)jsFPInfo["t2_TraitDensity"]; fpInfo.t2_TraitDensity = ja_t2_TraitDensity.ToObject <List <string> >(); JArray ja_t2_TraitSugarDegree = (JArray)jsFPInfo["t2_TraitSugarDegree"]; fpInfo.t2_TraitSugarDegree = ja_t2_TraitSugarDegree.ToObject <List <string> >(); JArray ja_t3_ExportID = (JArray)jsFPInfo["t3_ExportID"]; fpInfo.t3_ExportID = ja_t3_ExportID.ToObject <List <string> >(); JArray ja_t3_FruitNumber = (JArray)jsFPInfo["t3_FruitNumber"]; fpInfo.t3_FruitNumber = ja_t3_FruitNumber.ToObject <List <string> >(); JArray ja_t3_FruitWeight = (JArray)jsFPInfo["t3_FruitWeight"]; fpInfo.t3_FruitWeight = ja_t3_FruitWeight.ToObject <List <string> >(); DataSet dst3 = databaseOperation.GetFruitByEndTime(fpInfo.t1_EndTime); if (dst3.Tables[0].Rows.Count > 0)//本地数据库已包含本条数据,需跳过 { GlobalDataInterface.DownloadStartTime = fpInfo.t1_EndTime; #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "下载一条加工信息(数据已存在),批次时间:" + fpInfo.t1_EndTime + ",当前剩余待下载数量:" + (RemainNumber - 1).ToString(); UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return((RemainNumber - 1) == 0 ? 2 : 1); } bool bFlag = databaseOperation.InsertFruitInfo(fpInfo.t1_CustomerName, fpInfo.t1_FarmName, fpInfo.t1_FruitName, fpInfo.t1_StartTime, fpInfo.t1_EndTime, fpInfo.t1_StartedState, fpInfo.t1_CompletedState, int.Parse(fpInfo.t1_BatchWeight), int.Parse(fpInfo.t1_BatchNumber), int.Parse(fpInfo.t1_QualityGradeSum), int.Parse(fpInfo.t1_WeightOrSizeGradeNum), int.Parse(fpInfo.t1_ExportSum), fpInfo.t1_ColorGradeName, fpInfo.t1_ShapeGradeName, fpInfo.t1_FlawGradeName, fpInfo.t1_HardGradeName, fpInfo.t1_DensityGradeName, fpInfo.t1_SugarDegreeGradeName, fpInfo.t1_ProgramName); if (bFlag == false) { return(0);//插入有误 } DataSet dst4 = databaseOperation.GetFruitByEndTime(fpInfo.t1_EndTime); int CustomerID = int.Parse(dst4.Tables[0].Rows[0]["CustomerID"].ToString()); //由于CustomerID是自增的,所以要插入之后才知道ID号 for (int i = 0; i < fpInfo.t2_GradeID.Count; i++) { bFlag = databaseOperation.InsertGradeInfo(CustomerID, int.Parse(fpInfo.t2_GradeID[i]), int.Parse(fpInfo.t2_BoxNumber[i]), int.Parse(fpInfo.t2_FruitNumber[i]), int.Parse(fpInfo.t2_FruitWeight[i]), fpInfo.t2_QualityName[i], fpInfo.t2_WeightOrSizeName[i], float.Parse(fpInfo.t2_WeightOrSizeLimit[i]), fpInfo.t2_SelectWeightOrSize[i], fpInfo.t2_TraitWeightOrSize[i], fpInfo.t2_TraitColor[i], fpInfo.t2_TraitShape[i], fpInfo.t2_TraitFlaw[i], fpInfo.t2_TraitHard[i], fpInfo.t2_TraitDensity[i], fpInfo.t2_TraitSugarDegree[i]); } for (int i = 0; i < fpInfo.t3_ExportID.Count; i++) { bFlag = databaseOperation.InsertExportInfo(CustomerID, int.Parse(fpInfo.t3_ExportID[i]), int.Parse(fpInfo.t3_FruitNumber[i]), int.Parse(fpInfo.t3_FruitWeight[i])); } GlobalDataInterface.DownloadStartTime = fpInfo.t1_EndTime; #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "下载一条加工信息并保存,批次时间:" + fpInfo.t1_EndTime + ",当前剩余待下载数量:" + (RemainNumber - 1).ToString(); UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return((RemainNumber - 1) == 0 ? 2 : 1); } else if (reMessage.Contains("下传失败") && reMessage.Contains(GlobalDataInterface.DeviceNumber) && reStatusCode.Contains("SUCCESS")) { #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "请求下载失败,设备编号无效!"; UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return(2); } else { #region 显示日志 if (UpdateDownloadLogEvent != null) { strLog = "请求下载异常!"; UpdateDownloadLogEvent(strLog); log.WriteHttpLog(strLog); } #endregion return(3); } #endregion } catch (Exception ex) { #region 显示日志 if (UpdateDownloadLogEvent != null) { string errLog = "下载过程出现异常,请查看异常日志!"; UpdateDownloadLogEvent(errLog); log.WriteHttpLog(errLog); } #endregion #if REALEASE GlobalDataInterface.WriteErrorInfo("DataDownloadForm中函数OnDownLoadDataEvent出错" + ex); #endif return(3); } }
private void FruitSetInitial() { try { this.FruitTypedataGridView.Font = new Font("微软雅黑", 9, FontStyle.Regular); this.FruitTypedataGridView.AllowUserToAddRows = false; this.FruitTypedataGridView.Rows.Clear(); this.FruitTypedataGridView.ReadOnly = false; this.FruitTypedataGridView.RowHeadersWidth = 190;//行表头宽度 this.FruitTypedataGridView.TopLeftHeaderCell.Value = m_resourceManager.GetString("FruitTypeGridViewTopLeftHeadCelllabel.Text"); DataGridViewRow row; // m_FruitType.iCurrentFruitNumber = int.Parse(Commonfunction.GetAppSetting("已选水果数量")); fruittypeconfig = Commonfunction.GetAppSetting("水果种类大类"); sFruitMajortArray = fruittypeconfig.Split(';'); //分割具体水果种类 if (GlobalDataInterface.selectLanguage == "en") { fruittypeconfig = Commonfunction.GetAppSetting("水果种类大类en"); sFruitMajortArrayEn = fruittypeconfig.Split(';');//分割具体水果种类 } if (GlobalDataInterface.selectLanguage == "es") { fruittypeconfig = Commonfunction.GetAppSetting("水果种类大类es"); sFruitMajortArrayEs = fruittypeconfig.Split(';');//分割具体水果种类 //Add by ChengSk - 20181016 } byte[] btempArray = new byte[ConstPreDefine.MAX_FRUIT_TEXT_LENGTH]; for (int i = 0; i < sFruitMajortArray.Length - 1; i++) { row = new DataGridViewRow(); row.HeaderCell.Style.Alignment = DataGridViewContentAlignment.BottomLeft; //设置文字格式 this.FruitTypedataGridView.Rows.Add(row); if (GlobalDataInterface.selectLanguage == "en") //英语 { this.FruitTypedataGridView.Rows[i].HeaderCell.Value = sFruitMajortArrayEn[i]; //水果大类名称 } else if (GlobalDataInterface.selectLanguage == "es") //西班牙语 { this.FruitTypedataGridView.Rows[i].HeaderCell.Value = sFruitMajortArrayEs[i]; //水果大类名称 } else //中文 { this.FruitTypedataGridView.Rows[i].HeaderCell.Value = sFruitMajortArray[i]; //水果大类名称 } this.FruitTypedataGridView[0, i].Value = GlobalDataInterface.globalOut_AnalogDensity.uAnalogDensity[i].ToString("#0.00"); //水果密度 fruittypeconfig = Commonfunction.GetAppSetting(sFruitMajortArray[i]); if (fruittypeconfig == "") { continue; } string[] sFruitSubArray = fruittypeconfig.Split(';'); for (int j = 0; j < sFruitSubArray.Length - 1; j++) { m_FruitType.member[i * ConstPreDefine.MAX_FRUIT_TYPE_SUB_CLASS_NUM + j].iFruitTypeID = i * ConstPreDefine.MAX_FRUIT_TYPE_SUB_CLASS_NUM + j + 1; btempArray = Encoding.Default.GetBytes(sFruitSubArray[j]); Array.Copy(btempArray, m_FruitType.member[i * ConstPreDefine.MAX_FRUIT_TYPE_SUB_CLASS_NUM + j].bFruitName, btempArray.Length); this.FruitTypedataGridView[j + 1, i].Value = sFruitSubArray[j]; } } /*标记已选水果种类*/ fruittypeconfig = Commonfunction.GetAppSetting("已选水果种类"); string[] sFruitSelecttArray = fruittypeconfig.Split(';');//分割已选水果种类 for (int i = 0; i < sFruitSelecttArray.Length - 1; i++) { //string[] tempArray = s.Split(new char[3] { 'c', 'd', 'e' }); //string[] tempArray = sFruitSelecttArray[i].Split('-');//分割ID号 string[] tempArray = sFruitSelecttArray[i].Split(new char[2] { '.', '-' }); //分割ID号 int ID = int.Parse(tempArray[0]); int ColoID = int.Parse(tempArray[1]); int RowIndex = ID - 1 /*/ ConstPreDefine.MAX_FRUIT_TYPE_SUB_CLASS_NUM*/; int ColoumnIndex = ColoID % ConstPreDefine.MAX_FRUIT_TYPE_SUB_CLASS_NUM; this.FruitTypedataGridView[ColoumnIndex, RowIndex].Style.BackColor = Color.Pink; } } catch (Exception ex) { Trace.WriteLine("ProjectSetForm-FruitSet中函数FruitSetInitial出错" + ex); #if REALEASE GlobalDataInterface.WriteErrorInfo("ProjectSetForm-FruitSet中函数FruitSetInitial出错" + ex); #endif } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { //处理未捕获的异常 Add by ChengSk - 20180809 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理 UI线程异常 Add by ChengSk - 20180809 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 Add by ChengSk - 20180809 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandleException); // nLength = Marshal.SizeOf(typeof(stWeightBaseInfo)); #if REALEASE GlobalDataInterface.CreatErorrFile(); #endif // int nLength = Marshal.SizeOf(typeof(stGlobal)); //语言选择功能 GlobalDataInterface.selectLanguage = Common.Commonfunction.GetAppSetting("选择的语言"); //string path; //Add by xcw - 20191031 //string currentPath = System.AppDomain.CurrentDomain.BaseDirectory; //PrintProtocol.logoPathName = currentPath + PrintProtocol.logoPathName; //更改LOGO标签地址(相对地址转绝对地址) //string currentDefaultPath = currentPath + "config\\"; //path = currentDefaultPath + "languagekind.txt"; //Add by xcw - 20191031 //if (!Directory.Exists(currentDefaultPath)) //{ // Directory.CreateDirectory(currentDefaultPath); //} //if (!File.Exists(path)) //{ // FileStream fs = File.Create(path); // fs.Close(); //} //StreamReader sr = new StreamReader(path, Encoding.Default); //string m = sr.ReadToEnd();//显示内容 //m = m.Replace("\r\n", ""); //Add by xcw - 20191031 //sr.Close(); //GlobalDataInterface.selectLanguage = m; //MessageBox.Show(GlobalDataInterface.selectLanguage); if (GlobalDataInterface.selectLanguage == "" || GlobalDataInterface.selectLanguage == "null") //if (true) { LanguageSelectForm languageSelectForm = new LanguageSelectForm(); languageSelectForm.ShowDialog(); } Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GlobalDataInterface.selectLanguage); GlobalDataInterface.selectLanguageIndex = LanguageContainer.LanguageVersionIndex(GlobalDataInterface.selectLanguage); //信息提示框按钮附名称 //MessageBoxManager.OK = "OK"; //MessageBoxManager.No = "No"; //MessageBoxManager.Yes = "Yes"; //MessageBoxManager.Cancel = "Cancel"; //MessageBoxManager.Retry = "Retry"; //MessageBoxManager.Ignore = "Ignore"; //MessageBoxManager.Abort = "Abort"; //MessageBoxManager.Register(); MessageBoxManager.OK = LanguageContainer.ProgramMessageBoxManagerOK[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.No = LanguageContainer.ProgramMessageBoxManagerNo[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Yes = LanguageContainer.ProgramMessageBoxManagerYes[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Cancel = LanguageContainer.ProgramMessageBoxManagerCancel[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Retry = LanguageContainer.ProgramMessageBoxManagerRetry[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Ignore = LanguageContainer.ProgramMessageBoxManagerIgnore[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Abort = LanguageContainer.ProgramMessageBoxManagerAbort[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Register(); ////显示启动界面线程 Thread thSplash = new Thread(new ThreadStart(ShowSplashForm)); thSplash.Priority = ThreadPriority.Normal; thSplash.IsBackground = true; thSplash.Start(); //初始化系统线程 Thread thInitialSysterm = new Thread(new ThreadStart(InitialSysterm)); thInitialSysterm.Priority = ThreadPriority.Highest; thInitialSysterm.IsBackground = true; thInitialSysterm.Start(); thInitialSysterm.Join(); if (m_splashForm != null) { m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.Close(); })); } thSplash.Join(); //模拟测试广播通信代码 正常工作时注释掉 Thread thSendBroadcast = new Thread(new ThreadStart(sendBroadcast)); thSendBroadcast.IsBackground = true; thSendBroadcast.Start(); if (IsSystemContinue) { ////语言选择功能 //GlobalDataInterface.selectLanguage = Common.Commonfunction.GetAppSetting("选择的语言"); //Note by ChengSk - 20180723 代码放到网络连接之前 //if (GlobalDataInterface.selectLanguage == "null") //{ // LanguageSelectForm languageSelectForm = new LanguageSelectForm(); // languageSelectForm.ShowDialog(); //} //Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(GlobalDataInterface.selectLanguage); //GlobalDataInterface.selectLanguageIndex = LanguageContainer.LanguageVersionIndex(GlobalDataInterface.selectLanguage); //数据库配置功能 Add by ChengSk 20140320 ---START--- GlobalDataInterface.currentDatabase = Common.Commonfunction.GetAppSetting("当前数据库"); GlobalDataInterface.dataBaseConn = "data source=" + Common.Commonfunction.GetAppSetting("数据源") + ";database=" + Common.Commonfunction.GetAppSetting("数据库") + ";user="******"用户名") + ";pwd=" + Common.Commonfunction.GetAppSetting("密码"); bool isConnSuccess = false; SqlConnection conn = new SqlConnection(GlobalDataInterface.dataBaseConn); try { conn.Open(); isConnSuccess = true; conn.Close(); //Add 20180919 conn.Dispose(); //Add 20180919 } catch (Exception ex) { isConnSuccess = false; } if (GlobalDataInterface.currentDatabase == "null" || !isConnSuccess) { DatabaseSetForm databaseSetForm = new DatabaseSetForm(); databaseSetForm.ShowDialog(); if (GlobalDataInterface.DatabaseSet) { return; } } GlobalDataInterface.databaseOperation = new DB.DataBaseOperation(); // ---END-- - GlobalDataInterface.mainform = new MainForm(); Application.Run(GlobalDataInterface.mainform); } global.DestroyTCPServerMarsterSocket(); //Add by ChengSk - 20180723 #if REALEASE System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess(); int handleCount = p.HandleCount; //程序的句柄数 Add by ChengSk - 20180906 GlobalDataInterface.WriteErrorInfo("程序即将退出...,当前句柄数量:" + handleCount.ToString()); GlobalDataInterface.CloseErorrFile(); #endif Application.ThreadException -= new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); AppDomain.CurrentDomain.UnhandledException -= new UnhandledExceptionEventHandler(CurrentDomain_UnhandleException); } catch (Exception ex) { Trace.WriteLine("Program中函数Main出错:" + ex + "\n代码定位:" + ex.StackTrace); #if REALEASE System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess(); int handleCount = p.HandleCount; //程序的句柄数 Add by ChengSk - 20180906 GlobalDataInterface.WriteErrorInfo("程序即将退出...,当前句柄数量:" + handleCount.ToString()); GlobalDataInterface.WriteErrorInfo(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "Program中函数Main出错:" + ex + "\n代码定位:" + ex.StackTrace); #endif } }
/// <summary> /// 初始化系统线程 /// </summary> private static void InitialSysterm() { try { //信息提示框按钮附名称 //MessageBoxManager.OK = "OK"; //MessageBoxManager.No = "No"; //MessageBoxManager.Yes = "Yes"; //MessageBoxManager.Cancel = "Cancel"; //MessageBoxManager.Retry = "Retry"; //MessageBoxManager.Ignore = "Ignore"; //MessageBoxManager.Abort = "Abort"; //MessageBoxManager.Register(); MessageBoxManager.OK = LanguageContainer.ProgramMessageBoxManagerOK[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.No = LanguageContainer.ProgramMessageBoxManagerNo[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Yes = LanguageContainer.ProgramMessageBoxManagerYes[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Cancel = LanguageContainer.ProgramMessageBoxManagerCancel[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Retry = LanguageContainer.ProgramMessageBoxManagerRetry[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Ignore = LanguageContainer.ProgramMessageBoxManagerIgnore[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Abort = LanguageContainer.ProgramMessageBoxManagerAbort[GlobalDataInterface.selectLanguageIndex]; MessageBoxManager.Register(); Thread.Sleep(1000); if (m_splashForm != null) { // m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "检查本地IP..."; })); //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "Check the local IP..."; })); m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = LanguageContainer.ProgramMessagebox1Text[GlobalDataInterface.selectLanguageIndex]; })); } //检查IP地址 string hostName = Dns.GetHostName(); IPHostEntry IPEntry = Dns.GetHostEntry(hostName); IPAddress HCIP = IPAddress.Parse(ConstPreDefine.HC_IP_ADDR); string currentIP = ""; //for (int i = 0; i < IPEntry.AddressList.Length; i++) //{ // if (IPEntry.AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) // { // currentIP = IPEntry.AddressList[i].ToString(); // break; // } //} //if (!string.Equals(currentIP, ConstPreDefine.HC_IP_ADDR)) //{ // //MessageBox.Show("IP地址错误或没有网络连接!"); // MessageBox.Show("0x10000001 IP address error or no network!","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); // IsSystemContinue = false; // return; //} //解决多网卡的问题 bool IsExistCorrentIP = false; for (int i = 0; i < IPEntry.AddressList.Length; i++) { if (IPEntry.AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { currentIP = IPEntry.AddressList[i].ToString(); if (string.Equals(currentIP, ConstPreDefine.HC_IP_ADDR)) { IsExistCorrentIP = true; break; } } } if (!IsExistCorrentIP) { //MessageBox.Show("IP地址错误或没有网络连接!"); //MessageBox.Show("0x10000001 IP address error or no network!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("0x10000001 " + LanguageContainer.ProgramMessagebox2Text[GlobalDataInterface.selectLanguageIndex], LanguageContainer.ProgramMessageboxErrorCaption[GlobalDataInterface.selectLanguageIndex], MessageBoxButtons.OK, MessageBoxIcon.Error); IsSystemContinue = false; return; } //建立网络连接 if (m_splashForm != null) { //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "正在建立网络连接..."; })); //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "Establishing network..."; })); m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = LanguageContainer.ProgramMessagebox3Text[GlobalDataInterface.selectLanguageIndex]; })); } global.Init();//网络初始化 Thread.Sleep(1000); //建立数据库连接 // 查询子系统 if (m_splashForm != null) { //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "正在查询子系统..."; })); //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "Checking the Subsystems..."; })); m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = LanguageContainer.ProgramMessagebox4Text[GlobalDataInterface.selectLanguageIndex]; })); } string strSubSystemNum = Commonfunction.GetAppSetting("子系统个数"); GlobalDataInterface.TransmitParam(-1, (int)HC_FSM_COMMAND_TYPE.HC_CMD_DISPLAY_ON, null); if (GlobalDataInterface.SubSystemIsConnected[0] == false) { //MessageBox.Show("子系统1连接失败,请检查连接!"); //MessageBox.Show("0x10000003 Subsystem 1 connection failure,please check the connection!", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error); MessageBox.Show("0x10000003 初始化" + LanguageContainer.ProgramMessagebox5Text[GlobalDataInterface.selectLanguageIndex], LanguageContainer.ProgramMessageboxErrorCaption[GlobalDataInterface.selectLanguageIndex], MessageBoxButtons.OK, MessageBoxIcon.Error); //MessageBox.Show("初始化"); IsSystemContinue = false; return; } if (GlobalDataInterface.ConnectSystemNum == 0) { //MessageBox.Show("连接下位机失败,请检查连接!"); //MessageBox.Show("0x10000002 FSM connection failure,please check the connection!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("0x10000002 " + LanguageContainer.ProgramMessagebox6Text[GlobalDataInterface.selectLanguageIndex], LanguageContainer.ProgramMessageboxErrorCaption[GlobalDataInterface.selectLanguageIndex], MessageBoxButtons.OK, MessageBoxIcon.Error); IsSystemContinue = false; return; } if (GlobalDataInterface.ConnectSystemNum < byte.Parse(strSubSystemNum)) { //DialogResult result = MessageBox.Show("子系统与配置数目不符,是否继续运行?", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); //DialogResult result = MessageBox.Show("0x20001001 Configuration does not match the number of subsystems,whether to continue to run?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); DialogResult result = MessageBox.Show("0x20001001 " + LanguageContainer.ProgramMessagebox7Text[GlobalDataInterface.selectLanguageIndex], LanguageContainer.ProgramMessageboxWarningCaption[GlobalDataInterface.selectLanguageIndex], MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { IsSystemContinue = false; return; } } if (m_splashForm != null) { //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "正在启动..."; })); //m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "Starting..."; })); m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = LanguageContainer.ProgramMessagebox8Text[GlobalDataInterface.selectLanguageIndex]; })); } Thread.Sleep(2000); // m_splashForm.Invoke(new MethodInvoker(delegate { m_splashForm.InitialStatuslabel.Text = "完成"; })); } catch (Exception ex) { Trace.WriteLine("Program中函数InitialSysterm出错" + ex + "\n代码定位:" + ex.StackTrace); #if REALEASE GlobalDataInterface.WriteErrorInfo("Program中函数InitialSysterm出错:" + ex + "\n代码定位:" + ex.StackTrace); #endif } }
/// <summary> /// 处理非UI线程异常 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void CurrentDomain_UnhandleException(object sender, UnhandledExceptionEventArgs e) { #if REALEASE GlobalDataInterface.WriteErrorInfo(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " 5555555 CurrentDomain_UnhandleException: " + e.ExceptionObject.ToString()); #endif }
/// <summary> /// 打印 UI线程异常 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { #if REALEASE GlobalDataInterface.WriteErrorInfo(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " 5555555 Application_ThreadException: " + e.Exception.ToString()); #endif }
/// <summary> /// 远程关机 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Closebutton_Click(object sender, EventArgs e) { //Note by ChengSk - 20191112 //foreach (string item in this.IPMcustomCheckedListBox.CheckedItems) //{ // string[] sArray = item.Split('-'); // string IP = sArray[sArray.Length - 1]; // if (GlobalDataInterface.global_IsTestMode) // { // // int nDstId = Commonfunction.EncodeIPM(i, j); // //GlobalDataInterface.TransmitParam(nDstId, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SHUTDOWN, null); // //网络关闭IPM机器 // ConnectionOptions op = new ConnectionOptions(); // op.Username = "******";//账号 // op.Password = "";//登录密码 // op.Authority = "ntlmdomain:DOMAIN"; // ManagementScope scope = new ManagementScope("\\\\"+IP+"\\root\\cimv2", op); // try // { // scope.Connect(); // ObjectQuery oq = new ObjectQuery("select * from win32_OperatingSystem"); // ManagementObjectSearcher query1 = new ManagementObjectSearcher(scope, oq);//得到WMI控制 // ManagementObjectCollection queryCollection1 = query1.Get(); // foreach (ManagementObject mobj in queryCollection1) // { // string[] str = { "" }; // mobj.InvokeMethod("ShutDown", str); // } // } // catch (Exception ex) // { // } // } //} if (GlobalDataInterface.global_IsTestMode) //Modify by ChengSk - 20191112 { for (int i = 0; i < ConstPreDefine.MAX_SUBSYS_NUM; i++) { for (int j = 0; j < ConstPreDefine.MAX_CHANNEL_NUM; j++) { //if (GlobalDataInterface.globalOut_SysConfig.nChannelInfo[i * ConstPreDefine.MAX_CHANNEL_NUM + j] == 1) if (j < GlobalDataInterface.globalOut_SysConfig.nChannelInfo[i]) //Modify by ChengSk - 20191112 { int nDstId = 0; if (GlobalDataInterface.nVer == 1) //版本号判断 add by xcw 20200604 { nDstId = Commonfunction.EncodeIPMChannel(i, j); } else if (GlobalDataInterface.nVer == 0) { nDstId = Commonfunction.EncodeIPM(i, j); } int nSubsysId = Commonfunction.GetIPMID(nDstId); string strTemp = ConstPreDefine.LC_IP_ADDR_TEMPLATE; string strIP = strTemp + nSubsysId; //得到IPM的IP地址 string strIPName = (nSubsysId - 16).ToString(); //add by xcw 20201225 foreach (string item in this.IPMcustomCheckedListBox.CheckedItems) { string[] sArray = item.Split('-'); string IP = sArray[sArray.Length - 1]; //if (IP == strIP) if (IP == strIPName) { nDstId = Commonfunction.EncodeIPM(i, j); GlobalDataInterface.TransmitParam(nDstId, (int)HC_IPM_COMMAND_TYPE.HC_CMD_SHUTDOWN, null); #if REALEASE GlobalDataInterface.WriteErrorInfo("=> ShutDown to IPM, IP: " + IP + " !"); #endif break; } } } //End if } //End for } //End for } //End if }