public static void insertIntoOsnovneInformacije(RacunIzCSV rcsv, string idNadgledanaFirma) { string query; SqlCommand command; query = "INSERT INTO [OsnovneInformacije](IDNadgledanaFirma, PIB)" + "VALUES(@idNadgledanaFirma,@pib)"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@idNadgledanaFirma", idNadgledanaFirma.Trim()); command.Parameters.AddWithValue("@pib", (rcsv.PIB == null) ? DBNull.Value : (object)rcsv.PIB); command.ExecuteNonQuery(); command.Dispose(); }
public static void insertIntoRacuni(RacunIzCSV rcsv, String idNadgledanaFirma, String danRacuna) { DateTime datumOtvaranjaDT, datumPromeneDT, datumAzuriranjaDT; datumOtvaranjaDT = datumPromeneDT = datumAzuriranjaDT = DateTime.Now; string query; SqlCommand command; try { if (rcsv.datumOtvaranja != null && rcsv.datumOtvaranja.Length == 10) { datumOtvaranjaDT = DateTime.ParseExact(rcsv.datumOtvaranja, "dd.MM.yyyy", CultureInfo.InvariantCulture); } if (rcsv.datumPromene != null && rcsv.datumPromene.Length == 10) { datumPromeneDT = DateTime.ParseExact(rcsv.datumPromene, "dd.MM.yyyy", CultureInfo.InvariantCulture); } if (rcsv.datumAzuriranja != null && rcsv.datumAzuriranja.Length == 10) { datumAzuriranjaDT = DateTime.ParseExact(rcsv.datumAzuriranja, "dd.MM.yyyy", CultureInfo.InvariantCulture); } } catch (Exception e) { Console.WriteLine(rcsv.maticniBroj + " NEUSPENO UBACIVANJE " + e.ToString()); return; } query = "INSERT INTO [Racun](IDNadgledanaFirma,NazivBanke,BrojRacuna, DatumOtvaranja,DanRacuna, StatusRacunaSC) " + "VALUES(@idNadgledanaFirma,@nazivBanke,@brojRacuna,@datumOtvaranja,@danRacuna,@statusRacunaSC)"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@idNadgledanaFirma", idNadgledanaFirma); command.Parameters.AddWithValue("@nazivBanke", (rcsv.banka == null) ? DBNull.Value : (object)rcsv.banka.Replace("\"", "'").Trim());// ovo se radi zbog AIK banke command.Parameters.AddWithValue("@brojRacuna", (rcsv.brojRacuna == null) ? DBNull.Value : (object)rcsv.brojRacuna.Trim()); command.Parameters.AddWithValue("@datumOtvaranja", (rcsv.datumOtvaranja == null) ? DBNull.Value : (object)datumOtvaranjaDT); command.Parameters.AddWithValue("@danRacuna", danRacuna.Trim()); command.Parameters.AddWithValue("@statusRacunaSC", (rcsv.statusRacunaSC == null) ? DBNull.Value : (object)rcsv.statusRacunaSC.Trim()); command.ExecuteNonQuery(); command.Dispose(); }
public static void uploadSource(String filePath) { Console.WriteLine(DateTime.Now + ": Pocinje upload novog source-a..."); RacunIzCSV rcsv; StreamReader sr; CsvReader csvread; int lineCount; int i; // inicijalizacija rcsv = null; sr = new StreamReader(filePath); csvread = new CsvReader(sr); lineCount = File.ReadLines(filePath).Count(); i = 1; DBBasicFunctions.openConnection(); DBBasicFunctions.shiftOld(); csvread.Configuration.HasHeaderRecord = false; while (csvread.Read()) { rcsv = new RacunIzCSV(csvread); while (rcsv.maticniBroj == null) //ako maticni broj ne postoji { rcsv = new RacunIzCSV(csvread); } DBBasicFunctions.writeRacuniIzCSV(rcsv); if (i % 1000 == 0) { Console.WriteLine("Upisao " + i + "/" + lineCount); } i++; } DBBasicFunctions.closeConnection(); Console.WriteLine(DateTime.Now + ": Zavrsen upload source-a."); }
public static void writeRacuniIzCSV(RacunIzCSV rcsv) { string idNadgledanaFirma = null; // provera u nadgledana firma idNadgledanaFirma = proveraMBuNadgledanaFirma(rcsv.maticniBroj); // insert u nadgledana firma if (idNadgledanaFirma == null) { idNadgledanaFirma = insertIntoNadgledanaFirma(rcsv.maticniBroj); } // provera i insert u osnovne informacije if (!proveraIDNadgledanaUOsnovneInformacije(idNadgledanaFirma)) { insertIntoOsnovneInformacije(rcsv, idNadgledanaFirma); } insertIntoRacuni(rcsv, idNadgledanaFirma, "N"); }