public ActionResult SavePlant(Plant plant)
        {
            string long1     = Request.Form["long1"];
            string long2     = Request.Form["long2"];
            string long3     = Request.Form["long3"];
            double value     = 0;
            double longValue = 0;

            double.TryParse(long1, out longValue);
            value += longValue;
            double.TryParse(long2, out longValue);
            value += (longValue / 60);

            double.TryParse(long3, out longValue);
            value += (longValue / 3600);

            plant.longitude = value;
            value           = 0;
            longValue       = 0;
            string lat1 = Request.Form["lat1"];

            double.TryParse(lat1, out longValue);
            value += longValue;

            string lat2 = Request.Form["lat2"];

            double.TryParse(lat2, out longValue);
            value += (longValue / 60);

            string lat3 = Request.Form["lat3"];

            double.TryParse(lat3, out longValue);
            value                += (longValue / 3600);
            plant.latitude        = value;
            plant.longitudeString = string.Format("{0},{1},{2}", long1, long2, long3);
            plant.latitudeString  = string.Format("{0},{1},{2}", lat1, lat2, lat3);
            if (string.IsNullOrEmpty(plant.pic))
            {
                plant.pic = string.Empty;
            }
            plant.userID = UserUtil.getCurUser().id;
            CountryCity area = CountryCityService.GetInstance().GetCity(plant.country);

            plant.area = area == null ? string.Empty : area.weather_code;
            int plantid = plant.id;

            if (plant.id > 0)
            {
                PlantService.GetInstance().UpdatePlantInfo(plant);
            }
            else
            {
                plantid = PlantService.GetInstance().AddPlantInfo(plant);
                PlantUserService.GetInstance().AddPlantUser(new PlantUser {
                    plantID = plantid, userID = int.Parse(plant.userID.ToString())
                });                                                                                                                           //添加电站时,向电站用户关系表中加记录
            }
            UserUtil.ResetLogin(UserUtil.getCurUser());
            return(Redirect("/newregister/addplantcontrol?plantid=" + plantid));
        }
Beispiel #2
0
        //
        // GET: /Country/

        public ActionResult City()
        {
            IList <CountryCity> countries = CountryCityService.GetInstance().GetList();

            ViewData["countries"] = countries;
            return(View());
        }
        public ActionResult AddPlantControl(string plantid)
        {
            if (string.IsNullOrEmpty(plantid) == false)
            {
                int pid = 0;
                int.TryParse(plantid, out pid);
                Plant plant = PlantService.GetInstance().GetPlantInfoById(pid);//根据电站id获取电站
                if (string.IsNullOrEmpty(plant.startDate) || string.IsNullOrEmpty(plant.endDate))
                {
                    string code = string.Empty;

                    IList <CountryCity> countries = CountryCityService.GetInstance().GetList();
                    foreach (CountryCity country in countries)
                    {
                        if (country.name.Trim().Equals(plant.country))
                        {
                            code = country.code;
                            break;
                        }
                    }
                    code = string.IsNullOrEmpty(code) ? "&" : code;
                    string[] codes = code.Split('&');
                    if (codes.Length >= 3)
                    {
                        plant.startDate = codes[0];
                        plant.endDate   = codes[1];
                        plant.hours     = int.Parse(codes[2]);
                    }
                }
                try
                {
                    if (!string.IsNullOrEmpty(plant.pic))
                    {
                        string[] s = plant.pic.Split(',');
                        ViewData["pic"]      = s;
                        ViewData["username"] = UserUtil.getCurUser().username;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                return(View(plant));
            }
            return(View());
        }
Beispiel #4
0
        public ActionResult SavePlant(Plant plant)
        {
            //设置电站的经纬度
            string long1     = Request.Form["long1"];
            string long2     = Request.Form["long2"];
            string long3     = Request.Form["long3"];
            double value     = 0;
            double longValue = 0;

            double.TryParse(long1, out longValue);
            value += longValue;
            double.TryParse(long2, out longValue);
            value += (longValue / 60);

            double.TryParse(long3, out longValue);
            value += (longValue / 3600);

            plant.longitude = value;
            value           = 0;
            longValue       = 0;
            string lat1 = Request.Form["lat1"];

            double.TryParse(lat1, out longValue);
            value += longValue;

            string lat2 = Request.Form["lat2"];

            double.TryParse(lat2, out longValue);
            value += (longValue / 60);

            string lat3 = Request.Form["lat3"];

            double.TryParse(lat3, out longValue);
            value                += (longValue / 3600);
            plant.latitude        = value;
            plant.longitudeString = string.Format("{0},{1},{2}", long1, long2, long3);
            plant.latitudeString  = string.Format("{0},{1},{2}", lat1, lat2, lat3);
            if (string.IsNullOrEmpty(plant.pic))
            {
                plant.pic = string.Empty;
            }

            //设置电站的创建者
            plant.userID = UserUtil.getCurUser().id;
            CountryCity area = CountryCityService.GetInstance().GetCity(plant.country);

            plant.area = area == null ? string.Empty : area.weather_code;
            int plantid = plant.id;

            if (plant.id > 0)
            {
                PlantService.GetInstance().UpdatePlantInfo(plant);
            }
            else
            {
                plant.PaymentLimitDate = DateTime.Now.AddMonths(PaymentDelayMonth);
                plantid = PlantService.GetInstance().AddPlantInfo(plant);
                //添加电站时,向电站用户关系表中加记录,shared=false表示是自己创建的
                PlantUserService.GetInstance().AddPlantUser(new PlantUser {
                    plantID = plantid, userID = plant.userID, shared = false, roleId = Role.ROLE_SYSMANAGER
                });
            }
            UserUtil.ResetLogin(UserUtil.getCurUser());
            return(Redirect("/newregister/addplantcontrol?plantid=" + plantid));
        }