Example #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);
            }
        }
Example #2
0
 static int pegarIdLab(string nome, string ip)
 {
     using (var repo = new MaquinaContext(_DB))
     {
         var maquina = repo.Maquinas.FirstOrDefault(c => c.Ip == ip);
         return(maquina.IdLab);
     }
 }
Example #3
0
 private void btnRemover_Click(object sender, EventArgs e)
 {
     try
     {
         using (var maqContext = new MaquinaContext(_DB))
         {
             var id  = maqContext.Maquinas.Where(s => s.Nome == comboBoxMaqs.SelectedItem.ToString()).FirstOrDefault().id;
             var Maq = maqContext.Maquinas.Where(s => s.id == id).FirstOrDefault();
             maqContext.Maquinas.Remove(Maq);
             maqContext.SaveChanges();
             MessageBox.Show("Realizado com sucesso!");
             comboBoxMaqs.Items.RemoveAt(comboBoxMaqs.SelectedIndex);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         MessageBox.Show(ex.StackTrace);
     }
 }
Example #4
0
 private void btnListar_Click(object sender, EventArgs e)
 {
     comboBoxMaqs.Items.Clear();
     try
     {
         using (var maqContext = new MaquinaContext(_DB))
         {
             IList <Maquina> maquinas = maqContext.Maquinas.ToList();
             foreach (var item in maquinas)
             {
                 comboBoxMaqs.Items.Add(item.Nome);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         MessageBox.Show(ex.StackTrace);
     }
 }
Example #5
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);
         }
     }
 }