This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenText.cs
executable file
·251 lines (224 loc) · 7.47 KB
/
OpenText.cs
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
using Mind2Biz.DM.ClientMatter;
using System;
using System.Collections.Generic;
using System.Text;
namespace soti
{
public class OpenText
{
public Mind2Biz.DM.ClientMatter.Manager manager;
private const string ERROR_DUPLICATE = "Cannot insert duplicate key";
private const string ERROR_MISSING_CLIENT = "Client record couldn't be found in Database";
private const string ERROR_MISSING_MATTER = "Matter record couldn't be found in Database";
public OpenText()
{
}
public void connect()
{
if (Program.settings.otUsername != null && Program.settings.otUsername.Trim().Length > 0)
{
manager = new Manager(Program.settings.otServer, Program.settings.otDatabase, Program.settings.otUsername, Program.settings.otPassword);
}
else
{
manager = new Manager(Program.settings.otServer, Program.settings.otDatabase);
}
}
public void setMasterData(Sapservice.ZLAW_I_GET_MASTER_DATAResponse Res)
{
for (int n = 0; n < Res.E_CUSTOMERS.Length; n++)
{
switch (Res.E_CUSTOMERS[n].ACTIO)
{
case "I":
createClient(Res.E_CUSTOMERS[n]);
break;
case "U":
updateClient(Res.E_CUSTOMERS[n]);
break;
case "D":
deleteClient(Res.E_CUSTOMERS[n]);
break;
}
}
for (int n = 0; n < Res.E_MATTERS.Length; n++)
{
switch (Res.E_MATTERS[n].ACTIO)
{
case "I":
createMatter(Res.E_MATTERS[n]);
break;
case "U":
updateMatter(Res.E_MATTERS[n]);
break;
case "D":
deleteMatter(Res.E_MATTERS[n]);
break;
}
}
Program.sap.setMasterDataTransferred(Res);
}
private void createClient(soti.Sapservice.ZLAW_S_CUSTOMERI C)
{
try
{
manager.CreateClient(C.KUNNR, C.NAME1);
}
catch (Exception ex)
{
if (isClientDuplicate(ex)) return;
appendErrorObjectToLog(C, "Update");
throw ex;
}
}
private void updateClient(soti.Sapservice.ZLAW_S_CUSTOMERI C)
{
try
{
manager.UpdateClientName(C.KUNNR, C.NAME1);
}
catch (Exception ex)
{
if (isClientMissing(ex))
{
createClient(C);
return;
}
appendErrorObjectToLog(C, "Update");
throw ex;
}
}
private void deleteClient(soti.Sapservice.ZLAW_S_CUSTOMERI C)
{
try
{
manager.DeleteClient(C.KUNNR);
}
catch (Exception ex)
{
appendErrorObjectToLog(C, "Delete");
}
}
private void createMatter(soti.Sapservice.ZLAW_S_MATTERI M)
{
try
{
manager.CreateMatter(M.MATNO, M.MATNM, M.KUNNR);
}
catch (Exception ex)
{
if (isMatterDuplicate(ex))
{
updateMatter(M);
return;
}
if (isClientMissing(ex))
{
createClient(extractClientFromMatter(M));
createMatter(M);
return;
}
appendErrorObjectToLog(M, "Update");
throw ex;
}
}
private void updateMatter(soti.Sapservice.ZLAW_S_MATTERI M)
{
try
{
manager.UpdateClientOfMatter(M.MATNO, M.KUNNR);
}
catch (Mind2Biz.DM.ClientMatter.DuplicatedRecordException)
{
// Buraya düþtüysek, aslýnda herþey yolundadýr
}
catch (Exception ex)
{
if (isMatterMissing(ex))
{
createMatter(M);
}
else if (isClientMissing(ex))
{
createClient(extractClientFromMatter(M));
updateMatter(M);
}
else
{
appendErrorObjectToLog(M, "Update");
throw ex;
}
}
try
{
manager.UpdateMatterName(M.MATNO, M.MATNM);
}
catch (Exception ex)
{
if (isMatterMissing(ex))
{
createMatter(M);
}
else if (isClientMissing(ex))
{
createClient(extractClientFromMatter(M));
updateMatter(M);
}
else
{
appendErrorObjectToLog(M, "Update");
throw ex;
}
}
}
private void deleteMatter(soti.Sapservice.ZLAW_S_MATTERI M)
{
try
{
manager.DeleteMatter(M.MATNO);
}
catch (Exception ex)
{
appendErrorObjectToLog(M, "Delete");
}
}
private bool isClientMissing(Exception E)
{
return E.ToString().IndexOf(ERROR_MISSING_CLIENT) >= 0;
}
private bool isClientDuplicate(Exception E)
{
return E.ToString().IndexOf(ERROR_DUPLICATE) >= 0;
}
private bool isMatterMissing(Exception E)
{
return E.ToString().IndexOf(ERROR_MISSING_MATTER) >= 0;
}
private bool isMatterDuplicate(Exception E)
{
return E.ToString().IndexOf(ERROR_DUPLICATE) >= 0;
}
private soti.Sapservice.ZLAW_S_CUSTOMERI extractClientFromMatter(soti.Sapservice.ZLAW_S_MATTERI M)
{
soti.Sapservice.ZLAW_S_CUSTOMERI c = new soti.Sapservice.ZLAW_S_CUSTOMERI();
c.ACTIO = "I";
c.KUNNR = M.KUNNR;
c.NAME1 = M.NAME1;
c.ONAM1 = M.ONAM1;
c.ONAM2 = M.ONAM2;
return c;
}
private void appendErrorObjectToLog(soti.Sapservice.ZLAW_S_CUSTOMERI C, string Operation)
{
appendErrorObjectToLog("Customer", C.KUNNR, C.NAME1, Operation);
}
private void appendErrorObjectToLog(soti.Sapservice.ZLAW_S_MATTERI M, string Operation)
{
appendErrorObjectToLog("Matter", M.MATNO, M.MATNM, Operation);
}
private void appendErrorObjectToLog(string ObjectType, string Key, string Text, string Operation)
{
Program.appendLog(Operation + " error for " + ObjectType + " " + Key + " - " + Text + ": ");
}
}
}