public List <korisnik> Select() { string query = "SELECT * FROM korisnik"; List <korisnik> list = new List <korisnik>(); //String name, surname, phone, email, userName, password; //int idKor, status, tip, address; //Open connection if (this.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { var korisnici1 = new korisnik(); string pret = dataReader[0] + ""; korisnici1.idKorisnik = Int32.Parse(pret); korisnici1.ime = dataReader[1] + ""; korisnici1.prezime = dataReader[2] + ""; korisnici1.telefon = dataReader[3] + ""; korisnici1.email = dataReader[4] + ""; string bStatus = dataReader[5] + ""; korisnici1.status = Int32.Parse(bStatus); string bTip = dataReader[6] + ""; korisnici1.tip = Int32.Parse(bTip); korisnici1.korisnickoIme = dataReader[7] + ""; korisnici1.sifra = dataReader[8] + ""; string bAddress = dataReader[9] + ""; korisnici1.adresa = Int32.Parse(bAddress); list.Add(korisnici1); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return(list); } else { return(list); } }
private void btnAddMembership_Click(object sender, RoutedEventArgs e) { dt = new DateTime(); dtUntil = new DateTime(); dt = DateTime.Now; model currentModel = (model)listBoxModel.SelectedItem; korisnik currentUser = (korisnik)listBoxUser.SelectedItem; dtUntil = dt.AddDays(currentModel.trajanje); string date1 = dt.ToString("yyyy-MM-dd HH:mm:ss"); string date2 = dtUntil.ToString("yyyy-MM-dd HH:mm:ss"); string query = "insert into clanarina (model, korisnik, datumAktivacija, datumDeaktivacije) values (" + "'" + currentModel.idKorisnik + "'" + "," + "'" + currentUser.idKorisnik + "'" + "," + "'" + date1 + "'" + "," + "'" + date2 + "'" + ")"; db.insert(query); }