private DocumentVM DocumentFromTS(DocumentVM documentVM)
        {
            // Create document in archive base from trading system
            Document newDocument = new Document()
            {
                name        = documentVM.Document.name,
                number      = documentVM.Document.number,
                description = "_",
                type        = 21,
                author      = "_",
                createdDate = documentVM.Document.createdDate,
                uploadDate  = DateTime.Now,
                company     = documentVM.Document.company.Replace("'", "")
            };

            // Create link
            var CurrentNode = TemporaryDataService.GetCurrentNodeVM();

            string url  = CurrentNode == null ? "" : GetNewPath(CurrentNode);
            string path = string.IsNullOrEmpty(url) ? "" : FolderService.GetFolderPath(1, CurrentNode.Node.Name, url) + string.Format("{0} {1}.{2}", "Договор", newDocument.number.Replace("/", "_").Replace("\\", "_"), documentVM.Document.exchange.Substring(documentVM.Document.exchange.LastIndexOf(".") + 1));

            int linkId = DocumentService.CreateDocumentLink(path, path.Substring(path.LastIndexOf(".") + 1));

            if (linkId > 0)
            {
                newDocument.linkId = linkId;
                string query = string.Format("{0}={1},{2}", CurrentNode.Node.Level_id, CurrentNode.Node.Name, presentTreeVM.GetParentValues(CurrentNode.Parent));

                // Create document in base
                int newDocId = DocumentService.CreateDocument(newDocument, 1, query);

                if (newDocId > 0)
                {
                    // Set archive serial number if archive presentation
                    DocumentService.UpdateDocumentWithASN(newDocId, 0);

                    // Copy attached file to destination
                    FileSystemService.CopyFile(documentVM.Document.exchange, path);

                    var newDoc = DocumentService.ReadDocument(newDocId);

                    if (newDoc == null)
                    {
                        return(null);
                    }

                    documentVM.Document = newDoc;

                    return(documentVM);
                }
            }

            return(null);
        }
示例#2
0
        public void Copy(string sourcePath, string destinationPath)
        {
            string text = Path.Combine(RootDirectoryPath, PreparePath(sourcePath));
            string path = Path.Combine(RootDirectoryPath, PreparePath(destinationPath));

            if (FileSystemService.DirectoryExists(text))
            {
                string destinationPath2 = GenerateCopiedFileItemPath(path, Path.GetFileName(text), isDirectory: true);
                FileSystemService.CopyDirectory(text, destinationPath2);
            }
            else if (FileSystemService.FileExists(text))
            {
                string destinationFilePath = GenerateCopiedFileItemPath(path, Path.GetFileName(text), isDirectory: false);
                FileSystemService.CopyFile(text, destinationFilePath);
            }
            else
            {
                FileManagementExceptionExecutor.ThrowFileNotFound(destinationPath);
            }
        }
        private void Save()
        {
            if (IsAttach && !string.IsNullOrEmpty(SearchCompanyTxt) && !string.IsNullOrEmpty(DocumentNumber))
            {
                Document newDocument = FillDocument();

                // Get path from tree nodes
                string url = CurrentNode == null ? "" : GetNewPath(CurrentNode);

                // Check folder exist
                string path = string.IsNullOrEmpty(url) ? "" : FolderService.GetFolderPath((int)CurrentPresentation, CurrentNode.Node.Name, url) + string.Format("{0} {1}.{2}", SelectedDocumentType.descriptionRU, newDocument.number.Replace("/", "_").Replace("\\", "_"), AttachedDocument.Substring(AttachedDocument.LastIndexOf(".") + 1));

                if (document != null && document.id != null && document.id > 0) // Update
                {
                    // Update link if need
                    if (AttachedDocument != DocumentService.ReadDocumentLink(document.id))
                    {
                        if (!string.IsNullOrEmpty(path))
                        {
                            DocumentService.UpdateDocumentLink(path, path.Substring(path.LastIndexOf(".") + 1), (int)document.linkId);

                            // Copy attached file to destination
                            if (FileSystemService.CopyFile(AttachedDocument, path))
                            {
                                MessagesService.Show("РЕДАКТИРОВАНИЕ", "Файл удачно занесен в архив");
                            }
                        }
                        else
                        {
                            MessagesService.Show("РЕДАКТИРОВАНИЕ", "Изменение прикрепленного файла не возможно, так как не выбрана ветка пути.\nБудут изменены лишь основные данные.");
                        }
                    }

                    // Update document
                    DocumentService.UpdateDocument(newDocument, document.id);

                    // Update serial number
                    if (CurrentPresentation == PresentationEnum.Archive)
                    {
                        DocumentService.UpdateDocumentWithASN(document.id, DocumentSerialNumber);
                    }

                    // Update view
                    presentTreeVM.DetailsVM.SelectedDocument.Document = DocumentService.ReadDocument(document.id);

                    // Close panel
                    Cancel();
                }
                else // Create
                {
                    // Create link
                    int linkId = DocumentService.CreateDocumentLink(path, path.Substring(path.LastIndexOf(".") + 1));

                    if (linkId > 0)
                    {
                        newDocument.linkId = linkId;
                        string query = string.Format("{0}={1},{2}", CurrentNode.Node.Level_id, CurrentNode.Node.Name, presentTreeVM.GetParentValues(CurrentNode.Parent));

                        // Create document in base
                        int newDocId = DocumentService.CreateDocument(newDocument, (int)CurrentPresentation, query);

                        if (newDocId > 0)
                        {
                            // Set archive serial number if archive presentation
                            if (CurrentPresentation == PresentationEnum.Archive)
                            {
                                DocumentService.UpdateDocumentWithASN(newDocId, DocumentSerialNumber);
                            }

                            // Copy attached file to destination
                            if (FileSystemService.CopyFile(AttachedDocument, path))
                            {
                                MessagesService.Show("СОХРАНЕНИЕ", "Файл удачно занесен в архив");

                                // Update view
                                presentTreeVM.DetailsVM.Documents.Add(new DocumentVM(DocumentService.ReadDocument(newDocId)));

                                // Close panel
                                Cancel();
                            }
                            else
                            {
                                MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время занесения файла в архив");
                            }
                        }
                        else
                        {
                            MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время сохранения документа в базе");
                        }
                    }
                    else
                    {
                        MessagesService.Show("СОХРАНЕНИЕ", "Произошла ошибка во время сохранения пути");
                    }
                }
            }
            else
            {
                MessagesService.Show("СОХРАНЕНИЕ", "Нет прикрепленного документа или не все данные заполненны.");
            }
        }