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