예제 #1
0
        /// <summary>
        /// 查询设备故障日志
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnDefaultFind_Click(object sender, EventArgs e)
        {
            if (!CStaticClass.CheckPushService())
            {// 检查服务
                return;
            }

            QueryServiceClient proxy = new QueryServiceClient();

            try
            {
                int    nIndex     = this.CboFaultCondition.SelectedIndex;
                string strContent = "所有";
                if (this.TxtFaultContent.Visible && this.TxtFaultContent.Enabled)
                {
                    if (string.IsNullOrEmpty(this.TxtFaultContent.Text))
                    {
                        strContent = string.Empty;
                    }
                    else
                    {
                        strContent = this.TxtFaultContent.Text.Trim();
                    }
                }
                else if (this.CboFaultContent.Visible)
                {
                    if (string.IsNullOrEmpty(this.CboFaultContent.Text))
                    {
                        strContent = string.Empty;
                    }
                    else
                    {
                        strContent = this.CboFaultContent.Text.Trim();
                    }
                }

                if (0 > nIndex || string.IsNullOrEmpty(strContent))
                {
                    MessageBox.Show("查询条件和查询内容不能为空!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                DateTime dtStart = this.DtpFaultStart.Value; // 起始日期
                DateTime dtEnd   = this.DtpFaultEnd.Value;   // 截止日期

                if (0 == nIndex)
                {// 根据库区查询
                    strContent = CStaticClass.ConvertWareHouse(strContent).ToString();
                }

                // 获取所有设备故障日志列表(根据查询条件查询)
                List <CDeviceFaultLogDto> lstLogDto = proxy.GetDeviceFaultLogListByContent(nIndex, dtStart, dtEnd, strContent);

                //// 根据查询条件查询
                //switch (nIndex)
                //{
                //    case 0:// 根据库区查询
                //        {
                //            lstLogDto = lstLogDto.FindAll(s => CompareDateTime(s.time, dtStart, dtEnd) && CStaticClass.ConvertWareHouse(s.warehouse) == strContent);
                //            break;
                //        }
                //    case 1:// 根据设备号查询
                //        {
                //            lstLogDto = lstLogDto.FindAll(s => CompareDateTime(s.time, dtStart, dtEnd) && s.devicecode.ToString() == strContent);
                //            break;
                //        }
                //    case 2:// 根据故障描述
                //        {
                //            lstLogDto = lstLogDto.FindAll(s => CompareDateTime(s.time, dtStart, dtEnd) && s.faultdescp.Contains(strContent));
                //            break;
                //        }
                //    case 3:// 根据操作员
                //        {
                //            lstLogDto = lstLogDto.FindAll(s => CompareDateTime(s.time, dtStart, dtEnd) && s.optcode == strContent);
                //            break;
                //        }
                //    default:
                //        {
                //            lstLogDto = lstLogDto.FindAll(s => CompareDateTime(s.time, dtStart, dtEnd));
                //            break;
                //        }
                //}

                m_lstDeviceFaultLog      = lstLogDto;
                this.DgvFault.DataSource = new BindingList <CDeviceFaultLogDto>(lstLogDto);
                if (null == lstLogDto || 0 == lstLogDto.Count)
                {
                    MessageBox.Show("抱歉,没有找到符合条件的记录!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            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();
        }