Example #1
0
        /// <summary>
        /// 更新设备故障颜色
        /// </summary>
        /// <param name="tabPage"></param>
        /// <param name="nWareHouse"></param>
        /// <param name="nDeviceID"></param>
        private void UpdateFaultColor(TabPage tabPage, int nWareHouse, int nDeviceID)
        {
            if (!CStaticClass.GetPushServiceConnectFlag())
            {// 服务器通道断开时
                return;
            }

            QueryServiceClient proxy = new QueryServiceClient();
            //try
            //{
            // 根据库号和设备号获取所有故障列表(除内容为“备用”)
            List <CarLocationPanelLib.QueryService.CDeviceFaultDto> lstDeviceFault = proxy.GetDeviceFault(nWareHouse, nDeviceID, "备用");

            if (null == lstDeviceFault)
            {
                //无状态
                MessageBox.Show("无状态", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            foreach (Control label in tabPage.Controls)
            {
                int nPLCAddr;
                int.TryParse(label.Name.Substring(1), out nPLCAddr);
                CarLocationPanelLib.QueryService.CDeviceFaultDto deviceFault = lstDeviceFault.Find(a => a.faultaddress == nPLCAddr);

                if (null != deviceFault)
                {
                    switch (deviceFault.color)
                    {
                    case 4:
                        label.BackColor = Color.Cyan;
                        break;

                    case 1:
                        label.BackColor = Color.Red;
                        break;

                    case 2:
                        label.BackColor = Color.Yellow;
                        break;

                    case 3:
                        label.BackColor = Color.Green;
                        break;

                    default:
                        label.BackColor = Color.LightSkyBlue;
                        break;
                    }
                }
                else
                {
                    label.BackColor = Color.LightSkyBlue;
                }
            }
            //}
            //catch (TimeoutException)
            //{
            //    MessageBox.Show("The service operation timed out. ", "超时", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (FaultException exception)
            //{
            //    MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "SOAP错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (CommunicationException exception)
            //{
            //    MessageBox.Show("There was a communication problem. " + CStaticClass.GetExceptionInfo(exception), "通信错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (Exception exception)
            //{
            //    MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "应用程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            proxy.Close();
        }
Example #2
0
        /// <summary>
        /// 设置设备TabPage布局
        /// </summary>
        /// <param name="tabPage"></param>
        /// <param name="nWareHouse"></param>
        /// <param name="nDeviceID"></param>
        private void SetTabPageLayout(TabPage tabPage, int nWareHouse, int nDeviceID)
        {
            if (!CStaticClass.GetPushServiceConnectFlag())
            {// 服务器通道断开时
                return;
            }

            QueryServiceClient proxy = new QueryServiceClient();
            //try
            //{
            int nLabelWidth = CStaticClass.ConfigFaultLabelWidth();
            int nLabelHight = CStaticClass.ConfigFaultLabelHeight();
            int gap         = CStaticClass.ConfigMinGap();
            int nHeight     = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - 6 * gap;
            int nRowCount   = (nHeight - 2 * gap) / (nLabelHight + gap) - 1;

            //
            // tabPage
            //
            tabPage.Location = new System.Drawing.Point(0, 0);
            tabPage.Padding  = new System.Windows.Forms.Padding(3);
            tabPage.UseVisualStyleBackColor = true;
            tabPage.BackColor = System.Drawing.SystemColors.Control;

            // 根据库号和设备号获取所有故障列表(除内容为“备用”)
            List <CarLocationPanelLib.QueryService.CDeviceFaultDto> lstDeviceFault = proxy.GetDeviceFault(nWareHouse, nDeviceID, "备用");

            for (int i = 0; i < lstDeviceFault.Count; i++)
            {
                CarLocationPanelLib.QueryService.CDeviceFaultDto deviceFault = lstDeviceFault[i];

                if (null == deviceFault)
                {
                    continue;
                }

                int row    = i % nRowCount;
                int column = i / nRowCount;
                //
                // label
                //
                int   nx    = column == 0 ? gap : column * nLabelWidth + (column + 1) * gap;
                int   ny    = row == 0 ? gap : row * nLabelHight + (row + 1) * gap;
                Label label = new Label();
                label.Name      = "L" + deviceFault.faultaddress;
                label.BackColor = System.Drawing.Color.LightSkyBlue;
                label.Location  = new System.Drawing.Point(nx, ny);
                label.Size      = new System.Drawing.Size(nLabelWidth, nLabelHight);
                label.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
                label.Text      = deviceFault.faultdescp;
                m_toolTip.SetToolTip(label, deviceFault.faultdescp);
                tabPage.Controls.Add(label);

                if (this.TabDeviceFault.Width < nx + nLabelWidth + gap)
                {
                    this.TabDeviceFault.Width = nx + nLabelWidth + gap;
                    //this.ClientSize = this.TabDeviceFault.Size;
                }

                switch (deviceFault.color)
                {
                case 4:
                    label.BackColor = Color.Cyan;
                    break;

                case 1:
                    label.BackColor = Color.Red;
                    break;

                case 2:
                    label.BackColor = Color.Yellow;
                    break;

                case 3:
                    label.BackColor = Color.Green;
                    break;

                default:
                    label.BackColor = Color.LightSkyBlue;
                    break;
                }
            }
            //}
            //catch (TimeoutException)
            //{
            //    MessageBox.Show("The service operation timed out. ", "超时", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (FaultException exception)
            //{
            //    MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "SOAP错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (CommunicationException exception)
            //{
            //    MessageBox.Show("There was a communication problem. " + CStaticClass.GetExceptionInfo(exception), "通信错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //catch (Exception exception)
            //{
            //    MessageBox.Show(CStaticClass.GetExceptionInfo(exception), "应用程序异常", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            proxy.Close();
        }