示例#1
0
        // -----------------------------------------------------
        //    List Documents
        // -----------------------------------------------------
        public static List <DocumentVersion> List(Document document)
        {
            var documentIssueList = new List <DocumentVersion>();

            using (var connection = new SqlConnection(ConnString.ConnectionString))
            {
                var commandString = string.Format(
                    " SELECT " +
                    DocumentVersionFieldString() +
                    "  FROM " +
                    DocumentVersion.TableName +
                    " WHERE FKDocumentUID = '{0}'", document.UID);

                using (var command = new SqlCommand(
                           commandString, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DocumentVersion documentIssue = new DocumentVersion();
                            LoadObject(reader, documentIssue);

                            documentIssueList.Add(documentIssue);
                        }
                    }
                }
            }

            return(documentIssueList);
        }
示例#2
0
 /// <summary>
 /// Load reader information into object
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="documentIssue"></param>
 private static void LoadObject(SqlDataReader reader, DocumentVersion documentIssue)
 {
     documentIssue.UID            = Convert.ToInt32(reader["UID"].ToString());
     documentIssue.FKDocumentUID  = Convert.ToInt32(reader["FKDocumentUID"].ToString());
     documentIssue.FKDocumentCUID = reader["FKDocumentCUID"].ToString();
     documentIssue.IssueNumber    = Convert.ToInt32(reader["IssueNumber"].ToString());
     documentIssue.Location       = reader["Location"].ToString();
     documentIssue.FileName       = reader["FileName"].ToString();
 }
示例#3
0
        // -----------------------------------------------------
        //    Create new document version
        // -----------------------------------------------------
        public ResponseStatus NewVersion(HeaderInfo headerInfo)
        {
            ResponseStatus response = new ResponseStatus();

            response.Message = "New version created successfully.";

            // Copy existing version to old folder version
            // Old folder comes from %VERSIONFOLDER%
            //
            var versionFolder =
                CodeValue.GetCodeValueExtended(FCMConstant.CodeTypeString.SYSTSET, FCMConstant.SYSFOLDER.VERSIONFOLDER);

            // Create a record to point to the old version
            var documentVersion = new DocumentVersion();

            documentVersion.FKDocumentCUID = this.CUID;
            documentVersion.FKDocumentUID  = this.UID;

            // Generate the new version id
            documentVersion.IssueNumber = this.IssueNumber;
            documentVersion.Location    = Utils.GetVersionPath(this.Location);
            documentVersion.FileName    = this.FileName;
            documentVersion.Add();

            // Increments issue number
            this.IssueNumber++;

            // Create a new file name with version on it
            // POL-05-01 FILE NAME.doc
            //
            int    version  = Convert.ToInt32(this.IssueNumber);
            string tversion = version.ToString().PadLeft(2, '0');
            // string simpleFileName = this.Name.Substring(10).Trim();
            string simpleFileName = this.Name.Substring(07).Trim();

            string newFileName = this.CUID + '-' +
                                 tversion + '-' +
                                 simpleFileName;

            // string newFileNameWithExtension = newFileName + ".doc";

            // Well, the simple file name has extension already... so I have commented out the line above
            // 30/04/2011 - Testing to see if it works.
            //
            string newFileNameWithExtension = newFileName;

            // Copy the file with new name
            // Let's copy the document
            string realLocation        = Utils.getFilePathName(this.Location, this.FileName);
            string realDestination     = Utils.getFilePathName(documentVersion.Location, documentVersion.FileName);
            string realPathDestination = Utils.GetPathName(documentVersion.Location);

            if (!System.IO.Directory.Exists(realPathDestination))
            {
                System.IO.Directory.CreateDirectory(realPathDestination);
            }

            if (!System.IO.File.Exists(realLocation))
            {
                response.Message    = "File to be copied was not found. " + realLocation;
                response.ReturnCode = -0010;
                response.ReasonCode = 0001;
                response.UniqueCode = ResponseStatus.MessageCode.Error.FCMERR00000006;
                return(response);
            }
            File.Copy(realLocation, realDestination, true);

            // Copy file to new name
            //
            string newFilePathName = Utils.getFilePathName(
                this.Location,
                newFileNameWithExtension);

            File.Copy(realLocation, newFilePathName, true);

            // Delete old version from main folder
            //
            File.Delete(realLocation);

            // Update document details - version, name, etc
            this.IssueNumber = version;
            // this.ComboIssueNumber = "C" + version.ToString("000");
            this.FileName = newFileNameWithExtension;
            this.Name     = newFileName;
            this.UpdateVersion(headerInfo);

            // Build a screen to browse all versions of a file
            // Allow compare/ View
            // Check how to open a document read-only for users future

            response.Contents = version;
            return(response);
        }