Beispiel #1
0
        /// <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();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            // if (this.lstFarm.SelectedItems.Count == 0) return;

            if (this.txtName.Text.Trim().Equals(""))
            {
                MessageBox.Show("名称不能为空,请输入");
                this.txtName.Focus();
                return;
            }

            //if (this.txtCode1.Text.Trim().Equals(""))
            //{
            //    MessageBox.Show("编码1不能为空,请输入");
            //    this.txtName.Focus();
            //    return;
            //}
            //if (this.txtCode2.Text.Trim().Equals(""))
            //{
            //    MessageBox.Show("编码2不能为空,请输入");
            //    this.txtName.Focus();
            //    return;
            //}
            //if (this.txtCode3.Text.Trim().Equals(""))
            //{
            //    MessageBox.Show("编码3不能为空,请输入");
            //    this.txtName.Focus();
            //    return;
            //}
            //if (this.txtCompanySerialNum.Text.Trim().Equals(""))
            //{
            //    MessageBox.Show("公司不能为空,请输入");
            //    this.txtName.Focus();
            //    return;
            //}
            //List<Facility> facilityList = (from item in this.lstFacility.Items.Cast<ListViewItem>() where item.Checked select item.Tag as Facility).ToList();//设施列表

            if (this.farmId != 0)
            {
                try
                {
                    #region 更新基地

                    var farm = Farm.FindByID(this.farmId);
                    if (farm == null)
                    {
                        farm       = new Farm();
                        farm.Code1 = this.txtCode1.Text;
                    }

                    farm.Code1            = this.txtCode1.Text.Trim();
                    farm.Code2            = this.txtCode2.Text.Trim();
                    farm.Code3            = this.txtCode3.Text.Trim();
                    farm.Name             = this.txtName.Text.Trim();
                    farm.CompanySerialnum = this.txtCompanySerialNum.Text.Trim();
                    farm.Address          = this.txtAddress.Text.Trim();
                    //PhotoUrl = this.pbPhotoUrl.Text,
                    farm.Lotitude      = this.txtLotitude.Text;
                    farm.Latitude      = this.txtLatitude.Text;
                    farm.Area          = Convert.ToInt32(this.txtArea.Text.Trim());
                    farm.ContactMan    = this.txtContactMan.Text.Trim();
                    farm.ContactPhone  = this.txtContactPhone.Text.Trim();
                    farm.ContactMobile = this.txtContactMobile.Text.Trim();
                    //Status = Convert.ToBoolean(this.cbStatus.SelectedValue),
                    farm.Status = this.rbtOnlineStatus.Checked;
                    //CreateTime = this.dtCreateTime.Value,
                    farm.UpdateTime = Convert.ToDateTime(DateTime.Now.ToString("G"));
                    farm.APIKey     = this.txtAPIKey.Text;
                    //Upload = Convert.ToBoolean(this.cbUpLoad.SelectedValue),
                    //Upload=this.rbtUpLoad.Checked,
                    //Version = Convert.ToInt32(this.txtVersion.Text),
                    ////Introduce = this.lstIntroduce.Text,
                    farm.Remark = this.txtPwd.Text;

                    farm.Save();
                    this.farmId = farm.ID;

                    #endregion 更新基地

                    //MessageBox.Show("更新成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("更新失败");
                    return;
                }
            }
            else
            {
                try
                {
                    // 保存
                    var farm = new Farm();

                    farm.Code1            = this.txtCode1.Text.Trim();
                    farm.Code2            = this.txtCode2.Text.Trim();
                    farm.Code3            = this.txtCode3.Text.Trim();
                    farm.Name             = this.txtName.Text.Trim();
                    farm.CompanySerialnum = this.txtCompanySerialNum.Text.Trim();
                    farm.Address          = this.txtAddress.Text.Trim();
                    //PhotoUrl = this.pbPhotoUrl.Text,
                    farm.Lotitude      = this.txtLotitude.Text;
                    farm.Latitude      = this.txtLatitude.Text;
                    farm.Area          = Convert.ToInt32(this.txtArea.Text.Trim());
                    farm.ContactMan    = this.txtContactMan.Text.Trim();
                    farm.ContactPhone  = this.txtContactPhone.Text.Trim();
                    farm.ContactMobile = this.txtContactMobile.Text.Trim();
                    //Status = Convert.ToBoolean(this.cbStatus.SelectedValue),
                    farm.Status = this.rbtOnlineStatus.Checked;
                    //CreateTime = this.dtCreateTime.Value,
                    farm.UpdateTime = Convert.ToDateTime(DateTime.Now.ToString("G"));
                    farm.APIKey     = this.txtAPIKey.Text;
                    //Upload = Convert.ToBoolean(this.cbUpLoad.SelectedValue),
                    //Upload=this.rbtUpLoad.Checked,
                    //Version = Convert.ToInt32(this.txtVersion.Text),
                    ////Introduce = this.lstIntroduce.Text,
                    farm.Remark = this.txtPwd.Text;

                    farm.Save();
                    this.farmId = farm.ID;
                    //this.InitFacilityListView();
                    //MessageBox.Show("保存成功");
                }
                catch (Exception ex)
                {
                    XTrace.WriteException(ex);
                    MessageBox.Show("新增失败");
                    return;
                }
            }

            try
            {
                var facilityListChecked   = new List <Facility>();
                var facilityListUnchecked = new List <Facility>();
                foreach (ListViewItem item in this.lstFacility.Items)
                {
                    if (item.Checked == false)
                    {
                        var facility = item.Tag as Facility; //设施
                        facilityListUnchecked.Add(facility);
                    }
                    else
                    {
                        //facilityListChecked = (from i in this.lstFacility.Items.Cast<ListViewItem>() where i.Checked select i.Tag as Facility).ToList();//显示数据
                        foreach (ListViewItem lvi in lstFacility.Items)
                        {
                            if (lvi.Checked)
                            {
                                facilityListChecked.Add(lvi.Tag as Facility);
                            }
                        }
                    }
                }

                var farm = Farm.FindByID(farmId);

                //未选中的设施不能删除,只删除编码
                foreach (var item in facilityListUnchecked)
                {
                    if (item.FarmID == this.farmId)
                    {
                        item.Code1  = "";
                        item.FarmID = 0;
                        item.Update();
                        //删除映射关系
                        item.FacilitySensorDeviceUnits.Delete(true);
                        item.FacilityControlDeviceUnits.Delete(true);
                        item.FacilityCameras.Delete(true);
                    }
                }

                //更新基地设施
                foreach (var item in facilityListChecked)
                {
                    #region 更新设施

                    //Facility fac = new Facility();
                    //fac.ID = item.ID;
                    //fac.FarmID = this.farmId;
                    var fac = Facility.FindByID(item.ID);
                    fac.FarmID = farm.ID;
                    if (this.txtCode1.Text.IsNullOrWhiteSpace())
                    {
                        fac.Code1 = "";
                    }
                    else if (!this.txtCode1.Text.IsNullOrWhiteSpace() && !(fac.Code1 + "").StartsWith(farm.Code1))
                    {
                        fac.Code1 = fac.GetCode1();
                    }
                    fac.Update();

                    #endregion 更新设施

                    #region 设施下的采集设备的更新

                    IEnumerable <FacilitySensorDeviceUnit> facilitySensorDeviceUnits =
                        FacilitySensorDeviceUnit.FindAllByFacilityID(fac.ID).ToList().OrderBy(fas => fas.ID);
                    if (facilitySensorDeviceUnits.Count() > 0)
                    {
                        foreach (var fas in facilitySensorDeviceUnits)
                        {
                            if (fac.Code1.IsNullOrWhiteSpace())
                            {
                                fas.Code1 = "";
                            }
                            else if (!fac.Code1.IsNullOrWhiteSpace() && !(fas.Code1 + "").StartsWith(fac.Code1))
                            {
                                //XTrace.WriteLine("-->" + fas.Code1 + " -- " + fas.GetCode1());
                                fas.Code1 = fas.GetCode1();
                                //XTrace.WriteLine("<--" + fas.Code1);
                            }
                            fas.Save();
                        }
                    }

                    #endregion 设施下的采集设备的更新

                    #region 设施下的控制设备的更新

                    IEnumerable <FacilityControlDeviceUnit> facilityControlDeviceUnits =
                        FacilityControlDeviceUnit.FindAllByFacilityID(fac.ID).ToList().OrderBy(fas => fas.ID);
                    if (facilityControlDeviceUnits.Count() > 0)
                    {
                        foreach (var fas in facilityControlDeviceUnits)
                        {
                            if (fac.Code1.IsNullOrWhiteSpace())
                            {
                                fas.Code1 = "";
                            }
                            else if (!fac.Code1.IsNullOrWhiteSpace() && !(fas.Code1 + "").StartsWith(fac.Code1))
                            {
                                fas.Code1 = fas.GetCode1();
                            }
                            fas.Update();
                        }
                    }

                    #endregion 设施下的控制设备的更新

                    #region 设施下的摄像机设备的更新

                    IEnumerable <FacilityCamera> facilityCameras =
                        FacilityCamera.FindAllByFacilityID(fac.ID).ToList().OrderBy(fas => fas.ID);
                    if (facilityCameras.Count() > 0)
                    {
                        foreach (var fas in facilityCameras)
                        {
                            if (fac.Code1.IsNullOrWhiteSpace())
                            {
                                fas.Code1 = "";
                            }
                            else if (!fac.Code1.IsNullOrWhiteSpace() && !(fas.Code1 + "").StartsWith(fac.Code1))
                            {
                                fas.Code1 = fas.GetCode1();
                            }
                            fas.Update();
                        }
                    }

                    #endregion 设施下的摄像机设备的更新
                }

                this.InitFacilityListView();
                this.InitList();
                MessageBox.Show("操作成功");
            }
            catch (Exception ex)
            {
                XTrace.WriteException(ex);
                MessageBox.Show("更新设备编码失败");
                return;
            }
            this.farmId = 0;
        }
