Beispiel #1
0
        public List <Vacations> RetriveVacation(Name name)
        {
            string query     = "SELECT * FROM Puhkused AS a INNER JOIN Nimed AS b ON b.Id = a.UserID WHERE b.id = @User_Id";
            var    vacations = new List <Vacations>();

            using (Connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, Connection))
                    using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                    {
                        Connection.Open();
                        command.Parameters.AddWithValue("@User_Id", name.id);

                        command.ExecuteScalar();

                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                Vacations vacation = new Vacations();

                                vacation._Id       = Convert.ToInt32(reader["Id"]);
                                vacation._vacEnd   = Convert.ToDateTime(reader["VacEnd"]);
                                vacation._vacStart = Convert.ToDateTime(reader["VacStart"]);
                                vacation._UserID   = Convert.ToInt32(reader["UserID"]);
                                vacations.Add(vacation);
                            }
                        }
                        Connection.Close();
                    }
            return(vacations);
        }
Beispiel #2
0
        public void InsertVacation(Vacations vacations)
        {
            string query = "INSERT INTO Nimed VALUES (@VacStart, @VacEnd, @UserID);";

            using (Connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, Connection))
                {
                    Connection.Open();

                    command.Parameters.AddWithValue("@VacStart", vacations._vacEnd);
                    command.Parameters.AddWithValue("@VacEnd", vacations._vacStart);
                    command.Parameters.AddWithValue("@UserID", vacations._UserID);

                    command.ExecuteNonQuery();
                }
        }
Beispiel #3
0
        private void AddVacation_Click(object sender, EventArgs e)
        {
            Name name = new Name();

            name.name = Person_Enter.Text;

            Vacations vacation = new Vacations();

            vacation._vacEnd   = dateEnd.Value;
            vacation._vacStart = dateStart.Value;
            vacation._UserID   = names[Person_Enter.SelectedIndex].id;

            Database database = new Database();

            database.InsertVacation(vacation);
        }