Example #1
0
        private void DeviceDetails(object sender, EventArgs e)
        {
            Urzadzenie edited = new Urzadzenie();

            try
            {
                String nrUnikatowy = ShowDevices.selectedRow.Cells["Nr.Unikatowy"].Value.ToString();


                using (InzynierkaDBEntities db = new InzynierkaDBEntities())
                {
                    edited =
                        db.Urzadzenie.Where(x => x.nr_unikatowy ==
                                            nrUnikatowy
                                            ).First();
                }

                ShowDevice f = new ShowDevice(edited);
                if (f.ShowDialog() == DialogResult.Cancel)
                {
                    f.Dispose();
                }
            }
            catch (Exception) { }
        }
Example #2
0
        /// <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);
            }
        }
Example #3
0
        /// <summary>
        /// 初始化展示设备
        /// </summary>
        private void InitShowDevice()
        {
            List <ShowDevice> showDeviceList = ShowDevice.FindAll();

            //foreach (var showDevice in showDeviceList)
            //{
            //    this.cbShowDevice.Items.Add(showDevice);
            //    this.cbShowDevice.DisplayMember = showDevice.ID.ToString();
            //    this.cbShowDevice.ValueMember = showDevice.Name;
            //}
            if (showDeviceList.Count > 0)
            {
                this.cbShowDevice.DataSource    = showDeviceList;
                this.cbShowDevice.DisplayMember = "Name";
                this.cbShowDevice.ValueMember   = "ID";
            }
        }
Example #4
0
        /// <summary>
        /// 初始化展示设备列表
        /// </summary>
        private void InitShowDeviceListView()
        {
            this.listView1.Items.Clear();
            List <ShowDevice> showDeviceList = ShowDevice.FindAll();

            foreach (var showDevice in showDeviceList)
            {
                var strings = new string[]
                {
                    showDevice.ID.ToString(), showDevice.Name, showDevice.ShowDeviceTypeName,
                         showDevice.CommunicateDeviceName, showDevice.Address, showDevice.Remark
                };
                var listViewItem = new ListViewItem(strings);
                listViewItem.Tag = showDevice;
                this.listView1.Items.Add(listViewItem);
            }
        }
Example #5
0
 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 ShowDeviceType)
             {
                 var showDeviceType = this.listView1.SelectedItems[0].Tag as ShowDeviceType;
                 var id             = showDeviceType.ID;
                 List <ShowDevice> showDeviceList = ShowDevice.FindAllByShowDeviceTypeID(id);
                 if (showDeviceList != null)
                 {
                     MessageBox.Show("该设备类型在使用中,不能删除");
                     return;
                 }
                 ShowDeviceType.Delete(showDeviceType);
                 this.InitShowDeviceTypeListView();
                 this.showDeviceTypeId = 0;
             }
         }
     }
 }
