Forráskód Böngészése

Added Job Document Set Export Button

Frank van den Bos 2 éve
szülő
commit
0809c2b363

+ 2 - 2
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetMileStoneConverter.cs

@@ -14,7 +14,7 @@ namespace PRSDesktop
     public class JobDocumentSetMileStoneConverter : IValueConverter
     {
         
-        private static Dictionary<JobDocumentSetMileStoneStatus, System.Drawing.Color> _statuscolors = new Dictionary<JobDocumentSetMileStoneStatus, Color>()
+        public static Dictionary<JobDocumentSetMileStoneStatus, System.Drawing.Color> StatusColors = new Dictionary<JobDocumentSetMileStoneStatus, Color>()
         {
             { JobDocumentSetMileStoneStatus.Unknown, System.Drawing.Color.Red },
             { JobDocumentSetMileStoneStatus.NotStarted, System.Drawing.Color.LightSalmon },
@@ -47,7 +47,7 @@ namespace PRSDesktop
                 if (String.Equals(parameter, "Status"))
                     return block.Status.ToString().SplitCamelCase();
                 if (String.Equals(parameter, "Color"))
-                    return ImageUtils.ColorToString(_statuscolors[block.Status]);
+                    return ImageUtils.ColorToString(StatusColors[block.Status]);
                 
                 if (String.Equals(parameter, "Date"))
                     return String.Format("{0:dd MMM yy}", block.Date);

+ 22 - 8
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetPanel.xaml

@@ -15,7 +15,7 @@
     </UserControl.Resources>
     <dynamicGrid:DynamicSplitPanel AnchorWidth="250" MasterCaption="Folders" DetailCaption="Documents" View="Combined" OnChanged="DynamicSplitPanel_OnOnChanged" AllowableViews="Combined,Detail">
         <dynamicGrid:DynamicSplitPanel.Header>
-            <Border DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="0.75,0.75,0.75,0" Background="Gainsboro" Height="30">
+            <Border DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="0.75" Background="Gainsboro" Height="30">
                 <Label Content="Search" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="12"/>
             </Border>
         </dynamicGrid:DynamicSplitPanel.Header>
@@ -54,21 +54,35 @@
             <Grid>
                 <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*"/>
-                    <ColumnDefinition Width="260" />
+                    <ColumnDefinition Width="260" x:Name="PreviewColumn" />
                 </Grid.ColumnDefinitions>
                 <Grid.RowDefinitions>
                     <RowDefinition Height="Auto"/>
                     <RowDefinition Height="*"/>
                 </Grid.RowDefinitions>
                 
-                <Border Grid.Row="0" Grid.Column="0" DockPanel.Dock="Top" BorderBrush="Gray" BorderThickness="0.75,0.75,0.75,0" Background="Gainsboro" Height="30">
-                    <Label Content="Documents" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="12"/>
-                </Border> 
+                <DockPanel Grid.Row="0" Grid.Column="0">
+                    <Button x:Name="ShowPreview" DockPanel.Dock="Right" BorderBrush="Gray"
+                            BorderThickness="0.75" Margin="2,0,0,0" Background="WhiteSmoke" MinWidth="25"
+                            Click="ShowPreview_OnClick" Visibility="Collapsed">
+                        <Polygon Points="8,0 0,5, 8,10" Stroke="Gray" Fill="Silver" />
+                    </Button>
+                    <Border DockPanel.Dock="Left" BorderBrush="Gray" BorderThickness="0.75" Background="Gainsboro">
+                        <Label Content="Documents" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="12"/>
+                    </Border> 
+                    </DockPanel>
                 <local:JobDocumentSetTree Grid.Row="1" Grid.Column="0" x:Name="Documents" Margin="0,2,0,0" MileStoneSelected="Documents_OnMileStoneSelected" />
                 
-                <Border Grid.Row="0" Grid.Column="1" BorderBrush="Gray" BorderThickness="0.75,0.75,0.75,0" Background="Gainsboro" Height="30" Margin="4,0,0,0">
-                    <Label Content="Preview" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="12"/>
-                </Border>                
+                <DockPanel Grid.Row="0" Grid.Column="1" Margin="4,0,0,0">
+                    <Button x:Name="HidePreview" DockPanel.Dock="Left" BorderBrush="Gray"
+                            BorderThickness="0.75" Margin="0,0,2,0" Background="WhiteSmoke" MinHeight="25" MinWidth="25" 
+                            Click="HidePreview_OnClick">
+                        <Polygon Points="0,0 8,5, 0,10" Stroke="Gray" Fill="Silver" />
+                    </Button>
+                    <Border  DockPanel.Dock="Right" BorderBrush="Gray" BorderThickness="0.75" Background="Gainsboro" Height="30" >
+                        <Label Content="Preview" HorizontalContentAlignment="Center" FontWeight="Bold" FontSize="12"/>
+                    </Border>       
+                </DockPanel>
                 <ListView x:Name="preview" Grid.Row="1" Grid.Column="1" Background="DimGray" Margin="4,2,0,0" SizeChanged="Preview_OnSizeChanged"
                           ScrollViewer.HorizontalScrollBarVisibility="Disabled"  ItemContainerStyle="{StaticResource itemstyle}">
                     <ListView.ItemTemplate>

+ 12 - 0
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetPanel.xaml.cs

@@ -272,5 +272,17 @@ namespace PRSDesktop
         {
             EditDocumentTags(JobDocumentSetTagType.Category);
         }
+
+        private void ShowPreview_OnClick(object sender, RoutedEventArgs e)
+        {
+            PreviewColumn.Width = new GridLength(260, GridUnitType.Pixel);
+            ShowPreview.Visibility = Visibility.Collapsed;
+        }
+
+        private void HidePreview_OnClick(object sender, RoutedEventArgs e)
+        {
+            PreviewColumn.Width = new GridLength(0, GridUnitType.Pixel);
+            ShowPreview.Visibility = Visibility.Visible;
+        }
     }
 }

