public ActionResult AjaxGetPermisionList()
        {
            List<dynamic> res = new List<dynamic>();
            try
            {
                using (MemberShipDataContext context = new MemberShipDataContext())
                {
                    List<UserInfo> users = (from c in context.UserProfiles
                                            join d in context.UnitsInfos
                                            on c.UnitNum equals d.UnitNum
                                            where c.LabourNum.Equals(9807) || c.LabourNum.Equals(98012)
                                            select new UserInfo { ID = c.ID, UserName = c.UserName, RealName = c.RealName, UnitName = d.UnitName }).OrderBy(r => r.UserName).ToList<UserInfo>();
                    foreach (UserInfo usr in users)
                    {
                        bool stationManage = Roles.IsUserInRole(usr.UserName, "stationManage");
                        bool storageEquipmentStatus = Roles.IsUserInRole(usr.UserName, "storageEquipmentStatus");
                        bool storageEquipmentManage = Roles.IsUserInRole(usr.UserName, "storageEquipmentManage");
                        bool networdManage = Roles.IsUserInRole(usr.UserName, "networdManage");

                        res.Add(new { usr.UnitName, usr.UserName, usr.RealName, stationManage, storageEquipmentStatus, storageEquipmentManage, networdManage });
                    }
                }
                return Json(res, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json(res, JsonRequestBehavior.AllowGet);
            }
        }
Exemple #2
0
        public static bool CheckUserHasPermision(string userName, string permissionName)
        {
            List<Role> roleList = new List<Role>();
            List<PermissionsInRoles> permissionsInRolesList = new List<PermissionsInRoles>();
            using (MemberShipDataContext db = new MemberShipDataContext())
            {
                roleList = db.Roles.AsEnumerable<Role>().ToList<Role>();

            }

            using (MemberShipDataContext db = new MemberShipDataContext())
            {
                permissionsInRolesList = db.PermissionsInRoles
                                            .Include("Permission").Include("Role")
                                            .AsEnumerable<PermissionsInRoles>().ToList<PermissionsInRoles>();
            }

            string[] currentRoles = Roles.GetRolesForUser(userName);
            foreach (var roleName in currentRoles)
            {
                List<Permission> permissionList = permissionsInRolesList.Where(e => e.Role.RoleName == roleName)
                                                                            .Select(e => e.Permission).ToList<Permission>();

                foreach (var permission in permissionList)
                {
                    if (permission.PermissionName == permissionName)
                    {
                        return true;
                    }
                }
            }

            return false;
        }
Exemple #3
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password))
                {
                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(model.UserName)).FirstOrDefault();
                        if (null != usr)
                        {
                            HttpCookie cookie = new HttpCookie("User");
                            cookie.Values.Add("RealName", HttpUtility.UrlEncode(usr.RealName, System.Text.Encoding.UTF8));
                            cookie.Values.Add("ID", HttpUtility.UrlEncode(usr.ID.ToString(), System.Text.Encoding.UTF8));
                            cookie.Values.Add("UnitNum", HttpUtility.UrlEncode(usr.UnitNum.ToString(), System.Text.Encoding.UTF8));

                            cookie.Expires.AddHours(3);
                            Response.Cookies.Add(cookie);
                            using (HelperDataContext onlinecontext = new HelperDataContext())
                            {
                                UserAction newaction = new UserAction();
                                newaction.ID = usr.ID;
                                newaction.RealName = usr.RealName;
                                newaction.ActionName = "Login";
                                newaction.CreateTime = DateTime.Now;
                                newaction.LastModifyTime = newaction.CreateTime;
                                UserAction action = onlinecontext.UserActions.Where(c => c.ActionName.Equals(newaction.ActionName) && c.ID.Equals(newaction.ID) && c.CreateTime.Year.Equals(newaction.CreateTime.Year) && c.CreateTime.Month.Equals(newaction.CreateTime.Month) && c.CreateTime.Day.Equals(newaction.CreateTime.Day)).FirstOrDefault();
                                if (null == action)
                                {
                                    onlinecontext.UserActions.Add(newaction);
                                }
                                else
                                {
                                    action.LastModifyTime = newaction.LastModifyTime;
                                }
                                onlinecontext.SaveChanges();
                            }
                        }
                        else
                        {
                            WebSecurity.Logout();
                            return RedirectToAction("Login");
                        }
                        return RedirectToAction("Front", "Admin");
                    }
                }
                ModelState.AddModelError("", "用户名或密码错误");
                return View(model);
            }
            catch
            {
                WebSecurity.Logout();
                return RedirectToAction("Login", "Admin");
            }
        }
