/// <summary> /// Загрузить файл в карточку документа /// </summary> /// <param name="objectContext">Контекст объекта</param> /// <param name="provider">Провайдер</param> /// <param name="uploadFilesDir">Временная директория загрузки файла</param> /// <returns><see cref="Guid"/></returns> public Guid UploadFile(ObjectContext objectContext, MultipartFormDataStreamProvider provider, string uploadFilesDir) { var documentService = objectContext.GetService <DocsVision.BackOffice.ObjectModel.Services.IDocumentService>(); var cardId = new Guid(provider.FormData["cardId"]); var card = objectContext.GetObject <Document>(cardId); var fileDataItem = provider.FileData.SingleOrDefault() ?? throw new InvalidOperationException("There is no file content"); var newFileName = Path.Combine(uploadFilesDir, fileDataItem.Headers.ContentDisposition.FileName); File.Move(fileDataItem.LocalFileName, newFileName); var documentFile = documentService.AttachMainFile(card, newFileName); objectContext.AcceptChanges(); return(documentFile.FileVersionRowId); }
/// <summary> /// Конструктор формы заполнения журнала условий калибровки. /// </summary> /// <param name="Session">Пользовательская сессия DV.</param> /// <param name="Context">Объектный контекст.</param> /// <param name="JournalItemType">Тип справочника.</param> /// <param name="CabinetNumber">Номер кабинета.</param> public JournalForm(UserSession Session, ObjectContext Context, BaseUniversalItemType JournalItemType, Int32 CabinetNumber) { InitializeComponent(); this.Session = Session; this.Context = Context; IBaseUniversalService baseUniversalService = Context.GetService <IBaseUniversalService>(); this.CabinetNumber = CabinetNumber; staffEmployee = Context.GetCurrentEmployee(); BaseUniversalItem NewItem = baseUniversalService.AddNewItem(JournalItemType); NewItem.Name = "Каб. №" + CabinetNumber + ". Условия на " + DateTime.Today.ToShortDateString(); this.Text = "Каб. №" + (CabinetNumber == 237 ? 226 : 228) + ". Условия на " + DateTime.Today.ToShortDateString(); itemCard = baseUniversalService.OpenOrCreateItemCard(NewItem); NewItem.ItemCard = itemCard; Context.AcceptChanges(); this.Date.DateTime = DateTime.Today; this.Employee.Text = staffEmployee.DisplayString; }
/// <summary> /// Создать карточку документа /// </summary> /// <param name="sessionContext">Контекст сессии</param> /// <param name="objectContext">Контекст объекта</param> /// <param name="document">Модель документа</param> /// <returns><see cref="Guid"/></returns> public Guid Create(SessionContext sessionContext, ObjectContext objectContext, DocumentModel document) { var documentService = objectContext.GetService <DocsVision.BackOffice.ObjectModel.Services.IDocumentService>(); var kindsCardKind = document.KindId.HasValue ? objectContext.GetObject <KindsCardKind>(document.KindId) : null; var documentCard = documentService.CreateDocument(null, kindsCardKind); objectContext.AcceptChanges(); var cardId = documentCard.GetObjectId(); var cardData = sessionContext.Session.CardManager.GetCardData(cardId); cardData.BeginUpdate(); try { var mainInfoRow = cardData.Sections[CardDocument.MainInfo.ID].FirstRow; mainInfoRow.SetString(CardDocument.MainInfo.Name, document.Name); mainInfoRow.SetGuid(CardDocument.MainInfo.Registrar, document.Registrar); mainInfoRow.SetDateTime(CardDocument.MainInfo.RegDate, document.RegDate); if (document.Contract != null) { var documentContractRow = cardData.Sections[CardDocument.Contract.ID].FirstRow; documentContractRow.SetDecimal(CardDocument.Contract.ContractSum, document.Contract.ContractSum); documentContractRow.SetInt32(CardDocument.Contract.ContractCurrency, (int?)document.Contract.ContractCurrency); } cardData.EndUpdate(); return(cardId); } catch (Exception ex) { Logger.Error(ex); cardData.CancelUpdate(); throw; } }