コード例 #1
0
        private void Button_Click_4(object sender, RoutedEventArgs e) // Delete selected student
        {
            var selectedIndex = List.SelectedIndex;

            if (students.studentlist[selectedIndex].isHead == "+")
            {
                var rez = students.studentlist[selectedIndex].group;
                rez.head     = null;
                rez.headName = "-";
            }
            students.studentlist.Remove(students.studentlist[selectedIndex]);

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            FileNameTextBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;

            List.Items.Refresh();

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }
コード例 #2
0
 private void Clear_Click(object sender, EventArgs e)
 {
     IDBox.Clear();
     NameBox.Clear();
     SurnameBox.Clear();
     CityBox.Clear();
     MaleRadio.Checked   = false;
     FemaleRadio.Checked = false;
 }
コード例 #3
0
 private void ClearBoxes()
 {
     RegNumBox.Clear();
     NameBox.Clear();
     SurnameBox.Clear();
     EmailBox.Clear();
     PassBox.Clear();
     CourseTitleBox.Clear();
 }
コード例 #4
0
ファイル: AddNew_form.cs プロジェクト: szopqa/Address-Book
 /*Clears all TextBoxes */
 protected void clearAllBoxes()
 {
     SurnameBox.Clear();
     NameBox.Clear();
     PhoneBox.Clear();
     MailBox.Clear();
     CityBox.Clear();
     AddressBox.Clear();
     NoteBox.Clear();
 }
コード例 #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     using (StreamWriter stream = new StreamWriter("data.txt", true))
     {
         stream.WriteLine($"{SurnameBox.Text} {NameBox.Text} {textBox1.Text} {textBox2.Text} {textBox3.Text} {textBox4.Text} {textBox5.Text}");
     }
     NameBox.Clear();
     SurnameBox.Clear();
     textBox1.Clear();
     textBox2.Clear();
     textBox3.Clear();
     textBox4.Clear();
     textBox5.Clear();
 }
コード例 #6
0
        private void UpdateTeacherClick(object sender, RoutedEventArgs e)
        {
            string ConnectionString = @"Data Source=DESKTOP-15P21ID;Initial Catalog=kursovoi;Integrated Security=True";
            string sqlExpression    = $"SELECT id,name From facylties where name='{faculty}'";

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();
                SqlCommand    cm1     = connection.CreateCommand();
                try
                {
                    while (reader.Read())
                    {
                        object s = reader.GetValue(0);
                        fakk_id = Convert.ToInt32(s);
                    }
                    reader.Close();
                    if (fakk_id == 0)
                    {
                        MessageBox.Show("Такого факультета не существует");
                    }
                    else
                    {
                        cm1.CommandText = "update users set first_name='" + SurnameBox.Text + "',middle_name='" + NameBox.Text + "',login='******',email='" + PostBox.Text + "',faculty_id='" + fakk_id + "' where id='" + id_admin_panel + "'";
                        cm1.ExecuteNonQuery();
                        MessageBox.Show("Данные успешно обновлены!");
                    }
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    SurnameBox.Clear();
                    NameBox.Clear();
                    LoginBox.Clear();
                    PostBox.Clear();
                    FacultyBox.Clear();
                    connection.Close();
                    reader.Close();
                }
            }
        }
