Form3.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. DateTime date_1start = dateTimePicker1.Value;
  32. DateTime date_1end = date_1start.AddDays(Convert.ToInt32(textBox1.Text));
  33. Reader = command.ExecuteReader();
  34. listBox1.Items.Clear();
  35. if(comboBox1.SelectedItem.ToString() == "1-комнатный")
  36. {
  37. }
  38. while (Reader.Read()) {
  39. DateTime date_2_start = Convert.ToDateTime(Reader["date_zaezda"]);
  40. DateTime date_2_end = date_2_start.AddDays(Convert.ToInt16(Reader["kol_days"]));
  41. // bool intersect = !(date_2_end < date_1start || date_2_start > date_1end);
  42. bool intersect = date_2_end >= date_1start && date_2_start <= date_1end;
  43. if (!intersect) {
  44. }
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  50. }
  51. }
  52. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  53. {
  54. }
  55. }
  56. }