137 lines
5.3 KiB
C#
137 lines
5.3 KiB
C#
using MergeCMInpro.Business;
|
|
using MergeCMInpro.Data;
|
|
using NLog;
|
|
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace MergeCMInpro
|
|
{
|
|
static class Program
|
|
{
|
|
private static readonly Logger _logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
static string csvPath = String.Empty;
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.White;
|
|
|
|
//productive
|
|
csvPath = Path.Combine(Directory.GetFiles(Environment.CurrentDirectory, "*.csv").FirstOrDefault());
|
|
|
|
//testing
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_SAGA\815.922 - 819.917 SAGA HD 21 2021_09_27_Testing", "*.csv").FirstOrDefault());
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"C:\Testing\MergeInpro", "*.csv").FirstOrDefault());
|
|
|
|
|
|
string pathOutputFileCM = Path.Combine(Directory.GetParent(csvPath).FullName, "outputCM.csv");
|
|
string pathOutputFileInpro = Path.Combine(Directory.GetParent(csvPath).FullName, "outputInpro.csv");
|
|
string pathOutputFileStandort = Path.Combine(Directory.GetParent(csvPath).FullName, "outputStandort.csv");
|
|
|
|
if (CheckFileExist())
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.WriteLine("WARNING: import files already exist.");
|
|
Console.ResetColor();
|
|
return;
|
|
}
|
|
|
|
var config = File.ReadLines(@".\config.txt").ToArray();
|
|
DataOperations.conString = config[0];
|
|
DataOperations.kanalAktePath = config[2];
|
|
DataOperations.csvPath = csvPath;
|
|
|
|
if (!File.Exists(DataOperations.kanalAktePath))
|
|
throw new FileNotFoundException("Kanalaktendatei nicht gefunden.");
|
|
|
|
string archivNetPath = Path.Combine(config[1]);
|
|
|
|
Console.WriteLine("Working, please wait... or get yourself a tea.");
|
|
|
|
FileOperations.SplitRow(csvPath, archivNetPath);
|
|
|
|
//CM
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileCM))
|
|
{
|
|
foreach (var item in DataOperations.vorgängeCM)
|
|
{
|
|
sw.WriteLine(item.ToString());
|
|
}
|
|
}
|
|
|
|
//Inpro
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileInpro))
|
|
{
|
|
foreach (var item in DataOperations.vorgängeInpro)
|
|
{
|
|
sw.WriteLine(item.ToString());
|
|
}
|
|
}
|
|
|
|
//Standort
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileStandort))
|
|
{
|
|
for (int i = 0; i < DataOperations.vorgängeStandort.Count; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
sw.WriteLine(String.Concat("CID", "VORGANGID", "Sachbearbeiter", "Bemerkung", "Standort", "ENTNAHMEDATUM", "Entnahmezeit", "RUECKGABEDATUM", "Rückgabezeit"));
|
|
}
|
|
sw.WriteLine(DataOperations.vorgängeStandort[i]);
|
|
}
|
|
}
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
Console.WriteLine("{0} created.", pathOutputFileCM);
|
|
Console.WriteLine("{0} created.", pathOutputFileInpro);
|
|
Console.WriteLine("{0} created.", pathOutputFileStandort);
|
|
Console.ResetColor();
|
|
|
|
//Backup JPM-Files
|
|
Console.WriteLine("Start copying jpm-files, please wait...");
|
|
FileInfo fi = new FileInfo(csvPath);
|
|
FileOperations.CopyJPMFilesToDestination(fi.Directory.FullName, archivNetPath);
|
|
Console.WriteLine("");
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
Console.WriteLine("Done. You may close this window now.");
|
|
|
|
Console.ReadLine();
|
|
|
|
}
|
|
catch (DirectoryNotFoundException)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: source directory not found.");
|
|
Console.ReadLine();
|
|
}
|
|
catch (FileNotFoundException ex)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: "+ex.Message);
|
|
Console.ReadLine();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: unknown error occured. Maybe no csv-File? Please check!\r\n{0}", ex.InnerException);
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
|
|
public static bool CheckFileExist()
|
|
{
|
|
if (File.Exists(Path.Combine(Directory.GetParent(csvPath).FullName, "outputInpro.csv")) || File.Exists(Path.Combine(Directory.GetParent(csvPath).FullName, "outputCM.csv")))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|