Ejemplo n.º 1
0
 public ActionResult UpdateUser(User user)
 {
     if (ModelState.IsValid)
     {
         UserService userservice = UserService.GetInstance();
         user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
         try
         {
             userservice.save(user);
         }
         catch
         {
             //如果已经存在该采集器
             ModelState.AddModelError("Code", "the email is used");
         }
     }
     return RedirectToAction("Plants", "user");
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 所有当前用户的电站工作年份
 /// </summary>
 /// <param name="userId"></param>
 protected void FillAllPlantYears(User user)
 {
     IList<int> yearList = collectorYearDataService.GetWorkYears(user.displayPlants);
     IList<SelectListItem> plantYearsList = Currencies.FillYearItems(yearList);
     ViewData[ComConst.WorkYears] = plantYearsList;
 }
Ejemplo n.º 3
0
        public ActionResult Reg(User user)
        {
            int localZont = 0;
            int.TryParse(Request.Form["localZone"], out localZont);
            //创建语言服务
            LanguageService languageservice = LanguageService.GetInstance();
            //获取所有语言信息
            IList<Language> languages = languageservice.GetList();
            ViewData["languages"] = languages;
            User regUser = userService.GetUserByName(user.username);
            if (regUser == null)
            {
                int uid = 0;
                user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
                uid = userService.save(user);
                //注册用户默认管理员权限
                UserRoleService.GetInstance().Insert(new UserRole() { userId = uid, roleId = 3 });

                TempData[ComConst.User] = user;
                UserUtil.ResetLogin(user);
                //记录登录记录
                string ip = WebUtil.getClientIp(Request);
                LoginRecordService.GetInstance().Save(user.id, user.username, ip, localZont);

                return RedirectToAction("success", "auth");

            }
            else
            {

                ModelState.AddModelError("UserName", Resources.SunResource.REG_USERNAME_ERROR_INFO);
                return View();
            }
        }
Ejemplo n.º 4
0
 public int UpdateApplyCollectorCount(User user)
 {
     return _userDao.UpdateApplyCollectorCount(user);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 单个用户数据项数据
        /// </summary>
        /// <param name="plant">电站</param>
        /// <param name="dataItemCode">数据项代码</param>
        /// <param name="startTime">开始时间,日报表只取开始时间,周报表的时间格式为:yyyyMMdd-yyyyMMdd</param>
        /// <param name="endTime"></param>
        /// <returns>数据项为key</returns>
        private Hashtable getUserItemData(User user, int reportType, string startTime, string endTime)
        {
            Hashtable datahash = new Hashtable();
            double co2Rate = ItemConfigService.GetInstance().getCO2Config();
            switch (reportType)
            {
                //--------日报表数据 start--------------
                case DataReportType.TODAY_REPORT_CODE://日报表
                    //日发电量
                    float energy = CollectorMonthDayDataService.GetInstance().getDayData(user.plantUnits(), startTime);
                    //add发电量
                    datahash.Add(DataItem.TODAY_ENERGY, StringUtil.formatDouble(energy, "0.00") + " " + MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit);
                    //今日CO2减排
                    double co2reduce = Plant.computeCO2Reduce(co2Rate, energy);
                    datahash.Add(DataItem.TODAY_AVOIDED_CO2, StringUtil.formatDouble(co2reduce, "0.00") + " " + Plant.computeReduceUnit(co2Rate * energy));
                    //日收入
                    datahash.Add(DataItem.TODAY_REVENUE, user.currencies+" "+ Currencies.format(user.currencies, energy * user.revenueRate));

                    //累计总发电量
                    datahash.Add(DataItem.TODAY_TOTAL_ENERGY, user.DisplayTotalEnergy + " " + user.TotalEnergyUnit);
                    //累计总收入
                    datahash.Add(DataItem.TODAY_TOTAL_REVENUE, user.currencies+" "+user.DisplayRevenue);

                    //累计CO2减排
                    datahash.Add(DataItem.TODAY_TOTAL_AVOIDED_CO2, StringUtil.formatDouble(user.TotalReductiong, "0.00") + " " + user.TotalReductiongUnit);

                    return datahash;
                //--------周报表数据--------------
                case DataReportType.WEEK_REPORT_CODE:
                    //周发电量
                    float w_energy = 0;
                    double w_revenue = 0;
                    foreach (Plant plant in user.displayPlants)
                    {
                        Hashtable w_dataHash = CollectorMonthDayDataService.GetInstance().GetUnitBetweenMonthData(plant.allFactUnits, startTime, endTime);
                        float tmpenergy = 0;
                        foreach (Object o in w_dataHash.Values)
                        {
                            tmpenergy += StringUtil.stringtoFloat(o.ToString());
                        }
                        w_energy += tmpenergy;
                        w_revenue += tmpenergy * plant.revenueRate;
                    }

                    datahash.Add(DataItem.WEEK_ENERGY, StringUtil.formatDouble(w_energy, "0.00") + " " + MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit);
                    //周CO2减排
                    double co2reduce1 = Plant.computeCO2Reduce(co2Rate, w_energy);
                    datahash.Add(DataItem.WEEK_AVOIDED_CO2, co2reduce1 + " " + Plant.computeReduceUnit(co2Rate * w_energy));
                    //周收益
                    datahash.Add(DataItem.WEEK_REVENUE, user.currencies+" "+Currencies.format(user.currencies, w_revenue));
                    //累计总发电量
                    datahash.Add(DataItem.WEEK_TOTAL_ENERGY, user.DisplayTotalEnergy + " " + user.TotalEnergyUnit);
                    //累计总收入
                    datahash.Add(DataItem.WEEK_TOTAL_REVENUE, user.currencies+" "+user.DisplayRevenue);
                    //累计CO2减排
                    datahash.Add(DataItem.WEEK_TOTAL_AVOIDED_CO2, StringUtil.formatDouble(user.TotalReductiong, "0.00") + " " + user.TotalReductiongUnit);
                    return datahash;
                //--------月报表------------
                case DataReportType.MONTH_REPORT_CODE:
                    float m_energy = 0;
                    double m_revenue = 0;
                    foreach (Plant plant in user.displayPlants)
                    {
                        Hashtable m_dataHash = CollectorMonthDayDataService.GetInstance().GetUnitBetweenMonthData(plant.allFactUnits, startTime, endTime);
                        float tmpenergy = 0;
                        foreach (Object o in m_dataHash.Values)
                        {
                            tmpenergy += StringUtil.stringtoFloat(o.ToString());
                        }
                        m_energy += tmpenergy;
                        m_revenue += tmpenergy * plant.revenueRate;
                    }

                    datahash.Add(DataItem.MONTH_ENERGY, StringUtil.formatDouble(m_energy, "0.00") + " " + MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit);
                    //月CO2减排
                    double co2reduce_m = Plant.computeCO2Reduce(co2Rate, m_energy);
                    datahash.Add(DataItem.MONTH_AVOIDED_CO2, StringUtil.formatDouble(co2reduce_m, "0.00") + " " + Plant.computeReduceUnit(co2Rate * m_energy));
                    //月收益
                    datahash.Add(DataItem.MONTH_REVENUE,user.currencies+" "+ Currencies.format(user.currencies, m_revenue));
                    //累计总发电量
                    datahash.Add(DataItem.MONTH_TOTAL_ENERGY, user.DisplayTotalEnergy + " " + user.TotalEnergyUnit);
                    //累计总收入
                    datahash.Add(DataItem.MONTH_TOTAL_REVENUE, user.currencies+" "+user.DisplayRevenue);
                    //累计CO2减排
                    datahash.Add(DataItem.MONTH_TOTAL_AVOIDED_CO2, StringUtil.formatDouble(user.TotalReductiong, "0.00") + " " + user.TotalReductiongUnit);
                    return datahash;
                //------年报表-----------------
                case DataReportType.YEAR_REPORT_CODE:
                    int startYear = int.Parse(startTime.Substring(0, 4));
                    int endYear = int.Parse(endTime.Substring(0, 4));
                    float y_energy = 0;
                    double y_revenue = 0;
                    foreach (Plant plant in user.displayPlants)
                    {
                        Hashtable y_dataHash = CollectorYearMonthDataService.GetInstance().GetUnitBetweenYearData(user.plantUnits(), startYear, endYear);
                        float tmpenergy = 0;
                        foreach (Object o in y_dataHash.Values)
                        {
                            tmpenergy += StringUtil.stringtoFloat(o.ToString());
                        }
                        y_energy += tmpenergy;
                        y_revenue += tmpenergy * plant.revenueRate;
                    }

                    datahash.Add(DataItem.YEAR_ENERGY, StringUtil.formatDouble(y_energy, "0.00") + " " + MonitorType.getMonitorTypeByCode(MonitorType.PLANT_MONITORITEM_ENERGY_CODE).unit);
                    //年CO2减排

                    double co2reduce_y = Plant.computeCO2Reduce(co2Rate,y_energy);
                    datahash.Add(DataItem.YEAR_AVOIDED_CO2, StringUtil.formatDouble(co2reduce_y, "0.00") + " " + Plant.computeReduceUnit(co2Rate * y_energy));
                    //年收益
                    datahash.Add(DataItem.YEAR_REVENUE, user.currencies+" "+Currencies.format(user.currencies, y_revenue));
                    //累计总发电量
                    datahash.Add(DataItem.YEAR_TOTAL_ENERGY, user.DisplayTotalEnergy + " " + user.TotalEnergyUnit);
                    //累计总收入
                    datahash.Add(DataItem.YEAR_TOTAL_REVENUE, user.currencies+" "+user.DisplayRevenue);
                    //累计CO2减排
                    datahash.Add(DataItem.YEAR_TOTAL_AVOIDED_CO2, StringUtil.formatDouble(user.TotalReductiong, "0.00") + " " + user.TotalReductiongUnit);
                    return datahash;
                //------总量报表-----------------
                case DataReportType.TOTAL_REPORT_CODE:
                    //累计总发电量
                    datahash.Add(DataItem.TOTAL_ENERGY, user.DisplayTotalEnergy + " " + user.TotalEnergyUnit);
                    //累计总收入
                    datahash.Add(DataItem.TOTAL_REVENUE, user.currencies+" "+user.DisplayRevenue);
                    //累计CO2减排
                    datahash.Add(DataItem.TOTAL_AVOIDED_CO2, StringUtil.formatDouble(user.TotalReductiong, "0.00") + " " + user.TotalReductiongUnit);
                    return datahash;
                default:
                    return datahash;
            }
        }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            //先从cookie里面判断是否记住我即需要自动登录
            if (System.Web.HttpContext.Current.Request.Cookies["a_login"] != null)
            {
                HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["a_login"];
                User user = new User() { username = cookie.Values["un"], password = cookie.Values["pwd"] };
                System.Web.HttpContext.Current.Session[ComConst.validatecode] = "1111";
                Index(user, true, "0", "1111");
            }

            if (UserUtil.isLogined())
            {
                User loginUser = UserUtil.getCurUser();
                if(loginUser.username.Equals("admin"))
                    return RedirectToAction(@"users", "admin");
                else
                    //判断是否完成注册的三个步骤
                    return adjustUserPosition(loginUser);
            }

            loadIndexData();
            return View();
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 保存用户
 /// </summary>
 /// <param name="user">用户对象</param>
 public int save(User user)
 {
     if (user.id == 0)//新增
     {
         int success = _userDao.Insert(user);
         if (success > 0)//创建系统报表
             ReportService.GetInstance().batchCreateSysRunReport(user.id, 0);
         return success;
     }
     else
     {
         return _userDao.Update(user);
     }
 }
Ejemplo n.º 8
0
        public ActionResult Index(User user, bool autoLogin, string localZone, string validatecode)
        {
            float lzone = 0;
            try
            {
                float.TryParse(localZone, out lzone);
            }catch (Exception ee){
                Console.WriteLine("转换时区异常:"+ee.Message);
                try
                {
                    LogUtil.error("登录转换时区异常: " + user==null?"":user.username + ee.Message);
                }
                catch (Exception ee2)
                {
                    Console.WriteLine("写日志文件异常:" + ee2.Message);
                }
            }

            //验证码验证提示
            try{
                if (validatecode!=null && ValidateCodeUtil.Validated(validatecode) == false)
                {
                    ModelState.AddModelError("Error", "验证码输入错误!");
                    System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                    loadIndexData();
                    return View(user);
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("验证码验证异常:" + ee.Message);
                ModelState.AddModelError("Error", "验证码验证错误!");
                System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                loadIndexData();
                return View(user);
            }

            //验证用户名输入项
            if (user == null || user.username == null) {
                ModelState.AddModelError("Error", "请输入用户名!");
                System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                loadIndexData();
                return View(user);
            }

            //首先认为是电站用户登录
            User loginUser = userService.GetUserByName(user.username);

            if (loginUser == null || !loginUser.depassword.Equals(user.password))
            {
                //判断是否管理员
                Manager manager = managerService.GetUserByName(user.username);
                if (manager != null)
                {
                    if (manager.depassword.Equals(user.password))
                    {
                        manager = managerService.GetManagerByLocked(user.username);
                        if (manager != null)
                        {
                            if (autoLogin)
                                SetCookie(user.username, manager.password);
                            base.mlogin(manager);

                            //这里admin 默认所有权限
                            if (manager.username.Equals("admin"))
                                return RedirectToAction(@"users", "admin");
                            if (manager.roles == null || manager.roles.Count == 0)
                                return Content("access denied");
                            try
                            {
                                foreach (AdminUserRole auserRole in manager.roles)
                                {
                                    if (auserRole.role != null)
                                    {

                                        IList<AdminControllerAction> acas = AdminControllerActionServices.GetInstance().GetList();
                                        IList<AdminControllerAction> allow = AdminRole.AllowActionsList(acas, auserRole.role.actions);
                                        foreach (AdminControllerAction aca in allow)
                                        {
                                            if (aca.isAutoRedirect)
                                                return RedirectToAction(@aca.actionName, aca.controllerName);
                                        }
                                    }
                                }
                            }
                            catch (Exception ee3) { }
                        }
                        else
                        {
                            System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                            ModelState.AddModelError("Error", Resources.SunResource.MANAGER_LOGIN_LOCKED);
                            loadIndexData();
                            return View(user);
                        }
                    }
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                    ModelState.AddModelError("Error", Resources.SunResource.HOME_INDEX_VALIDATED);
                    loadIndexData();
                    return View(user);
                }
            }
            else
            {
                if (loginUser.depassword.Equals(user.password))
                {
                    //注释  不根据用户语言设置默认语言
                    //CultureInfo cultureInfo = null;
                    //if (loginUser.Language == null)
                    //    loginUser.Language = new Language() { codename = "en-us" };
                    //cultureInfo = new CultureInfo(loginUser.Language.codename);
                    //Session["Culture"] = cultureInfo;
                    //Thread.CurrentThread.CurrentCulture = cultureInfo;
                    //Session["display"] = loginUser.Language.name;

                    if (autoLogin)
                        SetCookie(user.username, loginUser.depassword);
                    UserUtil.login(loginUser);

                    //记录登录记录
                    try
                    {
                        string ip = WebUtil.getClientIp(Request);
                        LoginRecordService.GetInstance().Save(loginUser.id, loginUser.username, ip, lzone);
                    }
                    catch (Exception ee) {
                        Console.WriteLine("记录ip错误:" + ee.Message);
                    }

                    //判断是否完成注册的三个步骤
                    return adjustUserPosition(loginUser);
                }
            }
            //采集器管理员界面
            if (user.username.Equals("manuser") && user.depassword.Equals("sungrow2011"))
            {
                Session["collectorAddedEnable"] = true;
                return RedirectToAction("admin", "admin");
            }
            //登录失败
            ModelState.AddModelError("Error", "username or password is not validated");
            System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);

            loadIndexData();
            return View(user);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 判断非管理员用户登录重定向位置
 /// </summary>
 /// <param name="loginUser"></param>
 /// <returns></returns>
 private ActionResult adjustUserPosition(User loginUser)
 {
     //判断是否完成注册的三个步骤
     //第二步没有完成依据  用户下没有电站
     //第三步完成依据 任何电站下没有设备
     try
     {
         if (loginUser.plants.Count.Equals(0))
             return Redirect("/newregister/addplant");
         if (!loginUser.isBindUnit)
             return Redirect("/newregister/addunit");
         if (loginUser.plantUsers.Count == 1)
             return RedirectToAction("overview", "plant", new { @id = base.FirstPlant.id });
         else
         {
             if (loginUser.plantUsers.Count > 0)
             {
                 //用户登陆默认显示选中左边导航栏中的"所有电站",右边窗口打开"电站列表"页面。
                 return RedirectToAction("allplants", "user");
                 // return RedirectToAction("overview", "user");
             }
             else
             {
                 return RedirectToAction("addoneplant", "user");
             }
         }
     }
     catch (Exception ee)
     {
         Console.WriteLine("重定向具体页面判断异常:" + ee.Message);
         //用户登陆默认显示选中左边导航栏中的"所有电站",右边窗口打开"电站列表"页面。
         return RedirectToAction("allplants", "user");
     }
 }
Ejemplo n.º 10
0
        public ActionResult Login(User user)
        {
            if (string.IsNullOrEmpty(user.username) == false)
            {
                User loginUser = userService.GetUserByName(user.username);
                Session["Culture"] = new CultureInfo("en-us");

                if (loginUser != null && loginUser.depassword.Equals(user.password))
                {
                    if (loginUser.Language != null && string.IsNullOrEmpty(loginUser.Language.codename) == false)
                    {
                        Session["Culture"] = new CultureInfo(loginUser.Language.codename.ToLower());
                        Session["lang"] = loginUser.Language.codename.ToLower();
                    }
                    string sid = Session.SessionID;
                    Session[sid] = loginUser.id;
                    return Redirect(string.Format("/wap/overview/?sid={0}", sid));

                }

            }
            ViewData["error"] = "Username or password is not validated";
            return PartialView("index");
        }
Ejemplo n.º 11
0
 public PlantUserVO(User user, Role role)
 {
     this.user = user;
     this.plantRole = role;
 }
Ejemplo n.º 12
0
 public static void ResetLogin(User user)
 {
     login(user);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 
 /// 设置用户登录状态
 /// author:hbqian
 /// </summary>
 /// <param name="user"></param>
 public static void login(User user)
 {
     System.Web.HttpContext.Current.Session[ComConst.User] = user.id;
     System.Web.HttpContext.Current.Application[ComConst.User] = user.id;
 }
Ejemplo n.º 14
0
        public ActionResult Save(User user)
        {
            if (user.id > 0)
            {
                UserService userService = UserService.GetInstance();
                int languageId = userService.GetLanguageIdById(UserUtil.getCurUser().id);
                //创建语言服务
                LanguageService languageservice = LanguageService.GetInstance();
                //获取所有语言信息
                Language language = languageservice.GetNameByLanguageId(languageId);
                IList<Language> languages = languageservice.GetList();
                ViewData["lang"] = language;
                ViewData["languages"] = languages;
                UserService userservice = UserService.GetInstance();
                ViewData["langs"] = LanguageService.GetInstance().GetList();
                base.GetLanguage();

                IList<CommonInfo> currencies = CommonInfoService.GetInstance().GetList(new CommonInfo() { pid = CommonInfo.Currency });
                IList<SelectListItem> items = new List<SelectListItem>();
                foreach (CommonInfo currency in currencies)
                {
                    items.Add(new SelectListItem() { Text = string.Format("{0}:{1}", currency.code, currency.name), Value = currency.code });
                }

                ViewData["currencies"] = items;
                return RedirectToAction("addplant", "newregister");

            }
            else
            {
                int localZont = 0;
                int.TryParse(Request.Form["localZone"], out localZont);
                //创建语言服务
                LanguageService languageservice = LanguageService.GetInstance();
                //获取所有语言信息
                IList<Language> languages = languageservice.GetList();
                ViewData["languages"] = languages;
                User regUser = UserService.GetInstance().GetUserByName(user.username);
                if (regUser == null)
                {
                    int uid = 0;
                    user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
                    uid = UserService.GetInstance().save(user);
                    //注册用户默认管理员权限
                    UserRoleService.GetInstance().Insert(new UserRole() { userId = uid, roleId = 3 });

                    TempData[ComConst.User] = user;
                    UserUtil.ResetLogin(user);
                    //记录登录记录
                    string ip = WebUtil.getClientIp(Request);
                    LoginRecordService.GetInstance().Save(user.id, user.username, ip, localZont);

                    return RedirectToAction("addplant", "newregister");

                }
                else
                {

                    ModelState.AddModelError("UserName", Resources.SunResource.REG_USERNAME_ERROR_INFO);
                    return View("register");
                }
            }
        }
Ejemplo n.º 15
0
 public int GetUserNoConfirmLogsCount(User user)
 {
     string ids = string.Empty;
     int userTotalLogsCount = 0;
     foreach (Plant plant in user.displayPlants)
     {
         userTotalLogsCount += GetPlantNoConfirmLogsCount(plant);
     }
     return userTotalLogsCount;
 }
Ejemplo n.º 16
0
        /// <summary>
        /// 判断非管理员用户登录重定向位置
        /// </summary>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        private ActionResult adjustUserPosition(User loginUser)
        {
            //判断是否完成注册的三个步骤
            //第二步没有完成依据  用户下没有电站
            //第三步完成依据 任何电站下没有设备
            try
            {
                //用户关联的电站
                IList<Plant> plants = loginUser.relatedPlants;
                if (plants.Count == 0)
                    return Redirect("/newregister/addplant");

                //如果只有一个电站,而且这个电站是用户自己创建的要判断是器绑定单元了
                if (plants.Count == 1 && plants[0].userID == loginUser.id)
                {
                    if (!loginUser.isBindUnit)
                        return Redirect("/newregister/addunit");
                }

                //然后判断用户关联的电站是否
                if (plants.Count == 1)
                {
                    return RedirectToAction("overview", "plant", new { @id = plants[0].id });
                }
                else
                {
                    if (plants.Count > 1)
                    {
                        //用户登陆默认显示选中左边导航栏中的"所有电站",右边窗口打开"电站列表"页面。
                        //Session["firstLogin"] = true;
                        return RedirectToAction("allplants", "user");
                    }
                    else
                    {
                        return RedirectToAction("addoneplant", "user");
                    }
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("重定向具体页面判断异常:" + ee.Message);
                //用户登陆默认显示选中左边导航栏中的"所有电站",右边窗口打开"电站列表"页面。
                return RedirectToAction("allplants", "user");
            }
        }