/// <summary> /// 删除选择项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { //if (MessageBox.Show("是否删除该传感器?") == DialogResult.OK) if (MessageBox.Show("确定要删除该传感器吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (this.listView1.SelectedItems[0].Tag is Sensor) { var selectSensor = this.listView1.SelectedItems[0].Tag as Sensor; if (selectSensor.Code == "collect-facility-WenDu" || selectSensor.Code == "collect-facility-ShiDu" || selectSensor.Code == "collect-facility-GuangZhao") { MessageBox.Show("温湿光设备的传感器不能删除"); return; } var id = selectSensor.ID; List <SensorDeviceUnit> sensorDeviceUnitList = SensorDeviceUnit.FindAllBySensorId(id); if (sensorDeviceUnitList != null) { MessageBox.Show("该传感器已经被使用,不能删除"); return; } Sensor.Delete(selectSensor); this.InitListView(); this.sensorId = 0; } } } }
/// <summary> /// 初始化传感器设备列表 /// </summary> private void InitCollectDeviceListView() { this.listView2.Items.Clear(); List <SensorDeviceUnit> collectDeviceList = SensorDeviceUnit.FindAll(); foreach (var collectDevice in collectDeviceList) { var strings = new string[] { collectDevice.ModularDeviceName, collectDevice.Name }; var listViewItem = new ListViewItem(strings); listViewItem.Tag = collectDevice; this.listView2.Items.Add(listViewItem); } }
/// <summary> /// 获取节点属性 /// </summary> /// <param name="id"> /// </param> private void GetProperity(int id, string tag) { //this.advPropertyGrid1.SelectedObject = null; if (tag.Equals("SensorDeviceUnit")) { var s = SensorDeviceUnit.FindByID(id); s.ModularDevices = s.ModularDeviceName; s.Sensors = s.SensorName; this.advPropertyGrid1.SelectedObject = Mapper.Map <SensorDeviceUnitDto>(s); selectObj = new Tuple <IEntity>(s); //var sensor = Sensor.FindByID(s.SensorId); //PropertyHandle.SetPropertyReadOnly(s,"Remark", true); } else if (tag.Equals("ControlDeviceUnit")) { var c = ControlDeviceUnit.FindByID(id); c.ModularDevices = c.ModularDeviceName; c.DeviceTypes = c.DeviceTypeName; c.ControlJobTypes = c.ControlJobTypeName; c.RelayTypes = c.RelayTypeName; this.advPropertyGrid1.SelectedObject = Mapper.Map <ControlDeviceUnitDto>(c); selectObj = new Tuple <IEntity>(c); } else if (tag.Equals("Camera")) { var c = Camera.FindByID(id); this.advPropertyGrid1.SelectedObject = Mapper.Map <CameraDto>(c); selectObj = new Tuple <IEntity>(c); } else if (tag.Equals("ShowDevice")) { var sd = ShowDevice.FindByID(id); sd.ShowDeviceTypes = sd.ShowDeviceTypeName; sd.CommunicateDevices = sd.CommunicateDeviceName; this.advPropertyGrid1.SelectedObject = Mapper.Map <ShowDeviceDto>(sd);; selectObj = new Tuple <IEntity>(sd); } else if (tag.Equals("Facility")) { var fac = Facility.FindByID(id); fac.Farms = fac.FarmName; fac.FacilityTypes = fac.FacilityTypeName; this.advPropertyGrid1.SelectedObject = Mapper.Map <FacilityDto>(fac);; selectObj = new Tuple <IEntity>(fac); } }
/// <summary> /// 初始化传感器设备(采集设备) /// </summary> private void InitSensorDeviceUnit() { List <SensorDeviceUnit> sensorDeviceUnitList = SensorDeviceUnit.FindAll(); //foreach (var sensorDeviceUnit in sensorDeviceUnitList) //{ // this.cbSensorDeviceUnit.Items.Add(sensorDeviceUnit); // this.cbSensorDeviceUnit.DisplayMember = sensorDeviceUnit.ID.ToString(); // this.cbSensorDeviceUnit.ValueMember = sensorDeviceUnit.Name; //} if (sensorDeviceUnitList.Count > 0) { this.cbSensorDeviceUnit.DataSource = sensorDeviceUnitList; this.cbSensorDeviceUnit.DisplayMember = "Name"; this.cbSensorDeviceUnit.ValueMember = "ID"; } }
/// <summary> /// 初始化采集设备列表 /// </summary> private void InitCollectDeviceListView() { this.listView1.Items.Clear(); List <SensorDeviceUnit> collectDeviceList = SensorDeviceUnit.FindAll(); foreach (var collectDevice in collectDeviceList) { var strings = new string[] { collectDevice.ID.ToString(), collectDevice.Name, collectDevice.ModularDeviceName.ToString(), collectDevice.SensorName.ToString(), collectDevice.Function.ToString(), collectDevice.OriginalValue.ToString(), collectDevice.ShowValue, collectDevice.ProcessedValue.ToString(), collectDevice.UpdateTime.ToString(), collectDevice.RegisterSize.ToString(), collectDevice.RegisterAddress.ToString(), collectDevice.Location }; var listViewItem = new ListViewItem(strings); listViewItem.Tag = collectDevice; this.listView1.Items.Add(listViewItem); } }
private void advTreeData_DragDrop(object sender, DragEventArgs e) { //var item = e.Data.GetData(e.Data.GetFormats()[0]); if (status) { var location = this.advTreeData.PointToClient(new Point(e.X, e.Y)); var node = this.advTreeData.GetNodeAt(location.X, location.Y); if (node != null && node.Tag.Equals(parent)) { #region 采集设备 if (parent.Equals("SensorDeviceUnit")) { var device = SensorDeviceUnit.FindByID(dragId); var faciliy = node.Parent.Tag as Facility; if (MessageBox.Show("确定要将该设备移动到该设施下吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { var dbList = FacilitySensorDeviceUnit.FindAllByFacilityIdAndCollectDeviceId(faciliy.ID, device.ID); if (dbList == null || dbList.Count == 0) { var fas = new FacilitySensorDeviceUnit() { FacilityID = faciliy.ID, SensorDeviceUnitID = device.ID }; fas.Code1 = fas.GetCode1(); int i = fas.Insert(); if (i != 0) { FacilitySensorDeviceUnit.DeleteByFacilityAndSensorDeviceunit(facId, device.ID);//删除原有关系 } } else { var fas = dbList[0]; if (!(fas.Code1 + "").StartsWith(faciliy.Code1)) { fas.Code1 = fas.GetCode1(); fas.Update(); } } } } #endregion #region 控制设备 if (parent.Equals("ControlDeviceUnit")) { var device = ControlDeviceUnit.FindByID(dragId); var faciliy = node.Parent.Tag as Facility; if (MessageBox.Show("确定要将该设备移动到该设施下吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { var dbList = FacilityControlDeviceUnit.FindAllByFacilityIdAndControlDeviceGroupNum(faciliy.ID, device.GroupNum); if (dbList == null || dbList.Count == 0) { var fas = new FacilityControlDeviceUnit() { FacilityID = faciliy.ID, ControlDeviceUnitGroupNum = device.GroupNum }; fas.Code1 = fas.GetCode1(); int i = fas.Insert(); if (i != 0) { FacilityControlDeviceUnit.DeleteByFacilityAndControlDeviceunGroupNum(facId, device.GroupNum);//删除原有关系 } } else { var fas = dbList[0]; if (!(fas.Code1 + "").StartsWith(faciliy.Code1)) { fas.Code1 = fas.GetCode1(); fas.Update(); } } InitData(); } } #endregion #region 视频设备 if (parent.Equals("Camera")) { var device = Camera.FindByID(dragId); var faciliy = node.Parent.Tag as Facility; if (MessageBox.Show("确定要将该设备移动到该设施下吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { var dbList = FacilityCamera.FindAllByFacilityIdAndCameraId(faciliy.ID, device.ID); if (dbList == null || dbList.Count == 0) { var fas = new FacilityCamera() { FacilityID = faciliy.ID, CameraID = device.ID }; fas.Code1 = fas.GetCode1(); int i = fas.Insert(); if (i != 0) { FacilityCamera.GetDeviceByFacilityIdAndCameraId(facId, device.ID);//删除原有关系 } } else { var fas = dbList[0]; if (!(fas.Code1 + "").StartsWith(faciliy.Code1)) { fas.Code1 = fas.GetCode1(); fas.Update(); } } InitData(); } } #endregion } } else { return; } InitData(); }
private void btnSave_Click(object sender, EventArgs e) { if (this.txtName.Text.Trim().IsNullOrWhiteSpace()) { MessageBox.Show("名称不能为空,请输入"); this.txtName.Focus(); return; } //if (this.cbModularDeviceId.DisplayMember.Equals("")) //{ // MessageBox.Show("变送器不能为空,请输入"); // this.cbModularDeviceId.Focus(); // return; //} //if (this.cbSensorId.DisplayMember.Equals("")) //{ // MessageBox.Show("传感器不能为空,请输入"); // this.cbSensorId.Focus(); // return; //} //if (this.txtFunction.Text == null) //{ // MessageBox.Show("功能码不能为空"); // this.txtFunction.Focus(); // return; //} #region 获取所有选中的显示数据 //List<ShowData> showDataList = (from item in this.lstShowData.Items.Cast<ListViewItem>() where item.Checked select item.Tag as ShowData).ToList();//显示数据 var showDataList = new List <ShowData>(); var showDataList1 = new List <ShowData>(); foreach (ListViewItem item in this.lstShowData.Items) { if (item.Checked == false) { var showData = item.Tag as ShowData; //未选中的显示数据 showDataList1.Add(showData); } else { showDataList = (from i in this.lstShowData.Items.Cast <ListViewItem>() where i.Checked select i.Tag as ShowData) .ToList(); //选中的显示数据 } } #endregion 获取所有选中的显示数据 if (this.collectDeviceId != 0) { try { // 更新 var collectDevice = new SensorDeviceUnit { ID = this.collectDeviceId, Name = this.txtName.Text.Trim(), ModularDeviceID = Convert.ToInt32(this.cbModularDevice.SelectedValue), SensorId = Convert.ToInt32(this.cbSensor.SelectedValue), Function = Convert.ToInt32(this.txtFunction.Text.Trim()), OriginalValue = Convert.ToInt32(this.txtOriginalValue.Text.Trim()), ShowValue = this.txtShowValue.Value.ToString(), ProcessedValue = Convert.ToDecimal(this.txtProccessedValue.Text.Trim()), //UpdateTime = DateTime.Now, RegisterSize = Convert.ToInt32(this.txtRegisterSize.Text.Trim()), RegisterAddress = Convert.ToInt32(this.txtRegisterAddress.Text.Trim()), Location = this.txtLocation.Text.Trim() //Remark = this.txtRemark.Text.Trim() }; SensorDeviceUnit.Update(collectDevice); //更新显示数据 foreach (var item in showDataList) { item.SensorDeviceUnitID = this.collectDeviceId; ShowData.Update(item); } //foreach (var item in showDataList1) //{ // item.SensorDeviceUnitID = this.collectDeviceId; // ShowData.Delete(item); //} this.InitShowDataListView(); MessageBox.Show("更新成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("更新失败"); } } else { try { // 保存 var collectDevice = new SensorDeviceUnit { //ID = this.collectDeviceId, Name = this.txtName.Text.Trim(), ModularDeviceID = Convert.ToInt32(this.cbModularDevice.SelectedValue), SensorId = Convert.ToInt32(this.cbSensor.SelectedValue), Function = Convert.ToInt32(this.txtFunction.Text.Trim()), OriginalValue = Convert.ToInt32(this.txtOriginalValue.Text.Trim()), ShowValue = this.txtShowValue.Value.ToString(), ProcessedValue = Convert.ToDecimal(this.txtProccessedValue.Text.Trim()), //UpdateTime = DateTime.Now, RegisterSize = Convert.ToInt32(this.txtRegisterSize.Text.Trim()), RegisterAddress = Convert.ToInt32(this.txtRegisterAddress.Text.Trim()), Location = this.txtLocation.Text.Trim() ////Remark = this.txtRemark.Text.Trim() }; SensorDeviceUnit.Save(collectDevice); ////保存显示数据 //foreach (var item in showDataList) //{ // ShowData.Save(item); //} this.InitShowDataListView(); MessageBox.Show("保存成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("保存失败"); } } this.InitCollectDeviceListView(); }
private void listView1_SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { if (this.listView1.SelectedItems[0].Tag is ModularDevice) { //this.txtId.Text = (this.listView1.SelectedItems[0].Tag as ModularDevice).ID.ToString(); modularDeviceId = (this.listView1.SelectedItems[0].Tag as ModularDevice).ID; this.txtName.Text = this.listView1.SelectedItems[0].SubItems[1].Text; this.cbProtocalType.Text = this.listView1.SelectedItems[0].SubItems[2].Text; this.cbCommunicateDevice.Text = this.listView1.SelectedItems[0].SubItems[3].Text; this.txtAddress.Text = this.listView1.SelectedItems[0].SubItems[4].Text; //this.cbOnlineStatus.Text = this.listView1.SelectedItems[0].SubItems[5].Text; this.rbtOnlineStatus.Checked = Convert.ToBoolean(this.listView1.SelectedItems[0].SubItems[5].Text); //if (this.rbtOnlineStatus.Checked == true) //{ // this.rbtOnlineStatus1.Checked = false; //} //else //{ // this.rbtOnlineStatus1.Checked = true; //} this.txtException.Text = this.listView1.SelectedItems[0].SubItems[6].Text; //this.txtRemark.Text = this.listView1.SelectedItems[0].SubItems[7].Text; //采集设备列表的改变事件 List <SensorDeviceUnit> collectDeviceLsit = SensorDeviceUnit.FindAllByModularDeviceID( (this.listView1.SelectedItems[0].Tag as ModularDevice).ID); if (collectDeviceLsit == null || collectDeviceLsit.Count == 0) { foreach (ListViewItem item in this.lstCollectDevice.Items) { item.Checked = false; } //return; } else { foreach (ListViewItem item in this.lstCollectDevice.Items) { var isExists = false; foreach (var collectDevice in collectDeviceLsit) { var sD = item.Tag as SensorDeviceUnit; if (sD != null) { if (sD.ID == collectDevice.ID) { isExists = true; } } } item.Checked = isExists; } } //控制设备列表的改变事件 List <ControlDeviceUnit> controlDeviceLsit = ControlDeviceUnit.FindAllByModularDeviceID( (this.listView1.SelectedItems[0].Tag as ModularDevice).ID); if (controlDeviceLsit == null || controlDeviceLsit.Count == 0) { foreach (ListViewItem item in this.lstControlDevice.Items) { item.Checked = false; } //return; } else { foreach (ListViewItem item in this.lstControlDevice.Items) { var isExists = false; var cD = item.Tag as ControlDeviceUnit; foreach (var controlDevice in controlDeviceLsit) { if (cD != null) { if (cD.ID == controlDevice.ID) { isExists = true; } } } item.Checked = isExists; } } } } }
private void btnSave_Click(object sender, EventArgs e) { if (this.txtName.Text.Trim().IsNullOrWhiteSpace()) { MessageBox.Show("名称不能为空,请输入"); this.txtName.Focus(); return; } //if (ModularDevice.FindAllByName(this.txtName.Text, Name, Name, 0, 0) != null) //{ // MessageBox.Show("名称已经存在"); // this.txtName.Focus(); // return; //} #region 获取所有选中的设备 //List<SensorDeviceUnit> sensorDeviceUnitList = (from item in this.lstCollectDevice.Items.Cast<ListViewItem>() where item.Checked select item.Tag as SensorDeviceUnit).ToList();//采集设备 var sensorDeviceUnitList = new List <SensorDeviceUnit>(); var sensorDeviceUnitList1 = new List <SensorDeviceUnit>(); foreach (ListViewItem item in this.lstCollectDevice.Items) { if (item.Checked == false) { var sensorDeviceUnit = item.Tag as SensorDeviceUnit; //未选中的采集设备 sensorDeviceUnitList1.Add(sensorDeviceUnit); } else { sensorDeviceUnitList = (from i in this.lstCollectDevice.Items.Cast <ListViewItem>() where i.Checked select i.Tag as SensorDeviceUnit).ToList(); //选中的采集设备 } } //List<ControlDeviceUnit> controlDeviceUnitList = (from item in this.lstControlDevice.Items.Cast<ListViewItem>() where item.Checked select item.Tag as ControlDeviceUnit).ToList();//控制设备 var controlDeviceUnitList = new List <ControlDeviceUnit>(); var controlDeviceUnitList1 = new List <ControlDeviceUnit>(); foreach (ListViewItem item in this.lstControlDevice.Items) { if (item.Checked == false) { var controlDeviceUnit = item.Tag as ControlDeviceUnit; //未选中的控制设备 controlDeviceUnitList1.Add(controlDeviceUnit); } else { controlDeviceUnitList = (from i in this.lstControlDevice.Items.Cast <ListViewItem>() where i.Checked select i.Tag as ControlDeviceUnit).ToList(); //选中的控制设备 } } #endregion 获取所有选中的设备 if (this.modularDeviceId != 0) { try { // 更新 var modularDevice = new ModularDevice { ID = this.modularDeviceId, Name = this.txtName.Text.Trim(), ProtocalTypeID = Convert.ToInt32(this.cbProtocalType.SelectedValue), CommunicateDeviceID = Convert.ToInt32(this.cbCommunicateDevice.SelectedValue), Address = this.txtAddress.Text, //OnlineStatus = Convert.ToBoolean(this.cbOnlineStatus.SelectedValue), OnlineStatus = this.rbtOnlineStatus.Checked, Exception = this.txtException.Text, //Remark = this.txtRemark.Text.Trim() }; ModularDevice.Update(modularDevice); //更新采集设备 foreach (var item in sensorDeviceUnitList) { var sensorUnit = new SensorDeviceUnit(); sensorUnit.ID = item.ID; sensorUnit.ModularDeviceID = this.modularDeviceId; sensorUnit.Update(); } //foreach (var item in sensorDeviceUnitList1) //{ // item.ModularDeviceID = this.modularDeviceId; // SensorDeviceUnit.Delete(item); //} this.InitCollectDeviceListView(); //更新控制设备 foreach (var item in controlDeviceUnitList) { var controlUnit = new ControlDeviceUnit(); controlUnit.ID = item.ID; controlUnit.ModularDeviceID = this.modularDeviceId; controlUnit.Update(); } //foreach (var item in controlDeviceUnitList1) //{ // item.ModularDeviceID = this.modularDeviceId; // ControlDeviceUnit.Delete(item); //} this.InitControlDeviceListView(); MessageBox.Show("更新成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("更新失败"); } } else { try { // 保存 var modularDevice = new ModularDevice { Name = this.txtName.Text.Trim(), ProtocalTypeID = Convert.ToInt32(this.cbProtocalType.SelectedValue), CommunicateDeviceID = Convert.ToInt32(this.cbCommunicateDevice.SelectedValue), Address = this.txtAddress.Text, //OnlineStatus = Convert.ToBoolean(this.cbOnlineStatus.SelectedValue), OnlineStatus = this.rbtOnlineStatus.Checked, Exception = this.txtException.Text, //Remark = this.txtRemark.Text.Trim() }; ModularDevice.Save(modularDevice); ////保存采集设备 //foreach (var item in sensorDeviceUnitList) //{ // item.ModularDeviceID = this.modularDeviceId; // SensorDeviceUnit.Save(item); //} this.InitCollectDeviceListView(); ////保存控制设备 //foreach (var item in controlDeviceUnitList) //{ // item.ModularDeviceID = this.modularDeviceId; // ControlDeviceUnit.Save(item); //} this.InitControlDeviceListView(); MessageBox.Show("保存成功"); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("保存失败"); } } this.InitModularDeviceListView(); }
/// <summary> /// The list view 1 selected index changed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ListView1SelectedIndexChanged(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { if (this.listView1.SelectedItems[0].Tag is Facility) { //this.txtId.Text = (this.listView1.SelectedItems[0].Tag as Facility).ID.ToString(); facilityId = (this.listView1.SelectedItems[0].Tag as Facility).ID; this.txtName.Text = this.listView1.SelectedItems[0].SubItems[1].Text; this.txtCode1.Text = this.listView1.SelectedItems[0].SubItems[2].Text; this.txtCode2.Text = this.listView1.SelectedItems[0].SubItems[3].Text; this.txtCode3.Text = this.listView1.SelectedItems[0].SubItems[4].Text; this.cbFacilityType.Text = this.listView1.SelectedItems[0].SubItems[5].Text; this.cbFarm.Text = this.listView1.SelectedItems[0].SubItems[6].Text; this.txtContactPhone.Text = this.listView1.SelectedItems[0].SubItems[7].Text; //this.dtCreateTime.Value = Convert.ToDateTime(this.listView1.SelectedItems[0].SubItems[8].Text); //this.txtUpdateTime.Text = this.listView1.SelectedItems[0].SubItems[9].Text; //this.cbUpLoad.Text = this.listView1.SelectedItems[0].SubItems[10].Text; //this.rbtUpLoad.Checked = Convert.ToBoolean(this.listView1.SelectedItems[0].SubItems[10].Text); //if (this.rbtUpLoad.Checked == true) //{ // this.rbtUpLoad1.Checked = false; //} //else //{ // this.rbtUpLoad1.Checked = true; //} //this.txtVersion.Text = this.listView1.SelectedItems[0].SubItems[11].Text; //this.cbStatus.Text = this.listView1.SelectedItems[0].SubItems[12].Text; this.rbtOnlineStatus.Checked = Convert.ToBoolean(this.listView1.SelectedItems[0].SubItems[12].Text); //if (this.rbtOnlineStatus.Checked == true) //{ // this.rbtOnlineStatus1.Checked = false; //} //else //{ // this.rbtOnlineStatus1.Checked = true; //} this.txtAddress.Text = this.listView1.SelectedItems[0].SubItems[13].Text; this.txtIntroduce.Text = this.listView1.SelectedItems[0].SubItems[14].Text; this.txtContactMan.Text = this.listView1.SelectedItems[0].SubItems[15].Text; this.txtContactMobile.Text = this.listView1.SelectedItems[0].SubItems[16].Text; //this.txtRemark.Text = this.listView1.SelectedItems[0].SubItems[17].Text; //this.pbPhotoUrl.Text = this.listView1.SelectedItems[0].SubItems[18].Text; #region 采集设备列表的改变事件 List <FacilitySensorDeviceUnit> facilitySensorDeviceUnitList = (this.listView1.SelectedItems[0].Tag as Facility).FacilitySensorDeviceUnits; //获取该设施所拥有的所有采集设备的集合 var collectionDeviceList = new List <SensorDeviceUnit>(); foreach (var fac in facilitySensorDeviceUnitList) { var collectionDevice = SensorDeviceUnit.FindByID(fac.SensorDeviceUnitID); collectionDeviceList.Add(collectionDevice); } if (collectionDeviceList == null || collectionDeviceList.Count == 0) { foreach (ListViewItem item in this.listView2.Items) { item.Checked = false; } //return; } else { foreach (ListViewItem item in this.listView2.Items) { var isExists = false; foreach (var collectDevice in collectionDeviceList) { var sDevice = item.Tag as SensorDeviceUnit; if (sDevice != null) { if (sDevice.ID == collectDevice.ID) { isExists = true; } } } item.Checked = isExists; } } #endregion 采集设备列表的改变事件 #region 控制设备列表的改变事件 List <FacilityControlDeviceUnit> facilityControlDeviceUnitList = (this.listView1.SelectedItems[0].Tag as Facility).FacilityControlDeviceUnits; //获取该设施所拥有的所有控制设备的集合 var controlDeviceList = new List <ControlDeviceUnit>(); foreach (var fas in facilityControlDeviceUnitList) { var controlDevices = ControlDeviceUnit.FindByGroupNum(fas.ControlDeviceUnitGroupNum); controlDeviceList.AddRange(controlDevices); } if (controlDeviceList == null || controlDeviceList.Count == 0) { foreach (ListViewItem item in this.listView3.Items) { item.Checked = false; } } else { foreach (ListViewItem item in this.listView3.Items) { var isExists = false; foreach (var controlDevice in controlDeviceList) { var cDevice = item.Tag as ControlDeviceUnit; if (cDevice != null) { if (cDevice.ID == controlDevice.ID) { isExists = true; } } } item.Checked = isExists; } } #endregion 控制设备列表的改变事件 #region 摄像机设备列表的改变事件 //List<FacilityCamera> facilityCameraList = FacilityCamera.FindAllByFacilityID((this.listView1.SelectedItems[0].Tag as Facility).ID); List <FacilityCamera> facilityCameraList = (this.listView1.SelectedItems[0].Tag as Facility).FacilityCameras; //获取该设施所拥有的所有摄像机设备的集合 var cameraList = new List <Camera>(); foreach (var fc in facilityCameraList) { var camera = Camera.FindByID(fc.CameraID); cameraList.Add(camera); } if (cameraList == null || cameraList.Count == 0) { foreach (ListViewItem item in this.listView4.Items) { item.Checked = false; } //return; } foreach (ListViewItem item in this.listView4.Items) { var isExists = false; foreach (var facilityCamera in cameraList) { var c = item.Tag as Camera; if (c != null) { if (c.ID == facilityCamera.ID) { isExists = true; } } } item.Checked = isExists; } #endregion 摄像机设备列表的改变事件 } } }
/// <summary> /// 加载树结构 /// </summary> private void InitTreeView() { this.treeView1.Nodes.Clear(); // 获取所有的设施列表 List <Facility> facilityList = Facility.FindAll(); if (facilityList.Count > 0 && facilityList.Any()) { var firstNode = new TreeNode(facilityList[0].FarmName) { Tag = "FisrtPag" }; this.treeView1.Nodes.Add(firstNode); foreach (var facility in facilityList) { var allnode = new TreeNode(facility.Name) { ImageIndex = 0, Tag = facility }; //采集设备 var collectnode = new TreeNode("采集设备") { ImageIndex = 1, Tag = "SensorDeviceUnit" }; List <FacilitySensorDeviceUnit> sensorDeviceUnitList = FacilitySensorDeviceUnit.FindAllByFacilityID(facility.ID); if (sensorDeviceUnitList == null) { return; } foreach (var sensorDeviceUnit in sensorDeviceUnitList) { var treeNode = new TreeNode(SensorDeviceUnit.FindByID(sensorDeviceUnit.SensorDeviceUnitID).Name.ToString()); treeNode.Tag = sensorDeviceUnit; collectnode.Nodes.Add(treeNode); } allnode.Nodes.Add(collectnode); //控制设备 var controlnode = new TreeNode("控制设备") { ImageIndex = 1, Tag = "ControlDeviceUnit" }; List <FacilityControlDeviceUnit> controlDeviceUnitList = FacilityControlDeviceUnit.FindAllByFacilityID(facility.ID); if (controlDeviceUnitList == null) { return; } foreach (var controlDeviceUnit in controlDeviceUnitList) { var treeNode = new TreeNode( ControlDeviceUnit.FindByGroupNum(controlDeviceUnit.ControlDeviceUnitGroupNum)[0].Name .ToString()); treeNode.Tag = controlDeviceUnit; controlnode.Nodes.Add(treeNode); } allnode.Nodes.Add(controlnode); ////摄像机设备 //var cameranode = new TreeNode("摄像机设备") { ImageIndex = 1, Tag = "facilityCamera" }; //List<FacilityCamera> cameraList = FacilityCamera.FindAllByFacilityID(facility.ID); //if (cameraList == null) //{ // return; //} //foreach (FacilityCamera facilityCamera in cameraList) //{ // var treeNode = new TreeNode(facilityCamera.CameraName); // treeNode.Tag = facilityCamera; // cameranode.Nodes.Add(treeNode); //} //allnode.Nodes.Add(cameranode); ////展示设备 //var showDevicenode = new TreeNode("显示设备") { ImageIndex = 1, Tag = "showDevice" }; //List<ShowDevice> showDeviceList = ShowDevice.FindAll(); //if (showDeviceList == null) //{ // return; //} //foreach (ShowDevice showDevice in showDeviceList) //{ // var treeNode = new TreeNode(showDevice.Name); // treeNode.Tag = showDevice; // showDevicenode.Nodes.Add(treeNode); //} //allnode.Nodes.Add(showDevicenode); this.treeView1.Nodes.Add(allnode); } this.treeView1.ExpandAll(); } }