Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static int[] getIndices (string name, string country, string type, string company,
- string rules, string description)
- {
- int[] arr = new int[4];
- int ID_Company, ID_Country, ID_Type, ID_Demand;
- string commandCountry = $@"select ID from Country_Ecolabelling where
- CountriesList = '{country}'";
- SqlCommand findCountry = new SqlCommand(commandCountry, connection);
- SqlDataReader reader = findCountry.ExecuteReader();
- if (reader.HasRows)
- {
- reader.Read();
- ID_Country = reader.GetInt32(0);
- reader.Close();
- }
- else
- {
- reader.Close();
- SqlCommand addCountry = new SqlCommand($@"insert into Country_Ecolabelling
- (CountriesList) output INSERTED.ID values ('{country}')", connection);
- SqlDataReader countryReader = addCountry.ExecuteReader();
- countryReader.Read();
- ID_Country = countryReader.GetInt32(0);
- countryReader.Close();
- }
- string commandDemand = $@"select ID from Ecolabelling_Demand where
- Demandslist = '{rules}'";
- SqlCommand findDemand = new SqlCommand(commandDemand, connection);
- SqlDataReader reader2 = findDemand.ExecuteReader();
- if (reader2.HasRows)
- {
- reader2.Read();
- ID_Demand = reader2.GetInt32(0);
- reader2.Close();
- }
- else
- {
- reader2.Close();
- SqlCommand addType = new SqlCommand($@"insert into Ecolabelling_Demand
- (Demandslist) output INSERTED.ID values ('{rules}')", connection);
- SqlDataReader demandReader = addType.ExecuteReader();
- demandReader.Read();
- ID_Demand = demandReader.GetInt32(0);
- demandReader.Close();
- }
- string commandType = $@"select ID from Type_EcoLabelling where
- Types_List = '{type}'";
- SqlCommand findType = new SqlCommand(commandType, connection);
- SqlDataReader reader1 = findType.ExecuteReader();
- if (reader1.HasRows)
- {
- reader1.Read();
- ID_Type = reader1.GetInt32(0);
- reader1.Close();
- }
- else
- {
- reader1.Close();
- SqlCommand addType = new SqlCommand($@"insert into Type_Ecolabelling
- (Types_List) output INSERTED.ID values ('{type}')", connection);
- SqlDataReader typeReader = addType.ExecuteReader();
- typeReader.Read();
- ID_Type = typeReader.GetInt32(0);
- typeReader.Close();
- }
- string commandCompany = $@"select ID from Company where Name = '{company}'";
- SqlCommand findCompany = new SqlCommand(commandCompany, connection);
- SqlDataReader reader3 = findCompany.ExecuteReader();
- reader3.Read();
- ID_Company = reader3.GetInt32(0);
- reader3.Close();
- connection.Close();
- arr[0] = ID_Company;
- arr[1] = ID_Demand;
- arr[2] = ID_Type;
- arr[3] = ID_Country;
- return arr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement