private void frmconferenace_Load(object sender, EventArgs e)
        {
            VibesDataSourceEntities entities = new VibesDataSourceEntities();

            comboBox1.DataSource    = entities.Tb_Customers.ToList();
            comboBox1.ValueMember   = "ID";
            comboBox1.DisplayMember = "CustomerName";

            comboBox2.DataSource    = entities.Tb_Hotels.ToList();
            comboBox2.ValueMember   = "ID";
            comboBox2.DisplayMember = "Name";

            SelectData(entities);
        }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(labid.Text))
     {
         MessageBox.Show("Please Select Confereance", "Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         int ID = int.Parse(labid.Text);
         VibesDataSourceEntities entities    = new VibesDataSourceEntities();
         Tb_Conferences          conferences = entities.Tb_Conferences.SingleOrDefault(a => a.ID == ID);
         entities.Tb_Conferences.Remove(conferences);
         if (entities.SaveChanges() > 0)
         {
             MessageBox.Show("The conferance has been deleted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             SelectData(entities);
         }
     }
 }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            MyHelper helper = new MyHelper();

            if (helper.EnableandUnEnableControls(this.groupBox1))
            {
            }
            else
            {
                Tb_Conferences conferences = new Tb_Conferences();
                conferences.ID   = int.Parse(labid.Text);
                conferences.Name = txtname.Text;
                conferences.Persident_of_Conferences = txtpersident.Text;
                conferences.from         = datefrom.Value;
                conferences.to           = dateto.Value;
                conferences.introdaction = txtinroduced.Text;
                conferences.Note         = txtNote.Text;
                conferences.customerid   = Convert.ToInt32(comboBox1.SelectedValue);
                conferences.hotelid      = Convert.ToInt32(comboBox2.SelectedValue);

                ValidationContext       context = new ValidationContext(conferences);
                List <ValidationResult> list    = new List <ValidationResult>();

                if (Validator.TryValidateObject(conferences, context, list, true))
                {
                    VibesDataSourceEntities entities = new VibesDataSourceEntities();
                    entities.Entry <Tb_Conferences>(conferences).State = System.Data.Entity.EntityState.Modified;
                    if (entities.SaveChanges() > 0)
                    {
                        MessageBox.Show("The conferance has been edited", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        SelectData(entities);
                    }
                }
                else
                {
                    foreach (var item in list)
                    {
                        MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
        private void SelectData(VibesDataSourceEntities entities)
        {
            var select = from i in entities.Tb_Conferences.ToList()
                         select new
            {
                i.ID,
                i.Name
                ,
                i.Persident_of_Conferences
                ,
                i.@from,
                i.to
                ,
                i.introdaction
                ,
                i.Note
            };

            dataGridView1.DataSource         = select.ToList();
            dataGridView1.Columns[0].Visible = false;
        }
        private void Add()
        {
            VibesDataSourceEntities entities = new VibesDataSourceEntities();

            Tb_Conferences tb_Conferences = new Tb_Conferences()
            {
                Name = txtname.Text,
                Persident_of_Conferences = txtpersident.Text,
                from         = datefrom.Value,
                to           = dateto.Value,
                introdaction = txtinroduced.Text,
                customerid   = Convert.ToInt32(comboBox1.SelectedValue),
                hotelid      = Convert.ToInt32(comboBox2.SelectedValue),
                Note         = txtNote.Text
            };
            ValidationContext       context = new ValidationContext(tb_Conferences);
            List <ValidationResult> list    = new List <ValidationResult>();

            if (Validator.TryValidateObject(tb_Conferences, context, list, true))
            {
                entities.Tb_Conferences.Add(tb_Conferences);
            }
            else
            {
                foreach (var item in list)
                {
                    MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


            if (entities.SaveChanges() > 0)
            {
                MessageBox.Show("the Conferance has been added ", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                SelectData(entities);
            }
        }