-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHydraCallback.cs
More file actions
141 lines (111 loc) · 5.26 KB
/
Copy pathHydraCallback.cs
File metadata and controls
141 lines (111 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using Hydra;
using HydraAcceptKSeFInvoice.Data;
using HydraAcceptKSeFInvoice.Data.Enums;
using HydraAcceptKSeFInvoice.Repositories;
using HydraAcceptKSeFInvoice.Views;
using HydraDimentionsBoxes.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
[assembly: CallbackAssemblyDescription("Akceptacja dokumentu z KSeF",
"Akceptacja dokumentu z KSeF",
"Krzysztof Kurowski",
"1.0",
"8.0",
"12-03-2026")]
namespace HydraAcceptKSeFInvoice
{
[SubscribeProcedure((Procedures)Procedures.KSFEdycja, "callback na edycji dokumentu z KSeF")]
public class HydraCallback : Callback
{
private ClaWindow Parent;
private ClaWindow ButtonParent;
private ClaWindow Button;
private ClaWindow QualificationComboBox;
private ClaWindow DiscardCheckBox;
private ClaWindow DescriptionTextBox;
private KSeFRepository _ksefRepository;
private OperatorRepository _operatorRepository;
private AcceptationResult _lastResult;
public override void Init()
{
_ksefRepository = new KSeFRepository(Runtime.ActiveRuntime.Repository.Connection.Database);
_operatorRepository = new OperatorRepository(Runtime.ActiveRuntime.Repository.Connection.Database);
AddSubscription(true, 0, Events.OpenWindow, new TakeEventDelegate(OnOpenWindow));
AddSubscription(false, 0, Events.ResizeWindow, new TakeEventDelegate(ChangeWindow));
}
public bool OnOpenWindow(Procedures ProcId, int ControlId, Events Event)
{
Parent = GetWindow();
QualificationComboBox = Parent.Children["?cKwalifikacja"];
DiscardCheckBox = Parent.Children["?KSF:Odrzucony"];
DescriptionTextBox = Parent.Children["?KSF:Opis"];
ButtonParent = Parent.AllChildren["?ZlaczZDok"];
Button = Parent.Children["?Ogolne"].Children.Add(ControlTypes.button);
Button.Visible = true;
Button.Enabled = true;
Button.IconRaw = GetButtonIcon();
Button.Bounds = new System.Drawing.Rectangle(Convert.ToInt32(ButtonParent.XposRaw), Convert.ToInt32(ButtonParent.YposRaw) - 150, 15, 15);
AddSubscription(false, Button.Id, Events.Accepted, new TakeEventDelegate(Button_OnAfterMouseDown));
return true;
}
public bool ChangeWindow(Procedures ProcId, int ControlId, Events Event)
{
Button.Bounds = new System.Drawing.Rectangle(Convert.ToInt32(ButtonParent.XposRaw), Convert.ToInt32(ButtonParent.YposRaw) - 150, 15, 15);
return true;
}
private string GetButtonIcon()
{
var acceptationStatus = _ksefRepository.GetAcceptationStatus((int)KSeFDokumenty.KSF_ID);
switch (acceptationStatus)
{
case AcceptationStatus.Accepted:
return "//Backup/k/Dodatki/Ikony/green-dot.ico";
case AcceptationStatus.PartiallyAccepted:
return "//Backup/k/Dodatki/Ikony/yellow-dot.ico";
case AcceptationStatus.NotAccepted:
return "//Backup/k/Dodatki/Ikony/red-dot.ico";
default:
return "";
}
}
public bool Button_OnAfterMouseDown(Procedures ProcedureId, int ControlId, Events Event)
{
try
{
Qualification qualification = (Qualification)int.Parse(QualificationComboBox.SelectedRaw);
bool rejected = Convert.ToBoolean(int.Parse(DiscardCheckBox.UseRaw));
string description = DescriptionTextBox.TextRaw;
int documentId = (int)KSeFDokumenty.KSF_ID;
int workerId = _operatorRepository.GetWorkerId(Runtime.Config.NumerOperatora);
var acceptations = _ksefRepository.GetAcceptations(documentId);
var mainWindow = new MainWindow(documentId, qualification, rejected, workerId, description, acceptations);
if (mainWindow.ShowDialog() == true)
{
var result = mainWindow.Result;
Runtime.WindowController.Change(DiscardCheckBox.Id, Convert.ToInt32(result.IsRejected).ToString());
Runtime.WindowController.PostEvent(DiscardCheckBox.Id, Events.Accepted);
Runtime.WindowController.Change(QualificationComboBox.Id, result.Qualification.GetDescription());
Runtime.WindowController.PostEvent(QualificationComboBox.Id, Events.Accepted);
Runtime.WindowController.Change(DescriptionTextBox.Id, result.Description);
Runtime.WindowController.PostEvent(DescriptionTextBox.Id, Events.Accepted);
_ksefRepository.UpdateAcceptaions(result.AcceptationUpdates.ToList());
Button.BackgroundRaw = GetButtonIcon();
}
}
catch (Exception ex)
{
MessageBox.Show("Błąd: " + ex.Message);
}
Runtime.WindowController.PostEvent(0, Events.FullRefresh);
return true;
}
public override void Cleanup()
{
}
}
}