private void Button_Click(object sender, RoutedEventArgs e) { // try { OpenFileDialog openFileDialog = new OpenFileDialog(); { openFileDialog.Title = "Select picture of patient"; openFileDialog.Filter = "Image files(*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; openFileDialog.InitialDirectory = Environment.CurrentDirectory; openFileDialog.Multiselect = false; } string hhh = ""; if (openFileDialog.ShowDialog() == true) { picture = openFileDialog.FileName; byteImage = File.ReadAllBytes(picture); foreach (byte b in byteImage) { hhh = hhh + (char)b; } } if (TextPesel.Text.Length == 11) { kln = new Pacjent(TextImie.Text, TextNazwisko.Text, TextUlica.Text, TextMiasto.Text, TextKraj.Text, Convert.ToInt32(TextNr.Text), Convert.ToInt32(TextWiek.Text), Convert.ToInt64(TextPesel.Text), byteImage); MainWindow.klient.Add(kln); sqladd = "Insert into Base(Imie,Nazwisko,Ulica,Miasto,Kraj,Nr,Wiek,Pesel,Image) values('" + TextImie.Text + "','" + TextNazwisko.Text + "','" + TextUlica.Text + "','" + TextMiasto.Text + "','" + TextKraj.Text + "'," + Convert.ToInt32(TextNr.Text) + "," + Convert.ToInt32(TextWiek.Text) + "," + Convert.ToInt64(TextPesel.Text) + ",@data)"; mainwindow.savebaze(sqladd, byteImage); this.Hide(); } else { MessageBox.Show("zla dlugosc pesela"); } } // catch { MessageBox.Show("nr ulicy,wiek i pesel musi byc liczba"); } }
private void InitializeSql() { connetionString = @"Data Source=DESKTOP-3SJ6CNC\ASDF2019;Initial Catalog=Lista6;User ID=sa;Password=asdf"; //connetionString = @"Server = localhost; Database = Music; User Id = SA; Password = yourStrong(!)Password;"; cnn = new SqlConnection(connetionString); cnn.Open(); SqlDataReader dataReader; sql = "Select Imie,Nazwisko,Ulica,Nr,Miasto,Kraj,Wiek,Pesel,Image from Base"; command = new SqlCommand(sql, cnn); dataReader = command.ExecuteReader(); //MessageBox.Show(Output); klient = new ObservableCollection <Pacjent>(); while (dataReader.Read()) { Pacjent pacjent = new Pacjent(); pacjent.imie = (String)dataReader["Imie"]; pacjent.nazwisko = (String)dataReader["Nazwisko"]; pacjent.ulica = (String)dataReader["Ulica"]; pacjent.nr = (int)dataReader["Nr"]; pacjent.miasto = (String)dataReader["Miasto"]; pacjent.kraj = (String)dataReader["Kraj"]; pacjent.wiek = (int)dataReader["Wiek"]; pacjent.pesel = (long)dataReader["Pesel"]; //pacjent.image = Encoding.ASCII.GetBytes((string)dataReader["Image"]); pacjent.image = (byte[])dataReader["Image"]; klient.Add(pacjent); } dataReader.Close(); command.Dispose(); cnn.Close(); }
private void ButtonZapisz_Click(object sender, RoutedEventArgs e) { try { if (TextPesel.Text.Length == 11) { kln = new Pacjent(TextImie.Text, TextNazwisko.Text, TextUlica.Text, TextMiasto.Text, TextKraj.Text, Convert.ToInt32(TextNr.Text), Convert.ToInt32(TextWiek.Text), Convert.ToInt64(TextPesel.Text), byteImage); string sqladd = "Update Baza set Imie='" + TextImie.Text + "',Nazwisko='" + TextNazwisko.Text + "',Ulica='" + TextMiasto.Text + "',Kraj='" + TextKraj.Text + "',Nr=" + Convert.ToInt32(TextNr.Text) + ",Wiek=" + Convert.ToInt32(TextWiek.Text) + ",Pesel=" + Convert.ToInt64(TextPesel.Text) + " where Pesel=" + MainWindow.klient[mainwindow.i].pesel; mainwindow.changebaze(sqladd); MainWindow.klient[mainwindow.i] = (kln); this.Hide(); } else { MessageBox.Show("zla dlugosc pesela"); } } catch { MessageBox.Show("nr ulicy,wiek i pesel musi byc liczba"); } }