コード例 #1
0
        public async Task <LibDocument> CreateDocumentAsync(string blobname, DocumentController.PostDocumentRequest request)
        {
            var category = _documentlibContext.Categories.SingleOrDefault(cat => cat.Id == request.Category);
            var folder   = _documentlibContext.Folders
                           .Include(f => f.Registers)
                           .ThenInclude(reg => reg.Documents)
                           .Single(f => f.Id == request.Folder);

            var register = GetNextRegister(folder);

            var newDoc = new LibDocument
            {
                Category = category,
                Name     = request.Name,
                Register = register,
                Date     = request.Date,
                Blobname = GetBlobname(register, blobname)
            };

            await AddTagsAsync(request.Tags.Split('|'), newDoc);

            await _documentlibContext.LibDocuments.AddAsync(newDoc);

            await _documentlibContext.SaveChangesAsync();

            return(newDoc);
        }
コード例 #2
0
        public void DeleteDoc(LibDocument doc)
        {
            DirectoryInfo di = new DirectoryInfo(_appEnvironment.WebRootPath + doc.Path);

            Search index = new Search();

            index.DeleteFromIndex(doc);

            db.Documents.Remove(doc);
            db.SaveChanges();
        }
コード例 #3
0
        public FileResult GetFile(LibDocument doc)
        {
            string ReportURL = _appEnvironment.WebRootPath + doc.Path;

            if (doc.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
            {
                return(PhysicalFile(ReportURL, doc.ContentType, doc.DbName));
            }
            else
            {
                return(PhysicalFile(ReportURL, doc.ContentType));
            }
        }
コード例 #4
0
        public IActionResult edit(LibDocument doc)
        {
            if (ModelState.IsValid)
            {
                var editedDoc = db.Documents.Where(x => x.id == doc.id).FirstOrDefault();
                editedDoc.Name           = doc.Name;
                editedDoc.CategoryId     = doc.CategoryId;
                editedDoc.Desc1          = doc.Desc1;
                editedDoc.Published      = doc.Published;
                editedDoc.AccessLinkOnly = doc.AccessLinkOnly;

                db.Documents.Attach(editedDoc);
                db.Entry(editedDoc).State = EntityState.Modified;

                db.SaveChanges();
            }
            return(RedirectToAction("MyFiles"));
        }
コード例 #5
0
        private void DeleteFileFromCategory(int id)
        {
            LibDocument doc = db.Documents.Find(id);
            FileInfo    di  = new FileInfo(_appEnvironment.WebRootPath + doc.Path);

            string webRootPath     = _appEnvironment.WebRootPath;
            string contentRootPath = _appEnvironment.ContentRootPath;

            if (di.Exists)
            {
                di.Delete();
            }
            Search index = new Search();

            index.DeleteFromIndex(doc);
            db.Documents.Remove(doc);
            db.SaveChanges();
        }
コード例 #6
0
        private async Task AddTagsAsync(string[] tags, LibDocument newDoc)
        {
            var allTags = await _documentlibContext.Tags.ToListAsync();

            var newTags = tags.Where(tag => allTags.All(x => x.Name != tag)).Select(tag => new Tag {
                Name = tag
            });

            _documentlibContext.Tags.AddRange(newTags);
            await _documentlibContext.SaveChangesAsync();

            newDoc.Tags?.Clear();

            var tagsToAdd = await _documentlibContext.Tags.Where(tag => tags.Contains(tag.Name)).ToListAsync();

            newDoc.Tags = tagsToAdd.Select(tag => new DocumentTag {
                LibDocument = newDoc, Tag = tag
            }).ToList();
        }
コード例 #7
0
        public IActionResult Delete(int id)
        {
            LibDocument doc = db.Documents.Find(id);

            System.IO.FileInfo di = new FileInfo(_appEnvironment.WebRootPath + doc.Path);

            string webRootPath     = _appEnvironment.WebRootPath;
            string contentRootPath = _appEnvironment.ContentRootPath;

            if (di.Exists)
            {
                di.Delete();
            }

            Search index = new Search();

            index.DeleteFromIndex(doc);

            db.Documents.Remove(doc);
            db.SaveChanges();
            return(RedirectToAction("MyFiles"));
        }
コード例 #8
0
        public IActionResult Details(int id)
        {
            LibDocument doc = db.Documents.Where(x => x.id == id).Include(r => r.Executor).Include(e => e.User).FirstOrDefault();

            return(PartialView("_GetDetails", doc));
        }
コード例 #9
0
        //[RequestSizeLimit(40000000)]
        //public async Task<IActionResult> AddFile(IFormFile uploadedFile)
        public async Task <IActionResult> AddFile(AddFileModelView file)
        {
            //var s=User.FindFirstValue(ClaimTypes.NameIdentifier);
            if (file.uploadedFile != null)
            {
                string ext         = Path.GetExtension(file.uploadedFile.FileName).ToLowerInvariant();
                var    types       = GetMimeTypes();
                string newName     = DateTime.Now.ToString("M-d-yyyy_hh-mm-ss") + ext;
                string path        = "";
                string MonthNumber = DateTime.Now.Month.ToString();
                string YearNumber  = DateTime.Now.Year.ToString();

                DirectoryInfo directory = new DirectoryInfo(_appEnvironment.WebRootPath + @"\Files\" + YearNumber + @"\" + MonthNumber);
                if (directory.Exists)
                {
                    path = "\\Files\\" + YearNumber + @"\" + MonthNumber + @"\" + newName;
                }
                else
                {
                    directory.Create();
                    path = "\\Files\\" + YearNumber + @"\" + MonthNumber + @"\" + newName;
                }
                //DirectoryInfo directory=new DirectoryInfo("/Files/"); //Linux
                // путь к папке Files
                //path = "\\Files\\" + newName;


                //string s=pDF.ReadPdfFile(path);
                // сохраняем файл в папку Files в каталоге wwwroot

                // Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                //                             Encoding utf8 = Encoding.GetEncoding("utf-8");
                //                             Encoding win1251 = Encoding.GetEncoding("windows-1251");
                //                             byte[] utf8Bytes = win1251.GetBytes(pDF.ReadPdfFile(path));
                //                             byte[] win1251Bytes = Encoding.Convert(win1251, utf8, utf8Bytes);
                //                             string currentText = utf8.GetString(win1251Bytes);



                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await file.uploadedFile.CopyToAsync(fileStream);
                }
                string      userId  = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value.ToString();
                LibDocument newfile = new LibDocument();

                switch (ext)
                {
                case ".pdf":


                    //PDFParser pDF = new PDFParser(_appEnvironment);
                    //Task<string> pdfText=Task.Factory.StartNew(()=>pDF.ReadPdfFile(path));
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        Desc2          = "",//pDF.ReadPdfFile(path)
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;

                case ".mp4":
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        Desc2          = "",
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;

                case ".doc":
                case ".docx":
                    DocxParser docx = new DocxParser(_appEnvironment);
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        Desc2          = docx.GetText(path),
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;

                    // case ".xls":
                    // case ".xlsx":
                    //         newfile = new LibDocument {
                    //     Name = file.Name,
                    //     Path = path,
                    //     Desc1 = file.Desc1,
                    //     Desc2 = "",
                    //     UserId=Int32.Parse(userId),
                    //     CategoryId=file.categories,
                    //     DbName=newName,
                    //     Published=file.Published,
                    //     AccessLinkOnly=file.AccessLinkOnly,
                    //     ContentType=types[ext]
                    //         };
                    // break;
                }


                // if(ext==".pdf")
                // {
                //    newfile = new LibDocument {
                //      Name = file.Name,
                //       Path = path,
                //       Desc1 = file.Desc1,
                //        Desc2 = pDF.ReadPdfFile(path),
                //        UserId=Int32.Parse(userId),
                //        CategoryId=file.categories,
                //        DbName=newName,
                //        Published=file.Published,
                //        AccessLinkOnly=file.AccessLinkOnly,
                //        ContentType=types[ext]
                //         };
                // }
                // else if(ext==".mp4")
                // {
                //    newfile = new LibDocument {
                //      Name = file.Name,
                //       Path = path,
                //       Desc1 = file.Desc1,
                //        Desc2 = "",
                //        UserId=Int32.Parse(userId),
                //        CategoryId=file.categories,
                //        DbName=newName,
                //        Published=file.Published,
                //        AccessLinkOnly=file.AccessLinkOnly,
                //        ContentType=types[ext]
                //         };
                // }

                db.Documents.Add(newfile);

                await db.SaveChangesAsync();

                await Task.Factory.StartNew(() => InsertPdfTextToDbAsync(newfile.id, path));

                //int id =file.id;


                //AddToIndexDoc(newfile.id);

                //db.Entry(file).Reload()//Encoding.UTF8

                List <Category> categories = db.Categories.ToList();

                // categories.Insert(0, new Category { Name = "Все", Id = 0 });
                ViewBag.Categories = new SelectList(categories, "Id", "Name");
            }

            return(RedirectToAction("MyFiles", "File"));
        }
コード例 #10
0
 /// <summary>
 ///
 /// </summary>
 public void BillPayProgressRptDoc(string customerCode, string billTermId)
 {
     LibDocument.ExportExcel(BizBillRpt.GetBillPayProgressRpt(DataAccess, customerCode, billTermId));
 }
コード例 #11
0
        /// <summary>
        /// 通路手續費月結報表
        /// (舊:手續費報表)
        /// </summary>
        public void ChannelTotalFeeRpt(string customerId)
        {
            DataTable rpt = BizReceiptBillRpt.GetChannelTotalFeeRpt(DataAccess, customerId);

            LibDocument.ExportExcel(rpt);
        }
コード例 #12
0
        /// <summary>
        /// 無帳單主檔報表
        /// (舊:銷帳報表列印)
        /// </summary>
        public void NoBillReceiptRptDoc(string customerCode)
        {
            List <NoBillReceiptRptModel> rpt = BizReceiptBillRpt.NoBillReceiptRpt(DataAccess, customerCode);

            LibDocument.ExportExcel(rpt);
        }
コード例 #13
0
        public async Task <IActionResult> AddFile(AddFileModelView file)
        {
            if (file.uploadedFile != null)
            {
                string ext         = Path.GetExtension(file.uploadedFile.FileName).ToLowerInvariant();
                var    types       = GetMimeTypes();
                string newName     = DateTime.Now.ToString("M-d-yyyy_hh-mm-ss") + ext;
                string path        = "";
                string MonthNumber = DateTime.Now.Month.ToString();
                string YearNumber  = DateTime.Now.Year.ToString();

                DirectoryInfo directory = new DirectoryInfo(_appEnvironment.WebRootPath + @"\Files\" + YearNumber + @"\" + MonthNumber);
                if (directory.Exists)
                {
                    path = "\\Files\\" + YearNumber + @"\" + MonthNumber + @"\" + newName;
                }
                else
                {
                    directory.Create();
                    path = "\\Files\\" + YearNumber + @"\" + MonthNumber + @"\" + newName;
                }

                using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create))
                {
                    await file.uploadedFile.CopyToAsync(fileStream);
                }
                string      userId  = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value.ToString();
                LibDocument newfile = new LibDocument();

                switch (ext)
                {
                case ".pdf":


                    //PDFParser pDF = new PDFParser(_appEnvironment);
                    //Task<string> pdfText=Task.Factory.StartNew(()=>pDF.ReadPdfFile(path));
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;

                case ".mp4":
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;

                case ".doc":
                case ".docx":
                    DocxParser docx = new DocxParser(_appEnvironment);
                    newfile = new LibDocument {
                        Name           = file.Name,
                        Path           = path,
                        Desc1          = file.Desc1,
                        Desc2          = docx.GetText(path),
                        UserId         = Int32.Parse(userId),
                        CategoryId     = file.categories,
                        DbName         = newName,
                        Published      = file.Published,
                        AccessLinkOnly = file.AccessLinkOnly,
                        ContentType    = types[ext]
                    };
                    break;
                }

                db.Documents.Add(newfile);
                await db.SaveChangesAsync();

                await Task.Factory.StartNew(() => InsertPdfTextToDbAsync(newfile.id, path));

                List <Category> categories = db.Categories.ToList();
                ViewBag.Categories = new SelectList(categories, "Id", "Name");
            }
            return(RedirectToAction("MyFiles", "File"));
        }