/// <summary> /// Get the certificate data with its documents paginated /// </summary> /// <param name="certificateId">Certificate id</param> /// <param name="searchHeader">Flag to know if it is required to get the certificate information or only the documents</param> public void GetCertificateDetail(int certificateId, bool searchHeader) { PaginatedList<Document> result = new PaginatedList<Document>(); using (VocEntities db = new VocEntities()) { //Get the certificate data detail if (searchHeader) { Certificate = (from certificate in db.Certificates.Include("EntryPoint") where certificate.CertificateId == certificateId select certificate).FirstOrDefault(); } //Get the documents related to the certificate var querydocs = (from documents in db.Documents where documents.CertificateId == certificateId && documents.IsDeleted == false orderby documents.Certificate.IssuanceDate descending select documents); result.TotalCount = querydocs.Count(); var supportDocument = querydocs.Where(doc => doc.DocumentType == DocumentTypeEnum.SupportingDocument).ToList(); var releaseNotes = querydocs.Where(doc => doc.DocumentType == DocumentTypeEnum.ReleaseNote).ToList(); supportDocument.AddRange(releaseNotes); var certificatDoc = querydocs.Where(doc => doc.DocumentType == DocumentTypeEnum.Certificate).FirstOrDefault(); if (certificatDoc != null) supportDocument.Insert(0, certificatDoc); result.Collection = supportDocument; Documents = result; } }
public void GenerateReleaseNoteReport() { string errors = string.Empty; VocEntities db = new VocEntities(); ReleaseNote rs = db.ReleaseNotes.FirstOrDefault(x => x.ReleaseNoteId == 3001); MemoryStream report = WordManagement.GenerateReleaseNoteReport(rs, @"D:\NewTfs\VocIraqMain\Cotecna.Voc\Cotecna.Voc.Silverlight.Web\WordTemplates\TemplateRN.docx", out errors); report.Position = 0; File.WriteAllBytes(@"D:\rs.docx", report.ToArray()); WordManagement.SaveWordReportAsPdf(report,@"D:\rs.docx"); }
/// <summary> /// Searh the certificate list in base the filter criteria /// </summary> /// <param name="selectedPage">Selected page</param> /// <param name="isExport">When the data is exported to Microsoft Excel</param> public void SearchCertificateList(int selectedPage, bool isExport = false) { PaginatedList<CertificateDocument> result = new PaginatedList<CertificateDocument>(); int pageSize = result.PageSize; int currentIndex = (selectedPage - 1) * pageSize; using (VocEntities db = new VocEntities()) { var query = (from certificate in db.Certificates join document in db.Documents on certificate.CertificateId equals document.CertificateId into outer from document in outer.Where(f => f.IsDeleted == false && f.IsSupporting == false).DefaultIfEmpty() where certificate.IsDeleted == false && certificate.IsPublished == true select new CertificateDocument { Certificate = certificate, FileName = document.Filename, FilePath = document.FilePath, EntryPoint = certificate.EntryPoint }); query = FilterQuery.CreateCertificateFilters(query, this); List<CertificateDocument> queryList = null; if (!isExport) { queryList = query.OrderByDescending(item => item.Certificate.Sequential.Substring(6, 2)) .ThenByDescending(item => item.Certificate.Sequential.Substring(9, 5)) .Skip(currentIndex) .Take(pageSize) .ToList(); } else { queryList = query.OrderByDescending(item => item.Certificate.Sequential.Substring(6, 2)) .ThenByDescending(item => item.Certificate.Sequential.Substring(9, 5)) .ToList(); } result.Collection = queryList; //set the quantity of elements without pagination result.TotalCount = query.Count(); //set the number of pages result.NumberOfPages = (int)Math.Ceiling((double)result.TotalCount / (double)result.PageSize); result.Page = selectedPage; Certificates = result; } }
/// <summary> /// Filter by office /// </summary> /// <param name="filters">Filter parameters</param> /// <param name="user">Logged user</param> /// <param name="queryfiltered">Query to filter</param> /// <returns></returns> private static IQueryable<Certificate> FilterByOffice(CertificateFilterModel filters, VocUser user, IQueryable<Certificate> queryfiltered) { //filter by office if (filters.SelectedOffice > 0) queryfiltered = queryfiltered.Where(c => c.OfficeId == filters.SelectedOffice); else if (filters.SelectedOffice == 0 && user.IsRoUser && user.IsInRole(UserRoleEnum.Coordinator, UserRoleEnum.Issuer)) { VocEntities context = new VocEntities(); var localOffices = context.Offices.Where(x => x.RegionalOfficeId == user.OfficeId).Select(x => x.OfficeId).ToList(); var roOffice = context.Offices.FirstOrDefault(x => x.OfficeId == user.OfficeId).OfficeId; localOffices.Add(roOffice); context.Dispose(); queryfiltered = queryfiltered.Where(c => localOffices.Contains(c.OfficeId.Value)); } return queryfiltered; }
protected void Page_Load(object sender, EventArgs e) { // Get parameters string fileIdQuery = Request.QueryString["CertificateId"]; string documentIdQuery = Request.QueryString["DocumentId"]; string exportDocumentQuery = Request.QueryString["ExportDocument"]; string filename = Request.QueryString["filename"]; try { int certificateId; int documentId; if (int.TryParse(fileIdQuery, out certificateId)) { using (var ctx = new VocEntities()) { var certificate = ctx.Certificates.FirstOrDefault(x => x.CertificateId == certificateId); if (certificate != null) { string fileName = string.Empty; if(certificate.CertificateStatusId==CertificateStatusEnum.Conform) fileName="Coc.docx"; else fileName = "NCR.docx"; string templates = Server.MapPath(VirtualPathUtility.ToAbsolute("~/WordTemplates/")); string templatePath = templates + fileName; string errorValidation = string.Empty; var file = WordManagement.GenerateWordReport(certificate, templatePath,out errorValidation); if (!string.IsNullOrEmpty(errorValidation)) { lblDisplayFilesError.Text = errorValidation; return; } byte[] getContent = file.ToArray(); string certificateIdentifier = VocService.FixComdivNumberInformation(certificate); ReturnFile(certificateIdentifier + "_" + fileName, getContent); } } } else if(int.TryParse(documentIdQuery, out documentId)) { using (var ctx=new VocEntities()) { var doc=ctx.Documents.Where(x=>x.DocumentId==documentId).FirstOrDefault(); if (doc != null) { string path = Properties.Settings.Default.PathDocument + doc.FilePath + doc.Filename; if (!File.Exists(path)) { lblDisplayFilesError.Text = "Not exist the file: " + doc.Filename; return; } byte[] byteArray = File.ReadAllBytes(path); ReturnFile(doc.Filename, byteArray); } else { lblDisplayFilesError.Text = "Not found the document required"; } } } else if (!string.IsNullOrEmpty(exportDocumentQuery)) { string NameDocument= exportDocumentQuery; string folder = AuthenticationDomainService.GetSourcePathExcelFile(); string fullPath = folder + @"\" + NameDocument ; if (!File.Exists(fullPath)) { lblDisplayFilesError.Text = "file not found"; return; } byte[] byteArray = File.ReadAllBytes(fullPath); ReturnFile(NameDocument, byteArray); } else if (!string.IsNullOrEmpty(filename)) { VocEntities db = new VocEntities(); Document doc = db.Documents.FirstOrDefault(x => x.Filename == filename && x.IsDeleted == false); string path = Properties.Settings.Default.PathDocument + doc.FilePath + doc.Filename; if (!File.Exists(path)) { lblDisplayFilesError.Text = "file not found"; return; } byte[] byteArray = File.ReadAllBytes(path); ReturnFile(filename, byteArray); } } catch (Exception ex) { lblDisplayFilesError.Text = ex.Message; } }