public ActionResult SaveImage(serverShowInfo info)
        {
            try
            {
                HttpPostedFileBase imageName = Request.Files["image"];// 从前台获取文件
                if (imageName == null)
                {
                    return(Content("(error)未获取到文件"));
                }
                string file        = imageName.FileName;
                string fileFormat  = file.Split('.')[file.Split('.').Length - 1];   // 以“.”截取,获取“.”后面的文件后缀
                Regex  imageFormat = new Regex(@"^(bmp)|(png)|(gif)|(jpg)|(jpeg)"); // 验证文件后缀的表达式(自己写的,不规范别介意哈)
                if (string.IsNullOrEmpty(file) || !imageFormat.IsMatch(fileFormat)) // 验证后缀,判断文件是否是所要上传的格式
                {
                    return(Content("(error)文件格式支持(bmp)|(png)|(gif)|(jpg)|(jpeg)"));
                }
                else
                {
                    string timeStamp     = DateTime.Now.Ticks.ToString();                // 获取当前时间的string类型
                    string firstFileName = timeStamp.Substring(0, timeStamp.Length - 4); // 通过截取获得文件名
                    string imageStr      = "/Resource/picture/";                         // 获取保存图片的项目文件夹
                    string uploadPath    = Server.MapPath("~/" + imageStr);              // 将项目路径与文件夹合并
                    string pictureFormat = file.Split('.')[file.Split('.').Length - 1];  // 设置文件格式
                    string fileName      = firstFileName + "." + fileFormat;             // 设置完整(文件名+文件格式)
                    string saveFile      = uploadPath + fileName;                        //文件路径
                    imageName.SaveAs(saveFile);                                          // 保存文件
                    string image = imageStr + fileName;                                  // 设置数据库保存的路径

                    ViewBag.pictureAdr     = image;
                    ViewBag.serverShowInfo = info;
                    if (info.id != 0)
                    {
                        return(View("modelsUpdate"));
                    }
                    else if (info.areaId == 1)
                    {
                        return(View("modelsPicAdd_Index"));
                    }
                    else if (info.areaId == 0)
                    {
                        return(View("modelsPicAdd_Hello"));
                    }
                    return(Content("上传成功!"));
                }
            }
            catch
            {
                return(Content("上传出错!"));
            }
        }
