private Kontrahent TworzenieKontrahenta(string zapytanie) { _command = new SQLiteCommand(zapytanie, _dbConnection); SQLiteDataReader reader = _command.ExecuteReader(); Kontrahent kontrahent = new Kontrahent(); while (reader.Read()) { kontrahent = new Kontrahent { Id = Int32.Parse(reader["id"].ToString()), Nazwa = reader["nazwa"].ToString(), NazwaSkrocona = reader["nazwaSkrocona"].ToString(), Nip = reader["nip"].ToString(), Regon = reader["regon"].ToString(), Telefon = reader["telefon"].ToString(), Email = reader["email"].ToString(), Status = (Status)Int32.Parse(reader["status"].ToString()), FormaZaplaty = (FormaZaplaty)Int32.Parse(reader["formaZaplaty"].ToString()), TerminZaplaty = Int32.Parse(reader["terminZaplaty"].ToString()) }; } return(kontrahent); }
internal int DodajKontrahenta(Kontrahent kontrahent) { var wynik = 0; var zapytanie = $"INSERT INTO Kontrahent " + $"(nazwa, nazwaSkrocona, nip, regon, telefon, email, status, formaZaplaty, terminZaplaty) VALUES " + $"('{kontrahent.Nazwa}','{kontrahent.NazwaSkrocona}','{kontrahent.Nip}','{kontrahent.Regon}','{kontrahent.Telefon}'," + $"'{kontrahent.Email}', {(int)kontrahent.Status}, {(int)kontrahent.FormaZaplaty}, {kontrahent.TerminZaplaty})"; try { _dbConnection.Open(); _command = new SQLiteCommand(zapytanie, _dbConnection); wynik = _command.ExecuteNonQuery(); kontrahent.Id = kontrahent.AdresSiedziby.IdKontrahenta = kontrahent.AdresKorespondencyjny.IdKontrahenta = kontrahent.KontoBankowe.IdKontrahenta = PobierzId(); DodajAdres(TypAdresu.siedziby, kontrahent.AdresSiedziby); DodajAdres(TypAdresu.korespondencyjny, kontrahent.AdresKorespondencyjny); DodajKontoBankowe(kontrahent.KontoBankowe); } catch (Exception e) { MessageBox.Show(e.Message); } finally { _dbConnection.Close(); } return(wynik); }
internal void AktualizujKontrahenta(Kontrahent kontrahent, int id) { var zapytanie = $"UPDATE Kontrahent SET nazwa = '{kontrahent.Nazwa}', nazwaSkrocona = '{kontrahent.NazwaSkrocona}', " + $"nip = '{kontrahent.Nip}', regon = '{kontrahent.Regon}', telefon = '{kontrahent.Telefon}', " + $"email = '{kontrahent.Email}', status = {(int)kontrahent.Status}, formaZaplaty = {(int)kontrahent.FormaZaplaty}, " + $" terminZaplaty = {kontrahent.TerminZaplaty} WHERE id = {id}"; try { _dbConnection.Open(); _command = new SQLiteCommand(zapytanie, _dbConnection); _command.ExecuteNonQuery(); AktualizujKontoBankowe(id, kontrahent.KontoBankowe); AktualizujAdres(id, TypAdresu.siedziby, kontrahent.AdresSiedziby); AktualizujAdres(id, TypAdresu.korespondencyjny, kontrahent.AdresKorespondencyjny); } catch (Exception e) { MessageBox.Show(e.Message); } finally { _dbConnection.Close(); } }
internal Kontrahent PobierzKontrahenta(int id) { var zapytanie = $"SELECT id, nazwa, nazwaSkrocona, nip, regon, telefon, email, status, formaZaplaty, terminZaplaty FROM Kontrahent WHERE id={id} LIMIT 1"; Kontrahent kontrahent = null; try { _dbConnection.Open(); kontrahent = TworzenieKontrahenta(zapytanie); kontrahent.KontoBankowe = PobranieKonta(kontrahent.Id); kontrahent.AdresSiedziby = PobranieAdresu(TypAdresu.siedziby, kontrahent.Id); kontrahent.AdresKorespondencyjny = PobranieAdresu(TypAdresu.korespondencyjny, kontrahent.Id); } catch (Exception e) { MessageBox.Show(e.Message); } finally { _dbConnection.Close(); } return(kontrahent); }