using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlConnection baglanti = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Sinema_Bileti;Integrated Security=True");
int sayac = 0;
private void FilmveSalonGetir(ComboBox combo, string sql1, string sql2)
{
baglanti.Open();
SqlCommand komut = new SqlCommand(sql1, baglanti);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
combo.Items.Add(read[sql2].ToString());
}
baglanti.Close();
}
private void Combo_Dolu_Koltuklar()
{
//comboKoltukiptal.Items.Clear();
//comboKoltukiptal.Text = "";
//foreach (Control item in groupBox1.Controls)
//{
// if (item is Button)
// {
// if (item.BackColor == Color.Red)
// {
// comboKoltukiptal.Items.Add(item.Text);
// }
// }
//}
}
private void YenidenidenRenklendirme()
{
//foreach (Control item in groupBox1.Controls)
//{
// if (item is Button)
// {
// item.BackColor = Color.White;
// }
//}
}
private void Veritabani_Dolu_Koltuklar()
{
//baglanti.Open();
//SqlCommand komut = new SqlCommand("select*from satis_bilgileri where filmadi='" + comboFilmAdi.SelectedItem + "'and salonadi='" + comboSalonAdi.Text + "'and tarih='" + comboFilmTarihi.SelectedItem + "'and seans='"+comboFilmSeansi.SelectedItem+ "'and koltukno='"+txtKoltukNo.Text+"'", baglanti);
//SqlDataReader read = komut.ExecuteReader();
//while (read.Read())
//{
// foreach (Control item in groupBox1.Controls)
// {
// if (item is Button)
// {
// if (read["koltukno"].ToString() != item.Text)
// {
// item.BackColor = Color.Red;
// continue;
// }
// else if(read["koltukno"].ToString()==item.Text)
// {
// item.BackColor = Color.White;
// continue;
// }
// }
// }
//}
//baglanti.Close();
}
private void FilmAfisiGoster()
{
baglanti.Open();
SqlCommand komut = new SqlCommand("select*from film_bilgileri where filmadi='" + comboFilmAdi.SelectedItem + "'", baglanti);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
pictureBox1.ImageLocation = read["resim"].ToString();
}
baglanti.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
Bos_Koltuklar();
FilmveSalonGetir(comboFilmAdi, "select*from film_bilgileri", "filmadi");
FilmveSalonGetir(comboSalonAdi, "select*from salon_bilgileri", "salonadi");
}
private void Bos_Koltuklar()
{
sayac = 1;
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 9; j++)
{
Button btn = new Button();
btn.Size = new Size(30, 30);
btn.BackColor = Color.White;
btn.ForeColor = Color.Black;
btn.Location = new Point(j * 30 + 20, i * 30 + 20);
btn.Name = sayac.ToString();
btn.Text = sayac.ToString();
if (j == 4)
{
continue;
}
sayac++;
this.groupBox1.Controls.Add(btn);
btn.Click += Btn_Click;
}
}
}
private void Btn_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
if (b.BackColor == Color.White)
{
txtKoltukNo.Text = b.Text;
}
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
groupBox1.BackColor = Color.Transparent;
}
private void label6_Click(object sender, EventArgs e)
{
}
private void panel4_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form1 dd = new Form1();
dd.Show();
}
private void button2_Click(object sender, EventArgs e)
{
frmFilmEkle anasayfa = new frmFilmEkle();
anasayfa.ShowDialog();
}
private void button5_Click(object sender, EventArgs e)
{
Environment.Exit(0);
}
private void button3_Click(object sender, EventArgs e)
{
frmSeansEkle ss = new frmSeansEkle();
ss.ShowDialog();
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
frmSeansListele kk = new frmSeansListele();
kk.ShowDialog();
}
private void button10_Click(object sender, EventArgs e)
{
frmSatisListeleme tt = new frmSatisListeleme();
tt.ShowDialog();
}
private void comboFilmAdi_SelectedIndexChanged(object sender, EventArgs e)
{
comboFilmSeansi.Items.Clear();
comboFilmTarihi.Items.Clear();
comboSalonAdi.Text = "";
comboFilmSeansi.Text = "";
comboSalonAdi.Text = "";
foreach (Control item in groupBox1.Controls) if (item is TextBox) item.Text = "";
FilmAfisiGoster();
// YenidenidenRenklendirme();
// Combo_Dolu_Koltuklar();
Film_Tarihi_Getir();
}
sinemaTableAdapters.Satis_BilgileriTableAdapter satis = new sinemaTableAdapters.Satis_BilgileriTableAdapter();
private void button6_Click(object sender, EventArgs e)
{
comboFilmSeansi.Text = "";
comboFilmTarihi.Text = "";
comboSalonAdi.Text = "";
comboUcret.Text = "";
comboFilmAdi.Text = "";
txtKoltukNo.Text = "";
txtAd.Text = "";
txtSoyad.Text = "";
foreach (Control item in groupBox1.Controls) if (item is TextBox) item.Text = "";
if (txtKoltukNo.Text != "")
{
try
{
satis.Satıs_Yap(txtKoltukNo.Text, comboSalonAdi.Text, comboFilmAdi.Text, comboFilmTarihi.Text, comboFilmSeansi.Text, txtAd.Text, txtSoyad.Text, comboUcret.Text, DateTime.Now.ToString());
foreach (Control item in groupBox1.Controls) if (item is TextBox) item.Text = "";
YenidenidenRenklendirme();
Veritabani_Dolu_Koltuklar();
Combo_Dolu_Koltuklar();
}
catch (Exception hata)
{
MessageBox.Show("Hata oluştu!!!" + hata.Message, "Uyarı");
}
}
else
{
MessageBox.Show("Koltuk seçimi yapmadınız!!", "Uyarı");
}
}
private void Film_Seansi_Getir()
{
baglanti.Open();
SqlCommand komut = new SqlCommand("select*from seans_bilgileri where filmadi='" + comboFilmAdi.SelectedItem + "'and salonadi='" + comboSalonAdi.SelectedItem + "'and tarih='" + comboFilmTarihi.SelectedItem + "'", baglanti);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
if (DateTime.Parse(read["tarih"].ToString()) == DateTime.Parse(DateTime.Now.ToShortDateString()))
{
if (DateTime.Parse(read["seans"].ToString()) > DateTime.Parse(DateTime.Now.ToShortTimeString()))
{
comboFilmSeansi.Items.Add(read["seans"].ToString());
}
}
else if (DateTime.Parse(read["tarih"].ToString()) > DateTime.Parse(DateTime.Now.ToShortDateString()))
comboFilmSeansi.Items.Add(read["seans"].ToString());
}
baglanti.Close();
}
private void Film_Tarihi_Getir()
{
comboFilmTarihi.Text = "";
comboFilmSeansi.Text = "";
comboFilmTarihi.Items.Clear();
comboFilmSeansi.Items.Clear();
baglanti.Open();
SqlCommand komut = new SqlCommand("select*from seans_bilgileri where filmadi='" + comboFilmAdi.SelectedItem + "'and salonadi='" + comboSalonAdi.SelectedItem + "'", baglanti);
SqlDataReader read = komut.ExecuteReader();
while (read.Read())
{
if (DateTime.Parse(read["tarih"].ToString()) >= DateTime.Parse(DateTime.Now.ToShortDateString()))
{
if (!comboFilmTarihi.Items.Contains(read["tarih"].ToString()))
{
comboFilmTarihi.Items.Add(read["tarih"].ToString());
comboFilmSeansi.Items.Add(read["seans"].ToString());
}
}
}
baglanti.Close();
}
private void comboSalonAdi_SelectedIndexChanged(object sender, EventArgs e)
{
Film_Tarihi_Getir();
}
private void comboFilmTarihi_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void comboFilmSeansi_SelectedIndexChanged(object sender, EventArgs e)
{
// YenidenidenRenklendirme();
// Veritabani_Dolu_Koltuklar();
// Combo_Dolu_Koltuklar();
}
}
}
Hiç yorum yok:
Yorum Gönder