Beispiel #1
0
        /// <summary>
        /// 对设施采集设备编码进行更新
        /// </summary>
        /// <param name="fas">设施采集设备</param>
        /// <param name="strCode1">编码1</param>
        /// <param name="strCode2">编码2</param>
        /// <param name="strCode3">编码3</param>
        private static void AquireCollectCode(FacilitySensorDeviceUnit fas, string strCode1, string strCode2,
                                              string strCode3)
        {
            var list = FacilitySensorDeviceUnit.FindAllByFacilityIdAndCollectDeviceId(fas.FacilityID,
                                                                                      fas.SensorDeviceUnitID); //根据设施Id和采集设备Id查找设施采集设备

            if (list.Count > 0)
            {
                if (!list[0].Code1.EqualIgnoreCase())
                {
                    fas.Code1 = list[0].Code1; //编码1不动
                }
                else
                {
                    fas.Code1 = "";
                }
                //if (!list[0].Code2.EqualIgnoreCase())
                //{
                //    fas.Code2 = list[0].Code2;//编码2不动
                //}
                //else
                //{
                //    fas.Code2 = "";
                //}
                //if (!list[0].Code3.EqualIgnoreCase())
                //{
                //    fas.Code3 = list[0].Code3;//编码3不动
                //}
                //else
                //{
                //    fas.Code3 = "";
                //}
            }
            else
            {
                if (!strCode1.IsNullOrWhiteSpace())
                {
                    fas.Code1 = FacilitySensorDeviceUnit.GetCode1(fas.FacilityID);
                }
                if (!strCode2.IsNullOrWhiteSpace())
                {
                    fas.Code2 = FacilitySensorDeviceUnit.GetCode2(fas.FacilityID);
                }
                if (!strCode3.IsNullOrWhiteSpace())
                {
                    fas.Code3 = FacilitySensorDeviceUnit.GetCode3(fas.FacilityID);
                }
            }
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region 判断条件

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

            #endregion 判断条件

            var facility = new Facility();

            if (this.facilityId != 0)
            {
                #region 更新

                facility      = Facility.FindByID(this.facilityId);
                facility.Name = this.txtName.Text;
                facility.FacilityTypeSerialnum = this.cbFacilityType.SelectedValue.ToString();
                facility.FarmID = Convert.ToInt32(this.cbFarm.SelectedValue);
                //facility.Code1 = facility.GetCode1();
                //facility.Code2 = this.txtCode2.Text;
                //facility.Code3 = this.txtCode3.Text;
                facility.ContactPhone = this.txtContactPhone.Text;
                //facility.CreateTime = this.dtCreateTime.Value;
                facility.UpdateTime = DateTime.Now;
                //facility.Upload = this.rbtUpLoad.Checked;
                //facility.Version = Convert.ToInt32(this.txtVersion.Text);
                facility.Status        = this.rbtOnlineStatus.Checked;
                facility.Address       = this.txtAddress.Text;
                facility.Introduce     = this.txtIntroduce.Text;
                facility.ContactMan    = this.txtContactMan.Text;
                facility.ContactMobile = this.txtContactMobile.Text;
                //facility.Remark = this.txtRemark.Text;
                //facility.PhotoUrl = this.pbPhotoUrl.Text;
                try
                {
                    // Facility.Update(facility);
                    facility.Update();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("更新失败" + ex.Message);
                }

                #endregion 更新
            }
            else
            {
                #region 保存设施

                facility.Name   = this.txtName.Text;
                facility.FarmID = Convert.ToInt32(this.cbFarm.SelectedValue);
                if (!(facility.Code1 + "").StartsWith(facility.Farm.Code1 + ""))
                {
                    facility.Code1 = facility.GetCode1();
                }
                //if (!facility.Farm.Code2.IsNullOrWhiteSpace())
                //{
                //    //facility.Code2 = facility.Farm.Code2 + "G00" + facility.ID;
                //    facility.Code1 = Facility.GetCode2(facility.Farm.ID);
                //}
                //if (!facility.Farm.Code3.IsNullOrWhiteSpace())
                //{
                //    //facility.Code3 = facility.Farm.Code3 + "G00" + facility.ID;
                //    facility.Code1 = Facility.GetCode3(facility.Farm.ID);
                //}
                facility.FacilityTypeSerialnum = this.cbFacilityType.SelectedValue.ToString();
                facility.FarmID       = Convert.ToInt32(this.cbFarm.SelectedValue);
                facility.ContactPhone = this.txtContactPhone.Text;
                facility.CreateTime   = DateTime.Now;
                facility.UpdateTime   = DateTime.Now;
                //facility.Upload = Convert.ToBoolean(this.cbUpLoad.SelectedValue);
                //facility.Upload = this.rbtUpLoad.Checked;
                //facility.Version = Convert.ToInt32(this.txtVersion.Text);
                //facility.Status = Convert.ToBoolean(this.cbStatus.SelectedValue);
                facility.Status        = this.rbtOnlineStatus.Checked;
                facility.Address       = this.txtAddress.Text;
                facility.Introduce     = this.txtIntroduce.Text;
                facility.ContactMan    = this.txtContactMan.Text;
                facility.ContactMobile = this.txtContactMobile.Text;
                //facility.Remark = this.txtRemark.Text;
                //facility.PhotoUrl = this.pbPhotoUrl.Text;

                #endregion 保存设施

                try
                {
                    //Facility.Save(facility);
                    facility.Insert();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("新增失败" + ex);
                }
            }

            #region 获取所有选中的设备

            //List<SensorDeviceUnit> sensorDeviceUnitList = (from item in this.listView2.Items.Cast<ListViewItem>() where item.Checked select item.Tag as SensorDeviceUnit).ToList();
            var sensorDeviceUnitListChecked = new List <SensorDeviceUnit>();
            var sensorDeviceUnitListUncheck = new List <SensorDeviceUnit>();
            foreach (ListViewItem item in this.listView2.Items)
            {
                if (item.Checked == false)
                {
                    var sensorDeviceUnit = item.Tag as SensorDeviceUnit; //未选中的采集设备
                    sensorDeviceUnitListUncheck.Add(sensorDeviceUnit);
                }
                else
                {
                    sensorDeviceUnitListChecked =
                        (from i in this.listView2.Items.Cast <ListViewItem>()
                         where i.Checked
                         select i.Tag as SensorDeviceUnit).ToList();    //选中的采集设备
                }
            }

            //List<FacilityControlDeviceUnit> facilityControlDeviceUnitList = (from item in this.listView3.Items.Cast<ListViewItem>() where item.Checked select item.Tag as FacilityControlDeviceUnit).ToList();//控制设备
            var controlDeviceUnitListChecked   = new List <ControlDeviceUnit>();
            var controlDeviceUnitListUnchecked = new List <ControlDeviceUnit>();
            foreach (ListViewItem item in this.listView3.Items)
            {
                if (item.Checked == false)
                {
                    var controlDeviceUnit = item.Tag as ControlDeviceUnit; //未选中的控制设备
                    controlDeviceUnitListUnchecked.Add(controlDeviceUnit);
                }
                else
                {
                    controlDeviceUnitListChecked =
                        (from i in this.listView3.Items.Cast <ListViewItem>()
                         where i.Checked
                         select i.Tag as ControlDeviceUnit).ToList();    //选中的控制设备
                }
            }

            //List<FacilityCamera> facilityCameraList = (from item in this.listView4.Items.Cast<ListViewItem>() where item.Checked select item.Tag as FacilityCamera).ToList();//摄像机设备

            var cameraListChecked   = new List <Camera>();
            var cameraListUnchecked = new List <Camera>();
            foreach (ListViewItem item in this.listView4.Items)
            {
                if (item.Checked == false)
                {
                    var camera = item.Tag as Camera; //未选中的摄像机设备
                    cameraListUnchecked.Add(camera);
                }
                else
                {
                    cameraListChecked =
                        (from i in this.listView4.Items.Cast <ListViewItem>() where i.Checked select i.Tag as Camera)
                        .ToList();     //选中的摄像机设备
                }
            }

            #endregion 获取所有选中的设备

            #region 更新采集设备

            foreach (var sensorDevice in sensorDeviceUnitListChecked)
            {
                var dbList = FacilitySensorDeviceUnit.FindAllByFacilityIdAndCollectDeviceId(this.facilityId,
                                                                                            sensorDevice.ID);

                if (dbList == null || dbList.Count == 0)
                {
                    var fas = new FacilitySensorDeviceUnit()
                    {
                        FacilityID         = this.facilityId,
                        SensorDeviceUnitID = sensorDevice.ID
                    };
                    fas.Code1 = fas.GetCode1();
                    fas.Insert();
                }
                else
                {
                    var fas = dbList[0];
                    if (!(fas.Code1 + "").StartsWith(facility.Code1))
                    {
                        fas.Code1 = fas.GetCode1();
                        fas.Update();
                    }
                }
            }
            foreach (var sensorDevice in sensorDeviceUnitListUncheck)
            {
                FacilitySensorDeviceUnit.DeleteByFacilityAndSensorDeviceunit(this.facilityId, sensorDevice.ID);
            }
            this.InitCollectDeviceListView();

            #endregion 更新采集设备

            #region 更新控制设备

            foreach (var controlDevice in controlDeviceUnitListChecked)
            {
                var dbList = FacilityControlDeviceUnit.FindAllByFacilityIdAndControlDeviceGroupNum(this.facilityId,
                                                                                                   controlDevice.GroupNum);

                if (dbList == null || dbList.Count == 0)
                {
                    var fac = new FacilityControlDeviceUnit()
                    {
                        FacilityID = this.facilityId,
                        ControlDeviceUnitGroupNum = controlDevice.GroupNum,
                        Name = controlDevice.Name.ToString().Substring(0, controlDevice.Name.ToString().IndexOf("-"))
                    };
                    fac.Code1 = fac.GetCode1();
                    fac.Insert();
                }
                else
                {
                    var fac = dbList[0];
                    if (!(fac.Code1 + "").StartsWith(facility.Code1))
                    {
                        fac.Code1 = fac.GetCode1();
                        fac.Update();
                    }
                }
            }

            foreach (var controlDevice in controlDeviceUnitListUnchecked)
            {
                FacilityControlDeviceUnit.DeleteByFacilityAndControlDeviceunGroupNum(this.facilityId,
                                                                                     controlDevice.GroupNum);
            }
            this.InitControlDeviceListView();

            #endregion 更新控制设备

            #region 更新摄像机设备

            foreach (var facilityCamera in cameraListChecked)
            {
                var dbList = FacilityCamera.FindAllByFacilityIdAndCameraId(this.facilityId, facilityCamera.ID);

                if (dbList == null || dbList.Count == 0)
                {
                    var fac = new FacilityCamera()
                    {
                        FacilityID = this.facilityId,
                        CameraID   = facilityCamera.ID
                    };
                    fac.Code1 = fac.GetCode1();
                    fac.Save();
                }
                else
                {
                    var fac = dbList[0];
                    if (!(fac.Code1 + "").StartsWith(facility.Code1))
                    {
                        fac.Code1 = fac.GetCode1();
                        fac.Update();
                    }
                }
            }
            foreach (var camera in cameraListUnchecked)
            {
                FacilityCamera.DeleteByFacilityAndCamera(this.facilityId, camera.ID);
            }
            this.InitCameraDeviceListView();

            #endregion 更新摄像机设备

            this.InitFacilityListView();

            MessageBox.Show("更新成功");
        }