Beispiel #1
0
 public void WriteToLog(HeaderInfo headerInfo)
 {
     LogFile.WriteToTodaysLogFile(this.UniqueCode + this.Message, headerInfo.UserID);
 }
Beispiel #2
0
        /// <summary>
        /// Add new report metadata
        /// </summary>
        private void AddSubTransaction(
            SqlConnection connection,
            SqlTransaction sqltransaction,
            HeaderInfo headerInfo)
        {
            string ret  = "Item updated successfully";
            int    _uid = 0;

            _uid = GetLastUIDSubTransaction(connection, sqltransaction, headerInfo) + 1;

            DateTime _now = DateTime.Today;

            var commandString =
                (
                    "INSERT INTO [ReportMetadata] " +
                    "( " +
                    "  [UID] " +
                    " ,[RecordType] " +
                    " ,[Description] " +
                    " ,[FieldCode] " +
                    " ,[ClientType] " +
                    " ,[ClientUID] " +
                    " ,[InformationType] " +
                    " ,[Condition] " +
                    " ,[CompareWith] " +
                    " ,[Enabled] " +
                    " ) " +
                    " VALUES " +
                    " ( " +
                    "  @UID " +
                    " ,@RecordType " +
                    " ,@Description " +
                    " ,@FieldCode " +
                    " ,@ClientType " +
                    " ,@ClientUID " +
                    " ,@InformationType " +
                    " ,@Condition " +
                    " ,@CompareWith " +
                    " ,@Enabled " +
                    " )"
                );

            var command = new SqlCommand(commandString, connection, sqltransaction);

            command.Parameters.Add("@UID", SqlDbType.BigInt).Value              = _uid;
            command.Parameters.Add("@RecordType", SqlDbType.VarChar).Value      = RecordType;
            command.Parameters.Add("@Description", SqlDbType.VarChar).Value     = Description;
            command.Parameters.Add("@FieldCode", SqlDbType.VarChar).Value       = FieldCode;
            command.Parameters.Add("@ClientType", SqlDbType.VarChar).Value      = ClientType;
            command.Parameters.Add("@ClientUID", SqlDbType.BigInt).Value        = ClientUID;
            command.Parameters.Add("@InformationType", SqlDbType.VarChar).Value = InformationType;
            command.Parameters.Add("@Condition", SqlDbType.VarChar).Value       = Condition;
            command.Parameters.Add("@CompareWith", SqlDbType.VarChar).Value     = CompareWith;
            command.Parameters.Add("@Enabled", SqlDbType.Char).Value            = Enabled;

            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                LogFile.WriteToTodaysLogFile(ex.ToString(), headerInfo.UserID);
            }

            return;
        }
        // -----------------------------------------------------
        //    Add new Client Document Set
        // -----------------------------------------------------
        public ResponseStatus Add(HeaderInfo headerInfo, SqlConnection connection = null)
        {
            ResponseStatus response = new ResponseStatus();

            response.Message = "Client Document Set Added Successfully";

            UID         = GetLastUID() + 1;
            ClientSetID = GetLastUID(this.FKClientUID) + 1;
            Description = "Client Set Number " + ClientSetID;
            IsVoid      = "N";
            Status      = "DRAFT";

            FolderOnly =
                "CLIENT" + FKClientUID.ToString().Trim() +
                "SET" + ClientSetID.ToString().Trim().PadLeft(4, '0');

            Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + @"\" + this.FolderOnly;

            CreationDateTime = headerInfo.CurrentDateTime;
            UpdateDateTime   = headerInfo.CurrentDateTime;
            UserIdCreatedBy  = headerInfo.UserID;
            UserIdUpdatedBy  = headerInfo.UserID;

            // Default values
            DateTime _now = DateTime.Today;

            if (connection == null)
            {
                connection = new SqlConnection(ConnString.ConnectionString);
                connection.Open();
            }

            var commandString =
                (

                    "INSERT INTO [ClientDocumentSet] " +
                    "(" +
                    ClientDocumentSetFieldString() +
                    ")" +
                    " VALUES " +
                    "( @UID     " +
                    ", @FKClientUID    " +
                    ", @ClientSetID    " +
                    ", @Description " +
                    ", @Folder " +
                    ", @FolderOnly " +
                    ", @Status " +
                    ", @StartDate " +
                    ", @EndDate " +
                    ", @SourceFolder " +
                    ", @IsVoid " +
                    ", @CreationDateTime  " +
                    ", @UpdateDateTime " +
                    ", @UserIdCreatedBy " +
                    ", @UserIdUpdatedBy " +
                    ")"
                );

            using (var command = new SqlCommand(
                       commandString, connection))
            {
                command.Parameters.Add("@UID", SqlDbType.BigInt).Value                = UID;
                command.Parameters.Add("@FKClientUID", SqlDbType.BigInt).Value        = FKClientUID;
                command.Parameters.Add("@ClientSetID", SqlDbType.BigInt).Value        = ClientSetID;
                command.Parameters.Add("@Description", SqlDbType.VarChar).Value       = Description;
                command.Parameters.Add("@Folder", SqlDbType.VarChar).Value            = Folder;
                command.Parameters.Add("@FolderOnly", SqlDbType.VarChar).Value        = FolderOnly;
                command.Parameters.Add("@Status", SqlDbType.VarChar).Value            = Status;
                command.Parameters.Add("@SourceFolder", SqlDbType.VarChar).Value      = SourceFolder;
                command.Parameters.Add("@StartDate", SqlDbType.DateTime).Value        = _now;
                command.Parameters.Add("@EndDate", SqlDbType.DateTime).Value          = DateTime.MaxValue;
                command.Parameters.Add("@IsVoid", SqlDbType.Char).Value               = IsVoid;
                command.Parameters.Add("@CreationDateTime", SqlDbType.DateTime).Value = CreationDateTime;
                command.Parameters.Add("@UpdateDateTime", SqlDbType.DateTime).Value   = UpdateDateTime;
                command.Parameters.Add("@UserIdCreatedBy", SqlDbType.VarChar).Value   = UserIdCreatedBy;
                command.Parameters.Add("@UserIdUpdatedBy", SqlDbType.VarChar).Value   = UserIdUpdatedBy;

                command.ExecuteNonQuery();
            }
            return(response);
        }
        /// <summary>
        /// Create new document set. (Sub transaction)
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="sqltransaction"></param>
        /// <param name="headerInfo"></param>
        /// <returns></returns>
        public ResponseStatus AddSubTransaction(
            SqlConnection connection,
            SqlTransaction sqltransaction,
            HeaderInfo headerInfo)
        {
            ResponseStatus response = new ResponseStatus();

            response.Message = "Client Document Set Added Successfully";

            this.UID         = GetLastUID() + 1;
            this.ClientSetID = GetLastUID(this.FKClientUID) + 1;
            this.Description = "Client Set Number " + ClientSetID;
            this.IsVoid      = "N";
            this.Status      = "DRAFT";

            this.FolderOnly =
                "CLIENT" + this.FKClientUID.ToString().Trim() +
                "SET" + this.ClientSetID.ToString().Trim().PadLeft(4, '0');

            this.Folder = FCMConstant.SYSFOLDER.CLIENTFOLDER + @"\" + this.FolderOnly;

            this.CreationDateTime = System.DateTime.Now;
            this.UpdateDateTime   = System.DateTime.Now;
            this.UserIdCreatedBy  = Utils.UserID;
            this.UserIdUpdatedBy  = Utils.UserID;

            // Default values
            DateTime _now = DateTime.Today;

            var commandString =
                (

                    "INSERT INTO [ClientDocumentSet] " +
                    "(" +
                    ClientDocumentSetFieldString() +
                    ")" +
                    " VALUES " +
                    "( @UID     " +
                    ", @FKClientUID    " +
                    ", @ClientSetID    " +
                    ", @Description " +
                    ", @Folder " +
                    ", @FolderOnly " +
                    ", @Status " +
                    ", @StartDate " +
                    ", @EndDate " +
                    ", @SourceFolder " +
                    ", @IsVoid " +
                    ", @CreationDateTime  " +
                    ", @UpdateDateTime " +
                    ", @UserIdCreatedBy " +
                    ", @UserIdUpdatedBy " +
                    ")"
                );

            var command = new SqlCommand(commandString, connection, sqltransaction);

            command.Parameters.Add("@UID", SqlDbType.BigInt).Value                = UID;
            command.Parameters.Add("@FKClientUID", SqlDbType.BigInt).Value        = FKClientUID;
            command.Parameters.Add("@ClientSetID", SqlDbType.BigInt).Value        = ClientSetID;
            command.Parameters.Add("@Description", SqlDbType.VarChar).Value       = Description;
            command.Parameters.Add("@Folder", SqlDbType.VarChar).Value            = Folder;
            command.Parameters.Add("@FolderOnly", SqlDbType.VarChar).Value        = FolderOnly;
            command.Parameters.Add("@Status", SqlDbType.VarChar).Value            = Status;
            command.Parameters.Add("@SourceFolder", SqlDbType.VarChar).Value      = SourceFolder;
            command.Parameters.Add("@StartDate", SqlDbType.DateTime).Value        = _now;
            command.Parameters.Add("@EndDate", SqlDbType.DateTime).Value          = DateTime.MaxValue;
            command.Parameters.Add("@IsVoid", SqlDbType.Char).Value               = IsVoid;
            command.Parameters.Add("@CreationDateTime", SqlDbType.DateTime).Value = CreationDateTime;
            command.Parameters.Add("@UpdateDateTime", SqlDbType.DateTime).Value   = UpdateDateTime;
            command.Parameters.Add("@UserIdCreatedBy", SqlDbType.VarChar).Value   = UserIdCreatedBy;
            command.Parameters.Add("@UserIdUpdatedBy", SqlDbType.VarChar).Value   = UserIdUpdatedBy;

            command.ExecuteNonQuery();
            return(response);
        }
        // ----------------------------------------------------
        //       Copy folder structure including files
        // ----------------------------------------------------
        static public ResponseStatus LoadFolder(string sourceFolder,
                                                IOutputMessage uioutput,
                                                int parentUID, int sequenceNumber, HeaderInfo headerInfo)
        {
            ResponseStatus response = new ResponseStatus();

            response.Message = "Folder loaded successfully.";

            if (!Directory.Exists(sourceFolder))
            {
                response.ReturnCode = -0010;
                response.ReasonCode = -0001;
                response.Message    = "Source folder does not exist.";
                response.UniqueCode = "E00.00.0001";
                response.Icon       = MessageBoxIcon.Error;
                return(response);
            }

            string[] folderNameSplit = sourceFolder.Split('\\');
            string   folderName      = folderNameSplit[folderNameSplit.Length - 1];

            uioutput.Activate();

            string[] files = Directory.GetFiles(sourceFolder);

            // Create folder that contains files and keep the parent
            //
            // ...
            Document.Document folder = new Document.Document();

            if (folderName.Length >= 7)
            {
                folder.CUID = folderName.Substring(0, 7);
            }
            else
            {
                folder.CUID = folderName;
            }

            folder.FileName    = folderName;
            folder.Comments    = "Loaded by batch";
            folder.Name        = folderName;
            folder.DisplayName = folderName;
            folder.FKClientUID = 0;
            folder.IssueNumber = 0;
            string refPath =
                Utils.getReferenceFilePathName(sourceFolder);

            if (string.IsNullOrEmpty(refPath))
            {
                response.ReturnCode = -0010;
                response.ReasonCode = -0002;
                response.Message    = "Folder selected is not under managed template folder.";
                response.UniqueCode = "E00.00.0001";
                return(response);
            }

            folder.Location = refPath;
            // Store the folder being loaded at the root level
            //
            folder.Location       = FCMConstant.SYSFOLDER.TEMPLATEFOLDER;
            folder.ParentUID      = parentUID;
            folder.SequenceNumber = 0;
            folder.SourceCode     = "FCM";
            folder.UID            = 0;
            folder.RecordType     = Utils.RecordType.FOLDER;
            folder.DocumentType   = Utils.DocumentType.FOLDER;
            folder.SimpleFileName = folder.Name;
            folder.FileExtension  = "FOLDER";
            folder.IsProjectPlan  = "N";

            parentUID = folder.Save(headerInfo, Utils.SaveType.NEWONLY);

            // Store each file
            //
            foreach (string file in files)
            {
                #region File Processing
                string name = Path.GetFileName(file);

                string fileName      = Path.GetFileNameWithoutExtension(file);
                string fileExtension = Path.GetExtension(file);

                string validExtensions = ".doc .docx .xls . xlsx .pdf";

                // Not every extension will be loaded
                //
                if (!validExtensions.Contains(fileExtension))
                {
                    continue;
                }


                string fileNameExt = Path.GetFileName(file);

                string simpleFileName = fileNameExt;
                if (fileNameExt.Length > 10)
                {
                    simpleFileName = fileNameExt.Substring(10).Trim();
                }

                Document.Document document = new Document.Document();
                document.CUID     = fileName.Substring(0, 6);
                document.FileName = fileNameExt;

                //string refPath =
                //        Utils.getReferenceFilePathName(sourceFolder);

                document.Location = refPath;
                string issue = "1";
                document.IssueNumber = Convert.ToInt32(issue);

                try
                {
                    issue = fileName.Substring(7, 2);
                    document.IssueNumber = Convert.ToInt32(issue);
                }
                catch (Exception ex)
                {
                }
                document.Name           = fileName;
                document.SimpleFileName = simpleFileName;
                document.DisplayName    = simpleFileName;
                document.SequenceNumber = sequenceNumber;
                document.ParentUID      = parentUID;

                document.Comments      = "Loaded via batch";
                document.SourceCode    = "FCM";
                document.FKClientUID   = 0;
                document.RecordType    = Utils.RecordType.DOCUMENT;
                document.FileExtension = fileExtension;
                document.Status        = Utils.DocumentStatus.ACTIVE;
                document.IsProjectPlan = "N";

                switch (fileExtension)
                {
                case ".doc":
                    document.DocumentType = Utils.DocumentType.WORD;
                    break;

                case ".docx":
                    document.DocumentType = Utils.DocumentType.WORD;
                    break;

                case ".xls":
                    document.DocumentType = Utils.DocumentType.EXCEL;
                    break;

                case ".xlsx":
                    document.DocumentType = Utils.DocumentType.EXCEL;
                    break;

                case ".pdf":
                    document.DocumentType = Utils.DocumentType.PDF;
                    break;

                default:
                    document.DocumentType = Utils.DocumentType.UNDEFINED;
                    break;
                }

                document.Save(headerInfo, Utils.SaveType.NEWONLY);

                uioutput.AddOutputMessage(document.Name);

                sequenceNumber++;
                #endregion File Processing
            }

            // Recursion removed
            //
            string[] folders = Directory.GetDirectories(sourceFolder);
            foreach (string directory in folders)
            {
                string name = Path.GetFileName(directory);
                LoadFolder(directory, uioutput, parentUID, 0, headerInfo);
            }

            return(response);
        }