コード例 #1
0
 public ActionResult Index()
 {
     
     var model = new ProjectModel();
     ViewBag.href = "/Project/Index/?course=";
     if (Request.Params[COURSE] != null)
     {
         ViewBag.href += Request.Params[COURSE] + "&year=";
         if (Request.Params[YEAR] != null)
         {
             ViewBag.href += Request.Params[YEAR] + "&homework=";
             if (Request.Params[HOMEWORK] != null)
             {
                 ViewBag.href = "/Project/Info/?" + COURSE + "=" + Request.Params[COURSE] + "&" + YEAR + "=" + Request.Params[YEAR] + "&" + HOMEWORK + "=" + Request.Params[HOMEWORK]+"&"+STUDENT+"=";
                 ViewBag.data = model.getAllProjectStudent(Request.Params[COURSE], Request.Params[YEAR], Request.Params[HOMEWORK]);
                 
             }
             else
             {
                 
                 ViewBag.data = model.getAllHomeWork(Request.Params[COURSE], Request.Params[YEAR]);
             }
         }
         else
         {
             
             ViewBag.data = model.getAllYears(Request.Params[COURSE]);
         }
     }
     else
     {
         ViewBag.data = model.getAllCources();
     }
     return View();
 }
コード例 #2
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();
        }
コード例 #3
0
 public ActionResult Project()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     var model = new ProjectModel();
     ViewBag.Course = model.getAllCources();
     ViewBag.Years = model.getDistinctYears();
     ViewBag.Homeworks = model.getDistinctHomeWork();
     return View();
 }
コード例 #4
0
        public ActionResult GetProject()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            var root = new Dictionary<string, object>();
            var id = Request["id"];
            
            if (id == null)
            {
                return Json(root);
            }
            var dataArray = id.Split('_');
            var model = new ProjectModel();
            var list = new List<Dictionary<string, object>>();
            if (dataArray.Length == 1) //get course
            {
                
                var course = model.getAllCources();
                foreach (var c in course)
                {

                    Dictionary<string, object> node = new Dictionary<string, object>();
                    node.Add("text", c);
                    node.Add("id", string.Format("course_{0}",c));
                    node.Add("children",true);
                    list.Add(node);
                }
                root.Add("text", "PROJECT");
                root.Add("children", list);
                

            }
            else if (dataArray.Length == 2)//get year by course
            {
               var years =  model.getAllYears(dataArray[1]);
               foreach (var y in years)
               {
                   Dictionary<string, object> node = new Dictionary<string, object>();
                    node.Add("text", y);
                    node.Add("id", string.Format("course_{0}_{1}",dataArray[1],y));
                    node.Add("children",true);
                    list.Add(node);
               }
               return Json(list);
            }
            else if (dataArray.Length == 3)//get homework by course and year
            {
                var homeworks = model.getAllHomeWork(dataArray[1], dataArray[2]);
                foreach (var h in homeworks)
                {
                    Dictionary<string, object> node = new Dictionary<string, object>();
                    node.Add("text", h);
                    node.Add("id", string.Format("course_{0}_{1}_{2}", dataArray[1],dataArray[2], h));
                    node.Add("children", true);
                    list.Add(node);
                    
                }
                return Json(list);

            }
            else if(dataArray.Length==4)//get 
            {
                var students = model.getAllProjectStudent(dataArray[1], dataArray[2], dataArray[3]);
                foreach (var s in students)
                {
                    Dictionary<string, object> node = new Dictionary<string, object>();
                    node.Add("text", s);
                    node.Add("id", string.Format("course_{0}_{1}_{2}_{3}", dataArray[1], dataArray[2],dataArray[3], s));
                    //node.Add("children", true);
                    list.Add(node);

                }
                return Json(list);


            }



            return Json(root);
            
        }
コード例 #5
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);
       
 }
コード例 #6
0
 public ActionResult ModifyProject()
 {
     if (loginStatus() == false)
     {
         return Redirect("Login");
     }
     var response = new Dictionary<string, string>();
    
     var course = Request.Params["course"];
     var year = Request.Params["year"];
     var homework = Request.Params["homework"];
     var student = Request.Params["student"];
     var visible = Request.Params["visible"];
     if (course == null || year == null || homework == null || student == null || visible==null)
     {
         response.Add("status", "failed");
         response.Add("error", "bad param");
         return Json(response);
     }
     var model = new ProjectModel();
     int row = model.ModifyProjectStatus(course, year, homework, student, int.Parse(visible));
     if (row == 0)
     {
         response.Add("status", "failed");
         response.Add("error", "update failed");
         return Json(response);
     }
     response.Add("status", "success");
     return Json(response);
 }
コード例 #7
0
        public ActionResult DelProject()
        {
            if (loginStatus() == false)
            {
                return Redirect("Login");
            }
            var response = new Dictionary<string,string>();
            var course = Request.Params["course"];
            var year = Request.Params["year"];
            var homework = Request.Params["homework"];
            var student = Request.Params["student"];
            if (course == null || year == null || homework == null || student == null)
            {
                response.Add("status", "failed");
                response.Add("error", "bad param");
            }
            var model = new ProjectModel();
            int row = model.DelProject(course, year, homework, student);
            if (row == 0)
            {
                response.Add("status", "failed");
                response.Add("error", "delete error");
            }
            Directory.Delete(Server.MapPath(string.Format("~/upload/project/{0}/{1}/{2}/{3}",course,year,homework,student)), true);
            response.Add("status", "success");

            return Json(response);
        }
コード例 #8
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);
        }