Example #6
0
        private void InitData()
        {
            var facs = Facility.FindAllByFarmID(_farmId);

            if (facs != null && facs.Count > 0)
            {
                foreach (var fac in facs)
                {
                    var facnode = new DevComponents.AdvTree.Node("设施")
                    {
                        ImageIndex = 0,
                        Tag        = fac,
                        //TagString="Facility",
                        Expanded = true,
                        Name     = fac.Name,
                        Text     = fac.Name
                    };
                    this.advTreeData.Nodes.AddRange(new DevComponents.AdvTree.Node[] { facnode });

                    var collectnode = new DevComponents.AdvTree.Node("采集设备")
                    {
                        ImageIndex = 1, Tag = "SensorDeviceUnit"
                    };
                    var collects = fac.FacilitySensorDeviceUnits;
                    if (collects != null && collects.Count > 0)
                    {
                        foreach (var c in collects)
                        {
                            var cnode = new DevComponents.AdvTree.Node
                            {
                                Expanded = true,
                                Name     = c.SensorDeviceUnit.Name,
                                Text     = c.SensorDeviceUnit.Name,
                                Tag      = c.SensorDeviceUnit,
                                //TagString = "SensorDeviceUnit"
                            };
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.SensorDeviceUnit.ProcessedValue.ToString(), Name = c.SensorDeviceUnit.ProcessedValue.ToString()
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.SensorDeviceUnit.Sensor.Unit, Name = c.SensorDeviceUnit.Sensor.Unit
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.SensorDeviceUnit.UpdateTime.ToString(), Name = c.SensorDeviceUnit.UpdateTime.ToString()
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.Code1, Name = c.Code1
                            });
                            collectnode.Nodes.Add(cnode);
                        }
                    }
                    facnode.Nodes.Add(collectnode);

                    var controlnode = new DevComponents.AdvTree.Node("控制设备")
                    {
                        ImageIndex = 2, Tag = "ControlDeviceUnit"
                    };
                    var fcontrols = fac.FacilityControlDeviceUnits;
                    if (fcontrols != null && fcontrols.Count > 0)
                    {
                        foreach (var fc in fcontrols)
                        {
                            ControlDeviceUnit.FindByGroupNum(fc.ControlDeviceUnitGroupNum).ForEach(control =>
                            {
                                var cnode = new DevComponents.AdvTree.Node
                                {
                                    Expanded = true,
                                    Name     = control.Name,
                                    Text     = control.Name,
                                    Tag      = control,
                                    //TagString = "ControlDeviceUnit"
                                };
                                cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                    Text = control.ProcessedValue.ToString(), Name = control.ProcessedValue.ToString()
                                });
                                cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                    Text = " ", Name = " "
                                });
                                cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                    Text = control.UpdateTime.ToString(), Name = control.UpdateTime.ToString()
                                });
                                cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                    Text = fc.Code1, Name = fc.Code1
                                });
                                controlnode.Nodes.Add(cnode);
                            });
                        }
                    }
                    facnode.Nodes.Add(controlnode);

                    var cameranode = new DevComponents.AdvTree.Node("视频设备")
                    {
                        ImageIndex = 3, Tag = "Camera"
                    };
                    var cameras = fac.FacilityCameras;
                    if (cameras != null && cameras.Count > 0)
                    {
                        foreach (var c in cameras)
                        {
                            var cnode = new DevComponents.AdvTree.Node
                            {
                                Expanded = true,
                                Name     = c.Camera.Name,
                                Text     = c.Camera.Name,
                                Tag      = c.Camera,
                                //TagString = "Camera"
                            };
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = "正常", Name = "正常"
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = "", Name = ""
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.UpdateTime.ToString(), Name = c.UpdateTime.ToString()
                            });
                            cnode.Cells.Add(new DevComponents.AdvTree.Cell {
                                Text = c.Code1, Name = c.Code1
                            });
                            cameranode.Nodes.Add(cnode);
                        }
                    }
                    facnode.Nodes.Add(cameranode);

                    var shownode = new DevComponents.AdvTree.Node("展示设备")
                    {
                        ImageIndex = 4, Tag = "ShowDevice"
                    };
                    var shows = ShowDevice.FindAll();
                    if (shows != null && shows.Count > 0)
                    {
                        foreach (var s in shows)
                        {
                            var cnode = new DevComponents.AdvTree.Node
                            {
                                Expanded = true,
                                Name     = s.Name,
                                Text     = s.Name,
                                Tag      = s,
                                //TagString = "ShowDevice"
                            };
                            shownode.Nodes.Add(cnode);
                        }
                    }
                    facnode.Nodes.Add(shownode);
                }
            }
        }
Example #7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.txtName.Text.Trim().IsNullOrWhiteSpace())
            {
                MessageBox.Show("名称不能为空,请输入");
                this.txtName.Focus();
                return;
            }

            #region 获取所有选中的显示数据

            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();     //选中的显示数据
                }
            }
            //List<ShowData> showDataList = (from i in this.lstShowData.Items.Cast<ListViewItem>() where i.Checked select i.Tag as ShowData).ToList();

            #endregion 获取所有选中的显示数据

            if (this.showDeviceId != 0)
            {
                try
                {
                    // 更新
                    var showDevice = new ShowDevice
                    {
                        ID = this.showDeviceId,
                        //ID =Convert.ToInt32( this.txtId.Text),
                        Name                = this.txtName.Text.Trim(),
                        ShowDeviceTypeID    = Convert.ToInt32(this.cbShowDeviceType.SelectedValue),
                        CommunicateDeviceID = Convert.ToInt32(this.cbCommunicateDevice.SelectedValue),
                        Address             = this.txtAddress.Text.Trim(),
                        Remark              = this.txtRemark.Text.Trim()
                    };
                    ShowDevice.Update(showDevice);

                    //更新显示数据
                    foreach (var item in showDataList)
                    {
                        item.ShowDeviceID = this.showDeviceId;
                        ShowData.Update(item);
                    }
                    foreach (var item in showDataList1)
                    {
                        item.ShowDeviceID = this.showDeviceId;
                        ShowData.Delete(item);
                    }
                    this.InitShowDataListView();
                    MessageBox.Show("更新成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("更新失败");
                }
            }
            else
            {
                try
                {
                    // 保存
                    var showDevice = new ShowDevice
                    {
                        //ID = Convert.ToInt32(this.txtId.Text),
                        Name                = this.txtName.Text.Trim(),
                        ShowDeviceTypeID    = Convert.ToInt32(this.cbShowDeviceType.SelectedValue),
                        CommunicateDeviceID = Convert.ToInt32(this.cbCommunicateDevice.SelectedValue),
                        Address             = this.txtAddress.Text.Trim(),
                        Remark              = this.txtRemark.Text.Trim()
                    };
                    ShowDevice.Save(showDevice);

                    ////更新显示数据
                    //foreach (var item in showDataList)
                    //{
                    //    item.ShowDeviceID = this.showDeviceId;
                    //    ShowData.Save(item);
                    //}
                    this.InitShowDataListView();
                    MessageBox.Show("保存成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("保存失败");
                }
            }

            this.InitShowDeviceListView();
        }