コード例 #1
0
        public VlasnikVozila Get(int id)
        {
            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand command = new MySqlCommand(GetQuery, connection.Connection);
                connection.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                command.Parameters.Add("@id", MySqlDbType.Int32).Value = id;
                try
                {
                    return(null);

                    command.ExecuteReader().Read();
                    Lice lice = new LiceDao().Get(reader.GetInt32(reader.GetOrdinal("Lice_id")));
                    if (lice == null)
                    {
                        return(null);
                    }
                    return(new VlasnikVozila(id, lice));
                }
                finally
                {
                    reader.Close();
                }
            }
        }
コード例 #2
0
ファイル: FindThemAll.cs プロジェクト: Nefistofeles/Form
        public void FindThemAllInformation()
        {
            string          query      = "select * from question_option inner join question on question.id = question_option.question_id inner join form on question.form_id = form.id order by form.id";
            MySqlConnection connection = MyMySQLConnection.ConnectionSingleton();
            MySqlCommand    command    = new MySqlCommand(query, connection);

            try
            {
                connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                    }
                }

                command.Dispose();
                reader.Dispose();
                connection.Close();
            }
            catch (Exception error)
            {
                Console.WriteLine(error.ToString());
            }
        }
コード例 #3
0
        public List <Vozilo> GetAll()
        {
            List <Vozilo> vozila = new List <Vozilo>();

            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand command = new MySqlCommand(GetAllQuery, connection.Connection);
                connection.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        vozila.Add(new Vozilo(
                                       reader.GetInt32(reader.GetOrdinal("id")),
                                       (string)reader["marka"],
                                       (string)reader["model"],
                                       int.Parse((string)reader["godiste"]),
                                       (string)reader["registarskiBroj"],
                                       (string)reader["brojSasije"],
                                       (string)reader["brojMotora"],
                                       new VlasnikVozilaDao().Get(reader.GetInt32(reader.GetOrdinal("VlasnikVozila_id")))));
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return(vozila);
        }
コード例 #4
0
        public Vozilo Get(int id)
        {
            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand command = new MySqlCommand(GetQuery, connection.Connection);
                command.Parameters.Add("@id", MySqlDbType.Int32).Value = id;
                connection.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        return(new Vozilo(id,
                                          (string)reader["marka"],
                                          (string)reader["model"],
                                          (int)reader["godiste"],
                                          (string)reader["registarskiBroj"],
                                          (string)reader["brojSasije"],
                                          (string)reader["brojMotora"],
                                          new VlasnikVozilaDao().Get(reader.GetInt32(reader.GetOrdinal("VlasnikVozila_id")))));
                    }

                    return(null);
                }
                finally
                {
                    reader.Close();
                }
            }
        }
コード例 #5
0
        public List <Lice> GetAll()
        {
            List <Lice> lica = new List <Lice>();

            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand command = new MySqlCommand(GetAllQuery, connection.Connection);
                connection.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        lica.Add(new Lice(
                                     reader.GetInt32(reader.GetOrdinal("id")),
                                     (string)reader["ime"],
                                     (string)reader["prezime"],
                                     (string)reader["brojLicneKarte"],
                                     (string)reader["jmbg"],
                                     new MjestoStanovanja(
                                         reader.GetInt32(reader.GetOrdinal("MjestoStanovanja_id")),
                                         (string)reader["grad"],
                                         (string)reader["opstina"],
                                         (string)reader["ulica"],
                                         (string)reader["broj"]),
                                     (TipLica)Enum.Parse(typeof(TipLica), (string)reader["TipLica"])));
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return(lica);
        }
