public Records[] putDataToObjects(string[] collection) { Records[] cllctn = new Records[collection.Length]; string[] lijst = null; int counter = 0; foreach (string s in collection) { lijst = parseOnTab(s); Records record = new Records( deleteUFromHours(lijst[1]), parsePuntComma(lijst[3]), lijst[4], lijst[5], parsePuntComma(lijst[6]), parsePuntComma(lijst[7]), int.Parse(lijst[9]), deleteUFromHours(lijst[13]), getDayOutOfParser(lijst[12]), 8); cllctn[counter] = record; counter++; } //databaseConnector.addListToDatabase(cllctn); return cllctn; }
public void addListToDatabase(Records recs, string pcname, string username, string password) { connection = new SqlConnection(@"Data Source=" + pcname + ";Initial Catalog=Timetable;Persist Security Info=True;User ID=" + username + ";Password="******""); try { connection.Open(); int minutes = recs.StartUur % 100; int hours = recs.StartUur / 100; TimeSpan startTijd = new TimeSpan(hours, minutes, 0); int olodId = checkOlod(recs.Deelopleidingsonderdeel.Replace('\'', ' '), recs.Opleidingsonderdeel.Replace('\'', ' '), recs.Studiepunten); Docent[] docenten = new Docent[recs.Docenten.Length]; int count = 0; if (recs.Docenten.Length != 0) { foreach (string s in recs.Docenten) { if (s.Contains(' ')) { string[] naamvoornaam = s.Split(' '); if (naamvoornaam.Length == 2) { docenten[count] = new Docent(naamvoornaam[0].Replace('\'', ' '), naamvoornaam[1].Replace('\'', ' ')); } else { string achternaam = naamvoornaam[0]; for (int i = 1; i < naamvoornaam.Length-1; i++) { achternaam += " "+naamvoornaam[i]; } docenten[count] = new Docent(achternaam.Replace('\'', ' '), naamvoornaam[naamvoornaam.Length - 1].Replace('\'', ' ')); } } else { docenten[count] = new Docent(s, string.Empty); } count++; } } else { docenten[count] = new Docent("info", "artesis"); } int[] docentId = checkDocent(docenten); checkOlodDocentRelation(docentId, olodId); int[] klasid = checkKlas(recs.Klas); checkOlodKlasRelation(klasid, olodId); int duur = (recs.Duration%100)+((recs.Duration/100)*60); string room = null; foreach (string s in recs.Lokaal) { room += s + " "; } int dag = recs.Dag; CultureInfo ciCurr = CultureInfo.CurrentCulture; int week = ciCurr.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); SqlCommand addLes = connection.CreateCommand(); addLes.CommandText = "INSERT INTO Les (tijd, olod_id, duur_in_minuten,lokaal, dag, week) VALUES ('" + startTijd + "'," + olodId + ", " + +duur + ",'"+room+"'," + dag + "," + week + ")"; addLes.ExecuteNonQuery(); } catch (SqlException e) { Console.WriteLine(e.Message); } finally { connection.Close(); } }