Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.5 kB
3
Indexable
Never
 private async Task FillStudents()
        {
            try
            {
                txtsearchstudent.Text = "";
                studprogress.Visibility = Visibility.Visible;
                await Conopen();
                studentsList.Clear();
                Sqlcmd.Parameters.Clear();
                ListStudents.ItemsSource = null;
                Strsql = $"Select TOP {Default.display_rows} * from V_Students order by LRN";
                Sqlcmd.CommandText = Strsql;
                Sqlcmd.Connection = Cnn;
                Sqladapter.SelectCommand = Sqlcmd;
                Sqlreader = await Sqlcmd.ExecuteReaderAsync();
                while (Sqlreader.Read())
                {
                    var dte = Sqlreader["last_date_attended"];
                    var startDateTime = DateTime.ParseExact((dte as string)!, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    var a = startDateTime.Date.ToString("ddd, dd MMMM yyyy");
                    studentsList.Add(new Students
                    {
                        LRN = Sqlreader["LRN"].ToString()!,
                        fullname = Sqlreader["fullname"].ToString()!,
                        Address = Sqlreader["Address"].ToString()!,
                        S_mobile_number = Sqlreader["S_mobile_number"].ToString()!,
                        gender = Sqlreader["gender"].ToString()!,
                        guardian_name = Sqlreader["guardian_name"].ToString()!,
                        guardian_relationship = Sqlreader["guardian_relationship"].ToString()!,
                        guardian_address = Sqlreader["guardian_address"].ToString()!,
                        guardian_mobile = Sqlreader["guardian_mobile"].ToString()!,
                        last_date_attended = a!,
                        img = new BitmapImage(new Uri($"file:///{currentAssemblyParentPath}/net6.0-windows/StudentImages/{Sqlreader["img"]}"))
                    });
                }
                Sqlcmd.Dispose();
                await Sqlreader.CloseAsync();
                Strsql = "";
                ListStudents.ItemsSource = studentsList;
                studprogress.Visibility = Visibility.Collapsed;
                Sqlcmd.Dispose();
                await Sqlreader.CloseAsync();
                Cnn.Close();
            //Count total
                await Tot_Count();

            }
            catch
            {
                studprogress.Visibility = Visibility.Collapsed;
            }
        }