/// <summary> /// Инициализирует папку заданными значениями. /// </summary> /// <param name="Device">Прибор.</param> /// <param name="CodeID">ID кода СКБ.</param> /// <param name="CodeName">Отобразаемое значение кода СКБ.</param> /// <param name="DocumentID">ID документа.</param> /// <param name="DocumentName">Название документа.</param> /// <param name="FolderID">ID папки.</param> public DocumentsFolder(Folder ParentFolder, CardData Document, SavedSearchGroup SearchGroup, SavedView View, FolderCard FolderCard) { this.ParentFolder = ParentFolder; this.Document = Document; DocumentID = Document.Id; SectionData Properties = Document.Sections[CardOrd.Properties.ID]; DocumentType = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.FileType + "'").GetString("Value"); RowData Code = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Code + "'"); CodeID = Code.GetGuid("Value").Value; CodeName = Code.GetString("DisplayValue"); RowData Applicable = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.Applicable + "'"); Applicability = Applicable.GetString("DisplayValue"); RowData Name = Properties.FindRow("@Name = '" + RefPropertiesCD.Requisities.DocumentName + "'"); string ShortType = DocumentType == "СД - Спецификация (не платы)" || DocumentType == "СП - Спецификация платы" ? "" : DocumentType.Remove(DocumentType.IndexOf(" - ")); DocumentName = CodeName + " " + ShortType + " " + Name.GetString("Value"); Folder = FolderCard.CreateFolder(ParentFolder.Id, DocumentName); Folder.Type = FolderTypes.Virtual; if (!SearchGroup.Queries.Any(row => row.Name == DocumentName)) { SearchQuery Query = FolderCard.Session.CreateSearchQuery(); CardTypeQuery CardType = Query.AttributiveSearch.CardTypeQueries.AddNew(CardOrd.ID); SectionQuery Section = CardType.SectionQueries.AddNew(CardOrd.MainInfo.ID); Section.Operation = SectionQueryOperation.And; Section.ConditionGroup.Operation = ConditionGroupOperation.And; Section.ConditionGroup.Conditions.AddNew(CardOrd.MainInfo.Type, FieldType.RefId, ConditionOperation.Equals, MyHelper.RefType_CD); Section = CardType.SectionQueries.AddNew(CardOrd.Properties.ID); Section.Operation = SectionQueryOperation.And; Section.ConditionGroup.Operation = ConditionGroupOperation.And; Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.Unistring, ConditionOperation.Equals, DocumentType); Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.FileType); Section = CardType.SectionQueries.AddNew(CardOrd.Properties.ID); Section.Operation = SectionQueryOperation.And; Section.ConditionGroup.Operation = ConditionGroupOperation.And; Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Value, FieldType.RefId, ConditionOperation.Equals, CodeID); Section.ConditionGroup.Conditions.AddNew(CardOrd.Properties.Name, FieldType.Unistring, ConditionOperation.Equals, RefPropertiesCD.Requisities.Code); Query.Limit = 0; SearchGroup.Queries.AddNew(DocumentName).Import(Query); } SavedSearchQuery SavedQuery = SearchGroup.Queries.First(row => row.Name == DocumentName); Folder.RefId = SavedQuery.Id; Folder.CurrentViewId = View.Id; Folder.DefaultViewId = View.Id; }
/// <summary> /// Инициализирует строку по данным карточки файла. /// </summary> /// <param name="Context">Объектный контекст.</param> /// <param name="FileCard">Данные карточки файла.</param> private void Initalize(ObjectContext Context, CardData FileCard) { RowData FileCardMainInfoRow = FileCard.Sections[CardFile.MainInfo.ID].FirstRow; List <RowData> FileCardCategories = FileCard.Sections[CardFile.Categories.ID].Rows.Where(row => !row.GetObject(CardFile.Categories.CategoryID).ToGuid().IsEmpty()).ToList(); Guid AuthorId = FileCardMainInfoRow.GetGuid(CardFile.MainInfo.Author) ?? Guid.Empty; this.Name = FileCardMainInfoRow.GetString(CardFile.MainInfo.FileName); this.Size = (Decimal)FileCardMainInfoRow.GetInt32(CardFile.MainInfo.FileSize) / (Decimal)1024; this.Category = FileCardCategories.Any() ? FileCardCategories.Select(row => row.GetString("Name")).Aggregate((a, b) => a + ";" + b) : String.Empty; this.Registrar = AuthorId.IsEmpty() ? String.Empty : Context.GetEmployeeDisplay(AuthorId); this.RegistrarId = AuthorId; this.CreationDate = FileCard.CreateDate; }
public static Boolean RegisterProtocol(UserSession Session, String CardID, String TempFolder, Guid EmployeeId) { logger.Info("cardId='{0}'", CardID); logger.Info("tempName='{0}'", TempFolder); logger.Info("EmployeeId='{0}'", EmployeeId); using (new Impersonator(ServerExtension.Domain, ServerExtension.User, ServerExtension.SecurePassword)) { Guid CardId = new Guid(CardID); switch (Session.CardManager.GetCardState(CardId)) { case ObjectState.Existing: DirectoryInfo TempDirectory = new DirectoryInfo(Path.Combine(ArchiveTempPath, TempFolder)); FileInfo[] TempFiles = TempDirectory.GetFiles(); logger.Info("В папке файлов: " + TempFiles.Length); if (TempFiles.Length > 0) { logger.Info("Файлы: " + TempFiles.Select(file => file.Name).Aggregate((a, b) => a + "; " + b)); CardData Card = Session.CardManager.GetCardData(CardId); Card.UnlockCard(); if (Card.InUpdate) { Card.CancelUpdate(); } Card.PlaceLock(); Card.BeginUpdate(); foreach (Protocol Protocol in TempFiles.Select(fi => new Protocol(fi))) { if (Protocol.IsParsed) { RowData MainInfoRow = Card.Sections[CardOrd.MainInfo.ID].FirstRow; Guid FilesID = MainInfoRow.GetGuid(CardOrd.MainInfo.FilesID) ?? Guid.Empty; Boolean FileListExist = !(FilesID.IsEmpty() && Card.Session.CardManager.GetCardState(FilesID) == ObjectState.Existing); logger.Info("FileListExist = " + FileListExist); CardData FileListCard; if (FileListExist) { FileListCard = Card.Session.CardManager.GetCardData(FilesID); } else { FileListCard = Card.Session.CardManager.CreateCardData(FileList.ID); MainInfoRow.SetGuid(CardOrd.MainInfo.FilesID, FileListCard.Id); } SectionData FileReferencesSection = FileListCard.Sections[FileList.FileReferences.ID]; /* Проверка существования файла протокола в карточке */ if (!FileReferencesSection.Rows.Any(file => Protocol.PhysicalFile.Name.Contains(file.GetString(CardFile.MainInfo.FileName)))) { FileListCard.UnlockCard(); VersionedFileCard FileCard = (VersionedFileCard)Card.Session.CardManager.CreateCard(DocsVision.Platform.Cards.Constants.VersionedFileCard.ID); FileVersion FileCardVersion = FileCard.Initialize(Protocol.PhysicalFile.FullName, Guid.Empty, false, true); CardData FileData = Card.Session.CardManager.CreateCardData(CardFile.ID); FileData.BeginUpdate(); FileData.Description = "Файл: " + FileCard.Name; RowData FileMainInfoRow = FileData.Sections[CardFile.MainInfo.ID].Rows.AddNew(); FileMainInfoRow.SetGuid(CardFile.MainInfo.FileID, FileCard.Id); FileMainInfoRow.SetString(CardFile.MainInfo.FileName, FileCardVersion.Name); FileMainInfoRow.SetGuid(CardFile.MainInfo.Author, FileCardVersion.AuthorId); FileMainInfoRow.SetInt32(CardFile.MainInfo.FileSize, FileCardVersion.Size); FileMainInfoRow.SetInt32(CardFile.MainInfo.VersioningType, 0); RowData FilePropertiesRow = FileData.Sections[CardFile.Properties.ID].Rows.AddNew(); FilePropertiesRow.SetString(CardFile.Properties.Name, "Дата начала испытаний"); FilePropertiesRow.SetInt32(CardFile.Properties.ParamType, (Int32)PropertieParamType.Date); FilePropertiesRow.SetString(CardFile.Properties.Value, Protocol.StringDate); FilePropertiesRow.SetString(CardFile.Properties.DisplayValue, Protocol.StringDate); FileData.Sections[CardFile.Categories.ID].Rows.AddNew().SetGuid(CardFile.Categories.CategoryID, MyHelper.RefCategory_CalibrationProtocol); FileData.EndUpdate(); Int32 FilesCount = FileReferencesSection.Rows.Count; FileReferencesSection.Rows.AddNew().SetGuid(FileList.FileReferences.CardFileID, FileData.Id); FileListCard.Sections[FileList.MainInfo.ID].FirstRow.SetInt32(FileList.MainInfo.Count, FilesCount + 1); SectionData PropertiesSection = Card.Sections[CardOrd.Properties.ID]; RowData PropertyRow = PropertiesSection.GetProperty("Дата"); if (!PropertyRow.IsNull()) { RowDataCollection SelectedValuesRows = PropertyRow.ChildSections[CardOrd.SelectedValues.ID].Rows; RowData SelectedValuesRow = SelectedValuesRows.AddNew(); SelectedValuesRow.SetInt32(CardOrd.SelectedValues.Order, SelectedValuesRows.Count); SelectedValuesRow.SetDateTime(CardOrd.SelectedValues.SelectedValue, DateTime.Now); } PropertyRow = PropertiesSection.GetProperty("Действие"); if (!PropertyRow.IsNull()) { RowDataCollection SelectedValuesRows = PropertyRow.ChildSections[CardOrd.SelectedValues.ID].Rows; RowData SelectedValuesRow = SelectedValuesRows.AddNew(); SelectedValuesRow.SetInt32(CardOrd.SelectedValues.Order, SelectedValuesRows.Count); SelectedValuesRow.SetString(CardOrd.SelectedValues.SelectedValue, "Прикреплен протокол калибровки"); } PropertyRow = PropertiesSection.GetProperty("Участник"); if (!PropertyRow.IsNull()) { RowDataCollection SelectedValuesRows = PropertyRow.ChildSections[CardOrd.SelectedValues.ID].Rows; RowData SelectedValuesRow = SelectedValuesRows.AddNew(); SelectedValuesRow.SetInt32(CardOrd.SelectedValues.Order, SelectedValuesRows.Count); SelectedValuesRow.SetGuid(CardOrd.SelectedValues.SelectedValue, EmployeeId); } PropertyRow = PropertiesSection.GetProperty("Комментарий"); if (!PropertyRow.IsNull()) { RowDataCollection SelectedValuesRows = PropertyRow.ChildSections[CardOrd.SelectedValues.ID].Rows; RowData SelectedValuesRow = SelectedValuesRows.AddNew(); SelectedValuesRow.SetInt32(CardOrd.SelectedValues.Order, SelectedValuesRows.Count); SelectedValuesRow.SetString(CardOrd.SelectedValues.SelectedValue, "Автоматическое прикрепление протокола калибровки " + Protocol.PhysicalFile.Name); } PropertyRow = PropertiesSection.GetProperty("Ссылки"); if (!PropertyRow.IsNull()) { RowDataCollection SelectedValuesRows = PropertyRow.ChildSections[CardOrd.SelectedValues.ID].Rows; RowData SelectedValuesRow = SelectedValuesRows.AddNew(); SelectedValuesRow.SetInt32(CardOrd.SelectedValues.Order, SelectedValuesRows.Count); SelectedValuesRow.SetString(CardOrd.SelectedValues.SelectedValue, null); } if (!FileListExist) { Card.Sections[CardOrd.MainInfo.ID].FirstRow.SetGuid(CardOrd.MainInfo.FilesID, FileListCard.Id); } } } else { logger.Warn("Нераспознаный файл: " + Protocol.PhysicalFile.Name); } } Card.EndUpdate(); Card.RemoveLock(); TempDirectory.Delete(true); logger.Info("RegisterProtocol - выполнено."); } else { logger.Info("RegisterProtocol - не выполнено."); } return(true); default: logger.Info("RegisterProtocol - не выполнено. Паспорт прибора не существует."); return(false); } } }
private void CreateAccountCard_ItemClick(Object sender, ItemClickEventArgs e) { try { IReferenceListService ReferenceListService = Context.GetService <IReferenceListService>(); ReferenceList RefList = Context.GetObject <ReferenceList>(Control_Links.ReferenceListID); if (RefList.References.Any(r => r.CardType.Equals(RefAccountCard.ID))) { CardScript.CardFrame.CardHost.ShowCardModal(RefList.References.First(r => r.CardType.Equals(RefAccountCard.ID)).Card, ActivateMode.Edit); } if (Table_Service.RowCount > 0) { throw new MyException(1); } if (!CardScript.SaveCard()) { throw new MyException(0); } /* Формирование задания на отгрузку */ CardData AccountData = Context.CreateCard(RefAccountCard.ID); AccountData.BeginUpdate(); RowData MainInfoRow = AccountData.Sections[RefAccountCard.MainInfo.ID].FirstRow; SectionData Service = AccountData.Sections[RefAccountCard.Service.ID]; MainInfoRow.SetGuid(RefAccountCard.MainInfo.RegisterId, Context.GetCurrentUser()); MainInfoRow.SetGuid(RefAccountCard.MainInfo.ContractSubjectId, AccountCard.Item_Subject_Service.ToGuid()); MainInfoRow.SetGuid(RefAccountCard.MainInfo.ClientId, GetControlValue(RefApplicationCard.MainInfo.Client).ToGuid()); Guid?RefListId = MainInfoRow.GetGuid(RefAccountCard.MainInfo.LinkListId); RefList = RefListId.HasValue ? Context.GetObject <ReferenceList>(RefListId.Value) : ReferenceListService.CreateReferenceList(); if (!RefList.References.Any(RefRef => RefRef.Card.Equals(CardScript.CardData.Id))) { ReferenceListService.CreateReference(RefList, null, CardScript.CardData.Id, RefApplicationCard.ID, false); MainInfoRow.SetGuid(RefAccountCard.MainInfo.LinkListId, Context.GetObjectRef <ReferenceList>(RefList).Id); } RefList.References.First(RefRef => RefRef.Card.Equals(CardScript.CardData.Id)).LinkDescription = DateTime.Now.ToString("Создано dd.MM.yyyy HH:mm"); Context.SaveObject(RefList); for (Int32 i = 0; i < Table_Service.RowCount; i++) { BaseCardProperty Row = Table_Service[i]; RowData ServiceRow = Service.Rows.AddNew(); ServiceRow.SetGuid(RefAccountCard.Service.Id, Row[RefApplicationCard.Service.Id].ToGuid()); ServiceRow.SetGuid(RefAccountCard.Service.DeviceId, Row[RefApplicationCard.Service.DeviceID].ToGuid()); ServiceRow.SetBoolean(RefAccountCard.Service.AC, (Boolean)Row[RefApplicationCard.Service.Verify]); ServiceRow.SetBoolean(RefAccountCard.Service.Verify, (Boolean)Row[RefApplicationCard.Service.Verify]); ServiceRow.SetBoolean(RefAccountCard.Service.Repair, (Boolean)Row[RefApplicationCard.Service.Repair]); ServiceRow.SetBoolean(RefAccountCard.Service.Calibrate, (Boolean)Row[RefApplicationCard.Service.Calibrate]); ServiceRow.SetBoolean(RefAccountCard.Service.Delivery, false); ServiceRow.SetInt32(RefAccountCard.Service.Count, 1); ServiceRow.SetInt32(RefAccountCard.Service.Shipped, 0); ServiceRow.SetInt32(RefAccountCard.Service.ToShip, 1); ServiceRow.SetString(RefAccountCard.Service.ACList, Row[RefApplicationCard.Service.ACList]); ServiceRow.SetString(RefAccountCard.Service.PackedListData, Row[RefApplicationCard.Service.PackedListData]); ServiceRow.SetGuid(RefAccountCard.Service.PackedListId, Row[RefApplicationCard.Service.PackedListID].ToGuid()); ServiceRow.SetBoolean(RefAccountCard.Service.Warranty, (Boolean)Row[RefApplicationCard.Service.WarrantyServices]); } AccountData.EndUpdate(); if (CardScript.CardFrame.CardHost.ShowCardModal(AccountData.Id, ActivateMode.Edit, ActivateFlags.New)) { Control_Links.AddRef(AccountData.Id, DateTime.Now.ToString("Создано dd.MM.yyyy HH:mm"), true, false); MyHelper.SaveCard(CardScript); } else { AccountData.ForceUnlock(); CardScript.Session.CardManager.DeleteCard(AccountData.Id, true); } } catch (MyException Ex) { switch (Ex.ErrorCode) { case 1: MyMessageBox.Show("Таблица «Сервисное обслуживание» не заполнена!", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); break; } } catch (Exception Ex) { CallError(Ex); } }