Ejemplo n.º 1
0
        public static StudentInfo PollInformation(StudentInfo info, bool isEditing = false)
        {
            AddStudentWindow win = new AddStudentWindow();

            if (isEditing)
            {
                win.txtTitle.Text = "Edit Student";
            }

            win.iptName.Text           = info.Name;
            win.cboGrade.SelectedIndex = info.Grade;
            win.iptEBookCode.Text      = info.EBook != null ? info.EBook.Name : "";

            if (info.EBook != null)
            {
                win.dteEBookRenewal.DisplayDate = info.EBook.ExpiresOn;
                win.dteEBookRenewal.Text        = info.EBook.ExpiresOn.ToShortDateString();
            }

            win.information = info;

            win.ShowDialog();

            return(win.information);
        }
Ejemplo n.º 2
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            Button           clicked  = (Button)e.Source;
            List <UIElement> children = GetChildrenInRow(Grid.GetRow(clicked), gridStudents);

            TextBlock nameBox  = (TextBlock)children[0];
            TextBlock gradeBox = (TextBlock)children[1];
            TextBlock eBookBox = (TextBlock)children[2];

            StudentInfo studentInfo = new StudentInfo()
            {
                Name  = nameBox.Text,
                Grade = !gradeBox.Text.Equals("K") ? int.Parse(gradeBox.Text) : 0,
                EBook = (EBook)eBookBox.DataContext
            };

            info.Remove(studentInfo);

            string name  = studentInfo.Name;
            string eBook = studentInfo.EBook?.Name;

            studentInfo = AddStudentWindow.PollInformation(studentInfo);

            if (studentInfo != null)
            {
                nameBox.Text         = studentInfo.Name;
                nameBox.DataContext  = studentInfo;
                gradeBox.Text        = studentInfo.Grade != 0 ? studentInfo.Grade + "" : "K";
                eBookBox.Text        = studentInfo.EBook.Name;
                eBookBox.DataContext = studentInfo.EBook;

                info.Add(studentInfo);
                Save();

                if (!studentInfo.EBook.Name.Equals(eBook))
                {
                    Print.AddAction(name, eBook, PrintAction.RemoveEBook, DateTime.Now);
                    Print.AddAction(studentInfo.Name, studentInfo.EBook.Name, PrintAction.GrantEBook, DateTime.Now);
                }
            }
            else
            {
                Print.AddAction(name, eBook, PrintAction.RemoveEBook, DateTime.Now);

                RowDefinition def = (RowDefinition)gradeBox.DataContext;

                foreach (UIElement item in children)
                {
                    gridStudents.Children.Remove(item);
                }

                gridStudents.RowDefinitions.Remove(def);

                Save();
            }
        }
Ejemplo n.º 3
0
        private void btnAddNew_Click(object sender, RoutedEventArgs e)
        {
            StudentInfo info = AddStudentWindow.PollInformation();

            if (info != null && info.EBook != null)
            {
                CreateStudentElement(info);
            }

            scrStudents.ScrollToEnd();
        }