addChild.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 addChild : Form
  14. {
  15. SqlCommand query = null;
  16. public addChild()
  17. {
  18. InitializeComponent();
  19. }
  20. private void bt_add_Click(object sender, EventArgs e)
  21. {
  22. try
  23. {
  24. query = new SqlCommand($"select count(*) from children where kod_otryada like '{cb_otryad.SelectedItem}'", db_helper.sqlConnection);
  25. int amount = (int)query.ExecuteScalar();
  26. query = new SqlCommand($"select kol_vo_children from otryad where kod_otryad like '{cb_otryad.SelectedItem}'", db_helper.sqlConnection);
  27. int totalAmount = (int)query.ExecuteScalar();
  28. if (amount < totalAmount)
  29. {
  30. int price = (int)nud_stoimost.Value;
  31. double percent = price / 100.0;
  32. if (cb_lgotStoimost.Checked)
  33. {
  34. price -= (int)percent * 10;
  35. }
  36. query = new SqlCommand($"select kod_zakon_predstavitel from zakon_predstavitel where (surname + ' ' + [name] + ' ' + patronymic) like '{cb_zakPredstavitel.SelectedItem}'", db_helper.sqlConnection);
  37. string kodZP = query.ExecuteScalar().ToString();
  38. DateTime date1 = DateTime.Parse(dtp_dateVudach.Text);
  39. query = new SqlCommand($"insert into document (type_document, kem_vudan, date_vudachi, seria, nomer) values (@type_document, @kem_vudan, @date_vudachi, @seria, @nomer)", db_helper.sqlConnection);
  40. query.Parameters.AddWithValue("type_document", cb_typeDoc.SelectedItem);
  41. query.Parameters.AddWithValue("kem_vudan", tb_kemVudan.Text);
  42. query.Parameters.AddWithValue("date_vudachi", $"{date1.Day}.{date1.Month}.{date1.Year}");
  43. query.Parameters.AddWithValue("seria", mtb_seria.Text);
  44. query.Parameters.AddWithValue("nomer", mtb_nomer.Text);
  45. query.ExecuteNonQuery();
  46. query = new SqlCommand($"select kod_document from document where type_document like '{cb_typeDoc.SelectedItem}' and kem_vudan like '{tb_kemVudan.Text}' and date_vudachi = '{date1.Day}.{date1.Month}.{date1.Year}' and seria like '{mtb_seria.Text}' and nomer like '{mtb_nomer.Text}'", db_helper.sqlConnection);
  47. string kodDocument = query.ExecuteScalar().ToString();
  48. date1 = DateTime.Parse(dtp_yearBuy.Text);
  49. query = new SqlCommand($"insert into putevka (year_buy, stoimost) values (@year_buy, @stoimost)", db_helper.sqlConnection);
  50. query.Parameters.AddWithValue("year_buy", $"01.01.{date1.Year}");
  51. query.Parameters.AddWithValue("stoimost", nud_stoimost.Value);
  52. query.ExecuteNonQuery();
  53. query = new SqlCommand($"select kod_putevki from putevka where year(year_buy) = '{date1.Year}' and stoimost = {nud_stoimost.Value}", db_helper.sqlConnection);
  54. string kodPutevki = query.ExecuteScalar().ToString();
  55. date1 = DateTime.Parse(dtp_dateBirth.Text);
  56. query = new SqlCommand($"insert into children (surname, [name], patronymic, date_birth, kod_zakon_predstavitel, adress, kod_document, snils, kod_otryada, lgot_stoimost, stoimost) values (@surname, @name, @patronymic, @date_birth, @kod_zakon_predstavitel, @adress, @kod_document, @snils, @kod_otryada, @lgot_stoimost, @stoimost)", db_helper.sqlConnection);
  57. query.Parameters.AddWithValue("surname", tb_surname.Text);
  58. query.Parameters.AddWithValue("name", tb_name.Text);
  59. query.Parameters.AddWithValue("patronymic", tb_patronymic.Text);
  60. query.Parameters.AddWithValue("date_birth", $"{date1.Day}.{date1.Month}.{date1.Year}");
  61. query.Parameters.AddWithValue("kod_zakon_predstavitel", kodZP);
  62. query.Parameters.AddWithValue("adress", tb_adress.Text);
  63. query.Parameters.AddWithValue("kod_document", kodDocument);
  64. query.Parameters.AddWithValue("snils", mtb_snils.Text);
  65. query.Parameters.AddWithValue("kod_otryada", cb_otryad.SelectedItem);
  66. query.Parameters.AddWithValue("lgot_stoimost", cb_lgotStoimost.CheckState);
  67. query.Parameters.AddWithValue("stoimost", price);
  68. if (query.ExecuteNonQuery().ToString().Equals("1"))
  69. {
  70. MessageBox.Show("Добавление прошло успешно!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Information);
  71. this.Close();
  72. }
  73. }
  74. else
  75. {
  76. MessageBox.Show("Данный отряд полностью укомплектован", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  77. }
  78. }
  79. catch
  80. {
  81. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  82. }
  83. }
  84. private void addChild_Load(object sender, EventArgs e)
  85. {
  86. try
  87. {
  88. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  89. SqlDataReader reader = query.ExecuteReader();
  90. while (reader.Read())
  91. {
  92. cb_otryad.Items.Add(reader.GetInt32(0));
  93. }
  94. reader.Close();
  95. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  96. reader = query.ExecuteReader();
  97. while (reader.Read())
  98. {
  99. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  100. }
  101. reader.Close();
  102. cb_otryad.SelectedIndex = 0;
  103. cb_zakPredstavitel.SelectedIndex = 0;
  104. }
  105. catch
  106. {
  107. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  108. }
  109. }
  110. private void bt_addZP_Click(object sender, EventArgs e)
  111. {
  112. try
  113. {
  114. addZakPredstavitel add = new addZakPredstavitel();
  115. add.Show();
  116. cb_zakPredstavitel.Items.Clear();
  117. add.FormClosing += (obj, args) =>
  118. {
  119. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  120. SqlDataReader reader = query.ExecuteReader();
  121. while (reader.Read())
  122. {
  123. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  124. }
  125. reader.Close();
  126. };
  127. }
  128. catch
  129. {
  130. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  131. }
  132. }
  133. private void bt_addOtryad_Click(object sender, EventArgs e)
  134. {
  135. try
  136. {
  137. addOtryad add = new addOtryad();
  138. add.Show();
  139. cb_otryad.Items.Clear();
  140. add.FormClosing += (obj, args) =>
  141. {
  142. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  143. SqlDataReader reader = query.ExecuteReader();
  144. while (reader.Read())
  145. {
  146. cb_otryad.Items.Add(reader.GetInt32(0));
  147. }
  148. reader.Close();
  149. };
  150. }
  151. catch
  152. {
  153. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  154. }
  155. }
  156. private void bt_changeOtryad_Click(object sender, EventArgs e)
  157. {
  158. try
  159. {
  160. changeChild.row = cb_otryad.SelectedItem.ToString();
  161. changeOtryad change = new changeOtryad();
  162. change.Show();
  163. cb_otryad.Items.Clear();
  164. change.FormClosing += (obj, args) =>
  165. {
  166. query = new SqlCommand($"select kod_otryad from otryad", db_helper.sqlConnection);
  167. SqlDataReader reader = query.ExecuteReader();
  168. while (reader.Read())
  169. {
  170. cb_otryad.Items.Add(reader.GetInt32(0));
  171. }
  172. reader.Close();
  173. cb_otryad.SelectedIndex = 0;
  174. };
  175. }
  176. catch
  177. {
  178. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  179. }
  180. }
  181. private void bt_changeZP_Click(object sender, EventArgs e)
  182. {
  183. try
  184. {
  185. query = new SqlCommand($"select kod_zakon_predstavitel from zakon_predstavitel where (surname + ' ' + [name] + ' ' + patronymic) like '{cb_zakPredstavitel.SelectedItem}'", db_helper.sqlConnection);
  186. changeChild.row = query.ExecuteScalar().ToString();
  187. changeZakPredstavitel change = new changeZakPredstavitel();
  188. change.Show();
  189. cb_zakPredstavitel.Items.Clear();
  190. change.FormClosing += (obj, args) =>
  191. {
  192. query = new SqlCommand($"select surname + ' ' + [name] + ' ' + patronymic from zakon_predstavitel", db_helper.sqlConnection);
  193. SqlDataReader reader = query.ExecuteReader();
  194. while (reader.Read())
  195. {
  196. cb_zakPredstavitel.Items.Add(reader.GetString(0));
  197. }
  198. reader.Close();
  199. cb_zakPredstavitel.SelectedIndex = 0;
  200. };
  201. }
  202. catch
  203. {
  204. MessageBox.Show("Произошла непредвиденная ошибка!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
  205. }
  206. }
  207. }
  208. }