상속: User
예제 #1
0
 public void Save(Student student)
 {
     Boolean insert = true;
     if (student.Id != 0)
     {
         insert = false;
     }
     base.Save(student);
     this._db.OpenConnection();
     MySqlCommand command = this._db.CreateCommand();
     if (insert)
     {
         command.CommandText = "INSERT INTO student (user_id, studentnumber, study) VALUES " +
         "(?user_id, ?studentnumber, ?study)";
     }
     else
     {
         command.CommandText = "UPDATE student (studentnumber, study) VALUES " +
         "(?studentnumber, ?study) WHERE user_id = ?user_id";
     }
     command.Parameters.Add(new MySqlParameter("?user_id", MySqlDbType.Int32)).Value = student.Id;
     command.Parameters.Add(new MySqlParameter("?studentnumber", MySqlDbType.Int32)).Value = student.Studentnumber;
     command.Parameters.Add(new MySqlParameter("?study", MySqlDbType.String)).Value = student.Study;
     this._db.ExecuteCommand(command);
     this._db.CloseConnection();
     if (insert)
     {
         Pair pair = new Pair();
         pair.Student1 = student;
         pair.Student1_id = student.Id;
         PAZController.GetInstance().PairMapper.Save(pair);
     }
 }
예제 #2
0
파일: Pair.cs 프로젝트: PAZ-MI4Ie/PAZ
 public Pair(int id, Student student1, Student student2, int number_of_guests)
 {
     ID = id;
     Student1 = student1;
     Student2 = student2;
     Number_of_guests = number_of_guests;
 }
예제 #3
0
 public Student ProcessRow(Student student, MySqlDataReader Reader, int offset)
 {
     base.ProcessRow(student, Reader, offset);
     //student data
     student.Studentnumber = Reader.GetInt32(8 + offset);
     student.Study = Reader.GetString(9 + offset);
     return student;
 }
예제 #4
0
 public Student ProcessRow(Student student, MySqlDataReader Reader)
 {
     return this.ProcessRow(student, Reader, 0);
 }
예제 #5
0
        /*
         * import button
         * (C) Mark de Mol
         *
         * Shows a browse dialog. User must select a CSV file to import.
         * The CSV file must contain user data.
         *
         * TO DO:
         *  - ADD EACH ITEM TO THE DATABASE
         */
        private void buttonImport_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".csv";
            dlg.Title = "Open een CSV-gebruikers bestand";
            dlg.Filter = "CSV-bestand|*.csv";
            Nullable<bool> result = dlg.ShowDialog();

            if (result == true)
            {
                if (dlg.CheckFileExists)
                {
                    string filename = dlg.FileName;
                    string line;
                    StreamReader file = null;

                    try
                    {
                        file = new StreamReader( filename );
                        int a = 0;
                        List<Student> duplicates = new List<Student>();

                        while ((line = file.ReadLine()) != null)
                        {

                            string[] csvResult = line.Split(new Char[] { ',' });
                            if(a != 0)
                            {
                                Student student = new Student();

                                for (int i = 0; i < csvResult.Length; i++)
                                {
                                    Console.WriteLine(csvResult[4]);
                                    switch (i)
                                    {
                                        case 0: student.Firstname = csvResult[0]; break;
                                        case 1: student.Surname = csvResult[1]; break;
                                        case 2: student.Studentnumber = Convert.ToInt32(csvResult[2]); break;
                                        case 3: student.Study = csvResult[3]; break;
                                        case 4: student.Email = csvResult[4]; break;
                                    }

                                }
                                if (_controller.UserMapper.FindWithDuplicateCheck(Convert.ToInt32(csvResult[2]), csvResult[4]))
                                {
                                    duplicates.Add(student);
                                }
                                else
                                {
                                    _controller.StudentMapper.Save(student);
                                    MessageBox.Show("Importeren is gelukt. Alle items zijn toegevoegd.");
                                }
                            }
                            a++;
                        }

                        if (duplicates.Count > 0)
                        {
                            String dup = "duplicaten.txt";
                            if (!File.Exists(dup))
                            {
                                TextWriter tw = new StreamWriter(dup);

                                foreach (Student duplicate in duplicates)
                                {
                                    tw.WriteLine(duplicate.Studentnumber + "," + duplicate.Firstname + "" + duplicate.Surname + "," + duplicate.Email);
                                }
                                MessageBox.Show("Er zijn " + duplicates.Count + " duplicaten gevonden. Deze zijn niet geimporteerd, maar opgeslagen in een tekst-bestand. Dit bestand (duplicaten.txt) kunt u vinden in de map van de applicatie.\n\n De andere items zijn wel toegevoegd.");
                                tw.Close();
                            }
                            else
                            {
                                /*
                                 *  misschien voor later
                                 *
                                 *  - to add:
                                 *    - check in de duplicaten.txt of die student er
                                 *      al in staat, zo niet add hem. Zo wel, doe niks.
                                 *
                                 *  voor de rest werkt alles al.
                                 *
                                 * (C) Mark & Mark (H)
                                 *
                                 */
                                StreamWriter tw = File.AppendText("duplicaten.txt");
                                foreach (Student duplicate in duplicates)
                                {

                                    tw.WriteLine(duplicate.Studentnumber + "," + duplicate.Firstname + "" + duplicate.Surname + "," + duplicate.Email);
                                    tw.Flush();
                                }
                                MessageBox.Show("Er zijn " + duplicates.Count + " duplicaten gevonden. Deze zijn niet geimporteerd, maar opgeslagen in een tekst-bestand. Dit bestand (duplicaten.txt) kunt u vinden in de map van de applicatie. \n\n De andere items zijn wel toegevoegd.");
                                tw.Close();

                            }
                        }
                    }
                    finally
                    {
                        if (file != null)
                            file.Close();
                    }

                }
                else
                    MessageBox.Show("Bestand niet gevonden.");
            }
        }
