public ProtocolReport(ReportModel model) : base(model, "ProtocolTemplate.docx") { this.modelItems = ReportModel.ReportParameters["ProtocolResults"] as IOrderedEnumerable<ProtocolResult>; this.hasMKB = this.modelItems.Any(pr => pr.ProductTest.Test.TestType.ShortName == TestTypes.MKB); this.hasFZH = this.modelItems.Any(pr => pr.ProductTest.Test.TestType.ShortName == TestTypes.FZH); }
public string GenerateRequestListReport(Guid diaryId, DateTime date, int testingPeriod) { var diary = db.Diaries.Single(d => d.Id == diaryId); var diaryW = new DiaryW(diary); var acreditedItems = new List<RequestListModel>(); var notAcreditedItems = new List<RequestListModel>(); foreach (var product in diary.Products.OrderBy(dp => dp.Number)) { if (product.ProductTests.Any(pt => pt.Test.AcredetationLevel.Level == AcreditationLevels.Acredited)) { var item = new RequestListModel(); item.ProductNumber = product.Number; item.ProductName = product.Name; item.ProductTests = product.ProductTests .Where(pt => pt.Test.AcredetationLevel.Level == AcreditationLevels.Acredited) .Select(pt => new SubListModel() { TestType = pt.Test.TestType.ShortName, TestName = pt.Test.Name, Method = pt.TestMethod.Method, MethodValue = pt.Test.MethodValue, Remark = pt.Remark }) .ToList(); acreditedItems.Add(item); } if (product.ProductTests.Any(pt => pt.Test.AcredetationLevel.Level == AcreditationLevels.NotAcredited)) { var item = new RequestListModel(); item.ProductNumber = product.Number; item.ProductName = product.Name; item.ProductTests = product.ProductTests .Where(pt => pt.Test.AcredetationLevel.Level == AcreditationLevels.NotAcredited) .Select(pt => new SubListModel() { TestType = pt.Test.TestType.ShortName, TestName = pt.Test.Name, Method = pt.TestMethod.Method, MethodValue = pt.Test.MethodValue, Remark = pt.Remark }) .ToList(); notAcreditedItems.Add(item); } } string requestsGeneratedCount = string.Empty; if (acreditedItems.Count > 0) { //GENERATE REQUEST A var model = new ReportModel(); model.ReportParameters.Add("RequestNumber", AcreditationLevels.Acredited + diaryW.Number); model.ReportParameters.Add("TestingPeriod", testingPeriod); model.ReportParameters.Add("Date", date); model.reportItems = acreditedItems; var report = new RequestListReport(model); var data = report.GenerateReport(); //this is supposed to create all the necessary directories for the file. CheckAndGenerateDirectories(diary.Number); var fileProps = GetFileProperties(diary.Number, FileNames.RequestListReport, AcreditationLevels.Acredited); if (File.Exists(fileProps.FullPath)) { string newDestination = fileProps.FullPath.Substring(0, fileProps.FullPath.Length - 5) + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".xlsx"; File.Move(fileProps.FullPath, newDestination); } var file = File.Create(fileProps.FullPath); file.Write(data, 0, data.Length); file.Close(); requestsGeneratedCount += "A"; } if (notAcreditedItems.Count > 0) { //Generate Request B var model = new ReportModel(); model.ReportParameters.Add("RequestNumber", AcreditationLevels.NotAcredited + diaryW.Number); model.ReportParameters.Add("TestingPeriod", testingPeriod); model.ReportParameters.Add("Date", date); model.reportItems = notAcreditedItems; var report = new RequestListReport(model); var data = report.GenerateReport(); //this is supposed to create all the necessary directories for the file. CheckAndGenerateDirectories(diary.Number); var fileProps = GetFileProperties(diary.Number, FileNames.RequestListReport, AcreditationLevels.NotAcredited); if (File.Exists(fileProps.FullPath)) { string newDestination = fileProps.FullPath.Substring(0, fileProps.FullPath.Length - 5) + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".xlsx"; File.Move(fileProps.FullPath, newDestination); } var file = File.Create(fileProps.FullPath); file.Write(data, 0, data.Length); file.Close(); requestsGeneratedCount += "B"; } return requestsGeneratedCount; }
private void WriteProtocolReport(Protocol protocol, int diaryNumber, string category, IEnumerable<Product> products, Request request) { var model = new ReportModel(); model.ReportParameters.Add("AcredetationLevel", category); model.ReportParameters.Add("ProtocolNumber", category + diaryNumber); model.ReportParameters.Add("ProtocolIssuedDate", protocol.IssuedDate); model.ReportParameters.Add("Products", products); //var methods = products.SelectMany(p => p.ProductTests.Where(pt => pt.Test.AcredetationLevel.Level.Trim() == category).Select(pt => pt.Test.TestMethods)).Distinct(); var methods = products.SelectMany(p => p.ProductTests.Where(pt => pt.Test.AcredetationLevel.Level.Trim() == category) .Select(pt => new MethodsModel() { TestName = pt.Test.Name, TestMethod = pt.TestMethod.Method })).ToList().Distinct(); model.ReportParameters.Add("Methods", methods); var quantities = products.OrderBy(p => p.Number).Select(p => p.Quantity); model.ReportParameters.Add("Quantities", quantities); var protocolResults = protocol.ProtocolResults.Where(pr => pr.ProductTest.Test.AcredetationLevel.Level.Trim() == category) .OrderBy(x => x.ProductTest.Product.Number).ThenBy(x => x.ProductTest.Test.Name).ThenBy(x => x.ResultNumber); model.ReportParameters.Add("ProtocolResults", protocolResults); model.ReportParameters.Add("Contractor", request.Diary.Contractor); model.ReportParameters.Add("Client", request.Diary.Client.Name); model.ReportParameters.Add("LetterNumber", request.Diary.LetterNumber); model.ReportParameters.Add("LetterDate", request.Diary.LetterDate); model.ReportParameters.Add("RequestDate", request.Date.ToLocalTime()); model.ReportParameters.Add("LabLeader", protocol.LabLeader); model.ReportParameters.Add("TesterMKB", protocol.TesterMKB); model.ReportParameters.Add("TesterFZH", protocol.TesterFZH); var remarks = protocol.ProtocolsRemarks.Where(r => r.AcredetationLevel.Level.Trim() == category); model.ReportParameters.Add("Remarks", remarks); if (category == "A") { string acredetationString = @"АКРЕДИТИРАНА СЪГЛАСНО БДС EN ISO/IEC 17025:2006 СЕРТИФИКАТ №55 ЛИ ОТ 08.04.2015 г./ ИА „БСА” С ВАЛИДНОСТ НА АКРЕДИТАЦИЯТА ДО 31.03.2016 г. "; model.ReportParameters.Add("AcredetationString", acredetationString); } var report = new ProtocolReport(model); var data = report.GenerateReport(); CheckAndGenerateDirectories(diaryNumber); var fileProps = GetFileProperties(diaryNumber, FileNames.Protocol, category); if (File.Exists(fileProps.FullPath)) { string newDestination = fileProps.FullPath.Substring(0, fileProps.FullPath.Length - 5) + "_" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".docx"; File.Move(fileProps.FullPath, newDestination); } var file = File.Create(fileProps.FullPath); file.Write(data, 0, data.Length); file.Close(); }
public EPPlusBaseGeneric(ReportModel model, string fileName) : base(fileName) { this.ReportModel = model; }
public EPPlusBaseGeneric(ReportModel model) : base() { this.ReportModel = model; }
public DocXReportBase(ReportModel model, string fileName) : base(fileName) { this.ReportModel = model; }
public DocXReportBase(ReportModel model) : base() { this.ReportModel = model; }