public string CreaCombo(string Sql = "", string Clave = "", string Valor = "", string Inicial = "",bool opcionone = false)
		{
			string Salida = "";
			DatosPersonasModel model = new DatosPersonasModel();
			Salida = model.ComboSql(Sql, Clave, Valor, Inicial, opcionone);
			return Salida;
		}
		public ActionResult Delete(DatosPersonasModel model)
		{
			if (sesion == null) { sesion = SessionDB.start(Request, Response, false, db); }
			model.sesion = sesion;

			if (!sesion.permisos.havePermission(Privileges[0].Permiso))
				return Json(new { msg = Notification.notAccess() });

			try
			{
				if (model.Delete())
				{
					Log.write(this, "Delete", LOG.BORRADO, "SQL:" + model.sql, sesion);
					return Json(new { msg = Notification.Succes("Persona ELIMINADA con exito: " + model.Id_Persona) });
				}
				else
				{
					Log.write(this, "Delete", LOG.ERROR, "SQL:" + model.sql, sesion);
					return Json(new { msg = Notification.Error("Error al Eliminar la Persona = " + model.Id_Persona) });
				}
			}
			catch (Exception e)
			{
				return Json(new { msg = Notification.Error(e.Message) });

			}
		}
		public ActionResult Save(DatosPersonasModel model)
		{
			if (sesion == null) { sesion = SessionDB.start(Request, Response, false, db); }
			model.sesion = sesion;

			if (!sesion.permisos.havePermission(Privileges[0].Permiso))
				return Json(new { msg = Notification.notAccess() });
			try
			{
				if (model.Save())
				{
                    if (model.SaveTP())
                    {
                        Log.write(this, "Save", LOG.EDICION, "SQL:" + model.sql, sesion);
                        return Json(new { msg = Notification.Succes("Persona guardada con exito: " + model.Idsiu + " - " + model.Nombres + " " + model.Apellidos) });
                    } else
                    {
                        Log.write(this, "Save", LOG.EDICION, "SQL:" + model.sql, sesion);
                        return Json(new { msg = Notification.Warning("Persona guardada con exito: " + model.Idsiu + " - " + model.Nombres + " " + model.Apellidos + ", pero con errores en la PA (tipo de pago).") });
                    }
				}
				else
				{
					Log.write(this, "Save", LOG.ERROR, "SQL:" + model.sql, sesion);
					return Json(new { msg = Notification.Error(" Error al guardar Persona: " + model.Idsiu + " - " + model.Nombres + " " + model.Apellidos) });
				}
			}
			catch (Exception e)
			{
				return Json(new { msg = Notification.Error(e.Message) });

			}
		}
        public ActionResult getIdPersona(DatosPersonasModel model)
        {
            if ((sesion = SessionDB.start(Request, Response, false, db)) == null) { return Content("-1"); }

            if (model.getIdPersona())
            {
                if (model.Id_Persona != "-1")
                {
                    sesion.vdata["idPersona"] = model.Id_Persona;
                    sesion.saveSession();
                    return Json(new JavaScriptSerializer().Serialize(model));
                }
                else
                {
                    Log.write(this, "Buscar IDSIU en formulario DatosPersonas X", LOG.ERROR, "SQL:" + model.sql, sesion);
                    model.msg = Factory.Notification.Error(" La persona no existe en este contexto: " + model.Idsiu);
                    return Json(new JavaScriptSerializer().Serialize(model));
                }
            }
            else
            {
                Log.write(this, "Buscar IDSIU en formulario DatosPersonas Y", LOG.ERROR, "SQL:" + model.sql, sesion);
                model.msg = Factory.Notification.Error(" La persona no existe en este contexto: " + model.Idsiu);
                return Json(new JavaScriptSerializer().Serialize(model));
            }
            //return View();
        }
		public ActionResult Edit(DatosPersonasModel model)
		{
            if ((sesion = SessionDB.start(Request, Response, false, db)) == null) { return Content("-1"); }

            if (model.Edit())
			{
                sesion.vdata["idPersona"] = model.Id_Persona;
                sesion.saveSession();
                return Json(new JavaScriptSerializer().Serialize(model));
			}
			return View();
		}
		public ActionResult CodigoPostalResultados(DatosPersonasModel model)
		{
			Debug.WriteLine("controller CodigoPostalResultados");
			if (model.Obtener_Direccion())
			{
				return Json(new
				{
					Direccion_Estado = model.Direccion_Estado,
					Direccion_Pais = model.Direccion_Pais,
					Direccion_Ciudad = model.Direccion_Ciudad,
					Direccion_Entidad = model.Direccion_Entidad,
					Direccion_Colonia = model.Direccion_Colonia
				});
			}
			return View(Factory.View.Access + "Personas/DatosPersonas/Start.cshtml");
		}
		public ActionResult CodigoPostalRazonSocial(DatosPersonasModel model)
		{
			Debug.WriteLine("controller CodigoPostalRazonSocial");
			if (model.Obtener_Direccion())
			{
				// return Json(new JavaScriptSerializer().Serialize(model));
				return Json(new
				{
					Rz_Direccion_Estado = model.Direccion_Estado,
					Rz_Direccion_Pais = model.Direccion_Pais,
					Rz_Direccion_Ciudad = model.Direccion_Ciudad,
					Rz_Direccion_Entidad = model.Direccion_Entidad,
					Rz_Direccion_Colonia = model.Direccion_Colonia
				});
			}
			return View(Factory.View.Access + "Personas/DatosPersonas/Start.cshtml");
		}
		public ActionResult Add(DatosPersonasModel model)
		{
			if (sesion == null) { sesion = SessionDB.start(Request, Response, false, db); }
			model.sesion = sesion;

			if (!sesion.permisos.havePermission(Privileges[0].Permiso))
				return Json(new { msg = Notification.notAccess() });

			try
			{
				if (model.Add())
				{
                    if (model.existe)
                    {
                        Log.write(this, "Add", LOG.REGISTRO, "SQL:" + model.sql, sesion);
                        return Json(new { msg = Notification.Succes("Persona agregada con exito: " + model.Idsiu + " - " + model.Nombres + " " + model.Apellidos) });                     

                    } else
                    {
                        Log.write(this, "Add", LOG.REGISTRO, "SQL:" + model.sql, sesion);
                        return Json(new { msg = Notification.Warning("Persona con idsiu: " + model.Idsiu + " Ya existe!" ) });
                    }
                }
				else
				{
					Log.write(this, "Add", LOG.ERROR, "SQL:" + model.sql, sesion);
                    return Json(new { msg = Notification.Error(" Error al agregar: " + model.Idsiu + " - " + model.Nombres + " " + model.Apellidos) });
                 
                }
			}
			catch (Exception e)
			{
				return Json(new { msg = Factory.Notification.Error(e.Message) });

			}
		}