Example #1
0
        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);
                }
            }
        }