Form3.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 testkonkurs1
  12. {
  13. public partial class Form3 : Form
  14. {
  15. public Form3()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Form3_FormClosing(object sender, FormClosingEventArgs e)
  20. {
  21. Application.Exit();
  22. }
  23. private void button1_Click(object sender, EventArgs e)
  24. {
  25. string connString = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=Testkonkurs;Integrated Security=True";
  26. SqlConnection conn = new SqlConnection(connString);
  27. SqlCommand command = new SqlCommand("SELECT * FROM bronirovanie", conn);
  28. conn.Open();
  29. SqlDataReader Reader = null;
  30. try
  31. {
  32. dataGridView1.Rows.Clear();
  33. dataGridView1.Columns.Clear();
  34. DateTime date_1start = dateTimePicker1.Value;
  35. DateTime date_1end = date_1start.AddDays(Convert.ToInt32(textBox1.Text));
  36. Reader = command.ExecuteReader();
  37. if (comboBox1.SelectedItem.ToString() == "1-комнатный")
  38. {
  39. }
  40. int[] cod_mesta = new int[20];
  41. int[] nomer_comnat = new int[20];
  42. String[] lvl_comfort = new String[20];
  43. String[] price = new String[20];
  44. int i = 0;
  45. while (Reader.Read())
  46. {
  47. DateTime date_2_start = Convert.ToDateTime(Reader["date_zaezda"]);
  48. DateTime date_2_end = date_2_start.AddDays(Convert.ToInt16(Reader["kol_days"]));
  49. // bool intersect = !(date_2_end < date_1start || date_2_start > date_1end);
  50. bool intersect = date_2_end >= date_1start && date_2_start <= date_1end;
  51. if (!intersect)
  52. {
  53. cod_mesta[i] = Convert.ToInt32(Reader["nomer_mesta"]);
  54. i += 1;
  55. }
  56. }
  57. Reader.Close();
  58. DataGridViewTextBoxColumn nomer_comnatColum = new DataGridViewTextBoxColumn();
  59. nomer_comnatColum.HeaderText = "номер комнаты";
  60. nomer_comnatColum.Name = "text";
  61. dataGridView1.Columns.AddRange(nomer_comnatColum);
  62. DataGridViewTextBoxColumn lvlcomfortColum = new DataGridViewTextBoxColumn();
  63. lvlcomfortColum.HeaderText = "Уровень комфорта";
  64. lvlcomfortColum.Name = "text";
  65. dataGridView1.Columns.AddRange(lvlcomfortColum);
  66. DataGridViewTextBoxColumn pricecolum = new DataGridViewTextBoxColumn();
  67. pricecolum.HeaderText = "цена проживания";
  68. pricecolum.Name = "text";
  69. dataGridView1.Columns.AddRange(pricecolum);
  70. for (int j = 0; j < 20; j++)
  71. {
  72. if (cod_mesta[j] != 0)
  73. {
  74. SqlCommand takeMesta = new SqlCommand("SELECT * FROM mesto where cod_mesta = @nomer_mesta", conn);
  75. takeMesta.Parameters.AddWithValue("@nomer_mesta", cod_mesta[j]);
  76. SqlDataReader Mesta = takeMesta.ExecuteReader();
  77. Mesta.Read();
  78. nomer_comnat[j] = Convert.ToInt32(Mesta["nomer_comnat"]);
  79. Mesta.Close();
  80. }
  81. }
  82. for (int j = 0; j < 20; j++)
  83. {
  84. if (nomer_comnat[j] != 0)
  85. {
  86. SqlCommand takeMesta = new SqlCommand("SELECT * FROM nomera where nomer_comnat = @nomer_mesta", conn);
  87. takeMesta.Parameters.AddWithValue("@nomer_mesta", nomer_comnat[j]);
  88. SqlDataReader Mesta = takeMesta.ExecuteReader();
  89. Mesta.Read();
  90. lvl_comfort[j] = Mesta["lvl_comfort"].ToString();
  91. Mesta.Close();
  92. }
  93. }
  94. for (int j = 0; j < 20; j++)
  95. {
  96. if (lvl_comfort[j] != null)
  97. {
  98. SqlCommand takeMesta = new SqlCommand("SELECT * FROM comfort where [lvl-comfort] = @nomer_mesta", conn);
  99. takeMesta.Parameters.AddWithValue("@nomer_mesta", lvl_comfort[j]);
  100. SqlDataReader Mesta = takeMesta.ExecuteReader();
  101. Mesta.Read();
  102. price[j] = (Mesta["price_life"].ToString());
  103. Mesta.Close();
  104. }
  105. }
  106. int count = 0;
  107. for (int j = 0; j < 20; j++)
  108. {
  109. if (comboBox1.SelectedIndex == 2)
  110. {
  111. if (nomer_comnat[j] != 0)
  112. {
  113. dataGridView1.Rows.Add();
  114. dataGridView1.Rows[j].Cells[0].Value = nomer_comnat[j];
  115. dataGridView1.Rows[j].Cells[1].Value = lvl_comfort[j];
  116. dataGridView1.Rows[j].Cells[2].Value = price[j];
  117. }
  118. }
  119. if (comboBox1.SelectedIndex == 1)
  120. {
  121. if (nomer_comnat[j] != 0)
  122. {
  123. if(lvl_comfort[j] == "2-местный ")
  124. {
  125. dataGridView1.Rows.Add();
  126. dataGridView1.Rows[count].Cells[0].Value = nomer_comnat[j];
  127. dataGridView1.Rows[count].Cells[1].Value = lvl_comfort[j];
  128. dataGridView1.Rows[count].Cells[2].Value = price[j];
  129. count++;
  130. }
  131. }
  132. }
  133. if (comboBox1.SelectedIndex == 0)
  134. {
  135. if (nomer_comnat[j] != 0)
  136. {
  137. if (lvl_comfort[j] == "1-местный ")
  138. {
  139. dataGridView1.Rows.Add();
  140. dataGridView1.Rows[count].Cells[0].Value = nomer_comnat[j];
  141. dataGridView1.Rows[count].Cells[1].Value = lvl_comfort[j];
  142. dataGridView1.Rows[count].Cells[2].Value = price[j];
  143. count++;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. catch (Exception ex)
  150. {
  151. MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  152. }
  153. }
  154. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  155. {
  156. }
  157. private void Form3_Load(object sender, EventArgs e)
  158. {
  159. // TODO: данная строка кода позволяет загрузить данные в таблицу "konkursDataSet.comfort". При необходимости она может быть перемещена или удалена.
  160. this.comfortTableAdapter.Fill(this.konkursDataSet.comfort);
  161. }
  162. private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  163. {
  164. }
  165. private void textBox1_TextChanged(object sender, EventArgs e)
  166. {
  167. }
  168. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  169. {
  170. }
  171. private void button2_Click(object sender, EventArgs e)
  172. {
  173. Form4 fr4 = new Form4();
  174. fr4.Show();
  175. this.Hide();
  176. }
  177. }
  178. }