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");
            }
        }
        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);
            }
        }
        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);
            }
        }
Esempio n. 4
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");
            }
        }