예제 #1
0
 public int Save(Protal protal)
 {
     if (protal.id > 0)
         return _protalDao.Update(protal);
     return _protalDao.Insert(protal);
 }
예제 #2
0
 public ActionResult Manage()
 {
     User user = UserUtil.getCurUser();
     Protal protal = ProtalService.GetInstance().GetByUser(user.id);
     if (protal == null) protal = new Protal();
     return View(protal);
 }
예제 #3
0
        public ActionResult Save(HttpPostedFileBase markpic, HttpPostedFileBase logo)
        {
            string id = Request.Form["id"];
            if (string.IsNullOrEmpty(id)) id = "0";
            User user = UserUtil.getCurUser();
            Protal protal = ProtalService.GetInstance().GetByUser(user.id);
            if (protal == null) protal = new Protal();
            protal.id = int.Parse(id);
            protal.uid = user.id;
            protal.name = Request.Form["name"];
            protal.rate = Request.Form["rate"];
            protal.items = Request.Form["items"];
            protal.footer = Request.Form["footer"];
            try
            {
                if (!Directory.Exists(Server.MapPath("/protalimg/")))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath("/protalimg/"));
                }

                if (markpic != null && markpic.ContentLength > 0)
                {
                    string filename = string.Format("{0}_{1}", user.id, "markpic.") + markpic.FileName.Substring(markpic.FileName.LastIndexOf('.') + 1);
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../protalimg/"), filename);
                    protal.markPic = filename;
                    markpic.SaveAs(filePath);
                }

                if (logo != null && logo.ContentLength > 0)
                {
                    string filename = string.Format("{0}_{1}", user.id, "logo.") + logo.FileName.Substring(logo.FileName.LastIndexOf('.') + 1);
                    string filePath = Path.Combine(HttpContext.Server.MapPath("../protalimg/"), filename);

                    Bitmap myImage = new Bitmap(logo.InputStream);
                    //if (myImage.Width > 140)
                    //{
                    //    TempData["error"] = "图片宽度不能大于140";
                    //}
                    //else if (myImage.Height > 40)
                    //    TempData["error"] = "图片高度不能大于40";
                    //else
                    //{
                    myImage.Save(filePath);
                    protal.logo = filename;
                    //}
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                ViewData["errorMessage"] = "保存失败:"+e.Message;
            }
            ProtalService.GetInstance().Save(protal);
            ViewData["actionMessage"] = "保存成功!";
            return View("manage",protal);
        }
