/// <summary>
        /// 数据绑定
        /// </summary>
        private void DataBinding()
        {
            txtRecID.Text    = Recorder.ID.ToString();
            txtComTime.Text  = Recorder.CommunicationTime.ToString();
            txtRecNum.Text   = Recorder.RecordNum.ToString();
            txtRecTime.Text  = Recorder.RecordTime.ToString();
            txtRecTime1.Text = (Recorder.RecordTime + (Recorder.RecordNum * Recorder.PickSpan / 60)).ToString();
            txtPickSpan.Text = Recorder.PickSpan.ToString();
            txtRemark.Text   = Recorder.Remark;

            double max_amp, max_frq, min_amp, min_frq, leak_amp, leak_frq;

            NoiseDataHandler.IsLeak3(data.Amplitude, data.Frequency, Recorder.LeakValue, out max_amp, out max_frq, out min_amp, out min_frq, out leak_amp, out leak_frq);

            //double maxAmp = data.Amplitude.ToList().Max();
            //double minAmp = data.Amplitude.ToList().Min();
            //double maxHz = data.Frequency.ToList().Max();
            //double minHz = data.Frequency.ToList().Min();

            txtMaxNoise.Text    = max_amp.ToString();
            txtMinNoise.Text    = min_amp.ToString();
            txtMaxHz.Text       = max_frq.ToString();
            txtMinHz.Text       = min_frq.ToString();
            txtNum.Text         = data.UploadFlag.ToString();
            txtEnergyValue.Text = Recorder.Result.EnergyValue.ToString("f2");

            txtLeakNoise.Text = leak_amp.ToString(); // Recorder.Result.LeakAmplitude.ToString();
            txtLeakHz.Text    = leak_frq.ToString(); // Recorder.Result.LeakFrequency.ToString();

            if (Recorder.Result.IsLeak == 1)
            {
                //errorProvider.SetError(txtLeakNoise, "漏水!");
                //errorProvider.BlinkStyle = ErrorBlinkStyle.AlwaysBlink;

                PicBox.Visible = true;
                if (Settings.Instance.GetString(SettingKeys.LeakVoice) != string.Empty)
                {
                    SoundPlayer player = new SoundPlayer();
                    player.PlayLooping();
                }

                t_animation = new Thread(new ThreadStart(EnableLeak_animation));
                t_animation.Start();
            }
            else
            {
                PicBox.Visible = false;
            }
        }
