Example #1
0
        /// <summary>
        /// Sets the state to complete
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static GridInvokeMethodResult Release(GridFunctionParameter parameter)
        {
            Checkout(parameter);

            foreach (var row in parameter.GetSelectedRowsAsDataRow())
            {
                var documentId     = (Guid)row["Guid"];
                var documentPathId = (Guid)row["DocumentPathId"];
                var workflowId     = (Guid)row["WorkflowId"];

                var workflowOperation = new WorkflowOperation
                {
                    DocumentId     = documentId,
                    DocumentPath   = documentPathId,
                    UserId         = sessionService.CurrentSession.UserId,
                    CreateDateTime = DateTime.Now,
                    UpdateDateTime = DateTime.Now,
                    WorkflowId     = workflowId,
                    ActionName     = "released",
                    Guid           = Guid.NewGuid()
                };

                workflowOperationService.Release(workflowOperation);
            }

            return(new GridInvokeMethodResult {
                RefreshGrid = true
            });
        }
Example #2
0
        /// <summary>
        /// Tries to checkout a document if required
        /// </summary>
        /// <param name="parameter">Grid parameter</param>
        private static void Checkout(GridFunctionParameter parameter)
        {
            foreach (var row in parameter.GetSelectedRowsAsDataRow())
            {
                if (Guid.TryParse(row["OrganizationId"]?.ToString(), out Guid organizationUnitId))
                {
                    var documentId = (Guid)row["Guid"];

                    // The grid needs a the column workflow id
                    var workflowId  = (Guid)row["WorkflowId"];
                    var directoryId = (Guid)row["DirectoryId"];

                    var workflowOperation = new WorkflowOperation
                    {
                        DocumentId             = documentId,
                        UserId                 = sessionService.CurrentSession.UserId,
                        TargetUserId           = sessionService.CurrentSession.UserId,
                        CreateDateTime         = DateTime.Now,
                        UpdateDateTime         = DateTime.Now,
                        ActionName             = "forward",
                        WorkflowId             = workflowId,
                        WorkflowOrganizationId = organizationUnitId,
                        DirectoryId            = directoryId,
                        Guid = Guid.NewGuid()
                    };

                    var documentPath = workflowOperationService.DocumentCheckout(workflowOperation);
                    row["DocumentPathId"] = documentPath;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Edit file structure
        /// </summary>
        /// <param name="parameter">Grid parameter</param>
        /// <returns>Grid invoke result, to control grid refresh</returns>
        public static GridInvokeMethodResult EditFileStructure(GridFunctionParameter parameter)
        {
            foreach (var id in parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["Id"]))
            {
                var fileStructureWindow = new FileStructureWindow();

                // Get and copy
                var fileStructure = fileStructureService.Get(id);

                fileStructureWindow.Initialize(fileStructure);
                fileStructureWindow.WindowMode = Framework.UI.WindowMode.Edit;
                fileStructureWindow.Show();

                // Refresh grid after closed
                fileStructureWindow.Closed += (s, e) =>
                {
                    parameter.GridView.RefreshData();
                };

                return(new GridInvokeMethodResult
                {
                    RefreshGrid = false,
                    Window = fileStructureWindow
                });
            }

            // Do not refresh grid if no data is passed
            return(new GridInvokeMethodResult {
                RefreshGrid = false
            });
        }
Example #4
0
        /// <summary>
        /// Shows  the tracking for the parameter which is a document
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static GridInvokeMethodResult ShowTracking(GridFunctionParameter parameter)
        {
            foreach (var row in parameter.GetSelectedRowsAsDataRow())
            {
                var documentId = (Guid)row["Guid"];
                var ib         = (AsyncGridItemBox)ItemBoxManager.GetItemBoxFromDB($"IB_Document_Workflow_Tracking");
                ib.SetPlaceholder("DocumentId", documentId.ToString());
                ib.ShowDialog();
            }

            return(new GridInvokeMethodResult {
                RefreshGrid = true
            });
        }
Example #5
0
        /// <summary>
        /// Forwards the document into the substitute folder
        /// </summary>
        /// <param name="gridFunctionParameter"></param>
        /// <returns></returns>
        public static GridInvokeMethodResult ForwardToSubstitute(GridFunctionParameter gridFunctionParameter)
        {
            var documentId  = Guid.Empty;
            var pathService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IFileStructureDocumentPathService>();

            foreach (var documentRow in gridFunctionParameter.GetSelectedRowsAsDataRow())
            {
                documentId = (Guid)documentRow["Guid"];

                if (documentId.Equals(Guid.Empty))
                {
                    continue;
                }

                var workflowId     = (Guid)documentRow["WorkflowId"];
                var targetUserId   = (int)documentRow["UserId"];
                var sessionService = CommonServiceLocator.ServiceLocator.Current.GetInstance <ISessionService>();
                var currentUserId  = sessionService.CurrentSession.UserId;
                var paths          = pathService.GetByDocumentId(documentId);
                var pathId         = paths.FirstOrDefault(x => x.WorkflowState != DocumentWorkflowStateType.Completed).Id;
                if (pathId == null)
                {
                    continue;
                }

                //The User is authorized to take the document
                var workflowOperationService = CommonServiceLocator.ServiceLocator.Current.GetInstance <IWorkflowOperationService>();

                workflowOperationService.ForwardTo(new WorkflowOperation
                {
                    DocumentId    = documentId,
                    UserId        = currentUserId,
                    TargetUserId  = currentUserId,
                    ActionName    = "Forward",
                    WorkflowId    = workflowId,
                    DocumentPath  = pathId,
                    OperationType = WorkflowOperationType.User,
                });
            }

            return(new GridInvokeMethodResult()
            {
                RefreshGrid = true,
            });
        }
Example #6
0
        private static IList <WorkflowOperation> WorkflowOperationsItemBoxGet(GridFunctionParameter parameter)
        {
            IList <WorkflowOperation> workflowOperations = new List <WorkflowOperation>();

            Checkout(parameter);

            Guid?workflowOrganizationId = null;
            int  targetUserId           = 0;

            if (parameter.SelectedRows.Count == 0)
            {
                return(null);
            }

            var itemBox = (AsyncGridItemBox)ItemBoxManager.GetItemBoxFromDB("IB_Document_Workflow_User");

            itemBox.SetPlaceholder("WorkflowId", parameter.GetSelectedRowsAsDataRow().FirstOrDefault()["WorkflowId"].ToString());
            itemBox.ShowDialog();

            if (itemBox.SelectedItem == null)
            {
                return(null);
            }

            var comment = new Framework.Extension.InstanceDataCommentModel
            {
                UserGroupVisibility = Visibility.Hidden,
                UserId           = sessionService.CurrentSession.UserId,
                InstanceDataGuid = Guid.NewGuid(),
                StackGuid        = (Guid)parameter.GridView.Configuration.SelectedStackId
            };

            var commentWindow = new Framework.Extension.NewCommentWindow(comment);

            commentWindow.ShowDialog();

            if (itemBox.GetSelectedItemCell("InternalType").ToString() == "User")
            {
                targetUserId = (int)itemBox.GetSelectedItemCell("Ident");
            }
            else
            {
                workflowOrganizationId = (Guid)itemBox.GetSelectedItemCell("Guid");
            }

            foreach (var row in parameter.GetSelectedRowsAsDataRow())
            {
                var documentId     = (Guid)row["Guid"];
                var documentPathId = (Guid)row["DocumentPathId"];
                var workflowId     = (Guid)row["WorkflowId"];

                var workflowOperation = new WorkflowOperation
                {
                    DocumentId     = documentId,
                    DocumentPath   = documentPathId,
                    UserId         = sessionService.CurrentSession.UserId,
                    TargetUserId   = targetUserId,
                    CreateDateTime = DateTime.Now,
                    UpdateDateTime = DateTime.Now,
                    ActionName     = "forward",
                    WorkflowId     = workflowId,
                    Guid           = Guid.NewGuid()
                };
                if (itemBox.GetSelectedItemCell("InternalType").ToString() == "Group")
                {
                    workflowOperation.OperationType          = WorkflowOperationType.WorkflowOrganizationUnit;
                    workflowOperation.WorkflowOrganizationId = workflowOrganizationId;
                }
                workflowOperations.Add(workflowOperation);

                if (!string.IsNullOrWhiteSpace(comment.Comment))
                {
                    comment.InstanceDataGuid = documentId;
                    comment.CommentId        = Guid.NewGuid();

                    Framework.Extension.InstanceDataComment.Singleton.Create(comment);
                }
            }
            return(workflowOperations);
        }
Example #7
0
        private static IList <WorkflowOperation> WorkflowOperationsGet(GridFunctionParameter parameter)
        {
            IList <WorkflowOperation> workflowOperations = new List <WorkflowOperation>();

            Checkout(parameter);

            if (parameter.SelectedRows.Count == 0)
            {
                return(null);
            }

            Dictionary <string, string> dictParams = new Dictionary <string, string>();

            dictParams.Add("[WorkflowId]", parameter.GetSelectedRowsAsDataRow().FirstOrDefault()["WorkflowId"].ToString());

            var win = new ForwardWindow(dictParams);

            win.ShowDialog();

            var windowDataContext = win.DataContext;
            ObservableCollection <IMultiSelectionComboBoxItem> itemList = null;
            var commentText = "";

            if (windowDataContext is ForwardViewModel forwardViewModel)
            {
                itemList    = forwardViewModel.MultiItemboxItems;
                commentText = forwardViewModel.CommentText;
            }

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

            foreach (var item in itemList)
            {
                var user = userService.GetByGuid((Guid)item.Id);

                int  targetUserId            = 0;
                Guid?workflowOrganzisationId = null;

                if (user != null)
                {
                    targetUserId = user.Ident;
                }

                else
                {
                    workflowOrganzisationId = (Guid?)item.Id;
                }

                var comment = new Framework.Extension.InstanceDataCommentModel
                {
                    Comment             = commentText,
                    UserGroupVisibility = Visibility.Hidden,
                    UserId           = sessionService.CurrentSession.UserId,
                    InstanceDataGuid = Guid.NewGuid(),
                    StackGuid        = (Guid)parameter.GridView.Configuration.SelectedStackId
                };

                foreach (var row in parameter.GetSelectedRowsAsDataRow())
                {
                    var documentId     = (Guid)row["Guid"];
                    var documentPathId = (Guid)row["DocumentPathId"];
                    // The grid needs a the column workflow id
                    var workflowId = (Guid)fileStructureDocumentPathService.Get(documentPathId).WorkflowId;

                    if (workflowId == null)
                    {
                        continue;
                    }

                    var workflowOperation = new WorkflowOperation
                    {
                        DocumentId     = documentId,
                        DocumentPath   = documentPathId,
                        UserId         = sessionService.CurrentSession.UserId,
                        TargetUserId   = targetUserId,
                        CreateDateTime = DateTime.Now,
                        UpdateDateTime = DateTime.Now,
                        ActionName     = "forward",
                        WorkflowId     = workflowId,
                        Guid           = Guid.NewGuid(),
                    };

                    if (user == null)
                    {
                        workflowOperation.OperationType          = WorkflowOperationType.WorkflowOrganizationUnit;
                        workflowOperation.WorkflowOrganizationId = workflowOrganzisationId;
                    }

                    workflowOperations.Add(workflowOperation);

                    if (!string.IsNullOrWhiteSpace(comment.Comment))
                    {
                        comment.InstanceDataGuid = documentId;
                        comment.CommentId        = Guid.NewGuid();

                        Framework.Extension.InstanceDataComment.Singleton.Create(comment);
                    }
                }
            }
            return(workflowOperations);
        }
Example #8
0
        /// <summary>
        /// Open file structure editor for instance data
        /// </summary>
        /// <param name="parameter">Grid parameter</param>
        /// <returns>Grid invoke result, to control grid refresh</returns>
        public static GridInvokeMethodResult OpenFileStructureEditor(GridFunctionParameter parameter)
        {
            var fileStructureWindow = new FileStructureWindow();

            // TODO: Maybe change to foreach....
            var instanceDataGuid = parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["Guid"]).FirstOrDefault();
            var stackGuid        = parameter.GetSelectedRowsAsDataRow().Select(x => (Guid)x["StackGuid"]).FirstOrDefault();

            var fileStructure = fileStructureService.GetByInstanceDataGuid(instanceDataGuid);

            if (fileStructure == null)
            {
                var selectFromTemplateResult = MessageBox.Show(localizationService.Translate("filestructure_select_template_msg"), localizationService.Translate("filestructure_select_template_title"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);

                if (selectFromTemplateResult == MessageBoxResult.Cancel)
                {
                    return new GridInvokeMethodResult {
                               RefreshGrid = false
                    }
                }
                ;

                if (selectFromTemplateResult == MessageBoxResult.No)
                {
                    // Create new, maybe from template?
                    fileStructure = new FileStructure
                    {
                        InstanceDataGuid = instanceDataGuid,
                        StackGuid        = stackGuid,
                        IsTemplate       = false
                    };
                }
                else
                {
                    var templateItemBox = ItemBoxManager.GetItemBoxFromDB("IB_FileStructureTemplate");
                    templateItemBox.ShowDialog();

                    if (templateItemBox.SelectedItem != null)
                    {
                        var templateId = (Guid)templateItemBox.GetSelectedItemCell("Id");
                        var template   = fileStructureService.Get(templateId);

                        // Copy template and connect with instance data entry
                        fileStructure                  = template.Copy();
                        fileStructure.IsTemplate       = false;
                        fileStructure.InstanceDataGuid = instanceDataGuid;
                        fileStructure.StackGuid        = stackGuid;
                    }
                }

                // Exit if no file structure is created
                if (fileStructure == null)
                {
                    return new GridInvokeMethodResult {
                               RefreshGrid = false
                    }
                }
                ;
            }

            // Initialize window
            fileStructureWindow.Initialize(fileStructure);

            fileStructureWindow.Show();

            // Refresh grid after closed
            fileStructureWindow.Closed += (s, e) =>
            {
                parameter.GridView.RefreshData();
            };

            return(new GridInvokeMethodResult
            {
                RefreshGrid = false,
                Window = fileStructureWindow
            });
        }

        #endregion
    }
}