/// <summary> /// Handle the end of the dragging action /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Student_Drop(object sender, DragEventArgs e) { PlaceDisplay placeDisplay = (PlaceDisplay)((FrameworkElement)sender).DataContext; NameDisplay data = (NameDisplay)e.Data.GetData(typeof(NameDisplay)); if (placeDisplay.StudentId != 0) { return; } placeDisplay.Content = data.Name; placeDisplay.StudentId = data.ID; StudentPlaceDisplay studentPlace = new StudentPlaceDisplay() { StudentId = data.ID, Row = placeDisplay.Row, Column = placeDisplay.Column }; studentPlaceList.Add(studentPlace); ((IList)dragSource.ItemsSource).Remove(data); }
public PlanEditPage(int scheduleId, int classroomId) //Create plan { studentPlanList = new ObservableCollection <ObservableCollection <PlaceDisplay> >(); ScheduleInfo schedule = Database.Get.Schedule.FromId(scheduleId); if (schedule.scheduleId == null) { MessageBox.Show("Un probème est surnvenu"); return; } RoomInfo roomInfo = Database.Get.Room.FromID((int)schedule.roomId); if (roomInfo == null) { MessageBox.Show("Salle inexistante"); return; } roomId = (int)schedule.roomId; this.scheduleId = scheduleId; rowNumber = roomInfo.Rows; columnNumber = roomInfo.Columns; //double itemWidth = _mainGrid.ColumnDefinitions[1].ActualWidth / columnNumber; //double itemHeight = _mainGrid.RowDefinitions[0].ActualHeight / rowNumber; int initItemHeight = 60; int initItemWidth = 60; for (int i = 0; i < rowNumber; i++) { studentPlanList.Add(new ObservableCollection <PlaceDisplay>()); for (int j = 0; j < columnNumber; j++) { //if (j == 1) //{ // PlaceDisplay placeDisplay = new PlaceDisplay() // { // ItemHeight = (int)initItemHeight, // ItemWidth = (int)initItemWidth, // AbsoluteWidth = columnSkipSize, // Content = "", // Drop = false, // Thickness = 0 // }; // studentPlanList[i].Add(placeDisplay); //} else //{ PlaceDisplay placeDisplay = new PlaceDisplay() { Row = i, Column = j, ItemHeight = initItemHeight, ItemWidth = initItemWidth, AbsoluteWidth = 0, Content = $"Glisser déposer ici pour\nplacer l'élève {i} {j}", Drop = true, Thickness = 1, StudentId = 0 }; studentPlanList[i].Add(placeDisplay); //} } } InitializeComponent(); buttonList = new List <Button>(); List <string> spacingList = new List <string>(); //if (planId != null) //{ // List<PlanInfo> plan = Database.Get.Plan.FromScheduleId(scheduleId); // spacingList = plan.spacing.Split(",").ToList(); // planId = plan.planId; //} for (int i = 0; i < columnNumber - 1; i++) { Button btn = new Button(); btn.Content = "|"; btn.Height = 20; btn.Width = 20; btn.HorizontalAlignment = HorizontalAlignment.Left; btn.Tag = i; btn.Click += SpacingButton_Click; //btn.Margin = new Thickness(80 * (i + 1), 0, 0, 0); _mainGrid.Children.Add(btn); Grid.SetRow(btn, 0); Grid.SetColumn(btn, 1); string found = spacingList.Find(x => x == i.ToString()); if (found != null) { btn.IsEnabled = false; } buttonList.Add(btn); } List <StudentInfo> studentList = Database.Get.Student.AllFromClassroomId(classroomId); foreach (StudentInfo student in studentList) { NameDisplay nameDisplay = new NameDisplay() { ID = student.studentId, Name = String.Join(" ", new string[] { student.surname, student.lastname }) }; studentCollection.Add(nameDisplay); } _studentList.ItemsSource = studentCollection; _lst.ItemsSource = studentPlanList; }