예제 #6
0
        private void onStudentAddClicked(object sender, RoutedEventArgs e)
        {
            //Use this for input errors
            bool hasInputError = false;

            //Check study
            if (textBoxStudy.Text.Equals(String.Empty))
            {
                textBoxStudy.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                textBoxStudy.BorderBrush = Brushes.Gray;
            }

            //Check email adress
            if (EmailLeering1.Text.Equals(String.Empty))
            {
                EmailLeering1.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                EmailLeering1.BorderBrush = Brushes.Gray;
            }
            if (!EmailLeering1.Text.IsValidEmailAddress())
            {
                EmailLeering1.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                EmailLeering1.BorderBrush = Brushes.Gray;
            }

            //Check student number
            if (textBoxStudentennummer.Text.Equals(String.Empty))
            {
                textBoxStudentennummer.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                textBoxStudentennummer.BorderBrush = Brushes.Gray;
            }

            //Check first name
            if (textBoxVoornaam.Text.Equals(String.Empty))
            {
                textBoxVoornaam.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                textBoxVoornaam.BorderBrush = Brushes.Gray;
            }

            //Check surname
            if (textBoxAchternaam.Text.Equals(String.Empty))
            {
                textBoxAchternaam.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                textBoxAchternaam.BorderBrush = Brushes.Gray;
            }

            //Check Blocked timeslots

            if (blockedDayTimes.SelectedItem == null)
            {
                blockedDayTimes.BorderBrush = Brushes.Red;
                hasInputError = true;
            }
            else
            {
                blockedDayTimes.BorderBrush = Brushes.Gray;
            }

            if (_controller.StudentMapper.FindWithDuplicateCheck(int.Parse(textBoxStudentennummer.Text), EmailLeering1.Text))
            {
                textBoxStudentennummer.BorderBrush = Brushes.Red;
                EmailLeering1.BorderBrush = Brushes.Red;
                hasInputError = true;
                MessageBox.Show("Studentnummer of emailadres bestaat al.");
            }

            if (hasInputError == false)
            {
                //Create expert object and add values
                Student newStudent = new Student();
                newStudent.Firstname = textBoxVoornaam.Text;
                newStudent.Surname = textBoxAchternaam.Text;
                newStudent.Email = EmailLeering1.Text;
                newStudent.Studentnumber = Convert.ToInt32(textBoxStudentennummer.Text);
                newStudent.Study = textBoxStudy.Text;
                newStudent.WasChanged = false;
                Blocked_timeslot timeslot = new Blocked_timeslot();

                //Blocked Timeslot
                ListBoxItem selectedItem = (ListBoxItem)blockedDayTimes.SelectedItem;
                string date = selectedItem.Content.ToString();
                List<Daytime> foundDayTimes = _controller.DaytimeMapper.FindWithDate(date);
                foreach (Daytime thisTimeslot in foundDayTimes)
                {
                    newStudent.BlockedTimeslots.Add(new Blocked_timeslot(thisTimeslot, true));
                }

                //Send to the database
                _controller.StudentMapper.Save(newStudent);
                MessageBox.Show("Student toegevoegd");
                textBoxVoornaam.Text = "";
                textBoxAchternaam.Text = "";
                EmailLeering1.Text = "";
                textBoxStudentennummer.Text = "";
            }
        }