コード例 #1
0
        public ActionResult Edit([Bind(Include = "pt_id,ptempleadoid,ptubicacionid,pttipoid,estado,fecha,observaciones,modificado_el,id_encabezado,usuario_creacion")] pt_estadofuerza pt_estadofuerza)
        {
            if (ModelState.IsValid)
            {
                UsuarioTO usuarioTO = Cache.DiccionarioUsuariosLogueados[User.Identity.Name];
                pt_estadofuerza.modificado_el    = DateTime.Now;
                pt_estadofuerza.usuario_creacion = usuarioTO.usuario.usuario;

                db.Entry(pt_estadofuerza).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            IEnumerable <SelectListItem> empleados = db.pt_empleado
                                                     .Select(emp => new SelectListItem {
                Value = emp.PTEMPLEADOID.ToString() + " - " + emp.NOMBRE1 + " " + emp.NOMBRE2, Text = emp.PTEMPLEADOID.ToString()
            });

            ViewBag.ptempleadoid = empleados;

            ViewBag.id_encabezado = new SelectList(db.pt_estadofuerza_encabezado, "id", "creado_por", pt_estadofuerza.id_encabezado);
            ViewBag.estado        = new SelectList(db.pt_situacion, "id_situacion", "nombre", pt_estadofuerza.estado);
            ViewBag.ptubicacionid = new SelectList(db.pt_ubicacion, "PTUBICACIONID", "DIRECCION", pt_estadofuerza.ptubicacionid);
            ViewBag.pttipoid      = new SelectList(db.pt_tipo_ubicacion, "PTTIPOID", "DESCRIPCION", pt_estadofuerza.pttipoid);
            return(View(pt_estadofuerza));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(long id)
        {
            pt_estadofuerza pt_estadofuerza = db.pt_estadofuerza.Find(id);

            db.pt_estadofuerza.Remove(pt_estadofuerza);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
        // GET: EstadoFuerza/pt_estadofuerza/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            pt_estadofuerza pt_estadofuerza = db.pt_estadofuerza.Find(id);

            if (pt_estadofuerza == null)
            {
                return(HttpNotFound());
            }

            /*IEnumerable<SelectListItem> empleados = db.pt_empleado
             * .Select(emp => new SelectListItem { Value = emp.PTEMPLEADOID.ToString() + " - " + emp.NOMBRE1 + " " + emp.NOMBRE2, Text = emp.PTEMPLEADOID.ToString() });
             * ViewBag.ptempleadoid = empleados;*/

            //ViewBag.id_encabezado = new SelectList(db.pt_estadofuerza_encabezado, "id", "creado_por", pt_estadofuerza.id_encabezado);
            pt_empleado emp             = db.pt_empleado.Find(pt_estadofuerza.ptempleadoid);
            string      primerNombre    = emp.NOMBRE1 ?? "";
            string      segundoNombre   = emp.NOMBRE2 ?? "";
            string      primerApellido  = emp.APELLIDO1 ?? "";
            string      segundoApellido = emp.APELLIDO2 ?? "";

            ViewBag.NombreEmpleado = primerNombre + " " + segundoNombre + " " + primerApellido + " " + segundoApellido;

            IEnumerable <SelectListItem> estado = db.pt_situacion.Select(sit => new SelectListItem {
                Text = sit.id_situacion.ToString() + " - " + sit.nombre, Value = sit.id_situacion.ToString()
            });
            IEnumerable <SelectListItem> ubicacion = db.pt_ubicacion.Select(ub => new SelectListItem {
                Text = ub.PTUBICACIONID.ToString() + " - " + ub.DIRECCION, Value = ub.PTUBICACIONID.ToString()
            });
            IEnumerable <SelectListItem> tiposervicio = db.pt_tipo_ubicacion.Select(tp => new SelectListItem {
                Text = tp.PTTIPOID.ToString() + " - " + tp.DESCRIPCION, Value = tp.PTTIPOID.ToString()
            });

            //ViewBag.id_encabezado = new SelectList(db.pt_estadofuerza_encabezado, "id", "creado_por", pt_estadofuerza.id_encabezado);
            //ViewBag.estado = new SelectList(db.pt_situacion, "id_situacion", "nombre", pt_estadofuerza.estado);
            ViewBag.estado = estado;
            //ViewBag.ptubicacionid = new SelectList(db.pt_ubicacion, "PTUBICACIONID", "DIRECCION", pt_estadofuerza.ptubicacionid);
            ViewBag.ptubicacionid = ubicacion;
            //ViewBag.pttipoid = new SelectList(db.pt_tipo_ubicacion, "PTTIPOID", "DESCRIPCION", pt_estadofuerza.pttipoid);
            ViewBag.pttipoid = tiposervicio;
            return(View(pt_estadofuerza));
        }
コード例 #4
0
        // GET: EstadoFuerza/pt_estadofuerza/Delete/5
        public ActionResult Delete(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            pt_estadofuerza pt_estadofuerza = db.pt_estadofuerza.Find(id);

            if (pt_estadofuerza == null)
            {
                return(HttpNotFound());
            }
            pt_empleado emp             = db.pt_empleado.Find(pt_estadofuerza.ptempleadoid);
            string      primerNombre    = emp.NOMBRE1 ?? "";
            string      segundoNombre   = emp.NOMBRE2 ?? "";
            string      primerApellido  = emp.APELLIDO1 ?? "";
            string      segundoApellido = emp.APELLIDO2 ?? "";

            ViewBag.NombreEmpleado = primerNombre + " " + segundoNombre + " " + primerApellido + " " + segundoApellido;
            return(View(pt_estadofuerza));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "pt_id,ptempleadoid,ptubicacionid,pttipoid,estado,fecha,observaciones,modificado_el,id_encabezado,usuario_creacion")] pt_estadofuerza pt_estadofuerza)
        {
            if (ModelState.IsValid)
            {
                if (db.pt_estadofuerza.Where(x => x.fecha == pt_estadofuerza.fecha && x.ptempleadoid == pt_estadofuerza.ptempleadoid).Count() == 0)
                {
                    UsuarioTO usuarioTO = Cache.DiccionarioUsuariosLogueados[User.Identity.Name];
                    pt_estadofuerza.modificado_el    = DateTime.Now;
                    pt_estadofuerza.usuario_creacion = usuarioTO.usuario.usuario;
                    db.pt_estadofuerza.Add(pt_estadofuerza);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            //IEnumerable<SelectListItem> empleados = db.pt_empleado.Select(emp => new SelectListItem { Value = emp.PTEMPLEADOID.ToString() + " - " + emp.NOMBRE1 + " " + emp.NOMBRE2, Text = emp.PTEMPLEADOID.ToString() });
            //ViewBag.ptempleadoid = empleados;

            ViewBag.id_encabezado = new SelectList(db.pt_estadofuerza_encabezado, "id", "creado_por", pt_estadofuerza.id_encabezado);


            IEnumerable <SelectListItem> estado = db.pt_situacion.Select(sit => new SelectListItem {
                Text = sit.id_situacion.ToString() + " - " + sit.nombre, Value = sit.id_situacion.ToString()
            });
            IEnumerable <SelectListItem> ubicacion = db.pt_ubicacion.Select(ub => new SelectListItem {
                Text = ub.PTUBICACIONID.ToString() + " - " + ub.DIRECCION, Value = ub.PTUBICACIONID.ToString()
            });
            IEnumerable <SelectListItem> tiposervicio = db.pt_tipo_ubicacion.Select(tp => new SelectListItem {
                Text = tp.PTTIPOID.ToString() + " - " + tp.DESCRIPCION, Value = tp.PTTIPOID.ToString()
            });

            ViewBag.estado        = estado;
            ViewBag.ptubicacionid = ubicacion;
            ViewBag.pttipoid      = tiposervicio;


            return(View(pt_estadofuerza));
        }
コード例 #6
0
        /* PROCESANDO CARGA MASIVA DE SOLICITUDES */
        // GET: TransporteValores/Solicitudes/CargaMasiva
        public ActionResult SubeArchivo(HttpPostedFileBase file)
        {
            using (var context = new Protal_webEntities())
            {
                pt_estadofuerza_encabezado encabezado_dia;
                encabezado_dia = context.pt_estadofuerza_encabezado.FirstOrDefault(x => x.fecha_fin == null && x.estado == 1);
                List <int?> empleados_dia  = new List <int?>();
                List <int?> empleados      = new List <int?>();
                List <int?> ubicaciones    = new List <int?>();
                List <int?> tipo_ubicacion = new List <int?>();
                List <int?> estado         = new List <int?>();


                if (encabezado_dia != null)
                {
                    foreach (pt_estadofuerza item in context.pt_estadofuerza.Where(x => x.fecha == encabezado_dia.fecha_inicio))
                    {
                        empleados_dia.Add(item.ptempleadoid);
                    }
                    foreach (SelectListItem item in context.pt_empleado.Where(x => x.pt_contratacion.Count() > 0 && x.pt_contratacion.FirstOrDefault().ESTADO.ToUpper() != "BAJA").Select(s => new SelectListItem {
                        Value = s.PTEMPLEADOID.ToString()
                    }))
                    {
                        empleados.Add(int.Parse(item.Value));
                    }

                    foreach (pt_ubicacion item in context.pt_ubicacion.Where(x => x.ESTADO.ToUpper() != "BAJA"))
                    {
                        ubicaciones.Add(item.PTUBICACIONID);
                    }

                    foreach (pt_tipo_ubicacion item in context.pt_tipo_ubicacion)
                    {
                        tipo_ubicacion.Add(item.PTTIPOID);
                    }

                    foreach (pt_situacion item in context.pt_situacion)
                    {
                        estado.Add(item.id_situacion);
                    }
                }
                /* TRANSACCION DE OPERACIONES */
                try
                {
                    if (Request.Files["FileUpload1"].ContentLength > 0)
                    {
                        UsuarioTO usuarioTO = Cache.DiccionarioUsuariosLogueados[User.Identity.Name];
                        DateTime  now       = DateTime.Now;
                        string    fileName  = Request.Files["FileUpload1"].FileName;
                        string    extension = System.IO.Path.GetExtension(fileName);
                        string    path      = string.Format("{0}/{1}", System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + "_" + fileName);

                        //string pa = string.Format("{0}/{1}", System.IO.Path.GetTempPath(), Guid.NewGuid().ToString() + "_" + fileName);

                        /* ELIMINA EL ARCHIVO SI EXISTE */
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }

                        /* GUARDANDO EL ARCHIVO TEMPORALMENTE */
                        Request.Files["FileUpload1"].SaveAs(path);

                        /*LEYENDO ARCHIVO EXCEL*/
                        //using linq to excel
                        var excel          = new ExcelQueryFactory(path);
                        var worksheetNames = excel.GetWorksheetNames();

                        /* OBTENIENDO EL PRIMER WORKSHEET */
                        var firstWorksheet = worksheetNames.First();
                        var worksheet      = from a in excel.Worksheet(firstWorksheet) select a;


                        int contador = 0;

                        pt_estadofuerza_encabezado encabezado;
                        //List<MVC2013.Src.EstadoFuerza.EstadoFuerzaMasivo> lista_errores = new List<MVC2013.Src.EstadoFuerza.EstadoFuerzaMasivo> ();
                        Lista_EstadoFuerzaMasivo lista_errores   = new Lista_EstadoFuerzaMasivo();
                        Lista_EstadoFuerzaMasivo lista_correctos = new Lista_EstadoFuerzaMasivo();



                        encabezado = context.pt_estadofuerza_encabezado.FirstOrDefault(x => x.fecha_fin == null && x.estado == 1);
                        DateTime fecha_ingreso_masivo = DateTime.Now;
                        if (encabezado != null)
                        {
                            /* GUARDANDO EL ARCHIVO EN SERVIDOR */
                            string path_server = string.Format("{0}/{1}", Server.MapPath("~/files/CargaEstadoFuerza"), "(" + encabezado.fecha_inicio.Year.ToString("0000") + "-" + encabezado.fecha_inicio.Month.ToString("00") + "-" + encabezado.fecha_inicio.Day.ToString("00") + ")_(" + fecha_ingreso_masivo.Year.ToString("0000") + "-" + fecha_ingreso_masivo.Month.ToString("00") + "-" + fecha_ingreso_masivo.Day.ToString("00") + " " + fecha_ingreso_masivo.Hour.ToString("00") + ";" + fecha_ingreso_masivo.Minute.ToString("00") + ";" + fecha_ingreso_masivo.Second.ToString("00") + ")_" + usuarioTO.usuario.usuario + "_" + fileName);
                            if (System.IO.File.Exists(path_server))
                            {
                                System.IO.File.Delete(path_server);
                            }
                            Request.Files["FileUpload1"].SaveAs(path_server);


                            foreach (var a in worksheet)
                            {
                                EstadoFuerzaMasivo loteDetalle = new EstadoFuerzaMasivo();
                                loteDetalle.id_encabezado = encabezado.id;

                                try
                                {
                                    int    id_empleado       = int.Parse(a["id_empleado"]);
                                    int    id_ubicacion      = int.Parse(a["id_ubicacion"]);
                                    int    id_tipo_ubicacion = int.Parse(a["id_tipo_ubicacion"]);
                                    int    id_estado         = int.Parse(a["id_estado"]);
                                    string comentario        = a["comentario"];


                                    loteDetalle.id_empleado       = id_empleado;
                                    loteDetalle.id_ubicacion      = id_ubicacion;
                                    loteDetalle.id_tipo_ubicacion = id_tipo_ubicacion;
                                    loteDetalle.id_estado         = id_estado;
                                    loteDetalle.comentario        = comentario;
                                    loteDetalle.fecha             = encabezado.fecha_inicio;

                                    if (!empleados.Contains(loteDetalle.id_empleado))
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "Empleado Incorrecto o de baja. ";
                                    }

                                    if (!ubicaciones.Contains(loteDetalle.id_ubicacion))
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "Ubicacion Incorrecta o de baja. ";
                                    }

                                    if (!tipo_ubicacion.Contains(loteDetalle.id_tipo_ubicacion))
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "Tipo de Ubicacion Incorrecto. ";
                                    }
                                    if (!estado.Contains(loteDetalle.id_estado))
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "Estado Incorrecto. ";
                                    }
                                    if (empleados_dia.Contains(loteDetalle.id_empleado))
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "El empleado ya existe para este dia";
                                    }
                                    if (lista_correctos.lista_carga.Where(x => x.id_empleado == loteDetalle.id_empleado).Count() > 0)
                                    {
                                        loteDetalle.error      = true;
                                        loteDetalle.error_msg += "El empleado ya existe en el archivo cargado";
                                    }
                                    if (loteDetalle.valida_errores())
                                    {
                                        contador++;
                                        loteDetalle.error = true;
                                        lista_errores.lista_carga.Add(loteDetalle);
                                    }
                                    else
                                    {
                                        contador++;
                                        loteDetalle.error = false;

                                        //pt_estadofuerza estado_fuerza_masivo = new pt_estadofuerza();

                                        //estado_fuerza_masivo.ptempleadoid = loteDetalle.id_empleado;
                                        //estado_fuerza_masivo.ptubicacionid = loteDetalle.id_ubicacion;
                                        //estado_fuerza_masivo.pttipoid = loteDetalle.id_tipo_ubicacion;
                                        //estado_fuerza_masivo.estado = loteDetalle.id_estado;
                                        //estado_fuerza_masivo.fecha = encabezado.fecha_inicio;
                                        //estado_fuerza_masivo.id_encabezado = encabezado.id;
                                        //estado_fuerza_masivo.observaciones = loteDetalle.comentario;
                                        //estado_fuerza_masivo.modificado_el = fecha_ingreso_masivo;
                                        //estado_fuerza_masivo.usuario_creacion = usuarioTO.usuario.usuario;

                                        lista_correctos.lista_carga.Add(loteDetalle);
                                        //context.pt_estadofuerza.Add(estado_fuerza_masivo);
                                        //context.SaveChanges();
                                    }
                                }
                                catch (Exception e)
                                {
                                    contador++;
                                    loteDetalle.error = true;
                                    if (loteDetalle.id_empleado != 0)
                                    {
                                        lista_errores.lista_carga.Add(loteDetalle);
                                    }

                                    //loteDetalle.fila = contador;
                                    //loteDetalle.error_msg += e.Message;
                                    //context.Solicitudes_Lote_Detalle.Add(loteDetalle);
                                    //context.SaveChanges();
                                }
                            }
                        }

                        //if (lista_correctos.lista_carga.Count() == 0)
                        {
                            //throw new Exception("Error al procesar Archivo.");
                            //}                             else {
                            //using (var dbContextTransaction = context.Database.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
                            {
                                try
                                {
                                    foreach (EstadoFuerzaMasivo loteDetalle in lista_correctos.lista_carga)
                                    {
                                        pt_estadofuerza estado_fuerza_masivo = new pt_estadofuerza();
                                        estado_fuerza_masivo.ptempleadoid     = loteDetalle.id_empleado;
                                        estado_fuerza_masivo.ptubicacionid    = loteDetalle.id_ubicacion;
                                        estado_fuerza_masivo.pttipoid         = loteDetalle.id_tipo_ubicacion;
                                        estado_fuerza_masivo.estado           = loteDetalle.id_estado;
                                        estado_fuerza_masivo.fecha            = encabezado.fecha_inicio;
                                        estado_fuerza_masivo.id_encabezado    = encabezado.id;
                                        estado_fuerza_masivo.observaciones    = loteDetalle.comentario;
                                        estado_fuerza_masivo.modificado_el    = fecha_ingreso_masivo;
                                        estado_fuerza_masivo.usuario_creacion = usuarioTO.usuario.usuario;

                                        context.pt_estadofuerza.Add(estado_fuerza_masivo);
                                    }
                                    context.SaveChanges();

                                    //dbContextTransaction.Commit();
                                    TempData["listado_errores"] = lista_errores;
                                    return(RedirectToAction(
                                               "DetalleCarga",                                                // Action name
                                               "CargaMasiva",                                                 // Controller name
                                               new { total_cargado = lista_correctos.lista_carga.Count() })); // Route values
                                }
                                catch (Exception)
                                {
                                    //dbContextTransaction.UnderlyingTransaction.Rollback();
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    //
                    //ModelState.AddModelError("", App_GlobalResources.Resources.import_masivo_error);
                    // ViewBag.ErrorMessage = App_GlobalResources.Resources.import_masivo_error;
                    TempData["ErrorMessage"] = App_GlobalResources.Resources.import_masivo_error;
                }
            }

            return(RedirectToAction(
                       "Mensaje",                                                     // Action name
                       "CargaMasiva", new { msg = "Error al procesar el archivo" })); // Controller name
        }