Exemplo n.º 1
0
        public List <Schoolchild> GetChildNameFromGuardianID(int ID)
        {
            Schoolchild        sc;
            List <Schoolchild> children = new List <Schoolchild>();

            string stmt = $"SELECT guardian_schoolchild.guardian_id, guardian_schoolchild.schoolchild_id, schoolchild.firstname, schoolchild.lastname " +
                          $"          FROM(guardian_schoolchild INNER JOIN schoolchild ON guardian_schoolchild.schoolchild_id = schoolchild.schoolchild_id) " +
                          $"          WHERE guardian_id = {ID}";

            using (var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand(stmt, conn))
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            sc = new Schoolchild()
                            {
                                id        = (reader.GetInt32(1)),
                                firstname = (reader.GetString(2)),
                                lastname  = (reader.GetString(3)),
                            };
                            children.Add(sc);
                        }
                    }
                return(children);
            }
        }
Exemplo n.º 2
0
        public void InsertSchedule(Schoolchild child, DateTime date, string day_off, string breakfast,
                                   DateTime should_drop, DateTime should_pickup, string walk_home_alone, string walk_with_friend)
        {
            Schoolchild schoolchild;

            schoolchild = child;

            string stmt = "INSERT INTO schedule(schoolchild_id, date, day_off, breakfast, " +
                          "should_drop, should_pickup, walk_home_alone, home_with_friend) " +
                          "VALUES(@id, @date, @day_off, @breakfast, @drop, @pickup, @walk_alone, @walk_friend) ";

            using (var conn = new
                              NpgsqlConnection(ConfigurationManager.ConnectionStrings["DbConn"].ConnectionString))

            {
                conn.Open();
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = stmt;
                    cmd.Parameters.AddWithValue("id", child.id);
                    cmd.Parameters.AddWithValue("date", date);
                    cmd.Parameters.AddWithValue("day_off", day_off);
                    cmd.Parameters.AddWithValue("breakfast", breakfast);
                    cmd.Parameters.AddWithValue("drop", should_drop);
                    cmd.Parameters.AddWithValue("pickup", should_pickup);
                    cmd.Parameters.AddWithValue("walk_alone", walk_home_alone);
                    cmd.Parameters.AddWithValue("walk_friend", walk_with_friend);
                    cmd.ExecuteNonQuery();
                }
            }
        }
Exemplo n.º 3
0
        public List <Schoolchild> GetSchoolchildrenOrderBySection() // Hämtar skolbarn och sorterar efter avdelning
        {
            Schoolchild        schoolchild;
            List <Schoolchild> schoolchildren = new List <Schoolchild>();

            string stmt = "SELECT lastname, firstname, section_name FROM schoolchild INNER JOIN section ON schoolchild.section_id = section.section_id ORDER BY section.section_id";

            using (var conn = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString))
            {
                conn.Open();
                using (var cmd = new NpgsqlCommand(stmt, conn))
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            schoolchild = new Schoolchild
                            {
                                lastname  = reader.GetString(0),
                                firstname = reader.GetString(1),
                                section   = reader.GetString(2)
                            };
                            schoolchildren.Add(schoolchild);
                        }
                    }
                return(schoolchildren);
            }
        }
Exemplo n.º 4
0
        private void BtnSaveNewSchedule_Click(object sender, RoutedEventArgs e)
        {
            schoolchild = (Schoolchild)listBoxChildName.SelectedItem;

            DateTime date             = DateTime.Parse(textBoxDate.Text);
            string   day_off          = textBoxDay_of.Text.ToString();
            string   breakfast        = textBoxBreakfast.Text.ToString();
            DateTime should_drop      = DateTime.Parse(textBoxShould_drop.Text);
            DateTime should_pickup    = DateTime.Parse(textBoxShould_pickup.Text);
            string   walk_home_alone  = textBoxWalk_home_alone.Text.ToString();
            string   walk_with_friend = textBoxHome_with_friend.Text.ToString();

            db.InsertSchedule(schoolchild, date, day_off, breakfast, should_drop, should_pickup, walk_home_alone, walk_with_friend);

            MessageBox.Show($"Ditt schema har lagts till för {schoolchild.firstname} den {textBoxDate.Text.ToString()}.");
        }
Exemplo n.º 5
0
        private void listBoxChildName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            schoolchild = (Schoolchild)listBoxChildName.SelectedItem;

            label_child_schema.Content = schoolchild + "  schema";
        }