コード例 #6
0
        public void Save(VoziloOdFirme t)
        {
            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand cmd = new MySqlCommand("add_vozilo_za_prodaju", connection.Connection);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("id", MySqlDbType.Int32).Direction         = ParameterDirection.Output;
                cmd.Parameters.Add("markaIn", MySqlDbType.VarChar).Value      = t.Vozilo.Marka;
                cmd.Parameters.Add("modelIn", MySqlDbType.VarChar).Value      = t.Vozilo.Model;
                cmd.Parameters.Add("godisteIn", MySqlDbType.Year).Value       = t.Vozilo.GodinaProizvodnje;
                cmd.Parameters.Add("tabliceIn", MySqlDbType.VarChar).Value    = t.Vozilo.RegistarskiBroj;
                cmd.Parameters.Add("brojSasijeIn", MySqlDbType.VarChar).Value = t.Vozilo.BrojSasije;
                cmd.Parameters.Add("brojMotoraIn", MySqlDbType.VarChar).Value = t.Vozilo.BrojMotora;
                cmd.Parameters.Add("cijenaIn", MySqlDbType.Double).Value      = t.Cijena;
                cmd.Parameters.Add("snizenjeIn", MySqlDbType.Double).Value    = t.Snizenje;
                cmd.Parameters.Add("opisIn", MySqlDbType.VarChar).Value       = t.Opis;

                try
                {
                    connection.Connection.Open();
                    cmd.ExecuteNonQuery();
                    int id = int.Parse(cmd.Parameters["id"].Value.ToString());
                    t.Id = id;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Greška");
                }

                MySqlCommand commandImages = new MySqlCommand(AddImages, connection.Connection);
                commandImages.CommandType = CommandType.Text;
                commandImages.Prepare();
                if (t.Id.HasValue)
                {
                    foreach (var slikaBytes in t.Slike)
                    {
                        commandImages.Parameters.Clear();
                        commandImages.Parameters.Add("@id", MySqlDbType.Int32).Value       = t.Id.Value;
                        commandImages.Parameters.Add("@slika", MySqlDbType.LongBlob).Value = slikaBytes;
                        commandImages.ExecuteNonQuery();
                    }
                }
                connection.Connection.Close();
            }
        }
コード例 #7
0
        public List <VoziloOdFirme> GetAll()
        {
            List <VoziloOdFirme> vozila = new List <VoziloOdFirme>();

            using (MyMySQLConnection connection = new MyMySQLConnection())
            {
                MySqlCommand command = new MySqlCommand("get_all_vozila_za_prodaju", connection.Connection);
                command.CommandType = CommandType.StoredProcedure;
                connection.Connection.Open();
                MySqlDataReader reader = command.ExecuteReader();
                try
                {
                    while (reader.Read())
                    {
                        /*
                         * voziloodfirme.id, Vozilo_id, cijena, snizenje, opis, slika, marka, model, godiste, registarskiBroj, brojSasije, brojMotora, VlasnikVozila_id, Lice_id, ime, prezime, brojLicneKarte, jmbg, TipLica, MjestoStanovanja_id, grad, opstina, ulica, broj
                         */
                        vozila.Add(new VoziloOdFirme(
                                       Convert.IsDBNull(reader["id"]) ? default : reader.GetInt32(reader.GetOrdinal("id")),
                                       new Vozilo(
                                           Convert.IsDBNull(reader["Vozilo_id"])
                                    ? default
                                    : reader.GetInt32(reader.GetOrdinal("Vozilo_id")),
                                           Read <string>(reader, "marka"),
                                           Read <string>(reader, "model"),
                                           Read <int>(reader, "godiste"),
                                           Read <string>(reader, "registarskiBroj"),
                                           Read <string>(reader, "brojSasije"),
                                           Read <string>(reader, "brojMotora"),
                                           new VlasnikVozila(
                                               Convert.IsDBNull(reader["VlasnikVozila_id"])
                                        ? default
                                        : reader.GetInt32(reader.GetOrdinal("VlasnikVozila_id")),
                                               Convert.IsDBNull(reader["Lice_id"])
                                        ? default
                                        : reader.GetInt32(reader.GetOrdinal("Lice_id")),
                                               Read <string>(reader, "ime"),
                                               Read <string>(reader, "prezime"),
                                               Read <string>(reader, "brojLicneKarte"),
                                               Read <string>(reader, "jmbg"),
                                               new MjestoStanovanja(
                                                   Convert.IsDBNull(reader["MjestoStanovanja_id"])
                                            ? default
                                            : reader.GetInt32(reader.GetOrdinal("MjestoStanovanja_id")),
                                                   Read <string>(reader, "grad"),
                                                   Read <string>(reader, "opstina"),
                                                   Read <string>(reader, "ulica"),
                                                   Read <string>(reader, "broj")),
                                               (TipLica)Enum.Parse(typeof(TipLica),
                                                                   Read <string>(reader, "TipLica")))),
                                       new List <byte[]>(),
                                       Read <double>(reader, "cijena"),
                                       Read <double>(reader, "snizenje"),
                                       Read <string>(reader, "opis")));
                    }
                }
                finally
                {
                    reader.Close();
                }

                MySqlCommand    commandImages = new MySqlCommand(GetImages, connection.Connection);
                MySqlDataReader readerImages  = commandImages.ExecuteReader();
                try
                {
                    while (readerImages.Read())
                    {
                        int    id    = readerImages.GetInt32(readerImages.GetOrdinal("VoziloOdFirme_id"));
                        byte[] slika = (byte[])readerImages["slika"];
                        vozila.First(e => e.Id == id).Slike.Add(slika);
                    }
                }
                finally
                {
                    readerImages.Close();
                }

                return(vozila);
            }
        }