فهرست منبع

WPF - control for document approval process

Nick-PRSDigital@bitbucket.org 1 سال پیش
والد
کامیت
8295db96e5

+ 1 - 0
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -2050,6 +2050,7 @@ namespace InABox.DynamicGrid
                 cursor.Dispose();
                 cursor = null;
             }
+            bRefreshing = false;
         }
 
         protected override bool OnBeforeRefresh()

+ 26 - 0
inabox.wpf/DynamicGrid/PDF/DocumentApprovalControl.xaml

@@ -0,0 +1,26 @@
+<UserControl x:Class="InABox.Wpf.DocumentApprovalControl"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:InABox.DynamicGrid"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="auto"/>
+        </Grid.RowDefinitions>
+        <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="0">
+            <StackPanel x:Name="viewer" Orientation="Vertical" Margin="10"/>
+        </ScrollViewer>
+
+        <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0.5">
+            <StackPanel Orientation="Horizontal"  HorizontalAlignment="Right">
+                <Button Grid.Column="0" Content="Mark Up" HorizontalAlignment="Right" Height="35" Padding="20, 5, 20, 5" Margin="5" x:Name="markUpButton" Click="MarkUpButton_Click"/>
+                <Button Grid.Column="1" Content="Approve" HorizontalAlignment="Right" Height="35" Padding="20, 5, 20, 5" Margin="5" x:Name="approveButton" Click="ApproveButton_Click"/>
+                <Button Grid.Column="2" Content="Reject" HorizontalAlignment="Right" Height="35" Padding="20, 5, 20, 5" Margin="5, 5, 15, 5" x:Name="rejectButton" Click="RejectButton_Click"/>
+            </StackPanel>
+        </Border>
+    </Grid>
+</UserControl>

+ 131 - 0
inabox.wpf/DynamicGrid/PDF/DocumentApprovalControl.xaml.cs

@@ -0,0 +1,131 @@
+using InABox.Clients;
+using InABox.Core;
+using InABox.DynamicGrid;
+using InABox.WPF;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace InABox.Wpf
+{
+    /// <summary>
+    /// Interaction logic for DocumentApprovalControl.xaml
+    /// </summary>
+    public partial class DocumentApprovalControl : UserControl, IDocumentEditor
+    {
+        public delegate void MarkupComplete(IEntityDocument document);
+        public event MarkupComplete OnMarkupComplete;
+
+        public delegate void Approved(IEntityDocument document);
+        public event Approved OnApproved;
+
+        public delegate void Rejected(IEntityDocument document);
+        public event Rejected OnRejected;
+        public enum ControlMode
+        {
+            Markup,
+            Complete
+        }
+
+        ControlMode _mode;
+
+        public ControlMode Mode
+        {
+            get => _mode;
+            set
+            {
+                _mode = value;
+                if (_mode == ControlMode.Markup)
+                {
+                    markUpButton.Content = "Mark Up";
+                    approveButton.IsEnabled = true;
+                    rejectButton.IsEnabled = true;
+                }
+                else if (_mode == ControlMode.Complete)
+                {
+                    markUpButton.Content = "Complete";
+                    approveButton.IsEnabled = false;
+                    rejectButton.IsEnabled = false;
+                }
+            }
+        }
+
+        public void SetupButtons(bool markeupVisible = true, bool approveVisible = true, bool rejectVisible = true)
+        { 
+            markUpButton.Visibility = markeupVisible? Visibility.Visible : Visibility.Collapsed;
+            approveButton.Visibility = approveVisible? Visibility.Visible : Visibility.Collapsed;
+            rejectButton.Visibility = rejectVisible? Visibility.Visible : Visibility.Collapsed;
+        }
+
+        private IEntityDocument _document;
+        public IEntityDocument Document
+        {
+            get => _document;
+            set
+            {
+                _document = value;
+                Mode = ControlMode.Markup;
+                Render();
+            }
+        }
+        public DocumentApprovalControl()
+        {
+            InitializeComponent();
+            Mode = ControlMode.Markup;
+        }
+
+        private void Render()
+        {
+            viewer.Children.Clear();
+            var table = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(_document.DocumentLink.ID));
+            if (!table.Rows.Any())
+                return;
+            var data = table.Rows.FirstOrDefault().Get<Document, byte[]>(x => x.Data);
+            var images = ImageUtils.RenderPDFToImages(data);
+            foreach (var image in images)
+            {
+                viewer.Children.Add(new Image
+                {
+                    Source = ImageUtils.LoadImage(image),
+                    Margin = new Thickness(0, 0, 0, 20)
+                });
+            }
+        }
+
+        private void MarkUpButton_Click(object sender, RoutedEventArgs e)
+        {
+            if (Mode == ControlMode.Markup)
+            {
+                Mode = ControlMode.Complete;
+                MessageBox.Show("This will now launch the configured mark up program - please save and overwrite the original file when done, and press complete to refresh");
+                //launch shell command
+            }
+            else
+            {
+                OnMarkupComplete?.Invoke(_document);
+                Mode = ControlMode.Markup;
+            }
+        }
+
+        private void ApproveButton_Click(object sender, RoutedEventArgs e)
+        {
+            OnApproved?.Invoke(_document);
+        }
+
+        private void RejectButton_Click(object sender, RoutedEventArgs e)
+        {
+            OnRejected?.Invoke(_document);
+        }
+    }
+}