예제 #1
0
        public Nabidka Read(int id)
        {
            UzivatelDao   dao  = new UzivatelDao();
            Nabidka       n    = null;
            SqlConnection conn = DatabaseConnection.GetInstance();

            using (SqlCommand command = new SqlCommand("SELECT * FROM nabidka WHERE id = @Id", conn))
            {
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@Id";
                param.Value         = id;

                command.Parameters.Add(param);
                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    n = new Nabidka(
                        castka: Int32.Parse(reader[1].ToString()),
                        prihazujici: dao.GetById(Int32.Parse(reader[2].ToString())));
                    n.ID = Int32.Parse(reader[0].ToString());
                }
                reader.Close();
                return(n);
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            DatabazeUzivatelu db   = DatabazeUzivatelu.Instance;
            DrazebniDatabaze  test = new DrazebniDatabaze();

            try
            {
                db.NactiUzivatele();
                foreach (var uzivatel in db.uzivatele)
                {
                    Console.WriteLine(uzivatel);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Uzivatel u1 = db.GetById(1);
            Uzivatel u2 = db.GetById(2);
            Uzivatel u3 = db.GetById(3);

            Nabidka n1 = new Nabidka(u1, 25);
            Nabidka n2 = new Nabidka(u1, 15);
            Nabidka n3 = new Nabidka(u2, 35);

            Auto bmw   = new Auto("bmw", Skupina.A, DateTime.Now, 75, 4);
            Auto skoda = new Auto("Skoda", Skupina.B, DateTime.Now, 85, 6);

            Drazba d = new Drazba(bmw, "sdffffffffffwsefwefwef");

            d.pridej(n1);
            d.pridej(n2);
            d.pridej(n3);

            Drazba d2 = new Drazba(skoda, "adwaduadhqaudhhudli");

            d2.pridej(n1);
            d2.pridej(n2);
            d2.pridej(n3);

            test.PridejDrazbu(d);
            test.PridejDrazbu(d2);


            Console.WriteLine(n1.PrihazujiciID());
            Console.WriteLine(n3.PrihazujiciID());

            Console.WriteLine(test.AktualniDrazba);
            test.DrazbaSkoncila();
            Console.WriteLine(test.AktualniDrazba);
            test.DrazbaSkoncila();
        }
예제 #3
0
        public void Update(Nabidka n)
        {
            SqlConnection conn    = DatabaseConnection.GetInstance();
            SqlCommand    command = null;
            UzivatelDao   dao     = new UzivatelDao();

            using (command = new SqlCommand("UPDATE uzivatel SET jmeno=@jmeno,heslo=@heslo,adresa=@adresa, where id = @id", conn))
            {
                command.Parameters.Add(new SqlParameter("@id", n.ID));
                command.Parameters.Add(new SqlParameter("@castka", n.castka));
                command.Parameters.Add(new SqlParameter("@heslo", dao.UzivatelID(n.prihazujici)));
                command.ExecuteNonQuery();
            }
        }
예제 #4
0
        public int GetID(Nabidka n)
        {
            SqlConnection conn = DatabaseConnection.GetInstance();

            using (SqlCommand command = new SqlCommand("SELECT * FROM nabidka WHERE id = @id", conn))
            {
                command.Parameters.Add(new SqlParameter("@id", n.ID));
                SqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    return(Int32.Parse(reader[0].ToString()));
                }
                reader.Close();
                return(0);
            }
        }
예제 #5
0
        public void Create(Nabidka n, Drazba d)
        {
            SqlConnection conn    = DatabaseConnection.GetInstance();
            SqlCommand    command = null;
            UzivatelDao   dao     = new UzivatelDao();
            DrazbaDAO     daoD    = new DrazbaDAO();

            using (command = new SqlCommand("INSERT INTO nabidka(castka,uzivatel_id,drazba_id) VALUES (@castka,@uzivatel_id,@drazba_id)", conn))
            {
                command.Parameters.Add(new SqlParameter("@castka", n.castka));
                command.Parameters.Add(new SqlParameter("@uzivatel_id", dao.UzivatelID(n.prihazujici)));
                command.Parameters.Add(new SqlParameter("@drazba_id", daoD.GetID(d)));
                command.ExecuteNonQuery();
                command.CommandText = "Select @@Identity";
                n.ID = Convert.ToInt32(command.ExecuteScalar());
            }
        }