Esempio n. 1
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);
            }
        }
Esempio n. 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;
        }
Esempio n. 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("更新成功");
        }