Migracja z NAS do Gitea
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using Soneta.Business;
|
||||
using Soneta.Business.UI;
|
||||
using Soneta.Kadry;
|
||||
using Soneta.Kalend;
|
||||
using Soneta.Tools;
|
||||
using Soneta.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace FX2_SP_WORKERS.ImportRcpCsv
|
||||
{
|
||||
internal class ImportRCPFun
|
||||
{
|
||||
public static MessageBoxInformation Start(Context context, StreamReader streamReader)
|
||||
{
|
||||
string wiersz;
|
||||
string[] listWiersz = new string[4];
|
||||
|
||||
int rowCount = 0;
|
||||
|
||||
using (Session session = context.Login.CreateSession(false, true))
|
||||
{
|
||||
KadryModule kadryModule = KadryModule.GetInstance(session);
|
||||
KalendModule kalendModule = KalendModule.GetInstance(session);
|
||||
|
||||
using (ITransaction transaction = session.Logout(true))
|
||||
{
|
||||
while (!streamReader.EndOfStream)
|
||||
{
|
||||
try
|
||||
{
|
||||
rowCount++;
|
||||
Percent percentProgress = new Percent((decimal)rowCount / streamReader.BaseStream.Length);
|
||||
double progress = Soneta.Tools.Math.Round(((double)rowCount / streamReader.BaseStream.Length) * 100, 0);
|
||||
|
||||
TraceInfo.SetProgressBar(percentProgress);
|
||||
TraceInfo.WriteProgress(progress + "% Importowanie RCP");
|
||||
|
||||
listWiersz[0] = listWiersz[1] = listWiersz[2] = listWiersz[3] = null;
|
||||
wiersz = streamReader.ReadLineAsync().Result;
|
||||
listWiersz = wiersz.Split(';');
|
||||
|
||||
if (listWiersz.Length < 4)
|
||||
continue;
|
||||
|
||||
if (listWiersz[0] == null || listWiersz[1] == null || listWiersz[2] == null || listWiersz[3] == null)
|
||||
throw new Exception($"Brak danych przy wpisie: {listWiersz[0]}, {listWiersz[1]}, {listWiersz[2]}, {listWiersz[3]}");
|
||||
|
||||
Pracownik p = kadryModule.Pracownicy.WgKodu[listWiersz[0]];
|
||||
|
||||
if (p is null)
|
||||
throw new Exception("Nie znaleziono pracownika o kodzie: " + listWiersz[0]);
|
||||
|
||||
WejscieWyjscieI wwNew = new WejscieWyjscieI(p);
|
||||
kalendModule.WejsciaWyjsciaI.AddRow(wwNew);
|
||||
wwNew.Data = Date.Parse(listWiersz[1]);
|
||||
wwNew.Godzina = Time.Parse(listWiersz[2]);
|
||||
wwNew.Features["ZKT_TypOdbicia"] = listWiersz[3];
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Błąd podczas importu danych przy wpisie:\n" +
|
||||
$" {rowCount} |\t {listWiersz[0]}, {listWiersz[1]}, {listWiersz[2]}, {listWiersz[3]}\n\n{e.Message}");
|
||||
}
|
||||
}
|
||||
transaction.CommitUI();
|
||||
}
|
||||
session.Save();
|
||||
}
|
||||
|
||||
return new MessageBoxInformation("Import RCP")
|
||||
{
|
||||
Type = MessageBoxInformationType.Information,
|
||||
Text = $"Import wykonany pomyślnie dla {rowCount} wpisów",
|
||||
OKHandler = () => null
|
||||
};
|
||||
}
|
||||
|
||||
public static bool Visible(Context cx)
|
||||
{
|
||||
return cx.Login.Database.Name.ToUpper().Contains("WSCHODNI FRONT");
|
||||
}
|
||||
|
||||
public static bool Enabled(Context cx)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user