コード例 #7
0
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;
            FileNameTextBox.Clear();

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }
コード例 #8
0
        /// <summary>
        /// Głowna funkcja rejestrująca użytkownika.
        /// </summary>
        /// <returns>
        /// Funkcja Rejestracja() odpowiada za połączenie z bazą danych, zabezpieczenie hasła wprowadzonego przez użytkownika,
        /// a także przesłania danych do bazy danych.
        /// </returns>
        void Rejestracja()
        {
            //Połączenie z lokalną bazą danych.
            MySqlConnection polaczenie = new MySqlConnection("server=localhost; user=root; database=user; port=3306; pooling=false");
            MySqlCommand    komenda    = polaczenie.CreateCommand();
            MySqlCommand    komenda1   = polaczenie.CreateCommand();

            try
            {
                if (polaczenie.State == ConnectionState.Closed)
                {
                    polaczenie.Open();
                    //Sprawdza radiobutona, aby moc wprowadzić płeć użytkownika.
                    if (radioButtonMale.Checked == true)
                    {
                        plec = "male";
                    }
                    else if (radioButtonfemale.Checked == true)
                    {
                        plec = "female";
                    }
                    //Sprawdza które checboxy sa zaznaczone.
                    if (checkBox1.Checked == true && checkBox2.Checked == true && checkBox3.Checked == true && checkBox4.Checked == true)
                    {
                        wybor = "Rock,Pop,Metal,Other";
                    }
                    else if (checkBox1.Checked == true && checkBox2.Checked == true && checkBox3.Checked == true)
                    {
                        wybor = "Rock,Pop,Metal";
                    }
                    else if (checkBox1.Checked == true && checkBox2.Checked == true)
                    {
                        wybor = "Rock,Pop";
                    }
                    else if (checkBox1.Checked == true && checkBox3.Checked == true)
                    {
                        wybor = "Rock,Metal";
                    }
                    else if (checkBox1.Checked == true && checkBox4.Checked == true)
                    {
                        wybor = "Rock,Other";
                    }
                    else if (checkBox2.Checked == true && checkBox3.Checked == true)
                    {
                        wybor = "Pop,Metal";
                    }
                    else if (checkBox2.Checked == true && checkBox4.Checked == true)
                    {
                        wybor = "Pop,Other";
                    }
                    else if (checkBox3.Checked == true && checkBox4.Checked == true)
                    {
                        wybor = "Metal,Other";
                    }
                    else if (checkBox1.Checked == true)
                    {
                        wybor = "Rock";
                    }
                    else if (checkBox2.Checked == true)
                    {
                        wybor = "Pop";
                    }
                    else if (checkBox3.Checked == true)
                    {
                        wybor = "Metal";
                    }
                    else if (checkBox4.Checked == true)
                    {
                        wybor = "Other";
                    }
                    string haslo = PasswordBox.Text;
                    //hashowanie hasel.
                    using (MD5 hash = MD5.Create())
                    {
                        haslo = GetMd5Hash(hash, haslo);
                    }

                    komenda1.CommandText = string.Format("SELECT count(id) FROM user1 where Login='******'");
                    int wartosc = Convert.ToInt32(komenda1.ExecuteScalar());
                    if (wartosc == 1)
                    {
                        MessageBox.Show(String.Format("Login: {0}, already exists.", LoginBox.Text), "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        //komeda wstawiaajca dane z pol tekstowych.
                        komenda.CommandText = string.Format("INSERT INTO user1(Name,Surname,Login,Password,Music,Sex) VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", NameBox.Text, SurnameBox.Text, LoginBox.Text, haslo, wybor, plec);
                        //if sprawdzajacy czy komeda sie wykonala poprawnie --- czy zwrocila ilosc rzedow.
                        if (komenda.ExecuteNonQuery() == 1)
                        {
                            //komunkiat o poprawnym zajestestrowaniu uzytkownika.
                            MessageBox.Show("You have logged successfuly.", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //przejscie do panelu logownia
                            this.Hide();
                            LogPanel NewLogPanel = new LogPanel();
                            NewLogPanel.Show();
                        }
                        else
                        {
                            MessageBox.Show("Login Error.", "Informacja", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    NameBox.Clear(); SurnameBox.Clear(); LoginBox.Clear(); PasswordBox.Clear(); NameBox.Focus();
                }
            }
            catch (Exception ex)
            {
                string byk = string.Format("Problem registering user: \n{0}.", ex.Message);
                MessageBox.Show(byk, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                //jesli polaczenie jest otwarte, to zamnknij.
                if (polaczenie.State == ConnectionState.Open)
                {
                    polaczenie.Close();
                }
            }
        }
コード例 #9
0
        private void MenuItem_Click_1(object sender, RoutedEventArgs e)
        {
            GroupEnum   new_groups   = new GroupEnum();
            StudentEnum new_students = new StudentEnum();


            OpenFileDialog dialog = new OpenFileDialog();

            dialog.DefaultExt = ".zip";
            dialog.Filter     = "zip|*.zip";

            string selectedArchive = "";
            bool?  result          = dialog.ShowDialog();

            if (result == true)
            {
                selectedArchive = dialog.FileName;
            }
            else
            {
                return;
            }
            try
            {
                if (!Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer") && selectedArchive != "")
                {
                    ZipFile.ExtractToDirectory(selectedArchive, Directory.GetCurrentDirectory());
                }
                else
                {
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please, select another folder ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            FileStream   connector = new FileStream(Directory.GetCurrentDirectory() + @"\Buffer\Temp.txt", FileMode.Open);;
            StreamReader reader    = new StreamReader(connector);

            int groupsNumber = Convert.ToInt32(reader.ReadLine());

            reader.ReadLine();
            for (int i = 0; i < groupsNumber; i++)
            {
                reader.ReadLine();
                Group new_group = new Group();

                new_group.Number   = Convert.ToInt32(reader.ReadLine());
                new_group.Actual   = reader.ReadLine();
                new_group.headName = reader.ReadLine();
                int teachersNumber = Convert.ToInt32(reader.ReadLine());

                Group subject = new Group();
                if (teachersNumber != 0)
                {
                    reader.ReadLine();
                    for (int j = 0; j < teachersNumber; j++)
                    {
                        Group.struct_teachers new_teacher = new Group.struct_teachers();
                        new_teacher.Name    = reader.ReadLine();
                        new_teacher.Subject = reader.ReadLine();
                        subject.teachers.Add(new_teacher);
                    }
                    reader.ReadLine();
                    new_group.teachers = new List <Group.struct_teachers>(subject.teachers);
                }
                else
                {
                    reader.ReadLine();
                }

                reader.ReadLine();
                new_groups.groupList.Add(new_group);
            }
            reader.ReadLine();

            int studentsNumber = Convert.ToInt32(reader.ReadLine());

            reader.ReadLine();
            for (int i = 0; i < studentsNumber; i++)
            {
                reader.ReadLine();
                Student new_student = new Student();

                new_student.Name             = reader.ReadLine();
                new_student.Surname          = reader.ReadLine();
                new_student.Middlename       = reader.ReadLine();
                new_student.Year             = Convert.ToInt32(reader.ReadLine());
                new_student.isHead           = reader.ReadLine();
                new_student.groupHeading     = reader.ReadLine();
                new_student.group_number     = reader.ReadLine();
                new_student.old_group_number = reader.ReadLine();

                new_student.photoPath = reader.ReadLine();
                if (new_student.photoPath != "")
                {
                    BitmapImage StudentPhoto = new BitmapImage();
                    StudentPhoto.BeginInit();
                    StudentPhoto.UriSource   = new Uri(new_student.photoPath, UriKind.Absolute);
                    StudentPhoto.CacheOption = BitmapCacheOption.OnLoad;
                    StudentPhoto.EndInit();
                    new_student.studentPhoto = StudentPhoto;
                }

                int     marksNumber = Convert.ToInt32(reader.ReadLine());
                Student mark        = new Student();
                if (marksNumber != 0)
                {
                    reader.ReadLine();
                    for (int j = 0; j < marksNumber; j++)
                    {
                        Student.struct_marks new_mark = new Student.struct_marks();
                        new_mark.Mark    = Convert.ToInt32(reader.ReadLine());
                        new_mark.Subject = reader.ReadLine();
                        mark.marks.Add(new_mark);
                    }
                    reader.ReadLine();
                    new_student.marks = new List <Student.struct_marks>(mark.marks);
                }
                else
                {
                    reader.ReadLine();
                }

                reader.ReadLine();
                new_students.studentlist.Add(new_student);
            }

            for (int i = 0; i < new_groups.groupList.Count(); i++)
            {
                for (int j = 0; j < new_students.studentlist.Count(); j++)
                {
                    if (new_students.studentlist[j].group_number == Convert.ToString(new_groups.groupList[i].Number))
                    {
                        new_students.studentlist[j].group = new_groups.groupList[i];
                        if (new_students.studentlist[j].groupHeading == Convert.ToString(new_groups.groupList[i].Number))
                        {
                            new_groups.groupList[i].head = new_students.studentlist[j];
                        }
                    }
                    if (new_students.studentlist[j].old_group_number == Convert.ToString(new_groups.groupList[i].Number))
                    {
                        new_students.studentlist[j].oldGroup = new_groups.groupList[i];
                    }
                }
            }
            reader.Close();
            connector.Close();

            groups.groupList     = new_groups.groupList;
            students.studentlist = new_students.studentlist;

            List.ItemsSource = students.studentlist;
            List.Items.Refresh();
            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();

            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;
            HeadCheck.IsChecked         = false;
            FileNameTextBox.Text        = "";

            if (Directory.Exists(Directory.GetCurrentDirectory() + @"\Buffer"))
            {
                Directory.Delete(Directory.GetCurrentDirectory() + @"\Buffer", true);
            }

            MessageBox.Show("File loaded", "", MessageBoxButton.OK, MessageBoxImage.Information);
        }
コード例 #10
0
        private void Button_Click_3(object sender, RoutedEventArgs e) // Change information
        {
            if (String.IsNullOrWhiteSpace(NameBox.Text) || String.IsNullOrWhiteSpace(SurnameBox.Text) || String.IsNullOrWhiteSpace(Middlename.Text) || String.IsNullOrWhiteSpace(YearBox.Text))
            {
                MessageBox.Show("Please, fill all fields", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (NameBox.Text.Length > 16 || SurnameBox.Text.Length > 16 || Middlename.Text.Length > 16)
            {
                MessageBox.Show("Name, Surname and Middlename must not contain more than 16 letters ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (Convert.ToInt32(YearBox.Text) > 2017 || Convert.ToInt32(YearBox.Text) < 1950)
            {
                MessageBox.Show("In the year selection field number should be between 1950 to 2017", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                YearBox.Clear();
                return;
            }

            if (GroupCombo.SelectedItem != null && GroupCombo.SelectedItem == OldGroupCombo.SelectedItem)
            {
                MessageBox.Show("Old group and current group must be different", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                GroupCombo.SelectedItem    = null;
                OldGroupCombo.SelectedItem = null;
                return;
            }

            var selectedIndex = List.SelectedIndex;

            students.studentlist[selectedIndex].Name       = NameBox.Text;
            students.studentlist[selectedIndex].Surname    = SurnameBox.Text;
            students.studentlist[selectedIndex].Middlename = Middlename.Text;
            students.studentlist[selectedIndex].Year       = Convert.ToInt32(YearBox.Text);

            if (GroupCombo.SelectedItem == null)
            {
                students.studentlist[selectedIndex].group_number = "-";
                students.studentlist[selectedIndex].groupHeading = "-";
                students.studentlist[selectedIndex].isHead       = "-";
                students.studentlist[selectedIndex].group        = null;
            }
            else
            {
                students.studentlist[selectedIndex].group_number = GroupCombo.Text;
                var rez = (Group)GroupCombo.SelectedItem;

                if (HeadCheck.IsChecked == true)
                {
                    if (students.studentlist[selectedIndex].groupHeading != Convert.ToString(rez.Number))
                    {
                        if (rez != students.studentlist[selectedIndex].group)
                        {
                            if (students.studentlist[selectedIndex].isHead == "+")
                            {
                                var rez1 = students.studentlist[selectedIndex].group;
                                rez1.headName = "-";
                                rez1.head     = null;
                            }
                        }

                        if (rez.head == null)
                        {
                            students.studentlist[selectedIndex].isHead       = "+";
                            students.studentlist[selectedIndex].group_number = Convert.ToString(rez.Number);
                            students.studentlist[selectedIndex].groupHeading = students.studentlist[selectedIndex].group_number;
                            students.studentlist[selectedIndex].group        = rez;

                            rez.headName = students.studentlist[selectedIndex].Surname + " " + students.studentlist[selectedIndex].Name;
                            rez.head     = students.studentlist[selectedIndex];
                        }
                        else
                        {
                            students.studentlist[selectedIndex].group_number = Convert.ToString(rez.Number);
                            students.studentlist[selectedIndex].isHead       = "-";
                            students.studentlist[selectedIndex].groupHeading = "-";
                            students.studentlist[selectedIndex].group        = rez;
                            MessageBox.Show("This group already has a head. This student was not appointed head", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                    }
                    else
                    {
                        rez.headName = students.studentlist[selectedIndex].Surname + " " + students.studentlist[selectedIndex].Name;
                    }
                }
                else
                {
                    if (rez.head == students.studentlist[selectedIndex])
                    {
                        rez.head     = null;
                        rez.headName = "-";
                    }
                    students.studentlist[selectedIndex].isHead       = "-";
                    students.studentlist[selectedIndex].groupHeading = "-";
                }
                students.studentlist[selectedIndex].group = (Group)GroupCombo.SelectedItem;
            }

            if (students.studentlist[selectedIndex].isHead == "+")
            {
                students.studentlist[selectedIndex].groupHeading = students.studentlist[selectedIndex].group_number;
            }
            else
            {
                students.studentlist[selectedIndex].groupHeading = "-";
            }

            if (OldGroupCombo.SelectedItem == null)
            {
                students.studentlist[selectedIndex].old_group_number = "-";
            }
            else
            {
                students.studentlist[selectedIndex].old_group_number = OldGroupCombo.Text;
            }

            students.studentlist[selectedIndex].oldGroup = (Group)OldGroupCombo.SelectedItem;

            if (students.studentlist[selectedIndex].studentPhoto != null)
            {
                if ("file:///" + FileNameTextBox.Text != Convert.ToString(students.studentlist[selectedIndex].studentPhoto.UriSource))
                {
                    if (FileNameTextBox.Text != "")
                    {
                        BitmapImage StudentPhoto = new BitmapImage();
                        StudentPhoto.BeginInit();
                        StudentPhoto.UriSource   = new Uri(FileNameTextBox.Text, UriKind.Absolute);
                        StudentPhoto.CacheOption = BitmapCacheOption.OnLoad;
                        StudentPhoto.EndInit();
                        students.studentlist[selectedIndex].studentPhoto = StudentPhoto;
                        students.studentlist[selectedIndex].photoPath    = Convert.ToString(students.studentlist[selectedIndex].studentPhoto.UriSource);
                    }
                }
            }

            students.studentlist[selectedIndex].marks = new List <Student.struct_marks>(mark.marks);
            List.Items.Refresh();

            NameBox.Clear();
            SurnameBox.Clear();
            Middlename.Clear();
            YearBox.Clear();
            FileNameTextBox.Clear();
            GroupCombo.SelectedIndex    = -1;
            OldGroupCombo.SelectedIndex = -1;

            mark.marks.Clear();
            Table.ItemsSource = mark.marks;
            Table.Items.Refresh();

            AddButton.IsEnabled    = true;
            HeadCheck.IsChecked    = false;
            ChangeButton.IsEnabled = false;
            DeleteButton.IsEnabled = false;
        }