コード例 #1
0
        public void DeleteReport(Report DelReport)
        {
            string deleteFolder = string.Empty;

            var id = DelReport.Id;

            using (var db = new SAPTestContext())
            {
                var report = db.Reports.Find(id);
                if(report!=null && report.Executor == User.Identity.Name)
                {
                    deleteFolder = Path.Combine(HostingEnvironment.MapPath("/Report1/ReportFiles"), report.Url);
                    db.Reports.Remove(report);
                    db.SaveChanges();
                }
            }

            if (deleteFolder != "" && deleteFolder != HostingEnvironment.MapPath("/Report1/ReportFiles"))
            {
                if (Directory.Exists(deleteFolder))
                {
                    Directory.Delete(deleteFolder, true);
                }
            }
        }
コード例 #2
0
 public void UpdateReport(Report rp)
 {
     var id = rp.Id;
     var atId = rp.AssetId;
     using (var db = new SAPTestContext())
     {
         var report = db.Reports.Find(id);
         var asset = db.Assets.Find(atId);
         if(report!=null && asset != null && report.Executor == User.Identity.Name)
         {
             report.AssetId = atId;
             db.SaveChanges();
         }
     }
 }
コード例 #3
0
        public ActionResult Upload()
        {
            var u = InternalAttribute.GetUser();
            if (u!=null)
            {
                HttpPostedFileBase file = Request.Files["file"];
                string guid = Guid.NewGuid().ToString();
                string path = HttpContext.Server.MapPath("/Report1/Temp");
                string backupPath = HttpContext.Server.MapPath("/Report1/Backup");
                string reportFolder = HttpContext.Server.MapPath("/Report1/ReportFiles");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                if (!Directory.Exists(backupPath))
                {
                    Directory.CreateDirectory(backupPath);
                }

                string fileName = Path.Combine(path, guid + "_" + file.FileName.Split('\\').Last());
                string type = file.ContentType;
                file.SaveAs(fileName);
                FileInfo fi = new FileInfo(fileName);
                int atId;
                try
                {
                    if (string.Compare(fi.Extension, ".zip", true) == 0 && int.TryParse(Request.Form["asset"], out atId) && atId > 0)
                    {
                        ZipFile.ExtractToDirectory(fileName, Path.Combine(reportFolder, guid));
                        string reportFile = Path.Combine(reportFolder, guid, "report.xml");
                        if (System.IO.File.Exists(reportFile))
                        {
                            XmlDocument xDoc = new XmlDocument();
                            xDoc.Load(reportFile);
                            Report rp = ReportReader.ReadReport(xDoc);
                            rp.Executor = User.Identity.Name;
                            rp.Uid = u.Id;
                            using (var db = new SAPTestContext())
                            {
                                rp.Url = guid;
                                // "/Report1/ReportFiles/" + guid + "/report.xml";
                                Asset at = db.Assets.Find(atId);
                                if (at != null)
                                {
                                    rp.Asset = at;
                                }
                                db.Reports.Add(rp);
                                db.SaveChanges();
                            }
                            ViewBag.Flag = true;
                        }
                        else
                        {
                            Directory.Delete(Path.Combine(reportFolder, guid), true);
                            ViewBag.Flag = false;
                        }
                    }
                    else
                    {
                        ViewBag.Flag = false;
                    }
                    System.IO.File.Move(fileName, Path.Combine(backupPath, guid + ".zip"));
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMsg = ex.Message;
                    fi.Delete();
                    if (Directory.Exists(Path.Combine(reportFolder, guid)))
                    {
                        Directory.Delete(Path.Combine(reportFolder, guid), true);
                    }
                    throw new Exception();

                }
                MyReportFilter filter = new MyReportFilter();
                filter.isMyReport = true;
                return RedirectToAction("Index", filter);
            }
            return RedirectToAction("Index");
        }