/// <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); }
// ----------------------------------------------------- // 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> /// Add New Process Request /// </summary> public ResponseStatus Add() { ResponseStatus response = new ResponseStatus(); int _uid = 0; _uid = GetLastUID() + 1; this.UID = _uid; DateTime _now = DateTime.Today; if (UID == null) { ResponseStatus responseError = new ResponseStatus(messageType: MessageType.Error); responseError.Message = "UID Not Supplied"; return(responseError); } if (Description == null) { ResponseStatus responseError = new ResponseStatus(messageType: MessageType.Error); responseError.Message = "Description Not Supplied"; return(responseError); } using (var connection = new SqlConnection(ConnString.ConnectionString)) { var commandString = ( "INSERT INTO [ProcessRequest] " + "( " + FieldString() + ")" + " VALUES " + "( " + " @" + FieldName.UID + ", @" + FieldName.Description + ", @" + FieldName.FKClientUID + ", @" + FieldName.Type + ", @" + FieldName.Status + ", @" + FieldName.WhenToProcess + ", @" + FieldName.RequestedByUser + ", @" + FieldName.CreationDateTime + ", @" + FieldName.PlannedDateTime + ", @" + FieldName.StatusDateTime + " )" ); using (var command = new SqlCommand( commandString, connection)) { command.Parameters.Add("@UID", SqlDbType.BigInt).Value = UID; command.Parameters.Add("@Description", SqlDbType.VarChar).Value = Description; command.Parameters.Add("@FKClientUID", SqlDbType.BigInt).Value = FKClientUID; command.Parameters.Add("@Type", SqlDbType.VarChar).Value = Type; command.Parameters.Add("@Status", SqlDbType.VarChar).Value = Status; command.Parameters.Add("@WhenToProcess", SqlDbType.VarChar).Value = WhenToProcess; command.Parameters.Add("@RequestedByUser", SqlDbType.VarChar).Value = RequestedByUser; command.Parameters.Add("@CreationDateTime", SqlDbType.DateTime).Value = CreationDateTime; command.Parameters.Add("@PlannedDateTime", SqlDbType.DateTime).Value = PlannedDateTime; command.Parameters.Add("@StatusDateTime", SqlDbType.DateTime).Value = StatusDateTime; connection.Open(); 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); }
// --------------------------------------------- // // --------------------------------------------- /// <summary> /// Create client document and replace document tags /// </summary> /// <param name="fromFileName"></param> /// <param name="destinationFileName"></param> /// <param name="tag"></param> /// <param name="vkWordApp"></param> /// <returns></returns> public static ResponseStatus CopyDocument( object fromFileName, object destinationFileName, List <WordDocumentTasks.TagStructure> tag, Word.Application vkWordApp, IOutputMessage uioutput ) { ResponseStatus ret = new ResponseStatus(); object saveFile = destinationFileName; object vkReadOnly = false; object vkVisible = true; object vkFalse = false; object vkTrue = true; object vkDynamic = 2; object vkMissing = System.Reflection.Missing.Value; // Let's make the word application not visible // vkWordApp.Visible = false; // vkWordApp.Activate(); // Let's copy the document File.Copy(fromFileName.ToString(), destinationFileName.ToString(), true); // Let's open the DESTINATION document Word.Document vkMyDoc; try { vkMyDoc = vkWordApp.Documents.Open( ref destinationFileName, ref vkMissing, ref vkReadOnly, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkMissing, ref vkVisible); } catch (Exception ex) { ret.ReturnCode = -1; ret.ReasonCode = 1000; ret.Message = "Error copying file."; ret.Contents = ex; return(ret); } foreach (var t in tag) { if (t.TagType == Utils.InformationType.FIELD || t.TagType == Utils.InformationType.VARIABLE) { FindAndReplace(t.Tag, t.TagValue, 1, vkWordApp, vkMyDoc); } else { insertPicture(vkMyDoc, t.TagValue, t.Tag); } } // 24/10/2010 - Modificado quando troquei a referencia do Word // //vkMyDoc.Sections.Item( 1 ).Headers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update(); //vkMyDoc.Sections.Item( 1 ).Footers.Item( Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ).Range.Fields.Update(); try { vkMyDoc.Save(); } catch (Exception ex) { uioutput.AddOutputMessage("(Word) ERROR in file: " + fromFileName + " --- Message: " + ex.ToString()); } // close the new document vkMyDoc.Close(); // Trying to release COM object System.Runtime.InteropServices.Marshal.ReleaseComObject(vkMyDoc); return(ret); }
public ResponseStatus AddUser() { ResponseStatus response = new ResponseStatus(); response.Message = "User Added Successfully."; response.UniqueCode = ResponseStatus.MessageCode.Informational.FCMINF00000004; int _uid = 0; DateTime _now = DateTime.Today; if (_UserID == null) { response.ReturnCode = -0010; response.ReasonCode = 0001; response.Message = "User ID is mandatory."; response.UniqueCode = ResponseStatus.MessageCode.Error.FCMERR00000003; response.Contents = 0; return(response); } if (_Salt == null) { response.ReturnCode = -0010; response.ReasonCode = 0003; response.Message = "Salt is mandatory."; response.UniqueCode = ResponseStatus.MessageCode.Error.FCMERR00000005; response.Contents = 0; return(response); } using (var connection = new SqlConnection(ConnString.ConnectionString)) { var commandString = ( "INSERT INTO [FCMUser] " + "([UserID], [UserName], [LogonAttempts],[Password],[Salt]" + ")" + " VALUES " + "( " + " @UserID " + ", @UserName " + ", @LogonAttempts " + ", @Password " + ", @Salt " + " )" ); using (var command = new SqlCommand( commandString, connection)) { command.Parameters.Add("@UserID", SqlDbType.VarChar).Value = _UserID; command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = _UserName; command.Parameters.Add("@LogonAttempts", SqlDbType.Int).Value = 0; command.Parameters.Add("@Password", SqlDbType.VarChar).Value = "0"; command.Parameters.Add("@Salt", SqlDbType.Int).Value = 0; connection.Open(); command.ExecuteNonQuery(); } } return(response); }