Пример #1
0
 private void btnRemover_Click(object sender, EventArgs e)
 {
     try
     {
         using (var labContext = new LaboratorioContext(_DB))
         {
             var id  = labContext.Laboratorios.Where(s => s.Nome == comboBoxLabs.SelectedItem.ToString()).FirstOrDefault().Id;
             var lab = labContext.Laboratorios.Where(s => s.Id == id).FirstOrDefault();
             labContext.Laboratorios.Remove(lab);
             labContext.SaveChanges();
             MessageBox.Show("Realizado com sucesso!");
             comboBoxLabs.Items.RemoveAt(comboBoxLabs.SelectedIndex);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         MessageBox.Show(ex.StackTrace);
     }
 }
Пример #2
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            string nome = textBoxNome.Text.ToString();
            int    qtd  = Convert.ToInt32(textBoxQtd.Text.ToString());
            int    id   = Convert.ToInt32(textBoxGrupo.Text.ToString());

            try
            {
                using (var labContext = new LaboratorioContext(_DB))
                {
                    labContext.Laboratorios.Add(new Laboratorio(nome, qtd, id));
                    labContext.SaveChanges();
                    MessageBox.Show("Realizado com Sucesso!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Пример #3
0
 private void btnAtualizar_Click(object sender, EventArgs e)
 {
     if (checkBoxNome.Checked)
     {
         try
         {
             using (var laboratorioContext = new LaboratorioContext(_DB))
             {
                 var id   = lab.Where(c => c.Nome == comboBoxLabs.SelectedItem.ToString()).First().Id;
                 var item = lab.FirstOrDefault(c => c.Id == id);
                 if (item != null)
                 {
                     item.MudarNome(textBoxNome.Text.ToString());
                     laboratorioContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     laboratorioContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
     if (checkBoxQtd.Checked)
     {
         try
         {
             using (var laboratorioContext = new LaboratorioContext(_DB))
             {
                 var id   = lab.Where(c => c.Nome == comboBoxLabs.SelectedItem.ToString()).First().Id;
                 var item = lab.FirstOrDefault(c => c.Id == id);
                 if (item != null)
                 {
                     item.MudarQtd(Convert.ToInt32(textBoxQtd.Text.ToString()));
                     laboratorioContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     laboratorioContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
     if (checkBoxId.Checked)
     {
         try
         {
             using (var laboratorioContext = new LaboratorioContext(_DB))
             {
                 var id   = lab.Where(c => c.Nome == comboBoxLabs.SelectedItem.ToString()).First().Id;
                 var item = lab.FirstOrDefault(c => c.Id == id);
                 if (item != null)
                 {
                     item.MudarGrupoErro(Convert.ToInt32(textBoxGrupo.Text.ToString()));
                     laboratorioContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     laboratorioContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
 }