private void btnAddGroup_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtGroupName.Text) || string.IsNullOrEmpty(txtGroupNote.Text)) { XtraMessageBox.Show("分组名称/分组备注未输入!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } NoiseRecorderGroup newGrp = new NoiseRecorderGroup(); newGrp.ID = NoiseDataBaseHelper.GetGroupID(); newGrp.Name = txtGroupName.Text; newGrp.Remark = txtGroupNote.Text; int query = NoiseDataBaseHelper.AddGroup(newGrp); if (query != -1) { GlobalValue.groupList = NoiseDataBaseHelper.GetGroups(); BindTree(); } else { throw new Exception("数据入库发生错误。"); } } catch (Exception ex) { XtraMessageBox.Show("添加失败:" + ex.Message, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAlterGroupSet_Click(object sender, EventArgs e) { try { NoiseRecorderGroup alterGrp = new NoiseRecorderGroup(); alterGrp.ID = Convert.ToInt32(txtGroupID.Text); alterGrp.Name = txtGroupName.Text; alterGrp.Remark = txtGroupNote.Text; int query = NoiseDataBaseHelper.UpdateGroup(alterGrp); if (query != -1) { GlobalValue.groupList = NoiseDataBaseHelper.GetGroups(); XtraMessageBox.Show("更新成功!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); //LoadGroupList(); BindTree(); } else { throw new Exception("数据入库发生错误。"); } } 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(); } }
/// <summary> /// 从数据库中获取记录仪分组列表 /// </summary> public static List <NoiseRecorderGroup> GetGroups() { try { List <NoiseRecorder> recList = GetRecorders(); List <NoiseRecorderGroup> recGroupList = new List <NoiseRecorderGroup>(); string sql = string.Empty; sql = "SELECT * FROM EN_Group"; DataTable dtGroup = SQLHelper.ExecuteDataTable(sql); if (dtGroup.Rows.Count == 0) { return(recGroupList); //throw new Exception("分组数据为空。"); } for (int i = 0; i < dtGroup.Rows.Count; i++) { NoiseRecorderGroup gp = new NoiseRecorderGroup(); //gp.RecorderList = new List<NoiseRecorder>(); gp.ID = Convert.ToInt32(dtGroup.Rows[i]["GroupId"]); gp.Name = dtGroup.Rows[i]["Name"].ToString(); gp.Remark = dtGroup.Rows[i]["Remark"].ToString(); gp.RecorderList = (from item in recList.AsEnumerable() where item.GroupID == gp.ID select item).ToList(); //sql = "SELECT RecorderId FROM MP_GroupRecorder WHERE GroupId = " + group.ID.ToString(); //DataTable dtGroupRecorder = DbForAccess.GetDataTable(sql); //for (int j = 0; j < recList.Count; j++) //{ // for (int k = 0; k < dtGroupRecorder.Rows.Count; k++) // { // int recID = (int)dtGroupRecorder.Rows[k]["RecorderId"]; // if (recID == recList[j].ID) // gp.RecorderList.Add(recList[j]); // } //} recGroupList.Add(gp); } return(recGroupList); } catch (Exception ex) { throw ex; } }
/// <summary> /// 更新记录仪分组 /// </summary> /// <param name="group">分组对象</param> public static int UpdateGroup(NoiseRecorderGroup group) { try { string sql = string.Empty; int query = 0; sql = string.Format(@"UPDATE EN_Group SET Name = '{0}', Remark = '{1}' WHERE GroupId = {2}", group.Name, group.Remark, group.ID); query = SQLHelper.ExecuteNonQuery(sql); return(query); } catch (Exception) { return(-1); } }
/// <summary> /// 添加分组到数据库 /// </summary> /// <param name="rec">分组对象</param> public static int AddGroup(NoiseRecorderGroup group) { try { string sql = string.Empty; int query = 0; sql = string.Format(@"INSERT INTO EN_Group(GroupId,Name, Remark) VALUES('{0}','{1}','{2}')", group.ID, group.Name, group.Remark); query = SQLHelper.ExecuteNonQuery(sql); return(query); } catch (Exception ex) { throw ex; //return -1; } }
private void gridViewGroupList_RowClick(object sender, RowClickEventArgs e) { GridView gridview = sender as GridView; if (gridview.IsGroupRow(e.RowHandle)) { int id = Convert.ToInt32(gridview.GetGroupRowValue(e.RowHandle)); NoiseRecorderGroup gp = (from item in GlobalValue.groupList where item.ID == id select item).ToList()[0]; BindResult(gp); } else { int id = Convert.ToInt32(gridview.GetRowCellValue(e.RowHandle, "记录仪编号")); NoiseRecorder rec = (from item in GlobalValue.recorderList where item.ID == id select item).ToList()[0]; BindResult(rec); } //simpleButtonAny.Enabled = false; }
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(); }
/// <summary> /// 绑定结果列表 /// </summary> private void BindResult(NoiseRecorderGroup gp) { gridControlResult.DataSource = null; DataTable dt = new DataTable(); ; dt.Columns.Add("记录仪编号"); dt.Columns.Add("幅度"); dt.Columns.Add("频率"); dt.Columns.Add("读取时间"); dt.Columns.Add("漏水状态"); dt.Columns.Add("漏水概率"); for (int i = 0; i < gp.RecorderList.Count; i++) { if (gp.RecorderList[i].Result != null) { NoiseResult re = gp.RecorderList[i].Result; string str = "不漏水"; if (re.IsLeak == 0) { str = "不漏水"; } else if (re.IsLeak == 1) { str = "漏水"; } dt.Rows.Add(new object[] { GlobalValue.recorderList[i].ID, re.LeakAmplitude.ToString(), re.LeakFrequency.ToString(), re.ReadTime.ToString("yyyy-MM-dd HH:mm:ss"), str, (re.LeakProbability * 100).ToString("f1") + "%" }); } } // 绑定数据 MethodInvoker mi = (new MethodInvoker(() => { gridControlResult.DataSource = dt; })); this.Invoke(mi); }
private void btnSaveGroupSet_Click(object sender, EventArgs e) { //new Action(() => //{ Control cl = sender as Control; try { string msg = string.Empty; if (!ValidateRecorderManageInput(out msg)) { throw new Exception(msg); } if (string.IsNullOrEmpty(txtGroupID.Text)) { XtraMessageBox.Show("请选择需要操作的分组", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } NoiseRecorderGroup CurrentGroup = (from tmp in GlobalValue.groupList where tmp.ID == Convert.ToInt32(this.txtGroupID.Text) select tmp).ToList()[0]; if (CurrentGroup != null && CurrentGroup.RecorderList != null && CurrentGroup.RecorderList.Count > 0) { this.Enabled = false; DisableRibbonBar(); DisableNavigateBar(); ShowWaitForm("", "正在进行批量设置..."); Application.DoEvents(); SetStaticItem("正在进行批量设置..."); //this.Enabled = false; //cl.Enabled = false; //short id = 0; OptRecList = CurrentGroup.RecorderList; //foreach (NoiseRecorder alterRec in CurrentGroup.RecorderList) //{ //NoiseRecorder alterRec = OptRecList[currentOptRecIndex]; //id = Convert.ToInt16(alterRec.ID); GlobalValue.NoiseSerialPortOptData = new NoiseSerialPortOptEntity(); //GlobalValue.NoiseSerialPortOptData.ID = id; // 设置记录仪时间 GlobalValue.NoiseSerialPortOptData.dt = this.dateTimePicker.Value; // 设置远传通讯时间 GlobalValue.NoiseSerialPortOptData.ComTime = Convert.ToInt32(txtComTime.Text); // 设置记录时间段 GlobalValue.NoiseSerialPortOptData.colstarttime = Convert.ToInt32(txtRecTime.Text); GlobalValue.NoiseSerialPortOptData.colendtime = Convert.ToInt32(txtRecTime1.Text); // 设置采集间隔 GlobalValue.NoiseSerialPortOptData.Interval = (int)nUpDownSamSpan.Value; // 设置远传功能 if (comboBoxDist.SelectedIndex == 1) { GlobalValue.NoiseSerialPortOptData.RemoteSwitch = true; } else { GlobalValue.NoiseSerialPortOptData.RemoteSwitch = false; } foreach (NoiseRecorder alterRec in OptRecList) { // 设置开关 if (comboBoxEditPower.SelectedIndex == 1) { alterRec.Power = 1; } else if (comboBoxEditPower.SelectedIndex == 0) { alterRec.Power = 0; } alterRec.CommunicationTime = GlobalValue.NoiseSerialPortOptData.ComTime; alterRec.RecordTime = Convert.ToInt32(txtRecTime.Text); alterRec.PickSpan = GlobalValue.NoiseSerialPortOptData.Interval; if (comboBoxDist.SelectedIndex == 1) { alterRec.ControlerPower = 1; } else { alterRec.ControlerPower = 0; } } GlobalValue.NoiseSerialPortOptData.ID = Convert.ToInt16(OptRecList[0].ID); currentOptRecIndex = 0; BeginSerialPortDelegate(); GlobalValue.SerialPortMgr.SerialPortScheduleEvent -= new SerialPortScheduleHandle(SerialPortParm_SerialPortScheduleEvent); GlobalValue.SerialPortMgr.SerialPortScheduleEvent += new SerialPortScheduleHandle(SerialPortParm_SerialPortScheduleEvent); GlobalValue.SerialPortMgr.Send(SerialPortType.NoiseBatchWrite); //// 设置记录时间段 //GlobalValue.Noiselog.WriteStartEndTime(id, Convert.ToInt32(txtRecTime.Text), Convert.ToInt32(txtRecTime1.Text)); //alterRec.RecordTime = Convert.ToInt32(txtRecTime.Text); //// 设置采集间隔 //GlobalValue.Noiselog.WriteInterval(id, (int)nUpDownSamSpan.Value); //alterRec.PickSpan = Convert.ToInt32(nUpDownSamSpan.Value); //// 设置远传通讯时间 //GlobalValue.Noiselog.WriteRemoteSendTime(id, Convert.ToInt32(txtComTime.Text)); //alterRec.CommunicationTime = Convert.ToInt32(txtComTime.Text); //// 设置远传功能 //if (comboBoxDist.SelectedIndex == 1) //{ // GlobalValue.Noiselog.WriteRemoteSwitch(id, true); // alterRec.ControlerPower = 1; // //DistanceController alterCtrl = new DistanceController(); // //alterCtrl.ID = Convert.ToInt32(txtConId.Text); // //alterCtrl.RecordID = alterRec.ID; // //alterCtrl.Port = Convert.ToInt32(txtConPort.Text); // //alterCtrl.IPAdress = txtConAdress.Text; // //NoiseDataBaseHelper.UpdateControler(alterCtrl); //} //else //{ // GlobalValue.Noiselog.WriteRemoteSwitch(id, false); // alterRec.ControlerPower = 0; //} //short[] origitydata = null; //// 设置开关 //if (comboBoxEditPower.SelectedIndex == 1) //{ // GlobalValue.Noiselog.CtrlStartOrStop(id, true, out origitydata); // alterRec.Power = 1; //} //else if (comboBoxEditPower.SelectedIndex == 0) //{ // GlobalValue.Noiselog.CtrlStartOrStop(id, false, out origitydata); // alterRec.Power = 0; //} //// 设置记录仪时间 //GlobalValue.Noiselog.WriteTime(id, this.dateTimePicker.Value); //// 更新设置入库 //int query = NoiseDataBaseHelper.UpdateRecorder(alterRec); //if (query != -1) //{ // ShowDialog("设置成功!", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); // GlobalValue.recorderList = NoiseDataBaseHelper.GetRecorders(); // GlobalValue.groupList = NoiseDataBaseHelper.GetGroups(); //} //else // throw new Exception("数据入库发生错误。"); //} } else { ShowDialog("请选择需要操作的分组", GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //short id = Convert.ToInt16(txtRecID.Text); //NoiseRecorder alterRec = (from item in GlobalValue.recorderList // where item.ID == id // select item).ToList()[0]; //alterRec.ID = Convert.ToInt32(txtRecID.Text); //alterRec.LeakValue = Convert.ToInt32(txtLeakValue.Text); //alterRec.Remark = txtRecNote.Text; //SetStaticItem("当前设置已批量应用到该组设备"); } catch (Exception ex) { ShowDialog("设置失败:" + ex.Message, GlobalValue.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); SetStaticItem("设置失败"); } finally { //EnableRibbonBar(); //EnableNavigateBar(); //HideWaitForm(); //cl.Enabled = true; } //}).BeginInvoke(null, null); }