Esempio n. 1
0
        public byte[] ExcelFromDocumentListForm(Guid documentId, BizDocumentListForm docListForm)
        {
            var form = docListForm.TableForm;

            if (form == null && docListForm.FormId != null)
            {
                form = FormRepo.GetTableForm((Guid)docListForm.FormId);
            }
            if (form == null)
            {
                throw new ApplicationException("Табличная форма не указана!");
            }

            var sqb = _sqlQueryBuilderFactory.Create();

            if (docListForm.AttributeDefId != null)
            {
                using (var query = sqb.BuildAttrList(form, documentId, (Guid)docListForm.AttributeDefId, null, null))
                {
                    query.WithNoLock = true;

                    using (var reader = _sqlQueryReaderFactory.Create(query))
                    {
                        var defBuilder = new XlsGridDefBuilder(Provider, form, reader);
                        using (var def = defBuilder.BuildFromBizForm())
                        {
                            var builder = new XlsBuilder(def);
                            using (var workbook = builder.Build())
                            {
                                using (var stream = new MemoryStream())
                                {
                                    workbook.Write(stream);

                                    return(stream.ToArray());
                                }
                            }
                        }
                    }
                }
            }

            if (docListForm.FormAttributeDefId != null)
            {
                using (var query = sqb.BuildRefList(form, documentId, (Guid)docListForm.FormAttributeDefId, null, null))
                {
                    using (var reader = _sqlQueryReaderFactory.Create(query)) //new SqlQueryReader(DataContext, query))
                    {
                        var defBuilder = new XlsGridDefBuilder(Provider, form, reader);
                        using (var def = defBuilder.BuildFromBizForm())
                        {
                            var builder = new XlsBuilder(def);
                            using (var workbook = builder.Build())
                            {
                                using (var stream = new MemoryStream())
                                {
                                    workbook.Write(stream);

                                    return(stream.ToArray());
                                }
                            }
                        }
                    }
                }
            }

            throw new ApplicationException("Не могу сформировать Excel файл! Атрибут не указан!");
        }
Esempio n. 2
0
 /// <summary>
 /// Загружает табличную форму по идентификатору формы
 /// </summary>
 /// <param name="formId">Идентификатор формы</param>
 /// <param name="languageId">Язык</param>
 /// <returns>Загруженная табличная форма</returns>
 //[SmartCache(TimeOutSeconds = 600)]
 public BizTableForm GetGridForm(Guid formId, int languageId = 0)
 {
     return(FormRepo.GetTableForm(formId, languageId));
 }