Squashed 'FSI.Lib/' content from commit 6aa4846
git-subtree-dir: FSI.Lib git-subtree-split: 6aa48465a834a7bfdd9cbeae8d2e4f769d0c0ff8
This commit is contained in:
185
FSI.Lib/Guis/Prj.Mgt/FrmMain.xaml
Normal file
185
FSI.Lib/Guis/Prj.Mgt/FrmMain.xaml
Normal file
@@ -0,0 +1,185 @@
|
||||
<Window x:Class="FSI.Lib.Guis.Prj.Mgt.FrmMain"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase"
|
||||
xmlns:local="clr-namespace:FSI.Lib.Guis.Prj.Mgt"
|
||||
xmlns:control="clr-namespace:FSI.Lib.Wpf.Ctrls.FilterDataGrid"
|
||||
xmlns:viewmodel="clr-namespace:FSI.Lib.Guis.Prj.Mgt.ViewModel"
|
||||
d:DataContext="{d:DesignInstance Type=viewmodel:ViewModelPrj}"
|
||||
mc:Ignorable="d"
|
||||
SizeToContent="Width"
|
||||
Height="800"
|
||||
Width="Auto"
|
||||
Icon="../../Icons/FondiumU.ico">
|
||||
|
||||
<Window.Resources>
|
||||
<ObjectDataProvider x:Key="PrjsFiltered"></ObjectDataProvider>
|
||||
</Window.Resources>
|
||||
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Command="{Binding CmdOpen}"
|
||||
Gesture="CTRL+o" />
|
||||
</Window.InputBindings>
|
||||
|
||||
<Grid FocusManager.FocusedElement="{Binding ElementName=tbSearch}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Grid Grid.Row="0"
|
||||
Margin="0,10"
|
||||
HorizontalAlignment="Stretch">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="2*" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<StackPanel Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
Orientation="Horizontal">
|
||||
<Label Margin="0,0,20,0"
|
||||
VerticalAlignment="Bottom"
|
||||
Content="Suche:"
|
||||
FontWeight="Bold" />
|
||||
<TextBox Name="tbSearch"
|
||||
Height="26"
|
||||
MinWidth="200"
|
||||
VerticalAlignment="Center"
|
||||
VerticalContentAlignment="Center"
|
||||
Text="{Binding Search, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
|
||||
TextChanged="tbSearch_TextChanged" />
|
||||
<Button Width="Auto"
|
||||
Margin="5,0,0,0"
|
||||
Padding="4"
|
||||
Command="{Binding RefreshCommand}"
|
||||
ToolTip="Filter löschen"
|
||||
Cursor="Hand">
|
||||
<Image Source="../../Icons/Cross.png"
|
||||
Height="14" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
<StackPanel Grid.Column="2"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button Width="Auto"
|
||||
Margin="0 0 20 0"
|
||||
Padding="4"
|
||||
ToolTip="öffen"
|
||||
Command="{Binding CmdOpen}"
|
||||
IsEnabled="{Binding CanExecuteOpen}"
|
||||
Cursor="Hand">
|
||||
<Image Source="../../Icons/Open.png"
|
||||
Height="14" />
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1"
|
||||
HorizontalAlignment="Left"
|
||||
Orientation="Horizontal"
|
||||
Margin="0,5">
|
||||
<Label Margin="0,0,20,0"
|
||||
VerticalAlignment="Bottom"
|
||||
Content="Quick-Filter:"
|
||||
FontWeight="Bold" />
|
||||
<Button Width="Auto"
|
||||
Margin="5,0,0,0"
|
||||
Padding="4"
|
||||
ToolTip="Filter löschen"
|
||||
Command="{Binding RefreshCommand}"
|
||||
Cursor="Hand">
|
||||
<Image Source="../../Icons/Cross.png"
|
||||
Height="14" />
|
||||
</Button>
|
||||
<Button Content="PL1"
|
||||
Width="Auto"
|
||||
Margin="10,0,0,0"
|
||||
ToolTip="Filter auf PL1"
|
||||
Command="{Binding CmdQuickSearch}"
|
||||
CommandParameter="PL1"
|
||||
FocusManager.FocusedElement="{Binding ElementName=tbSearch}" />
|
||||
<Button Content="PL2"
|
||||
Width="Auto"
|
||||
Margin="10,0,0,0"
|
||||
ToolTip="Filter auf PL2"
|
||||
Command="{Binding CmdQuickSearch}"
|
||||
CommandParameter="PL2"
|
||||
FocusManager.FocusedElement="{Binding ElementName=tbSearch}" />
|
||||
<Button Content="PL3"
|
||||
Width="Auto"
|
||||
Margin="10,0,0,0"
|
||||
ToolTip="Filter auf PL3"
|
||||
Command="{Binding CmdQuickSearch}"
|
||||
CommandParameter="PL3"
|
||||
FocusManager.FocusedElement="{Binding ElementName=tbSearch}" />
|
||||
<Button Content="SMZ"
|
||||
Width="Auto"
|
||||
Margin="10,0,0,0"
|
||||
ToolTip="Filter auf SMZ"
|
||||
Command="{Binding CmdQuickSearch}"
|
||||
CommandParameter="SMZ"
|
||||
FocusManager.FocusedElement="{Binding ElementName=tbSearch}" />
|
||||
</StackPanel>
|
||||
|
||||
<control:FilterDataGrid x:Name="FilterDataGrid"
|
||||
Grid.Row="2"
|
||||
AutoGenerateColumns="False"
|
||||
DateFormatString="d"
|
||||
FilterLanguage="German"
|
||||
ItemsSource="{Binding PrjsFiltered, UpdateSourceTrigger=PropertyChanged}"
|
||||
SelectionMode="Single"
|
||||
SelectedItem="{Binding SeletctedPrj, UpdateSourceTrigger=PropertyChanged}"
|
||||
ShowElapsedTime="false"
|
||||
ShowRowsCount="True"
|
||||
ShowStatusBar="True">
|
||||
|
||||
<control:FilterDataGrid.InputBindings>
|
||||
<MouseBinding MouseAction="LeftDoubleClick"
|
||||
Command="{Binding CmdOpen}" />
|
||||
|
||||
</control:FilterDataGrid.InputBindings>
|
||||
<control:FilterDataGrid.Columns>
|
||||
|
||||
<control:DataGridTemplateColumn FieldName="PlantNo"
|
||||
Header="Anlagen-Nr."
|
||||
IsColumnFiltered="True"
|
||||
SortMemberPath="PlantNo">
|
||||
<control:DataGridTemplateColumn.CellTemplate>
|
||||
<DataTemplate DataType="local:Prj">
|
||||
<TextBlock Text="{Binding PlantNo}" />
|
||||
</DataTemplate>
|
||||
</control:DataGridTemplateColumn.CellTemplate>
|
||||
</control:DataGridTemplateColumn>
|
||||
|
||||
<control:DataGridTextColumn Binding="{Binding SubPlantNo}"
|
||||
Header="Teilanlagen-Nr."
|
||||
IsReadOnly="True"
|
||||
IsColumnFiltered="True" />
|
||||
|
||||
<control:DataGridTextColumn Binding="{Binding No, StringFormat={}{0:0000}}"
|
||||
Header="Lfd.-Nr."
|
||||
IsReadOnly="True"
|
||||
IsColumnFiltered="True" />
|
||||
|
||||
<control:DataGridTextColumn Binding="{Binding Plant}"
|
||||
Header="Anlage"
|
||||
IsReadOnly="True"
|
||||
IsColumnFiltered="True" />
|
||||
|
||||
<control:DataGridTextColumn Binding="{Binding SubPlant}"
|
||||
Header="Teilanlage"
|
||||
IsReadOnly="True"
|
||||
IsColumnFiltered="True" />
|
||||
|
||||
<control:DataGridTextColumn Binding="{Binding Description}"
|
||||
Header="Bezeichnung"
|
||||
IsReadOnly="True"
|
||||
IsColumnFiltered="True" />
|
||||
</control:FilterDataGrid.Columns>
|
||||
</control:FilterDataGrid>
|
||||
</Grid>
|
||||
</Window>
|
||||
64
FSI.Lib/Guis/Prj.Mgt/FrmMain.xaml.cs
Normal file
64
FSI.Lib/Guis/Prj.Mgt/FrmMain.xaml.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using FSI.Lib.Guis.Prj.Mgt.ViewModel;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace FSI.Lib.Guis.Prj.Mgt
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für Main.xaml
|
||||
/// </summary>
|
||||
public partial class FrmMain : Window
|
||||
{
|
||||
public ViewModelPrj Prj { get; set; }
|
||||
public bool ShowPdf { get; set; }
|
||||
public bool CloseAtLostFocus { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string[] EplExes { get; set; }
|
||||
|
||||
public FrmMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Loaded += Main_Loaded;
|
||||
Deactivated += FrmMain_Deactivated;
|
||||
}
|
||||
|
||||
private void FrmMain_Deactivated(object sender, System.EventArgs e)
|
||||
{
|
||||
if (CloseAtLostFocus)
|
||||
Visibility = Visibility.Hidden;
|
||||
}
|
||||
|
||||
private void Main_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (ShowPdf)
|
||||
{
|
||||
Title = "FSI PDF-Auswahl";
|
||||
}
|
||||
else
|
||||
{
|
||||
Title = "FSI Epl Projektauswahl";
|
||||
}
|
||||
|
||||
Title += " v" + Assembly.GetExecutingAssembly().GetName().Version; // Version in Titel eintragen
|
||||
|
||||
Prj = new ViewModelPrj(new PrjDataProvider())
|
||||
{
|
||||
DataPath = Path,
|
||||
ShowPdf = ShowPdf,
|
||||
EplExes = EplExes,
|
||||
};
|
||||
DataContext = Prj;
|
||||
|
||||
Prj.Load();
|
||||
}
|
||||
|
||||
private void tbSearch_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
tbSearch.Select(tbSearch.Text.Length, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
FSI.Lib/Guis/Prj.Mgt/Model/Prj.cs
Normal file
25
FSI.Lib/Guis/Prj.Mgt/Model/Prj.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FSI.Lib.Guis.Prj.Mgt.Model
|
||||
{
|
||||
public class Prj
|
||||
{
|
||||
public Int64 PlantNo { get; set; }
|
||||
public Int64 SubPlantNo { get; set; }
|
||||
public Int64 No { get; set; }
|
||||
public string Plant { get; set; }
|
||||
public string SubPlant { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string DescriptionDetail { get; set; }
|
||||
public string FullName { get; set; }
|
||||
}
|
||||
|
||||
public interface IPrjDataProvider
|
||||
{
|
||||
IEnumerable<Prj> Load(string path, bool showPdf);
|
||||
}
|
||||
}
|
||||
208
FSI.Lib/Guis/Prj.Mgt/ViewModel/ViewModelPrj.cs
Normal file
208
FSI.Lib/Guis/Prj.Mgt/ViewModel/ViewModelPrj.cs
Normal file
@@ -0,0 +1,208 @@
|
||||
using FSI.Lib.Guis.Prj.Mgt.Model;
|
||||
using FSI.Lib.MVVM;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace FSI.Lib.Guis.Prj.Mgt.ViewModel
|
||||
{
|
||||
public class ViewModelPrj : MVVM.ViewModelBase
|
||||
{
|
||||
readonly IPrjDataProvider _prjDataProvider;
|
||||
private string _search;
|
||||
private ICollectionView _collView;
|
||||
|
||||
public ICommand RefreshCommand => new DelegateCommand(RefreshData);
|
||||
private ICommand _cmdQuickSearch;
|
||||
private ICommand _cmdOpen;
|
||||
|
||||
public ViewModelPrj(IPrjDataProvider prjDataProvider)
|
||||
{
|
||||
Prjs = new ObservableCollection<Model.Prj>();
|
||||
_prjDataProvider = prjDataProvider;
|
||||
|
||||
_cmdQuickSearch = new RelayCommand<object>(ExecuteQuickSearch, CanExecuteQuickSearch);
|
||||
_cmdOpen = new RelayCommand<object>(ExecuteOpen, CanExecuteOpen);
|
||||
}
|
||||
|
||||
public ObservableCollection<Model.Prj> Prjs { get; }
|
||||
public ObservableCollection<Model.Prj> PrjsFiltered { get; set; }
|
||||
|
||||
public Model.Prj SeletctedPrj { get; set; }
|
||||
|
||||
public string DataPath { get; set; }
|
||||
|
||||
public bool ShowPdf { get; set; }
|
||||
public string[] EplExes { get; set; }
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var prjs = _prjDataProvider.Load(DataPath, ShowPdf);
|
||||
Prjs.Clear();
|
||||
|
||||
if (prjs != null)
|
||||
{
|
||||
foreach (Model.Prj prj in prjs)
|
||||
{
|
||||
Prjs.Add(prj);
|
||||
}
|
||||
}
|
||||
|
||||
PrjsFiltered = new ObservableCollection<Model.Prj>(Prjs);
|
||||
_collView = CollectionViewSource.GetDefaultView(PrjsFiltered);
|
||||
}
|
||||
|
||||
public string Search
|
||||
{
|
||||
get => _search;
|
||||
set
|
||||
{
|
||||
_search = value;
|
||||
|
||||
_collView.Filter = e =>
|
||||
{
|
||||
var item = (Model.Prj)e;
|
||||
return item != null && ((item.Plant?.StartsWith(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (item.SubPlant?.StartsWith(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
#if NET472
|
||||
|| (item.Description?.Contains(_search) ?? false)
|
||||
|| (item.DescriptionDetail?.Contains(_search) ?? false)
|
||||
#elif NET6_0
|
||||
|| (item.Description?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
|| (item.DescriptionDetail?.Contains(_search, StringComparison.OrdinalIgnoreCase) ?? false)
|
||||
#endif
|
||||
);
|
||||
};
|
||||
|
||||
_collView.Refresh();
|
||||
PrjsFiltered = new ObservableCollection<Model.Prj>(_collView.OfType<Model.Prj>().ToList());
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void QuickSearch(string search)
|
||||
{
|
||||
Search = search + " ";
|
||||
}
|
||||
|
||||
private void RefreshData(object obj)
|
||||
{
|
||||
Search = string.Empty;
|
||||
}
|
||||
|
||||
private bool CanExecuteQuickSearch(object obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ExecuteQuickSearch(object obj)
|
||||
{
|
||||
QuickSearch(obj.ToString());
|
||||
}
|
||||
|
||||
public ICommand CmdQuickSearch
|
||||
{
|
||||
get { return _cmdQuickSearch; }
|
||||
set => _cmdQuickSearch = value;
|
||||
}
|
||||
|
||||
private bool CanExecuteOpen(object obj)
|
||||
{
|
||||
if (SeletctedPrj != null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ExecuteOpen(object obj)
|
||||
{
|
||||
if (ShowPdf)
|
||||
{
|
||||
new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo(SeletctedPrj.FullName)
|
||||
{
|
||||
UseShellExecute = true
|
||||
}
|
||||
}.Start();
|
||||
}
|
||||
else
|
||||
{
|
||||
var arguments = " /Variant:\"Electric P8\" ProjectOpen /Project:\"" + SeletctedPrj.FullName + "\"";
|
||||
|
||||
string fileName = string.Empty;
|
||||
string path = string.Empty;
|
||||
|
||||
for (int i = 0; i <= EplExes.Length - 1; i++)
|
||||
{
|
||||
if (File.Exists(EplExes[i].Trim()))
|
||||
{
|
||||
fileName = EplExes[i].Trim();
|
||||
}
|
||||
}
|
||||
|
||||
new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = fileName,
|
||||
Arguments = arguments,
|
||||
}
|
||||
}.Start();
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand CmdOpen
|
||||
{
|
||||
get { return _cmdOpen; }
|
||||
set => _cmdOpen = value;
|
||||
}
|
||||
}
|
||||
|
||||
public class PrjDataProvider : IPrjDataProvider
|
||||
{
|
||||
public IEnumerable<Model.Prj> Load(string path, bool showPdf)
|
||||
{
|
||||
var prjs = new ObservableCollection<Model.Prj>();
|
||||
string[] files = Directory.GetFiles(path); // alle PDF-Dateien einlesen
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
if (((file.EndsWith(".elk") || file.EndsWith(".elp") || file.EndsWith(".els") || file.EndsWith(".elx") || file.EndsWith(".elr") || file.EndsWith(".ell") || file.EndsWith(".elf"))
|
||||
&& !showPdf) || (file.EndsWith(".pdf") && showPdf))
|
||||
{
|
||||
Model.Prj prj = new Model.Prj();
|
||||
FileInfo fileInfo = new FileInfo(file);
|
||||
string[] nameNo = fileInfo.Name.Substring(0, 27 - 1).Split('-');
|
||||
|
||||
if (nameNo.Length == 3) // 3 Zahlenblöcke vorhanden?
|
||||
{
|
||||
if (nameNo[0].Length == 10 || Int64.TryParse(nameNo[0], out _) || nameNo[1].Length == 10 || Int64.TryParse(nameNo[1], out _) || nameNo[2].Length == 4 || !Int64.TryParse(nameNo[2], out _)) // Länge der Zahlenblöcke überprüfen
|
||||
{
|
||||
prj.PlantNo = Int64.Parse(nameNo[0]);
|
||||
prj.SubPlantNo = Int64.Parse(nameNo[1]);
|
||||
prj.No = Int64.Parse(nameNo[2]);
|
||||
|
||||
string[] fileStrings = System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name).Split(' ');
|
||||
prj.Plant = fileStrings[1];
|
||||
prj.SubPlant = fileStrings[2];
|
||||
prj.Description = System.IO.Path.GetFileNameWithoutExtension(fileInfo.Name).Replace(nameNo[0] + "-" + nameNo[1] + "-" + nameNo[2] + " " + fileStrings[1] + " " + fileStrings[2], "");
|
||||
prj.Description = prj.Description.Trim();
|
||||
prj.DescriptionDetail = prj.Plant + " " + prj.SubPlant + " " + prj.Description;
|
||||
prj.FullName = fileInfo.FullName;
|
||||
prjs.Add(prj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return prjs;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user