+ 4 - 0
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml

@@ -211,6 +211,10 @@
                     Click="IncludeRetired_OnClick" BorderBrush="Gray" BorderThickness="0.75">
                 <Label x:Name="IncludeRetiredLabel" Content="Include Retired" />
             </Button>
+            <Button x:Name="Export" DockPanel.Dock="Left" Margin="0,2,2,0"
+                    Click="Export_OnClick" BorderBrush="Gray" BorderThickness="0.75">
+                <Label x:Name="ExportLabel" Content="Export" />
+            </Button>
             <Button x:Name="Delete" DockPanel.Dock="Right" Margin="2,2,0,0" Width="30" Height="30"
                     Padding="2" Click="Delete_OnClick" BorderBrush="Gray" BorderThickness="0.75">
                 <Image x:Name="DeleteImage"  Source="../../Resources/delete.png" />

+ 126 - 0
prs.desktop/Panels/Jobs/DocumentSets/JobDocumentSetTree.xaml.cs

@@ -19,11 +19,17 @@ using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
 using net.sf.mpxj.phoenix.schema.phoenix5;
+using org.omg.CORBA;
 using Syncfusion.Compression.Zip;
 using Syncfusion.Data.Extensions;
 using Syncfusion.UI.Xaml.Grid;
 using Syncfusion.UI.Xaml.TreeGrid;
 using Syncfusion.UI.Xaml.TreeGrid.Helpers;
+using Syncfusion.Windows.Controls.Grid;
+using Syncfusion.XlsIO;
+using Color = System.Drawing.Color;
+using Environment = System.Environment;
+using GridSelectionChangedEventArgs = Syncfusion.UI.Xaml.Grid.GridSelectionChangedEventArgs;
 using JobDocumentSetFolder = Comal.Classes.JobDocumentSetFolder;
 using MessageBox = System.Windows.MessageBox;
 using UserControl = System.Windows.Controls.UserControl;
@@ -1665,5 +1671,125 @@ namespace PRSDesktop
             if (set != null)
                 EditDocumentSets(new Guid[] { set.ID });
         }
