コード例 #1
0
 private static void PrepareCommand(SqlCommand command, Zamestnanec Zamestnanec)
 {
     command.Parameters.AddWithValue("@idZam", Zamestnanec.idZam);
     command.Parameters.AddWithValue("@Jmeno", Zamestnanec.Jmeno);
     command.Parameters.AddWithValue("@Prijmeni", Zamestnanec.Prijmeni);
     command.Parameters.AddWithValue("@email", Zamestnanec.email);
     command.Parameters.AddWithValue("@Datum_narozeni", Zamestnanec.Datum_narozeni);
 }
コード例 #2
0
        public static int update(Zamestnanec Zamestnanec)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_UPDATE);

            PrepareCommand(command, Zamestnanec);
            int ret = db.ExecuteNonQuery(command);

            db.Close();
            return(ret);
        }
コード例 #3
0
        private static Collection <Zamestnanec> Read(SqlDataReader reader, bool withItemsCount = false)
        {
            Collection <Zamestnanec> zamestnanci = new Collection <Zamestnanec>();

            while (reader.Read())
            {
                Zamestnanec zamestnanec = new Zamestnanec();
                int         i           = -1;
                zamestnanec.idZam          = reader.GetInt32(++i);
                zamestnanec.Jmeno          = reader.GetString(++i);
                zamestnanec.Prijmeni       = reader.GetString(++i);
                zamestnanec.email          = reader.GetString(++i);
                zamestnanec.Datum_narozeni = reader.GetDateTime(++i).Date;

                zamestnanci.Add(zamestnanec);
            }
            return(zamestnanci);
        }
コード例 #4
0
        static void ZamTest()
        {
            Zamestnanec zam = new Zamestnanec
            {
                idZam          = 1,
                Jmeno          = "Steve",
                Prijmeni       = "Nojobs",
                email          = "*****@*****.**",
                Datum_narozeni = new DateTime(1989, 7, 15)
            };

            Console.WriteLine("Testovani funkce zamestnance Insert - Vypis poctu prvku - update - select - delete - Vypis poctu prvku.\n"
                              + zam.Jmeno + " " + zam.Prijmeni);

            ZamestnanecTable.insert(zam);

            int count = ZamestnanecTable.select().Count;

            zam.Jmeno    = "Zmenil";
            zam.Prijmeni = "Jmeno";

            ZamestnanecTable.update(zam);

            zam.Jmeno    = "a";
            zam.Prijmeni = "b";

            Console.WriteLine("#C: " + count);

            zam = ZamestnanecTable.select(1);

            Console.WriteLine(zam.Jmeno + " " + zam.Prijmeni);

            ZamestnanecTable.delete(1);

            count = ZamestnanecTable.select().Count;

            ZamestnanecTable.insert(zam);

            Console.WriteLine("#C: " + count + "\n" + "Test pro tabulku zamestnanec ukoncen, stisknutim libovolne klavesy pokracujte k dalsimu testu.");

            Console.ReadKey();
        }
コード例 #5
0
        public static Zamestnanec select(int idZam)
        {
            Database db = new Database();

            db.Connect();
            SqlCommand command = db.CreateCommand(SQL_SELECT_ID);

            command.Parameters.AddWithValue("@idZam", idZam);
            SqlDataReader reader = db.Select(command);

            Collection <Zamestnanec> zamestnanci = Read(reader);
            Zamestnanec zamestnanec = null;

            if (zamestnanci.Count == 1)
            {
                zamestnanec = zamestnanci[0];
            }
            reader.Close();
            db.Close();
            return(zamestnanec);
        }