Beispiel #2
0
 /// <summary>
 /// 展示表增加数据
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public static Boolean insertServerShowInfo(serverShowInfo info)
 {
     try
     {
         using (LazyfitnessEntities db = new LazyfitnessEntities())
         {
             db.serverShowInfo.Add(info);
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Beispiel #3
0
 public string displayUpdateInfo(serverShowInfo serverShowInfo)
 {
     try
     {
         if (toolsHelpers.updateToolsController.updateServerShowInfo(u => u.id == serverShowInfo.id, serverShowInfo) == true)
         {
             Response.Redirect("/backStage/displayManagement/displaySearch");
             return("success");
         }
         return("修改失败!");
     }
     catch
     {
         return("修改失败(ERROR)");
     }
 }
Beispiel #4
0
 public ActionResult displayAddInfo(serverShowInfo info)
 {
     try
     {
         if (toolsHelpers.insertToolsController.insertServerShowInfo(info) == true)
         {
             Response.Redirect("/backStage/displayManagement/Index");
             return(Content("success"));
         }
         return(Content("增加失败!"));
     }
     catch
     {
         return(Content("内容增加失败(ERROR)"));
     }
 }
Beispiel #5
0
 /// <summary>
 /// 查询展示表
 /// </summary>
 /// <param name="whereLambda"></param>
 /// <returns></returns>
 public static serverShowInfo[] selectServerShowInfo(Expression <Func <serverShowInfo, bool> > whereLambda)
 {
     try
     {
         using (LazyfitnessEntities db = new LazyfitnessEntities())
         {
             DbQuery <serverShowInfo> dataObject = db.serverShowInfo.Where(whereLambda) as DbQuery <serverShowInfo>;
             serverShowInfo[]         infoList   = dataObject.ToArray();
             return(infoList);
         }
     }
     catch
     {
         serverShowInfo[] nullInfo = new serverShowInfo[0];
         return(nullInfo);
     }
 }
Beispiel #6
0
 public string displayDelete(serverShowInfo info)
 {
     try
     {
         if (toolsHelpers.deleteToolsController.deleteServerShowInfo(u => u.id == info.id) == true)
         {
             Response.Redirect("/backStage/displayManagement/displaySearch");
             return("success");
         }
         else
         {
             return("不存在删除内容!");
         }
     }
     catch
     {
         return("删除失败!(ERROR)");
     }
 }
 /// <summary>
 /// 往展示表修改数据
 /// </summary>
 /// <param name="whereLambda"></param>
 /// <param name="info"></param>
 /// <returns></returns>
 public static Boolean updateServerShowInfo(Expression <Func <serverShowInfo, bool> > whereLambda, serverShowInfo info)
 {
     try
     {
         using (LazyfitnessEntities db = new LazyfitnessEntities())
         {
             DbQuery <serverShowInfo> dataObject = db.serverShowInfo.Where(whereLambda) as DbQuery <serverShowInfo>;
             serverShowInfo           oldInfo    = dataObject.FirstOrDefault();
             oldInfo.title      = info.title;
             oldInfo.pictureAdr = info.pictureAdr;
             oldInfo.url        = info.url;
             oldInfo.Infostatus = info.Infostatus;
             db.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Beispiel #8
0
 public ActionResult displayAdd(serverShowInfo serverShowInfo)
 {
     ViewBag.serverShowInfo = serverShowInfo;
     return(View());
 }
Beispiel #9
0
        public ActionResult showResult(string id, serverShowInfo showInfo)
        {
            if (Request.Cookies["managerId"] != null)
            {
                //获取Cookies的值
                HttpCookie cookieName = Request.Cookies["managerId"];
                var        cookieText = Server.HtmlEncode(cookieName.Value);
            }
            else
            {
                return(View("Index"));
            }
            try
            {
                if (showInfo.title == null)
                {
                    int sumPage = GetSumPage(10, u => u.areaId == showInfo.areaId && u.flag == showInfo.flag);
                    if (id == null)
                    {
                        id = 1.ToString();
                    }
                    if (sumPage <= Convert.ToInt32(id))
                    {
                        id = sumPage.ToString();
                    }
                    if (Convert.ToInt32(id) <= 0)
                    {
                        id = 1.ToString();
                    }
                    int nowPage           = Convert.ToInt32(id);
                    serverShowInfo[] info = GetPagedList(Convert.ToInt32(id), 10, u => u.areaId == showInfo.areaId && u.flag == showInfo.flag, u => u.id);
                    if (info == null || info.Length == 0)
                    {
                        return(Content("没有此展示!"));
                    }

                    ViewBag.nowPage   = nowPage;
                    ViewBag.sumPage   = sumPage;
                    ViewBag.allInfo   = info;
                    ViewBag.rightInfo = showInfo;
                    return(View());
                }
                else
                {
                    int sumPage = GetSumPage(10, u => u.areaId == showInfo.areaId && u.flag == showInfo.flag && u.title == showInfo.title);
                    if (id == null)
                    {
                        id = 1.ToString();
                    }
                    if (sumPage <= Convert.ToInt32(id))
                    {
                        id = sumPage.ToString();
                    }
                    if (Convert.ToInt32(id) <= 0)
                    {
                        id = 1.ToString();
                    }
                    int nowPage           = Convert.ToInt32(id);
                    serverShowInfo[] info = GetPagedList(Convert.ToInt32(id), 10, u => u.areaId == showInfo.areaId && u.flag == showInfo.flag && u.title == showInfo.title, u => u.id);
                    if (info == null || info.Length == 0)
                    {
                        return(Content("没有此展示!"));
                    }
                    ViewBag.nowPage   = nowPage;
                    ViewBag.sumPage   = sumPage;
                    ViewBag.allInfo   = info;
                    ViewBag.rightInfo = showInfo;
                    return(View());
                }
            }
            catch
            {
                return(Content("查询失败!(ERROR)"));
            }
        }