Beispiel #3
0
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="id">
        /// </param>
        private void SearchDataInfo(int id, string tag)
        {
            this.listView1.Items.Clear();

            if (tag.EqualIgnoreCase("SensorDeviceUnit"))
            {
                string data;
                var    fs = FacilitySensorDeviceUnit.FindByID(id);
                if (fs.SensorDeviceUnit.Sensor.Code.EqualIgnoreCase("collect-weather-YuXueGanZhi"))
                {
                    data = fs.SensorDeviceUnit.ProcessedValue == 1 ? "有" : "无";
                }
                else
                {
                    data = fs.SensorDeviceUnit.ProcessedValue.ToString();
                }

                var strings = new[]
                {
                    fs.Code1, fs.SensorDeviceUnit.Name, data, fs.SensorDeviceUnit.Sensor.Unit,
                    fs.SensorDeviceUnit.UpdateTime.ToString()
                };
                var listViewItem = new ListViewItem(strings);
                this.listView1.Items.Add(listViewItem);
            }
            else if (tag.EqualIgnoreCase("ControlDeviceUnit"))
            {
                string data;
                var    controlList = ControlDeviceUnit.FindByGroupNum(id);
                if (controlList.Count > 0)
                {
                    controlList.ForEach(c =>
                    {
                        data        = c.ProcessedValue;
                        var strings = new[]
                        { c.FacilityControlDeviceUnits[0].Code1, c.Name, data, "", c.UpdateTime.ToString() };
                        var listViewItem = new ListViewItem(strings);
                        this.listView1.Items.Add(listViewItem);
                    });
                }
            }

            var    fsList = FacilitySensorDeviceUnit.FindAllByFacilityID(id);
            var    fcList = FacilityControlDeviceUnit.FindAllByFacilityID(id);
            string data1;

            if (fsList.Count > 0)
            {
                fsList.ForEach(
                    fs =>
                {
                    if (fs.SensorDeviceUnit.Sensor.Code.EqualIgnoreCase("collect-weather-YuXueGanZhi"))
                    {
                        data1 = fs.SensorDeviceUnit.ProcessedValue == 1 ? "有" : "无";
                    }
                    else
                    {
                        data1 = fs.SensorDeviceUnit.ProcessedValue.ToString();
                    }

                    var strings = new[]
                    {
                        fs.Code1, fs.SensorDeviceUnit.Name, data1, fs.SensorDeviceUnit.Sensor.Unit,
                        fs.SensorDeviceUnit.UpdateTime.ToString()
                    };
                    var listViewItem = new ListViewItem(strings);
                    this.listView1.Items.Add(listViewItem);
                });
            }
            if (fcList.Count > 0)
            {
                fcList.ForEach(fc =>
                {
                    var controls = ControlDeviceUnit.FindByGroupNum(fc.ControlDeviceUnitGroupNum);
                    controls.ForEach(control =>
                    {
                        data1            = control.ProcessedValue;
                        var strings      = new[] { fc.Code1, control.Name, data1, "", control.UpdateTime.ToString() };
                        var listViewItem = new ListViewItem(strings);
                        this.listView1.Items.Add(listViewItem);
                    });
                });
            }
        }