Ejemplo n.º 1
0
        private void btnCadastro_Click(object sender, EventArgs e)
        {
            string nome = textBoxNome.Text.ToString();
            string ip   = textBoxIp.Text.ToString();

            try
            {
                int id;
                using (var labContext = new LaboratorioContext(_DB))
                {
                    id = labContext.Laboratorios.FirstOrDefault(s => s.Nome.Contains(textBoxLab.Text.ToString())).Id;
                }
                using (var maqContext = new MaquinaContext(_DB))
                {
                    maqContext.Maquinas.Add(maq = new Maquina(nome, ip, id));
                    maqContext.SaveChanges();
                    MessageBox.Show("Realizado com sucesso!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Ejemplo n.º 2
0
 private void btnProcurar_Click(object sender, EventArgs e)
 {
     try
     {
         using (var labContext = new LaboratorioContext(_DB))
         {
             comboBoxLabs.Items.Clear();
             lab = labContext.Laboratorios.ToList();
             //List<string> nomes = labContext.Laboratorios.Select(c => c.Nome).ToList();
             //string[] Lista = new string[nomes.Count];
             //int index = 0;
             //foreach (var item in nomes)
             //{
             //    Lista[index] = item;
             //    index++;
             //}
             comboBoxLabs.Items.AddRange(labContext.Laboratorios.Select(c => c.Nome).ToArray());
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 private void btnListar_Click(object sender, EventArgs e)
 {
     comboBoxLabs.Items.Clear();
     try
     {
         using (var labContext = new LaboratorioContext(_DB))
         {
             IList <Laboratorio> labs = labContext.Laboratorios.ToList();
             foreach (var item in labs)
             {
                 comboBoxLabs.Items.Add(item.Nome);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         MessageBox.Show(ex.StackTrace);
     }
 }
Ejemplo n.º 5
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);
            }
        }
Ejemplo n.º 6
0
 static void listaTipoErro(Maquina maq)
 {
     try
     {
         using (var Labcont = new LaboratorioContext(_DB))
         {
             var lab = Labcont.Laboratorios.FirstOrDefault(c => c.Id == maq.IdLab);
             Labname = lab.Nome;
             idGrupo = lab.IdGrupoErro;
             using (var GrupoCont = new GErrosContext(_DB))
             {
                 IList <GruposDeErro> TodoErros     = GrupoCont.GruposErro.Where(c => c.IdGrupo == lab.IdGrupoErro).ToList();
                 List <int>           idDeTodoErros = TodoErros.Select(s => s.IdTipoErro).ToList();
                 using (var tErros = new TErrosContext(_DB))
                 {
                     IList <TiposDeErro> tiposDeErros = tErros.TiposErro.ToList();
                     Lista = new string[idDeTodoErros.Count];
                     int index = 0;
                     foreach (var item in idDeTodoErros)
                     {
                         if (tiposDeErros.Select(s => s.Id).Contains(item))
                         {
                             var nome = tiposDeErros.FirstOrDefault(s => s.Id == item).Nome;
                             Lista[index] = nome;
                             index++;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         MessageBox.Show(ex.StackTrace);
     }
 }
Ejemplo n.º 7
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);
         }
     }
 }
Ejemplo n.º 8
0
 public CategoriasController(LaboratorioContext context)
 {
     _context = context;
 }
Ejemplo n.º 9
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (checkBoxNome.Checked)
     {
         try
         {
             using (var maqContext = new MaquinaContext(_DB))
             {
                 var item = maqContext.Maquinas.FirstOrDefault(c => c.Ip == textBoxIp.Text.ToString());
                 if (item != null)
                 {
                     item.MudarNome(textBoxNome.Text.ToString());
                     maqContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     maqContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
     if (checkBoxLab.Checked)
     {
         try
         {
             int id;
             using (var labContext = new LaboratorioContext(_DB))
             {
                 id = labContext.Laboratorios.Where(s => s.Nome.Contains(textBoxLab.Text.ToString())).FirstOrDefault().Id;
             }
             using (var maqContext = new MaquinaContext(_DB))
             {
                 var item = maqContext.Maquinas.FirstOrDefault(c => c.Ip == textBoxIp.Text.ToString());
                 if (item != null)
                 {
                     item.MudarIdLab(id);
                     maqContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     maqContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
     if (checkBoxIp.Checked)
     {
         try
         {
             using (var maqContext = new MaquinaContext(_DB))
             {
                 var item = maqContext.Maquinas.FirstOrDefault(c => c.Nome == textBoxNome.Text.ToString());
                 if (item != null)
                 {
                     item.MudarIp(textBoxIp.Text.ToString());
                     maqContext.Entry(item).State = System.Data.Entity.EntityState.Modified;
                     maqContext.SaveChanges();
                     MessageBox.Show("Realizado com sucesso!");
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
             MessageBox.Show(ex.StackTrace);
         }
     }
 }