Form1.cs 6.0 KB

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