Form1.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  12. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
  13. namespace oprosnik
  14. {
  15. public partial class Form1 : Form
  16. {
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21. public string filePath;
  22. public string selectedGender;
  23. public string selectedEducation;
  24. public string SelectedCheckBox;
  25. public string prefix;
  26. public string imagePath;
  27. private void button1_Click(object sender, EventArgs e)
  28. {
  29. //
  30. //специальность
  31. switch (comboBox2.SelectedItem)
  32. {
  33. case "Лесозаготовки":
  34. prefix = "ЛЗ";
  35. break;
  36. case "Администратирование базз данных":
  37. prefix = "АД";
  38. break;
  39. case "Разработчик Веб и мультимидийных - приложений":
  40. prefix = "РП";
  41. break;
  42. case "Гостиничное Дело":
  43. prefix = "ГД";
  44. break;
  45. case "Сальто Назад":
  46. prefix = "СН";
  47. break;
  48. default:
  49. prefix = "Неизвестно";
  50. break;
  51. }
  52. filePath = Convert.ToString(prefix + "_" + textBox1.Text + ".txt");
  53. if (!File.Exists(filePath))
  54. {
  55. using (File.Create(filePath))
  56. {
  57. Console.WriteLine("Файл создан: " + filePath);
  58. }
  59. }
  60. using (StreamWriter fileStream = File.AppendText(filePath))
  61. {
  62. try
  63. {
  64. if (imagePath == null || textBox1.Text == "" || selectedGender == null || textBox2.Text == "" || textBox3.Text == "" || selectedEducation == null || richTextBox1.Text == "" || textBox4.Text == "" || textBox6.Text == "" || textBox7.Text == "" || comboBox1.SelectedItem == null || comboBox2.SelectedItem == null)
  65. {
  66. MessageBox.Show("Заполните все поля!!!", "Ошибка");
  67. }
  68. else
  69. {
  70. List<System.Windows.Forms.CheckBox> checkBoxes = Interes.Controls.OfType<System.Windows.Forms.CheckBox>().ToList();
  71. Console.WriteLine("Файл открыт для чтения: " + filePath);
  72. fileStream.WriteLine(textBox1.Text);
  73. fileStream.WriteLine(textBox7.Text);
  74. fileStream.WriteLine(textBox6.Text);
  75. fileStream.WriteLine(selectedGender);
  76. fileStream.WriteLine(dateTimePicker1.Value);
  77. fileStream.WriteLine(textBox2.Text);
  78. fileStream.WriteLine(textBox3.Text);
  79. fileStream.WriteLine(comboBox1.SelectedItem);
  80. fileStream.WriteLine(comboBox2.SelectedItem);
  81. fileStream.WriteLine(selectedEducation);
  82. fileStream.WriteLine(richTextBox1.Text);
  83. fileStream.WriteLine(imagePath + " - Путь до картинки, а как еще её в текстовый файл записать? мм?");
  84. fileStream.WriteLine(" ");
  85. fileStream.WriteLine("Интересы:");
  86. foreach (System.Windows.Forms.CheckBox checkBox in checkBoxes)
  87. {
  88. if (checkBox.Checked)
  89. {
  90. fileStream.WriteLine(checkBox.Text);
  91. }
  92. }
  93. fileStream.WriteLine(" ");
  94. fileStream.WriteLine(textBox4.Text);
  95. fileStream.WriteLine(dateTimePicker2.Value);
  96. fileStream.WriteLine(" ");
  97. }
  98. }
  99. catch (Exception exept)
  100. {
  101. MessageBox.Show(string.Format("Произошла ошибка {0}", exept), "Ошибка");
  102. }
  103. }
  104. }
  105. //Радио кнопки
  106. private void radioButton_CheckedChanged(object sender, EventArgs e)
  107. {
  108. System.Windows.Forms.RadioButton selectedRadioButton = Gender.Controls.OfType<System.Windows.Forms.RadioButton>().FirstOrDefault(r => r.Checked);
  109. if (selectedRadioButton != null)
  110. {
  111. selectedGender = selectedRadioButton.Text;
  112. }
  113. }
  114. //Мужской
  115. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  116. {
  117. System.Windows.Forms.RadioButton selectedRadioButton = Education.Controls.OfType<System.Windows.Forms.RadioButton>().FirstOrDefault(r => r.Checked);
  118. if (selectedRadioButton != null)
  119. {
  120. selectedEducation = selectedRadioButton.Text;
  121. }
  122. }
  123. //Женский
  124. private void button2_Click(object sender, EventArgs e)
  125. {
  126. openFileDialog1.Filter = "Image Files|*.jpg;*.jpeg;*.png;*.gif;*.bmp";
  127. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  128. {
  129. imagePath = openFileDialog1.FileName;
  130. byte[] imageBytes = File.ReadAllBytes(imagePath);
  131. using (MemoryStream ms = new MemoryStream(imageBytes))
  132. {
  133. Image image = Image.FromStream(ms);
  134. pictureBox1.Image = image;
  135. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; // Настройка режима размеров изображения
  136. }
  137. }
  138. }
  139. }
  140. }