예제 #4
0
        /// <summary>
        /// 取得门户各页面的汇总数据
        /// plant和user只能传一个值,另外一个为null
        /// </summary>
        /// <param name="itemStr">数据项目</param>
        /// <param name="plant">电站</param>
        /// <param name="portal">门户</param>
        private void GetIcos(string itemStr, Plant plant, Protal portal)
        {
            User portalUser = UserUtil.getCurUser();
            //门户用户的管理者
            User parentUser = UserService.GetInstance().Get(portalUser.ParentUserId);
            if (string.IsNullOrEmpty(itemStr)) itemStr = ",";
            string[] items = itemStr.Split(',');
            IList<Hashtable> tableIcos = new List<Hashtable>();
            Hashtable ico = null;
            foreach (string item in items)
                if (string.IsNullOrEmpty(item) == false)
                {
                    if ((item.Equals(ProtalItems.temperature) || item.Equals(ProtalItems.sunshine)) && !(plant != null && !plant.isVirtualPlant))
                        continue;
                    if (item.Equals(ProtalItems.plantCount) && (plant != null && !plant.isVirtualPlant))
                        continue;
                    ico = new Hashtable();
                    ico.Add("id", item);
                    switch (item)
                    {
                        case ProtalItems.todayEnergy://今日发电
                            ico.Add(string.Format("data"), plant == null ? portalUser.DisplayTotalDayEnergy : plant.DisplayTotalDayEnergy);
                            ico.Add(string.Format("unit"), plant == null ? portalUser.TotalDayEnergyUnit : plant.TotalDayEnergyUnit);
                            ico.Add("displayName", ProtalItems.todayEnergyDisplayName);
                            break;
                        case ProtalItems.totalEnergy://总发电
                            ico.Add(string.Format("data"), plant == null ? portalUser.DisplayTotalEnergy : plant.DisplayTotalEnergy);
                            ico.Add(string.Format("unit"), plant == null ? portalUser.TotalEnergyUnit : plant.TotalEnergyUnit);
                            ico.Add("displayName", ProtalItems.totalEnergyDisplayName);
                            break;
                        case ProtalItems.power://功率
                            ico.Add(string.Format("data"), plant == null ? portalUser.DisplayTotalPower : plant.DisplayTodayTotalPower);
                            ico.Add(string.Format("unit"), plant == null ? portalUser.TotalPowerUnit : plant.TodayTotalPowerUnit);
                            ico.Add("displayName", ProtalItems.powerDisplayName);
                            break;
                        case ProtalItems.totalCo2://总CO2
                            ico.Add(string.Format("data"), plant == null ? StringUtil.formatDouble(portalUser.TotalReductiong, "0.00") : StringUtil.formatDouble(plant.Reductiong, "0.00"));
                            ico.Add(string.Format("unit"), plant == null ? portalUser.TotalReductiongUnit : plant.ReductiongUnit);
                            ico.Add("displayName", ProtalItems.totalCo2DisplayName);
                            break;
                        case ProtalItems.trees://等效树木
                            ico.Add(string.Format("data"), plant == null ? (portalUser.TotalEnergy / 40).ToString("0") : (plant.TotalEnergy / 40).ToString("0"));
                            ico.Add(string.Format("unit"), "棵");
                            ico.Add("displayName", ProtalItems.treesDisplayName);
                            break;
                        case ProtalItems.Income://收益
                            //先将门户的设置的收益转化率付给门户用户,即所有门户用户的采用同一个换算率
                            portalUser.revenueRate = StringUtil.stringtoDouble(portal.rate);
                            portalUser.currencies = "¥";
                            if (plant != null)
                            {
                                plant.revenueRate = StringUtil.stringtoDouble(portal.rate);
                                plant.currencies = parentUser.currencies;
                            }
                            ico.Add(string.Format("data"), plant == null ? portalUser.DisplayRevenue : plant.DisplayRevenue);
                            ico.Add(string.Format("unit"), parentUser.currencies);
                            ico.Add("displayName", ProtalItems.incomeDisplayName);
                            break;
                        case ProtalItems.sunshine://日照
                            ico.Add(string.Format("data"), plant == null ? "" : plant.Sunstrength==null?"":plant.Sunstrength.ToString());
                            ico.Add(string.Format("unit"), plant == null ? "" : MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_LINGT_CODE).unit);
                            ico.Add("displayName", ProtalItems.sunshineDisplayName);
                            break;
                        case ProtalItems.temperature://温度
                            double temper = plant.Temperature;
                            if (double.IsNaN(temper))
                            {
                                CityCodeService codeService = CityCodeService.GetInstance();
                                temper = codeService.GetTemperature(plant.city);
                            }
                            if (!double.IsNaN(temper))
                            {
                                if (parentUser != null && !parentUser.TemperatureType.ToLower().Equals("c"))
                                {
                                    temper = 32 + ((double)temper * 1.8);
                                }
                                ico.Add(string.Format("data", item), temper.ToString("0.0"));
                            }
                            else
                                ico.Add(string.Format("data", item), "");

                            ico.Add(string.Format("unit"), "°" + parentUser.TemperatureType);
                            ico.Add("displayName", ProtalItems.temperatureDispalyName);
                            break;
                        case ProtalItems.plantCount://电站数量
                            ico.Add("data", plant == null ? portalUser.allAssignedFactPlants.Count : plant.childs.Count);
                            ico.Add(string.Format("unit"), "个");
                            ico.Add("displayName", ProtalItems.plantCountDisplayName);
                            break;

                        case ProtalItems.installPower://安装功率
                            ico.Add("data", plant == null ? portalUser.assignedPlants.Sum(m => m.TotalDegignPower).ToString("0") : plant.TotalDegignPower.ToString("0"));
                            ico.Add(string.Format("unit"), "kWp");
                            ico.Add("displayName", ProtalItems.installPowerDisplayName);
                            break;

                        default:
                            break;

                    }
                    tableIcos.Add(ico);
                }

            ViewData["icos"] = tableIcos;
        }