Exemple #1
0
        public ActionResult DeleteList(string plantId, string unitId)
        {
            try
            {
                string[] s = unitId.Split(',');
                for (int i = 0; i < s.Length; i++)
                {
                    //根据电站id和电站单元Id查询该电站是否有该单元
                    PlantUnit plantUnit = plantUnitService.GetPlantUnitByPlantIdPlantUnitId(int.Parse(plantId), Convert.ToInt32(s[i]));
                    if (plantUnit == null)
                    {
                        return(RedirectToAction("list", "unit", new { @id = plantId }));
                    }
                    else
                    {
                        plantUnitService.DeletePlantUnit(int.Parse(plantId), Convert.ToInt32(s[i]));//根据电站Id和电站单元Id删除电站单元
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(RedirectToAction("list", "unit", new { @id = plantId }));
        }
Exemple #2
0
        public ActionResult DeleteList(string plantId, string unitId)
        {
            try
            {
                string[] s = unitId.Split(',');
                for (int i = 0; i < s.Length; i++)
                {
                    //根据电站id和电站单元Id查询该电站是否有该单元
                    int       collectorId = Convert.ToInt32(s[i]);
                    PlantUnit plantUnit   = plantUnitService.GetPlantUnitByPlantIdCollectorId(int.Parse(plantId), collectorId);
                    if (plantUnit == null)
                    {
                        return(RedirectToAction("list", "unit", new { @id = plantId }));
                    }
                    else
                    {
                        Collector      collector = plantUnit.collector;
                        IList <Device> devices   = plantUnit.devices;

                        int res = plantUnitService.DeletePlantUnit(int.Parse(plantId), collectorId); //根据电站Id和电站单元Id删除电站单元
                        if (res > 0)                                                                 //删除成功后将采集器的使用标识为false
                        {
                            collector.isUsed = false;
                            collectorInfoService.Save(collector);
                            //删除单元要将单元的物理设备的planunitid属性值null,即解除物理关系
                            foreach (Device device in devices)
                            {
                                if (device.plantUnitId != plantUnit.id)
                                {
                                    continue;                                    //已有属主则不纳入该单元
                                }
                                device.parentId    = 0;
                                device.plantUnitId = null;
                                DeviceService.GetInstance().Save(device);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(RedirectToAction("list", "unit", new { @id = plantId }));
        }