public WordPrintedDocument GetPrintedDocument(int idCommission, string name) { try { CheckViewRight(); var transaction = Context.CommissionTransactions .All(x => x.User, x => x.Buyer.City, x => x.Buyer.Region, x => x.Buyer.LegalPerson, x => x.Owner.City, x => x.Owner.Region, x => x.Owner.LegalPerson, x => x.Seller.City, x => x.Seller.Region, x => x.Seller.LegalPerson, x => x.Trancport.Make, x => x.Trancport.Model, x => x.Trancport.Type, x => x.Trancport.Category, x => x.Trancport.EngineType) .FirstOrDefault(x => x.Id == idCommission); if (transaction == null) { throw new SqlNullValueException("Документ не найден"); } var typeId = PrintedDocumentTemplateType.Сделка.ToString(); var fileTemplate = Context.PrintedDocumentTemplates.All().FirstOrDefault(x => x.Name == name); if (fileTemplate == null) { throw new SqlNullValueException("Шаблон не найден"); } var template = new CommissionTransactionPrintedDocumentTemplate(transaction, fileTemplate.File); using (var printedService = new WordPrintedDocumentService()) { return((WordPrintedDocument)printedService.GetDocument(template)); } } catch (SqlNullValueException) { throw; } catch (AccessDeniedException) { throw; } catch (Exception ex) { Logger.Instance.Log(ex); throw new Exception("Не удалось получить печатную форму, обратитесь к администратору"); } }
public WordPrintedDocument GetPrintedDocument(int idTransaction, string name) { try { CheckViewRight(); var transaction = Context.CreditTransactions .All(x => x.User, x => x.Buyer.City, x => x.Buyer.Region, x => x.Buyer.LegalPerson, x => x.Owner.City, x => x.Owner.Region, x => x.Owner.LegalPerson, x => x.Seller.City, x => x.Seller.Region, x => x.Seller.LegalPerson, x => x.Trancport.Make, x => x.Trancport.Model, x => x.Trancport.Type, x => x.Trancport.Category, x => x.Trancport.EngineType, x => x.Creditor, x => x.Requisit) .FirstOrDefault(x => x.Id == idTransaction); if (transaction == null) { throw new SqlNullValueException("Документ не найден"); } PrintedDocumentTemplate template = null; if (name == CreditTransactionPrintedDocumentTemplate.AKT_REPORT_NAME || name == CreditTransactionPrintedDocumentTemplate.DKP_REPORT_NAME) { var creditorName = transaction.Creditor.Name; if (name == CreditTransactionPrintedDocumentTemplate.AKT_REPORT_NAME) { string typeAkt = PrintedDocumentTemplateType.Акт.ToString(); template = Context.PrintedDocumentTemplates .All() .FirstOrDefault(x => x.Name == creditorName && x.Type == typeAkt); } else { string typeDkp = PrintedDocumentTemplateType.Дкп.ToString(); template = Context.PrintedDocumentTemplates .All() .FirstOrDefault(x => x.Name == creditorName && x.Type == typeDkp); } } else { template = Context.PrintedDocumentTemplates .All() .FirstOrDefault(x => x.Name == name); } if (template == null) { throw new SqlNullValueException("Шаблон не найден"); } var resurl = new CreditTransactionPrintedDocumentTemplate(transaction, template.File); using (var printedService = new WordPrintedDocumentService()) { return((WordPrintedDocument)printedService.GetDocument(resurl)); } } catch (AccessDeniedException) { throw; } catch (Exception ex) { Logger.Instance.Log(ex); throw new Exception("Не удалось получить список печатных форм, обратитесь к администратору"); } }