Exemple #4
0
        public List<SelectListItem> GetUnitsList()
        {
            List<SelectListItem> List = new List<SelectListItem>();

            using (MemberShipDataContext context = new MemberShipDataContext())
            {
                List<UnitsInfo> units = context.UnitsInfos.ToList<UnitsInfo>();
                foreach (UnitsInfo unit in units)
                {
                    List.Add(new SelectListItem { Text = unit.UnitName, Value = unit.UnitNum.ToString() });
                }
            }
            return List;
        }
Exemple #5
0
        public List<SelectListItem> GetLaboursList()
        {
            List<SelectListItem> List = new List<SelectListItem>();

            using (MemberShipDataContext context = new MemberShipDataContext())
            {
                List<LaboursInfo> labours = context.LaboursInfos.ToList<LaboursInfo>();
                foreach (LaboursInfo labour in labours)
                {
                    List.Add(new SelectListItem { Text = labour.LabourName, Value = labour.LabourNum.ToString() });
                }
            }
            return List;
        }
Exemple #6
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password))
                {
                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(model.UserName)).FirstOrDefault();
                        if (null != usr)
                        {
                            HttpCookie cookie = new HttpCookie("User");
                            cookie.Values.Add("RealName", HttpUtility.UrlEncode(usr.RealName, System.Text.Encoding.UTF8));
                            cookie.Values.Add("ID", HttpUtility.UrlEncode(usr.ID.ToString(), System.Text.Encoding.UTF8));

                            using (InfoManageDataContext infocontext = new InfoManageDataContext())
                            {
                                if (Roles.IsUserInRole(usr.UserName, AllConsts.adminRole))
                                {
                                    Response.Cookies.Add(cookie);
                                    return RedirectToAction("Front", "ManageAdmin");
                                }
                                else
                                {
                                    StoragesInfo info = infocontext.StoragesInfos.Where(c => c.StoragesInfoID.Equals(usr.UnitNum)).FirstOrDefault();
                                    cookie.Values.Add("UnitNum", HttpUtility.UrlEncode(usr.UnitNum.ToString(), System.Text.Encoding.UTF8));
                                    cookie.Values.Add("UnitName", HttpUtility.UrlEncode(info.StoragesInfoName, System.Text.Encoding.UTF8));

                                    cookie.Expires.AddHours(3);
                                    Response.Cookies.Add(cookie);
                                    using (InfoManageDataContext onlinecontext = new InfoManageDataContext())
                                    {
                                        UserAction newaction = new UserAction();
                                        newaction.ID = usr.ID;
                                        newaction.RealName = usr.RealName;
                                        newaction.ActionName = "Login";
                                        newaction.CreateTime = DateTime.Now;
                                        newaction.LastModifyTime = newaction.CreateTime;
                                        onlinecontext.UserActions.Add(newaction);
                                        onlinecontext.SaveChanges();
                                    }
                                }
                            }
                        }
                        else
                        {
                            WebSecurity.Logout();
                            return RedirectToAction("Login");
                        }
                        return RedirectToAction("Front", "Admin");
                    }
                }
                ModelState.AddModelError("", "用户名或密码错误");
                return View(model);
            }
            catch
            {
                WebSecurity.Logout();
                return RedirectToAction("Login", "Admin");
            }
        }
 public ActionResult AjaxRemoveUserManage(string UserName)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             if (usr != null)
             {
                 usr.UserName = AllConsts.NULL_USER;
                 usr.LabourNum = int.Parse(AllConsts.NULL_USER);
                 usr.UnitNum = int.Parse(AllConsts.NULL_USER);
                 usr.pword = AllConsts.NULL_USER;
                 context.SaveChanges();
             }
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult AjaxGetUserPermisionModify(
     string UserName,
     bool stationManage,
     bool storageEquipmentStatus,
     bool storageEquipmentManage,
     bool networdManage)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             if (usr != null)
             {
                 if (stationManage && !Roles.IsUserInRole(usr.UserName, "stationManage"))
                     Roles.AddUserToRole(usr.UserName, "stationManage");
                 if (!stationManage && Roles.IsUserInRole(usr.UserName, "stationManage"))
                     Roles.RemoveUserFromRole(usr.UserName, "stationManage");
                 if (storageEquipmentStatus && !Roles.IsUserInRole(usr.UserName, "storageEquipmentStatus"))
                     Roles.AddUserToRole(usr.UserName, "storageEquipmentStatus");
                 if (!storageEquipmentStatus && Roles.IsUserInRole(usr.UserName, "storageEquipmentStatus"))
                     Roles.RemoveUserFromRole(usr.UserName, "storageEquipmentStatus");
                 if (storageEquipmentManage && !Roles.IsUserInRole(usr.UserName, "storageEquipmentManage"))
                     Roles.AddUserToRole(usr.UserName, "storageEquipmentManage");
                 if (!storageEquipmentManage && Roles.IsUserInRole(usr.UserName, "storageEquipmentManage"))
                     Roles.RemoveUserFromRole(usr.UserName, "storageEquipmentManage");
                 if (networdManage && !Roles.IsUserInRole(usr.UserName, "networdManage"))
                     Roles.AddUserToRole(usr.UserName, "networdManage");
                 if (!networdManage && Roles.IsUserInRole(usr.UserName, "networdManage"))
                     Roles.RemoveUserFromRole(usr.UserName, "networdManage");
                 return Json("OK", JsonRequestBehavior.AllowGet);
             }
             return Json("NO", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult AjaxGetUserPermisionDetail(string UserName)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             //UserInfo usr = (UserInfo)(from c in context.UserProfiles
             //                          join d in context.UnitsInfos
             //                          on c.UnitNum equals d.UnitNum
             //                          where c.UserName.Equals(UserName)
             //                          select new UserInfo { ID = c.ID, UserName = c.UserName, RealName = c.RealName, UnitName = d.UnitName });
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             bool stationManage = Roles.IsUserInRole(usr.UserName, "stationManage");
             bool storageEquipmentStatus = Roles.IsUserInRole(usr.UserName, "storageEquipmentStatus");
             bool storageEquipmentManage = Roles.IsUserInRole(usr.UserName, "storageEquipmentManage");
             bool networdManage = Roles.IsUserInRole(usr.UserName, "networdManage");
             return Json(new { usr.UserName, usr.RealName, stationManage, storageEquipmentStatus, storageEquipmentManage, networdManage }, JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("", JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult AjaxGetUserDetail(string UserName)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             return Json(new { usr.UserName, usr.RealName, usr.UnitNum }, JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("", JsonRequestBehavior.AllowGet);
     }
 }
 public ActionResult AjaxGetUnitNums()
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             List<UnitsInfo> result = context.UnitsInfos.ToList<UnitsInfo>();
             return Json(result, JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("", JsonRequestBehavior.AllowGet);
     }
 }
Exemple #12
0
        public ActionResult AjaxGetLoginDate(string SDate, int UnitNum)
        {
            try
            {
                using (MemberShipDataContext membercontext = new MemberShipDataContext())
                {
                    DateTime sTime = DateTime.ParseExact(SDate, AllConsts.MONTY_DAY, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                    List<moniterMan> res = new List<moniterMan>();
                    List<UserProfile> users = membercontext.UserProfiles.Where(c => c.UnitNum.Equals(UnitNum)).ToList<UserProfile>();
                    foreach (UserProfile usr in users)
                    {
                        using (InfoManageDataContext infocontext = new InfoManageDataContext())
                        {
                            UserAction action1 = infocontext.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.CreateTime.Day.Equals(sTime.Day) && 0 <= c.CreateTime.Hour && c.CreateTime.Hour < 12).FirstOrDefault();
                            UserAction action2 = infocontext.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.CreateTime.Day.Equals(sTime.Day) && 12 <= c.CreateTime.Hour && c.CreateTime.Hour <= 23).FirstOrDefault();

                            moniterMan man = new moniterMan();
                            man.RealName = usr.RealName;
                            if (action1 != null)
                            {
                                man.AM = action1.CreateTime.ToString();
                            }
                            else
                            {
                                man.AM = "未登陆";
                            }
                            if (action2 != null)
                            {
                                man.PM = action2.CreateTime.ToString();
                            }
                            else
                            {
                                man.PM = "未登陆";
                            }
                            res.Add(man);
                        }
                    }
                    return Json(res, JsonRequestBehavior.AllowGet);
                }
            }
            catch
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult AjaxAddNewStation(
            string StationNum,
            string StationBuildDate,
            string StationName,
            string StationAdrass,
            int StoragesInfoID,
            int transportManageType,
            int StationClass,
            int ElementsNum,
            int samplingMod,
            string windDirectorHigh,
            string windSpeederHigh,
            string StationLetterCode,
            string StationType,
            string StationManufacturer,
            string StationLongitude,
            string StationLatitude,
            string StationAltitude,
            string SIM,
            string IP,
            int powerSupplyMod,
            string BatteryStartDate,
            string SIMRenewFeeDate,
            string Operator)
        {
            try
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["User"];
                    ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
                    int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));

                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Find(id);
                        if (null != usr)
                        {
                            using (InfoManageDataContext InfoManageContext = new InfoManageDataContext())
                            {
                                Station newStation = new Station();
                                newStation.StationNum = StationNum.Trim();
                                newStation.StationBuildDate = DateTime.ParseExact(StationBuildDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newStation.StationName = StationName;
                                newStation.StationAdrass = StationAdrass;
                                newStation.StoragesInfoID = StoragesInfoID;
                                newStation.transportManageType = transportManageType;
                                newStation.StationClass = StationClass;
                                newStation.StationLetterCode = StationLetterCode;
                                newStation.StationType = StationType;
                                newStation.StationManufacturer = StationManufacturer;
                                newStation.StationLongitude = StationLongitude;
                                newStation.StationLatitude = StationLatitude;
                                newStation.StationAltitude = StationAltitude;
                                newStation.ElementsNum = ElementsNum;
                                newStation.samplingMod = samplingMod;
                                newStation.windDirectorHigh = windDirectorHigh;
                                newStation.windSpeederHigh = windSpeederHigh;
                                newStation.SIM = SIM;
                                newStation.IP = IP;
                                newStation.powerSupplyMod = powerSupplyMod;
                                newStation.Operator = Operator;
                                newStation.LastModifier = newStation.Operator;
                                newStation.LastModifyDate = DateTime.Now;
                                if (newStation.powerSupplyMod == (int)AllConsts.powerSupplyMod.SolarEnergy)
                                    newStation.BatteryStartDate = DateTime.ParseExact(BatteryStartDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                else
                                    newStation.BatteryStartDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                if (newStation.SIM.Trim() != "")
                                    newStation.SIMRenewFeeDate = DateTime.ParseExact(SIMRenewFeeDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                else
                                    newStation.SIMRenewFeeDate = DateTime.ParseExact(AllConsts.MAX_DATE_HOUR_MINUTE, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                Station oldstation = InfoManageContext.Stations.Where(c => c.StationNum.Equals(newStation.StationNum)).FirstOrDefault();
                                if (oldstation == null)
                                    InfoManageContext.Stations.Add(newStation);
                                else
                                {
                                    oldstation.StationBuildDate = newStation.StationBuildDate;
                                    oldstation.StationName = newStation.StationName;
                                    oldstation.StationAdrass = newStation.StationAdrass;
                                    oldstation.transportManageType = newStation.transportManageType;
                                    oldstation.StationClass = newStation.StationClass;
                                    oldstation.StationLetterCode = newStation.StationLetterCode;
                                    oldstation.StationType = newStation.StationType;
                                    oldstation.StationManufacturer = newStation.StationManufacturer;
                                    oldstation.StationLongitude = newStation.StationLongitude;
                                    oldstation.StationLatitude = newStation.StationLatitude;
                                    oldstation.StationAltitude = newStation.StationAltitude;
                                    oldstation.ElementsNum = newStation.ElementsNum;
                                    oldstation.samplingMod = newStation.samplingMod;
                                    oldstation.windDirectorHigh = newStation.windDirectorHigh;
                                    oldstation.windSpeederHigh = newStation.windSpeederHigh;
                                    oldstation.SIM = newStation.SIM;
                                    oldstation.IP = newStation.IP;
                                    oldstation.powerSupplyMod = newStation.powerSupplyMod;
                                    oldstation.Operator = newStation.Operator;
                                    oldstation.BatteryStartDate = newStation.BatteryStartDate;
                                    oldstation.SIMRenewFeeDate = newStation.SIMRenewFeeDate;
                                    oldstation.StoragesInfoID = StoragesInfoID;
                                    oldstation.LastModifier = oldstation.Operator;
                                    oldstation.LastModifyDate = DateTime.Now;
                                }

                                UserAction newaction = new UserAction();
                                newaction.ID = usr.ID;
                                newaction.RealName = usr.RealName;
                                newaction.ActionName = "AjaxSetTurnInStorageList";
                                newaction.CreateTime = DateTime.Now;
                                newaction.LastModifyTime = newaction.CreateTime;
                                InfoManageContext.UserActions.Add(newaction);

                                InfoManageContext.SaveChanges();
                                return Json("OK", JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                }
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
        }
Exemple #14
0
        public ActionResult AjaxUserMonthUsageNum(int StoragesInfoID, string SDate)
        {
            if (SDate.Trim().Equals(""))
                return Json("", JsonRequestBehavior.AllowGet);
            DateTime sTime = DateTime.ParseExact(SDate, AllConsts.YEAR_MONTH, System.Globalization.DateTimeFormatInfo.CurrentInfo);

            try
            {

                using (MemberShipDataContext membercontext = new MemberShipDataContext())
                {
                    List<UserProfile> users = membercontext.UserProfiles.Where(c => c.UnitNum.Equals(StoragesInfoID)).ToList<UserProfile>();
                    List<dynamic> res = new List<dynamic>();
                    foreach (UserProfile usr in users)
                    {
                        int Login = 0, MonitorStation = 0, MonitorNetwork = 0, EquipmentManagement = 0, Analysis = 0, storageEquipmentStatus = 0, storageEquipmentManage = 0, SoftWareShare = 0;
                        using (InfoManageDataContext context = new InfoManageDataContext())
                        {
                            //Login[i] = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime < end && c.CreateTime > start && c.ActionName.Equals("Login")).Count();
                            MonitorStation = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("MonitorStation")).Count();
                            MonitorNetwork = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("MonitorNetwork")).Count();
                            EquipmentManagement = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("EquipmentManagement")).Count();
                            Analysis = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("Analysis")).Count();
                            storageEquipmentStatus = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("storageEquipmentStatus")).Count();
                            storageEquipmentManage = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(sTime.Year) && c.CreateTime.Month.Equals(sTime.Month) && c.ActionName.Equals("storageEquipmentManage")).Count();
                            //SoftWareShare[i] = context.UserActions.Where(c => c.ID.Equals(usr.ID) && c.CreateTime < end && c.CreateTime > start && c.ActionName.Equals("SoftWareShare")).Count();
                        }
                        res.Add(new { usr.RealName, MonitorStation, MonitorNetwork, EquipmentManagement, Analysis, storageEquipmentStatus, storageEquipmentManage });
                    }
                    return Json(res, JsonRequestBehavior.AllowGet);
                }
            }
            catch
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }
Exemple #15
0
 public ActionResult AjaxSetImportantStatement(string Requester, string RequestText, string RequestDate)
 {
     try
     {
         using (InfoManageDataContext context = new InfoManageDataContext())
         {
             using (MemberShipDataContext member = new MemberShipDataContext())
             {
                 UserProfile usr = member.UserProfiles.Where(c => c.RealName.Equals(Requester)).FirstOrDefault();
                 if (usr != null)
                 {
                     ImportantStatement newRequest = new ImportantStatement();
                     newRequest.Requester = Requester;
                     newRequest.RequestText = RequestText;
                     newRequest.RequestDate = DateTime.ParseExact(RequestDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                     newRequest.StoragesInfoID = usr.UnitNum;
                     //ImportantStatement olodRequest = context.ImportantStatements.Where(c => c.Requester.Equals(Requester) && c.RequestDate.Year.Equals(DateTime.Now.Year) && c.RequestDate.Month.Equals(DateTime.Now.Month) && c.RequestDate.Day.Equals(DateTime.Now.Day) && c.RequestDate.Hour.Equals(DateTime.Now.Hour) && c.RequestDate.Minute.Equals(DateTime.Now.Minute)).FirstOrDefault();
                     //if (olodRequest == null)
                     //{
                     context.ImportantStatements.Add(newRequest);
                     //}
                     //else
                     //{
                     //    olodRequest.Requester = newRequest.Requester;
                     //    olodRequest.RequestText = newRequest.RequestText;
                     //    olodRequest.ToUnit = newRequest.ToUnit;
                     //}
                     context.SaveChanges();
                     return Json("OK", JsonRequestBehavior.AllowGet);
                 }
             }
             return Json("NO", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
Exemple #16
0
 public ActionResult AjaxGetUsrNames(int StoragesInfoID)
 {
     try
     {
         List<dynamic> res = new List<dynamic>();
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             List<UserProfile> stations123 = context.UserProfiles.Where(c => c.UnitNum.Equals(StoragesInfoID)).ToList<UserProfile>();
             foreach (UserProfile sta in stations123)
             {
                 res.Add(new { sta.RealName, sta.ID });
             }
         }
         return Json(res, JsonRequestBehavior.AllowGet);
     }
     catch
     {
         return Json("", JsonRequestBehavior.AllowGet);
     }
 }
Exemple #17
0
        public ActionResult AjaxGetMonthLoginDate(string SDate, int UnitNum)
        {
            try
            {
                using (MemberShipDataContext membercontext = new MemberShipDataContext())
                {
                    DateTime dt_First = DateTime.ParseExact(SDate + "/01", AllConsts.MONTY_DAY, System.Globalization.DateTimeFormatInfo.CurrentInfo);

                    int year = dt_First.Date.Year;
                    int month = dt_First.Date.Month;
                    int dayCount = DateTime.DaysInMonth(year, month);
                    DateTime dt_Last = dt_First.AddDays(dayCount - 1);

                    List<dynamic> res = new List<dynamic>();
                    List<UserProfile> users = membercontext.UserProfiles.Where(c => c.UnitNum.Equals(UnitNum)).ToList<UserProfile>();
                    using (InfoManageDataContext infocontext = new InfoManageDataContext())
                    {
                        foreach (UserProfile usr in users)
                        {
                            int AM = 0, PM = 0;
                            for (DateTime tmp = dt_First; tmp <= dt_Last; tmp = tmp.AddDays(1))
                            {
                                int AM123 = infocontext.UserActions.Where(c => (c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(tmp.Year) && c.CreateTime.Month.Equals(tmp.Month) && c.CreateTime.Day.Equals(tmp.Day) && c.CreateTime.Hour.Equals(7)) || (c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(tmp.Year) && c.CreateTime.Month.Equals(tmp.Month) && c.CreateTime.Day.Equals(tmp.Day) && c.CreateTime.Hour.Equals(8))).Count();
                                int PM123 = infocontext.UserActions.Where(c => (c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(tmp.Year) && c.CreateTime.Month.Equals(tmp.Month) && c.CreateTime.Day.Equals(tmp.Day) && c.CreateTime.Hour.Equals(13)) || (c.ID.Equals(usr.ID) && c.CreateTime.Year.Equals(tmp.Year) && c.CreateTime.Month.Equals(tmp.Month) && c.CreateTime.Day.Equals(tmp.Day) && c.CreateTime.Hour.Equals(14))).Count();
                                if (AM123 != 0)
                                {
                                    AM++;
                                }
                                if (PM123 != 0)
                                {
                                    PM++;
                                }
                            }
                            res.Add(new { usr.RealName, AM, PM, dayCount });
                        }
                    }
                    return Json(res, JsonRequestBehavior.AllowGet);
                }
            }
            catch
            {
                return Json("", JsonRequestBehavior.AllowGet);
            }
        }
 public ActionResult AjaxUserModify(
     string UserName,
     string RealName,
     string pword,
     int unitNum)
 {
     try
     {
         using (MemberShipDataContext context = new MemberShipDataContext())
         {
             UserProfile usr = context.UserProfiles.Where(c => c.UserName.Equals(UserName)).FirstOrDefault();
             if (usr != null)
             {
                 //usr.UserName = UserName;
                 usr.RealName = RealName;
                 usr.UnitNum = unitNum;
             }
             else
             {
                 UserProfile newusr = new UserProfile();
                 newusr.UserName = UserName;
                 newusr.RealName = RealName;
                 newusr.UnitNum = unitNum;
                 newusr.pword = pword;
                 context.UserProfiles.Add(newusr);
             }
             context.SaveChanges();
             return Json("OK", JsonRequestBehavior.AllowGet);
         }
     }
     catch
     {
         return Json("NO", JsonRequestBehavior.AllowGet);
     }
 }
        public ActionResult AjaxSetTurnInStorageList(
            int ElementID, string SparePartsType, string ApplicableModels,
            string SparePartsCode, string Operator, string TurnInDate, int SparePartsStatus,
            int SparePartsBelongingStatus, string SparePartsManufacturer, string CheckDate, string VaildDate)
        {
            try
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["User"];
                    ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
                    int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));

                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Find(id);
                        if (null != usr)
                        {
                            using (InfoManageDataContext InfoManageContext = new InfoManageDataContext())
                            {
                                EquipmentsStorage newTurnInStorage = new EquipmentsStorage();
                                newTurnInStorage.SparePartsType = SparePartsType;
                                newTurnInStorage.ApplicableModels = ApplicableModels;
                                newTurnInStorage.SparePartsCode = SparePartsCode.Trim();
                                newTurnInStorage.TurnInDate = DateTime.ParseExact(TurnInDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.Operator = Operator;
                                newTurnInStorage.SparePartsStatus = SparePartsStatus;
                                newTurnInStorage.SparePartsBelongingStatus = SparePartsBelongingStatus;
                                newTurnInStorage.CheckDate = DateTime.ParseExact(CheckDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.VaildDate = DateTime.ParseExact(VaildDate, AllConsts.HOUR_MINUTE, System.Globalization.DateTimeFormatInfo.CurrentInfo);
                                newTurnInStorage.SparePartsManufacturer = SparePartsManufacturer;
                                newTurnInStorage.ElementID = ElementID;
                                newTurnInStorage.LastModifyDate = DateTime.Now;
                                newTurnInStorage.LastModifier = Operator;
                                EquipmentsStorage result = InfoManageContext.EquipmentsStorages.Where(c => c.SparePartsCode.Equals(SparePartsCode)).FirstOrDefault();
                                if (null == result)
                                {
                                    InfoManageContext.EquipmentsStorages.Add(newTurnInStorage);
                                }
                                else
                                {
                                    result.SparePartsType = newTurnInStorage.SparePartsType;
                                    result.ApplicableModels = newTurnInStorage.ApplicableModels;
                                    result.TurnInDate = newTurnInStorage.TurnInDate;
                                    result.Operator = newTurnInStorage.Operator;
                                    result.CheckDate = newTurnInStorage.CheckDate;
                                    result.VaildDate = newTurnInStorage.VaildDate;
                                    result.SparePartsManufacturer = newTurnInStorage.SparePartsManufacturer;
                                    result.ElementID = newTurnInStorage.ElementID;
                                    result.SparePartsBelongingStatus = SparePartsBelongingStatus;
                                    result.LastModifyDate = DateTime.Now;
                                    result.LastModifier = Operator;
                                }

                                UserAction newaction = new UserAction();
                                newaction.ID = usr.ID;
                                newaction.RealName = usr.RealName;
                                newaction.ActionName = "AjaxSetTurnInStorageList";
                                newaction.CreateTime = DateTime.Now;
                                newaction.LastModifyTime = newaction.CreateTime;
                                InfoManageContext.UserActions.Add(newaction);

                                InfoManageContext.SaveChanges();
                                return Json("OK", JsonRequestBehavior.AllowGet);
                            }
                        }
                    }
                }
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
            catch
            {
                return Json("NO", JsonRequestBehavior.AllowGet);
            }
        }
        public ActionResult Front()
        {
            try
            {
                if (Request.Cookies["User"] != null)
                {
                    HttpCookie aCookie = Request.Cookies["User"];
                    ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
                    int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));
                    int UnitNum = Convert.ToInt32(Server.UrlDecode(aCookie["UnitNum"]));
                    ViewBag.UnitName = Server.UrlDecode(aCookie["UnitName"]);

                    using (MemberShipDataContext context = new MemberShipDataContext())
                    {
                        UserProfile usr = context.UserProfiles.Find(id);
                        if (null != usr)
                        {
                            using (InfoManageDataContext onlinecontext = new InfoManageDataContext())
                            {
                                UserAction newaction = new UserAction();
                                newaction.ID = usr.ID;
                                newaction.RealName = usr.RealName;
                                newaction.ActionName = "EquipmentManagement";
                                newaction.CreateTime = DateTime.Now;
                                newaction.LastModifyTime = newaction.CreateTime;
                                onlinecontext.UserActions.Add(newaction);
                                onlinecontext.SaveChanges();
                            }
                        }
                    }

                    ViewBag.Title = "维修维护管理";
                    ViewBag.UnitNum = UnitNum;
                    return View(UnitNum);
                }
                else
                {
                    WebSecurity.Logout();
                    return RedirectToAction("Login", "Admin");
                }
            }
            catch
            {
                WebSecurity.Logout();
                return RedirectToAction("Login", "Admin");
            }
        }
