126 lines
4.3 KiB
C#
126 lines
4.3 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace PEP_Tool
|
|
{
|
|
public static class Reader
|
|
{
|
|
public static string OpenFile(string Dialogname = "Datei")
|
|
{
|
|
OpenFileDialog dialog = new OpenFileDialog();
|
|
dialog.RestoreDirectory = true;
|
|
|
|
dialog.Title = $"{Dialogname} öffnen";
|
|
|
|
dialog.Filter = "Excel Arbeitsblatt CSV|*.csv";
|
|
dialog.ShowDialog();
|
|
|
|
var result = dialog.FileName;
|
|
|
|
if (string.IsNullOrEmpty(result))
|
|
return OpenFile(Dialogname);
|
|
else
|
|
return result;
|
|
}
|
|
|
|
internal static List<string> ReadZuweisungsMoeglichkeiten()
|
|
{
|
|
var path = "";
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\Zuweisungen.csv")) path = @"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\Zuweisungen.csv";
|
|
else
|
|
path = Properties.Settings.Default.ZuweisungenPath == "" ? OpenFile("Zuweisungen") : Properties.Settings.Default.ZuweisungenPath;
|
|
|
|
if (!File.Exists(path)) path = OpenFile("Zuweisungen");
|
|
|
|
if (!File.ReadAllText(path, Encoding.GetEncoding(1250)).Contains(";"))
|
|
{
|
|
if (path != Properties.Settings.Default.ZuweisungenPath)
|
|
{
|
|
Properties.Settings.Default.ZuweisungenPath = path;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
|
|
var list = File.ReadAllLines(path, Encoding.GetEncoding(1250)).ToList();
|
|
list.Insert(0, "");
|
|
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Keine korrekte Zuweisungen-Datei ausgewählt", "Fehler", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
|
|
return ReadZuweisungsMoeglichkeiten();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
internal static Dictionary<string, Tuple<string, string>> ReadAbteilungsNamen()
|
|
{
|
|
var path = "";
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\DKEYS.csv")) path = @"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\DKEYS.csv";
|
|
else
|
|
path = Properties.Settings.Default.AbteilungsnamenPath == "" ? OpenFile("Abteilungsnamen") : Properties.Settings.Default.AbteilungsnamenPath;
|
|
|
|
if (!File.Exists(path)) path = OpenFile("Abteilungsnamen");
|
|
|
|
if (File.ReadAllLines(path).First().StartsWith("Abteilung;"))
|
|
{
|
|
if (path != Properties.Settings.Default.AbteilungsnamenPath)
|
|
{
|
|
Properties.Settings.Default.AbteilungsnamenPath = path;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
|
|
|
|
Dictionary<string, Tuple<string, string>> list = new Dictionary<string, Tuple<string, string>>();
|
|
foreach (var line in File.ReadAllLines(path))
|
|
{
|
|
list.Add(line.Split(';')[0], new Tuple<string, string>(line.Split(';')[1], line.Split(';')[2]));
|
|
}
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Keine korrekte Abteilungsnamen-Datei ausgewählt", "Fehler", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
|
|
return ReadAbteilungsNamen();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static class Extensions
|
|
{
|
|
/// <summary>
|
|
/// Get the array slice between the two indexes.
|
|
/// ... Inclusive for start index, exclusive for end index.
|
|
/// </summary>
|
|
public static T[] Slice<T>(this T[] source, int start, int end)
|
|
{
|
|
// Handles negative ends.
|
|
if (end < 0)
|
|
{
|
|
end = source.Length + end;
|
|
}
|
|
int len = end - start;
|
|
|
|
// Return new array.
|
|
T[] res = new T[len];
|
|
for (int i = 0; i < len; i++)
|
|
{
|
|
res[i] = source[i + start];
|
|
}
|
|
return res;
|
|
}
|
|
}
|
|
|
|
}
|