Exemple #1
0
        public async Task <ActionResult <Depto> > PostDepto(Depto depto)
        {
            _context.Deptos.Add(depto);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDepto", new { id = depto.Id }, depto));
        }
Exemple #2
0
        public async Task <IActionResult> PutDepto(int id, Depto depto)
        {
            if (id != depto.Id)
            {
                return(BadRequest());
            }

            _context.Entry(depto).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DeptoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemple #3
0
        public static bool EliminarDepto(Depto d)
        {
            string        cadenaConexion = System.Configuration.ConfigurationManager.AppSettings["CadenaBD"];
            SqlConnection cn             = new SqlConnection(cadenaConexion);
            bool          resultado      = false;

            try
            {
                SqlCommand cmd      = new SqlCommand();
                string     consulta = "DeleteDepto";
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@idDepto", d.IdDepto);

                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = consulta;

                cn.Open();
                cmd.Connection = cn;
                cmd.ExecuteNonQuery();
                resultado = true;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                cn.Close();
            }
            return(resultado);
        }
Exemple #4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtNroDepto.Text.Equals("") || txtNombreDepto.Text.Equals("") || cmbProvincias.SelectedIndex == -1)
            {
                DialogResult mensaje = MessageBox.Show("Ingrese todos los campos necesarios!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtNombreDepto.Focus();
            }
            else
            {
                Depto  d           = ObtenerDatosDepto();
                string nombreDepto = d.NombreDepto;
                int    idProvincia = d.IdProvinciaDepto;
                bool   existe      = AD_Deptos.ExisteDepto(nombreDepto, idProvincia);
                if (existe)
                {
                    MessageBox.Show("El departamento ingresado ya esta en el sistema!", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtNombreDepto.Focus();
                }
                else
                {
                    bool resultado = AD_Deptos.AgregarDepto(d);

                    if (resultado)
                    {
                        MessageBox.Show("Departamento agredado correctamente!", "Informacion");
                        frmAltaDepto_Load(sender, e);
                    }
                    else
                    {
                        MessageBox.Show("Error al insertar el departamento!");
                    }
                }
            }
        }
        public frmModificarEliminarDepto(Depto d)
        {
            InitializeComponent();
            CargarComboProvincias();

            txtNroDepto.Text            = d.IdDepto.ToString();
            txtNombreDepto.Text         = d.NombreDepto.ToString();
            cmbProvincias.SelectedValue = d.IdProvinciaDepto;
        }
 public void EditarDepartamentos(Depto dep)
 {
     using (var query = new DocumentControllerEntities())
     {
         var a = query.Depto.Find(dep.idDepto);
         a.siglas   = dep.siglas;
         a.FullName = dep.FullName;
         query.SaveChanges();
     }
 }
Exemple #7
0
        private Depto ObtenerDatosDepto()
        {
            Depto d = new Depto();

            d.IdDepto          = int.Parse(txtNroDepto.Text);
            d.NombreDepto      = txtNombreDepto.Text.Trim();
            d.IdProvinciaDepto = (int)cmbProvincias.SelectedValue;

            return(d);
        }
 public XMLUser(int userId, string userName, string forename, string surname, DateTime startDate, int roleId, int dptoId, bool leaver, DateTime?leavingDate)
 {
     UserId      = userId;
     UserName    = userName;
     Forename    = forename;
     Surname     = surname;
     StartDate   = startDate;
     Role        = Role.GetById(roleId);
     Depto       = Depto.GetById(dptoId);
     Leaver      = leaver;
     LeavingDate = leavingDate;
 }
 public ActionResult Create(Depto data)
 {
     try
     {
         enviar.guardar(data);
         return(RedirectToAction("Create"));
     }
     catch
     {
         return(View());
     }
 }
 public ActionResult Edit(int id, Depto dep)
 {
     try
     {
         editarData = new EditarDatacs();
         editarData.Editar(dep);
         return(RedirectToAction("Edit"));
     }
     catch
     {
         return(View());
     }
 }
Exemple #11
0
 public string InsertDatos(Depto tabla)
 {
     try
     {
         Query.Depto.Add(tabla);
         Query.SaveChanges();
         return("");
     }
     catch (Exception ex)
     {
         return("Error" + ex.Message);
     }
 }
Exemple #12
0
        private void grillaDeptos_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int             indice           = e.RowIndex;
            DataGridViewRow filaSeleccionada = grillaDeptos.Rows[indice];

            Depto d = new Depto();

            d.IdDepto          = int.Parse(filaSeleccionada.Cells[0].Value.ToString());
            d.NombreDepto      = filaSeleccionada.Cells[1].Value.ToString();
            d.IdProvinciaDepto = int.Parse(filaSeleccionada.Cells[2].Value.ToString());

            frmModificarEliminarDepto ventana = new frmModificarEliminarDepto(d);

            ventana.ShowDialog();
        }
        public ActionResult Crear()
        {
            //Estados:
            ViewBag.es1 = new Estado().EsCount(1);
            ViewBag.es2 = new Estado().EsCount(2);
            ViewBag.es3 = new Estado().EsCount(3);
            ViewBag.es4 = new Estado().EsCount(4);
            //Estados.

            List <Sucursal> sucursales = _db.Sucursales.ToList();

            ViewBag.Sucursal = sucursales;

            Depto p = new Depto();

            return(View(p));
        }
        public ActionResult Ver(int id)
        {
            //Estados:
            ViewBag.es1 = new Estado().EsCount(1);
            ViewBag.es2 = new Estado().EsCount(2);
            ViewBag.es3 = new Estado().EsCount(3);
            ViewBag.es4 = new Estado().EsCount(4);
            //Estados.

            Depto p = _db.Deptos.Find(id);

            if (p == null)
            {
                return(new HttpNotFoundResult());
            }
            return(View(p));
        }
        public ActionResult Editar(int id)
        {
            //Estados:
            ViewBag.es1 = new Estado().EsCount(1);
            ViewBag.es2 = new Estado().EsCount(2);
            ViewBag.es3 = new Estado().EsCount(3);
            ViewBag.es4 = new Estado().EsCount(4);
            //Estados.

            Depto p = _db.Deptos.Find(id);

            if (p == null)
            {
                return(new HttpNotFoundResult());
            }

            List <Sucursal> sucursales = _db.Sucursales.ToList();

            ViewBag.Sucursal = sucursales;

            return(View(p));
        }
        public ActionResult Crear(Depto p)
        {
            //Estados:
            ViewBag.es1 = new Estado().EsCount(1);
            ViewBag.es2 = new Estado().EsCount(2);
            ViewBag.es3 = new Estado().EsCount(3);
            ViewBag.es4 = new Estado().EsCount(4);
            //Estados.

            if (ModelState.IsValid)
            {
                _db.Deptos.Add(p);
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            List <Sucursal> sucursales = _db.Sucursales.ToList();

            ViewBag.Sucursal = sucursales;

            return(View(p));
        }
        public ActionResult Editar(int id, Depto p)
        {
            //Estados:
            ViewBag.es1 = new Estado().EsCount(1);
            ViewBag.es2 = new Estado().EsCount(2);
            ViewBag.es3 = new Estado().EsCount(3);
            ViewBag.es4 = new Estado().EsCount(4);
            //Estados.

            if (ModelState.IsValid)
            {
                _db.Entry(p).State = System.Data.Entity.EntityState.Modified;
                _db.SaveChanges();
                return(RedirectToAction("Index", "Departamento", new { Id = p.Id }));
            }

            List <Sucursal> sucursales = _db.Sucursales.ToList();

            ViewBag.Sucursal = sucursales;

            return(View(p));
        }
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            DialogResult confirmacion = MessageBox.Show("¿Desea eliminar el departamento seleccionado?", "Confirmación", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);

            if (confirmacion == DialogResult.OK)
            {
                Depto d         = ObternerDatosDepto();
                bool  resultado = AD_Deptos.EliminarDepto(d);
                if (resultado)
                {
                    MessageBox.Show("Departamento eliminado con exito!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Error al eliminar el departamento!");
                }
            }
            else if (confirmacion == DialogResult.Cancel)
            {
                MessageBox.Show("Operacion cancelada!");
            }
        }
Exemple #19
0
 public Administrador(string numero, string nombre, string apellidos, string direccion, Depto depto)
     : base(numero, nombre, apellidos, direccion)
 {
     Departamento = depto;
 }
        static void Transacciones()
        {
            try
            {
                //Instanciamos el contexto de Entity Framework
                BBDDLocalClase3Entities db = new BBDDLocalClase3Entities();

                //Se le asigna un valor en segundos, si se le asigna 0 entonces obligamos a EF a esperar indefinidamente la respuesta de SQL
                db.Database.CommandTimeout = 0;
                Console.WriteLine("***********ANTES DE TRANSACCION*************");
                var ListaPaisA = db.Pais.Select(x =>
                                                new
                {
                    CodigoPais  = x.CodigoPais,
                    Descripcion = x.Descripcion
                }
                                                ).ToList();
                Console.WriteLine("***********PAIS*************");
                foreach (var item in ListaPaisA)
                {
                    Console.WriteLine(item.CodigoPais.ToString() + " - " + item.Descripcion);
                }

                var ListaDeptoA = db.Depto.Select(x =>
                                                  new
                {
                    CodigoDepto = x.CodigoDepto,
                    Descripcion = x.Descripcion
                }
                                                  ).ToList();
                Console.WriteLine("***********DEPARTAMENTO*************");
                foreach (var item in ListaDeptoA)
                {
                    Console.WriteLine(item.CodigoDepto.ToString() + " - " + item.Descripcion);
                }

                var ListaMunicipioA = db.Municipio.Select(x =>
                                                          new
                {
                    CodigoMunicipio = x.CodigoMunicipio,
                    Descripcion     = x.Descripcion
                }
                                                          ).ToList();
                Console.WriteLine("***********MUNICIPIO*************");
                foreach (var item in ListaMunicipioA)
                {
                    Console.WriteLine(item.CodigoMunicipio.ToString() + " - " + item.Descripcion);
                }

                #region Transacciones
                using (var dbTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Pais newPais = new Pais()
                        {
                            Descripcion = "Pais nuevo"
                        };
                        db.Pais.Add(newPais);

                        //Correcto
                        //Depto newDepto = new Depto() { CodigoPais = newPais.CodigoPais, Descripcion = "Depto nuevo" };
                        //db.Depto.Add(newDepto);

                        //Con error
                        Depto newDepto = new Depto()
                        {
                            CodigoPais = 10, Descripcion = "Depto nuevo"
                        };
                        db.Depto.Add(newDepto);

                        Municipio newMunicipio = new Municipio()
                        {
                            CodigoDepto = newDepto.CodigoDepto, Descripcion = "Municipio nuevo"
                        };
                        db.Municipio.Add(newMunicipio);

                        db.SaveChanges();

                        dbTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        Console.WriteLine(ex.InnerException.Message);
                        Console.WriteLine(ex.InnerException.InnerException.Message);
                        dbTransaction.Rollback();
                    }
                }
                Console.WriteLine("***********DESPUES DE TRANSACCION*************");
                var ListaPais = db.Pais.Select(x =>
                                               new
                {
                    CodigoPais  = x.CodigoPais,
                    Descripcion = x.Descripcion
                }
                                               ).ToList();
                Console.WriteLine("***********PAIS*************");
                foreach (var item in ListaPais)
                {
                    Console.WriteLine(item.CodigoPais.ToString() + " - " + item.Descripcion);
                }

                var ListaDepto = db.Depto.Select(x =>
                                                 new
                {
                    CodigoDepto = x.CodigoDepto,
                    Descripcion = x.Descripcion
                }
                                                 ).ToList();
                Console.WriteLine("***********DEPARTAMENTO*************");
                foreach (var item in ListaDepto)
                {
                    Console.WriteLine(item.CodigoDepto.ToString() + " - " + item.Descripcion);
                }

                var ListaMunicipio = db.Municipio.Select(x =>
                                                         new
                {
                    CodigoMunicipio = x.CodigoMunicipio,
                    Descripcion     = x.Descripcion
                }
                                                         ).ToList();
                Console.WriteLine("***********MUNICIPIO*************");
                foreach (var item in ListaMunicipio)
                {
                    Console.WriteLine(item.CodigoMunicipio.ToString() + " - " + item.Descripcion);
                }
                #endregion
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.Read();
            }
        }
 public void Editar(Depto dep)
 {
     edicion.EditarDepartamentos(dep);
 }
 public void guardar(Depto tabla)
 {
     registro.InsertDatos(tabla);
 }
Exemple #23
0
 public Manger(string EmpNumber, string Name, string LastName, string Address, Depto depto)
     : base(EmpNumber, Name, LastName, Address)
 {
     departamento = Departamento;
 }