Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.87 KB | None | 0 0
  1. //
  2.  
  3. // Name: MRN_PLM_DialogChange
  4.  
  5. // Description: Retreive all Parts with classification Finished Good as well the last ExportDefinition from MRN_PLM_ExportDefinition, that is enabled and with target system: Dialoge. Get the information to be extracted fromn the ExportDefinition. Generate two files according of the triggering event in the Reletionship: IDENT6 and Measure. According of the relationships and the itemType, InfoType, Information,DafaultValue, ItemInformaton, ExportPosition, StartPosition and Length, as well Usage(for Document in Labaling Item) and Prioryty(list with two values: Priminary and Alternative).The method will be run from the Scheduler.
  6.  
  7. // Called by: Executed by the Scheduler
  8.  
  9. // <02-Dec-2019> - Kostadin Markov - code for Mersen
  10.  
  11. //======================================================================I
  12.  
  13. Innovator inn = this.getInnovator();
  14.  
  15. System.Diagnostics.Debugger.Break();
  16.  
  17. Item someExportDefinitions = inn.newItem("MRN_PLM_ExportDefinition", "get");
  18. someExportDefinitions.setProperty("mrn_plm_target_system", "DIALOGUE");
  19. someExportDefinitions.setProperty("mrn_plm_is_enabled", "1");
  20. someExportDefinitions = someExportDefinitions.apply();
  21.  
  22. string assas = someExportDefinitions.getID();
  23.  
  24. someExportDefinitions.fetchRelationships("MRN_PLM_ExportDefinitionRel");
  25. Item someRelationships = someExportDefinitions.getRelationships("MRN_PLM_ExportDefinitionRel");
  26. int count = someRelationships.getItemCount();
  27.  
  28. //string triggeringEvent = null;
  29. string itemType = null;
  30. string infoType = null;
  31. string information = null;
  32. string defaultValue = null;
  33. string itemInformation = null;
  34. //string exportPosition = null;
  35. string startPosition = null;
  36. string length = null;
  37. string usage = null;
  38. string priority = null;
  39.  
  40.  
  41. Item someFinishedGood = inn.newItem("Part", "get");
  42. someFinishedGood.setAttribute("where", "[Part].classification='Finished good' AND [Part].state='Released'");
  43. //someFinishedGood.setAttribute("where", "[Part].state='Released'");
  44. someFinishedGood = someFinishedGood.apply();
  45.  
  46. int countOfFinishedGoods = someFinishedGood.getItemCount();
  47. List<Item> allNeededFinishedGoods = new List<Item>();
  48.  
  49. for(int ib = 0; ib < countOfFinishedGoods; ib++)
  50. {
  51. Item ourFG = someFinishedGood.getItemByIndex(ib);
  52. allNeededFinishedGoods.Add(ourFG);
  53. }
  54.  
  55. int fdf = allNeededFinishedGoods.Count();
  56.  
  57. Item variable = inn.newItem("Variable", "get");
  58. variable.setProperty("name", "MRN_PLM_DialogueExport");
  59. variable = variable.apply();
  60.  
  61. string filePath = variable.getProperty("value", "");
  62.  
  63. //int countOfPartsNeeded = someFinishedGood.getItemCount();
  64.  
  65. string fileParthNameIdent = filePath + "\\" + "IDENT6.txt";
  66. string fileParthNameMesure = filePath + "\\" + "MESURE.txt";
  67.  
  68. StreamWriter id = new StreamWriter(fileParthNameIdent);
  69. StreamWriter me = new StreamWriter(fileParthNameMesure);
  70.  
  71. List<Item> IDENT6_LIST = new List<Item>();
  72. List<Item> MEASURE_LIST = new List<Item>();
  73.  
  74. for(int ia = 0; ia < count; ia++)
  75. {
  76. Item rel = someRelationships.getItemByIndex(ia);
  77. string relEvent = rel.getProperty("mrn_plm_triggering_event");
  78.  
  79. //exportPosition = Convert.ToInt32(rel.getProperty("mrn_plm_exportposition"));
  80. if(relEvent == "IDENT6")
  81. {
  82. IDENT6_LIST.Add(rel);
  83. }
  84. else if(relEvent == "MESURE")
  85. {
  86. MEASURE_LIST.Add(rel);
  87. }
  88. }
  89.  
  90. int identCount = IDENT6_LIST.Count;
  91. int measureCount = MEASURE_LIST.Count;
  92.  
  93. CompareItem comp = new CompareItem();
  94. IDENT6_LIST.Sort(comp);
  95. MEASURE_LIST.Sort(comp);
  96. allNeededFinishedGoods.Sort(comp);
  97.  
  98. Item last = null;
  99. Item lastMeasure = null;
  100.  
  101. if(identCount > 0)
  102. {
  103. last = IDENT6_LIST.Last();
  104. }
  105. if(measureCount > 0){
  106. lastMeasure = MEASURE_LIST.Last();
  107. }
  108.  
  109. System.Diagnostics.Debugger.Break();
  110.  
  111. string wantedProperty = null;
  112. foreach(Item finishedGood in allNeededFinishedGoods)
  113. {
  114. wantedProperty = "";
  115. foreach(Item itemItm in IDENT6_LIST)
  116. {
  117. itemType = itemItm.getProperty("mrn_plm_item_type", "");
  118. infoType = itemItm.getProperty("mrn_plm_info_type", "");
  119. information = itemItm.getProperty("mrn_plm_information", "");
  120. defaultValue = itemItm.getProperty("mrn_plm_defaut_value", "");
  121. itemInformation = itemItm.getProperty("mrn_plm_item_information", "");
  122. //exportPosition = itemItm.getProperty("mrn_plm_exportposition");
  123. startPosition = itemItm.getProperty("mrn_plm_start_position", "");
  124. length = itemItm.getProperty("mrn_plm_length", "");
  125. usage = itemItm.getProperty("mrn_plm_usage_doc", "");
  126. priority = itemItm.getProperty("mrn_plm_priority", "");
  127. string value = null;
  128. string labItemId = finishedGood.getProperty("mrn_plm_label_item", "");
  129.  
  130. if((itemType == "Item" || itemType == "Generic Label Item" || itemType == "Product Label Item" || itemType == "R35" || itemType == "MSL" || itemType == "Frame" || itemType == "Certificatio") && (infoType == "DateTime-YYMMDDhhmm" || infoType == "Date-MM/DD/YYYY"))
  131. {
  132.  
  133. if(infoType == "DateTime-YYMMDDhhmm")
  134. {
  135. DateTime dt = DateTime.Now;;
  136. if (information == "Today") {dt = DateTime.Now;}
  137. if (information == "Yesterday") {dt = dt.AddDays(-1);}
  138. if (information == "Tomorrow") {dt = dt.AddDays(1);}
  139. value = dt.ToString("yyMMddHHmm");
  140. for(int f = 0; f < int.Parse(length); f++)
  141. {
  142. if(defaultValue == "") defaultValue = " ";
  143. if(value == "") value = defaultValue;
  144. if(value == null || f >= value.Length)
  145. {
  146. wantedProperty += " ";
  147. continue;
  148. }
  149. wantedProperty += value[f];
  150. }
  151. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  152. {
  153.  
  154. return inn.newError("Please Look at the table");
  155. }
  156. }
  157. else if(infoType == "Date-MM/DD/YYYY")
  158. {
  159.  
  160. DateTime dte = DateTime.Now;
  161. if (information == "Today") {dte = DateTime.Now;}
  162. if (information == "Yesterday") {dte = dte.AddDays(-1);}
  163. if (information == "Tomorrow") {dte = dte.AddDays(1);}
  164. value = dte.ToString(@"MM\/dd\/yyyy");
  165. for(int f = 0; f < int.Parse(length); f++)
  166. {
  167. if(defaultValue == "") defaultValue = " ";
  168. if(value == "") value = defaultValue;
  169. if(value == null || f >= value.Length)
  170. {
  171. wantedProperty += " ";
  172. continue;
  173. }
  174. wantedProperty += value[f];
  175. }
  176. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  177. {
  178.  
  179. return inn.newError("Please Look at the table");
  180. }
  181. }
  182. }
  183. else if(itemType == "Item")
  184. {
  185. int d = wantedProperty.Length;
  186. switch(infoType)
  187. {
  188. case "Property":
  189. value = finishedGood.getProperty(information, "");
  190. for(int s = 0; s < int.Parse(length); s++)
  191. {
  192. if(defaultValue == "") defaultValue = " ";
  193. if(value == "") value = defaultValue;
  194. if(value == null || s >= value.Length)
  195. {
  196. wantedProperty += " ";
  197. continue;
  198. }
  199. wantedProperty += value[s];
  200. }
  201.  
  202. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  203. {
  204.  
  205. return inn.newError("Please Look at the table");
  206. }
  207. break;
  208. }
  209. }
  210.  
  211. else if(itemType == "Generic Label Item")
  212. {
  213.  
  214. switch(infoType)
  215. {
  216. case "Property":
  217. if(labItemId != "")
  218. {
  219. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  220. value = ourLabItem.getProperty(information);
  221. }
  222. else value = " ";
  223. for(int s = 0; s < int.Parse(length); s++)
  224. {
  225. if(defaultValue == "") defaultValue = " ";
  226. if(value == "") value = defaultValue;
  227. if(value == null || s >= value.Length)
  228. {
  229. wantedProperty += " ";
  230. continue;
  231. }
  232. wantedProperty += value[s];
  233. }
  234. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  235. {
  236.  
  237. return inn.newError("Please Look at the table");
  238. }
  239. break;
  240. case "ItemPropertyItem":
  241. Item myStockPart = null;
  242. string myStockPartId = null;
  243. string cItem = finishedGood.getProperty("mrn_plm_label_item", "");
  244. Item ssd = null;
  245. if(cItem != "")
  246. ssd = inn.getItemById("mrn_plm_labeling_item", cItem);
  247.  
  248. if(ssd != null)
  249. myStockPartId = ssd.getProperty(information);
  250.  
  251. if(myStockPartId != null)
  252. {
  253. myStockPart = inn.getItemById("Part", myStockPartId);
  254. value = myStockPart.getProperty(itemInformation, "");
  255. }
  256.  
  257. else value = "";
  258.  
  259. for(int s = 0; s < int.Parse(length); s++)
  260. {
  261. if(defaultValue == "") defaultValue = " ";
  262. if(value == "") value = defaultValue;
  263. if(value == null || s >= value.Length)
  264. {
  265. wantedProperty += " ";
  266. continue;
  267. }
  268. wantedProperty += value[s];
  269. }
  270. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  271. {
  272. return inn.newError("Please Look at the table");
  273. }
  274. break;
  275. case "Document":
  276.  
  277. if(labItemId != "")
  278. {
  279. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  280.  
  281. ourLabItem.fetchRelationships("mrn_plm_label_item_doc");
  282. Item docRelationships = ourLabItem.getRelationships("mrn_plm_label_item_doc");
  283.  
  284. int docRelCount = docRelationships.getItemCount();
  285.  
  286. for(int f = 0; f < docRelCount; f++)
  287. {
  288. Item currDoc = docRelationships.getItemByIndex(f);
  289. var docUsage = currDoc.getProperty("mrn_plm_usage");
  290. if(docUsage == usage)
  291. {
  292. value = currDoc.getProperty(information);
  293. break;
  294. }
  295. }
  296.  
  297. var nextItem = 0;
  298.  
  299. if(value ==null)
  300. {
  301. nextItem = IDENT6_LIST.Select(itm => itm.getProperty("mrn_plm_start_position") == startPosition && itm.getProperty("mrn_plm_priority") == "Alternative").Count();
  302. }
  303.  
  304. if(nextItem >= 2 && priority == "Preminary") break;
  305. //else value = "";
  306.  
  307. for(int s = 0; s < int.Parse(length); s++)
  308. {
  309. if(defaultValue == "") defaultValue = " ";
  310. if(value == "") value = defaultValue;
  311. if(value == null || s >= value.Length)
  312. {
  313. wantedProperty += " ";
  314. continue;
  315. }
  316. wantedProperty += value[s];
  317. }
  318. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  319. {
  320. return inn.newError("Please Look at the table");
  321. }
  322. }
  323.  
  324. else
  325. {
  326. value = " ";
  327. for(int s = 0; s < int.Parse(length); s++)
  328. {
  329. if(defaultValue == "") defaultValue = " ";
  330. if(value == "") value = defaultValue;
  331. if(value == null || s >= value.Length)
  332. {
  333. wantedProperty += " ";
  334. continue;
  335. }
  336. wantedProperty += value[s];
  337. }
  338. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  339. {
  340. return inn.newError("Please Look at the table");
  341. }
  342. }
  343.  
  344. break;
  345. }
  346. }
  347.  
  348. else if(itemType == "Product Label Item")
  349. {
  350. switch(infoType)
  351. {
  352. case "Property":
  353. if(labItemId != "")
  354. {
  355. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  356. value = ourLabItem.getProperty(information, "");
  357. }
  358.  
  359. else value = " ";
  360. for(int s = 0; s < int.Parse(length); s++)
  361. {
  362. if(defaultValue == "") defaultValue = " ";
  363. if(value == "") value = defaultValue;
  364. if(value == null || s >= value.Length)
  365. {
  366. wantedProperty += " ";
  367. continue;
  368. }
  369. wantedProperty += value[s];
  370. }
  371. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  372. {
  373. return inn.newError("Please Look at the table");
  374. }
  375. break;
  376. case "ItemPropertyItem":
  377. Item myStockPart = null;
  378. string myStockPartId = null;
  379. string cItem = finishedGood.getProperty("mrn_plm_product_label_item", "");
  380. Item ssd = null;
  381. if(cItem != "")
  382. ssd = inn.getItemById("mrn_plm_labeling_item", cItem);
  383.  
  384. if(ssd != null)
  385. myStockPartId = ssd.getProperty(information);
  386.  
  387. if(myStockPartId != null)
  388. {
  389. myStockPart = inn.getItemById("Part", myStockPartId);
  390. value = myStockPart.getProperty(itemInformation, "");
  391. }
  392.  
  393. else value = "";
  394.  
  395. for(int s = 0; s < int.Parse(length); s++)
  396. {
  397. if(defaultValue == "") defaultValue = " ";
  398. if(value == "") value = defaultValue;
  399. if(value == null || s >= value.Length)
  400. {
  401. wantedProperty += " ";
  402. continue;
  403. }
  404. wantedProperty += value[s];
  405. }
  406. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  407. {
  408. return inn.newError("Please Look at the table");
  409. }
  410. break;
  411. case "Document":
  412.  
  413. if(labItemId != "")
  414. {
  415. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  416.  
  417. ourLabItem.fetchRelationships("mrn_plm_label_item_doc");
  418. Item docRelationships = ourLabItem.getRelationships("mrn_plm_label_item_doc");
  419.  
  420. int docRelCount = docRelationships.getItemCount();
  421.  
  422. for(int f = 0; f < docRelCount; f++)
  423. {
  424. Item currDoc = docRelationships.getItemByIndex(f);
  425. var docUsage = currDoc.getProperty("mrn_plm_usage");
  426. if(docUsage == usage)
  427. {
  428. value = currDoc.getProperty(information);
  429. break;
  430. }
  431. }
  432.  
  433. var nextItem = 0;
  434.  
  435. if(value ==null)
  436. {
  437. nextItem = IDENT6_LIST.Select(itm => itm.getProperty("mrn_plm_start_position") == startPosition && itm.getProperty("mrn_plm_priority") == "Alternative").Count();
  438. }
  439.  
  440. if(nextItem >= 2 && priority == "Preminary") break;
  441. //else value = "";
  442.  
  443. for(int s = 0; s < int.Parse(length); s++)
  444. {
  445. if(defaultValue == "") defaultValue = " ";
  446. if(value == "") value = defaultValue;
  447. if(value == null || s >= value.Length)
  448. {
  449. wantedProperty += " ";
  450. continue;
  451. }
  452. wantedProperty += value[s];
  453. }
  454. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  455. {
  456. return inn.newError("Please Look at the table");
  457. }
  458. }
  459.  
  460. else
  461. {
  462. value = " ";
  463. for(int s = 0; s < int.Parse(length); s++)
  464. {
  465. if(defaultValue == "") defaultValue = " ";
  466. if(value == "") value = defaultValue;
  467. if(value == null || s >= value.Length)
  468. {
  469. wantedProperty += " ";
  470. continue;
  471. }
  472. wantedProperty += value[s];
  473. }
  474. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  475. {
  476. return inn.newError("Please Look at the table");
  477. }
  478. }
  479.  
  480. break;
  481. }
  482. }
  483.  
  484. else if(itemType == "Constitution")
  485. {
  486. switch(infoType)
  487. {
  488. case "Property":
  489. string partConstId = finishedGood.getProperty("mrn_plm_constitution");
  490.  
  491. Item someXProps = inn.newItem("xPropertyDefinition", "get");
  492. someXProps.setProperty("name", information);
  493. someXProps = someXProps.apply();
  494. try
  495. {
  496. string res = someXProps.getProperty("name");
  497.  
  498. string sql = @"SELECT [" + res + "] FROM [xp].[XPROPERTYVALUES] WHERE item_id='" + partConstId + "'";
  499. Item sqlResult = inn.applySQL(sql);
  500. value = sqlResult.getProperty(res);
  501. }
  502.  
  503. catch(Exception ex){value = "";}
  504.  
  505.  
  506. for(int s = 0; s < int.Parse(length); s++)
  507. {
  508. if(defaultValue == "") defaultValue = " ";
  509. if(value == "") value = defaultValue;
  510. if(value == null || s >= value.Length)
  511. {
  512. wantedProperty += " ";
  513. continue;
  514. }
  515. wantedProperty += value[s];
  516. }
  517. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  518. {
  519. return inn.newError("Please Look at the table");
  520. }
  521. break;
  522. }
  523. }
  524.  
  525. else if(itemType == "R35")
  526. {
  527. Item r35Item = null;
  528. string r35 = finishedGood.getProperty("mrn_plm_r35", "");
  529.  
  530. if(r35 != "")
  531. {
  532. r35Item = inn.getItemById("mrn_plm_labeling_item", r35);
  533. }
  534.  
  535. switch(infoType)
  536. {
  537. case "Property":
  538. if(r35Item != null)
  539. value = r35Item.getProperty(information, "");
  540. else value = "";
  541. for(int s = 0; s < int.Parse(length); s++)
  542. {
  543. if(defaultValue == "") defaultValue = " ";
  544. if(value == "") value = defaultValue;
  545. if(value == null || s >= value.Length)
  546. {
  547. wantedProperty += " ";
  548. continue;
  549. }
  550. wantedProperty += value[s];
  551. }
  552. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  553. {
  554. return inn.newError("Please Look at the table");
  555. }
  556. break;
  557.  
  558. case "ItemPropertyItem":
  559. string myStockPartId = null;
  560. Item myStockPart = null;
  561.  
  562. if(r35Item != null)
  563. {
  564. myStockPartId = r35Item.getProperty(information, "");
  565.  
  566. if(myStockPartId != "")
  567. myStockPart = inn.getItemById("Part", myStockPartId);
  568. }
  569. if(myStockPart != null)
  570. {
  571. value = myStockPart.getProperty(itemInformation, "");
  572. //return inn.newError("There is stock Item");
  573. }
  574. else value = "";
  575.  
  576. for(int s = 0; s < int.Parse(length); s++)
  577. {
  578. if(defaultValue == "") defaultValue = " ";
  579. if(value == "") value = defaultValue;
  580. if(value == null || s >= value.Length)
  581. {
  582. wantedProperty += " ";
  583. continue;
  584. }
  585. wantedProperty += value[s];
  586. }
  587. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  588. {
  589. return inn.newError("Please Look at the table");
  590. }
  591. break;
  592. }
  593. }
  594.  
  595. else if(itemType == "MSL")
  596. {
  597. string pimId = finishedGood.getProperty("mrn_plm_pim_product", "");
  598. Item pim = null;
  599. Item msl = null;
  600. if(pimId != "")
  601. {
  602. pim = inn.getItemById("MRN_Item", pimId);
  603.  
  604. string mslId = pim.getProperty("mrn_parent_msl", "");
  605.  
  606. if(mslId != "")
  607. msl = inn.getItemById("MRN_Item", mslId);
  608. }
  609.  
  610. switch(infoType)
  611. {
  612. case "Property":
  613. if(msl != null)
  614. value = msl.getProperty(information, "");
  615. else value = "";
  616. for(int s = 0; s < int.Parse(length); s++)
  617. {
  618. if(defaultValue == "") defaultValue = " ";
  619. if(value == "") value = defaultValue;
  620. if(value == null || s >= value.Length)
  621. {
  622. wantedProperty += " ";
  623. continue;
  624. }
  625. wantedProperty += value[s];
  626. }
  627. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  628. {
  629. return inn.newError("Please Look at the table");
  630. }
  631. break;
  632. }
  633. }
  634.  
  635. else if(itemType == "Frame")
  636. {
  637. string pimId = finishedGood.getProperty("mrn_plm_pim_product", "");
  638. Item pim = null;
  639. Item frame = null;
  640. if(pimId != "")
  641. {
  642. pim = inn.getItemById("MRN_Item", pimId);
  643.  
  644. string frameId = pim.getProperty("mrn_frame", "");
  645.  
  646. if(frameId != "")
  647. frame = inn.getItemById("MRN_Item", frameId);
  648. }
  649.  
  650. switch(infoType)
  651. {
  652. case "Property":
  653. if(frame != null)
  654. value = frame.getProperty(information, "");
  655. else value = "";
  656. for(int s = 0; s < int.Parse(length); s++)
  657. {
  658. if(defaultValue == "") defaultValue = " ";
  659. if(value == "") value = defaultValue;
  660. if(value == null || s >= value.Length)
  661. {
  662. wantedProperty += " ";
  663. continue;
  664. }
  665. wantedProperty += value[s];
  666. }
  667. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  668. {
  669. return inn.newError("Please Look at the table");
  670. }
  671. break;
  672. }
  673. }
  674.  
  675.  
  676. if (itemItm.Equals(last))
  677. {
  678. System.Diagnostics.Debugger.Break();
  679.  
  680. id.Write(wantedProperty);
  681. id.Write("*");
  682. id.WriteLine();
  683. }
  684. }
  685.  
  686. wantedProperty = "";
  687. foreach(Item itemItM in MEASURE_LIST)
  688. {
  689. itemType = itemItM.getProperty("mrn_plm_item_type");
  690. infoType = itemItM.getProperty("mrn_plm_info_type");
  691. information = itemItM.getProperty("mrn_plm_information");
  692. defaultValue = itemItM.getProperty("mrn_plm_defaut_value");
  693. itemInformation = itemItM.getProperty("mrn_plm_item_information");
  694. startPosition = itemItM.getProperty("mrn_plm_start_position");
  695. length = itemItM.getProperty("mrn_plm_length");
  696. usage = itemItM.getProperty("mrn_plm_usage_doc", "");
  697. priority = itemItM.getProperty("mrn_plm_priority", "");
  698. string labItemId = finishedGood.getProperty("mrn_plm_label_item", "");
  699. string value = null;
  700.  
  701.  
  702. if((itemType == "Item" || itemType == "Generic Label Item" || itemType == "Product Label Item" || itemType == "R35" || itemType == "MSL" || itemType == "Frame" || itemType == "Certificatio") && (infoType == "DateTime-YYMMDDhhmm" || infoType == "Date-MM/DD/YYYY"))
  703. {
  704. if(infoType == "DateTime-YYMMDDhhmm")
  705. {
  706. DateTime dt = DateTime.Now;;
  707. if (information == "Today") {dt = DateTime.Now;}
  708. if (information == "Yesterday") {dt = dt.AddDays(-1);}
  709. if (information == "Tomorrow") {dt = dt.AddDays(1);}
  710. value = dt.ToString("yyMMddHHmm");
  711. for(int f = 0; f < int.Parse(length); f++)
  712. {
  713. if(defaultValue == "") defaultValue = " ";
  714. if(value == "") value = defaultValue;
  715. if(value == null || f >= value.Length)
  716. {
  717. wantedProperty += " ";
  718. continue;
  719. }
  720. wantedProperty += value[f];
  721. }
  722. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  723. {
  724. return inn.newError("Please Look at the table");
  725. }
  726. }
  727. else if(infoType == "Date-MM/DD/YYYY")
  728. {
  729. DateTime dte = DateTime.Now;
  730. if (information == "Today") {dte = DateTime.Now;}
  731. if (information == "Yesterday") {dte = dte.AddDays(-1);}
  732. if (information == "Tomorrow") {dte = dte.AddDays(1);}
  733. value = dte.ToString(@"MM\/dd\/yyyy");
  734. for(int f = 0; f < int.Parse(length); f++)
  735. {
  736. if(defaultValue == "") defaultValue = " ";
  737. if(value == "") value = defaultValue;
  738. if(value == null || f >= value.Length)
  739. {
  740. wantedProperty += " ";
  741. continue;
  742. }
  743. wantedProperty += value[f];
  744. }
  745. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  746. {
  747. return inn.newError("Please Look at the table");
  748. }
  749. }
  750. }
  751.  
  752. else if(itemType == "Item")
  753. {
  754.  
  755. if(infoType == "Property")
  756. {
  757. value = finishedGood.getProperty(information, "");
  758. for(int s = 0; s < int.Parse(length); s++)
  759. {
  760. if(defaultValue == "") defaultValue = " ";
  761. if(value == "") value = defaultValue;
  762. if(value == null || s >= value.Length)
  763. {
  764. wantedProperty += " ";
  765. continue;
  766. }
  767. wantedProperty += value[s];
  768. }
  769. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  770. {
  771. return inn.newError("Please Look at the table");
  772. }
  773. }
  774. }
  775.  
  776. else if(itemType == "Generic Label Item")
  777. {
  778. switch(infoType)
  779. {
  780. case "Property":
  781. value = finishedGood.getProperty(information, "");
  782. for(int s = 0; s < int.Parse(length); s++)
  783. {
  784. if(defaultValue == "") defaultValue = " ";
  785. if(value == "") value = defaultValue;
  786. if(value == null || s >= value.Length)
  787. {
  788. wantedProperty += " ";
  789. continue;
  790. }
  791. wantedProperty += value[s];
  792. }
  793. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  794. {
  795. return inn.newError("Please Look at the table");
  796. }
  797. break;
  798. case "ItemPropertyItem":
  799. value = "";
  800. Item myStockPart = null;
  801. string myStockPartId = null;
  802. string cItem = finishedGood.getPropertyItem("mrn_plm_label_item").getID();
  803. Item ssd = inn.getItemById("mrn_plm_labeling_item", cItem);
  804.  
  805. myStockPartId = ssd.getProperty(information);
  806.  
  807. myStockPart = inn.getItemById("Part", myStockPartId);
  808.  
  809. if(myStockPartId == null)
  810. {
  811. return inn.newError("There is stock Item");
  812. }
  813.  
  814. value = myStockPart.getProperty(itemInformation, "");
  815.  
  816. for(int s = 0; s < int.Parse(length); s++)
  817. {
  818. if(defaultValue == "") defaultValue = " ";
  819. if(value == "") value = defaultValue;
  820. if(value == null || s >= value.Length)
  821. {
  822. wantedProperty += " ";
  823. continue;
  824. }
  825. wantedProperty += value[s];
  826. }
  827. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  828. {
  829. return inn.newError("Please Look at the table");
  830. }
  831. break;
  832. case "Document":
  833.  
  834. if(labItemId != "")
  835. {
  836. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  837.  
  838. ourLabItem.fetchRelationships("mrn_plm_label_item_doc");
  839. Item docRelationships = ourLabItem.getRelationships("mrn_plm_label_item_doc");
  840.  
  841. int docRelCount = docRelationships.getItemCount();
  842.  
  843. for(int f = 0; f < docRelCount; f++)
  844. {
  845. Item currDoc = docRelationships.getItemByIndex(f);
  846. var docUsage = currDoc.getProperty("mrn_plm_usage");
  847. if(docUsage == usage)
  848. {
  849. value = currDoc.getProperty(information);
  850. break;
  851. }
  852. }
  853.  
  854. var nextItem = 0;
  855.  
  856. if(value ==null)
  857. {
  858. nextItem = IDENT6_LIST.Select(itm => itm.getProperty("mrn_plm_start_position") == startPosition && itm.getProperty("mrn_plm_priority") == "Alternative").Count();
  859. }
  860.  
  861. if(nextItem >= 2 && priority == "Preminary") break;
  862. //else value = "";
  863.  
  864. for(int s = 0; s < int.Parse(length); s++)
  865. {
  866. if(defaultValue == "") defaultValue = " ";
  867. if(value == "") value = defaultValue;
  868. if(value == null || s >= value.Length)
  869. {
  870. wantedProperty += " ";
  871. continue;
  872. }
  873. wantedProperty += value[s];
  874. }
  875. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  876. {
  877. return inn.newError("Please Look at the table");
  878. }
  879. }
  880.  
  881. else
  882. {
  883. value = " ";
  884. for(int s = 0; s < int.Parse(length); s++)
  885. {
  886. if(defaultValue == "") defaultValue = " ";
  887. if(value == "") value = defaultValue;
  888. if(value == null || s >= value.Length)
  889. {
  890. wantedProperty += " ";
  891. continue;
  892. }
  893. wantedProperty += value[s];
  894. }
  895. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  896. {
  897. return inn.newError("Please Look at the table");
  898. }
  899. }
  900.  
  901. break;
  902. }
  903. }
  904.  
  905. else if(itemType == "Product Label Item")
  906. {
  907. switch(infoType)
  908. {
  909. case "Property":
  910. if(labItemId != "")
  911. {
  912. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  913. value = ourLabItem.getProperty(information, "");
  914. }
  915.  
  916. else value = " ";
  917. for(int s = 0; s < int.Parse(length); s++)
  918. {
  919. if(defaultValue == "") defaultValue = " ";
  920. if(value == "") value = defaultValue;
  921. if(value == null || s >= value.Length)
  922. {
  923. wantedProperty += " ";
  924. continue;
  925. }
  926. wantedProperty += value[s];
  927. }
  928. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  929. {
  930. return inn.newError("Please Look at the table");
  931. }
  932. break;
  933. case "ItemPropertyItem":
  934. Item myStockPart = null;
  935. string myStockPartId = null;
  936. string cItem = finishedGood.getProperty("mrn_plm_product_label_item", "");
  937. Item ssd = null;
  938. if(cItem != "")
  939. ssd = inn.getItemById("mrn_plm_labeling_item", cItem);
  940.  
  941. if(ssd != null)
  942. myStockPartId = ssd.getProperty(information);
  943.  
  944. if(myStockPartId != null)
  945. {
  946. myStockPart = inn.getItemById("Part", myStockPartId);
  947. value = myStockPart.getProperty(itemInformation, "");
  948. }
  949.  
  950. else value = "";
  951. //if(myStockPartId == ""null"") break;
  952.  
  953. // value = myStockPart.getProperty(itemInformation, "");
  954.  
  955. for(int s = 0; s < int.Parse(length); s++)
  956. {
  957. if(defaultValue == "") defaultValue = " ";
  958. if(value == "") value = defaultValue;
  959. if(value == null || s >= value.Length)
  960. {
  961. wantedProperty += " ";
  962. continue;
  963. }
  964. wantedProperty += value[s];
  965. }
  966. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  967. {
  968. return inn.newError("Please Look at the table");
  969. }
  970. break;
  971. case "Document":
  972.  
  973. if(labItemId != "")
  974. {
  975. Item ourLabItem = inn.getItemById("mrn_plm_labeling_item", labItemId);
  976.  
  977. ourLabItem.fetchRelationships("mrn_plm_label_item_doc");
  978. Item docRelationships = ourLabItem.getRelationships("mrn_plm_label_item_doc");
  979.  
  980. int docRelCount = docRelationships.getItemCount();
  981.  
  982. for(int f = 0; f < docRelCount; f++)
  983. {
  984. Item currDoc = docRelationships.getItemByIndex(f);
  985. var docUsage = currDoc.getProperty("mrn_plm_usage");
  986. if(docUsage == usage)
  987. {
  988. value = currDoc.getProperty(information);
  989. break;
  990. }
  991. }
  992.  
  993. var nextItem = 0;
  994.  
  995. if(value ==null)
  996. {
  997. nextItem = IDENT6_LIST.Select(itm => itm.getProperty("mrn_plm_start_position") == startPosition && itm.getProperty("mrn_plm_priority") == "Alternative").Count();
  998. }
  999.  
  1000. if(nextItem >= 2 && priority == "Preminary") break;
  1001. //else value = "";
  1002.  
  1003. for(int s = 0; s < int.Parse(length); s++)
  1004. {
  1005. if(defaultValue == "") defaultValue = " ";
  1006. if(value == "") value = defaultValue;
  1007. if(value == null || s >= value.Length)
  1008. {
  1009. wantedProperty += " ";
  1010. continue;
  1011. }
  1012. wantedProperty += value[s];
  1013. }
  1014. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1015. {
  1016. return inn.newError("Please Look at the table");
  1017. }
  1018. }
  1019.  
  1020. else
  1021. {
  1022. value = " ";
  1023. for(int s = 0; s < int.Parse(length); s++)
  1024. {
  1025. if(defaultValue == "") defaultValue = " ";
  1026. if(value == "") value = defaultValue;
  1027. if(value == null || s >= value.Length)
  1028. {
  1029. wantedProperty += " ";
  1030. continue;
  1031. }
  1032. wantedProperty += value[s];
  1033. }
  1034. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1035. {
  1036. return inn.newError("Please Look at the table");
  1037. }
  1038. }
  1039.  
  1040. break;
  1041. }
  1042. }
  1043.  
  1044.  
  1045. else if(itemType == "Constitution")
  1046. {
  1047. switch(infoType)
  1048. {
  1049. case "Property":
  1050. string partConstId = finishedGood.getProperty("mrn_plm_constitution");
  1051.  
  1052. Item someXProps = inn.newItem("xPropertyDefinition", "get");
  1053. someXProps.setProperty("name", information);
  1054. someXProps = someXProps.apply();
  1055. try
  1056. {
  1057. string res = someXProps.getProperty("name");
  1058.  
  1059. string sql = @"SELECT [" + res + "] FROM [xp].[XPROPERTYVALUES] WHERE item_id='" + partConstId + "'";
  1060. Item sqlResult = inn.applySQL(sql);
  1061. value = sqlResult.getProperty(res);
  1062. }
  1063.  
  1064. catch(Exception ex){value = "";}
  1065.  
  1066.  
  1067. for(int s = 0; s < int.Parse(length); s++)
  1068. {
  1069. if(defaultValue == "") defaultValue = " ";
  1070. if(value == "") value = defaultValue;
  1071. if(value == null || s >= value.Length)
  1072. {
  1073. wantedProperty += " ";
  1074. continue;
  1075. }
  1076. wantedProperty += value[s];
  1077. }
  1078. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1079. {
  1080. return inn.newError("Please Look at the table");
  1081. }
  1082. break;
  1083. }
  1084. }
  1085.  
  1086. else if(itemType == "R35")
  1087. {
  1088. Item r35Item = null;
  1089. string r35 = finishedGood.getProperty("mrn_plm_r35", "");
  1090.  
  1091. if(r35 != "")
  1092. {
  1093. r35Item = inn.getItemById("mrn_plm_labeling_item", r35);
  1094. }
  1095.  
  1096. switch(infoType)
  1097. {
  1098. case "Property":
  1099.  
  1100. if(r35Item != null)
  1101. value = r35Item.getProperty(information, "");
  1102. else value = "";
  1103. for(int s = 0; s < int.Parse(length); s++)
  1104. {
  1105. if(defaultValue == "") defaultValue = " ";
  1106. if(value == "") value = defaultValue;
  1107. if(value == null || s >= value.Length)
  1108. {
  1109. wantedProperty += " ";
  1110. continue;
  1111. }
  1112. wantedProperty += value[s];
  1113. }
  1114. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1115. {
  1116. return inn.newError("Please Look at the table");
  1117. }
  1118. break;
  1119.  
  1120. case "ItemPropertyItem":
  1121. string myStockPartId = null;
  1122. Item myStockPart = null;
  1123.  
  1124. if(r35Item != null)
  1125. {
  1126. myStockPartId = r35Item.getProperty(information, "");
  1127.  
  1128. if(myStockPartId != "")
  1129. myStockPart = inn.getItemById("Part", myStockPartId);
  1130. }
  1131. if(myStockPart != null)
  1132. {
  1133. value = myStockPart.getProperty(itemInformation, "");
  1134. //return inn.newError("There is stock Item");
  1135. }
  1136. else value = "";
  1137.  
  1138. for(int s = 0; s < int.Parse(length); s++)
  1139. {
  1140. if(defaultValue == "") defaultValue = " ";
  1141. if(value == "") value = defaultValue;
  1142. if(value == null || s >= value.Length)
  1143. {
  1144. wantedProperty += " ";
  1145. continue;
  1146. }
  1147. wantedProperty += value[s];
  1148. }
  1149. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1150. {
  1151. return inn.newError("Please Look at the table");
  1152. }
  1153. break;
  1154. }
  1155. }
  1156.  
  1157. else if(itemType == "MSL")
  1158. {
  1159. string pimId = finishedGood.getProperty("mrn_plm_pim_product", "");
  1160. Item pim = null;
  1161. Item msl = null;
  1162. if(pimId != "")
  1163. {
  1164. pim = inn.getItemById("MRN_Item", pimId);
  1165.  
  1166. string mslId = pim.getProperty("mrn_parent_msl", "");
  1167.  
  1168. if(mslId != "")
  1169. msl = inn.getItemById("MRN_Item", mslId);
  1170. }
  1171.  
  1172. switch(infoType)
  1173. {
  1174. case "Property":
  1175. if(msl != null)
  1176. value = msl.getProperty(information, "");
  1177. else
  1178. value = "";
  1179. for(int s = 0; s < int.Parse(length); s++)
  1180. {
  1181. if(defaultValue == "") defaultValue = " ";
  1182. if(value == "") value = defaultValue;
  1183. if(value == null || s >= value.Length)
  1184. {
  1185. wantedProperty += " ";
  1186. continue;
  1187. }
  1188. wantedProperty += value[s];
  1189. }
  1190. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1191. {
  1192. return inn.newError("Please Look at the table");
  1193. }
  1194. break;
  1195. }
  1196. }
  1197.  
  1198. else if(itemType == "Frame")
  1199. {
  1200. string pimId = finishedGood.getProperty("mrn_plm_pim_product", "");
  1201. Item pim = null;
  1202. Item frame = null;
  1203. if(pimId != "")
  1204. {
  1205. pim = inn.getItemById("MRN_Item", pimId);
  1206.  
  1207. string frameId = pim.getProperty("mrn_frame", "");
  1208.  
  1209. if(frameId != "")
  1210. frame = inn.getItemById("MRN_Item", frameId);
  1211. }
  1212.  
  1213. switch(infoType)
  1214. {
  1215. case "Property":
  1216. if(frame != null)
  1217. value = frame.getProperty(information, "");
  1218. else value = "";
  1219. for(int s = 0; s < int.Parse(length); s++)
  1220. {
  1221. if(defaultValue == "") defaultValue = " ";
  1222. if(value == "") value = defaultValue;
  1223. if(value == null || s >= value.Length)
  1224. {
  1225. wantedProperty += " ";
  1226. continue;
  1227. }
  1228. wantedProperty += value[s];
  1229. }
  1230. if(wantedProperty.Length + 1 != int.Parse(startPosition) + int.Parse(length))
  1231. {
  1232. return inn.newError("Please Look at the table");
  1233. }
  1234. break;
  1235. }
  1236. }
  1237.  
  1238.  
  1239. if (itemItM.Equals(lastMeasure))
  1240. {
  1241. System.Diagnostics.Debugger.Break();
  1242. me.Write(wantedProperty);
  1243. me.WriteLine();
  1244. }
  1245. }
  1246. }
  1247. id.Close();
  1248. me.Close();
  1249.  
  1250. return this;
  1251. }
  1252.  
  1253. class CompareItem : IComparer<Item>
  1254. {
  1255. public int Compare(Item x, Item y)
  1256. {
  1257. // CompareTo() method
  1258. int positionx = Convert.ToInt32(x.getProperty("mrn_plm_exportposition", "0"));
  1259. int positiony = Convert.ToInt32(y.getProperty("mrn_plm_exportposition", "0"));
  1260.  
  1261. return positionx.CompareTo(positiony);
  1262.  
  1263. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement