Пример #1
0
        private void Display_DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid dg = sender as DataGrid;

            if (dg.SelectedItem is DataRowView drv)
            {
                Type_ComboBox.ItemsSource = null;
                var comboItems = LoadComboBox(dg, 3);
                Type_ComboBox.ItemsSource = comboItems;

                Subject_ComboBox.ItemsSource = null;
                comboItems = LoadComboBox(dg, 4);
                Subject_ComboBox.ItemsSource = comboItems;

                this.DataContext = classRoomTask = new ClassRoomTask
                {
                    Id                 = drv["Id"].ToString(),
                    WhenDate           = drv["Date"].ToString(),
                    Vote               = drv["Vote"].ToString(),
                    ClassRoomTaskType  = drv["Task Type"].ToString(),
                    SubjectDescritpion = drv["Subject"].ToString(),
                };

                AddButton.IsEnabled    = false;
                UpdateButton.IsEnabled = true;
                DeleteButton.IsEnabled = true;
            }
        }
Пример #2
0
 public DataClassRoomTask()
 {
     InitializeComponent();
     classRoomTask = new ClassRoomTask();
     dbConnection  = new DbConnection();
 }
        public void LoadDataGrid(string subject)
        {
            var dbConnection = new DbConnection();

            Homeworks_DataGrid.ItemsSource = null;
            using (_SqlConn = new SqlConnection(dbConnection.PrepareStringConnection()))
            {
                _Comm = _SqlConn.CreateCommand();
                _SqlConn.Open();

                _Comm.CommandText = "select h.Description, CONVERT(date, h.StartDate), CONVERT(date, h.EndDate), s.Description" +
                                    " from Homeworks as h " +
                                    "join Subjects as s on s.Id = h.SubjectId " +
                                    $"where s.Description = '{subject}' " +
                                    "order by h.StartDate ";
                _Comm.CommandType = CommandType.Text;
                var homeWorkList = new List <HomeWork>();
                using (SqlDataReader reader = _Comm.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            HomeWork hw = new HomeWork
                            {
                                Description = reader.GetString(0),
                                Start_Date  = reader.GetDateTime(1),
                                End_Date    = reader.IsDBNull(2)
                                ? (DateTime?)null
                                : reader.GetDateTime(2),
                                SubjectDescription = reader.GetString(3)
                            };
                            hw.StartDate = hw.Start_Date.ToString("dd/MM/yyyy");
                            hw.EndDate   = hw.End_Date == null ? "" : hw.End_Date.Value.ToString("dd/MM/yyyy");
                            homeWorkList.Add(hw);
                        }
                        Homeworks_DataGrid.ItemsSource = homeWorkList;
                    }
                }

                ClassTasks_DataGrid.ItemsSource = null;
                _Comm.CommandText = "select ctt.Description, CONVERT(date, ct.WhenDate), ct.Vote " +
                                    "from ClassroomTasks as ct " +
                                    "join Subjects as s on s.Id = SubjectId " +
                                    "join ClassroomTaskTypes as ctt on ctt.Id = TaskId " +
                                    $"where s.Description = '{subject}' " +
                                    "order by ct.WhenDate ";
                _Comm.CommandType = CommandType.Text;
                var classRoomTask = new List <ClassRoomTask>();
                using (SqlDataReader reader = _Comm.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            ClassRoomTask crt = new ClassRoomTask
                            {
                                ClassRoomTaskType = reader.GetString(0),
                                When_Date         = reader.GetDateTime(1),
                                Vote = reader.IsDBNull(2)
                                ? ""
                                : reader.GetInt32(2).ToString(),
                            };
                            crt.WhenDate = crt.When_Date.ToString("dd/MM/yyyy");
                            classRoomTask.Add(crt);
                        }
                        ClassTasks_DataGrid.ItemsSource = classRoomTask;
                    }
                }
            }
        }