Esempio n. 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cboCodigo.Text))
            {
                MessageBox.Show("Código não informado");
                return;
            }
            homeEntities h    = new homeEntities();
            var          data = h.Family.First(m => m.Id.ToString() == cboCodigo.Text);

            if (data == null)
            {
                MessageBox.Show("Código não encontrado");
                return;
            }
            else
            {
                h.Family.Remove(data);

                /*
                 * h.Family.Remove(new Family()
                 * {
                 *  Id = Convert.ToInt32(cboCodigo.Text)
                 * });*/
            }
            h.SaveChanges();
            MessageBox.Show("Dados excluidos");
        }
Esempio n. 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cboCodigo.Text))
            {
                MessageBox.Show("Código não informado");
                return;
            }
            homeEntities h    = new homeEntities();
            var          data = h.Family.First(m => m.Id.ToString() == cboCodigo.Text);

            if (data == null)
            {
                MessageBox.Show("Código não encontrado");
                return;
            }
            else
            {
                h.Family.AddOrUpdate(new Family()
                {
                    Id          = Convert.ToInt32(cboCodigo.Text),
                    name        = txtNome.Text,
                    Gender      = cboSexo.Text.Substring(0, 1),
                    DateOfBirth = dateTimePicker1.Value
                });
            }
            h.SaveChanges();
            MessageBox.Show("Dados atualizados");
        }
Esempio n. 3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtNome.Text))
            {
                MessageBox.Show("Nome não informado");
                return;
            }

            if (string.IsNullOrEmpty(cboSexo.Text))
            {
                MessageBox.Show("Sexo não informado");
                return;
            }
            homeEntities h = new homeEntities();

            Home.Family family = new Home.Family();
            var         qtd    = h.Family.Count();
            int         maxId  = 0;

            if (qtd != 0)
            {
                maxId = h.Family.Max(i => i.Id);
            }

            try
            {
                family = h.Family.First(n => n.name == txtNome.Text);
            }
            catch (Exception)
            {
            }

            if (family.Id != 0)
            {
                MessageBox.Show("Nome já incluído");
                return;
            }

            family.Id          = ++maxId;
            family.name        = txtNome.Text;
            family.Gender      = cboSexo.Text.Substring(0, 1);
            family.DateOfBirth = dateTimePicker1.Value;

            h.Family.Add(family);

            h.SaveChanges();



            MessageBox.Show("Dados incluidos com sucesso");
        }