Beispiel #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            Del_Stu del_student = new Del_Stu();

            del_student.ShowDialog();
            students.standart_obr(students.writePath, listBox1);
        }
Beispiel #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            fix_st();
            Del_Stu student = new Del_Stu();

            student.ShowDialog();
            fix_st();
            reload_st();
        }
Beispiel #3
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string          connStr = "server=localhost;user=root;database=Students;password=0000;";
         MySqlConnection conn    = new MySqlConnection(connStr);
         conn.Open();
         string          sql     = "SELECT `ID`, `FIO`, `Group` FROM `students`";
         MySqlCommand    command = new MySqlCommand(sql, conn);
         MySqlDataReader reader  = command.ExecuteReader();
         while (reader.Read())
         {
             if (Convert.ToInt32(reader[0].ToString()) == listBox1.SelectedIndex + 1)
             {
                 string message = "Вы хотите удалить студента " + reader[1] + " из " + reader[2] + " группы?";
                 var    result  = MessageBox.Show(message, "Удаление",
                                                  MessageBoxButtons.YesNo,
                                                  MessageBoxIcon.Question);
                 if (result == DialogResult.Yes)
                 {
                     string delet = "DELETE FROM `students` WHERE ID = " + reader[0];
                     command = new MySqlCommand(delet, conn);
                 }
             }
         }
         reader.Close();
         command.ExecuteNonQuery();
         conn.Close();
         Close();
     }
     catch (Exception z)
     {
         Del_Stu student = new Del_Stu();
         student.ShowDialog();
     }
 }
Beispiel #4
0
 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         string text_after_del = "";
         using (FileStream fstream = new FileStream(writePath, FileMode.OpenOrCreate))
         {
             byte[] output = new byte[4];
             fstream.Seek(0, SeekOrigin.Begin);
             output = new byte[fstream.Length];
             fstream.Read(output, 0, output.Length);
             // декодируем байты в строку
             string textFromFile = Encoding.Default.GetString(output);
             text_after_del = textFromFile;
         }
         using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
         {
             char[] charsToTrim = { '\r' };
             string result      = text_after_del.Trim(charsToTrim);
             sw.WriteLine(result);
         }
         using (FileStream fstream = new FileStream(writePath, FileMode.OpenOrCreate))
         {
             byte[] output = new byte[4];
             fstream.Seek(0, SeekOrigin.Begin);
             output = new byte[fstream.Length];
             fstream.Read(output, 0, output.Length);
             // декодируем байты в строку
             string textFromFile = Encoding.Default.GetString(output);
             char[] charsToTrim  = { '\r' };
             textFromFile   = textFromFile.Trim(charsToTrim);
             text_after_del = textFromFile;
             string[] mystring = textFromFile.Split('\n');
             //Разделил файл на строки, теперь разделим строки на слова.
             int      N                = mystring.Length - 1;
             int      dolg             = 0;;
             string[] mass_of_students = new string[N];
             for (int i = 0; i < N; i++)
             {
                 mass_of_students[i] = "";
             }
             bool     prov  = false;
             string[] words = mystring[listBox1.SelectedIndex].Split(' ');
             dolg = Convert.ToInt32(words[4]);
             for (int i = 5; i < 5 + Convert.ToInt32(words[4]); i++)
             {
                 //MessageBox.Show("" + words[i]);
                 if (words[i] == "-1")
                 {
                     dolg--;
                     prov = true;
                 }
                 else if (Convert.ToInt32(words[i]) >= 0)
                 {
                     prov = false;
                 }
             }
             if (prov)
             {
                 string       message = "Вы хотите удалить студента " + words[0] + " " + words[1] + " " + words[2] + " из " + words[3] + " группы? Все задания ВЫПОЛНЕННЫ! Поздравляю студента!";
                 const string caption = "Form Closing";
                 var          result  = MessageBox.Show(message, caption,
                                                        MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question);
                 if (result == DialogResult.Yes)
                 {
                     //Удаление студента
                     string substr = mystring[listBox1.SelectedIndex] + "\n";
                     text_after_del = textFromFile.Replace(substr, "");
                 }
             }
             else
             {
                 string       message = "Вы хотите удалить студента " + words[0] + " " + words[1] + " " + words[2] + " из " + words[3] + " группы? Ещё не выполненны " + dolg + "/" + words[4] + " заданий!";
                 const string caption = "Form Closing";
                 var          result  = MessageBox.Show(message, caption,
                                                        MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Question);
                 if (result == DialogResult.Yes)
                 {
                     string substr = mystring[listBox1.SelectedIndex] + "\n";
                     text_after_del = textFromFile.Replace(substr, "");
                 }
             }
         }
         using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
         {
             char[] charsToTrim = { '\r' };
             string result      = text_after_del.Trim(charsToTrim);
             sw.WriteLine(result);
             Close();
         }
     }
     catch (Exception z)
     {
         Del_Stu student = new Del_Stu();
         student.ShowDialog();
     }
 }