Esempio n. 1
0
        public static void ConvertXMLToPDF(object xmlFilename, object pdfFileName)
        {
            Microsoft.Office.Interop.Word.Application oWord;
            Object oMissing = System.Reflection.Missing.Value;
            Object oTrue    = true;
            Object oFalse   = false;

            oWord         = new Microsoft.Office.Interop.Word.Application();
            oWord.Visible = false;

            try
            {
                File.Delete(pdfFileName.ToString());
            }
            catch (Exception)
            {
                oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
            }

            Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref xmlFilename, ref oMissing, ref oMissing,
                                                                              ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                                                                              ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

            object oFmt = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

            doc.SaveAs(ref pdfFileName, ref oFmt, ref oMissing, ref oMissing, ref oMissing,
                       ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                       ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);


            CaseDocument.ReleaseComObject(oFmt);
            CaseDocument.ReleaseComObject(doc);
            oWord.Quit(ref oFalse, ref oMissing, ref oMissing);
            CaseDocument.ReleaseComObject(oWord);
        }
        private void downloadDocuments(string path, CourtCase case1)
        {
            try
            {
                string documents_tables_sel = "#divDocumentsInformation_body";
                var    documents_tables     = FindElementIfExists(By.CssSelector(documents_tables_sel));
                if (documents_tables == null)
                {
                    logNoDocumentsFound(case1);
                    return;
                }
                var docs_p = documents_tables.FindElements(By.TagName("p"));

                foreach (var doc_p in docs_p)
                {
                    CaseDocument casedoc = new CaseDocument();
                    casedoc.inCase = case1;
                    var doc_a = doc_p.FindElement(By.TagName("a"));
                    casedoc.URL         = doc_a.GetAttribute("href");
                    casedoc.description = doc_p.Text;
                    var doc_filename_span = doc_p.FindElement(By.TagName("span"));
                    casedoc.fileName = RemoveIllegalChars(doc_filename_span.Text);
                    case1.Documents.Add(casedoc);
                }

                for (int i = 0; i < case1.Documents.Count; i += 20)
                {
                    int      th_count = case1.Documents.Count - i < 20 ? case1.Documents.Count - i : 20;
                    Thread[] ths      = new Thread[th_count];
                    for (int j = 0; j < th_count; j++)
                    {
                        var docs = case1.Documents[i + j];
                        Console.WriteLine(docs.URL);
                        docs.fileNumber = i + j + 1;
                        var file_num_str = docs.fileNumber.ToString().PadLeft(4, '0');
                        docs.fileName = path + "/" + file_num_str + "-" + docs.fileName;
                        downloadDocument(docs, path, ths[j]);
                    }
                    for (int j = 0; j < th_count; j++)
                    {
                        if (ths[j] != null)
                        {
                            try
                            {
                                ths[j].Join();
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(driver.Url);
            }
        }
        private bool downloadDocument(CaseDocument case_doc, string filename, Thread th)
        {
            try
            {
                string downloadLinksel = "a.btn:nth-child(1)";
                takescreenshot("download document");
                driver.Navigate().GoToUrl(case_doc.URL);
                try
                {
                    var body = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.CssSelector(downloadLinksel)));
                }
                catch (Exception ex)
                {
                    Thread.Sleep(1000);
                    try
                    {
                        var body = new WebDriverWait(driver, TimeSpan.FromSeconds(30)).Until(ExpectedConditions.ElementExists(By.CssSelector(downloadLinksel)));
                    }
                    catch (Exception ex1)
                    {
                        Console.WriteLine(ex1.Message);
                        return(false);
                    }
                }


                takescreenshot("download document view");

                var downloadLink = driver.FindElementByCssSelector(downloadLinksel);
                case_doc.D_URL = downloadLink.GetAttribute("href");
                Console.WriteLine(case_doc.D_URL);

                if (th != null)
                {
                    th = new Thread(() => { bool is_downloaded = TryDownloadFile(case_doc); });
                    th.Start();
                    return(true);
                }
                else
                {
                    return(TryDownloadFile(case_doc));
                }
            }
            catch (WebDriverTimeoutException ex2)
            {
                Console.WriteLine(ex2.Message);
                return(false);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            return(true);
        }
Esempio n. 4
0
        public void DeleteDoc(int Id)
        {
            CaseDocument doc = _database.ClientDocuments.Get(Id);

            if (doc == null)
            {
                throw new ValidationException("Документ не найден", "");
            }
            _database.ClientDocuments.Delete(doc.Id);
            _database.Save();
        }
Esempio n. 5
0
        public void OpenTemplate()
        {
            YellowstonePathology.Business.OrderIdParser orderIdParser = new YellowstonePathology.Business.OrderIdParser(this.m_PanelSetOrderCytology.ReportNo);
            this.m_ReportXml.Load(this.m_TemplateName);
            switch (this.m_ReportSaveEnum)
            {
            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Draft:
                this.m_SaveFileName = CaseDocument.GetSaveDraftDocumentFilePath(orderIdParser);
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Normal:
                this.m_SaveFileName = YellowstonePathology.Document.CaseDocumentPath.GetPath(orderIdParser) + this.m_PanelSetOrderCytology.ReportNo + ".xml";
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Test:
                this.m_SaveFileName = @"c:\test.xml";
                break;
            }
        }
Esempio n. 6
0
        public void AddDocument(CaseDocDTO doc)
        {
            Case _case = _database.Cases.Get(doc.CaseId);

            if (_case == null)
            {
                throw new ValidationException("Дело не найдено", "");
            }
            CaseDocument _newDoc = new CaseDocument
            {
                Name = doc.Name,
                Path = doc.Path,
                Date = doc.Date,
                Case = _case
            };

            _database.ClientDocuments.Create(_newDoc);
            _database.Save();
        }
Esempio n. 7
0
        public void SaveReport()
        {
            YellowstonePathology.Business.OrderIdParser orderIdParser = new YellowstonePathology.Business.OrderIdParser(this.m_PanelSetOrder.ReportNo);
            switch (this.m_ReportSaveMode)
            {
            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Test:
                this.m_ReportXml.Save(@"c:\testing\test.xml");
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Draft:
                this.m_SaveFileName = CaseDocument.GetSaveDraftDocumentFilePath(orderIdParser);
                this.m_ReportXml.Save(this.m_SaveFileName);
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Normal:
                this.m_ReportXml.Save(this.m_SaveFileName);
                Business.Helper.FileConversionHelper.ConvertDocumentTo(orderIdParser, CaseDocumentTypeEnum.CaseReport, CaseDocumentFileTypeEnum.xml, CaseDocumentFileTypeEnum.doc);
                Business.Helper.FileConversionHelper.ConvertDocumentTo(orderIdParser, CaseDocumentTypeEnum.CaseReport, CaseDocumentFileTypeEnum.doc, CaseDocumentFileTypeEnum.xps);
                break;
            }
        }
Esempio n. 8
0
        public void SaveReport()
        {
            YellowstonePathology.Business.OrderIdParser orderIdParser = new YellowstonePathology.Business.OrderIdParser(this.m_PanelSetOrder.ReportNo);
            switch (this.m_ReportSaveMode)
            {
            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Test:
                this.m_ReportXml.Save(@"c:\testing\test.xml");
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Draft:
                this.m_SaveFileName = YellowstonePathology.Document.CaseDocumentPath.GetPath(orderIdParser) + this.m_PanelSetOrder.ReportNo + ".draft.xml";
                this.m_ReportXml.Save(this.m_SaveFileName);
                break;

            case YellowstonePathology.Business.Document.ReportSaveModeEnum.Normal:
                this.m_ReportXml.Save(this.m_SaveFileName);
                CaseDocument.SaveXMLAsDoc(orderIdParser);
                CaseDocument.SaveDocAsXPS(orderIdParser);
                break;
            }
        }
        public ActionResult ShowAllCaseTemplates(int id, FormCollection formCollection)
        {
            int stid = db.Students.Single(x => x.Client_Id == id).Student_Id;
            int caseId = db.Cases.Single(x => x.Student_Id == stid).Case_Id;

            var oldCaseDoc = db.CaseDocuments.Where(x => x.Case_Id == caseId).ToList();
            // create a list of all  case  old general documents ID's
            List<int?> oldlistID = db.CaseDocuments.Where(x => x.Case_Id == caseId).Select(x => x.CaseDocTemplate_Id).ToList();
            // create a list of all  case  new general documents ID's
            List<int> newListID = new List<int>();

            var fc = formCollection["listID"].Split(',');
            foreach (var input in fc)
            {

                newListID.Add(Int32.Parse(input));
            }

            foreach (int? item in oldlistID)
            {
                if (item != null)
                {
                    //newListID.Remove((int)item);
                    CaseDocument casedoc = db.CaseDocuments.DefaultIfEmpty(null).SingleOrDefault(c => c.CaseDocTemplate_Id == item && c.Case_Id == caseId && c.UploadedOn == null);

                    if (casedoc != null)
                    {
                        db.CaseDocuments.DeleteObject(casedoc);
                        db.SaveChanges();
                        LogHelper.writeToStudentLog(new string[] { CookieHelper.Username }, (casedoc.CaseDocTemplate_Id + " Case Template is Deleted "), LogHelper.LOG_DELETE, LogHelper.SECTION_DOCUMENT);

                    }
                }
            }

            if (ModelState.IsValid)
            {

                foreach (int item in newListID)
                {
                    // Add the corresponding Template into the Case Docuemnt

                    CaseDocument found = (from e in db.CaseDocuments
                                          where e.CaseDocTemplate_Id == item && e.Case_Id == caseId
                                          select e).DefaultIfEmpty(null).SingleOrDefault();

                    // add a new record only if doesnt exist in the file
                    if (found == null)
                    {
                        CaseDocument doc = new CaseDocument();

                        doc.CaseDocTemplate_Id = item;
                        doc.Case_Id = caseId;
                        db.CaseDocuments.AddObject(doc);
                    }

                }
                db.SaveChanges();

            }
            return RedirectToAction("StudentDetails", new { id = id });
        }
Esempio n. 10
0
        public override Object Upload(List <HttpContent> streamContent, string path, int id, string type, string uploadpath)
        {
            List <BO.Document> docInfo = new List <BO.Document>();

            uploadpath = uploadpath + path;
            Directory.CreateDirectory(uploadpath.ToString());
            int companyid = 0;

            foreach (HttpContent content in streamContent)
            {
                string errMessage = string.Empty;
                string filename   = string.Empty;
                using (var dbContextTransaction = _context.Database.BeginTransaction())
                {
                    try
                    {
                        if (type.ToUpper().Contains(EN.Constants.ConsentType))
                        {
                            companyid = System.Convert.ToInt16(type.Split('_')[1]);
                            if (_context.MidasDocuments.Any(cc => cc.ObjectId == id &&
                                                            cc.ObjectType == EN.Constants.ConsentType + "_" + companyid &&
                                                            (cc.IsDeleted.HasValue == false || (cc.IsDeleted.HasValue == true && cc.IsDeleted.Value == false))))
                            {
                                throw new Exception("Company, Case and Consent data already exists.");
                            }
                        }

                        MidasDocument midasdoc = _context.MidasDocuments.Add(new MidasDocument()
                        {
                            ObjectType   = type,
                            ObjectId     = id,
                            DocumentName = content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                            DocumentPath = ConfigurationManager.AppSettings.Get("BLOB_SERVER") + path.ToString(),
                            CreateDate   = DateTime.UtcNow
                        });
                        _context.Entry(midasdoc).State = System.Data.Entity.EntityState.Added;
                        _context.SaveChanges();

                        if (type.ToUpper().Contains(EN.Constants.ConsentType))
                        {
                            type = EN.Constants.ConsentType;
                        }
                        switch (type)
                        {
                        case EN.Constants.ConsentType:
                            CaseCompanyConsentDocument caseCompanyConsentDocument = _context.CaseCompanyConsentDocuments.Add(new CaseCompanyConsentDocument()
                            {
                                MidasDocumentId = midasdoc.Id,
                                CaseId          = id,
                                CompanyId       = companyid,
                                DocumentName    = content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                                CreateDate      = DateTime.UtcNow
                            });
                            _context.Entry(caseCompanyConsentDocument).State = System.Data.Entity.EntityState.Added;
                            _context.SaveChanges();
                            filename = caseCompanyConsentDocument.DocumentName;
                            break;

                        case EN.Constants.CaseType:
                            CaseDocument caseDoc = _context.CaseDocuments.Add(new CaseDocument()
                            {
                                MidasDocumentId = midasdoc.Id,
                                CaseId          = id,
                                DocumentName    = content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                                CreateDate      = DateTime.UtcNow
                            });
                            _context.Entry(caseDoc).State = System.Data.Entity.EntityState.Added;
                            _context.SaveChanges();
                            filename = caseDoc.DocumentName;
                            break;

                        case EN.Constants.VisitType:
                            CaseDocument visitDoc = _context.CaseDocuments.Add(new CaseDocument()
                            {
                                MidasDocumentId = midasdoc.Id,
                                CaseId          = id,
                                DocumentName    = content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                                CreateDate      = DateTime.UtcNow
                            });
                            _context.Entry(visitDoc).State = System.Data.Entity.EntityState.Added;
                            _context.SaveChanges();
                            filename = visitDoc.DocumentName;
                            break;
                        }

                        //docInfo.Type = type;

                        using (Stream stream = content.ReadAsStreamAsync().Result)
                        {
                            if (File.Exists(uploadpath + "/" + content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty)))
                            {
                                errMessage = "DuplicateFileName";
                                dbContextTransaction.Rollback();
                            }
                            else if (!Enum.IsDefined(typeof(BO.GBEnums.FileTypes), content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty).Split('.')[1]))
                            {
                                errMessage = "Invalid file extension";
                                dbContextTransaction.Rollback();
                            }
                            else if (!(System.Convert.ToDecimal(content.Headers.ContentLength / (1024.0m * 1024.0m)) > 0 && System.Convert.ToDecimal(content.Headers.ContentLength / (1024.0m * 1024.0m)) <= 1))
                            {
                                errMessage = "File size exccded the limit : 1MB";
                                dbContextTransaction.Rollback();
                            }
                            else
                            {
                                stream.Seek(0, SeekOrigin.Begin);
                                FileStream filestream = File.Create(uploadpath + "/" + content.Headers.ContentDisposition.FileName.Replace("\"", string.Empty));
                                stream.CopyTo(filestream);
                                stream.Close();
                                filestream.Close();
                                dbContextTransaction.Commit();
                            }
                        }
                        docInfo.Add(new BO.Document()
                        {
                            Status       = errMessage.Equals(string.Empty) ? "Success" : "Failed",
                            Message      = errMessage,
                            DocumentId   = midasdoc.Id,
                            DocumentPath = errMessage.Equals(string.Empty) ? midasdoc.DocumentPath + "/" + midasdoc.DocumentName : midasdoc.DocumentName,
                            DocumentName = midasdoc.DocumentName,
                            id           = id
                        });
                    }
                    catch (Exception err)
                    {
                        docInfo.Add(new BO.Document()
                        {
                            Status       = "Failed",
                            Message      = err.Message.ToString(),
                            DocumentId   = 0,
                            DocumentPath = "",
                            DocumentName = filename,
                            id           = id
                        });
                        dbContextTransaction.Rollback();
                    }
                }
            }
            return(docInfo);
        }
Esempio n. 11
0
 private void AddDocumentTemplate(Case nCase)
 {
     // Create entries for General documents to be uploaded by the students
     foreach (CaseDoc_Template cdTemplates in db.CaseDoc_Template.Where(x => x.Required == true).ToList())
     {
         CaseDocument cd = new CaseDocument();
         cd.CaseDocTemplate_Id = cdTemplates.CaseDocTemplate_Id;
         cd.Case_Id = nCase.Case_Id;
         db.CaseDocuments.AddObject(cd);
     }
 }
        public override Object SaveAsBlob(int objectId, int companyId, string objectType, string documentType, string uploadpath)
        {
            BO.Document docInfo    = new BO.Document();
            string      errMessage = string.Empty;
            string      errDesc    = string.Empty;

            using (var dbContextTransaction = _context.Database.BeginTransaction())
            {
                MidasDocument midasdoc = _context.MidasDocuments.Add(new MidasDocument()
                {
                    ObjectType   = documentType.ToUpper().Equals(EN.Constants.ConsentType) ? string.Concat(EN.Constants.ConsentType, "_" + companyId) : objectType,
                    ObjectId     = objectId,
                    DocumentType = documentType,
                    DocumentName = Path.GetFileName(uploadpath),//streamContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                    DocumentPath = uploadpath,
                    CreateDate   = DateTime.UtcNow
                });
                _context.Entry(midasdoc).State = System.Data.Entity.EntityState.Added;
                _context.SaveChanges();

                if (documentType.ToUpper().Equals(EN.Constants.ConsentType))
                {
                    CaseCompanyConsentDocument caseCompConsentDoc = _context.CaseCompanyConsentDocuments.Add(new CaseCompanyConsentDocument()
                    {
                        MidasDocumentId = midasdoc.Id,
                        CaseId          = objectId,
                        DocumentType    = documentType,
                        CompanyId       = companyId,
                        DocumentName    = Path.GetFileName(uploadpath),//streamContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                        CreateDate      = DateTime.UtcNow
                    });
                    _context.Entry(caseCompConsentDoc).State = System.Data.Entity.EntityState.Added;
                    _context.SaveChanges();

                    BO.CompanyCaseConsentApproval        companyCaseConsentApprovalBO         = new BO.CompanyCaseConsentApproval();
                    CompanyCaseConsentApprovalRepository CompanyCaseConsentApprovalRepository = new CompanyCaseConsentApprovalRepository(_context);
                    companyCaseConsentApprovalBO.CaseId    = objectId;
                    companyCaseConsentApprovalBO.CompanyId = companyId;
                    var result = CompanyCaseConsentApprovalRepository.Save(companyCaseConsentApprovalBO);
                    if (result is BO.ErrorObject)
                    {
                        errMessage = "Failed";
                        errDesc    = ((BO.ErrorObject)result).ErrorMessage;
                        dbContextTransaction.Rollback();
                    }
                    else
                    {
                        dbContextTransaction.Commit();
                    }
                }
                else
                {
                    CaseDocument caseDoc = _context.CaseDocuments.Add(new CaseDocument()
                    {
                        MidasDocumentId = midasdoc.Id,
                        CaseId          = objectId,
                        DocumentType    = documentType,
                        DocumentName    = Path.GetFileName(uploadpath),//streamContent.Headers.ContentDisposition.FileName.Replace("\"", string.Empty),
                        CreateDate      = DateTime.UtcNow
                    });
                    _context.Entry(caseDoc).State = System.Data.Entity.EntityState.Added;
                    _context.SaveChanges();
                    dbContextTransaction.Commit();
                }

                docInfo.Status       = errMessage.Equals(string.Empty) ? "Success" : "Failed";
                docInfo.Message      = errDesc;
                docInfo.DocumentId   = midasdoc.Id;
                docInfo.DocumentPath = errMessage.Equals(string.Empty) ? midasdoc.DocumentPath : midasdoc.DocumentName;
                docInfo.DocumentName = midasdoc.DocumentName;
                docInfo.DocumentType = errMessage.Equals(string.Empty) ? midasdoc.DocumentType : string.Empty;
                docInfo.id           = objectId;
            }

            return((Object)docInfo);
        }