// 移除记录仪
        private void btnDelRecFromGroup_Click(object sender, EventArgs e)
        {
            try
            {
                //DialogResult dr = XtraMessageBox.Show("确定移除该记录仪?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                //if (dr == System.Windows.Forms.DialogResult.Yes)
                //{

                List <DevExpress.XtraTreeList.Nodes.TreeListNode> nodes = treeList1.GetAllCheckedNodes();
                foreach (DevExpress.XtraTreeList.Nodes.TreeListNode item in nodes)
                {
                    if (item.Level == 1)
                    {
                        int recID = Convert.ToInt32(item.GetValue("ID"));
                        int gID   = Convert.ToInt32(item.ParentNode.GetValue("Name"));

                        for (int i = 0; i < GlobalValue.recorderList.Count; i++)
                        {
                            if (GlobalValue.recorderList[i].ID == recID)
                            {
                                GlobalValue.recorderList[i].GroupState = 0;
                                NoiseDataBaseHelper.UpdateRecorder(GlobalValue.recorderList[i]);
                                break;
                            }
                        }

                        int query = NoiseDataBaseHelper.DeleteOneRelation(recID, gID);
                        if (query != -1)
                        {
                        }
                    }
                }

                btnDelRecFromGroup.Enabled = false;
                //NoiseRecorderGroup gp = (from temp in GlobalValue.groupList
                //                         where temp.ID == gID
                //                         select temp).ToList()[0];
                //gp.RecorderList = NoiseDataBaseHelper.GetRecordersByGroupId(gp.ID);
                GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                GlobalValue.groupList    = NoiseDataBaseHelper.GetGroups();
                BindTree();
                BindListBox();
                GlobalValue.reReadIdList.Clear();
                //}
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("移除失败:" + ex.Message, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        // 分配记录仪
        private void btnImportRec_Click(object sender, EventArgs e)
        {
            if (treeList1.Selection != null)
            {
                if (treeList1.Selection.Count == 0)
                {
                    return;
                }
                if (treeList1.Selection[0].Level == 1)
                {
                    return;
                }

                if (listBoxRec.Items.Count == 0)
                {
                    XtraMessageBox.Show("当前无记录仪可分配!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (listBoxRec.SelectedItems.Count == 0)
                {
                    XtraMessageBox.Show("请选择需要分配的记录仪!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                NoiseRecorderGroup gp = (from temp in GlobalValue.groupList
                                         where temp.ID == Convert.ToInt32(treeList1.Selection[0].GetValue("Name"))
                                         select temp).ToList()[0];
                if (gp == null)
                {
                    return;
                }

                for (int i = 0; i < listBoxRec.SelectedItems.Count; i++)
                {
                    NoiseRecorder tmp = (from item in GlobalValue.recorderList.AsEnumerable()
                                         where item.ID.ToString() == listBoxRec.SelectedItems[i].ToString()
                                         select item).ToList()[0];

                    tmp.GroupState = 1;
                    NoiseDataBaseHelper.AddRecorderGroupRelation(tmp.ID, gp.ID);
                    NoiseDataBaseHelper.UpdateRecorder(tmp);
                }

                gp.RecorderList          = NoiseDataBaseHelper.GetRecordersByGroupId(gp.ID);
                GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                BindTree();
                BindListBox();
            }
        }
        private void btnImportApply_Click(object sender, EventArgs e)
        {
            NoiseRecorderGroup gp = (from temp in GlobalValue.groupList
                                     where temp.ID == Convert.ToInt32(btnImportRec.Tag)
                                     select temp).ToList()[0];

            for (int i = 0; i < listBoxRec.SelectedItems.Count; i++)
            {
                NoiseRecorder tmp = (from item in GlobalValue.recorderList.AsEnumerable()
                                     where item.ID.ToString() == listBoxRec.SelectedItems[i].ToString()
                                     select item).ToList()[0];

                tmp.GroupState = 1;
                NoiseDataBaseHelper.AddRecorderGroupRelation(tmp.ID, gp.ID);
                NoiseDataBaseHelper.UpdateRecorder(tmp);
            }

            gp.RecorderList          = NoiseDataBaseHelper.GetRecordersByGroupId(gp.ID);
            GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
            BindTree();
            listBoxRec.Items.Clear();
        }
        public override void OnSerialPortNotify(object sender, SerialPortEventArgs e)
        {
            if (e.TransactStatus != TransStatus.Start && e.OptType == SerialPortType.NoiseBatchWrite)
            {
                if (e.TransactStatus == TransStatus.Success)
                {
                    if (OptRecList != null && OptRecList.Count > currentOptRecIndex)
                    {
                        // 更新设置入库
                        int query = NoiseDataBaseHelper.UpdateRecorder(OptRecList[currentOptRecIndex]);
                        if (query != -1)
                        {
                            //XtraMessageBox.Show("噪声记录仪[" + currentRec.ID + "]设置成功!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders();
                            GlobalValue.groupList    = NoiseDataBaseHelper.GetGroups();
                        }
                        else
                        {
                            XtraMessageBox.Show("噪声记录仪[" + OptRecList[currentOptRecIndex].ID + "]数据入库发生错误!", GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                        }

                        if (++currentOptRecIndex < OptRecList.Count)
                        {
                            GlobalValue.NoiseSerialPortOptData.ID = Convert.ToInt16(OptRecList[currentOptRecIndex].ID);
                            GlobalValue.SerialPortMgr.Send(SerialPortType.NoiseBatchWrite);
                        }
                        else
                        {
                            this.Enabled = true;
                            GlobalValue.SerialPortMgr.SerialPortEvent -= new SerialPortHandle(SerialPortNotify);
                            EnableRibbonBar();
                            EnableNavigateBar();
                            HideWaitForm();
                            XtraMessageBox.Show("批量设置噪声记录仪参数成功!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else
                {
                    if (OptRecList != null && OptRecList.Count > currentOptRecIndex)
                    {
                        HideWaitForm();
                        if (DialogResult.Yes == XtraMessageBox.Show("噪声记录仪[" + OptRecList[currentOptRecIndex].ID + "]设置参数失败,是否重试?" + e.Msg, GlobalValue.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                        {
                            GlobalValue.SerialPortMgr.Send(SerialPortType.NoiseBatchWrite);
                        }
                        else
                        {
                            if (++currentOptRecIndex < OptRecList.Count)
                            {
                                GlobalValue.NoiseSerialPortOptData.ID = Convert.ToInt16(OptRecList[currentOptRecIndex].ID);
                                GlobalValue.SerialPortMgr.Send(SerialPortType.NoiseBatchWrite);
                            }
                            else
                            {
                                this.Enabled = true;
                                GlobalValue.SerialPortMgr.SerialPortEvent -= new SerialPortHandle(SerialPortNotify);
                                EnableRibbonBar();
                                EnableNavigateBar();
                                HideWaitForm();
                            }
                        }
                    }
                    else
                    {
                        XtraMessageBox.Show("噪声记录仪设置参数失败!" + e.Msg, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Enabled = true;
                        GlobalValue.SerialPortMgr.SerialPortEvent -= new SerialPortHandle(SerialPortNotify);
                        EnableRibbonBar();
                        EnableNavigateBar();
                        HideWaitForm();
                    }
                }
            }
        }