123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.SqlClient;
- namespace testkonkurs1
- {
- public partial class Form3 : Form
- {
- public Form3()
- {
- InitializeComponent();
- }
- private void Form3_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string connString = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=Testkonkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connString);
- SqlCommand command = new SqlCommand("SELECT * FROM bronirovanie", conn);
- conn.Open();
- SqlDataReader Reader = null;
- try
- {
- dataGridView1.Rows.Clear();
- dataGridView1.Columns.Clear();
- DateTime date_1start = dateTimePicker1.Value;
- DateTime date_1end = date_1start.AddDays(Convert.ToInt32(textBox1.Text));
- Reader = command.ExecuteReader();
- if (comboBox1.SelectedItem.ToString() == "1-комнатный")
- {
- }
- int[] cod_mesta = new int[20];
- int[] nomer_comnat = new int[20];
- String[] lvl_comfort = new String[20];
- String[] price = new String[20];
- int i = 0;
- while (Reader.Read())
- {
- DateTime date_2_start = Convert.ToDateTime(Reader["date_zaezda"]);
- DateTime date_2_end = date_2_start.AddDays(Convert.ToInt16(Reader["kol_days"]));
- // bool intersect = !(date_2_end < date_1start || date_2_start > date_1end);
- bool intersect = date_2_end >= date_1start && date_2_start <= date_1end;
- if (!intersect)
- {
- cod_mesta[i] = Convert.ToInt32(Reader["nomer_mesta"]);
- i += 1;
- }
- }
- Reader.Close();
- DataGridViewTextBoxColumn nomer_comnatColum = new DataGridViewTextBoxColumn();
- nomer_comnatColum.HeaderText = "номер комнаты";
- nomer_comnatColum.Name = "text";
- dataGridView1.Columns.AddRange(nomer_comnatColum);
- DataGridViewTextBoxColumn lvlcomfortColum = new DataGridViewTextBoxColumn();
- lvlcomfortColum.HeaderText = "Уровень комфорта";
- lvlcomfortColum.Name = "text";
- dataGridView1.Columns.AddRange(lvlcomfortColum);
- DataGridViewTextBoxColumn pricecolum = new DataGridViewTextBoxColumn();
- pricecolum.HeaderText = "цена проживания";
- pricecolum.Name = "text";
- dataGridView1.Columns.AddRange(pricecolum);
- for (int j = 0; j < 20; j++)
- {
- if (cod_mesta[j] != 0)
- {
- SqlCommand takeMesta = new SqlCommand("SELECT * FROM mesto where cod_mesta = @nomer_mesta", conn);
- takeMesta.Parameters.AddWithValue("@nomer_mesta", cod_mesta[j]);
- SqlDataReader Mesta = takeMesta.ExecuteReader();
- Mesta.Read();
- nomer_comnat[j] = Convert.ToInt32(Mesta["nomer_comnat"]);
- Mesta.Close();
- }
- }
- for (int j = 0; j < 20; j++)
- {
- if (nomer_comnat[j] != 0)
- {
- SqlCommand takeMesta = new SqlCommand("SELECT * FROM nomera where nomer_comnat = @nomer_mesta", conn);
- takeMesta.Parameters.AddWithValue("@nomer_mesta", nomer_comnat[j]);
- SqlDataReader Mesta = takeMesta.ExecuteReader();
- Mesta.Read();
- lvl_comfort[j] = Mesta["lvl_comfort"].ToString();
- Mesta.Close();
- }
- }
- for (int j = 0; j < 20; j++)
- {
- if (lvl_comfort[j] != null)
- {
- SqlCommand takeMesta = new SqlCommand("SELECT * FROM comfort where [lvl-comfort] = @nomer_mesta", conn);
- takeMesta.Parameters.AddWithValue("@nomer_mesta", lvl_comfort[j]);
- SqlDataReader Mesta = takeMesta.ExecuteReader();
- Mesta.Read();
- price[j] = (Mesta["price_life"].ToString());
- Mesta.Close();
- }
- }
- int count = 0;
- for (int j = 0; j < 20; j++)
- {
- if (comboBox1.SelectedIndex == 2)
- {
- if (nomer_comnat[j] != 0)
- {
- dataGridView1.Rows.Add();
- dataGridView1.Rows[j].Cells[0].Value = nomer_comnat[j];
- dataGridView1.Rows[j].Cells[1].Value = lvl_comfort[j];
- dataGridView1.Rows[j].Cells[2].Value = price[j];
- }
- }
- if (comboBox1.SelectedIndex == 1)
- {
- if (nomer_comnat[j] != 0)
- {
- if(lvl_comfort[j] == "2-местный ")
- {
-
- dataGridView1.Rows.Add();
- dataGridView1.Rows[count].Cells[0].Value = nomer_comnat[j];
- dataGridView1.Rows[count].Cells[1].Value = lvl_comfort[j];
- dataGridView1.Rows[count].Cells[2].Value = price[j];
- count++;
- }
- }
- }
- if (comboBox1.SelectedIndex == 0)
- {
- if (nomer_comnat[j] != 0)
- {
- if (lvl_comfort[j] == "1-местный ")
- {
- dataGridView1.Rows.Add();
- dataGridView1.Rows[count].Cells[0].Value = nomer_comnat[j];
- dataGridView1.Rows[count].Cells[1].Value = lvl_comfort[j];
- dataGridView1.Rows[count].Cells[2].Value = price[j];
- count++;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
-
- }
- private void Form3_Load(object sender, EventArgs e)
- {
- // TODO: данная строка кода позволяет загрузить данные в таблицу "konkursDataSet.comfort". При необходимости она может быть перемещена или удалена.
- this.comfortTableAdapter.Fill(this.konkursDataSet.comfort);
- }
- private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- Form4 fr4 = new Form4();
- fr4.Show();
- this.Hide();
- }
- }
- }
|