public ActionResult DownLoadStuChu() { string name = Request["name"]; StuFile file = new StuFile(); StuFileDal stufile = new StuFileDal(); IQueryable <StuFile> stuf = stufile.GetEntities(u => u.Student.Stu_Name == name && u.Status == 1); foreach (var item in stuf) { file = item; } string filepath = file.Url; string filePath = Server.MapPath(filepath); FileInfo fileInfo = new FileInfo(filePath); try { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Url); Response.AddHeader("Content-Length", fileInfo.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentType = "application/octet-stream"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.WriteFile(fileInfo.FullName); Response.Flush(); Response.End(); } catch (Exception) { return(Content("此文件已被删除")); } return(null); }
public ActionResult GetAllMyFuZeLunWen() { Teacher s = (Teacher)Session["teacher"]; TeaGroup tg = s.TeaGroup; if (tg == null) { Response.Write(""); Response.End(); return(View()); } ChoseThemeService chosetser = new ChoseThemeService(); IQueryable <ChoseTheme> choiq = chosetser.GetAllChoseTheme(); StuFileService sfser = new StuFileService(); IList <int> stuidlist = new List <int>(); IList <string> strlist = new List <string>(); string str = ""; int m = 0; strlist.Add(tg.TG_Name); foreach (var item in choiq) { if (item.Theme.TeaGroup.TG_Id == tg.TG_Id) { //stuidlist.Add((int)item.Student.Stu_Id); StuFile sf = sfser.GetStuFileByStu((int)item.Student.Stu_Id); if (sf == null) { m++; } if (sf != null) { str = sf.Student.Stu_Name + "=" + sf.StuF_Name + "=" + sf.SubTime + "=" + sf.Url; strlist.Add(str); } } } //string str = ""; //for (int i = 0; i < stuidlist.Count(); i++) //{ // StuFile sf = sfser.GetStuFileByStu(stuidlist[i]); // if (sf == null) // { // m++; // } // if (sf!=null) // { // str = sf.Student.Stu_Name + "=" + sf.StuF_Name + "=" + sf.SubTime+"="+sf.Url; // strlist.Add(str); // } //} string outstr = js.Serialize(strlist); Response.Write(outstr); Response.End(); return(null); }
public IQueryable <StuFile> GetStuFileChuByDep(string dep) { StuFile sf = new StuFile(); IQueryable <StuFile> iq = stufdal.GetEntities(u => u.Student.Department.Dep_Name == dep && u.Status == 1); if (iq.Count() == 0) { return(null); } return(iq); }
public bool AddStuFile(StuFile f) { DBSession db = new DBSession(); if (stufdal.Add(f) != null) { db.SaveChanges(); return(true); } ; return(false); }
public ActionResult TeaUpStuChu() { string p = Server.MapPath(""); StuFileService adfs = new StuFileService(); StuFileDal adfd = new StuFileDal(); StuFile adf = new StuFile(); string name = Request["name"]; StudentDal stud = new StudentDal(); Student stu = new Student(); IQueryable <Student> siq = stud.GetEntities(U => U.Stu_Name == name); foreach (var item in siq) { stu = item; } var file = Request.Files["file2"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var intro = Request["intro2"]; var filename = Request["filename2"]; IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Name == name && u.Status == 1); if (iq.Count() == 0) { return(Content("改还未提交过论文初稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm); } catch (Exception) { } string path = "/Upload/管理与信息工程学院/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm;; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 4); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); }
public void UpdateStuFile(StuFile file, string name, string intro, string url, int status) { DBSession db = new DBSession(); file.StuF_Intro = intro; file.StuF_Name = name; file.Url = url; file.Status = status; file.SubTime = DateTime.Now; stufdal.UpdateEntity(file); db.SaveChanges(); }
public StuFile GetStuFileByStu(int stuid) { StuFile sf = new StuFile(); IQueryable <StuFile> iq = stufdal.GetEntities(u => u.Student.Stu_Id == stuid && u.Status == 2); if (iq.Count() == 0) { return(null); } foreach (var item in iq) { sf = item; } return(sf); }
public ActionResult StuFileOverUpLoad() { string p = Server.MapPath(""); //System.IO.File.Delete(p + "/管理与信息工程学院/论文终稿/201301020127-黄杰-论文终稿.jpg"); //StuFileService adfs = new StuFileService(); //StuFileDal adfd = new StuFileDal(); //Student stu = (Student)Session["student"]; //var file = Request.Files["file1"]; //if (file.ContentLength==0) //{ // return Content("请选择要上传的文件"); //} //var filename = Request["filename1"]; //var intro = Request["intro1"]; //IQueryable<StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id&&u.Status==1); //if (iq.Count()==0) //{ // return Content("你还未提交过论文"); //} //StuFile adf = new StuFile(); //foreach (var item in iq) //{ // adf = item; //} //string s = file.FileName; //全路径的名字 //int index = s.LastIndexOf("."); //获取最后面点的位置 //string hzm = s.Substring(index); // 获取后缀名 //string path = "/Upload/" +filename+ Guid.NewGuid().ToString() + hzm; //防止命名相同 //adfs.UpdateStuFile(adf,filename,intro,path); //file.SaveAs(Request.MapPath(path)); //return Content("上传成功"); var file = Request.Files["file1"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var intro = Request["intro1"]; var filename = Request["filename1"]; StuFileService adfs = new StuFileService(); StuFileDal adfd = new StuFileDal(); Student stu = (Student)Session["student"]; var filename1 = stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告"; string filestyle = Request["style"]; string dir = stu.Department.Dep_Name; StuFile adf = new StuFile(); if (filestyle == "开题报告") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 0); if (iq.Count() == 0) { return(Content("你还未提交过开题报告")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/开题报告/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename1, intro, path, 0); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文初稿") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 1); if (iq.Count() == 0) { return(Content("你还未提交过论文初稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 1); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文终稿") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 2); if (iq.Count() == 0) { return(Content("你还未提交过论文终稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文终稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 2); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } return(null); }
public ActionResult StuFileUpLoad() { var file = Request.Files["file"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var intro = Request["intro"]; var filename = Request["filename"]; StuFileService adfs = new StuFileService(); StuFileDal adfd = new StuFileDal(); Student stu = (Student)Session["student"]; string filestyle = Request["style"]; string dir = stu.Department.Dep_Name; if (Directory.Exists(Server.MapPath("/Upload/" + dir)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath("/Upload/" + dir)); } if (filestyle == "开题报告") { if (Directory.Exists(Server.MapPath("/Upload/" + dir + "/" + filestyle)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath("/Upload/" + dir + "/" + filestyle)); } IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 0); if (iq.Count() >= 1) { return(Content("您已上传过开题报告,如果想要覆盖已上传的开题报告,请选择下面的覆盖上传!")); } StuFile adf = new StuFile(); // adf.Admin = ad; adf.StuF_Intro = intro; adf.StuF_Name = stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告"; adf.Student = stu; adf.Status = 0; adf.SubTime = DateTime.Now; string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Id + "-" + stu.Stu_Name + "-" + "开题报告" + hzm; //防止命名相同 adf.Url = path; adfs.AddStuFile(adf); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文初稿") { if (Directory.Exists(Server.MapPath("/Upload/" + dir + "/" + filestyle)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath("/Upload/" + dir + "/" + filestyle)); } IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 1); if (iq.Count() >= 1) { return(Content("您已上传过论文初稿,如果想要覆盖已上传的论文初稿,请选择下面的覆盖上传!")); } StuFile adf = new StuFile(); // adf.Admin = ad; adf.StuF_Intro = intro; adf.StuF_Name = stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿"; adf.Student = stu; adf.Status = 1; adf.SubTime = DateTime.Now; string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm; //防止命名相同 adf.Url = path; adfs.AddStuFile(adf); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文终稿") { if (Directory.Exists(Server.MapPath("/Upload/" + dir + "/" + filestyle)) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(Server.MapPath("/Upload/" + dir + "/" + filestyle)); } IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 2); if (iq.Count() >= 1) { return(Content("您已上传过论文,如果想要覆盖已上传的论文,请选择下面的覆盖上传!")); } StuFile adf = new StuFile(); // adf.Admin = ad; adf.StuF_Intro = intro; adf.StuF_Name = stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿"; adf.Student = stu; adf.Status = 2; adf.SubTime = DateTime.Now; string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿" + hzm; //防止命名相同 // string path = "/Upload/"+ filename + hzm; adf.Url = path; adfs.AddStuFile(adf); //string path = "/Upload/" + file.FileName; //string activeDir = @"C:\myDir"; //string newPath = System.IO.Path.Combine(activeDir, "mySubDirOne"); //System.IO.Directory.CreateDirectory(newPath); file.SaveAs(Request.MapPath(path)); //return Content(s + " " + hzm + " " + path); return(Content("上传成功")); } return(Content("上传成功")); }