· 8 years ago · Jan 12, 2018, 05:06 PM
1// 6.5 Regrouped methods into region and cleaned up code for readability
2 // 6.4 Add White Diamond and Pink Glitter as colors
3 // 6.3 Changing 10103R/N colors and filters to match 10008N/R
4 // 6.2 PO Required work
5 // 6.1 Shrunk Summary fields on main page
6 // 6.0 Ensuring all MessageBox.Show give verbose Messages
7 // 5.9 Moved FitTech box and label Drop
8 // -If partnum changes, verify that the selected colour and filters are valid. If not, clear the value and notify the user.
9 // -PEU PO Num changed label to PEUS and make it disappear unless company = 200 and customer = 250
10 // 5.8 Fixing Person Contact Update not refreshing properly
11
12 // ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
13 // Begin Wizard Added Module Level Variables **
14 EpiDataView edvOrderDtl;
15 EpiBaseAdapter oTrans_ordAdapter;
16 EpiDataView edvOrderRel;
17 EpiDataView edvOrderHed;
18 // End Wizard Added Module Level Variables **
19 Hashtable m_hashCopyColumns;
20 // Add Custom Module Level Variables Here **
21 //DataTable m_dtDropDownTable;
22 bool m_copying;
23 ContactSearch m_ContactSearch;
24 ContactSearch m_CastSearch;
25 string m_custID;
26 int m_custNum;
27 string m_version;
28 string m_shipToNum;
29 string m_targetCompany;
30 string m_sysConfigFile;
31 string m_userName;
32 string m_passWord;
33 Session m_targetSession;
34 readonly string SQLServer = "CPE-ERPSQL";
35 readonly string SQLUser = "EpicorViews";
36 readonly string SQLPass = "Ep1c0rViews";
37 readonly string Database = "erp1016CRP";
38
39 public void InitializeCustomCode() {
40 // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
41 // Begin Wizard Added Variable Initialization
42 edvOrderDtl = (EpiDataView)oTrans.EpiDataViews["OrderDtl"];
43 edvOrderDtl.EpiViewNotification += edvOrderDtl_EpiViewNotification;
44 OrderDtl_Column.ColumnChanged += OrderDtl_AfterFieldChange;
45 oTrans_ordAdapter = (EpiBaseAdapter)csm.TransAdaptersHT["oTrans_ordAdapter"];
46 oTrans_ordAdapter.BeforeAdapterMethod += oTrans_ordAdapter_BeforeAdapterMethod;
47 OrderHed_Column.ColumnChanged += OrderHed_AfterFieldChange;
48 edvOrderRel = (EpiDataView)oTrans.EpiDataViews["OrderRel"];
49 OrderHed_Column.ColumnChanging += OrderHed_BeforeFieldChange;
50 edvOrderHed = (EpiDataView)oTrans.EpiDataViews["OrderHed"];
51 edvOrderHed.EpiViewNotification += edvOrderHed_EpiViewNotification;
52 oTrans_ordAdapter.AfterAdapterMethod += oTrans_ordAdapter_AfterAdapterMethod;
53 // End Wizard Added Variable Initialization
54 m_custID = "";
55 m_version = "6.5";
56 // Begin Wizard Added Custom Method Calls
57
58 btnSelectContact.Click += btnSelectContact_Click;
59 btnCreateNewContact.Click += btnCreateNewContact_Click;
60 SetExtendedProperties();
61 grdDtlList.BeforeRowInsert += grdDtlList_BeforeRowInsert;
62 grdDtlList.ClickCellButton += grdDtlList_ClickCellButton;
63 grdDtlList.CellChange += grdDtlList_CellChange;
64 cmbSearchType.ValueChanged += cmbSearchType_ValueChanged;
65 btnRefreshContact.Click += btnRefreshContact_Click;
66 // End Wizard Added Custom Method Calls
67
68 m_copying = false;
69 m_custNum = 0;
70 m_shipToNum = "";
71
72 m_targetCompany = "200";
73
74 //ENV
75 //m_sysConfigFile = @"\\cpe-erp\ERP10.1.600.0Deployment\Client\Config\erp1016production.sysconfig";
76 m_sysConfigFile = @"\\cpe-erp\ERP10.1.600.0Deployment\Client\Config\erp1016crp.sysconfig";
77 m_userName = "CANADAONLY";
78 m_passWord = "Epicor";
79 m_targetSession = null;
80 m_targetSession = new Session(m_userName, m_passWord, Session.LicenseType.EnterpriseProcessing, m_sysConfigFile);
81 }
82
83 public void DestroyCustomCode() {
84 // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
85 // Begin Wizard Added Object Disposal
86 btnSelectContact.Click -= btnSelectContact_Click;
87 btnCreateNewContact.Click -= btnCreateNewContact_Click;
88 edvOrderDtl.EpiViewNotification -= edvOrderDtl_EpiViewNotification;
89 edvOrderDtl = null;
90 OrderDtl_Column.ColumnChanged -= OrderDtl_AfterFieldChange;
91 grdDtlList.BeforeRowInsert -= grdDtlList_BeforeRowInsert;
92 oTrans_ordAdapter.BeforeAdapterMethod -= oTrans_ordAdapter_BeforeAdapterMethod;
93 oTrans_ordAdapter = null;
94 grdDtlList.ClickCellButton -= grdDtlList_ClickCellButton;
95 grdDtlList.CellChange -= grdDtlList_CellChange;
96 OrderHed_Column.ColumnChanged -= OrderHed_AfterFieldChange;
97 edvOrderRel = null;
98 OrderHed_Column.ColumnChanging -= OrderHed_BeforeFieldChange;
99 cmbSearchType.ValueChanged -= cmbSearchType_ValueChanged;
100 edvOrderHed.EpiViewNotification -= edvOrderHed_EpiViewNotification;
101 edvOrderHed = null;
102 oTrans_ordAdapter.AfterAdapterMethod -= oTrans_ordAdapter_AfterAdapterMethod;
103 btnRefreshContact.Click -= btnRefreshContact_Click;
104 // End Wizard Added Object Disposal
105 // Begin Custom Code Disposal
106 new Thread(() => {
107 Thread.CurrentThread.IsBackground = true;
108 /* run your code here */
109 Thread.Sleep(3000);
110 if (m_targetSession==null)
111 return;
112 m_targetSession.Dispose();
113 m_targetSession = null;
114 }).Start();
115 // End Custom Code Disposal
116 }
117
118 void DebugMsg(Exception e) {
119 MessageBox.Show(string.Format("Error: {0}{1}At: {2}", e.Message, Environment.NewLine, e.StackTrace));
120 }
121
122 #region UI Event Handlers
123 void SalesOrderForm_Load(object sender, EventArgs args) {
124 txtCustomerComments.Dock = DockStyle.Fill;
125 try {
126 SetHeaderPriceListDropDown(0, "");
127 m_hashCopyColumns = new Hashtable();
128 string[] columns = {
129 "BoxNumber_c", "OpportunityNum_c", "PartNum", "SellingQuantity", "SalesUM", "PerConFirstName_c", "PerConLastName_c", "PerConDOB_c", "PerConID_c", "EmployeeNum_c",
130 "DocUnitPrice", "Colour_c", "Filter_c", "CPE_MouldRight_c", "CPE_MouldLeft_c", "CPE_Cast_c", "PerCon_c", "PerConCorpName_c"
131 };
132 foreach (var column in columns)
133 m_hashCopyColumns.Add(column.ToLower(), 0);
134 m_ContactSearch = new ContactSearch("Person // Contact");
135
136 m_ContactSearch.Icon = SalesOrderForm.Icon;
137
138 m_CastSearch = new ContactSearch("Cast Number");
139 m_CastSearch.Icon = SalesOrderForm.Icon;
140 } catch (Exception ex) {
141 MessageBox.Show("SalesOrderForm_Load1 error: "+ex.Message);
142 }
143
144 SetVersionNumber();
145 grdDtlList.Dock = DockStyle.Fill;
146 SetGridDropDown(grdDtlList, "SalesUM", "CPEUOM");
147
148 var dtSearch = new DataTable();
149 dtSearch.Columns.Add("Value");
150 dtSearch.Columns.Add("Display");
151 var newRow = dtSearch.NewRow();
152 newRow["Value"] = "Auto3";
153 newRow["Display"] = "3 Character Last Name Auto Search";
154 dtSearch.Rows.Add(newRow);
155 newRow = dtSearch.NewRow();
156 newRow["Value"] = "GridButton";
157 newRow["Display"] = "Button Click Search";
158 dtSearch.Rows.Add(newRow);
159 cmbSearchType.DataSource = dtSearch;
160 cmbSearchType.ValueMember = "Value";
161 cmbSearchType.DisplayMember = "Display";
162 cmbSearchType.Value = "GridButton";
163 grdDtlList.DisplayLayout.Bands[0].Columns["Search_c"].Hidden = false;
164
165 try {
166 grdDtlList.DisplayLayout.Bands[0].Columns["Copy_c"].Style = ColumnStyle.Button;
167 grdDtlList.DisplayLayout.Bands[0].Columns["Copy_c"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
168
169 grdDtlList.DisplayLayout.Bands[0].Columns["Search_c"].Style = ColumnStyle.Button;
170 grdDtlList.DisplayLayout.Bands[0].Columns["Search_c"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
171
172 grdDtlList.DisplayLayout.Bands[0].Columns["New_c"].Style = ColumnStyle.Button;
173 grdDtlList.DisplayLayout.Bands[0].Columns["New_c"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
174
175 grdDtlList.DisplayLayout.Bands[0].Columns["CPE_Cast_c"].Style = ColumnStyle.Button;
176 grdDtlList.DisplayLayout.Bands[0].Columns["CPE_Cast_c"].ButtonDisplayStyle = ButtonDisplayStyle.Always;
177
178 grdDtlList.DisplayLayout.Bands[0].Override.ButtonStyle = UIElementButtonStyle.Button3D;
179 //grdDtlList.DisplayLayout.Bands[0].Columns["Search"].Header.VisiblePosition = 6;
180 } catch (Exception ex) {
181 MessageBox.Show("SalesOrderForm_Load2 error: "+ex.Message);
182 }
183 }
184
185 void btnSelectContact_Click(object sender, EventArgs args) {
186 //MessageBox.Show("btnSelectContact_Click");
187 var select =
188 " select PerConID as PerConID, FirstName, LastName, DOB_c as DOB, EmployeeNum_c as EmployeeNum, CorpName as Company, Comment," +
189 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
190 " '1' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '3' "+
191 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
192 " '5' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '7' "+
193 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
194 " '9' " +" else "+" '' "+" end as RightMould, "+
195 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
196 " '2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '4' "+
197 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
198 " '6' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '8' "+
199 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
200 " '10' " +" else "+" '' "+" end as LeftMould, "+
201 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
202 " plo.lotnum + '1-2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+
203 " plo.lotnum + '3-4' " +
204 " when plo.percon_5_6_c = dbo.percon.PerConID then " +" plo.lotnum + '5-6' "+
205 " when plo.percon_7_8_c = dbo.percon.PerConID then " +
206 " plo.lotnum + '7-8' " +" when plo.percon_9_10_c = dbo.percon.PerConID then "+
207 " plo.lotnum + '9-10' " +
208 " else " +" '' "+" end as SerialNo"+
209 " , case when plo.percon_1_2_c = dbo.percon.PerConID then " +
210 " plo.PerCon_1_2_Notes_c " +
211 " when plo.percon_3_4_c = dbo.percon.PerConID then " +" plo.PerCon_3_4_Notes_c "+
212 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
213 " plo.PerCon_5_6_Notes_c " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+
214 " plo.PerCon_7_8_Notes_c " +
215 " when plo.percon_9_10_c = dbo.percon.PerConID then " +" plo.PerCon_9_10_Notes_c "+" else "+" '' "+
216 " end " +
217 " as Notes, " +
218 " plo.ExpirationDate as ExpirationDate, " +" plo.lotnum as ExistingCast "+" from dbo.percon with (nolock) "+
219 " left outer join dbo.partlot as plo on plo.company = dbo.percon.company and plo.ExpirationDate > GetDate() and ( plo.percon_1_2_c = PerConID or plo.percon_3_4_c = PerConID or plo.percon_5_6_c = PerConID or plo.percon_7_8_c = PerConID or plo.percon_9_10_c = PerConID) "+
220 " where dbo.percon.company = '" +
221 ((Session)oTrans.Session).CompanyID +"' order by dbo.percon.perconid, ExistingCast ";
222
223 if (((Session)oTrans.Session).CompanyID!="200")
224 select = " select pc.PerConID as PerConID, pc.FirstName, pc.LastName, pc.DOB_c as DOB, pc.EmployeeNum_c as EmployeeNum, pc.Comment, pc.CorpName as Company, "+
225 " case when pl.percon_1_2_c = gpc.PerConID then " +
226 " '1' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '3' "+
227 " when pl.percon_5_6_c = gpc.PerConID then " +
228 " '5' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '7' "+
229 " when pl.percon_9_10_c = gpc.PerConID then " +
230 " '9' " +" else "+" '' "+" end as RightMould, "+
231 " case when pl.percon_1_2_c = gpc.PerConID then " +
232 " '2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '4' "+
233 " when pl.percon_5_6_c = gpc.PerConID then " +
234 " '6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '8' "+
235 " when pl.percon_9_10_c = gpc.PerConID then " +
236 " '10' " +" else "+" '' "+" end as LeftMould, "+
237 " case when pl.percon_1_2_c = gpc.PerConID then " +
238 " pl.lotnum + '1-2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" pl.lotnum + '3-4' "+
239 " when pl.percon_5_6_c = gpc.PerConID then " +
240 " pl.lotnum + '5-6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" pl.lotnum + '7-8' "+
241 " when pl.percon_9_10_c = gpc.PerConID then " +
242 " pl.lotnum + '9-10' " +" else "+" '' "+
243 " end as SerialNo, " +
244 " case when pl.percon_1_2_c = gpc.PerConID then " +
245 " pl.PerCon_1_2_Notes_c " +" when pl.percon_3_4_c = gpc.PerConID then "+
246 " pl.PerCon_3_4_Notes_c " +
247 " when pl.percon_5_6_c = gpc.PerConID then " +" pl.PerCon_5_6_Notes_c "+
248 " when pl.percon_7_8_c = gpc.PerConID then " +
249 " pl.PerCon_7_8_Notes_c " +" when pl.percon_9_10_c = gpc.PerConID then "+
250 " pl.PerCon_9_10_Notes_c " +
251 " else " +" '' "+" end as Notes , "+
252 " pl.ExpirationDate as ExpirationDate, " +
253 " pl.lotnum as ExistingCast " +
254 " from dbo.percon as pc with (nolock) " +
255 " join erp.glbpercon as gpc on '200' = gpc.company and gpc.GlbCompany = '" +
256 ((Session)oTrans.Session).CompanyID +
257 "' and gpc.glbperconid = pc.perconid " +
258 " left outer join dbo.PartLot as pl with (nolock)on pl.company = gpc.company and ( pl.percon_1_2_c = gpc.PerConID or " +
259 " pl.percon_3_4_c = gpc.PerConID or pl.percon_5_6_c = gpc.PerConID or pl.percon_7_8_c = gpc.PerConID or pl.percon_9_10_c = gpc.PerConID) " +
260 " where pc.company = '" +
261 ((Session)oTrans.Session).CompanyID +"' order by pc.perconid, pl.lotnum";
262 //MessageBox.Show("262");
263 txtQuery.Text += "262***********************************************262\n\n"+select;
264 LaunchSearch(select);
265 }
266
267 void btnCreateNewContact_Click(object sender, EventArgs args) {
268 if (CheckContactExists(txtFirstName.Text.Trim(), epiTextBoxC4.Text.Trim(), epiDateTimeEditorC1.Value)==false) {
269 CreateNewContact(txtFirstName.Text.Trim(), epiTextBoxC4.Text.Trim(), epiDateTimeEditorC1.Value, txtEmpNum.Text,
270 Convert.ToString(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustomerName"]),
271 Convert.ToInt32(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustNum"]));
272 } else {
273 txtFirstName.Text = "";
274 epiTextBoxC4.Text = "";
275 epiDateTimeEditorC1.Value = null;
276 }
277 }
278
279 void btnRefreshContact_Click(object sender, EventArgs args) {
280 var select =
281 " select PerConID as PerConID, FirstName, LastName, DOB_c as DOB, EmployeeNum_c as EmployeeNum, CorpName as Company, Comment," +
282 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
283 " '1' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '3' "+
284 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
285 " '5' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '7' "+
286 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
287 " '9' " +" else "+" '' "+" end as RightMould, "+
288 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
289 " '2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '4' "+
290 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
291 " '6' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '8' "+
292 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
293 " '10' " +" else "+" '' "+" end as LeftMould, "+
294 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
295 " plo.lotnum + '1-2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+
296 " plo.lotnum + '3-4' " +
297 " when plo.percon_5_6_c = dbo.percon.PerConID then " +" plo.lotnum + '5-6' "+
298 " when plo.percon_7_8_c = dbo.percon.PerConID then " +
299 " plo.lotnum + '7-8' " +" when plo.percon_9_10_c = dbo.percon.PerConID then "+
300 " plo.lotnum + '9-10' " +
301 " else " +" '' "+" end as SerialNo"+
302 " , case when plo.percon_1_2_c = dbo.percon.PerConID then " +
303 " plo.PerCon_1_2_Notes_c " +
304 " when plo.percon_3_4_c = dbo.percon.PerConID then " +" plo.PerCon_3_4_Notes_c "+
305 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
306 " plo.PerCon_5_6_Notes_c " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+
307 " plo.PerCon_7_8_Notes_c " +
308 " when plo.percon_9_10_c = dbo.percon.PerConID then " +" plo.PerCon_9_10_Notes_c "+" else "+" '' "+
309 " end " +
310 " as Notes, " +
311 " plo.ExpirationDate as ExpirationDate, " +" plo.lotnum as ExistingCast "+" from dbo.percon with (nolock) "+
312 " left outer join dbo.partlot as plo on plo.company = dbo.percon.company and plo.ExpirationDate > GetDate() and ( plo.percon_1_2_c = PerConID or plo.percon_3_4_c = PerConID or plo.percon_5_6_c = PerConID or plo.percon_7_8_c = PerConID or plo.percon_9_10_c = PerConID) "+
313 " where dbo.percon.company = '" +
314 ((Session)oTrans.Session).CompanyID +"' and dbo.percon.PerConId = "+
315 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]
316 ["PerCon_c"]+
317 " order by dbo.percon.perconid, ExistingCast ";
318
319 if (((Session)oTrans.Session).CompanyID!="200")
320 select =
321 " select pc.PerConID as PerConID, pc.FirstName, pc.LastName, pc.DOB_c as DOB, pc.EmployeeNum_c as EmployeeNum, pc.CorpName as Company, " +
322 " case when pl.percon_1_2_c = gpc.PerConID then " +
323 " '1' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '3' "+
324 " when pl.percon_5_6_c = gpc.PerConID then " +
325 " '5' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '7' "+
326 " when pl.percon_9_10_c = gpc.PerConID then " +
327 " '9' " +" else "+" '' "+" end as RightMould, "+
328 " case when pl.percon_1_2_c = gpc.PerConID then " +
329 " '2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '4' "+
330 " when pl.percon_5_6_c = gpc.PerConID then " +
331 " '6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '8' "+
332 " when pl.percon_9_10_c = gpc.PerConID then " +
333 " '10' " +" else "+" '' "+" end as LeftMould, "+
334 " case when pl.percon_1_2_c = gpc.PerConID then " +
335 " pl.lotnum + '1-2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" pl.lotnum + '3-4' "+
336 " when pl.percon_5_6_c = gpc.PerConID then " +
337 " pl.lotnum + '5-6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" pl.lotnum + '7-8' "+
338 " when pl.percon_9_10_c = gpc.PerConID then " +
339 " pl.lotnum + '9-10' " +" else "+" '' "+" end as SerialNo, "+
340 " case when pl.percon_1_2_c = gpc.PerConID then " +
341 " pl.PerCon_1_2_Notes_c " +" when pl.percon_3_4_c = gpc.PerConID then "+
342 " pl.PerCon_3_4_Notes_c " +
343 " when pl.percon_5_6_c = gpc.PerConID then " +" pl.PerCon_5_6_Notes_c "+
344 " when pl.percon_7_8_c = gpc.PerConID then " +
345 " pl.PerCon_7_8_Notes_c " +" when pl.percon_9_10_c = gpc.PerConID then "+
346 " pl.PerCon_9_10_Notes_c " +
347 " else " +" '' "+" end as Notes , "+
348 " pl.ExpirationDate as ExpirationDate, " +
349 " pl.lotnum as ExistingCast " +
350 " from dbo.percon as pc with (nolock) " +
351 " join erp.glbpercon as gpc on '200' = gpc.company and gpc.GlbCompany = '" +
352 ((Session)oTrans.Session).CompanyID +
353 "' and gpc.glbperconid = pc.perconid " +
354 " left outer join dbo.PartLot as pl with (nolock)on pl.company = gpc.company and pl.expirationdate > Getdate() and ( (pl.percon_1_2_c = gpc.PerConID and gpc.perconid > 0 ) or " +
355 " (pl.percon_3_4_c = gpc.PerConID and gpc.perconid > 0 ) or (pl.percon_5_6_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_7_8_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_9_10_c = gpc.PerConID and gpc.perconid > 0 ) ) "+
356 " where pc.company = '" +
357 ((Session)oTrans.Session).CompanyID +"' and pc.PerConId = "+edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"]+
358 " order by pc.perconid, pl.lotnum";
359
360 // MessageBox.Show("2511");
361 // txtQuery.Text += "2511***********************************************2511\n\n" + select;
362 LaunchSearch(select, true);
363 }
364
365 void cmbSearchType_ValueChanged(object sender, EventArgs args) {
366 try {
367 grdDtlList.DisplayLayout.Bands[0].Columns["Search_c"].Hidden = cmbSearchType.Value.ToString()=="Auto3";
368 } catch (Exception ex) {
369 DebugMsg(ex);
370 }
371 }
372
373 void grdDtlList_BeforeRowInsert(object sender, BeforeRowInsertEventArgs args) {
374 // Event handling code generated by wizard.
375 args.Cancel = true;
376 oTrans.SetCurrentEvent(TransactionEvent.AddNewOnNewFromGrid);
377 try {
378 oTrans.GetNewOrderDtl();
379 } catch (Exception ex) {
380 DebugMsg(ex);
381 }
382 }
383
384 void grdDtlList_ClickCellButton(object sender, CellEventArgs args) {
385 if (args.Cell.Column.Key=="Copy_c") {
386 CopyFromPrevious(true);
387 } else if (args.Cell.Column.Key=="New_c") {
388 CopyFromPrevious(false);
389 } else if (args.Cell.Column.Key=="CPE_Cast_c") {
390 if (!edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PartNum"].ToString().EndsWith("R"))
391 return;
392 var select = "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', " +
393 " case when PerCon_1_2_c = " +
394 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
395 " then '1' when PerCon_3_4_c = " +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"]+
396 " then '3' when PerCon_5_6_c = " +
397 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +" then '5' when PerCon_7_8_c = "+
398 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
399 " then '7' when PerCon_9_10_c = " +
400 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
401 " then '9' else '' end as RightMould, " +" case when PerCon_1_2_c = "+
402 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
403 " then '2' when PerCon_3_4_c = " +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"]+
404 " then '4' when PerCon_5_6_c = " +
405 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +" then '6' when PerCon_7_8_c = "+
406 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
407 " then '8' when PerCon_9_10_c = " +
408 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
409 " then '10' else '' end as LeftMould, " +" case when PerCon_1_2_c = "+
410 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
411 " then lotnum + '1-2' when PerCon_3_4_c = " +
412 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
413 " then lotnum + '3-4' when PerCon_5_6_c = " +
414 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
415 " then lotnum + '5-6' when PerCon_7_8_c = " +
416 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
417 " then lotnum + '7-8' when PerCon_9_10_c = " +
418 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
419 " then lotnum + '9-10' else '' end as SerialNo, case when PerCon_1_2_c = " +
420 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
421 " then PerCon_1_2_Notes_c when PerCon_3_4_c = " +
422 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
423 " then PerCon_3_4_Notes_c when PerCon_5_6_c = " +
424 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
425 " then PerCon_5_6_Notes_c when PerCon_7_8_c = " +
426 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
427 " then PerCon_7_8_Notes_c when PerCon_9_10_c = " +
428 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
429 " then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot where company = '"+
430 ((Session)oTrans.Session).CompanyID +
431 "' and expirationdate > GETDATE() and ( PerCon_1_2_c = " +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"]+
432 " or PerCon_3_4_c = " +
433 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +" or PerCon_5_6_c = "+
434 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +
435 " or PerCon_7_8_c = " +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"]+
436 " or PerCon_9_10_c = " +
437 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] +")";
438 if (((Session)oTrans.Session).CompanyID=="250")
439 select =
440 "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', " +
441 " case when PerCon_1_2_c = glb.perconid then '1' when PerCon_3_4_c = glb.perconid then '3' when PerCon_5_6_c = glb.perconid then '5' when PerCon_7_8_c = glb.perconid then '7' when PerCon_9_10_c = glb.perconid then '9' else '' end as RightMould, " +
442 " case when PerCon_1_2_c = glb.perconid then '2' when PerCon_3_4_c = glb.perconid then '4' when PerCon_5_6_c = glb.perconid then '6' when PerCon_7_8_c = glb.perconid then '8' when PerCon_9_10_c = glb.perconid then '10' else '' end as LeftMould, " +
443 " case when PerCon_1_2_c = glb.perconid then lotnum + '1-2' when PerCon_3_4_c = glb.perconid then lotnum + '3-4' when PerCon_5_6_c = glb.perconid then lotnum + '5-6' when PerCon_7_8_c = glb.perconid then lotnum + '7-8' when PerCon_9_10_c = glb.perconid then lotnum + '9-10' else '' end as SerialNo, " +
444 " case when PerCon_1_2_c = glb.perconid then PerCon_1_2_Notes_c when PerCon_3_4_c = glb.perconid then PerCon_3_4_Notes_c when PerCon_5_6_c = glb.perconid then PerCon_5_6_Notes_c when PerCon_7_8_c = glb.perconid then PerCon_7_8_Notes_c when PerCon_9_10_c = glb.perconid then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot as pl with (nolock) join erp.glbpercon as glb with (nolock) on pl.company = glb.company and glb.glbperconid = "+
445 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]
446 ["PerCon_c"]+
447 " and ( pl.PerCon_1_2_c = glb.perconid or pl.PerCon_3_4_c = glb.perconid or pl.PerCon_5_6_c = glb.perconid or pl.PerCon_7_8_c = glb.perconid or pl.PerCon_9_10_c = glb.perconid ) where pl.company = '200' and expirationdate > GETDATE() ";
448 LaunchCastSearch(select, true);
449 } else if (args.Cell.Column.Key=="Search_c") {
450 if (edvOrderDtl.Row <=-1)
451 return;
452 //MessageBox.Show("1");
453
454 var select =
455 "SELECT PerConID as PerConID, FirstName, LastName, DOB_c as DOB, EmployeeNum_c as EmployeeNum, CorpName as Company, Comment," +
456 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
457 " '1' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '3' "+
458 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
459 " '5' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '7' "+
460 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
461 " '9' " +" else "+" '' "+" end as RightMould, "+
462 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
463 " '2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '4' "+
464 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
465 " '6' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '8' "+
466 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
467 " '10' " +" else "+" '' "+" end as LeftMould, "+
468 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
469 " plo.lotnum + '1-2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+
470 " plo.lotnum + '3-4' " +
471 " when plo.percon_5_6_c = dbo.percon.PerConID then " +" plo.lotnum + '5-6' "+
472 " when plo.percon_7_8_c = dbo.percon.PerConID then " +
473 " plo.lotnum + '7-8' " +" when plo.percon_9_10_c = dbo.percon.PerConID then "+
474 " plo.lotnum + '9-10' " +
475 " else " +" '' "+" end as SerialNo"+
476 " , case when plo.percon_1_2_c = dbo.percon.PerConID then " +
477 " plo.PerCon_1_2_Notes_c " +
478 " when plo.percon_3_4_c = dbo.percon.PerConID then " +" plo.PerCon_3_4_Notes_c "+
479 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
480 " plo.PerCon_5_6_Notes_c " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+
481 " plo.PerCon_7_8_Notes_c " +
482 " when plo.percon_9_10_c = dbo.percon.PerConID then " +" plo.PerCon_9_10_Notes_c "+" else "+" '' "+
483 " end " +
484 " as Notes, " +" plo.ExpirationDate as ExpirationDate, "+" plo.lotnum as ExistingCast "+" ,ml.MfgLoc"+
485 " from dbo.percon with (nolock) " +
486 " left outer join dbo.partlot as plo on plo.company = dbo.percon.company and plo.ExpirationDate > GetDate() and ( plo.percon_1_2_c = PerConID or plo.percon_3_4_c = PerConID or plo.percon_5_6_c = PerConID or plo.percon_7_8_c = PerConID or plo.percon_9_10_c = PerConID) "+
487 " LEFT JOIN dbo.CPE_SLXLotNumMfgLoc ml ON ml.LotNum COLLATE SQL_Latin1_General_CP1250_CI_AS = plo.LotNum" +
488 " where dbo.percon.company = '" +
489 ((Session)oTrans.Session)
490 .CompanyID +
491 "' and dbo.percon.LastName = '" +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"]+
492 "' and dbo.percon.FirstName = '" +
493 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"]+"' order by dbo.percon.perconid, ExistingCast ";
494
495 if (((Session)oTrans.Session).CompanyID!="200")
496 select =
497 " select pc.PerConID as PerConID, pc.FirstName, pc.LastName, pc.DOB_c as DOB, pc.EmployeeNum_c as EmployeeNum, pc.Comment, pc.CorpName as Company, " +
498 " case when pl.percon_1_2_c = gpc.PerConID then " +
499 " '1' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '3' "+
500 " when pl.percon_5_6_c = gpc.PerConID then " +
501 " '5' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '7' "+
502 " when pl.percon_9_10_c = gpc.PerConID then " +
503 " '9' " +" else "+" '' "+
504 " end as RightMould, " +
505 " case when pl.percon_1_2_c = gpc.PerConID then " +
506 " '2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '4' "+
507 " when pl.percon_5_6_c = gpc.PerConID then " +
508 " '6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '8' "+
509 " when pl.percon_9_10_c = gpc.PerConID then " +
510 " '10' " +" else "+" '' "+
511 " end as LeftMould, " +
512 " case when pl.percon_1_2_c = gpc.PerConID then " +
513 " pl.lotnum + '1-2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" pl.lotnum + '3-4' "+
514 " when pl.percon_5_6_c = gpc.PerConID then " +
515 " pl.lotnum + '5-6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" pl.lotnum + '7-8' "+
516 " when pl.percon_9_10_c = gpc.PerConID then " +
517 " pl.lotnum + '9-10' " +" else "+" '' "+" end as SerialNo, "+
518 " case when pl.percon_1_2_c = gpc.PerConID then " +
519 " pl.PerCon_1_2_Notes_c " +" when pl.percon_3_4_c = gpc.PerConID then "+
520 " pl.PerCon_3_4_Notes_c " +
521 " when pl.percon_5_6_c = gpc.PerConID then " +" pl.PerCon_5_6_Notes_c "+
522 " when pl.percon_7_8_c = gpc.PerConID then " +
523 " pl.PerCon_7_8_Notes_c " +" when pl.percon_9_10_c = gpc.PerConID then "+
524 " pl.PerCon_9_10_Notes_c " +
525 " else " +" '' "+" end as Notes , "+
526 " pl.ExpirationDate as ExpirationDate, " +
527 " pl.lotnum as ExistingCast " +
528 " ,ml.MfgLoc" +" from dbo.percon as pc with (nolock) "+
529 " join erp.glbpercon as gpc on '200' = gpc.company and gpc.GlbCompany = '" +
530 ((Session)oTrans.Session).CompanyID +
531 "' and gpc.glbperconid = pc.perconid " +
532 " left outer join dbo.PartLot as pl with (nolock)on pl.company = gpc.company and pl.expirationdate > Getdate() and ( (pl.percon_1_2_c = gpc.PerConID and gpc.perconid > 0 ) or " +
533 " ( pl.percon_3_4_c = gpc.PerConID and gpc.perconid > 0 ) or (pl.percon_5_6_c = gpc.PerConID and gpc.perconid > 0 ) or (pl.percon_7_8_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_9_10_c = gpc.PerConID and gpc.perconid > 0 )) "+
534 " LEFT JOIN dbo.CPE_SLXLotNumMfgLoc ml ON ml.LotNum COLLATE SQL_Latin1_General_CP1250_CI_AS = pl.LotNum" +
535 " where pc.company = '" +
536 ((Session)oTrans.Session)
537 .CompanyID +
538 "' and pc.LastName = '"+edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"]+"' and pc.FirstName = '"+
539 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]
540 ["PerConFirstName_c"]+
541 "' order by pc.perconid, pl.lotnum";
542 // MessageBox.Show("1351");
543 // txtQuery.Text += "1351***********************************************1351\n\n" + select;
544 //MessageBox.Show("1410");
545 if (!LaunchSearch(select))
546 return;
547 //MessageBox.Show("3");
548 select =
549 " select PerConID as PerConID, FirstName, LastName, DOB_c as DOB, EmployeeNum_c as EmployeeNum, CorpName as Company, Comment," +
550 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
551 " '1' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '3' "+
552 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
553 " '5' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '7' "+
554 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
555 " '9' " +" else "+" '' "+" end as RightMould, "+
556 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
557 " '2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '4' "+
558 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
559 " '6' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '8' "+
560 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
561 " '10' " +" else "+" '' "+" end as LeftMould, "+
562 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
563 " plo.lotnum + '1-2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+
564 " plo.lotnum + '3-4' " +
565 " when plo.percon_5_6_c = dbo.percon.PerConID then " +" plo.lotnum + '5-6' "+
566 " when plo.percon_7_8_c = dbo.percon.PerConID then " +
567 " plo.lotnum + '7-8' " +" when plo.percon_9_10_c = dbo.percon.PerConID then "+
568 " plo.lotnum + '9-10' " +
569 " else " +" '' "+" end as SerialNo "+
570 " , case when plo.percon_1_2_c = dbo.percon.PerConID then " +
571 " plo.PerCon_1_2_Notes_c " +
572 " when plo.percon_3_4_c = dbo.percon.PerConID then " +" plo.PerCon_3_4_Notes_c "+
573 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
574 " plo.PerCon_5_6_Notes_c " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+
575 " plo.PerCon_7_8_Notes_c " +
576 " when plo.percon_9_10_c = dbo.percon.PerConID then " +" plo.PerCon_9_10_Notes_c "+" else "+" '' "+
577 " end " +
578 " as Notes, " +
579 " plo.ExpirationDate as ExpirationDate, " +" plo.lotnum as ExistingCast "+" ,ml.MfgLoc"+" from dbo.percon with (nolock) "+
580 " left outer join dbo.partlot as plo on plo.company = dbo.percon.company and plo.ExpirationDate > GetDate() and ( plo.percon_1_2_c = PerConID or plo.percon_3_4_c = PerConID or plo.percon_5_6_c = PerConID or plo.percon_7_8_c = PerConID or plo.percon_9_10_c = PerConID) "+
581 " LEFT JOIN dbo.CPE_SLXLotNumMfgLoc ml ON ml.LotNum COLLATE SQL_Latin1_General_CP1250_CI_AS = plo.LotNum" +
582 " where dbo.percon.company = '" +
583 ((Session)oTrans.Session)
584 .CompanyID +
585 "' and dbo.percon.LastName like '" +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"]+
586 "%' and dbo.percon.FirstName like '" +
587 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"]+"%' order by dbo.percon.perconid, ExistingCast ";
588
589 if (((Session)oTrans.Session).CompanyID!="200")
590 select =
591 " select pc.PerConID as PerConID, pc.FirstName, pc.LastName, pc.DOB_c as DOB, pc.EmployeeNum_c as EmployeeNum, pc.Comment, pc.CorpName as Company, " +
592 " case when pl.percon_1_2_c = gpc.PerConID then " +
593 " '1' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '3' "+
594 " when pl.percon_5_6_c = gpc.PerConID then " +
595 " '5' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '7' "+
596 " when pl.percon_9_10_c = gpc.PerConID then " +
597 " '9' " +" else "+" '' "+
598 " end as RightMould, " +
599 " case when pl.percon_1_2_c = gpc.PerConID then " +
600 " '2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '4' "+
601 " when pl.percon_5_6_c = gpc.PerConID then " +
602 " '6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '8' "+
603 " when pl.percon_9_10_c = gpc.PerConID then " +
604 " '10' " +" else "+" '' "+
605 " end as LeftMould, " +
606 " case when pl.percon_1_2_c = gpc.PerConID then " +
607 " pl.lotnum + '1-2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" pl.lotnum + '3-4' "+
608 " when pl.percon_5_6_c = gpc.PerConID then " +
609 " pl.lotnum + '5-6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" pl.lotnum + '7-8' "+
610 " when pl.percon_9_10_c = gpc.PerConID then " +
611 " pl.lotnum + '9-10' " +" else "+" '' "+" end as SerialNo, "+
612 " case when pl.percon_1_2_c = gpc.PerConID then " +
613 " pl.PerCon_1_2_Notes_c " +" when pl.percon_3_4_c = gpc.PerConID then "+
614 " pl.PerCon_3_4_Notes_c " +
615 " when pl.percon_5_6_c = gpc.PerConID then " +" pl.PerCon_5_6_Notes_c "+
616 " when pl.percon_7_8_c = gpc.PerConID then " +
617 " pl.PerCon_7_8_Notes_c " +" when pl.percon_9_10_c = gpc.PerConID then "+
618 " pl.PerCon_9_10_Notes_c " +
619 " else " +" '' "+" end as Notes , "+
620 " pl.ExpirationDate as ExpirationDate, " +
621 " pl.lotnum as ExistingCast " +
622 " ,ml.MfgLoc" +" from dbo.percon as pc with (nolock) "+
623 " join erp.glbpercon as gpc on '200' = gpc.company and gpc.GlbCompany = '" +
624 ((Session)oTrans.Session).CompanyID +
625 "' and gpc.glbperconid = pc.perconid " +
626 " left outer join dbo.PartLot as pl with (nolock)on pl.company = gpc.company and pl.expirationdate > Getdate() and ( ( pl.percon_1_2_c = gpc.PerConID and gpc.perconid > 0 ) or " +
627 " ( pl.percon_3_4_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_5_6_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_7_8_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_9_10_c = gpc.PerConID and gpc.perconid > 0 ) ) "+
628 " LEFT JOIN dbo.CPE_SLXLotNumMfgLoc ml ON ml.LotNum COLLATE SQL_Latin1_General_CP1250_CI_AS = pl.LotNum" +
629 " where pc.company = '" +
630 ((Session)oTrans.Session)
631 .CompanyID +
632 "' and pc.LastName like '" +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"]+
633 "%' and pc.FirstName like '" +
634 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"]+"%' order by pc.perconid, pl.lotnum";
635 // MessageBox.Show("1480");
636 // txtQuery.Text += "1480***********************************************1480\n\n" + select;
637 if (LaunchSearch(select))
638 MessageBox.Show("No contacts found with\nLastName starts or equal to:"+edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"]+
639 "\nand FirstName starts or equal to:" +edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"]);
640 }
641 }
642
643 void grdDtlList_CellChange(object sender, CellEventArgs args) {
644 try {
645 var searchType = "Auto3";
646 try {
647 searchType = cmbSearchType.Value.ToString();
648 } catch (Exception ex) {
649 DebugMsg(ex);
650 }
651
652 if (searchType!="Auto3")
653 return;
654 if (args.Cell.Column.Key!="PerConLastName_c")
655 return;
656 if (args.Cell.Text.Length!=3)
657 return;
658 args.Cell.Row.Cells["PerConFirstName_c"].Value = "";
659 args.Cell.Row.Cells["PerConDOB_c"].Value = DBNull.Value;
660 args.Cell.Row.Cells["EmployeeNum_c"].Value = "";
661
662 var select =
663 " select PerConID as PerConID, FirstName, LastName, DOB_c as DOB, EmployeeNum_c as EmployeeNum, Comment, CorpName as Company, " +
664 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
665 " '1' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '3' "+
666 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
667 " '5' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '7' "+
668 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
669 " '9' " +" else "+" '' "+" end as RightMould, "+
670 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
671 " '2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+" '4' "+
672 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
673 " '6' " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+" '8' "+
674 " when plo.percon_9_10_c = dbo.percon.PerConID then " +
675 " '10' " +" else "+" '' "+" end as LeftMould, "+
676 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
677 " plo.lotnum + '1-2' " +" when plo.percon_3_4_c = dbo.percon.PerConID then "+
678 " plo.lotnum + '3-4' " +
679 " when plo.percon_5_6_c = dbo.percon.PerConID then " +" plo.lotnum + '5-6' "+
680 " when plo.percon_7_8_c = dbo.percon.PerConID then " +
681 " plo.lotnum + '7-8' " +" when plo.percon_9_10_c = dbo.percon.PerConID then "+
682 " plo.lotnum + '9-10' " +
683 " else " +" '' "+" end as SerialNo, "+
684 " case when plo.percon_1_2_c = dbo.percon.PerConID then " +
685 " plo.PerCon_1_2_Notes_c " +
686 " when plo.percon_3_4_c = dbo.percon.PerConID then " +" plo.PerCon_3_4_Notes_c "+
687 " when plo.percon_5_6_c = dbo.percon.PerConID then " +
688 " plo.PerCon_5_6_Notes_c " +" when plo.percon_7_8_c = dbo.percon.PerConID then "+
689 " plo.PerCon_7_8_Notes_c " +
690 " when plo.percon_9_10_c = dbo.percon.PerConID then " +" plo.PerCon_9_10_Notes_c "+" else "+
691 " '' " +
692 " end " +
693 " as Notes, " +" plo.ExpirationDate as ExpirationDate, "+" plo.lotnum as ExistingCast "+
694 " from dbo.percon with (nolock) " +
695 " left outer join dbo.partlot as plo on plo.company = dbo.percon.company and plo.ExpirationDate > GetDate() and ( plo.percon_1_2_c = PerConID or plo.percon_3_4_c = PerConID or plo.percon_5_6_c = PerConID or plo.percon_7_8_c = PerConID or plo.percon_9_10_c = PerConID) "+
696 " where dbo.percon.company = '" +
697 ((Session)oTrans.Session).CompanyID +"' and dbo.percon.LastName like '"+args.Cell.Text+
698 "%' order by dbo.percon.perconid, ExistingCast ";
699
700 if (((Session)oTrans.Session).CompanyID!="200")
701 select =
702 " select pc.PerConID as PerConID, pc.FirstName, pc.LastName, pc.DOB_c as DOB, pc.EmployeeNum_c as EmployeeNum, pc.Comment, pc.CorpName as Company, " +
703 " case when pl.percon_1_2_c = gpc.PerConID then " +
704 " '1' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '3' "+
705 " when pl.percon_5_6_c = gpc.PerConID then " +
706 " '5' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '7' "+
707 " when pl.percon_9_10_c = gpc.PerConID then " +
708 " '9' " +" else "+" '' "+" end as RightMould, "+
709 " case when pl.percon_1_2_c = gpc.PerConID then " +
710 " '2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" '4' "+
711 " when pl.percon_5_6_c = gpc.PerConID then " +
712 " '6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" '8' "+
713 " when pl.percon_9_10_c = gpc.PerConID then " +
714 " '10' " +" else "+" '' "+" end as LeftMould, "+
715 " case when pl.percon_1_2_c = gpc.PerConID then " +
716 " pl.lotnum + '1-2' " +" when pl.percon_3_4_c = gpc.PerConID then "+" pl.lotnum + '3-4' "+
717 " when pl.percon_5_6_c = gpc.PerConID then " +
718 " pl.lotnum + '5-6' " +" when pl.percon_7_8_c = gpc.PerConID then "+" pl.lotnum + '7-8' "+
719 " when pl.percon_9_10_c = gpc.PerConID then " +
720 " pl.lotnum + '9-10' " +" else "+" '' "+" end as SerialNo, "+
721 " case when pl.percon_1_2_c = gpc.PerConID then " +
722 " pl.PerCon_1_2_Notes_c " +" when pl.percon_3_4_c = gpc.PerConID then "+
723 " pl.PerCon_3_4_Notes_c " +
724 " when pl.percon_5_6_c = gpc.PerConID then " +" pl.PerCon_5_6_Notes_c "+
725 " when pl.percon_7_8_c = gpc.PerConID then " +
726 " pl.PerCon_7_8_Notes_c " +" when pl.percon_9_10_c = gpc.PerConID then "+
727 " pl.PerCon_9_10_Notes_c " +
728 " else " +" '' "+" end as Notes , "+
729 " pl.ExpirationDate as ExpirationDate, " +
730 " pl.lotnum as ExistingCast " +
731 " from dbo.percon as pc with (nolock) " +
732 " join erp.glbpercon as gpc on '200' = gpc.company and gpc.GlbCompany = '" +
733 ((Session)oTrans.Session).CompanyID +
734 "' and gpc.glbperconid = pc.perconid " +
735 " left outer join dbo.PartLot as pl with (nolock)on pl.company = gpc.company and pl.expirationdate > Getdate() and ( ( pl.percon_1_2_c = gpc.PerConID and gpc.perconid > 0 ) or " +
736 " ( pl.percon_3_4_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_5_6_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_7_8_c = gpc.PerConID and gpc.perconid > 0 ) or ( pl.percon_9_10_c = gpc.PerConID and gpc.perconid > 0 ) ) "+
737 " where pc.company = '" +
738 ((Session)oTrans.Session).CompanyID +"' and pc.LastName like '"+args.Cell.Text+"%' order by pc.perconid, pl.lotnum";
739 // MessageBox.Show("2025");
740 // txtQuery.Text += "2025***********************************************2025\n\n" + select;
741 LaunchSearch(select);
742 } catch (Exception ex) {
743 MessageBox.Show("Cell change error: "+ex.Message);
744 }
745 }
746 #endregion
747
748 #region Adapter Event Handlers
749 void oTrans_ordAdapter_BeforeAdapterMethod(object sender, BeforeAdapterMethodArgs args) {
750 switch (args.MethodName) {
751 case "Update":
752 case "MasterUpdate":
753 if (edvOrderDtl.Row>-1 && edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["RowMod"].ToString()=="A") {
754 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["Copy_c"] = "";
755 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["New_c"] = "";
756 }
757
758 var parameters = new Hashtable();
759 parameters.Add("pcustid", m_custID);
760 var dt = GetQueryData("CPECustomerPORequired", parameters);
761 if (dt.Rows.Count >0)
762 if (Convert.ToBoolean(dt.Rows[0]["Customer_PORequired_c"]) && edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["PONum"].ToString().Length==0) {
763 MessageBox.Show("Customer requires a PO number");
764 args.Cancel = true;
765 }
766
767 break;
768 }
769 }
770
771 void oTrans_ordAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args) {
772 switch (args.MethodName) {
773 case "ChangeSoldToID":
774 edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CommentsFromCustomer_c"] = "Start";
775 var parameters = new Hashtable();
776 parameters.Add("pcustnum", edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustNum"].ToString());
777 var dt = GetQueryData("CPECustomerComments", parameters);
778 if (dt.Rows.Count>0)
779 edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CommentsFromCustomer_c"] = dt.Rows[0]["Calculated_Comments"];
780 break;
781 }
782 }
783 #endregion
784
785 #region DataView Event Handlers
786 void edvOrderHed_EpiViewNotification(EpiDataView view, EpiNotifyArgs args) {
787 try {
788 if (args.Row<=-1) {
789 m_custID = "";
790 m_custNum = 0;
791 m_shipToNum = "";
792 return;
793 }
794
795 var company = view.dataView[args.Row]["Company"].ToString();
796 var custID = view.dataView[args.Row]["CustomerCustID"].ToString();
797 if (company=="200" && custID=="250") {
798 txtCustomerPONum.ReadOnly = false;
799 txtCustomerPONum.Visible = true;
800 lblCustomerPONum.Visible = true;
801 epiTextBoxSalesRepCode1.Value = view.dataView[args.Row]["PEU_SalesRepCode1_c"].ToString();
802 } else {
803 txtCustomerPONum.ReadOnly = false;
804 txtCustomerPONum.Visible = false;
805 lblCustomerPONum.Visible = false;
806 epiTextBoxSalesRepCode1.Value = view.dataView[args.Row]["SalesRepCode1"].ToString();
807 }
808
809 if (m_custID!=Convert.ToString(view.dataView[args.Row]["CustomerCustID"])) {
810 m_custID = Convert.ToString(view.dataView[args.Row]["CustomerCustID"]);
811
812 if (Convert.ToBoolean(view.dataView[args.Row]["OpenOrder"])) {
813 edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CommentsFromCustomer_c"] = "Start";
814 var parameters = new Hashtable();
815 parameters.Add("pcustid", m_custID);
816 var dt = GetQueryData("CPECustomerComments", parameters);
817 if (dt.Rows.Count>0)
818 edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CommentsFromCustomer_c"] = dt.Rows[0]["Calculated_Comments"];
819 }
820 }
821
822 if (m_custNum!=Convert.ToInt32(view.dataView[args.Row]["CustNum"]) || m_shipToNum!=Convert.ToString(view.dataView[args.Row]["ShipToNum"])) {
823 m_custNum = Convert.ToInt32(view.dataView[args.Row]["CustNum"]);
824 m_shipToNum = Convert.ToString(view.dataView[args.Row]["ShipToNum"]);
825 SetHeaderPriceListDropDown(m_custNum, m_shipToNum);
826 }
827 } catch (Exception ex) {
828 MessageBox.Show("edvOrderHed_EpiViewNotification error: "+ex.Message);
829 }
830 }
831
832 void edvOrderDtl_EpiViewNotification(EpiDataView view, EpiNotifyArgs args) {
833 try {
834 if (edvOrderDtl.Row>-1) {
835 btnCreateNewContact.ReadOnly = false;
836 btnSelectContact.ReadOnly = false;
837 } else {
838 btnCreateNewContact.ReadOnly = true;
839 btnSelectContact.ReadOnly = true;
840 }
841
842 if (args.NotifyType==EpiTransaction.NotifyType.AddRow)
843 view.dataView[args.Row]["SalesUM"] = "PR";
844 } catch (Exception ex) {
845 DebugMsg(ex);
846 }
847 }
848
849 void OrderHed_AfterFieldChange(object sender, DataColumnChangeEventArgs args) {
850 switch (args.Column.ColumnName) {
851 case "HeaderPriceList_c":
852 // set price list from header
853 HeaderPriceListChanged(args);
854 break;
855 }
856 }
857
858 void OrderHed_BeforeFieldChange(object sender, DataColumnChangeEventArgs args) {
859 switch (args.Column.ColumnName) {
860 case "OrderSite_c":
861 if (edvOrderRel.dataView.Table.Rows.Count>0)
862 MessageBox.Show("Changing the Order Site will not update existing order line release site values.");
863 break;
864 }
865 }
866
867 void OrderDtl_AfterFieldChange(object sender, DataColumnChangeEventArgs args) {
868 try {
869 switch (args.Column.ColumnName) {
870 case "PerConLastName_c":
871 case "PerConFirstName_c":
872 case "PerConDOB_c":
873 PerConChanged(args);
874 break;
875 case "SalesUM":
876 //Reorders are automatically populated as pairs, this should catch if it is then changed to Left or Right
877 SalesUMChanged(args);
878
879 break;
880 case "PerCon_c":
881 case "PartNum":
882 PartNumChanged(args);
883 break;
884 }
885 } catch (Exception ex) {
886 MessageBox.Show("After field change: "+ex.Message);
887 }
888 }
889
890 void HeaderPriceListChanged(DataColumnChangeEventArgs args) {
891 if (!string.IsNullOrEmpty(args.Row["HeaderPriceList_c"].ToString())) {
892 oTrans.Update();
893 foreach (DataRow row in edvOrderDtl.dataView.Table.Rows) {
894 row["OverridePriceList"] = true;
895 row["BreakListCode"] = args.Row["HeaderPriceList_c"];
896 }
897
898 oTrans.Update();
899 oTrans.Refresh();
900 }
901 }
902
903 void PartNumChanged(DataColumnChangeEventArgs args) {
904 // set revision to latest approved for the Site selected
905 string latestRev;
906 if (GetLatestRev(args.Row["PartNum"].ToString(), edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["OrderSite_c"].ToString(), out latestRev))
907 args.Row["RevisionNum"] = latestRev;
908 // set price list from header
909 if (!string.IsNullOrEmpty(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["HeaderPriceList_c"].ToString())) {
910 args.Row["OverridePriceList"] = true;
911 args.Row["BreakListCode"] = edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["HeaderPriceList_c"];
912 }
913 // load the available colours and filters for this part //greg
914 //MessageBox.Show(args.Row["PartNum"].ToString() + "-c");
915
916 var filter_GrYeWh =
917 "10001N 10001R 10002N 10002R 10003N 10003R 10004N 10004R 10005N 10005R 10006N 10006R 10007N 10007R 10008N 10008R 10009N 10009R 10010N 10010R " +
918 "10011N 10011R 10012N 10012R 10013N 10013R 10014N 10014R 10015N 10015R 10016N 10016R 10017N 10017R 10018N 10018R 10037N 10037R 10038N 10038R 10039N 10039R 10048N " +
919 "10048R 10049N 10049R 10050N 10050R 10051N 10051R 10052N 10052R 10053N 10053R 10054N 10054R 10055N 10055R 10056N 10056R 10057N 10057R 10068N 10068R 10069N 10069R " +
920 "10070N 10070R 10071N 10071R 10073N 10073R 10074N 10074R 10075N 10075R 10076N 10076R 10077N 10077R 10078N 10078R 10079N 10079R 10080N 10080R 10100N 10100R 10101N " +
921 "10101R 10102N 10102R 10103N 10103R 12001N 12001R 12009R 12010N 12010R 12012N 12012R 12013N 12013R 12022N 12022R 13005N 13005R 14002N 14002R 14005N 14005R 11005N 11005R 11016N 11016R 10040N "+
922 "10040R 10041N 10041R 10042N 10042R 10072N 10072R 10094N 10094R 10095N 10095R 10096N 10096R 10097N 10097R 10098N 10098R 10099N 10099R";
923
924 var filter_musician = "11001N 11001R 11002N 11002R 11003N 11003R 11004N 11004R 11018N 11018R 11019N 11019R 11020N 11020R 11021N 11021R";
925
926 var filter_none = "10019N 10019R 10020N 10020R 10021N 10021R 10022N 10022R 10023N 10023R 10024N 10024R 10025N 10025R 10026N 10026R 10027N 10027R 10028N 10028R " +
927 "10029N 10029R 10030N 10030R 10031N 10031R 10032N 10032R 10033N 10033R 10034N 10034R 10035N 10035R 10036N 10036R 10058N 10058R 10059N 10059R 10060N 10060R " +
928 "10061N 10061R 10062N 10062R 10063N 10063R 10064N 10064R 10065N 10065R 10066N 10066R 10067N 10067R 10081N 10081R 10082N 10082R 10083N 10083R 10084N 10084R " +
929 "10086N 10086R 10087N 10087R 10088N 10088R 10089N 10089R 10090N 10090R 10091N 10091R 10092N 10092R 10093N 10093R 11007N 11007R 11010N 11010R 11011N 11011R " +
930 "11012N 11012R 11013N 11013R 11014N 11014R 11015N 11015R 12006N 12006R 12007N 12007R 12008N 12008R 12009N 12011N 12011R 12014 12014K 12015 " +
931 "12015K 12016 12016K 12017 12017K 12018 12018K 12019 12019K 12020 12021 12031N 12031R 12032N 12032R 12041N 12041R 13001N 13001R 13002N 13002R 13003N 13003R "+
932 "13004N 13004R 13006N 13006R 13007N 13007R 13008N 13008R 13009N 13009R 13010N 13010R 13011N 13011R 13012N 13012R 13013N 13013R 13014N 13014R 13015N 13015R " +
933 "13016N 13016R 13017N 13017R 13018N 13018R 13019N 13019R 14001N 14001R 14003N 14003R 14004N 14004R 11006N 11006R 11017N 11017R 10045N 10045R 10046N 10046R " +
934 "10085N 10085R 12005N 12005R";
935
936 string[] filters;
937
938 //MessageBox.Show(args.Row["Filter_c"].ToString());
939
940 if (filter_GrYeWh.IndexOf(args.Row["PartNum"].ToString())>-1) {
941 //Set the available filter colours
942 filters = new string[] {"Green", "Yellow", "White"};
943
944 //Test that the current filter colour is one of the available colours. If not, notify the user and clear it.
945 if (args.Row["Filter_c"].ToString()!="") {
946 var filterfound = false;
947 foreach (var fil in filters)
948 if (fil==args.Row["Filter_c"].ToString()) {
949 filterfound = true;
950 break;
951 }
952
953 if (filterfound) {
954 //MessageBox.Show(args.Row["Filter_c"].ToString() + " is in the newly populated filter dropdown.");
955 } else {
956 MessageBox.Show("The previous filter colour is not allowed for new Part number. Please select a new one.");
957 args.Row["Filter_c"] = "";
958 }
959 }
960 } else if (filter_musician.IndexOf(args.Row["PartNum"].ToString())>-1) {
961 //Set the available filter colours
962 filters = new string[2] {"ER9", "ER15"};
963 //Test that the current filter colour is one of the available colours. If not, notify the user and clear it.
964 if (args.Row["Filter_c"].ToString()!="") {
965 var filterfound = false;
966 foreach (var fil in filters)
967 if (fil==args.Row["Filter_c"].ToString()) {
968 filterfound = true;
969 break;
970 }
971
972 if (filterfound) {
973 //MessageBox.Show(args.Row["Filter_c"].ToString() + " is in the newly populated filter dropdown.");
974 } else {
975 MessageBox.Show("The previous filter colour is not allowed for new Part number. Please select a new one.");
976 args.Row["Filter_c"] = "";
977 }
978 }
979 } else {
980 filters = new string [0] { };
981 args.Row["Filter_c"] = "";
982 }
983
984 //Populate the Filter dropdown
985 SetGridDropDown(grdDtlList, "Filter_c", filters);
986
987 //standard colors are blk, blu, cle, grn, org, pur, red, safT tan, Teal, wht, yel, pink
988 var colour_standard =
989 "10001N 10001R 10002N 10002R 10003N 10003R 10004N 10004R 10005N 10005R 10006N 10006R 10007N 10007R 10008N 10008R 10009N 10009R 10010N " +
990 "10010R 10011N 10011R 10012N 10012R 10013N 10013R 10014N 10014R 10015N 10015R 10016N 10016R 10017N 10017R 10018N 10018R 10037N 10037R 10038N 10038R 10039N " +
991 "10039R 10048N 10048R 10049N 10049R 10050N 10050R 10051N 10051R 10052N 10052R 10053N 10053R 10054N 10054R 10055N 10055R 10056N 10056R 10057N 10057R 10068N " +
992 "10068R 10069N 10069R 10070N 10070R 10071N 10071R 10073N 10073R 10074N 10074R 10075N 10075R 10076N 10076R 10077N 10077R 10078N 10078R 10079N 10079R 10080N " +
993 "10080R 10100N 10100R 10101N 10101R 10102N 10102R 12009R 12010N 12010R 12012N 12012R 12013N 12013R 12022N 12022R 13005N 13005R 14002N 14002R 14005N 14005R " +
994 "11001N 11001R 11002N 11002R 11003N 11003R 11004N 11004R 11018N 11018R 11019N 11019R 11020N 11020R 11021N 11021R 10019N 10019R 10020N 10020R 10021N 10021R " +
995 "10022N 10022R 10023N 10023R 10024N 10024R 10025N 10025R 10026N 10026R 10027N 10027R 10028N 10028R 10029N 10029R 10030N 10030R 10031N 10031R 10032N 10032R " +
996 "10033N 10033R 10034N 10034R 10035N 10035R 10036N 10036R 10058N 10058R 10059N 10059R 10060N 10060R 10061N 10061R 10062N 10062R 10063N 10063R 10064N 10064R " +
997 "10065N 10065R 10066N 10066R 10067N 10067R 10081N 10081R 10082N 10082R 10083N 10083R 10084N 10084R 10086N 10086R 10087N 10087R 10088N 10088R 10089N 10089R " +
998 "10090N 10090R 10091N 10091R 10092N 10092R 10093N 10093R 10103N 10103R 11007N 11007R 11010N 11010R 11011N 11011R 11012N 11012R 11013N 11013R 11014N 11014R 11015N 11015R "+
999 "12001N 12001R 2006N 12006R 12007N 12007R 12008N 12008R 12009N 12011N 12011R 12014 12014K 12015 12015K 12016 12016K 12017 12017K 12018 12018K 12019 12019K " +
1000 "12020 12021 12031N 12031R 12032N 12032R 12041N 12041R 13001N 13001R 13002N 13002R 13003N 13003R 13004N 13004R 13006N 13006R 13007N 13007R 13008N 13008R " +
1001 "13009N 13009R 13010N 13010R 13011N 13011R 13012N 13012R 13013N 13013R 13014N 13014R 13015N 13015R 13016N 13016R 13017N 13017R 13018N 13018R 13019N 13019R " +
1002 "14001N 14001R 14003N 14003R 14004N 14004R";
1003
1004 var colour_standard_plus_GID = "11005N 11005R 11016N 11016R 11006N 11006R 11017N 11017R";
1005
1006 var colour_standard_plus_grey = "10040N 10040R 10041N 10041R 10042N 10042R 10072N 10072R 10094N 10094R 10095N 10095R 10096N 10096R 10097N 10097R 10098N 10098R "+
1007 "10099N 10099R 10045N 10045R 10046N 10046R 10085N 10085R 12005N 12005R";
1008
1009 var colour_PartNum_NOT_Pink_Diamond_and_White_Diamond =
1010 "11016N 11016R 11017N 11017R 11005N 11005R 11006N 11006R 10100N 10100R 10101N 10101R 10102N 10102R 10103N 10103R 11001N 11001R 11004N 11004R";
1011
1012 var colorList = new List<string> {"Black", "Blue", "Clear", "Green", "Orange", "Purple", "Red", "SafT", "Tan", "Teal", "White", "Yellow", "Pink"};
1013 var currentColor = "";
1014
1015 //if there's a current color selected, capture it for comparison later
1016 if (colour_standard.IndexOf(args.Row["PartNum"].ToString())>-1) { } else if (colour_standard_plus_GID.IndexOf(args.Row["PartNum"].ToString())>-1) {
1017 colorList.Add("GID");
1018 } else if (colour_standard_plus_grey.IndexOf(args.Row["PartNum"].ToString())>-1) {
1019 colorList.Add("Grey");
1020 }
1021
1022 //Check to see if the part num is one that does NOT have Pink Glitter or White Diamond as an option and add them accordingly
1023 if (colour_PartNum_NOT_Pink_Diamond_and_White_Diamond.IndexOf(args.Row["PartNum"].ToString())==-1) {
1024 colorList.Add("White Diamond");
1025 colorList.Add("Pink Glitter");
1026 }
1027
1028 //Test that the current colour is one of the available colours. If not, notify the user and clear it.
1029 if (currentColor!="") {
1030 var colourfound = false;
1031 foreach (var col in colorList)
1032 if (col==args.Row["Colour_c"].ToString()) {
1033 colourfound = true;
1034 break;
1035 }
1036
1037 if (!colourfound) {
1038 MessageBox.Show("The previous colour is not allowed for new Part number. Please select a new one.");
1039 args.Row["Colour_c"] = "";
1040 }
1041 }
1042
1043 //Populate the Colour dropdown
1044 SetGridDropDown(grdDtlList, "Colour_c", colorList);
1045
1046 // if part ends with an N and ther PerCon_c already has a line for a part change the last character to an R
1047 if (Convert.ToInt32(args.Row["PerCon_c"])>0 && args.Row["PartNum"].ToString().ToUpper().EndsWith("N")) {
1048 var rowsInThisOrder = edvOrderDtl.dataView.Table.Select("PerCon_c = " +args.Row["PerCon_c"].ToString().Trim()+" and OrderNum = "+
1049 args.Row["OrderNum"].ToString().Trim()+
1050 " and OrderLine <> " +args.Row["OrderLine"].ToString().Trim());
1051 // see if there is only one N part num
1052 var bHasNewPartRow = false;
1053 var nLine = " ";
1054 foreach (var nRow in rowsInThisOrder)
1055 if (nRow["PartNum"].ToString().ToUpper().EndsWith("N")) {
1056 bHasNewPartRow = true;
1057 nLine += nRow["OrderLine"]+" ";
1058 }
1059
1060 if (bHasNewPartRow)
1061 MessageBox.Show(args.Row["PerConFirstName_c"]+" "+args.Row["PerConLastName_c"]+" has a new part in line "+nLine); // + "\nSwitching part number to R.");
1062 } else if (Convert.ToInt32(args.Row["PerCon_c"])>0 && args.Row["PartNum"].ToString().ToUpper().EndsWith("R")) {
1063 var newValue = ChangeContact(false, Convert.ToInt32(args.Row["PerCon_c"]));
1064 if (newValue!=Convert.ToInt32(args.Row["PerCon_c"]))
1065 args.Row["PerCon_c"] = newValue;
1066 //string select = "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date' from erp.partlot where company = '" + ((Ice.Core.Session)oTrans.Session).CompanyID + "' and lotnum in (select distinct(pl.lotnum) from erp.partlot as pl with (nolock) join dbo.PlantConfCtrl as pcc with (nolock) on pl.company = pcc.company and pl.partnum = pcc.CastPartNum_c and pcc.plant = '" + ((Ice.Core.Session)oTrans.Session).PlantID + "' and pcc.company = '" + ((Ice.Core.Session)oTrans.Session).CompanyID + "' join dbo.orderdtl as od with (nolock) on od.company = pl.company and pl.lotnum = od.CPE_Cast_c join dbo.PerCon as pc with (nolock) on pc.company = od.company and pc.PerConID = od.PerCon_c where pc.PerConID = " + args.Row["PerCon_c"].ToString() + " and pl.expirationdate > GETDATE())";
1067 var select = "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', case when PerCon_1_2_c = "+args.Row["PerCon_c"] +
1068 " then PerCon_1_2_Notes_c when PerCon_3_4_c = " +args.Row["PerCon_c"] +
1069 " then PerCon_3_4_Notes_c when PerCon_5_6_c = " +args.Row["PerCon_c"] +
1070 " then PerCon_5_6_Notes_c when PerCon_7_8_c = " +args.Row["PerCon_c"] +
1071 " then PerCon_7_8_Notes_c when PerCon_9_10_c = " +args.Row["PerCon_c"] +
1072 " then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot where company = '" +((Session)oTrans.Session).CompanyID+
1073 "' and expirationdate > GETDATE() and ( PerCon_1_2_c = " +args.Row["PerCon_c"] +" or PerCon_3_4_c = "+
1074 args.Row["PerCon_c"] +" or PerCon_5_6_c = " +
1075 args.Row["PerCon_c"] +" or PerCon_7_8_c = " +args.Row["PerCon_c"]+
1076 " or PerCon_9_10_c = " +args.Row["PerCon_c"] +")";
1077
1078 @select = "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', case when PerCon_1_2_c = "+args.Row["PerCon_c"] +
1079 " then PerCon_1_2_Notes_c when PerCon_3_4_c = " +args.Row["PerCon_c"] +
1080 " then PerCon_3_4_Notes_c when PerCon_5_6_c = " +args.Row["PerCon_c"] +
1081 " then PerCon_5_6_Notes_c when PerCon_7_8_c = " +args.Row["PerCon_c"] +
1082 " then PerCon_7_8_Notes_c when PerCon_9_10_c = " +args.Row["PerCon_c"] +
1083 " then PerCon_9_10_Notes_c else '' end as Notes , " +" case when PerCon_1_2_c = "+
1084 args.Row["PerCon_c"] +" then '1' " +" when PerCon_3_4_c = "+args.Row["PerCon_c"]+
1085 " then '3' " +" when PerCon_5_6_c = " +
1086 args.Row["PerCon_c"] +" then '5' " +" when PerCon_7_8_c = "+args.Row["PerCon_c"]+" then '7' "+
1087 " when PerCon_9_10_c = " +
1088 args.Row["PerCon_c"] +" then '9' else '' end as RightMould, "+
1089 " case when PerCon_1_2_c = " +args.Row["PerCon_c"] +" then '2' when PerCon_3_4_c = "+
1090 args.Row["PerCon_c"] +" then '4' when PerCon_5_6_c = " +
1091 args.Row["PerCon_c"] +" then '6' when PerCon_7_8_c = " +args.Row["PerCon_c"]+
1092 " then '8' when PerCon_9_10_c = " +args.Row["PerCon_c"] +
1093 " then '10' else '' end as LeftMould, " +" case when PerCon_1_2_c = " +args.Row["PerCon_c"]+
1094 " then lotnum + '1-2' " +" when PerCon_3_4_c = " +
1095 args.Row["PerCon_c"] +" then lotnum + '3-4' " +" when PerCon_5_6_c = "+args.Row["PerCon_c"]+" then lotnum + '5-6' "+
1096 " when PerCon_7_8_c = " +args.Row["PerCon_c"] +
1097 " then lotnum + '7-8' " +"when PerCon_9_10_c = " +args.Row["PerCon_c"]+
1098 " then lotnum + '9-10' else '' end as SerialNo " +" from dbo.partlot where company = '" +
1099 ((Session)oTrans.Session).CompanyID +
1100 "' and expirationdate > GETDATE() and ( PerCon_1_2_c = " +args.Row["PerCon_c"] +
1101 " or PerCon_3_4_c = " +args.Row["PerCon_c"] +" or PerCon_5_6_c = "+
1102 args.Row["PerCon_c"] +" or PerCon_7_8_c = " +
1103 args.Row["PerCon_c"] +" or PerCon_9_10_c = "+args.Row["PerCon_c"]+")";
1104
1105 if (((Session)oTrans.Session).CompanyID=="250")
1106 @select =
1107 "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', " +
1108 " case when PerCon_1_2_c = glb.perconid then '1' when PerCon_3_4_c = glb.perconid then '3' when PerCon_5_6_c = glb.perconid then '5' when PerCon_7_8_c = glb.perconid then '7' when PerCon_9_10_c = glb.perconid then '9' else '' end as RightMould, " +
1109 " case when PerCon_1_2_c = glb.perconid then '2' when PerCon_3_4_c = glb.perconid then '4' when PerCon_5_6_c = glb.perconid then '6' when PerCon_7_8_c = glb.perconid then '8' when PerCon_9_10_c = glb.perconid then '10' else '' end as LeftMould, " +
1110 " case when PerCon_1_2_c = glb.perconid then lotnum + '1-2' when PerCon_3_4_c = glb.perconid then lotnum + '3-4' when PerCon_5_6_c = glb.perconid then lotnum + '5-6' when PerCon_7_8_c = glb.perconid then lotnum + '7-8' when PerCon_9_10_c = glb.perconid then lotnum + '9-10' else '' end as SerialNo, case when PerCon_1_2_c = glb.perconid then PerCon_1_2_Notes_c when PerCon_3_4_c = glb.perconid then PerCon_3_4_Notes_c when PerCon_5_6_c = glb.perconid then PerCon_5_6_Notes_c when PerCon_7_8_c = glb.perconid then PerCon_7_8_Notes_c when PerCon_9_10_c = glb.perconid then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot as pl with (nolock) join erp.glbpercon as glb with (nolock) on pl.company = glb.company and glb.glbperconid = "+
1111 args.Row
1112 ["PerCon_c"]+
1113 " and ( pl.PerCon_1_2_c = glb.perconid or pl.PerCon_3_4_c = glb.perconid or pl.PerCon_5_6_c = glb.perconid or pl.PerCon_7_8_c = glb.perconid or pl.PerCon_9_10_c = glb.perconid ) where pl.company = '200' and expirationdate > GETDATE() ";
1114 // MessageBox.Show("869");
1115 // txtQuery.Text = select;
1116 LaunchCastSearch(@select, false);
1117 } else {
1118 args.Row["CPE_Cast_c"] = "";
1119 }
1120
1121 args.Row["PerConDropDown_c"] = args.Row["PerCon_c"];
1122 }
1123
1124 void SalesUMChanged(DataColumnChangeEventArgs args) {
1125 if (args.Row["PartNum"].ToString().ToUpper().EndsWith("R")) {
1126 var salesUM = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["SalesUM"].ToString().Trim().ToLower();
1127
1128 if (salesUM=="pr" || salesUM=="right" || salesUM=="ea")
1129 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldRight_c"] = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldRight_c"];
1130 else
1131 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldRight_c"] = "";
1132 if (salesUM=="pr" || salesUM=="left" || salesUM=="ea")
1133 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldLeft_c"] = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldLeft_c"];
1134 else
1135 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldLeft_c"] = "";
1136 }
1137 }
1138
1139 void PerConChanged(DataColumnChangeEventArgs args) {
1140 if (m_copying ==false &&
1141 args.Row["PerConLastName_c"].ToString().Length >0 && args.Row["PerConFirstName_c"].ToString().Length>0)
1142 if (args.Row["PerConDOB_c"] !=DBNull.Value)
1143 if (CheckContactExists(args.Row["PerConFirstName_c"].ToString(), args.Row["PerConLastName_c"].ToString(), Convert.ToDateTime(args.Row["PerConDOB_c"]))==false)
1144 CreateNewContact(args.Row["PerConFirstName_c"].ToString(), args.Row["PerConLastName_c"].ToString(), args.Row["PerConDOB_c"], args.Row["EmployeeNum_c"].ToString(),
1145 Convert.ToString(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustomerName"]),
1146 Convert.ToInt32(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustNum"]));
1147 else
1148 UpdateContact(Convert.ToInt32(args.Row["PerCon_c"]), Convert.ToInt32(edvOrderHed.dataView.Table.Rows[edvOrderHed.Row]["CustNum"]));
1149 }
1150 #endregion
1151
1152 bool CheckContactExists(string FirstName, string LastName, object dboValue) {
1153 var useExistingContact = false;
1154 try {
1155 var dob = new DateTime(1900, 01, 01);
1156 try {
1157 dob = Convert.ToDateTime(dboValue);
1158 } catch (Exception ex) {
1159 DebugMsg(ex);
1160 }
1161
1162 var filter = "firstname = '"+FirstName+"' and lastname = '"+LastName+"' and DOB_c = '"+dob.ToString("yyyy-MM-dd")+"'";
1163 bool recSelected;
1164 var ds = SearchFunctions.listLookup(oTrans, "PerConAdapter", out recSelected, false, filter, true);
1165 if (recSelected) {
1166 var dsBO = BOReaderData("PerCon", "PerConID = "+ds.Tables[0].Rows[0]["PerConID"], "EmployeeNum_c");
1167 var empNum = "";
1168 if (dsBO.Tables[0].Rows.Count>0)
1169 empNum = dsBO.Tables[0].Rows[0]["EmployeeNum_c"].ToString();
1170 //MessageBox.Show("168: Contact Exists where FirstName, LastName and DOB match.\nOn the next dialog box click search and select an existing contact or cancel out of it to create a new contact entry.");
1171 if (ds.Tables[0].Rows.Count==1) {
1172 useExistingContact = true;
1173 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"].ToString()!=ds.Tables[0].Rows[0]["PerConID"].ToString())
1174 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] = ds.Tables[0].Rows[0]["PerConID"];
1175 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"].ToString()!=empNum)
1176 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"] = empNum; //ds.Tables[0].Rows[0]["EmployeeNum_c"];
1177 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"].ToString()!=ds.Tables[0].Rows[0]["CorpName"].ToString())
1178 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"] = ds.Tables[0].Rows[0]["CorpName"];
1179 } else {
1180 //ds = SearchFunctions.listLookup(oTrans,"PerConAdapter", out recSelected, true, filter);
1181 ds = SearchFunctions.listLookup(oTrans, "PerConAdapter", out recSelected, false, filter);
1182 if (recSelected) {
1183 useExistingContact = true;
1184 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"].ToString()!=ds.Tables[0].Rows[0]["PerConID"].ToString())
1185 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] = ds.Tables[0].Rows[0]["PerConID"];
1186 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"].ToString()!=empNum)
1187 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"] = empNum; //ds.Tables[0].Rows[0]["EmployeeNum_c"];
1188 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"].ToString()!=ds.Tables[0].Rows[0]["CorpName"].ToString())
1189 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"] = ds.Tables[0].Rows[0]["CorpName"];
1190 }
1191 }
1192 }
1193 } catch (Exception ex) {
1194 MessageBox.Show("Check Contact Exists: "+ex.Message);
1195 }
1196
1197 return useExistingContact;
1198 }
1199
1200 void CreateNewContact(string firstName, string lastName, object dboValue, string empNum, string company, int custNum) {
1201 try {
1202 var boPerCon = WCFServiceSupport.CreateImpl<PerConImpl>((Session)oTrans.Session, "erp/bo/percon.svc");
1203 var dsPerCon = new PerConDataSet();
1204 boPerCon.GetNewPerCon(dsPerCon);
1205 dsPerCon.Tables["PerCon"].Rows[0]["FirstName"] = firstName;
1206 dsPerCon.Tables["PerCon"].Rows[0]["LastName"] = lastName;
1207 dsPerCon.Tables["PerCon"].Rows[0]["Name"] = firstName+" "+lastName;
1208 dsPerCon.Tables["PerCon"].Rows[0]["EmployeeNum_c"] = empNum;
1209 dsPerCon.Tables["PerCon"].Rows[0]["CorpName"] = company;
1210 dsPerCon.Tables["PerCon"].Rows[0]["Company_c"] = company;
1211 if (edvOrderDtl.Row>-1)
1212 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"] = company;
1213 if (dboValue==DBNull.Value)
1214 dsPerCon.Tables["PerCon"].Rows[0]["DOB_c"] = new DateTime(1900, 01, 01);
1215 else
1216 dsPerCon.Tables["PerCon"].Rows[0]["DOB_c"] = dboValue;
1217 boPerCon.Update(dsPerCon);
1218
1219 // if US company make the Person global
1220 var session = (Session)oTrans.Session;
1221 if (session.CompanyID=="250") {
1222 dsPerCon.Tables["PerCon"].Rows[0]["RowMod"] = "U";
1223 dsPerCon.Tables["PerCon"].Rows[0]["GlobalPerCon"] = true;
1224 boPerCon.Update(dsPerCon);
1225 CreateLinkContact(session.CompanyID, Convert.ToInt32(dsPerCon.Tables["PerCon"].Rows[0]["PerConID"]), m_targetCompany, ref dsPerCon);
1226 }
1227
1228 //add to customer
1229 var boCustCnt = WCFServiceSupport.CreateImpl<CustCntImpl>((Session)oTrans.Session, "erp/bo/custcnt.svc");
1230 var dsCustCnt = new CustCntDataSet();
1231 boCustCnt.GetNewCustCnt(dsCustCnt, custNum, "");
1232 boCustCnt.GetPerConData(Convert.ToInt32(dsPerCon.Tables["PerCon"].Rows[0]["PerConID"]), dsCustCnt);
1233 boCustCnt.Update(dsCustCnt);
1234
1235 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] = dsPerCon.Tables["PerCon"].Rows[0]["PerConID"];
1236
1237 boPerCon.Dispose();
1238 dsPerCon.Clear();
1239
1240 boCustCnt.Dispose();
1241 dsCustCnt.Clear();
1242
1243 txtFirstName.Text = "";
1244 epiTextBoxC4.Text = "";
1245 epiDateTimeEditorC1.Value = null;
1246 } catch (Exception ex) {
1247 MessageBox.Show("CreateNewContact Error: "+ex.Message);
1248 }
1249 }
1250
1251 void CreateLinkContact(string sourceCompany, int sourcePerConID, string targetCompany, ref PerConDataSet sourcePerCon) {
1252 // MessageBox.Show("Create link");
1253 Hashtable parameters = null;
1254 DataTable dtGlbPerConExists = null;
1255 PerConImpl boPerConImpl = null;
1256 GlbPerConDataSet dsGlbPerCon = null;
1257 int targetPerConID;
1258
1259 try {
1260 // verify that glbpercon does not exist
1261 parameters = new Hashtable();
1262 parameters.Add("psourcecompany", sourceCompany);
1263 parameters.Add("ptargetcompany", targetCompany);
1264 parameters.Add("psourceperconid", sourcePerConID);
1265 dtGlbPerConExists = GetQueryData("CPEGlobalContactLink", parameters);
1266 var bLinked = false;
1267
1268 if (dtGlbPerConExists.Rows.Count >0)
1269 bLinked = Convert.ToInt32(dtGlbPerConExists.Rows[0]["GlbPerCon_PerConID"])!=0;
1270
1271 {
1272 // create row in GlbPerCon table using SQL
1273 if (bLinked==false) {
1274 boPerConImpl = WCFServiceSupport.CreateImpl<PerConImpl>(m_targetSession, "erp/bo/PerCon.svc");
1275 var dsPerCon = new PerConDataSet();
1276 boPerConImpl.GetNewPerCon(dsPerCon);
1277 dsPerCon.Tables["PerCon"].Rows[0]["Name"] = sourcePerCon.Tables["PerCon"].Rows[0]["Name"];
1278 boPerConImpl.DefaultName("Detail", 0, dsPerCon);
1279 boPerConImpl.Update(dsPerCon);
1280
1281 targetPerConID = Convert.ToInt32(dsPerCon.Tables["PerCon"].Rows[0]["PerConID"]);
1282 // MessageBox.Show(targetPerConID.ToString() + " id created" + ">>>" + sourceCompany + "`" + sourcePerConID);
1283 // link the contacts
1284 var bFound = false;
1285 var counter = 0;
1286 while (bFound==false && counter<65) {
1287 counter++;
1288 dsGlbPerCon = boPerConImpl.GetGlbPerConList(sourceCompany+"`"+sourcePerConID);
1289 if (dsGlbPerCon.Tables["GlbPerCon"].Rows.Count>0) {
1290 bFound = true;
1291 dsGlbPerCon.Tables["GlbPerCon"].Rows[0]["LinkPerConID"] = targetPerConID;
1292 dsGlbPerCon.Tables["GlbPerCon"].Rows[0]["LinkName"] = sourcePerCon.Tables["PerCon"].Rows[0]["Name"];
1293 dsGlbPerCon.Tables["GlbPerCon"].Rows[0]["RowMod"] = "U";
1294 } else {
1295 Thread.Sleep(1000);
1296 }
1297 }
1298 // MessageBox.Show(dsGlbPerCon.Tables["GlbPerCon"].Rows.Count.ToString() + "Found it " + counter.ToString());
1299 //string message;
1300 //boPerConImpl.PreLinkGlbPerCon(sourceCompany, sourcePerConID, false, dsGlbPerCon, out message);
1301
1302 // MessageBox.Show("391");
1303 string[] copyColumns = {
1304 "DOB_c", "EmployeeNum_c", "name", "firstname", "middlename", "lastname", "prname", "func", "FaxNum", "PhoneNum", "EMailAddress", "CellPhoneNum", "PagerNum",
1305 "HomeNum", "AltNum", "Prefix", "Suffix", "Initials", "WebSite", "IM", "Twitter", "LinkedIn", "FaceBook", "WebLink1", "WebLink2", "WebLink3", "WebLink4",
1306 "WebLink5", "Address1", "Address2", "Address3", "City", "State", "Zip", "Country", "CountryNum", "CorpName", "RoleCode", "Comment", "ContactTitle",
1307 "ReportsTo", "PRLastName", "PRFirstName", "PRMiddleName"
1308 };
1309 foreach (var colName in copyColumns)
1310 dsPerCon.Tables["PerCon"].Rows[0][colName] = sourcePerCon.Tables["PerCon"].Rows[0][colName];
1311 // MessageBox.Show("397");
1312 dsPerCon.Tables["PerCon"].Rows[0]["RowMod"] = "U";
1313 boPerConImpl.LinkGlbPerCon(sourceCompany, sourcePerConID, dsGlbPerCon, dsPerCon);
1314 dsPerCon.Tables["PerCon"].Rows[0]["GlbFlag"] = true;
1315 dsPerCon.Tables["PerCon"].Rows[0]["GlbLink"] = sourceCompany+"~"+sourcePerConID;
1316 dsPerCon.Tables["PerCon"].Rows[0]["RowMod"] = "U";
1317 boPerConImpl.Update(dsPerCon);
1318 // MessageBox.Show("linked");
1319
1320 dsPerCon.Clear();
1321 dsGlbPerCon.Clear();
1322 }
1323 }
1324
1325 // clean everything up
1326 } catch (Exception ex) {
1327 MessageBox.Show("Create Global Contact Link Error: "+ex.Message);
1328 } finally {
1329 if (boPerConImpl!=null)
1330 boPerConImpl.Dispose();
1331
1332 if (parameters!=null)
1333 parameters.Clear();
1334
1335 if (dtGlbPerConExists!=null)
1336 dtGlbPerConExists.Clear();
1337 }
1338 }
1339
1340 void UpdateContact(int perCon, int custNum) {
1341 try {
1342 var boPerCon = WCFServiceSupport.CreateImpl<PerConImpl>((Session)oTrans.Session, "erp/bo/percon.svc");
1343 var dsPerCon = boPerCon.GetByID(perCon);
1344 var boCustCnt = WCFServiceSupport.CreateImpl<CustCntImpl>((Session)oTrans.Session, "erp/bo/custcnt.svc");
1345 var dsCustCnt = new CustCntDataSet();
1346 try {
1347 //add to customer
1348 boCustCnt.GetNewCustCnt(dsCustCnt, custNum, "");
1349 boCustCnt.GetPerConData(perCon, dsCustCnt);
1350 boCustCnt.Update(dsCustCnt);
1351 } catch (Exception ex) {
1352 DebugMsg(ex);
1353 } finally {
1354 boCustCnt.Dispose();
1355 dsCustCnt.Clear();
1356 }
1357
1358 boPerCon.Dispose();
1359 dsPerCon.Clear();
1360 } catch (Exception ex) {
1361 MessageBox.Show("Update Contact Error: "+ex.Message);
1362 }
1363 }
1364
1365 DataSet BOReaderData(string businessObject, string filter, string fieldList) {
1366 var ds = new DataSet();
1367 BOReaderImpl boReader = null;
1368 try {
1369 var session = (Session)oTrans.Session;
1370 boReader = WCFServiceSupport.CreateImpl<BOReaderImpl>(session, "ice/lib/BOReader.svc");
1371 ds = boReader.GetRows("Erp:BO:"+businessObject, filter, fieldList);
1372 } catch (Exception ex) {
1373 MessageBox.Show("Populate from BO error: "+ex.Message);
1374 } finally {
1375 if (boReader!=null)
1376 boReader.Dispose();
1377 }
1378
1379 return ds;
1380 }
1381
1382 void SetHeaderPriceListDropDown(int custNum, string shipToNum) {
1383 try {
1384 var parameters = new Hashtable();
1385 parameters.Add("pcustnum", custNum.ToString());
1386 parameters.Add("pshiptonum", shipToNum);
1387 //DataTable dt = GetQueryData("CPEPriceLists", parameters);
1388 var dtCustPriceLst = GetQueryData("CPE_CustomerPriceLists", parameters);
1389 var dtGrpPriceLst = GetQueryData("CPE_CustGrpPriceLists", parameters);
1390 foreach (DataRow grpRow in dtGrpPriceLst.Rows) {
1391 var exists = dtCustPriceLst.Select("Calculated_Value = '"+grpRow["Calculated_Value"]+"'");
1392 if (exists.Length<=0)
1393 dtCustPriceLst.ImportRow(grpRow);
1394 }
1395
1396 cmbHeaderPriceList.DataSource = dtCustPriceLst;
1397 cmbHeaderPriceList.DisplayMember = "Calculated_Display";
1398 cmbHeaderPriceList.ValueMember = "Calculated_Value";
1399 } catch (Exception ex) {
1400 MessageBox.Show("SetHeaderPriceList dropdown: "+ex.Message);
1401 }
1402 }
1403
1404 void SetVersionNumber() {
1405 SalesOrderForm.Text = SalesOrderForm.Text+" - Version "+m_version;
1406 }
1407
1408 void SetExtendedProperties() {
1409 // Begin Wizard Added EpiDataView Initialization
1410 // End Wizard Added EpiDataView Initialization
1411 // Begin Wizard Added Conditional Block
1412 if (edvOrderDtl.dataView.Table.Columns.Contains("PerConDropDown_c"))
1413 edvOrderDtl.dataView.Table.Columns["PerConDropDown_c"].ExtendedProperties["ReadOnly"] = true;
1414 if (edvOrderDtl.dataView.Table.Columns.Contains("PerConCorpName_c"))
1415 edvOrderDtl.dataView.Table.Columns["PerConCorpName_c"].ExtendedProperties["ReadOnly"] = true;
1416 if (edvOrderHed.dataView.Table.Columns.Contains("CommentsFromCustomer_c"))
1417 edvOrderHed.dataView.Table.Columns["CommentsFromCustomer_c"].ExtendedProperties["ReadOnly"] = true;
1418 // End Wizard Added Conditional Block
1419 }
1420
1421 bool GetLatestRev(string partNum, string site, out string rev) {
1422 var hasRev = false;
1423 rev = "";
1424 try {
1425 var parameters = new Hashtable();
1426 parameters.Add("ppartnum", partNum);
1427 parameters.Add("psite", site);
1428
1429 var dt = GetQueryData("CPELatestRevBySite", parameters);
1430 if (dt.Rows.Count>0) {
1431 rev = dt.Rows[0]["PartRev_RevisionNum"].ToString();
1432 hasRev = true;
1433 }
1434
1435 //MessageBox.Show("334: partnum:" + partNum + " site:" + site + " rev:" + rev);
1436 } catch (Exception ex) {
1437 MessageBox.Show("GetLastest rev error: "+ex.Message);
1438 }
1439
1440 return hasRev;
1441 }
1442
1443 int ChangeItem(bool bShow, int proposedValue, ref EpiDataView edv, string key, string adapter, Hashtable fromToHash) {
1444 var value = proposedValue;
1445 try {
1446 //if ( bShow )
1447 {
1448 bool recSelected;
1449 var where = "";
1450 if (bShow==false)
1451 where = key+" = "+proposedValue;
1452 var ds = SearchFunctions.listLookup(oTrans, adapter, out recSelected, bShow, where);
1453 if (bShow==false && recSelected==false) {
1454 MessageBox.Show("ChangeItem error: "+key+": "+proposedValue+" does not exist.");
1455 value = 0;
1456
1457 if (edv.Row>-1) {
1458 foreach (DictionaryEntry dic in fromToHash)
1459 edv.dataView.Table.Rows[edv.Row][dic.Key.ToString()] = 0;
1460 value = 0;
1461 }
1462 } else {
1463 if (edv.Row>-1)
1464 foreach (DictionaryEntry dic in fromToHash)
1465 if (key.Trim().ToLower() ==dic.ToString().Trim().ToLower()) {
1466 if (Convert.ToInt32(edv.dataView.Table.Rows[edv.Row][key])!=Convert.ToInt32(ds.Tables[0].Rows[0][dic.Value.ToString()]))
1467 edv.dataView.Table.Rows[edv.Row][key] = Convert.ToInt32(ds.Tables[0].Rows[0][dic.Value.ToString()]);
1468 value = Convert.ToInt32(ds.Tables[0].Rows[0][key]);
1469 } else {
1470 if (Convert.ToInt32(edv.dataView.Table.Rows[edv.Row][dic.Key.ToString()])!=Convert.ToInt32(ds.Tables[0].Rows[0][dic.Value.ToString()]))
1471 edv.dataView.Table.Rows[edv.Row][dic.Key.ToString()] = Convert.ToInt32(ds.Tables[0].Rows[0][dic.Value.ToString()]);
1472 }
1473 else
1474 value = 0;
1475 }
1476 }
1477 } catch (Exception ex) {
1478 MessageBox.Show("Change "+key+" error:"+ex.Message);
1479 }
1480
1481 return value;
1482 }
1483
1484 int ChangeContact(bool bShow, int proposedValue) {
1485 var fromToHash = new Hashtable();
1486 fromToHash.Add("PerCon_c", "PerConID");
1487 fromToHash.Add("PerConDropDown_c", "PerConID");
1488
1489 var perCon = ChangeItem(bShow, proposedValue, ref edvOrderDtl, "PerConID", "PerConAdapter", fromToHash);
1490 fromToHash.Clear();
1491
1492 return perCon;
1493 }
1494
1495 DataTable GetQueryData(string baqName, Hashtable parameters) {
1496 // ** Place Event Handling Code Here **
1497 var orgbaqName = baqName;
1498 var session = (Session)oTrans.Session;
1499 var adDynamicQuery = new DynamicQueryAdapter(oTrans);
1500 adDynamicQuery.BOConnect();
1501 try {
1502 adDynamicQuery.ClearDynamicQueryData();
1503 DynamicQueryDataSet baqQuery;
1504 try {
1505 baqQuery = adDynamicQuery.GetQueryDesignData(baqName) as DynamicQueryDataSet;
1506 } catch {
1507 baqName = session.CompanyID+"-"+baqName;
1508 baqQuery = adDynamicQuery.GetQueryDesignData(baqName) as DynamicQueryDataSet;
1509 }
1510
1511 var executionDS = adDynamicQuery.GetQueryExecutionParametersByID(baqName);
1512 if (baqQuery !=null && executionDS!=null) {
1513 for (var i = 0; i<executionDS.ExecutionParameter.Rows.Count; i++) {
1514 var executeParams = executionDS.ExecutionParameter[i]["ParameterID"].ToString().Trim().ToLower();
1515 if (parameters.Contains(executeParams))
1516 executionDS.ExecutionParameter[i]["ParameterValue"] = parameters[executeParams].ToString();
1517 }
1518
1519 executionDS.AcceptChanges();
1520
1521 adDynamicQuery.Execute(baqQuery, executionDS);
1522 } else {
1523 MessageBox.Show("GetQueryData error1: "+baqName+" not found.");
1524 }
1525 } catch (Exception ex) {
1526 MessageBox.Show("GetQueryData2:Error running BAQ "+orgbaqName+" or "+baqName+":"+ex.Message);
1527 }
1528
1529 var dataTable = adDynamicQuery.QueryResults.Tables[0]; //.Copy();
1530 adDynamicQuery.Dispose();
1531 return dataTable;
1532 }
1533
1534 void SetGridDropDown(UltraGrid grid, string columnName, string BAQ) {
1535 try {
1536 grid.DisplayLayout.Bands[0].Columns[columnName].Style = ColumnStyle.DropDownValidate;
1537 var theList = new ValueList();
1538 var parameters = new Hashtable();
1539
1540 var dt = GetQueryData(BAQ, parameters);
1541
1542 foreach (DataRow row in dt.Rows)
1543 theList.ValueListItems.Add(row["Calculated_Display"].ToString(), row["Calculated_Value"].ToString());
1544
1545 grid.DisplayLayout.Bands[0].Columns[columnName].ValueList = theList;
1546 } catch (Exception ex) {
1547 MessageBox.Show("Modify Grid error: "+ex.Message);
1548 }
1549 }
1550
1551 void SetGridDropDown(UltraGrid grid, string columnName, string[] color_array) {
1552 try {
1553 grid.DisplayLayout.Bands[0].Columns[columnName].Style = ColumnStyle.DropDownValidate;
1554 var theList = new ValueList();
1555 foreach (var color in color_array)
1556 theList.ValueListItems.Add(color);
1557 grid.DisplayLayout.Bands[0].Columns[columnName].ValueList = theList;
1558 } catch (Exception ex) {
1559 MessageBox.Show("Modify Grid error: "+ex.Message);
1560 }
1561 }
1562
1563 void SetGridDropDown(UltraGrid grid, string columnName, List<string> color_array) {
1564 try {
1565 grid.DisplayLayout.Bands[0].Columns[columnName].Style = ColumnStyle.DropDownValidate;
1566 var theList = new ValueList();
1567 foreach (var color in color_array)
1568 theList.ValueListItems.Add(color);
1569 grid.DisplayLayout.Bands[0].Columns[columnName].ValueList = theList;
1570 } catch (Exception ex) {
1571 MessageBox.Show("Modify Grid error: "+ex.Message);
1572 }
1573 }
1574
1575 void CopyFromPrevious(bool bCopyContact) {
1576 try {
1577 if (edvOrderDtl.Row<=0)
1578 return;
1579 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["RowMod"].ToString()!="A")
1580 return;
1581 m_copying = true;
1582 foreach (DataColumn column in edvOrderDtl.dataView.Table.Columns)
1583 if (m_hashCopyColumns.Contains(column.ColumnName.ToLower()))
1584 if (bCopyContact==false &&
1585 (column.ColumnName.ToLower().StartsWith("percon") || column.ColumnName.ToLower().StartsWith("employeenum_c"))) { }
1586 else if (
1587 bCopyContact ==false &&
1588 (column.ColumnName.ToLower()=="cpe_mouldright_c" || column.ColumnName.ToLower()=="cpe_mouldleft_c" ||
1589 column.ColumnName.ToLower()=="cpe_cast_c")) { } else {
1590 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row][column.ColumnName] = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row-1][column.ColumnName];
1591 }
1592
1593 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["DocUnitPrice"] = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row-1]["DocUnitPrice"];
1594 m_copying = false;
1595 } catch (Exception ex) {
1596 MessageBox.Show("Copy from previous error: "+ex.Message);
1597 }
1598 }
1599
1600 public class ContactSearch : Form {
1601 public string columnName;
1602 public string selectedValue;
1603 public bool m_bSelected;
1604 public string m_server;
1605 public string m_user;
1606 public string m_password;
1607 public string m_dataBase;
1608 public string m_select;
1609 public bool m_multiSelect;
1610 public DataTable m_dtSelected;
1611 public DataTable m_dtResults;
1612
1613 Button btnSelect;
1614 Button btnCancel;
1615 DataGridView dataGridView1;
1616 readonly IContainer components = null;
1617
1618 public ContactSearch(string title) {
1619 InitializeComponent();
1620
1621 m_dtSelected = new DataTable();
1622
1623 Text = title;
1624 }
1625
1626 public bool InitSearch(string server, string database, string password, string user, string select, bool multiselect, out bool nothingFound, bool newRow,
1627 out string oneRecord) {
1628 oneRecord = "";
1629 nothingFound = false;
1630 m_bSelected = false;
1631 m_server = server;
1632 m_password = password;
1633 m_user = user;
1634 m_dataBase = database;
1635 m_select = select;
1636 m_multiSelect = multiselect;
1637 dataGridView1.MultiSelect = multiselect;
1638
1639 return LoadGrid(out nothingFound, out oneRecord, newRow);
1640 }
1641
1642 protected override void Dispose(bool disposing) {
1643 m_dtSelected.Dispose();
1644 m_dtSelected = null;
1645 if (disposing && components!=null)
1646 components.Dispose();
1647 base.Dispose(disposing);
1648 }
1649
1650 void InitializeComponent() {
1651 btnSelect = new Button();
1652 btnCancel = new Button();
1653 dataGridView1 = new DataGridView();
1654 ((ISupportInitialize)dataGridView1).BeginInit();
1655 SuspendLayout();
1656 //
1657 // btnSelect
1658 //
1659 btnSelect.Location = new Point(12, 192);
1660 btnSelect.Name = "btnSelect";
1661 btnSelect.Size = new Size(117, 26);
1662 btnSelect.TabIndex = 0;
1663 btnSelect.Text = "Select";
1664 btnSelect.UseVisualStyleBackColor = true;
1665 btnSelect.Click += btnSelect_Click;
1666 //
1667 // btnCancel
1668 //
1669 btnCancel.Location = new Point(135, 192);
1670 btnCancel.Name = "btnCancel";
1671 btnCancel.Size = new Size(117, 26);
1672 btnCancel.TabIndex = 1;
1673 btnCancel.Text = "Cancel";
1674 btnCancel.UseVisualStyleBackColor = true;
1675 btnCancel.Click += btnCancel_Click;
1676 //
1677 // dataGridView1
1678 //
1679 dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
1680 dataGridView1.Location = new Point(12, 12);
1681 dataGridView1.Name = "dataGridView1";
1682 dataGridView1.Size = new Size(840, 174);
1683 dataGridView1.TabIndex = 2;
1684 dataGridView1.CellContentClick += dataGridView1_CellContentClick;
1685 dataGridView1.CellDoubleClick += dataGridView1_CellDoubleClick;
1686 dataGridView1.Anchor = AnchorStyles.Top|AnchorStyles.Right|AnchorStyles.Left;
1687 //
1688 // Form1
1689 //
1690 AutoScaleDimensions = new SizeF(6F, 13F);
1691 AutoScaleMode = AutoScaleMode.Font;
1692 ClientSize = new Size(860, 230);
1693 Controls.Add(dataGridView1);
1694 Controls.Add(btnCancel);
1695 Controls.Add(btnSelect);
1696 Name = "Form1";
1697 Text = "Person / Contact";
1698 Load += Form1_Load;
1699 ((ISupportInitialize)dataGridView1).EndInit();
1700 ResumeLayout(false);
1701 }
1702
1703 void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { }
1704
1705 void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) {
1706 m_dtSelected = ((DataTable)dataGridView1.DataSource).Clone();
1707 var row = ((DataRowView)dataGridView1.Rows[e.RowIndex].DataBoundItem).Row;
1708 m_dtSelected.ImportRow(row);
1709 m_bSelected = true;
1710 //MessageBox.Show(m_dtSelected.Rows[0][0].ToString());
1711 Close();
1712 }
1713
1714 bool LoadGrid(out bool nothingFound, out string oneRecord, bool newRow) {
1715 var bHasResults = false;
1716 nothingFound = false;
1717 oneRecord = "";
1718 try {
1719 dataGridView1.DataSource = null;
1720 m_dtResults = SQLExecuteSelect(m_select);
1721 if (m_dtResults.Rows.Count >0) {
1722 if (m_dtResults.Rows.Count==1)
1723 oneRecord = m_dtResults.Rows[0][0].ToString();
1724 if (newRow) {
1725 var theNewRow = m_dtResults.NewRow();
1726 theNewRow[0] = "New";
1727 for (var index = 1; index<m_dtResults.Columns.Count; ++index)
1728 try {
1729 theNewRow[index] = "";
1730 } catch {
1731 try {
1732 theNewRow[index] = 0;
1733 } catch (Exception ex) { }
1734 }
1735
1736 m_dtResults.Rows.Add(theNewRow);
1737 }
1738
1739 bHasResults = true;
1740 dataGridView1.DataSource = m_dtResults;
1741 dataGridView1.Rows[0].Selected = true;
1742 } else {
1743 nothingFound = true;
1744 }
1745 } catch (Exception ex) {
1746 MessageBox.Show("LoadGrid error: "+ex.Message);
1747 }
1748
1749 return bHasResults;
1750 }
1751
1752 void Form1_Load(object sender, EventArgs e) {
1753 dataGridView1.AllowUserToAddRows = false;
1754 dataGridView1.ReadOnly = true;
1755
1756 m_bSelected = false;
1757 }
1758
1759 void btnCancel_Click(object sender, EventArgs e) {
1760 Close();
1761 }
1762
1763 void btnSelect_Click(object sender, EventArgs e) {
1764 //MessageBox.Show("btnSelect_Click: 1797");
1765 if (dataGridView1.SelectedRows.Count>0) {
1766 m_dtSelected = ((DataTable)dataGridView1.DataSource).Clone();
1767 for (var index = 0; index<dataGridView1.SelectedRows.Count; ++index) {
1768 var row = ((DataRowView)dataGridView1.SelectedRows[index].DataBoundItem).Row;
1769 m_dtSelected.ImportRow(row);
1770 m_bSelected = true;
1771 }
1772
1773 /*string id = "\n";
1774 foreach (DataRow row in m_dtSelected.Rows)
1775 {
1776 id += row[0].ToString() + "\n";
1777 }
1778 MessageBox.Show(id);*/
1779 Close();
1780 } else {
1781 MessageBox.Show("Nothing selected.");
1782 }
1783 }
1784
1785 SqlConnection GetSQLConnection() {
1786 try {
1787 var SQLCon = new SqlConnection();
1788 var timeout = "3000";
1789 var connectionString = "Persist Security Info=false;Integrated Security=false;database="+m_dataBase+";User ID="+m_user+";password="+m_password+";server="+m_server+
1790 ";Connect Timeout=" +timeout;
1791 SQLCon.ConnectionString = connectionString;
1792 SQLCon.Open();
1793 return SQLCon;
1794 } catch (Exception ex) {
1795 MessageBox.Show("GetSQLConnection error: "+ex.Message);
1796 }
1797
1798 return null;
1799 }
1800
1801 DataTable SQLExecuteSelect(string selectStatement) {
1802 var dt = new DataTable();
1803 try {
1804 var SQLCon = GetSQLConnection();
1805 var command = new SqlCommand(selectStatement, SQLCon);
1806 command.CommandTimeout = 90;
1807 var reader = command.ExecuteReader();
1808 dt.Load(reader);
1809 DisconnectCon(SQLCon);
1810 // set readonly = false
1811 foreach (DataColumn col in dt.Columns)
1812 col.ReadOnly = false;
1813 } catch (Exception ex) {
1814 MessageBox.Show("Select statement error "+ex.Message+"\n\n"+selectStatement);
1815 }
1816
1817 return dt;
1818 }
1819
1820 void DisconnectCon(SqlConnection SQLCon) {
1821 try {
1822 SQLCon.Close();
1823 } catch (Exception ex) { }
1824 }
1825 }
1826
1827 bool LaunchSearch(string select) {
1828 return LaunchSearch(select, true);
1829 }
1830
1831 bool LaunchSearch(string select, bool bAlwaysShow) {
1832 txtQuery.Text = select;
1833 var nothingFound = false;
1834 try {
1835 string oneRow;
1836 if (m_ContactSearch.InitSearch(SQLServer, Database, SQLPass, SQLUser, select, false, out nothingFound, false, out oneRow)) {
1837 if (string.IsNullOrEmpty(oneRow) || bAlwaysShow)
1838 m_ContactSearch.ShowDialog();
1839 else
1840 m_ContactSearch.m_bSelected = true;
1841 if (m_ContactSearch.m_bSelected) {
1842 grdDtlList.ActiveCell = grdDtlList.ActiveRow.Cells["PartNum"];
1843 grdDtlList.PerformAction(UltraGridAction.EnterEditMode, false, false);
1844 var perConID = Convert.ToInt32(m_ContactSearch.m_dtSelected.Rows[0]["PerConID"]);
1845
1846 //greg - percon has been selected. Query to see if there's any comments on the contact and show in messagebox if so.
1847 //string select2 = "SELECT Comment FROM ERP.PerCon pc WHERE pc.Company = '" + ((Ice.Core.Session)oTrans.Session).CompanyID + "' AND pc.PerConID = " + perConID;
1848 if (m_ContactSearch.m_dtSelected.Rows[0]["Comment"]!=DBNull.Value) {
1849 var temp = m_ContactSearch.m_dtSelected.Rows[0]["Comment"].ToString();
1850 if (!string.IsNullOrEmpty(temp))
1851 MessageBox.Show("LaunchSearch error: "+temp);
1852 }
1853
1854 if (m_ContactSearch.m_dtSelected.Rows[0]["LastName"] !=DBNull.Value)
1855 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"].ToString()!=m_ContactSearch.m_dtSelected.Rows[0]["LastName"].ToString())
1856 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConLastName_c"] = m_ContactSearch.m_dtSelected.Rows[0]["LastName"].ToString();
1857 if (m_ContactSearch.m_dtSelected.Rows[0]["FirstName"] !=DBNull.Value)
1858 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"].ToString()!=m_ContactSearch.m_dtSelected.Rows[0]["FirstName"].ToString())
1859 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConFirstName_c"] = m_ContactSearch.m_dtSelected.Rows[0]["FirstName"].ToString();
1860
1861 if (m_ContactSearch.m_dtSelected.Rows[0]["DOB"] !=DBNull.Value)
1862 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConDOB_c"].ToString()!=m_ContactSearch.m_dtSelected.Rows[0]["DOB"].ToString())
1863 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConDOB_c"] = m_ContactSearch.m_dtSelected.Rows[0]["DOB"];
1864
1865 if (m_ContactSearch.m_dtSelected.Rows[0]["EmployeeNum"] !=DBNull.Value)
1866 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"].ToString()!=m_ContactSearch.m_dtSelected.Rows[0]["EmployeeNum"].ToString())
1867 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["EmployeeNum_c"] = m_ContactSearch.m_dtSelected.Rows[0]["EmployeeNum"];
1868
1869 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"].ToString()!=m_ContactSearch.m_dtSelected.Rows[0]["Company"].ToString())
1870 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerConCorpName_c"] = m_ContactSearch.m_dtSelected.Rows[0]["Company"];
1871
1872 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"].ToString()!=perConID.ToString())
1873 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PerCon_c"] = perConID;
1874 if (edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["PartNum"].ToString().EndsWith("R")) {
1875 var newselect = "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', " +" case when PerCon_1_2_c = "+
1876 perConID +
1877 " then '1' when PerCon_3_4_c = " +perConID +
1878 " then '3' when PerCon_5_6_c = " +perConID +" then '5' when PerCon_7_8_c = "+perConID+
1879 " then '7' when PerCon_9_10_c = " +perConID +
1880 " then '9' else '' end as RightMould, " +" case when PerCon_1_2_c = " +perConID+
1881 " then '2' when PerCon_3_4_c = " +perConID +
1882 " then '4' when PerCon_5_6_c = " +perConID +" then '6' when PerCon_7_8_c = "+perConID+
1883 " then '8' when PerCon_9_10_c = " +perConID +
1884 " then '10' else '' end as LeftMould, " +" case when PerCon_1_2_c = " +perConID+
1885 " then lotnum + '1-2' when PerCon_3_4_c = " +perConID +
1886 " then lotnum + '3-4' when PerCon_5_6_c = " +perConID +
1887 " then lotnum + '5-6' when PerCon_7_8_c = " +perConID +
1888 " then lotnum + '7-8' when PerCon_9_10_c = " +perConID +
1889 " then lotnum + '9-10' else '' end as SerialNo, " +" case when PerCon_1_2_c = " +
1890 perConID +" then PerCon_1_2_Notes_c when PerCon_3_4_c = "+
1891 perConID +" then PerCon_3_4_Notes_c when PerCon_5_6_c = "+
1892 perConID +" then PerCon_5_6_Notes_c when PerCon_7_8_c = "+perConID+
1893 " then PerCon_7_8_Notes_c when PerCon_9_10_c = " +perConID +
1894 " then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot where company = '"+((Session)oTrans.Session).CompanyID +
1895 "' and expirationdate > GETDATE() and ( PerCon_1_2_c = " +perConID +
1896 " or PerCon_3_4_c = " +perConID +" or PerCon_5_6_c = "+perConID+
1897 " or PerCon_7_8_c = " +perConID +
1898 " or PerCon_9_10_c = " +perConID +")";
1899 // "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date' from erp.partlot where company = '" + ((Ice.Core.Session)oTrans.Session).CompanyID + "' and lotnum in (select distinct(pl.lotnum) from erp.partlot as pl with (nolock) join dbo.PlantConfCtrl as pcc with (nolock) on pl.company = pcc.company and pl.partnum = pcc.CastPartNum_c and pcc.plant = '" + ((Ice.Core.Session)oTrans.Session).PlantID + "' and pcc.company = '" + ((Ice.Core.Session)oTrans.Session).CompanyID + "' join dbo.orderdtl as od with (nolock) on od.company = pl.company and pl.lotnum = od.CPE_Cast_c join dbo.PerCon as pc with (nolock) on pc.company = od.company and pc.PerConID = od.PerCon_c where pc.PerConID = " + perConID.ToString() + " and pl.expirationdate > GETDATE())";
1900 if (((Session)oTrans.Session).CompanyID=="250")
1901 select =
1902 "select lotnum as 'Cast_Number', ExpirationDate as 'Expiration-Date', " +
1903 " case when PerCon_1_2_c = glb.perconid then '1' when PerCon_3_4_c = glb.perconid then '3' when PerCon_5_6_c = glb.perconid then '5' when PerCon_7_8_c = glb.perconid then '7' when PerCon_9_10_c = glb.perconid then '9' else '' end as RightMould, " +
1904 " case when PerCon_1_2_c = glb.perconid then '2' when PerCon_3_4_c = glb.perconid then '4' when PerCon_5_6_c = glb.perconid then '6' when PerCon_7_8_c = glb.perconid then '8' when PerCon_9_10_c = glb.perconid then '10' else '' end as LeftMould, " +
1905 " case when PerCon_1_2_c = glb.perconid then lotnum + '1-2' when PerCon_3_4_c = glb.perconid then lotnum + '3-4' when PerCon_5_6_c = glb.perconid then lotnum + '5-6' when PerCon_7_8_c = glb.perconid then lotnum + '7-8' when PerCon_9_10_c = glb.perconid then lotnum + '9-10' else '' end as SerialNo, " +
1906 " case when PerCon_1_2_c = glb.perconid then PerCon_1_2_Notes_c when PerCon_3_4_c = glb.perconid then PerCon_3_4_Notes_c when PerCon_5_6_c = glb.perconid then PerCon_5_6_Notes_c when PerCon_7_8_c = glb.perconid then PerCon_7_8_Notes_c when PerCon_9_10_c = glb.perconid then PerCon_9_10_Notes_c else '' end as Notes from dbo.partlot as pl with (nolock) join erp.glbpercon as glb with (nolock) on pl.company = glb.company and glb.glbperconid = "+
1907 perConID +
1908 " and ( pl.PerCon_1_2_c = glb.perconid or pl.PerCon_3_4_c = glb.perconid or pl.PerCon_5_6_c = glb.perconid or pl.PerCon_7_8_c = glb.perconid or pl.PerCon_9_10_c = glb.perconid ) where pl.company = '200' and expirationdate > GETDATE() ";
1909 // MessageBox.Show("2138");
1910 //txtQuery.Text = select;
1911 LaunchCastSearch(newselect, false);
1912 }
1913 }
1914 }
1915 } catch (Exception ex) {
1916 MessageBox.Show("Launch Search error: "+ex.Message+"\n\n"+select);
1917 }
1918
1919 return nothingFound;
1920 }
1921
1922 void LaunchCastSearch(string select, bool bAlwaysShow) {
1923 txtQuery.Text = select;
1924 bool nothingFound;
1925 try {
1926 string oneCastNum;
1927 var salesUM = edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["SalesUM"].ToString().Trim().ToLower();
1928 if (m_CastSearch.InitSearch(SQLServer, Database, SQLPass, SQLUser, select, false, out nothingFound, true, out oneCastNum)) {
1929 if (string.IsNullOrEmpty(oneCastNum) || bAlwaysShow) {
1930 m_CastSearch.ShowDialog();
1931 if (m_CastSearch.m_bSelected) {
1932 grdDtlList.ActiveCell = grdDtlList.ActiveRow.Cells["PartNum"];
1933 grdDtlList.PerformAction(UltraGridAction.EnterEditMode, false, false);
1934 var castNum = Convert.ToString(m_CastSearch.m_dtSelected.Rows[0]["Cast_Number"]);
1935 var leftMould = Convert.ToString(m_CastSearch.m_dtSelected.Rows[0]["leftMould"]);
1936 var rightMould = Convert.ToString(m_CastSearch.m_dtSelected.Rows[0]["rightMould"]);
1937 if (castNum.ToLower()=="new") {
1938 castNum = "";
1939 leftMould = "";
1940 rightMould = "";
1941 }
1942
1943 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_Cast_c"] = castNum;
1944 if (salesUM=="pr" || salesUM=="right" || salesUM=="ea")
1945 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldRight_c"] = rightMould;
1946 if (salesUM=="pr" || salesUM=="left" || salesUM=="ea")
1947 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldLeft_c"] = leftMould;
1948 }
1949 } else if (!string.IsNullOrEmpty(oneCastNum)) {
1950 try {
1951 var leftMould = Convert.ToString(m_CastSearch.m_dtResults.Rows[0]["leftMould"]);
1952 var rightMould = Convert.ToString(m_CastSearch.m_dtResults.Rows[0]["rightMould"]);
1953 if (salesUM=="pr" || salesUM=="right" || salesUM=="ea")
1954 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldRight_c"] = rightMould;
1955 if (salesUM=="pr" || salesUM=="left" || salesUM=="ea")
1956 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldLeft_c"] = leftMould;
1957
1958 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldRight_c"] = rightMould;
1959
1960 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldLeft_c"] = leftMould;
1961 } catch (Exception ex) {
1962 DebugMsg(ex);
1963 }
1964
1965 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_Cast_c"] = oneCastNum;
1966 }
1967 } else {
1968 try {
1969 var leftMould = Convert.ToString(m_CastSearch.m_dtResults.Rows[0]["leftMould"]);
1970 var rightMould = Convert.ToString(m_CastSearch.m_dtResults.Rows[0]["rightMould"]);
1971 if (salesUM=="pr" || salesUM=="right" || salesUM=="ea")
1972 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldRight_c"] = rightMould;
1973 if (salesUM=="pr" || salesUM=="left" || salesUM=="ea")
1974 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_DspMouldLeft_c"] = leftMould;
1975 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldRight_c"] = rightMould;
1976 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_MouldLeft_c"] = leftMould;
1977 } catch (Exception ex) {
1978 DebugMsg(ex);
1979 }
1980
1981 edvOrderDtl.dataView.Table.Rows[edvOrderDtl.Row]["CPE_Cast_c"] = oneCastNum;
1982 }
1983 } catch (Exception ex) {
1984 MessageBox.Show("Launch Cast Search error: "+ex.Message);
1985 }
1986 }
1987}