private void button5_Click(object sender, EventArgs e)

        {
            DateTime d;

            if (comboBox1.Text != "")
            {
                d = Convert.ToDateTime(comboBox1.Text).Date;
            }
            else
            {
                d = GunTarihi.Value;
            }
            DialogResult dr = MessageBox.Show("Veriyi Silmek İstediğinize Eminmisiniz", "Uyarı", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                try
                {
                    var query  = Form1.Adibahce.Shift.Where(x => x.PersonelAdSoyad == label1.Text.ToString()).Where(x => x.Yil_ID == d.Year).Where(x => x.Ay_ID == d.Month).Where(x => x.Gun_ID == d.Day).Select(x => x.Shift_ID).FirstOrDefault();
                    var query1 = Form1.Adibahce.Antre.Where(x => x.PersonelAdSoyad == label1.Text && x.Tarih == d.Date).Select(x => x.Id).FirstOrDefault();

                    Shift s = Form1.Adibahce.Shift.First(x => x.Shift_ID == query);
                    Form1.Adibahce.Shift.Remove(s);
                    try
                    {
                        Antre a = Form1.Adibahce.Antre.FirstOrDefault(x => x.Id == query1);
                        Form1.Adibahce.Antre.Remove(a);
                    }
                    catch (Exception)
                    {
                    }



                    Form1.Adibahce.SaveChanges();
                    MessageBox.Show("Veri Başarıyla Silindi", "Mesaj");
                    FormDoldur(label1, GunTarihi.Value);
                }
                catch (Exception)
                {
                    MessageBox.Show("Lütfen Belirtilen Tarih Aralığında Veri Olduğundan Emin Olunuz", "Veri Silinemedi");
                }
            }
            else
            {
                MessageBox.Show("Veri Silme İşleminden Vazgeçildi", "Mesaj");
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            DateTime d;

            if (comboBox1.Text != "")
            {
                d = Convert.ToDateTime(comboBox1.Text).Date;
            }
            else
            {
                d = GunTarihi.Value.Date;
            }

            if (Form1.Adibahce.Antre.Where(x => x.Tarih == d && x.PersonelAdSoyad == label1.Text).ToList().Count() != 0)
            {
                TimeSpan t = new TimeSpan();
                try
                {
                    if (textBox4.Text != "")
                    {
                        t = TimeSpan.Parse(textBox4.Text);
                    }
                    if (textBox5.Text != "")
                    {
                        t = TimeSpan.Parse(textBox5.Text);
                    }
                    if (textBox6.Text != "")
                    {
                        t = TimeSpan.Parse(textBox6.Text);
                    }
                    if (textBox7.Text != "")
                    {
                        t = TimeSpan.Parse(textBox7.Text);
                    }

                    var   adb = Form1.Adibahce.Antre.Where(x => x.Tarih == d && x.PersonelAdSoyad == label1.Text).Select(x => x.Id).FirstOrDefault();
                    Antre a   = Form1.Adibahce.Antre.First(x => x.Id == adb);
                    if (textBox4.Text != "")
                    {
                        a.BirinciGiris = TimeSpan.Parse(textBox4.Text);
                    }
                    if (textBox5.Text != "")
                    {
                        a.BirinciCikis = TimeSpan.Parse(textBox5.Text);
                    }
                    if (textBox6.Text != "")
                    {
                        a.İkinciGiris = TimeSpan.Parse(textBox6.Text);
                    }
                    if (textBox7.Text != "")
                    {
                        a.İkinciCikis = TimeSpan.Parse(textBox7.Text);
                    }
                    if (textBox8.Text != "")
                    {
                        a.Fark = TimeSpan.Parse(textBox8.Text);
                    }
                    if (textBox8.Text != "")
                    {
                        var   query = Form1.Adibahce.Shift.Where(x => x.PersonelAdSoyad == label1.Text.ToString()).Where(x => x.Yil_ID == d.Year).Where(x => x.Ay_ID == d.Month).Where(x => x.Gun_ID == d.Day).Select(x => x.Shift_ID).FirstOrDefault();
                        Shift s     = Form1.Adibahce.Shift.FirstOrDefault(x => x.Shift_ID == query);
                        s.Fark = a.Fark;
                    }
                    Form1.Adibahce.SaveChanges();
                    MessageBox.Show("Güncelleme İşlemi Başarıyla Tamamlandı", "Mesaj");
                    FormDoldur(label1, d);
                }
                catch (Exception)
                {
                    MessageBox.Show("Lütfen Saat Formatında veri giriniz!!", "Uyarı");
                }
            }
            else
            {
                MessageBox.Show("Veri Güncellemek İçin ,Önce Veri Eklemelisiniz ", "Uyarı");
            }
        }
        private void button8_Click(object sender, EventArgs e)
        {
            DateTime d;

            if (comboBox1.Text != "")
            {
                d = Convert.ToDateTime(comboBox1.Text);
            }

            else
            {
                d = GunTarihi.Value.Date;
            }
            try
            {
                bool     kontrol = true;
                TimeSpan t       = new TimeSpan();
                try
                {
                    if (textBox4.Text != "")
                    {
                        t = TimeSpan.Parse(textBox4.Text);
                    }
                    if (textBox5.Text != "")
                    {
                        t = TimeSpan.Parse(textBox5.Text);
                    }
                    if (textBox6.Text != "")
                    {
                        t = TimeSpan.Parse(textBox6.Text);
                    }
                    if (textBox7.Text != "")
                    {
                        t = TimeSpan.Parse(textBox7.Text);
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Lütfen Saat Formatında veri giriniz!!", "Uyarı");
                    kontrol = false;
                }

                if (kontrol)
                {
                    Antre a     = new Antre();
                    var   sorgu = Form1.Adibahce.Antre.ToList();
                    a.Id = Form1.Adibahce.Antre.Count() + 1;
                    a.PersonelAdSoyad = label1.Text;
                    a.Tarih           = GunTarihi.Value.Date;
                    if (textBox4.Text != "")
                    {
                        a.BirinciGiris = TimeSpan.Parse(textBox4.Text);
                    }
                    if (textBox5.Text != "")
                    {
                        a.BirinciCikis = TimeSpan.Parse(textBox5.Text);
                    }
                    if (textBox6.Text != "")
                    {
                        a.İkinciGiris = TimeSpan.Parse(textBox6.Text);
                    }
                    if (textBox7.Text != "")
                    {
                        a.İkinciCikis = TimeSpan.Parse(textBox7.Text);
                    }
                    if (textBox4.Text != "" && textBox5.Text != "" && textBox6.Text != "" && textBox7.Text != "")
                    {
                        a.Fark = TimeSpan.Parse(textBox8.Text);
                    }

                    Shift s = new Shift();
                    s.Shift_ID        = Form1.Adibahce.Shift.Count() + 1;
                    s.PersonelAdSoyad = label1.Text;
                    s.Tarih           = GunTarihi.Value.Date;
                    s.Yil_ID          = GunTarihi.Value.Year;
                    s.Ay_ID           = GunTarihi.Value.Month;
                    s.Gun_ID          = GunTarihi.Value.Day;
                    s.Antre           = true;
                    bool veri = false;
                    foreach (var item in  sorgu)
                    {
                        if (item.PersonelAdSoyad == label1.Text && item.Tarih == GunTarihi.Value.Date)
                        {
                            MessageBox.Show("Aynı Tarihe Aynı Kişi için veri Kaydedilemez!!", "Uyarı");
                            veri = true;
                        }
                    }
                    if (veri == false)
                    {
                        Form1.Adibahce.Shift.Add(s);

                        Form1.Adibahce.Antre.Add(a);
                        Form1.Adibahce.SaveChanges();
                        if (textBox8.Text != "")
                        {
                            var   query = Form1.Adibahce.Shift.Where(x => x.PersonelAdSoyad == label1.Text.ToString()).Where(x => x.Yil_ID == GunTarihi.Value.Year).Where(x => x.Ay_ID == GunTarihi.Value.Month).Where(x => x.Gun_ID == GunTarihi.Value.Day).Select(x => x.Shift_ID).FirstOrDefault();
                            Shift sh    = Form1.Adibahce.Shift.FirstOrDefault(x => x.Shift_ID == query);
                            sh.Fark = a.Fark;
                            Form1.Adibahce.SaveChanges();
                        }

                        MessageBox.Show("Veri Başarıyla Kaydedildi", "Mesaj");
                        FormDoldur(label1, d.Date);
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Veri Kaydedilirken Bir Hata Oluştu,Veri Kaydedilemedi", "Uyarı ");
            }
        }