Exemple #21
0
        public ActionResult Manage(LocalPasswordModel model)
        {
            //if (Request.Cookies["User"] != null)
            //{
            //HttpCookie aCookie = Request.Cookies["User"];
            //ViewBag.RealName = Server.UrlDecode(aCookie["RealName"]);
            //int id = Convert.ToInt32(Server.UrlDecode(aCookie["ID"]));
            //int UnitNum = Convert.ToInt32(Server.UrlDecode(aCookie["UnitNum"]));
            //ViewBag.UnitName = Server.UrlDecode(aCookie["UnitName"]);

            ViewBag.Title = "首页";
            //ViewBag.UnitNum = UnitNum;
            ViewBag.ReturnUrl = Url.Action("Manage");

            if (ModelState.IsValid)
            {
                bool changePasswordSucceeded;
                try
                {
                    changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    using (MemberShipDataContext PracticeDC = new MemberShipDataContext())
                    {
                        UserProfile user = PracticeDC.UserProfiles.Where(u => u.UserName == @User.Identity.Name).FirstOrDefault();
                        if (null != user)
                        {
                            user.pword = model.NewPassword;
                            PracticeDC.SaveChanges();
                        }
                    }
                    return RedirectToAction("Manage", new { Message = ManageMessageId.ChangePasswordSuccess });
                }
                else
                {
                    ModelState.AddModelError("", "当前密码不正确或新密码无效。");
                }
            }
            return PartialView("~/Views/Admin/Manage.cshtml", model);
            //}
            //else
            //{
            //    WebSecurity.Logout();
            //    return RedirectToAction("Login", "Admin");
            //}
        }