예제 #1
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);
            }
        }
예제 #2
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();
                }
            }
        }