public WordPrintedDocument GetPrintedDocument(int idTransaction, string name)
        {
            try
            {
                CheckViewRight();

                var transaction = Context.CashTransactions
                                  .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 == idTransaction);
                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 CashTransactionPrintedDocumentTemplate(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("Не удалось получить печатную форму, обратитесь к администратору");
            }
        }
Exemplo n.º 2
0
        public WordPrintedDocument GetPrintedDocument(DocumentType type, string name, int id)
        {
            try
            {
                using (var context = IoC.Resolve <IAimpContext>())
                {
                    switch (type)
                    {
                    case DocumentType.CashTransaction:
                    {
                        var transaction = context.CashTransactions
                                          .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 == id);
                        if (transaction == null)
                        {
                            throw new NullReferenceException("Документ не найден");
                        }
                        var typeId       = PrintedDocumentTemplateType.Сделка.ToString();
                        var fileTemplate =
                            context.PrintedDocumentTemplates.All().FirstOrDefault(x => x.Name == name);
                        if (fileTemplate == null)
                        {
                            throw new NullReferenceException("Шаблон не найден");
                        }
                        var template = new CashTransactionPrintedDocumentTemplate(transaction, fileTemplate.File);
                        using (var printedService = new WordPrintedDocumentService())
                        {
                            return((WordPrintedDocument)printedService.Build(template));
                        }
                    }

                    case DocumentType.CreditTransaction:
                    {
                        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 == id);
                        if (transaction == null)
                        {
                            throw new NullReferenceException("Документ не найден");
                        }
                        Entities.IPrintedDocumentTemplate 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 NullReferenceException("Шаблон не найден");
                        }
                        var resurl = new CreditTransactionPrintedDocumentTemplate(transaction, template.File);
                        using (var printedService = new WordPrintedDocumentService())
                        {
                            return((WordPrintedDocument)printedService.Build(resurl));
                        }
                    }

                    case DocumentType.Commission:
                    {
                        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 == id);
                        if (transaction == null)
                        {
                            throw new NullReferenceException("Документ не найден");
                        }
                        var typeId       = PrintedDocumentTemplateType.Сделка.ToString();
                        var fileTemplate =
                            context.PrintedDocumentTemplates.All().FirstOrDefault(x => x.Name == name);
                        if (fileTemplate == null)
                        {
                            throw new NullReferenceException("Шаблон не найден");
                        }
                        var template = new CommissionTransactionPrintedDocumentTemplate(transaction, fileTemplate.File);
                        using (var printedService = new WordPrintedDocumentService())
                        {
                            return((WordPrintedDocument)printedService.Build(template));
                        }
                    }

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerProvider.Logger.Log(ex);
                throw;
            }
        }