Example #2
0
        private void btnReadFromFold_Click(object sender, EventArgs e)
        {
            //if (!Regex.IsMatch(txtID.Text, @"^\d+$"))
            //{
            //    XtraMessageBox.Show("请输入一个记录仪ID!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    txtID.Focus();
            //    return;
            //}

            if (!CheckFileExist())
            {
                if (DialogResult.Yes == XtraMessageBox.Show("请将原始数据文件(txt)放入路径:" + OriginalFilePath + ",是否打开目录?", GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    btnOpenFold_Click(null, null);
                }
                return;
            }


            List <int> readIdList = new List <int>(); // 需要读取的ID列表
            //readIdList.Add(Convert.ToInt32(txtID.Text));
            bool isError = false;

            for (int j = 0; j < selectList.Count; j++)
            {
                if (!readIdList.Contains(selectList[j].ID))
                {
                    readIdList.Add(selectList[j].ID);
                }
            }
            if (selectList.Count != 0)
            {
                List <NoiseRecorder> lstSelecttmp = new List <NoiseRecorder>();
                lstSelecttmp.AddRange(selectList.OrderBy(a => a.ID));
                selectList = lstSelecttmp;

                btnReadFromFold.Enabled = false;
                List <NoiseData>   dataList   = new List <NoiseData>();
                List <NoiseResult> resultList = new List <NoiseResult>();
                GlobalValue.Noiselog.ValueChanged -= new ReadDataChangedEventHandler(log_ValueChanged);
                GlobalValue.Noiselog.ValueChanged += new ReadDataChangedEventHandler(log_ValueChanged);

                NoiseDataHandler.FourierData.Clear();
                isReading = true;
                new Action(() =>
                {
                    try
                    {
                        foreach (var id in readIdList)
                        {
                            try
                            {
                                DisableRibbonBar();
                                DisableNavigateBar();
                                Thread.Sleep(1000);
                                this.Invoke(new MethodInvoker(() =>
                                {
                                    for (int i = 0; i < gridViewGroupList.RowCount; i++)
                                    {
                                        if (gridViewGroupList.GetRowCellValue(i, "选择") != null)
                                        {
                                            if (gridViewGroupList.GetRowCellValue(i, "记录仪编号").ToString() == id.ToString())
                                            {
                                                gridViewGroupList.SetRowCellValue(i, "读取进度", 0);
                                                this.rowHandle = i;
                                                break;
                                            }
                                        }
                                    }
                                }));

                                Dictionary <short, short[]> result = new Dictionary <short, short[]>();
                                SetStaticItem(string.Format("正在读取记录仪{0}...", id));
                                ShowWaitForm("", string.Format("正在读取记录仪{0}...", id));
                                short[] arr = GetDataFromFiles();
                                if (arr == null || arr.Length == 0)
                                {
                                    throw new ArgumentNullException("数据获取失败");
                                }
                                result.Add((short)id, arr);
                                string TestPath = Application.StartupPath + @"\Data\记录仪{0}\";
                                string errmsg   = NoiseDataHandler.CallbackReaded(result, selectList, TestPath, ref GlobalValue.recorderList);
                                if (!string.IsNullOrEmpty(errmsg))
                                {
                                    ShowDialog("记录仪" + id + "分析数据发生错误,errmsg:" + errmsg, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    isError = true;
                                    return;
                                }
                                GlobalValue.reReadIdList.Remove(id);

                                NoiseRecorder gpRec = (from item in GlobalValue.recorderList.AsEnumerable()
                                                       where item.ID == id
                                                       select item).ToList()[0];

                                dataList.Add(gpRec.Data);
                                resultList.Add(gpRec.Result);

                                BindResult(gpRec);
                            }
                            catch (TimeoutException)
                            {
                                ShowDialog("记录仪" + id + "读取超时!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                isError = true;
                            }
                            catch (ArgumentNullException)
                            {
                                ShowDialog("记录仪" + id + "数据为空!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                isError = true;
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        isReading = false;
                        SetStaticItem("数据读取完成");
                        btnReadFromFold.Enabled = true;
                        HideWaitForm();
                        EnableRibbonBar();
                        EnableNavigateBar();

                        if (dataList.Count != 0)
                        {
                            DialogResult dr = XtraMessageBox.Show("已成功读取" + dataList.Count + "条数据,是否保存到数据库?", GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == System.Windows.Forms.DialogResult.Yes)
                            {
                                for (int i = 0; i < dataList.Count; i++)
                                {
                                    NoiseDataBaseHelper.AddNoiseData(dataList[i]);
                                    NoiseDataBaseHelper.AddNoiseResult(resultList[i]);
                                    GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                                    GlobalValue.groupList    = NoiseDataBaseHelper.GetGroups();
                                }
                            }
                        }
                    }
                }).BeginInvoke(null, null);
            }
            else
            {
                XtraMessageBox.Show("请勾选需要读取的记录仪!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #3
0
        private void btnSelect1_Click(object sender, EventArgs e)
        {
            openFileDialog.FileName = "选择需要分析的文件";
            DialogResult dr = openFileDialog.ShowDialog();
            StreamReader sr = null;
            StreamWriter sw = null;

            if (dr == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    List <double> s  = new List <double>();
                    double[]      db = null;
                    sr = new StreamReader(openFileDialog.FileName);
                    sw = new StreamWriter(string.Format(GlobalValue.TestPath + @"转换前数据{0}.txt", 99 + 1));
                    //string[] str = sr.ReadLine().Split('\t');
                    //foreach (string item in str)
                    //{
                    //    double a = Convert.ToDouble(item);
                    //    s.Add(a);
                    //    sw.WriteLine(a);
                    //}
                    //sw.Flush();
                    while (!sr.EndOfStream)
                    {
                        string str = sr.ReadLine();
                        double a   = Convert.ToDouble(str);
                        s.Add(a);
                        sw.WriteLine(a);
                    }
                    sw.Flush();
                    sw.Close();

                    NoiseDataHandler.num = Convert.ToInt32(txtSize.Text);
                    NoiseDataHandler.AmpCalc(99, s.ToArray(), ref db);

                    List <double> d = new List <double>();
                    sr = new StreamReader(string.Format(GlobalValue.TestPath + "转换后数据{0}.txt", 99 + 1));
                    while (!sr.EndOfStream)
                    {
                        string str1 = sr.ReadLine();
                        if (str1 != string.Empty)
                        {
                            d.Add(Convert.ToDouble(str1));
                        }
                    }
                    sr.Close();
                    data = d;
                    winChartViewer1.updateViewPort(true, false);
                    if (!winChartViewer1.Visible)
                    {
                        winChartViewer1.Visible = true;
                    }
                }
                catch (Exception)
                {
                    XtraMessageBox.Show("文件格式不正确!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                finally
                {
                    if (sr != null)
                    {
                        sr.Close();
                    }
                    if (sw != null)
                    {
                        sw.Close();
                    }
                }
            }
        }
Example #4
0
        public override void OnSerialPortNotify(object sender, SerialPortEventArgs e)
        {
            if (e.TransactStatus != TransStatus.Start && e.OptType == SerialPortType.NoiseReadData)
            {
                string message = string.Empty;
                if (e.Tag != null)
                {
                    message = e.Tag.ToString();
                }

                this.Enabled                  = true;
                simpleButtonRead.Enabled      = true;
                simpleButtonSelectAll.Enabled = true;
                simpleButtonUnSelect.Enabled  = true;
                HideWaitForm();
                EnableRibbonBar();
                EnableNavigateBar();

                GlobalValue.SerialPortMgr.SerialPortEvent -= new SerialPortHandle(SerialPortNotify);
                if (e.TransactStatus == TransStatus.Success)
                {
                    Dictionary <short, short[]> result = new Dictionary <short, short[]>();
                    result.Add(GlobalValue.NoiseSerialPortOptData.ID, (short[])e.Tag);
                    string TestPath = Application.StartupPath + @"\Data\记录仪{0}\";
                    string errmsg   = NoiseDataHandler.CallbackReaded(result, selectList, TestPath, ref GlobalValue.recorderList);
                    if (!string.IsNullOrEmpty(errmsg))
                    {
                        ShowDialog("分析数据发生错误,errmsg:" + errmsg, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    GlobalValue.reReadIdList.Remove(GlobalValue.NoiseSerialPortOptData.ID);

                    NoiseRecorder gpRec = (from item in GlobalValue.recorderList.AsEnumerable()
                                           where item.ID == GlobalValue.NoiseSerialPortOptData.ID
                                           select item).ToList()[0];

                    dataList.Add(gpRec.Data);
                    resultList.Add(gpRec.Result);

                    BindResult(gpRec);

                    if (ReadIdList != null && ReadIdList.Count > 0)
                    {
                        ReadData(Convert.ToInt16(ReadIdList.Dequeue()));
                    }
                    else
                    {
                        if (dataList.Count != 0)
                        {
                            DialogResult dr = XtraMessageBox.Show("已成功读取" + dataList.Count + "条数据,是否保存到数据库?", GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == System.Windows.Forms.DialogResult.Yes)
                            {
                                for (int i = 0; i < dataList.Count; i++)
                                {
                                    NoiseDataBaseHelper.AddNoiseData(dataList[i]);
                                    NoiseDataBaseHelper.AddNoiseResult(resultList[i]);
                                    GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                                    GlobalValue.groupList    = NoiseDataBaseHelper.GetGroups();
                                }
                            }
                        }
                    }
                    gridViewResultList.RefreshData();
                }
                else
                {
                    XtraMessageBox.Show("读取数据失败!" + e.Msg, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (ReadIdList != null && ReadIdList.Count > 0)
                    {
                        ReadData(Convert.ToInt16(ReadIdList.Dequeue()));
                    }
                    else
                    {
                        if (dataList.Count != 0)
                        {
                            DialogResult dr = XtraMessageBox.Show("已成功读取" + dataList.Count + "条数据,是否保存到数据库?", GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == System.Windows.Forms.DialogResult.Yes)
                            {
                                for (int i = 0; i < dataList.Count; i++)
                                {
                                    NoiseDataBaseHelper.AddNoiseData(dataList[i]);
                                    NoiseDataBaseHelper.AddNoiseResult(resultList[i]);
                                    GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                                    GlobalValue.groupList    = NoiseDataBaseHelper.GetGroups();
                                }
                            }
                        }
                    }
                    gridViewResultList.RefreshData();
                }
            }
        }