public static void InsertPracownik(int rows) { List <string> commandsToTextFile = new List <string>(); List <int> daneId = new List <int>(); List <DateTime> daty = GetDate("data_zatrudnienia", "Pracownik"); DateTime data; if (daty.Count == 0) { data = new DateTime(1995, 1, 1); } else { data = daty[daty.Count - 1]; } List <int> foreignKeys = new List <int>(); int liczba_rand = 0; foreignKeys.Clear(); daneId.Clear(); daneId = GetIds("dane_id", "Dane"); foreignKeys = GetIds("dane_dane_id", "Pracownik"); daneId.RemoveAll(i => foreignKeys.Contains(i)); if (daneId.Count == 0) { throw new Exception("brak mozliwych do uzycia wierszy w tabeli dane"); } Random rnd = new Random(); for (int i = 0; i < rows; i++) { var commandText = "insert into Pracownik (PRACOWNIK_ID, imie, nazwisko, fax, dane_dane_id, data_zatrudnienia) values(:PRACOWNIK_ID, :imie, :nazwisko, :fax, :dane_dane_id, :data_zatrudnienia)"; using (OracleConnection connection = new OracleConnection(connectionstring)) { using (OracleCommand command = new OracleCommand(commandText, connection)) { int range = (DateTime.Today - data).Days; data = data.AddDays(rnd.Next(range)); liczba_rand = rnd.Next(daneId.Count - 1); command.Parameters.Add(new OracleParameter("PRACOWNIK_ID", GetRowCount("Pracownik"))); command.Parameters.Add(new OracleParameter("imie", Generatory.generatorZnakow(9, false))); command.Parameters.Add(new OracleParameter("nazwisko", Generatory.generatorZnakow(9, true))); command.Parameters.Add(new OracleParameter("fax", Convert.ToString(Generatory.generatorTelefon()))); command.Parameters.Add(new OracleParameter("dane_dane_id", daneId[liczba_rand])); command.Parameters.Add(new OracleParameter("data_zatrudnienia", data)); commandsToTextFile.Add("insert into Pracownik (PRACOWNIK_ID, imie, nazwisko, fax, dane_dane_id, data_zatrudnienia) " + "values(" + command.Parameters[0].Value.ToString() + ", " + command.Parameters[1].Value.ToString() + ", " + command.Parameters[2].Value.ToString() + ", " + command.Parameters[3].Value.ToString() + ", " + command.Parameters[4].Value.ToString() + ", " + command.Parameters[5].Value.ToString() + ")"); command.Connection.Open(); command.ExecuteNonQueryAsync(); command.Connection.Close(); daneId.Remove((int)command.Parameters[4].Value); } } } foreignKeys.Clear(); daneId.Clear(); Generatory.zapis_plik("Pracownik", commandsToTextFile); }
public static void InsertDane(int rows) { List <string> commandsToTextFile = new List <string>(); List <int> adresId = new List <int>(); List <int> foreignKeys = new List <int>(); int liczba_rand = 0; foreignKeys.Clear(); adresId.Clear(); adresId = GetIds("adres_id", "Adres"); foreignKeys = GetIds("adres_adres_id", "Dane"); adresId.RemoveAll(i => foreignKeys.Contains(i)); if (adresId.Count == 0) { throw new Exception("brak mozliwych do uzycia wierszy w tabeli adres"); } Random rnd = new Random(); for (int i = 0; i < rows; i++) { var commandText = "insert into Dane (dane_id, e_mail , adres_adres_id, telefon) values(:dane_id, :e_mail, :adres_adres_id, :telefon)"; using (OracleConnection connection = new OracleConnection(connectionstring)) { using (OracleCommand command = new OracleCommand(commandText, connection)) { liczba_rand = rnd.Next(adresId.Count - 1); command.Parameters.Add(new OracleParameter("dane_id", GetRowCount("Dane"))); command.Parameters.Add(new OracleParameter("e_mail", Generatory.generatorZnakow(15, false))); command.Parameters.Add(new OracleParameter("adres_adres_id", adresId[liczba_rand])); command.Parameters.Add(new OracleParameter("telefon", Convert.ToString(Generatory.generatorTelefon()))); commandsToTextFile.Add("insert into Dane (dane_id, e_mail, adres_adres_id, telefon) " + "values(" + command.Parameters[0].Value.ToString() + ", " + command.Parameters[1].Value.ToString() + ", " + command.Parameters[2].Value.ToString() + ", " + command.Parameters[3].Value.ToString() + ")"); command.Connection.Open(); command.ExecuteNonQueryAsync(); command.Connection.Close(); adresId.Remove((int)command.Parameters[2].Value); } } } foreignKeys.Clear(); adresId.Clear(); Generatory.zapis_plik("Dane", commandsToTextFile); }