Example #1
0
        public ActionResult Info()
        {
            var model = new ProjectModel();
            string course = Request.Params[COURSE];
            string year = Request.Params[YEAR];
            string homeork = Request.Params[HOMEWORK];
            string student = Request.Params[STUDENT];
            
            var project  = model.getAllProject(course, year, homeork, student);
            var url = project.htmlUrl;
            ViewBag.url = url;
            return View();
            //return Redirect(url);

            //if (project.imgUrl.LastIndexOf('~')!=-1)
            //{
            //    var tmp = project.imgUrl.Split('~');
            //    project.imgUrl = tmp[tmp.Length - 1];

            //}
            //ViewBag.data = project;
            //string jar = ViewBag.data.classFileUrl;

            //var mainClass = jar.Split('/');
            //var actualName = mainClass[mainClass.Length - 1];
            //ViewBag.MainClass = actualName.Split('.')[0];

            ////ViewBag.MainClass = jar.Substring(0, jar.Length - 3) + "class";
            
            //string codepath = ViewBag.data.code;
            //codepath = Server.MapPath(codepath);

            //ViewBag.data.codetext = System.IO.File.ReadAllText(codepath);
            ////ViewBag.MainClass = codepath.Replace(".java","").Replace(@"\", ".");

            //return View();
        }
Example #2
0
 public ActionResult GetProjectDetail()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     var response = new Dictionary<string,string>();
     var model = new ProjectModel();
     string course = Request.Params["course"];
     string year = Request.Params["year"];
     string homework = Request.Params["homework"];
     string student = Request.Params["student"];
     var data = model.getAllProject(course, year, homework, student);
     if (data != null)
     {
         response.Add("name", data.student);
         response.Add("description", data.description);
      //   var img_url = data.imgUrl.Split('~');
      //   response.Add("image", img_url[img_url.Length-1]);
        // var jar_url = data.classFileUrl.Split('~');
         var jar_url = data.htmlUrl.Split('~');
         response.Add("programa", jar_url[jar_url.Length-1]);
      //   response.Add("code", string.Format("upload/project/{0}/{1}/{2}/{3}/{4}",course,year,homework,student,data.code));
         response.Add("visible",string.Format("{0}",data.visible));
         response.Add("status", "success");
     }
     else
     {
         response.Add("status", "failed");
     }
     return Json(response);
       
 }
Example #3
0
        public ActionResult AddProject()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            var response = new Dictionary<string, string>();
            HttpPostedFileBase jar = Request.Files.Get("jar");
            HttpPostedFileBase html = Request.Files.Get("html");
            var baseSavePath = "~/upload/project";
            var savePath = "";
            var imgfilename = "";
            var jarfilename = "";
            var htmlname = "";
            var img_url = "";
            var html_url = "";
            var jar_url = "";
            if (html != null)
            {
                var model = new ProjectModel();
                HttpPostedFileBase image = Request.Files.Get("image");
                if (image!=null&&!checkFileExt(image.FileName, "jpg,gif,png,bmp"))
                {//检查图片后缀
                    response.Add("status", "failed");
                    response.Add("error", "only jpg,gif,png,bmp allowed!");
                    return Json(response);
                }
                if (jar != null && !checkFileExt(jar.FileName, "jar"))
                {//检测jar后缀
                    response.Add("status", "failed");
                    response.Add("error", "only jar file allowed!");
                    return Json(response);
                }


                if (checkFileExt(html.FileName, "html,htm"))
                {
                    var course = Request.Params["course"];
                    var year = Request.Params["year"];
                    var homework = Request.Params["homework"];
                    var student = Request.Params["student"];
                    var description = Request.Params["description"];
                    var visible = Request.Params["visible"];
                    if (course != null && year != null && homework != null&&student!=null)
                    {
                        savePath = string.Format("{0}/{1}/{2}/{3}/{4}", baseSavePath, course, year, homework,student);
                  

                        if (Directory.Exists(Server.MapPath(savePath)))//检查目录是否存在,存在则递归删除目录
                        {
                            
                            var project = model.getAllProject(course,year,homework,student);
                            if (project.id > 0)  //数据库中存在则删除数据
                            {
                                model.DelProject(course, year, homework, student);
                            }
                            Directory.Delete(Server.MapPath(savePath), true);
                        }
                        Directory.CreateDirectory(Server.MapPath(savePath));
                        //储存图片文件
                        
                       
                        if (image != null)
                        { //是否存在图片,存在则保存图片
                            //img_url = string.Format("{0}/{1}", savePath, image.FileName);
                            if (image.FileName.LastIndexOf('\\') != -1)  //IE文件获取文件名
                            {
                                imgfilename = image.FileName.Substring(image.FileName.LastIndexOf('\\') + 1, image.FileName.Length - 1 - image.FileName.LastIndexOf('\\'));
                            }
                            else
                            {
                                imgfilename = image.FileName;
                            }
                            img_url = string.Format("{0}/{1}", savePath, imgfilename);
                            image.SaveAs(Server.MapPath(img_url));
                            //image.SaveAs(Server.MapPath(img_url));
                        }

                        //储存jar文件
                        if (jar != null)
                        {
                            if (jar.FileName.LastIndexOf('\\') != -1) //IE文件获取文件名
                            {

                                jarfilename = jar.FileName.Substring(jar.FileName.LastIndexOf('\\') + 1, jar.FileName.Length - 1 - jar.FileName.LastIndexOf('\\'));

                            }
                            else
                            {
                                jarfilename = jar.FileName;
                            }
                            jar_url = string.Format("{0}/{1}", savePath, jarfilename);
                            jar.SaveAs(Server.MapPath(jar_url));
                        }
                        
                       //存储html文件
                       
                        if (html.FileName.LastIndexOf('\\') != -1)  //IE文件获取文件名
                        {
                            htmlname = html.FileName.Substring(html.FileName.LastIndexOf('\\') + 1, html.FileName.Length - 1 - html.FileName.LastIndexOf('\\'));
                        }
                        else
                        {
                            htmlname = html.FileName;
                        }
                        html_url = string.Format("{0}/{1}", savePath, htmlname);
                        html.SaveAs(Server.MapPath(html_url));
                        
                        if (visible != null && visible=="0")
                        {
                          var row =  model.AddProject(course, year, homework, student, html_url, jar_url, img_url, description,0);
                          if (row < 1)
                          {
                              response.Add("status", "failed");
                              response.Add("error", "insert error");
                              return Json(response);
                          }
                        }
                        else
                        {
                          var  row = model.AddProject(course, year, homework, student, html_url, jar_url, img_url, description);
                          if (row < 1)
                          {
                              response.Add("status", "failed");
                              response.Add("error", "insert error");
                              return Json(response);
                          }
                        }

                        

                        response.Add("status", "success");
                        
                    }
                    else
                    {
                        response.Add("status", "failed");
                        //response.Add("error", "course,year,homework can't be null");
                        response.Add("error", "only html,htm allowed!");
                    }
                }
                else
                {
                    response.Add("status", "failed");
                    response.Add("error", "only  *.java allowed");
                }
                
            }
            else
            {
                response.Add("status", "failed");
                response.Add("error", "no html");
            }
            return Json(response);
        }