864 lines
36 KiB
C#
864 lines
36 KiB
C#
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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 bool PersonalNummerIsEnabled { get; set; } = true;
|
|
|
|
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;
|
|
}
|
|
|
|
private static List<TableInfo> CreateLizenzList()
|
|
{
|
|
var path = "";
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\Lizenzen.csv")) path = @"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\Lizenzen.csv";
|
|
else
|
|
path = Properties.Settings.Default.LizenzenPath == "" ? OpenFile("Lizenzen") : Properties.Settings.Default.LizenzenPath;
|
|
|
|
if (!File.Exists(path)) path = OpenFile("Lizenzen");
|
|
|
|
|
|
if (File.ReadAllLines(path).First().StartsWith("Name;") || File.ReadAllLines(path).First().StartsWith("Personalnummer;0001"))
|
|
{
|
|
if (path != Properties.Settings.Default.LizenzenPath)
|
|
{
|
|
Properties.Settings.Default.LizenzenPath = path;
|
|
Properties.Settings.Default.Save();
|
|
}
|
|
|
|
var lizenzen = File.ReadAllLines(path, Encoding.GetEncoding(850));
|
|
var LizenzName = lizenzen.First().Split(';');
|
|
var lizenzList = new List<TableInfo>();
|
|
var sa = new List<string>();
|
|
|
|
|
|
for (var j = 1; j < lizenzen.Count(); j++)
|
|
{
|
|
string fLine = "";
|
|
var x = lizenzen[j].Split(';');
|
|
for (var i = 0; i < x.Length; i++)
|
|
{
|
|
var word = x[i];
|
|
if (word == "vorhanden" || word.Contains("."))
|
|
word = LizenzName[i];
|
|
|
|
if (word == "nicht mehr benötigt" || word == "verfallen") word = "";
|
|
|
|
fLine += word + ";";
|
|
}
|
|
|
|
lizenzList.Add(new TableInfo()
|
|
{
|
|
PersNummer = fLine.Split(';')[0],
|
|
Lizenzen = fLine.Split(';').Slice(1, fLine.Split(';').Count()).ToList().Where(s => !string.IsNullOrWhiteSpace(s)).Distinct().ToList()
|
|
});
|
|
}
|
|
|
|
return lizenzList;
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("Keine korrekte Lizenzen-Datei ausgewählt", "Fehler", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK, MessageBoxOptions.ServiceNotification);
|
|
return CreateLizenzList();
|
|
}
|
|
}
|
|
|
|
static bool exceptionBemerkungen = false;
|
|
static List<TableInfo> lastBemerkungenList = new List<TableInfo>();
|
|
static DateTime lastWriteBemerkungen = DateTime.Now;
|
|
public static async Task<List<TableInfo>> CreateBemerkungenList()
|
|
{
|
|
if (MainWindow.propertyChangeAllowed)
|
|
{
|
|
try
|
|
{
|
|
var list = new List<TableInfo>();
|
|
list = null;
|
|
|
|
var tNew = File.GetLastWriteTime(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json");
|
|
|
|
if (tNew != lastWriteBemerkungen)
|
|
{
|
|
if (Convert.ToDateTime(MainWindow.main.LastChangeTime) < tNew) MainWindow.main.LastChangeTime = tNew.ToString();
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json"))
|
|
{
|
|
try
|
|
{
|
|
//var jsonBemerkungen = File.ReadAllText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json");
|
|
|
|
for (var i = 0; list == null; i++)
|
|
{
|
|
if (i >= 50)
|
|
{
|
|
throw new StackOverflowException("Anzahl der Versuche 'ReadBemerkungenJSON' überschritten (i >= 50)");
|
|
break;
|
|
}
|
|
|
|
await Task.Delay(100);
|
|
list = await ReadBemerkungenJSON();
|
|
//if (list != null) break;
|
|
}
|
|
|
|
|
|
if (exceptionBemerkungen)
|
|
{
|
|
LogFile.WriteLine("Successfully created BemerkungenList");
|
|
exceptionBemerkungen = false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
exceptionBemerkungen = true;
|
|
|
|
return await CreateBemerkungenList();
|
|
}
|
|
}
|
|
else File.CreateText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json");
|
|
|
|
lastWriteBemerkungen = tNew;
|
|
|
|
if (list != null)
|
|
{
|
|
lastBemerkungenList = list;
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
LogFile.WriteLine("B-list is null");
|
|
return await CreateBemerkungenList();
|
|
}
|
|
}
|
|
else return lastBemerkungenList;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
return lastBemerkungenList;
|
|
}
|
|
}
|
|
else if (lastBemerkungenList != null) return lastBemerkungenList;
|
|
else return await CreateBemerkungenList();
|
|
}
|
|
|
|
private static async Task<List<TableInfo>> ReadBemerkungenJSON()
|
|
{
|
|
var fail = false;
|
|
|
|
try
|
|
{
|
|
using (var fs = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json", FileMode.Open, FileAccess.Read, FileShare.Read)) //Write | FileShare.Delete
|
|
{
|
|
if (fs != null)
|
|
{
|
|
byte[] json = new byte[fs.Length];
|
|
await fs.ReadAsync(json, 0, (int)fs.Length);
|
|
var jsonBemerkungen = Encoding.UTF8.GetString(json);
|
|
|
|
if (!Helper.IsBase64String(jsonBemerkungen) || jsonBemerkungen == "")
|
|
return null;
|
|
|
|
var jsonBemerkungenDecrypted = "%%";
|
|
for (var i = 0; jsonBemerkungenDecrypted == "%%" || i <= 10; i++)
|
|
{
|
|
jsonBemerkungenDecrypted = await Crypto.DecryptString(jsonBemerkungen);
|
|
|
|
if (jsonBemerkungenDecrypted == "%%")
|
|
{
|
|
if (i > 0)
|
|
{
|
|
LogFile.WriteLine($"Decrypt Bemerkungen failed - for the {i}. Time - Trying again...");
|
|
fail = true;
|
|
}
|
|
|
|
using (var fs1 = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Bemerkungen.json", FileMode.Open, FileAccess.Read, FileShare.Read))//Write | FileShare.Delete
|
|
{
|
|
json = new byte[fs1.Length];
|
|
await fs1.ReadAsync(json, 0, (int)fs1.Length);
|
|
jsonBemerkungen = Encoding.UTF8.GetString(json);
|
|
|
|
await Task.Delay(100);
|
|
}
|
|
}
|
|
else break;
|
|
}
|
|
|
|
if (fail) LogFile.WriteLine("Decrypt Bemerkungen succeeded");
|
|
fail = false;
|
|
|
|
//jsonBemerkungen = Crypto.DecryptString(jsonBemerkungen);
|
|
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TableInfo>>(jsonBemerkungenDecrypted);
|
|
|
|
//jsonLength = json == null ? 111111 : json.Length;
|
|
//jsonBemerkungenLength = jsonBemerkungen == null ? 111111 : jsonBemerkungen.Length;
|
|
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
fs.Dispose();
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static bool exceptionZuweisungen = false;
|
|
static List<TableInfo> lastZuweisungenList = new List<TableInfo>();
|
|
public static DateTime lastWriteZuweisungen = DateTime.Now;
|
|
public static async Task<List<TableInfo>> CreateZuweisungenList()
|
|
{
|
|
if (MainWindow.propertyChangeAllowed)
|
|
{
|
|
try
|
|
{
|
|
var list = new List<TableInfo>();
|
|
list = null;
|
|
|
|
var tNew = File.GetLastWriteTime(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json");
|
|
|
|
|
|
if (tNew != lastWriteZuweisungen)
|
|
{
|
|
if (Convert.ToDateTime(MainWindow.main.LastChangeTime) < tNew) MainWindow.main.LastChangeTime = tNew.ToString();
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json"))
|
|
{
|
|
var jsonLength = 0;
|
|
var jsonZuweisungenLength = 0;
|
|
|
|
|
|
try
|
|
{
|
|
//var jsonZuweisungen = File.ReadAllText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json");
|
|
|
|
for (var i = 0; list == null; i++)
|
|
{
|
|
await Task.Delay(100);
|
|
list = await ReadZuweisungenJSON();
|
|
|
|
//if (list != null) break;
|
|
if (i >= 50)
|
|
{
|
|
LogFile.WriteLine("Anzahl der Versuche 'ReadZuweisungenJSON' überschritten (i >= 50)");
|
|
i = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (exceptionZuweisungen)
|
|
{
|
|
LogFile.WriteLine("Successfully created ZuweisungenList");
|
|
exceptionZuweisungen = false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
|
|
LogFile.WriteLine("json.Length: " + jsonLength);
|
|
LogFile.WriteLine("jsonZuweisungen.Length " + jsonZuweisungenLength);
|
|
|
|
|
|
exceptionZuweisungen = true;
|
|
|
|
return await CreateZuweisungenList();
|
|
}
|
|
}
|
|
else File.CreateText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json");
|
|
|
|
lastWriteZuweisungen = tNew;
|
|
|
|
if (list != null)
|
|
{
|
|
lastZuweisungenList = list;
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
LogFile.WriteLine("list is null");
|
|
return lastZuweisungenList;//await CreateZuweisungenList();
|
|
}
|
|
}
|
|
else return lastZuweisungenList;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
return lastZuweisungenList;
|
|
}
|
|
}
|
|
else if (lastZuweisungenList != null) return lastZuweisungenList;
|
|
else return await CreateZuweisungenList();
|
|
}
|
|
|
|
private static async Task<List<TableInfo>> ReadZuweisungenJSON()
|
|
{
|
|
var fail = false;
|
|
try
|
|
{
|
|
using (var fs = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json", FileMode.Open, FileAccess.Read, FileShare.Read)) //Test 25.07.19 FileShare.ReadWrite | FileShare.Delete
|
|
{
|
|
if (fs != null)
|
|
{
|
|
byte[] json = new byte[fs.Length];
|
|
await fs.ReadAsync(json, 0, (int)fs.Length);
|
|
var jsonZuweisungen = Encoding.UTF8.GetString(json);
|
|
|
|
if (!Helper.IsBase64String(jsonZuweisungen) || jsonZuweisungen == "")
|
|
return null;
|
|
|
|
var jsonZuweisungenDecrypted = "%%";
|
|
for (var i = 0; jsonZuweisungenDecrypted == "%%" || i <= 10; i++)
|
|
{
|
|
jsonZuweisungenDecrypted = await Crypto.DecryptString(jsonZuweisungen);
|
|
|
|
if (jsonZuweisungenDecrypted == "%%")
|
|
{
|
|
if (i > 0)
|
|
{
|
|
LogFile.WriteLine($"Decrypt Zuweisungen failed - for the {i}. Time - Trying again...");
|
|
|
|
fail = true;
|
|
}
|
|
|
|
using (var fs1 = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Zuweisungen.json", FileMode.Open, FileAccess.Read, FileShare.Read))//Write | FileShare.Delete
|
|
{
|
|
json = new byte[fs1.Length];
|
|
await fs1.ReadAsync(json, 0, (int)fs1.Length);
|
|
jsonZuweisungen = Encoding.UTF8.GetString(json);
|
|
|
|
await Task.Delay(1000);
|
|
}
|
|
}
|
|
else break;
|
|
}
|
|
|
|
if (fail) LogFile.WriteLine("Decrypt Zuweisungen succeeded");
|
|
fail = false;
|
|
|
|
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TableInfo>>(jsonZuweisungenDecrypted);
|
|
//var items = Enumerable.SequenceEqual(list, lastZuweisungenList);
|
|
//jsonLength = json == null ? 111111 : json.Length;
|
|
//jsonZuweisungenLength = jsonZuweisungen == null ? 111111 : jsonZuweisungen.Length;
|
|
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
fs.Dispose();
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
LogFile.WriteLine(ex.ToString());
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
static bool exceptionTelefon = false;
|
|
static List<TableInfo> lastTelefonList = new List<TableInfo>();
|
|
public static DateTime lastWriteTelefon = DateTime.Now;
|
|
public static async Task<List<TableInfo>> CreateTelefonList()
|
|
{
|
|
if (MainWindow.propertyChangeAllowed)
|
|
{
|
|
try
|
|
{
|
|
var list = new List<TableInfo>();
|
|
list = null;
|
|
|
|
var tNew = File.GetLastWriteTime(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json");
|
|
|
|
|
|
if (tNew != lastWriteTelefon)
|
|
{
|
|
if (Convert.ToDateTime(MainWindow.main.LastChangeTime) < tNew) MainWindow.main.LastChangeTime = tNew.ToString();
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json"))
|
|
{
|
|
var jsonLength = 0;
|
|
var jsonTelefonLength = 0;
|
|
|
|
|
|
try
|
|
{
|
|
//var jsonTelefon = File.ReadAllText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json");
|
|
|
|
for (var i = 0; list == null; i++)
|
|
{
|
|
list = await ReadTelefonJSON();
|
|
await Task.Delay(100);
|
|
//if (list != null) break;
|
|
if (i >= 50)
|
|
{
|
|
LogFile.WriteLine("Anzahl der Versuche 'ReadTelefonJSON' überschritten (i >= 50)");
|
|
i = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (exceptionTelefon)
|
|
{
|
|
LogFile.WriteLine("Successfully created TelefonList");
|
|
exceptionTelefon = false;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
|
|
LogFile.WriteLine("json.Length: " + jsonLength);
|
|
LogFile.WriteLine("jsonTelefon.Length " + jsonTelefonLength);
|
|
|
|
|
|
exceptionTelefon = true;
|
|
|
|
return await CreateTelefonList();
|
|
}
|
|
}
|
|
else File.CreateText(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json");
|
|
|
|
lastWriteTelefon = tNew;
|
|
|
|
if (list != null)
|
|
{
|
|
lastTelefonList = list;
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
LogFile.WriteLine("list is null");
|
|
return lastTelefonList;//await CreateTelefonList();
|
|
}
|
|
}
|
|
else return lastTelefonList;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
LogFile.WriteLine("Message: " + ex.Message);
|
|
if (ex.InnerException != null) LogFile.WriteLine("InnerException: " + ex.InnerException);
|
|
return lastTelefonList;
|
|
}
|
|
}
|
|
else if (lastTelefonList != null) return lastTelefonList;
|
|
else return await CreateTelefonList();
|
|
}
|
|
|
|
private static async Task<List<TableInfo>> ReadTelefonJSON()
|
|
{
|
|
var fail = false;
|
|
try
|
|
{
|
|
using (var fs = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json", FileMode.Open, FileAccess.Read, FileShare.Read)) //Write | FileShare.Delete
|
|
{
|
|
if (fs != null)
|
|
{
|
|
byte[] json = new byte[fs.Length];
|
|
await fs.ReadAsync(json, 0, (int)fs.Length);
|
|
var jsonTelefon = Encoding.UTF8.GetString(json);
|
|
|
|
if (!Helper.IsBase64String(jsonTelefon) || jsonTelefon == "")
|
|
return null;
|
|
|
|
var jsonTelefonDecrypted = "%%";
|
|
for (var i = 0; jsonTelefonDecrypted == "%%" || i <= 10; i++)
|
|
{
|
|
jsonTelefonDecrypted = await Crypto.DecryptString(jsonTelefon);
|
|
|
|
if (jsonTelefonDecrypted == "%%")
|
|
{
|
|
if (i > 0)
|
|
{
|
|
LogFile.WriteLine($"Decrypt Telefon failed - for the {i}. Time - Trying again...");
|
|
|
|
fail = true;
|
|
}
|
|
|
|
using (var fs1 = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\JSON\Telefon.json", FileMode.Open, FileAccess.Read, FileShare.Read))//Write | FileShare.Delete
|
|
{
|
|
json = new byte[fs1.Length];
|
|
await fs1.ReadAsync(json, 0, (int)fs1.Length);
|
|
jsonTelefon = Encoding.UTF8.GetString(json);
|
|
|
|
await Task.Delay(1000);
|
|
}
|
|
}
|
|
else break;
|
|
}
|
|
|
|
if (fail) LogFile.WriteLine("Decrypt Telefon succeeded");
|
|
fail = false;
|
|
|
|
var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<TableInfo>>(jsonTelefonDecrypted);
|
|
//var items = Enumerable.SequenceEqual(list, lastTelefonList);
|
|
//jsonLength = json == null ? 111111 : json.Length;
|
|
//jsonTelefonLength = jsonTelefon == null ? 111111 : jsonTelefon.Length;
|
|
|
|
return list;
|
|
}
|
|
else
|
|
{
|
|
fs.Dispose();
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogFile.WriteLine(ex.ToString());
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public static List<TableInfo> LizenzList { get; set; }
|
|
|
|
|
|
public static List<TableInfo> ReadUserList(bool FilePicker = false)
|
|
{
|
|
var lizenzList = CreateLizenzList();
|
|
LizenzList = lizenzList;
|
|
var bemerkungenList = CreateBemerkungenList();
|
|
var zuweisungenList = CreateZuweisungenList();
|
|
var telefonList = CreateTelefonList();
|
|
List<TableInfo> list = new List<TableInfo>();
|
|
var users = OpenUserList(FilePicker);
|
|
|
|
foreach (var user in users)
|
|
{
|
|
if (user.StartsWith("0"))
|
|
{
|
|
var liz = new TableInfo();
|
|
if (PersonalNummerIsEnabled)
|
|
{
|
|
var li = lizenzList.Where(p => p.PersNummer == user.Split(';')[0]);
|
|
|
|
if (li.Count() > 0)
|
|
{
|
|
liz = li.First();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var li = lizenzList.Where(p => p.Name == user.Split(';')[1] && p.Vorname == user.Split(';')[2]);
|
|
|
|
if (li.Count() > 0) liz = li.First();
|
|
}
|
|
|
|
var bem = new TableInfo();
|
|
if (bemerkungenList.Result != null)
|
|
{
|
|
if (PersonalNummerIsEnabled)
|
|
{
|
|
var be = bemerkungenList.Result.Where(p => p.PersNummer == user.Split(';')[0] && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (be.Count() > 0) bem = be.First();
|
|
}
|
|
else
|
|
{
|
|
var be = bemerkungenList.Result.Where(p => p.Name == user.Split(';')[1] && p.Vorname == user.Split(';')[2] && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (be.Count() > 0) bem = be.First();
|
|
}
|
|
}
|
|
|
|
var zuw = new TableInfo();
|
|
if (zuweisungenList.Result != null)
|
|
{
|
|
if (PersonalNummerIsEnabled)
|
|
{
|
|
var zu = zuweisungenList.Result.Where(p => p.PersNummer == user.Split(';')[0] && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (zu.Count() > 0) zuw = zu.First();
|
|
}
|
|
else
|
|
{
|
|
var zu = zuweisungenList.Result.Where(p => p.Name == user.Split(';')[1] && p.Vorname == user.Split(';')[2] && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (zu.Count() > 0) zuw = zu.First();
|
|
}
|
|
}
|
|
|
|
var tele = new TableInfo();
|
|
if (telefonList.Result != null)
|
|
{
|
|
if (PersonalNummerIsEnabled)
|
|
{
|
|
var tel = telefonList.Result.Where(p => p.PersNummer == user.Split(';')[0]);// && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (tel.Count() > 0) tele = tel.First();
|
|
}
|
|
else
|
|
{
|
|
var tel = telefonList.Result.Where(p => p.Name == user.Split(';')[1] && p.Vorname == user.Split(';')[2] && p.Datum == DateTime.Parse(user.Split(';')[3]));
|
|
if (tel.Count() > 0) tele = tel.First();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Tuple<string, string> abtName = null;
|
|
if (MainWindow.main.AbteilungsNamen.TryGetValue(user.Split(';')[10], out abtName)) ;
|
|
else abtName = new Tuple<string, string>(user.Split(';')[10].Split(';')[0], user.Split(';')[10].Split(';')[1]);
|
|
|
|
|
|
|
|
list.Add(new TableInfo()
|
|
{
|
|
PersNummer = user.Split(';')[0],
|
|
Name = user.Split(';')[1],
|
|
Vorname = user.Split(';')[2],
|
|
Datum = DateTime.Parse(user.Split(';')[3]),
|
|
Gehen = user.Split(';')[6],
|
|
Arbeitsmuster = user.Split(';')[4],
|
|
Abteilung = abtName.Item2 == "" ? abtName.Item1 : abtName.Item2,
|
|
Tagescode = user.Split(';')[12],
|
|
Beginn = user.Split(';')[5],
|
|
Zuweisung = zuw.Zuweisung,
|
|
ZuweisungsMoeglichkeiten = MainWindow.main.ZuweisungsMoeglichkeiten,
|
|
Lizenzen = liz.Lizenzen,
|
|
Bemerkung = bem.Bemerkung,
|
|
Telefon = tele.Telefon
|
|
});
|
|
}
|
|
}
|
|
|
|
var last = 0;
|
|
foreach (var entry in list)
|
|
{
|
|
if (last != Convert.ToInt32(entry.PersNummer))
|
|
{
|
|
if (entry.Lizenzen != null) entry.Lizenzen.Insert(0, $"{entry.Lizenzen.Count} Lizenzen");
|
|
else
|
|
{
|
|
entry.Lizenzen = new List<string>();
|
|
entry.Lizenzen.Add("keine Lizenzen");
|
|
}
|
|
}
|
|
else if (entry.Lizenzen == null)
|
|
{
|
|
entry.Lizenzen = new List<string>();
|
|
entry.Lizenzen.Add("keine Lizenzen");
|
|
}
|
|
|
|
last = Convert.ToInt32(entry.PersNummer);
|
|
}
|
|
|
|
list = list.Where(p => p.Tagescode == "" || p.Tagescode.All(char.IsDigit)).ToList();
|
|
list = list.Where(p => p.Arbeitsmuster.ToLower() != "frei").ToList();
|
|
//list.Sort((a, b) => a.Name.CompareTo(b.Name));
|
|
list = list.OrderBy(name => name.Name).ThenBy(vorname => vorname.Vorname).ThenBy(abteilung => abteilung.Abteilung).ThenBy(datum => datum.Datum).ToList();
|
|
|
|
return list;
|
|
}
|
|
|
|
private static string[] OpenUserList(bool FilePicker = false)
|
|
{
|
|
var path = "";
|
|
|
|
if (File.Exists(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\DTIME.csv") && !FilePicker) path = @"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\DTIME.csv";
|
|
else
|
|
path = OpenFile("Mitarbeiterliste");
|
|
|
|
var users = System.IO.File.ReadAllLines(path, Encoding.GetEncoding(65001));
|
|
|
|
if (users[0].StartsWith("Personalnummer;Nachname")) users = users;
|
|
else
|
|
{
|
|
var x = System.Windows.MessageBox.Show("Keine gültige Mitarbeiterliste ausgewählt!", "Fehler!", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Exclamation, System.Windows.MessageBoxResult.OK, System.Windows.MessageBoxOptions.ServiceNotification);
|
|
return OpenUserList();
|
|
}
|
|
|
|
return users;
|
|
}
|
|
|
|
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 async Task<double> ReadTime(Dictionary<string, Tuple<double, bool, string>> keyValuePairs)
|
|
{
|
|
var client = await Crypto.EncryptString(Environment.MachineName);
|
|
KeyValuePair<string, double> output = new KeyValuePair<string, double>();
|
|
|
|
|
|
if (keyValuePairs != null && keyValuePairs.Where(p => p.Key == client).Count() > 0)
|
|
{
|
|
var o = keyValuePairs.Where(p => p.Key == client).First();
|
|
output = new KeyValuePair<string, double>(o.Key, o.Value.Item1);
|
|
|
|
}
|
|
else return 0;
|
|
|
|
return output.Value;
|
|
}
|
|
|
|
public static async Task<Dictionary<string, Tuple<double, bool, string>>> ReadTimeJSON()
|
|
{
|
|
using (var fs = Writer.WaitForFile(@"\\bku.db.de\db\DB_006\GLW_11\ICE-Fertigung\M2\Personaleinsatzplanung\Log\Track.json", FileMode.Open, FileAccess.Read, FileShare.Read)) //Write | FileShare.Delete
|
|
{
|
|
byte[] json = new byte[fs.Length];
|
|
await fs.ReadAsync(json, 0, (int)fs.Length);
|
|
var jsonTrack = Encoding.UTF8.GetString(json);
|
|
|
|
//if (!Helper.IsBase64String(jsonTrack) || jsonTrack == "")
|
|
// return null;
|
|
|
|
//var enc = "%%";
|
|
|
|
//enc = await Crypto.DecryptString(jsonTrack);
|
|
try
|
|
{
|
|
var keyValuePairs = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, Tuple<double, bool, string>>>(jsonTrack);
|
|
return keyValuePairs;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
fs.Dispose();
|
|
return await ReadTimeJSON();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
}
|