Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)//поиск между датами
        {
            wrongdate = false;
            ctx       = new BuyGamesEntities();   //обновляем контекст (внутреннюю информацию)
            DateTime D1 = GetDate(textBox1.Text); //в GetDate проверяем дату на корректность
            DateTime D2 = GetDate(textBox2.Text);

            if (wrongdate)
            {
                label5.Text      = "Статус выполнения: wrong date";
                label5.ForeColor = Color.Red;
                return;
            }
            //поск цены игры между датами
            var result = (from tb in ctx.buy
                          join tg in ctx.games on tb.game_id equals tg.game_id
                          join tp in ctx.game_price on tg.game_id equals tp.game_id
                          where tb.buy_date > D1 && tb.buy_date < D2//сравнение
                          select new{
                game_name = tg.game_name,
                price = tp.price,
                date = tb.buy_date
            });

            dataGridView1.DataSource = result.ToList();//вывод результат запроса
            label5.Text      = "Статус выполнения: done";
            label5.ForeColor = Color.Blue;
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)//выводим таблицу
        {
            if (dataGridView1.Columns.Count > 0)
            {
                dataGridView1.Columns[0].ReadOnly = false; //запрещаем менять айди
            }
            ctx = new BuyGamesEntities();                  //обновляем контекст
            if (comboBox1.SelectedItem == null)
            {
                labelChange(false); return;
            }                               //если не выбрана ни одна из таблиц - ошибка
            switch (comboBox1.SelectedItem) //для получения данных и заполнения грида
            {
            case "buy":
                ctx.buy.Load();
                dataGridView1.DataSource = ctx.buy.Local.ToBindingList();
                break;

            case "clients":
                ctx.clients.Load();
                dataGridView1.DataSource = ctx.clients.Local.ToBindingList();
                break;

            case "game_price":
                ctx.game_price.Load();
                dataGridView1.DataSource = ctx.game_price.Local.ToBindingList();
                break;

            case "games":
                ctx.games.Load();
                dataGridView1.DataSource = ctx.games.Local.ToBindingList();
                break;

            case "genres":
                ctx.genres.Load();
                dataGridView1.DataSource = ctx.genres.Local.ToBindingList();
                break;
            }
            dataGridView1.Columns[0].ReadOnly = true;//запрещаем менять айди
            //скрываем лишние элементы
            for (int i = 0; i < dataGridView1.Columns.Count; i++)
            {
                if (comboBox1.Items.Contains(dataGridView1.Columns[i].HeaderText))
                {
                    dataGridView1.Columns[i].Visible = false;
                }
            }
            labelChange(true);//сообщаем об успешном выполнении
        }