-
Notifications
You must be signed in to change notification settings - Fork 1
/
RAN_EM_QtyAdjust.cs
169 lines (139 loc) · 6.68 KB
/
RAN_EM_QtyAdjust.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
// **************************************************
// Custom code for InventoryQtyAdjustForm
// Created: 2/15/2018 7:17:10 AM
// **************************************************
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 EpiDataView edvview;
private EpiDataView edvClient;
private DataView inventoryQtyAdjBrwView_DataView;
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
this.edvview = ((EpiDataView)(this.oTrans.EpiDataViews["view"]));
this.edvClient = ((EpiDataView)(this.oTrans.EpiDataViews["CallContextClientData"]));
this.inventoryQtyAdjBrwView_DataView = this.inventoryQtyAdjBrwView_Row.dataView;
this.inventoryQtyAdjBrwView_DataView.ListChanged += new ListChangedEventHandler(this.inventoryQtyAdjBrwView_DataView_ListChanged);
this.InventoryQtyAdj_Column.ColumnChanged += new DataColumnChangeEventHandler(this.InventoryQtyAdj_AfterFieldChange);
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
// 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.edvview = null;
this.edvClient = null;
this.inventoryQtyAdjBrwView_DataView.ListChanged -= new ListChangedEventHandler(this.inventoryQtyAdjBrwView_DataView_ListChanged);
this.inventoryQtyAdjBrwView_DataView = null;
this.InventoryQtyAdj_Column.ColumnChanged -= new DataColumnChangeEventHandler(this.InventoryQtyAdj_AfterFieldChange);
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void SetCost(string partNum)
{
try
{
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
PartCostSearchAdapter adapterPartCostSearch = new PartCostSearchAdapter(this.oTrans);
adapterPartCostSearch.BOConnect();
// Declare and Initialize Variables
// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
System.Guid guidID = System.Guid.Empty;
// Call Adapter method
string site = edvClient.dataView[edvClient.Row]["CurrentPlant"].ToString();
bool result = adapterPartCostSearch.GetByID(partNum, site);
if(result) {
bool converted = false;
double AvgMaterialCost = 0;
double AvgBurdenCost = 0;
double AvgLaborCost = 0;
double AvgMtlBurCost = 0;
double AvgSubContCost = 0;
converted = double.TryParse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgMaterialCost"].ToString(), out AvgMaterialCost);
converted = double.TryParse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgBurdenCost"].ToString(), out AvgBurdenCost);
converted = double.TryParse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgLaborCost"].ToString(), out AvgLaborCost);
converted = double.TryParse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgMtlBurCost"].ToString(), out AvgMtlBurCost);
converted = double.TryParse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgSubContCost"].ToString(), out AvgSubContCost);
double avgTotal = AvgMaterialCost + AvgBurdenCost + AvgLaborCost + AvgMtlBurCost + AvgSubContCost;
this.UnitCost.Text = avgTotal.ToString("0.##");
/*double avgCost = Double.Parse(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgMaterialCost"].ToString()) ;
// +Convert.ToDouble(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgMaterialCost"].ToString());
this.UnitCost.Text = avgCost.ToString("D2");
MessageBox.Show(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgBurdenCost"].ToString());
MessageBox.Show(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgLaborCost"].ToString());
MessageBox.Show(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgMtlBurCost"].ToString());
MessageBox.Show(adapterPartCostSearch.PartCostSearchData.PartCost.Rows[0]["AvgSubContCost"].ToString());*/
}
// Cleanup Adapter Reference
adapterPartCostSearch.Dispose();
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}
private void SetExtendedCost(string quantity) {
try {
double extCost = Double.Parse(this.UnitCost.Text) * Double.Parse(quantity);
this.ExtendedCost.Text = extCost.ToString();
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}
private void inventoryQtyAdjBrwView_DataView_ListChanged(object sender, ListChangedEventArgs args)
{
// ** Argument Properties and Uses **
// inventoryQtyAdjBrwView_DataView[0]["FieldName"]
// args.ListChangedType, args.NewIndex, args.OldIndex
// ListChangedType.ItemAdded, ListChangedType.ItemChanged, ListChangedType.ItemDeleted, ListChangedType.ItemMoved, ListChangedType.Reset
// Add Event Handler Code
if(edvview != null){
string partNum = edvview.dataView[edvview.Row]["PartNum"].ToString();
string quantity = edvview.dataView[edvview.Row]["AdjustQuantity"].ToString();
SetCost(partNum);
SetExtendedCost(quantity);
}
}
private void InventoryQtyAdj_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row["FieldName"]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
if(edvview != null){
string quantity = edvview.dataView[edvview.Row]["AdjustQuantity"].ToString();
switch (args.Column.ColumnName)
{
case "AdjustQuantity":
SetExtendedCost(quantity);
break;
case "UnitOfMeasure":
SetExtendedCost(quantity);
break;
}
}
}
}