+
+        private void Export_OnClick(object sender, RoutedEventArgs e)
+        {
+            var engine = new ExcelEngine();
+            var application = engine.Excel;
+            var workbook = application.Workbooks.Create(1);
+            workbook.Version = ExcelVersion.Excel2007;
+            
+            var sheet = workbook.Worksheets[0];
+            sheet.Name = "Document Register";
+            
+            int iRow = 1;
+            int iCol = 1;
+            
+            SetHeader(sheet, iRow, iCol++, "Document Number", 40, false, false);
+            SetHeader(sheet, iRow, iCol++, "Description", 80, false, false);
+
+            SetHeader(sheet, iRow, iCol++, "Discipline", 15, true, false);
+            SetHeader(sheet, iRow, iCol++, "Type", 15, true, false);
+            SetHeader(sheet, iRow, iCol++, "Category", 15, true, false);
+            SetHeader(sheet, iRow, iCol++, "ITP Area", 15, true, false);
+            
+            Dictionary<String, int> blkmap = new Dictionary<string, int>();
+
+            foreach (var key in _types.Keys)
+            {
+                var _type = _types[key];
+                SetHeader(sheet, iRow, iCol, _type.Code, 5, true, true);
+                sheet.Range[iRow, iCol].Text = _type.Code;
+                int iCount = _types[key].Columns.Count;
+                if (iCount > 1)
+                    sheet.Range[iRow, iCol, iRow, iCol + iCount - 1].Merge();
+                foreach (var col in _type.Columns)
+                {
+                    sheet.SetColumnWidth(iCol,5);
+                    blkmap[col] = iCol++;
+                }
+            }
+
+            iRow++;
+            foreach (var node in _documentsets.Nodes)
+            {
+                var desc = Serialization.Deserialize<JobDocumentSetDescriptionBlock>(node.Description);
+                CoreRow row = Data.Rows.FirstOrDefault(r => r.Get<JobDocumentSet, Guid>(c => c.ID) == desc.ID);
+                if (row != null)
+                {
+                    iCol = 1;
+                    SetContent(sheet, iRow, iCol++, desc.Code, false, false, System.Drawing.Color.Transparent);
+                    SetContent(sheet, iRow, iCol++, desc.Description, false, true, System.Drawing.Color.Transparent);
+
+                    SetContent(sheet, iRow, iCol++, row.Get<JobDocumentSet, String>(c => c.Discipline.Description), true, false, System.Drawing.Color.Transparent);
+                    SetContent(sheet, iRow, iCol++, row.Get<JobDocumentSet, String>(c => c.Type.Description), true, false, System.Drawing.Color.Transparent);
+                    SetContent(sheet, iRow, iCol++, row.Get<JobDocumentSet, String>(c => c.Category.Description), true, false, System.Drawing.Color.Transparent);
+                    SetContent(sheet, iRow, iCol++, row.Get<JobDocumentSet, String>(c => c.Area.Description), true, false, System.Drawing.Color.Transparent);
+                    
+                    foreach (var key in node.Blocks.Keys)
+                    {
+                        if (!String.IsNullOrWhiteSpace(node.Blocks[key]))
+                        {
+                            var block = Serialization.Deserialize<JobDocumentSetMileStoneBlock>(node.Blocks[key]);
+                            iCol = blkmap[$"Blocks[{key}]"];
+                            var color = JobDocumentSetMileStoneConverter.StatusColors[block.Status];
+                            var status = String.IsNullOrWhiteSpace(block.Revision) ? "--" : block.Revision;
+                            SetContent(sheet, iRow, iCol, status, true, false, color);
+                        }
+                    }
+                }
+                iRow++;
+            }
+
+            sheet.UsedRange.BorderAround();
+            sheet.UsedRange.BorderInside();
+            sheet.UsedRange.AutofitRows();
+            foreach (var row in sheet.UsedRange.Rows)
+            {
+                row.RowHeight += 5;
+                row.VerticalAlignment = ExcelVAlign.VAlignCenter;
+            }
+            
+            var dlg = new SaveFileDialog();
+            dlg.Filter = "Excel Files (*.xlsx)|*.xlsx";
+            dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            dlg.FileName = string.Format("Document Register {0:yyyy-MM-dd hh-mm-ss}.xlsx", DateTime.Now);
+            if (dlg.ShowDialog() == DialogResult.OK)
+            {
+                try
+                {
+                    workbook.SaveAs(dlg.FileName, ExcelSaveType.SaveAsXLS);
+                    Process.Start(new ProcessStartInfo(dlg.FileName) { UseShellExecute = true });
+                }
+                catch (Exception e2)
+                {
+                    MessageBox.Show("Error saving spreadsheet!\n\n" + e2.Message);
+                }
+            }
+            
+        }
+
+        private void SetContent(IWorksheet sheet, int row, int col, string text, bool center, bool wrap, Color? color)
+        {
+            var range = sheet.Range[row, col];
+            range.Text = text;
+            range.WrapText = wrap;
+            if (center)
+                range.CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
+            if (color != null)
+                range.CellStyle.Color = color.Value;
+        }
+
+        private void SetHeader(IWorksheet sheet, int row, int col, string text, double width, bool center, bool rotate)
+        {
+            var range = sheet.Range[row, col];
+            range.Text = text;
+            range.CellStyle.Color = System.Drawing.Color.Silver;
+            sheet.SetColumnWidth(col,width);
+            if (center)
+                range.CellStyle.HorizontalAlignment = ExcelHAlign.HAlignCenter;
+            if (rotate)
+                range.CellStyle.Rotation = 90;
+        }
     }
 }