選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

1週間前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.OleDb;
  4. using System.Xml;
  5. using System.IO;
  6. using TM.Shared.Components;
  7. namespace TM.Bosman.Components
  8. {
  9. public class MSsql
  10. {
  11. public static string AddReference(string reference)
  12. {
  13. // Possible results: "Added", "Already exists", "Error!", "Unexpected result!"
  14. string result = "Unexpected result!";
  15. string creation = DateTimeFunctions.GetCurrentDateTime();
  16. OleDbConnection ESBLookups = new OleDbConnection(SSOFunctions.GetValue("TM.Bosman", "ESBLookupConnectionString2016"));
  17. try
  18. {
  19. ESBLookups.Open();
  20. OleDbCommand sqlCommand = ESBLookups.CreateCommand();
  21. sqlCommand.CommandText = "select count(*) COUNT from TM_Bosman_Reference where reference = '" + reference.Trim() + "'";
  22. OleDbDataReader reader = sqlCommand.ExecuteReader();
  23. while (reader.Read())
  24. {
  25. if (Convert.ToInt32(reader["COUNT"].ToString()) > 0)
  26. {
  27. result = "Already exists";
  28. }
  29. else
  30. {
  31. result = "Not found";
  32. }
  33. }
  34. reader.Close();
  35. if (result == "Not found")
  36. {
  37. sqlCommand.CommandText = "INSERT INTO TM_Bosman_Reference (Reference, DateTime) VALUES ('" + reference.Trim() + "', '" + creation.ToString() + "')";
  38. reader = sqlCommand.ExecuteReader();
  39. result = "Added";
  40. }
  41. reader.Close();
  42. }
  43. catch (Exception ex) { throw ex; result = "Error!"; }
  44. finally { ESBLookups.Close(); }
  45. return result;
  46. }
  47. public static string CheckReference(string reference)
  48. {
  49. // Possible results: "Found", "Not Found", "Error!", "Unexpected result!"
  50. string result = "Unexpected result!";
  51. OleDbConnection ESBLookups = new OleDbConnection(SSOFunctions.GetValue("TM.Bosman", "ESBLookupConnectionString2016"));
  52. try
  53. {
  54. ESBLookups.Open();
  55. OleDbCommand sqlCommand = ESBLookups.CreateCommand();
  56. sqlCommand.CommandText = "select count(*) COUNT from TM_Bosman_Reference where reference = '" + reference.Trim() + "'";
  57. OleDbDataReader reader = sqlCommand.ExecuteReader();
  58. while (reader.Read())
  59. {
  60. if (Convert.ToInt32(reader["COUNT"].ToString()) > 0)
  61. {
  62. result = "Final"; // = "Found"
  63. }
  64. else
  65. {
  66. result = "New"; // = Not Found"
  67. }
  68. }
  69. }
  70. catch (Exception ex) { throw ex; result = "Error!"; }
  71. finally { ESBLookups.Close(); }
  72. return result;
  73. }
  74. }
  75. public class Ixolution
  76. {
  77. // Oorspronkelijk Biztalk opzet werden referenties in de Ixolution TMS Oracle database gechecked.
  78. // In de nieuwe opzet 'mag dat niet meer' en wordt een eigen administratie met MS SQL Server opgezet.
  79. public static string WimBosman_checkPreAdvicesAndFinals(XmlDocument doc)
  80. {
  81. // Check the references that are sent if they are already in the system at venlo or eersel to identfy new or finals in the e-mail header!
  82. OleDbConnection OracleConnectionVenlo = new OleDbConnection(@"File Name='c:\Program Files\Common Files\KLG\KLG_TMS_ORACLE.udl';");
  83. OleDbConnection OracleConnectionEersel = new OleDbConnection(@"File Name='c:\Program Files\Common Files\KLG\KLG_TMS_ORACLE_EERSEL.udl';");
  84. string receiver = doc.SelectSingleNode("//*[local-name()='OrdersIntern']/*[local-name()='Header']/*[local-name()='Receiver']").InnerText;
  85. List<string> references = new List<string>();
  86. XmlNodeList nodes = doc.SelectNodes("//*[local-name()='ShipmentFields']");
  87. int preAdvices = 0;
  88. int finals = 0;
  89. foreach (XmlNode node in nodes)
  90. {
  91. // Check existense in iXolution Venlo
  92. if (receiver == "KLGNLVEN")
  93. {
  94. try
  95. {
  96. OracleConnectionVenlo.Open();
  97. OleDbCommand OracleCommand = OracleConnectionVenlo.CreateCommand();
  98. OracleCommand.CommandText = "SELECT COUNT(*) CTR FROM TMS.SHIPMENT WHERE REFERENCE = '" + node.SelectSingleNode("*[local-name()='ClientReference']").InnerText + "' AND CONSIGNOR_COMPANY_CODE = 'BOSMASHEER01'";
  99. OleDbDataReader OracleReader = OracleCommand.ExecuteReader();
  100. while (OracleReader.Read())
  101. {
  102. if (Convert.ToInt32(OracleReader["CTR"].ToString()) > 0)
  103. {
  104. finals = finals + 1;
  105. }
  106. else
  107. {
  108. preAdvices = preAdvices + 1;
  109. }
  110. }
  111. }
  112. catch (Exception ex) { throw ex; }
  113. finally { OracleConnectionVenlo.Close(); }
  114. OracleConnectionVenlo.Close();
  115. }
  116. else if (receiver == "KLGNLEER")
  117. {
  118. // Check existense in iXolution Venlo
  119. try
  120. {
  121. OracleConnectionEersel.Open();
  122. OleDbCommand OracleCommand = OracleConnectionEersel.CreateCommand();
  123. OracleCommand.CommandText = "SELECT COUNT(*) CTR FROM TMS.SHIPMENT WHERE REFERENCE = '" + node.SelectSingleNode("//*[local-name()='Shipment']/*[local-name()='ShipmentFields']/*[local-name()='ClientReference']").InnerText + "' AND CONSIGNOR_COMPANY_CODE = 'WIMBOSHEER01'";
  124. OleDbDataReader OracleReader = OracleCommand.ExecuteReader();
  125. while (OracleReader.Read())
  126. {
  127. if (Convert.ToInt32(OracleReader["CTR"].ToString()) > 0)
  128. {
  129. finals = finals + 1;
  130. }
  131. else
  132. {
  133. preAdvices = preAdvices + 1;
  134. }
  135. }
  136. }
  137. catch (Exception ex) { throw ex; }
  138. finally { OracleConnectionEersel.Close(); }
  139. OracleConnectionEersel.Close();
  140. }
  141. else
  142. {
  143. string message = "Receiver is not KLGNLVEN or KLGNLEER!";
  144. throw new Exception(message, new Exception(doc.InnerXml));
  145. }
  146. }
  147. if (nodes.Count != (preAdvices + finals))
  148. {
  149. string message = "Total count in xml (" + nodes.Count + ") for preAdvices (" + preAdvices + ") and finals (" + finals + ") in this message did not meet eachoter, see innerexception for used the message\r probably there was a connection error with the check in iXolution?";
  150. throw new Exception(message, new Exception(doc.InnerXml));
  151. }
  152. return " (" + preAdvices + " new, " + finals + " finals)";
  153. }
  154. }
  155. public class Logging
  156. {
  157. public static void WriteToLog(String Message)
  158. {
  159. StreamWriter writeText = new StreamWriter("D:\\SVN\\EDI\\KLG.BizTalk\\TM\\Bosman\\Transforms.Test\\Logging\\LogBosman.txt", append: true);
  160. writeText.WriteLine(Message);
  161. writeText.Close();
  162. }
  163. }
  164. }