/// <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); } }
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(); }
/// <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(); } }