public ActionResult Index() { HttpCookie cookie = Request.Cookies.Get(CookieModel.Logistics_User_Cookie.ToString()); if (cookie == null) { return(View(new UserModel())); } if (cookie[CookieModel.UserName.ToString()] != null && cookie[CookieModel.Password.ToString()] != null) { UserModel user = new UserModel() { UserName = cookie[CookieModel.UserName.ToString()], Password = DESEncrypt.CreateInstance().Decrypt(cookie[CookieModel.Password.ToString()]), RememberMe = true }; DataSet dst = ServiceModel.CreateInstance().Client.UserLogin(user.UserName, user.Password); if (dst == null || dst.Tables.Count == 0) { ViewBag.ErrorMessage = "用户名或密码错误"; return(View(user)); } user.Password = cookie[CookieModel.Password.ToString()]; AddHttpContextItems(user); Session[CookieModel.UserName.ToString()] = user.UserName; return(RedirectToAction("Index", "Home")); } return(View(new UserModel())); }
public ActionResult Index(string firstLetter) { BuildModel build = new BuildModel(); firstLetter = string.IsNullOrEmpty(firstLetter) ? string.Empty : firstLetter; try { DataSet dst = ServiceModel.CreateInstance().Client.GetBuild(firstLetter); if (dst != null && dst.Tables.Count > 0) { foreach (DataRow drow in dst.Tables[0].Rows) { build.FirstLetter.Add(drow[0].ToString()); } foreach (DataRow drow in dst.Tables[1].Rows) { build.Build.Add(new BuildInfo() { ID = int.Parse(drow[0].ToString()), Name = drow[1].ToString() }); } } } catch { } return(View(build)); }
public JsonResult GetProject(ProjectModel project) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; try { project.ProjectStatus = string.IsNullOrEmpty(project.ProjectStatus) ? string.Empty : project.ProjectStatus; project.CustomerName = string.IsNullOrEmpty(project.CustomerName) ? string.Empty : project.CustomerName; project.CustomerTel = string.IsNullOrEmpty(project.CustomerTel) ? string.Empty : project.CustomerTel; project.ProjectAddress = string.IsNullOrEmpty(project.ProjectAddress) ? string.Empty : project.ProjectAddress; project.ProjectType = string.IsNullOrEmpty(project.ProjectType) ? string.Empty : project.ProjectType; project.MachineType = string.IsNullOrEmpty(project.MachineType) ? string.Empty : project.MachineType; project.StartDate = string.IsNullOrEmpty(project.StartDate) ? string.Empty : project.StartDate; project.EndDate = string.IsNullOrEmpty(project.EndDate) ? string.Empty : project.EndDate; int page = 0; if (!int.TryParse(HttpContext.Request.Params["page"], out page)) { page = 1; } page = page == 0 ? 1 : page; int rows = 0; if (!int.TryParse(HttpContext.Request.Params["rows"], out rows)) { rows = 50; } rows = rows == 0 ? 50 : rows; DataSet dst = ServiceModel.CreateInstance().Client.GetProject(Session[CookieModel.UserName.ToString()].ToString(), project.ProjectStatus, project.CustomerName, project.CustomerTel, project.ProjectAddress, project.ProjectType, project.MachineType, project.StartDate, project.EndDate, page, rows); if (dst == null) { return(null); } if (dst.Tables.Count != 2) { return(null); } var data = from row in dst.Tables[0].AsEnumerable() select new ProjectQueryModel() { createtime = row["createtime"].ToString().Trim(), pname = row["pname"].ToString().Trim(), paddress = row["paddress"].ToString().Trim(), price = row["price"].ToString().Trim(), customer = row["customer"].ToString().Trim(), pstatus = row["pstatus"].ToString().Trim(), view = row["view"].ToString().Trim() }; json.Data = new { total = Convert.ToInt32(dst.Tables[1].Rows[0][0]), rows = data }; } catch { } return(json); }
public JsonResult Add(ProjectModel project) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; string message = ValidateInput(project); if (!string.IsNullOrEmpty(message)) { json.Data = new { Result = 0, Message = message }; return(json); } try { project.ProjectAddress = string.Format("{0}市{1}(乡、镇、街道){2}(路、街){3}(号、大厦){4}楼{5}", project.Area1, project.Area2, project.Area3, project.Area4, project.Area5, project.Area6); project.MachineType = string.Empty; project.ProjectType = "工程"; project.ProjectStatus = "登录成功"; result = ServiceModel.CreateInstance().Client.AddProject(Session[CookieModel.UserName.ToString()].ToString(), project.ProjectName, project.ProjectUses, project.MachineType, project.ProjectAddress, project.CustomerName, project.CustomerTel, float.Parse(project.Price), project.ProjectStatus, project.ProjectType); switch (result) { case -1: message = "没有权限"; break; case 0: message = "登录项目失败"; break; case 1: message = "登录项目成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }
public JsonResult ChangePassword(UserModel user) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; user.UserName = Session[CookieModel.UserName.ToString()].ToString(); string message = ValidateInput(user); if (!string.IsNullOrEmpty(message)) { json.Data = new { Result = 0, Message = message }; return(json); } try { user.Password = Md5Encrypt.CreateInstance().Encrypt(user.Password); user.Password_New = Md5Encrypt.CreateInstance().Encrypt(user.Password_New); result = ServiceModel.CreateInstance().Client.ModifyPassword(user.UserName, user.Password, user.Password_New); switch (result) { case -1: message = "没有权限"; break; case 0: message = "旧密码输入不正确"; break; case 1: message = "修改成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }
public JsonResult Add(UserModel user) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; string message = ValidateInput(user); if (!string.IsNullOrEmpty(message)) { json.Data = new { Result = result, Message = message }; return(json); } try { user.Password = string.IsNullOrEmpty(user.Password) ? "123456" : user.Password; user.Password = Md5Encrypt.CreateInstance().Encrypt(user.Password); result = ServiceModel.CreateInstance().Client.AddUser(Session[CookieModel.UserName.ToString()].ToString(), user.UserName, user.RealName, user.Phone, user.IsAdmin); switch (result) { case -1: message = "没有权限"; break; case 0: message = "添加失败"; break; case 1: message = "添加成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }
public ActionResult Index(UserModel user) { if (!ModelState.IsValid) { return(View(user)); } if (!ValidateInput(user)) { return(View(user)); } string password = Md5Encrypt.CreateInstance().Encrypt(user.Password); DataSet dst = ServiceModel.CreateInstance().Client.UserLogin(user.UserName, password); if (dst == null || dst.Tables.Count == 0) { ViewBag.ErrorMessage = "用户名或密码错误"; return(View(user)); } if (user.RememberMe) { FormsAuthentication.SetAuthCookie(user.UserName, true, FormsAuthentication.FormsCookiePath); FormsAuthenticationTicket Ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddTicks(FormsAuthentication.Timeout.Ticks), false, JsonConvert.SerializeObject(user)); string hashTicket = FormsAuthentication.Encrypt(Ticket); HttpCookie cookie = new HttpCookie(CookieModel.Logistics_User_Cookie.ToString(), hashTicket); cookie[CookieModel.UserName.ToString()] = user.UserName; password = DESEncrypt.CreateInstance().Encrypt(password); cookie[CookieModel.Password.ToString()] = password; cookie.Expires = DateTime.Now.AddMonths(1); Response.Cookies.Add(cookie); } else { HttpCookie cookie = new HttpCookie(CookieModel.Logistics_User_Cookie.ToString()); cookie.Expires = DateTime.Now.AddMonths(-1); Request.Cookies.Add(cookie); cookie[CookieModel.UserName.ToString()] = null; cookie[CookieModel.Password.ToString()] = null; Response.Cookies.Add(cookie); } user.Password = DESEncrypt.CreateInstance().Encrypt(Md5Encrypt.CreateInstance().Encrypt(user.Password)); AddHttpContextItems(user); Session[CookieModel.UserName.ToString()] = user.UserName; return(RedirectToAction("Index", "Home")); }
public JsonResult Query(UserModel user) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; try { user.UserName = string.IsNullOrEmpty(user.UserName) ? string.Empty : user.UserName; DataSet dst = ServiceModel.CreateInstance().Client.GetAllUser(Session[CookieModel.UserName.ToString()].ToString(), user.UserName); if (dst == null) { return(null); } if (dst.Tables.Count != 1) { return(null); } if (Convert.ToInt32(dst.Tables[0].Rows[0][0]) == -1) { return(null); } var data = from row in dst.Tables[0].AsEnumerable() select new UserQueryModel() { id = Convert.ToInt32(row["id"]), uname = row["uname"].ToString().Trim(), rname = row["rname"].ToString().Trim(), phone = row["phone"].ToString().Trim(), isadmin = Convert.ToBoolean(row["isadmin"])?"是":"否" }; json.Data = new { total = Convert.ToInt32(dst.Tables[0].Rows[0][0]), rows = data }; } catch { } return(json); }
public JsonResult Current(UserModel user) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; if (Session[CookieModel.CurrentUser.ToString()] == null || Session[CookieModel.CurrentAdmin.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.CurrentUser.ToString()].ToString()) || string.IsNullOrEmpty(Session[CookieModel.CurrentAdmin.ToString()].ToString())) { try { DataSet dst = ServiceModel.CreateInstance().Client.GetCurrentUser(Session[CookieModel.UserName.ToString()].ToString()); if (dst == null) { return(null); } if (dst.Tables.Count != 2) { return(null); } StringBuilder sb = new StringBuilder(); foreach (DataRow drow in dst.Tables[1].Rows) { sb.Append(drow[0].ToString()); sb.Append(" "); } Session[CookieModel.CurrentUser.ToString()] = string.Format("登录用户:{0} ", dst.Tables[0].Rows[0][0].ToString()); Session[CookieModel.CurrentAdmin.ToString()] = string.Format("系统管理员:{0}", sb.ToString().Trim()); } catch { } } json.Data = new { current = Session[CookieModel.CurrentUser.ToString()].ToString(), admin = Session[CookieModel.CurrentAdmin.ToString()].ToString() }; return(json); }
public JsonResult ModifyProjectStatus(ProjectModel project) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; string message = string.Empty; try { project.ProjectStatus = string.IsNullOrEmpty(project.ProjectStatus) ? string.Empty : project.ProjectStatus; project.ProjectStatus = project.ProjectStatus == "1" ? "登录成功" : "登录失败"; result = ServiceModel.CreateInstance().Client.ModifyProjectStatus(Session[CookieModel.UserName.ToString()].ToString(), project.ProjectID, project.ProjectStatus); switch (result) { case -1: message = "没有权限"; break; case 0: message = "修改失败"; break; case 1: message = "修改成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }
public JsonResult Delete(UserModel user) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; string message = string.Empty; try { result = ServiceModel.CreateInstance().Client.DeleteUser(Session[CookieModel.UserName.ToString()].ToString(), user.UserID); switch (result) { case -1: message = "没有权限"; break; case 0: message = "删除失败"; break; case 1: message = "删除成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }
public JsonResult Add(ProjectModel project) { if (Session[CookieModel.UserName.ToString()] == null || string.IsNullOrEmpty(Session[CookieModel.UserName.ToString()].ToString())) { Redirect("Login/Index"); return(null); } JsonResult json = new JsonResult() { ContentType = "text/html" }; int result = 0; string message = ValidateInput(project); if (!string.IsNullOrEmpty(message)) { json.Data = new { Result = 0, Message = message }; return(json); } try { if (project.ProHouseType == "1") { project.ProjectAddress = string.Format("{0}{1}{2}期{3}幢{4}室", project.Address0, project.Address1, project.Address2, project.Address3, project.Address4); } if (project.ProHouseType == "2") { project.ProjectAddress = string.Format("{0}{1}{2}期{3}幢", project.Address0, project.Address1, project.Address2, project.Address3); } if (project.ProHouseType == "3") { project.ProjectAddress = string.Format("{0}{1}镇{2}村{3}", project.Address0, project.Address1, project.Address6, project.Address5); } project.ProjectName = string.Empty; project.ProjectUses = string.Empty; project.ProjectType = GetProHouseType(project.ProHouseType); project.ProjectStatus = "登录成功"; result = ServiceModel.CreateInstance().Client.AddProject(Session[CookieModel.UserName.ToString()].ToString(), project.ProjectName, project.ProjectUses, project.MachineType, project.ProjectAddress, project.CustomerName, project.CustomerTel, float.Parse(project.Price), project.ProjectStatus, project.ProjectType); switch (result) { case -1: message = "没有权限"; break; case 0: message = "登录项目失败"; break; case 1: message = "登录项目成功"; break; } } catch (Exception ex) { result = 0; message = ex.Message; } json.Data = new { Result = result, Message = message }; return(json); }