Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. private static int[] getIndices (string name, string country, string type, string company,
  2. string rules, string description)
  3. {
  4. int[] arr = new int[4];
  5. int ID_Company, ID_Country, ID_Type, ID_Demand;
  6. string commandCountry = $@"select ID from Country_Ecolabelling where
  7. CountriesList = '{country}'";
  8. SqlCommand findCountry = new SqlCommand(commandCountry, connection);
  9. SqlDataReader reader = findCountry.ExecuteReader();
  10. if (reader.HasRows)
  11. {
  12. reader.Read();
  13. ID_Country = reader.GetInt32(0);
  14. reader.Close();
  15. }
  16. else
  17. {
  18. reader.Close();
  19. SqlCommand addCountry = new SqlCommand($@"insert into Country_Ecolabelling
  20. (CountriesList) output INSERTED.ID values ('{country}')", connection);
  21. SqlDataReader countryReader = addCountry.ExecuteReader();
  22. countryReader.Read();
  23. ID_Country = countryReader.GetInt32(0);
  24. countryReader.Close();
  25. }
  26.  
  27. string commandDemand = $@"select ID from Ecolabelling_Demand where
  28. Demandslist = '{rules}'";
  29. SqlCommand findDemand = new SqlCommand(commandDemand, connection);
  30. SqlDataReader reader2 = findDemand.ExecuteReader();
  31. if (reader2.HasRows)
  32. {
  33. reader2.Read();
  34. ID_Demand = reader2.GetInt32(0);
  35. reader2.Close();
  36. }
  37. else
  38. {
  39. reader2.Close();
  40. SqlCommand addType = new SqlCommand($@"insert into Ecolabelling_Demand
  41. (Demandslist) output INSERTED.ID values ('{rules}')", connection);
  42. SqlDataReader demandReader = addType.ExecuteReader();
  43. demandReader.Read();
  44. ID_Demand = demandReader.GetInt32(0);
  45. demandReader.Close();
  46. }
  47.  
  48. string commandType = $@"select ID from Type_EcoLabelling where
  49. Types_List = '{type}'";
  50. SqlCommand findType = new SqlCommand(commandType, connection);
  51. SqlDataReader reader1 = findType.ExecuteReader();
  52. if (reader1.HasRows)
  53. {
  54. reader1.Read();
  55. ID_Type = reader1.GetInt32(0);
  56. reader1.Close();
  57. }
  58. else
  59. {
  60. reader1.Close();
  61. SqlCommand addType = new SqlCommand($@"insert into Type_Ecolabelling
  62. (Types_List) output INSERTED.ID values ('{type}')", connection);
  63. SqlDataReader typeReader = addType.ExecuteReader();
  64. typeReader.Read();
  65. ID_Type = typeReader.GetInt32(0);
  66. typeReader.Close();
  67. }
  68.  
  69. string commandCompany = $@"select ID from Company where Name = '{company}'";
  70. SqlCommand findCompany = new SqlCommand(commandCompany, connection);
  71. SqlDataReader reader3 = findCompany.ExecuteReader();
  72. reader3.Read();
  73. ID_Company = reader3.GetInt32(0);
  74. reader3.Close();
  75. connection.Close();
  76. arr[0] = ID_Company;
  77. arr[1] = ID_Demand;
  78. arr[2] = ID_Type;
  79. arr[3] = ID_Country;
  80. return arr;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement