changeChild.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11. namespace Дол_Восток
  12. {
  13. public partial class changeChild : Form
  14. {
  15. SqlCommand query = null;
  16. public changeChild()
  17. {
  18. InitializeComponent();
  19. }
  20. private void changeChild_Load(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  25. SqlDataReader reader = query.ExecuteReader();
  26. while (reader.Read())
  27. {
  28. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  29. }
  30. reader.Close();
  31. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  32. reader = query.ExecuteReader();
  33. while (reader.Read())
  34. {
  35. cb_otryad.Items.Add(reader.GetInt32(0));
  36. }
  37. reader.Close();
  38. query = new SqlCommand($"select surname from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  39. tb_surname.Text = query.ExecuteScalar().ToString();
  40. query = new SqlCommand($"select [name] from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  41. tb_name.Text = query.ExecuteScalar().ToString();
  42. query = new SqlCommand($"select patronymic from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  43. tb_patronymic.Text = query.ExecuteScalar().ToString();
  44. query = new SqlCommand($"select date_birth from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  45. dtp_dateBirth.Text = query.ExecuteScalar().ToString();
  46. query = new SqlCommand($"select zakon_predstavitel.surname + ' ' + zakon_predstavitel.[name] + ' ' + zakon_predstavitel.patronymic from children join zakon_predstavitel on zakon_predstavitel.kod_zakon_predstavitel = children.kod_zakon_predstavitel where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  47. cb_zakPredstavitel.SelectedItem = query.ExecuteScalar().ToString();
  48. query = new SqlCommand($"select adress from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  49. tb_adress.Text = query.ExecuteScalar().ToString();
  50. query = new SqlCommand($"select type_document from children join document on document.kod_document = children.kod_document where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  51. cb_typeDoc.SelectedItem = query.ExecuteScalar().ToString();
  52. query = new SqlCommand($"select kem_vudan from children join document on document.kod_document = children.kod_document where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  53. tb_kemVudan.Text = query.ExecuteScalar().ToString();
  54. query = new SqlCommand($"select date_vudachi from children join document on document.kod_document = children.kod_document where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  55. dtp_dateVudach.Text = query.ExecuteScalar().ToString();
  56. query = new SqlCommand($"select seria from children join document on document.kod_document = children.kod_document where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  57. mtb_seria.Text = query.ExecuteScalar().ToString();
  58. query = new SqlCommand($"select nomer from children join document on document.kod_document = children.kod_document where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  59. mtb_nomer.Text = query.ExecuteScalar().ToString();
  60. query = new SqlCommand($"select snils from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  61. mtb_snils.Text = query.ExecuteScalar().ToString();
  62. //query = new SqlCommand($"select year_buy from children join putevka on putevka.kod_putevki = children.kod_putevki where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  63. //dtp_yearBuy.Text = query.ExecuteScalar().ToString();
  64. query = new SqlCommand($"select stoimost from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  65. nud_stoimost.Value = Convert.ToInt32(query.ExecuteScalar());
  66. query = new SqlCommand($"select lgot_stoimost from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  67. cb_lgotStoimost.Checked = Convert.ToBoolean(query.ExecuteScalar());
  68. query = new SqlCommand($"select kod_otryada from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  69. cb_otryad.SelectedItem = Convert.ToInt32(query.ExecuteScalar());
  70. }
  71. catch
  72. {
  73. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  74. }
  75. }
  76. private void bt_change_Click(object sender, EventArgs e)
  77. {
  78. try
  79. {
  80. query = new SqlCommand($"select count(*) from children where kod_otryada like '{cb_otryad.SelectedItem}'", db_helper.sqlConnection);
  81. int amount = (int)query.ExecuteScalar();
  82. query = new SqlCommand($"select kol_vo_children from otryad where kod_otryad like '{cb_otryad.SelectedItem}'", db_helper.sqlConnection);
  83. int totalAmount = (int)query.ExecuteScalar();
  84. if (amount < totalAmount)
  85. {
  86. var res = MessageBox.Show("Вы точно хотите изменить данные?", "Подтверждение", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
  87. if(res == DialogResult.Yes)
  88. {
  89. double price = (double)nud_stoimost.Value;
  90. double percent = 0;
  91. query = new SqlCommand($"select lgot_stoimost from children where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  92. if (cb_lgotStoimost.Checked == true && cb_lgotStoimost.Checked != Convert.ToBoolean(query.ExecuteScalar()))
  93. {
  94. percent = price / 100.0;
  95. price -= percent * 10;
  96. }
  97. else if (cb_lgotStoimost.Checked == false && cb_lgotStoimost.Checked != Convert.ToBoolean(query.ExecuteScalar()))
  98. {
  99. percent = price / 90.0;
  100. price += percent * 10;
  101. }
  102. DateTime date1 = DateTime.Parse(dtp_dateBirth.Text);
  103. query = new SqlCommand($"select kod_zakon_predstavitel from zakon_predstavitel where (surname + ' ' + [name] + ' ' + patronymic) like '{cb_zakPredstavitel.SelectedItem}'", db_helper.sqlConnection);
  104. string kodZP = query.ExecuteScalar().ToString();
  105. query = new SqlCommand($"update children set surname = @surname, [name] = @name, patronymic = @patronymic, date_birth = @date_birth, kod_zakon_predstavitel = @kod_zakon_predstavitel, adress = @adress, snils = @snils, kod_otryada = @kod_otryada, lgot_stoimost = @lgot_stoimost, stoimost = @stoimost where kod_children like '{GLavn.row}'", db_helper.sqlConnection);
  106. query.Parameters.AddWithValue("surname", tb_surname.Text);
  107. query.Parameters.AddWithValue("name", tb_name.Text);
  108. query.Parameters.AddWithValue("patronymic", tb_patronymic.Text);
  109. query.Parameters.AddWithValue("date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  110. query.Parameters.AddWithValue("kod_zakon_predstavitel", kodZP);
  111. query.Parameters.AddWithValue("adress", tb_adress.Text);
  112. query.Parameters.AddWithValue("snils", mtb_snils.Text);
  113. query.Parameters.AddWithValue("kod_otryada", cb_otryad.SelectedItem);
  114. query.Parameters.AddWithValue("lgot_stoimost", cb_lgotStoimost.Checked);
  115. query.Parameters.AddWithValue("stoimost", Math.Round(price));
  116. if (query.ExecuteNonQuery().ToString().Equals("1"))
  117. {
  118. MessageBox.Show("Изменение прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  119. this.Close();
  120. }
  121. }
  122. else
  123. {
  124. MessageBox.Show("Действие отменено!", "Уведмоление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  125. }
  126. }
  127. else
  128. {
  129. MessageBox.Show("Данный отряд полностью укомплектован", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  130. }
  131. }
  132. catch
  133. {
  134. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  135. }
  136. }
  137. private void bt_addZP_Click(object sender, EventArgs e)
  138. {
  139. try
  140. {
  141. addZakPredstavitel add = new addZakPredstavitel();
  142. add.Show();
  143. cb_zakPredstavitel.Items.Clear();
  144. add.FormClosing += (obj, args) =>
  145. {
  146. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  147. SqlDataReader reader = query.ExecuteReader();
  148. while (reader.Read())
  149. {
  150. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  151. }
  152. reader.Close();
  153. };
  154. }
  155. catch
  156. {
  157. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  158. }
  159. }
  160. private void bt_addOtryad_Click(object sender, EventArgs e)
  161. {
  162. try
  163. {
  164. addOtryad add = new addOtryad();
  165. add.Show();
  166. cb_otryad.Items.Clear();
  167. add.FormClosing += (obj, args) =>
  168. {
  169. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  170. SqlDataReader reader = query.ExecuteReader();
  171. while (reader.Read())
  172. {
  173. cb_otryad.Items.Add(reader.GetInt32(0));
  174. }
  175. reader.Close();
  176. };
  177. }
  178. catch
  179. {
  180. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  181. }
  182. }
  183. static public string row = null;
  184. private void bt_changeOtryad_Click(object sender, EventArgs e)
  185. {
  186. try
  187. {
  188. row = cb_otryad.SelectedItem.ToString();
  189. changeOtryad change = new changeOtryad();
  190. change.Show();
  191. cb_otryad.Items.Clear();
  192. change.FormClosing += (obj, args) =>
  193. {
  194. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  195. SqlDataReader reader = query.ExecuteReader();
  196. while (reader.Read())
  197. {
  198. cb_otryad.Items.Add(reader.GetInt32(0));
  199. }
  200. reader.Close();
  201. cb_otryad.SelectedIndex = 0;
  202. };
  203. }
  204. catch
  205. {
  206. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  207. }
  208. }
  209. private void bt_changeZP_Click(object sender, EventArgs e)
  210. {
  211. try
  212. {
  213. query = new SqlCommand($"select kod_zakon_predstavitel from zakon_predstavitel where (surname + ' ' + [name] + ' ' + patronymic) like '{cb_zakPredstavitel.SelectedItem}'", db_helper.sqlConnection);
  214. row = query.ExecuteScalar().ToString();
  215. changeZakPredstavitel change = new changeZakPredstavitel();
  216. change.Show();
  217. cb_zakPredstavitel.Items.Clear();
  218. change.FormClosing += (obj, args) =>
  219. {
  220. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  221. SqlDataReader reader = query.ExecuteReader();
  222. while (reader.Read())
  223. {
  224. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  225. }
  226. reader.Close();
  227. cb_zakPredstavitel.SelectedIndex = 0;
  228. };
  229. }
  230. catch
  231. {
  232. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  233. }
  234. }
  235. private void label17_Click(object sender, EventArgs e)
  236. {
  237. }
  238. }
  239. }