コード例 #1
0
        public string addArhiva(Arhiva data)
        {
            try
            {
                connection();
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO Arhiva(id_arhiva,naziv,datoteka) " +
                                      " VALUES(@id_arhiva,@naziv,@datoteka)";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@id_arhiva", data.id_zgrada);
                    cmd.Parameters.AddWithValue("@naziv", data.naziv);
                    cmd.Parameters.AddWithValue("@datoteka", data.datoteka);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    return("OK");
                }
            }
            catch (Exception err)
            {
                con.Close();
                return("Error");
            }
        }
コード例 #2
0
        public string updateArhiva(Arhiva data)
        {
            try
            {
                connection();
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection  = con;
                    cmd.CommandText = "UPDATE Arhiva SET naziv = @naziv, datoteka = @datoteka  WHERE id = @id";
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.AddWithValue("@id_arhiva", data.id_arhiva);
                    cmd.Parameters.AddWithValue("@naziv", data.naziv);
                    cmd.Parameters.AddWithValue("@datoteka", data.datoteka);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    return("OK");
                }
            }
            catch (Exception err)
            {
                con.Close();
                return("Error");
            }
        }
コード例 #3
0
        public List <Arhiva> GetArhiva()
        {
            connection();
            List <Arhiva> arhiva = new List <Arhiva>();

            con.ConnectionString = str;
            using (MySqlCommand cmd = new MySqlCommand())
            {
                cmd.Connection  = con;
                cmd.CommandText = "SELECT id_arhiva, naziv, datoteka  FROM Arhiva ORDER BY naziv ASC";
                con.Open();
                using (MySqlDataReader sdr = cmd.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            Arhiva emp = new Arhiva()
                            {
                                id_arhiva = Convert.ToInt32(sdr["id_arhiva"]),
                                naziv     = sdr["naziv"].ToString(),
                                datoteka  = sdr["datoteka"].ToString(),
                            };
                            if (emp.naziv.Length > 0 && emp.datoteka.Length > 0)
                            {
                                arhiva.Add(emp);
                            }
                        }
                    }
                }
                con.Close();
            }
            return(arhiva);
        }
コード例 #4
0
        public Arhiva getArhivaID(int _id)
        {
            connection();
            Arhiva arhiva = new Arhiva();

            con.ConnectionString = str;
            using (MySqlCommand cmd = new MySqlCommand())
            {
                cmd.Connection  = con;
                cmd.CommandText = "SELECT id_arhiva, naziv, datoteka  FROM Arhiva WHERE id=+@id";
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.AddWithValue("@id", _id);
                con.Open();
                using (MySqlDataReader sdr = cmd.ExecuteReader())
                {
                    if (sdr.HasRows)
                    {
                        while (sdr.Read())
                        {
                            arhiva = new Arhiva()
                            {
                                id_arhiva = Convert.ToInt32(sdr["id_arhiva"]),
                                naziv     = sdr["naziv"].ToString(),
                                datoteka  = sdr["datoteka"].ToString(),
                            };
                        }
                    }
                }
                con.Close();
            }
            return(arhiva);
        }