-
Notifications
You must be signed in to change notification settings - Fork 1
/
RAN_EM_CustomerEntry.cs
451 lines (365 loc) · 14 KB
/
RAN_EM_CustomerEntry.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
// **************************************************
// Custom code for CustomerEntryForm
// Created: 7/25/2017 12:12:42 PM
// **************************************************
// ECS/NPHAM
// RAN_CustomerEntry_1.2.0 Created: 9/29/2017
// Project: RAN-17-004
// Add Parent Customer
// **************************************************
extern alias Erp_Contracts_BO_Customer;
extern alias Erp_Contracts_BO_BankAcct;
extern alias Erp_Contracts_BO_ShipTo;
extern alias Erp_Adapters_Customer;
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
private EpiBaseAdapter oTrans_customerAdapter;
private static EpiCheckBox activeDistributor;
private static EpiCombo metroArea;
private static EpiCombo primaryLineVE;
private static EpiCombo countryNum;
private static EpiCombo category;
private static EpiCombo fleetSize;
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
private CustomerAdapter custAdapter;
private EpiDataView custDataView;
private EpiTextBox et_newCustID;
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
this.oTrans_customerAdapter = ((EpiBaseAdapter)(this.csm.TransAdaptersHT["oTrans_customerAdapter"]));
this.custDataView = (EpiDataView)oTrans.EpiDataViews["Customer"];
this.oTrans_customerAdapter.BeforeAdapterMethod += new BeforeAdapterMethod(this.oTrans_customerAdapter_BeforeAdapterMethod);
this.Customer_Column.ColumnChanged += new DataColumnChangeEventHandler(this.Customer_AfterFieldChange);
this.custDataView = ((EpiDataView)(this.oTrans.EpiDataViews["Customer"]));
this.custDataView.EpiViewNotification += new EpiViewNotification(this.custDataView_EpiViewNotification);
this.CustCnt_Column.ColumnChanged += new DataColumnChangeEventHandler(this.CustCnt_AfterFieldChange);
this.CustomerEntryForm.AfterToolClick += new Ice.Lib.Framework.AfterToolClickEventHandler(this.CustomerEntryForm_AfterToolClick);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
this.btnParentCust.Click += new System.EventHandler(this.btnParentCust_Click);
this.btnNextCustID.Click += new System.EventHandler(this.btnNextCustID_Click);
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
this.oTrans_customerAdapter.BeforeAdapterMethod -= new BeforeAdapterMethod(this.oTrans_customerAdapter_BeforeAdapterMethod);
this.oTrans_customerAdapter = null;
this.Customer_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.Customer_AfterFieldChange);
this.btnParentCust.Click -= new System.EventHandler(this.btnParentCust_Click);
this.btnNextCustID.Click -= new System.EventHandler(this.btnNextCustID_Click);
this.custDataView = null;
this.custDataView.EpiViewNotification -= new EpiViewNotification(this.custDataView_EpiViewNotification);
this.CustCnt_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.CustCnt_AfterFieldChange);
this.CustomerEntryForm.AfterToolClick -= new Ice.Lib.Framework.AfterToolClickEventHandler(this.CustomerEntryForm_AfterToolClick);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void oTrans_customerAdapter_BeforeAdapterMethod(object sender, BeforeAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **
// ** Use MessageBox to find adapter method name
// EpiMessageBox.Show(args.MethodName);
string parentcustnum="";
switch (args.MethodName)
{
case "Update":
activeDistributor = ((EpiCheckBox)csm.GetNativeControlReference("4ff5eda0-9888-4703-a1b1-5185e494758e"));
metroArea = ((EpiCombo)csm.GetNativeControlReference("c0355971-9f0a-4126-905a-7d5eca9fb7c5"));
primaryLineVE = ((EpiCombo)csm.GetNativeControlReference("bc535f05-1878-40e0-8c80-ddd3a6d70a0f"));
if(activeDistributor.Checked)
{
if(metroArea.Text.Length == 0 || primaryLineVE.Text.Length == 0)
throw new UIException("Metro Area and Primary Line Van Equip must be filled for an Active distributor.");
}
category = ((EpiCombo)csm.GetNativeControlReference("f76dd0e7-ba1f-4fff-aaec-9cc5e3f15156"));
fleetSize = ((EpiCombo)csm.GetNativeControlReference("8228301d-6ad4-4b54-8834-5a9a50535bf1"));
if(category.Text == "Fleet" && fleetSize .Text.Length == 0)
{
throw new UIException("Fleet size must be filled for Category: Fleet");
}
if (custDataView!=null && custDataView.HasRow)
{
if (custDataView.dataView[custDataView.Row]["ParentCustID_c"].ToString() =="")
{
custDataView.dataView[custDataView.Row]["ParentCustNum_c"] =0;
}
else
{
parentcustnum = GetParentCustNumByCustNum(custDataView.dataView[custDataView.Row]["ParentCustID_c"].ToString());
if (parentcustnum.Length ==0)
{
throw new UIException("Parent Customer ID doesn't exists.");
}
else
{
custDataView.dataView[custDataView.Row]["ParentCustNum_c"] = parentcustnum;
}
}
}
break;
}
}
private void Customer_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case "CreditHold":
//args.Row["LastCreditHold_c"] = System.DateTime.Today;
break;
}
}
private string GetParentCustNumByCustNum(string code)
{
string returnV = "";
try
{
CustomerAdapter adapterCustomer = new CustomerAdapter(this.oTrans);
adapterCustomer.BOConnect();
adapterCustomer.GetByCustID(code,false);
if (adapterCustomer.CustomerData.Customer.Rows.Count == 1)
{
DataRow rRow = adapterCustomer.CustomerData.Customer[adapterCustomer.CustomerData.Customer.Rows.Count-1];
if (rRow!=null )
{
returnV = rRow["CustNum"].ToString();
}
}
adapterCustomer.Dispose();
}
catch (Exception ex)
{
//ExceptionBox.Show(ex);
return "";
}
return returnV;
}
private void CustomerEntryForm_Load(object sender, EventArgs args)
{
SetVersionNumber(this.oTrans.EpiBaseForm);
}
public static void SetVersionNumber(EpiBaseForm frm)
{
if(frm.Text.Contains("Version") == true) return;
string custName = frm.CustomizationName;
string version = "?.?";
int pos = custName.LastIndexOf("_");
if (pos >= 0)
{
version = custName.Substring(pos + 1, custName.Length - pos - 1);
}
frm.Text = String.Format("{0} - Version {1}", frm.Text, version);
}
private void btnParentCust_Click(object sender, System.EventArgs args)
{
// ** Place Event Handling Code Here **
SearchOnCustomerAdapterShowDialog();
}
private void SearchOnCustomerAdapterShowDialog()
{
// Wizard Generated Search Method
// You will need to call this method from another method in custom code
// For example, [Form]_Load or [Button]_Click
bool recSelected;
string whereClause = string.Empty;
System.Data.DataSet dsCustomerAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "CustomerAdapter", out recSelected, true, whereClause);
if (recSelected)
{
System.Data.DataRow adapterRow = dsCustomerAdapter.Tables[0].Rows[0];
// Map Search Fields to Application Fields
EpiDataView custDataView = ((EpiDataView)(this.oTrans.EpiDataViews["Customer"]));
System.Data.DataRow custDataViewRow = custDataView.CurrentDataRow;
if ((custDataViewRow != null))
{
custDataViewRow.BeginEdit();
custDataViewRow["ParentCustNum_c"] = adapterRow["CustNum"];
custDataViewRow["ParentCustID_c"] = adapterRow["CustID"];
custDataViewRow.EndEdit();
}
}
}
private void btnNextCustID_Click(object sender, System.EventArgs args)
{
DialogResult dialogResult = EpiMessageBox.Show("Are you sure you want to get next Cust ID?", "Cancel", MessageBoxButtons.YesNo);
if ((dialogResult == DialogResult.Yes)) {
this.custAdapter = new CustomerAdapter(this.oTrans);
this.custAdapter.BOConnect();
DataRow currentCustomer = this.custDataView.CurrentDataRow;
// Add Prefix
string custID = formatNewID(currentCustomer["Name"].ToString());
// Set Suffix
int custSuffix = 0; // 001
// Iterate until suffix exists with prefix
do {
custSuffix++;
try {
this.custAdapter.GetByCustID(custID + custSuffix.ToString("D3"),false);
}catch(Exception e) {
break;
}
} while(custSuffix < 1000);
// Set new custID
string newCustID = custID + custSuffix.ToString("D3");
//MessageBox.Show("New CustID: " + newCustID);
currentCustomer["CustID"] = newCustID;
/*et_newCustID = ((EpiTextBox)csm.GetNativeControlReference("3a3fffc1-6dee-4be0-b52e-7fc5f80e7b95"));
et_newCustID.Text = newCustID;*/
}
}
/* Format new ID to only contain uppercase letters */
private static string formatNewID(string name) {
string prefix = name;
string cleanPrefix = "";
foreach(Char i in prefix) {
if(Char.IsLetter(i) || Char.IsDigit(i)) {
cleanPrefix = cleanPrefix + i;
}
}
while( cleanPrefix.Length < 3){
cleanPrefix = cleanPrefix + "0";
}
string newPrefix = cleanPrefix.ToUpper().Substring(0,3);
/*
if(Regex.IsMatch(newCustID, @"^[a-zA-Z]+$")) {
return newCustID;
}
*/
return newPrefix;
}
private void custDataView_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
// ** Argument Properties and Uses **
// view.dataView[args.Row]["FieldName"]
// args.Row, args.Column, args.Sender, args.NotifyType
// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
if ((args.NotifyType == EpiTransaction.NotifyType.AddRow))
{
DataRow currentCustomer = this.custDataView.CurrentDataRow;
if(this.custDataView.CurrentDataRow != null){
this.btnNextCustID.Enabled = true;
if(this.custDataView.CurrentDataRow.RowState.ToString() == "Added")
{
this.custDataView.CurrentDataRow["CheckDuplicatePO"] = true;
this.custDataView.CurrentDataRow["WebCustomer"] = true;
this.custDataView.CurrentDataRow["AllowOTS"] = true;
this.custDataView.CurrentDataRow["AllowShipTo3"] = true;
this.custDataView.CurrentDataRow["ECCType"] = "B";
}
}
else{
this.btnNextCustID.Enabled = false;
}
}
else if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
{
GetLeadDistContact();
}
}
private void CustCnt_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
EpiDataView edvCustomer = ((EpiDataView)(this.oTrans.EpiDataViews["Customer"]));
System.Data.DataRow edvCustomerRow = edvCustomer.CurrentDataRow;
string custID = edvCustomerRow["CustID"].ToString();
CustomerAdapter custAdapter = new CustomerAdapter(this.oTrans);
custAdapter.BOConnect();
custAdapter.GetByCustID(custID,false);
DataRow row = custAdapter.CustomerData.Customer[0];
int primB = int.Parse(row["PrimBCon"].ToString());
int primP = int.Parse(row["PrimPCon"].ToString());
int primS = int.Parse(row["PrimSCon"].ToString());
string leadType = "";
bool warning = false;
switch (args.Column.ColumnName)
{
case "PrimaryBilling":
if(primB != 0 && args.ProposedValue.ToString() == "True"){
warning = true;
leadType = "billing";
}
break;
case "PrimaryPurchasing":
if(primP != 0 && args.ProposedValue.ToString() == "True"){
warning = true;
leadType = "purchasing";
}
break;
case "PrimaryShipping":
if(primS != 0 && args.ProposedValue.ToString() == "True"){
warning = true;
leadType = "shipping";
}
break;
}
if(warning)
{
DialogResult dialogResult = EpiMessageBox.Show("There exists another contact for " + leadType + "\nContinue?", "Cancel", MessageBoxButtons.YesNo);
if ((dialogResult == DialogResult.No)) {
oTrans.Undo();
}
}
}
private void GetLeadDistContact()
{
try
{
EpiDataView edvCustomer = ((EpiDataView)(this.oTrans.EpiDataViews["Distributor"]));
DataRow drCustomer = edvCustomer.CurrentDataRow;
if(drCustomer != null)
{
string distNum = drCustomer["CustNum"].ToString();
CustCntAdapter adapterCustCnt = new CustCntAdapter(this.oTrans);
adapterCustCnt.BOConnect();
string whereClause = "CustNum = " + distNum + " AND LeadContact_c = true";
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
opts.NamedSearch.WhereClauses.Add("CustCnt", whereClause);
bool morePages = false;
DataSet dsLeadContact = adapterCustCnt.GetRows(opts, out morePages);
if(dsLeadContact.Tables["CustCnt"].Rows.Count>0)
{
this.LeadDistributorContact.Text = dsLeadContact.Tables["CustCnt"].Rows[0]["Name"].ToString();
}
}
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}
private void CustomerEntryForm_AfterToolClick(object sender, Ice.Lib.Framework.AfterToolClickEventArgs args)
{
if(args.Tool.Key == "ClearTool")
{
this.LeadDistributorContact.ResetText();
}
}
}