コード例 #1
0
ファイル: Dieta.cs プロジェクト: ZEUSRPA/SaludFisica
        public List <Dieta> all(Context context)
        {
            List <Dieta> lista = new List <Dieta>();
            Conexion     con   = new Conexion();

            con.start(context);
            MySqlDataReader data = null;

            try
            {
                var cmd = new MySqlCommand(string.Format("SELECT * FROM dietas"), con.getConnection());
                data = cmd.ExecuteReader();
                while (data.Read())
                {
                    Dieta aux = new Dieta();
                    aux.id      = data.GetInt32("ID");
                    aux.kcal    = data.GetInt32("kcal");
                    aux.name    = data.GetString("Nombre");
                    aux.content = data.GetString("Contenido");
                    lista.Add(aux);
                }
                data.Close();
                con.end(context);
                return(lista);
            }
            catch (Exception ex)
            {
                con.end(context);
                Toast.MakeText(context, ex.ToString(), ToastLength.Long).Show();
                return(lista);
            }
        }
コード例 #2
0
        protected override void OnStart()
        {
            base.OnStart();
            var diet = new Dieta();

            dietas       = diet.all(this);
            list.Adapter = new DietaAdapter(this, Resource.Layout.itemDiet, dietas);
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.pacientDiet);

            pacient.id = Intent.GetIntExtra("Pacient", 0);
            pacient.findAndLoad(this, pacient.id);
            authLevel = Intent.GetIntExtra("Auth", 4);
            diet.findAndLoad(this, pacient.paciente.idDieta);

            nameET = FindViewById <EditText>(Resource.Id.dietNameDetailsET);
            kcal   = FindViewById <EditText>(Resource.Id.dietKcalDetailsET);



            name        = FindViewById <Spinner>(Resource.Id.dietNameDetailsSP);
            description = FindViewById <EditText>(Resource.Id.dietDescriptionDetailsET);
            var dieta = new Dieta();

            dietas      = dieta.all(this);
            nameET.Text = diet.name;
            kcal.Text   = diet.kcal.ToString();
            ArrayAdapter <Dieta> adapter = new ArrayAdapter <Dieta>(this, Resource.Layout.support_simple_spinner_dropdown_item, dietas);

            name.Adapter = adapter;

            if (pacient.paciente.idDieta == 0)
            {
                pacient.paciente.idDieta = dietas[dietas.FindIndex(a => a.name == "Sin dieta")].id;
            }

            name.SetSelection(dietas.FindIndex(a => a.id == pacient.paciente.idDieta));
            name.ItemSelected += dietSelectionChange;

            changePacientDietPB        = FindViewById <Button>(Resource.Id.changePacientDietPB);
            changePacientDietPB.Click += changePacientDiet;

            if (authLevel == 4 || authLevel == 3)
            {
                changePacientDietPB.Visibility = ViewStates.Invisible;
            }

            cancelPacientDietUpdatePB        = FindViewById <Button>(Resource.Id.cancelPacientDietUpdatePB);
            cancelPacientDietUpdatePB.Click += cancelPacientDietUpdate;

            savePacientDietUpdatePB        = FindViewById <Button>(Resource.Id.savePacientDietUpdatePB);
            savePacientDietUpdatePB.Click += savePacientDietUpdate;



            // Create your application here
        }
コード例 #4
0
ファイル: Dieta.cs プロジェクト: ZEUSRPA/SaludFisica
        public bool update(Context context, Dieta value)
        {
            if (!findAndLoad(context, this.id))
            {
                Toast.MakeText(context, "La dieta no existe", ToastLength.Short).Show();
                return(false);
            }
            Conexion con = new Conexion();

            con.start(context);
            try
            {
                if (this.name != value.name)
                {
                    if (findAndLoad(context, value.name))
                    {
                        Toast.MakeText(context, "El nombre ya esta asignado", ToastLength.Short).Show();
                        return(false);
                    }
                }
                var cmd = new MySqlCommand(string.Format("UPDATE dietas SET nombre = '{0}', contenido = '{1}', kcal={2} WHERE id = {3}", value.name, value.content, value.kcal, id), con.getConnection());


                if (cmd.ExecuteNonQuery() > 0)
                {
                    Toast.MakeText(context, "Dieta Agregada", ToastLength.Short).Show();
                    this.name    = value.name;
                    this.content = value.content;
                    this.kcal    = value.kcal;
                }

                con.end(context);
                return(true);
            }
            catch (Exception ex)
            {
                Toast.MakeText(context, ex.ToString(), ToastLength.Long).Show();
                con.end(context);
                return(false);
            }
        }
コード例 #5
0
        private void saveRutineUpdate(object sender, EventArgs e)
        {
            Dieta aux = new Dieta();

            aux.name    = name.Text;
            aux.content = description.Text;
            if (kcal.Text != "")
            {
                aux.kcal = int.Parse(kcal.Text);
            }
            else
            {
                aux.kcal = 0;
            }
            if (rutine.update(this, aux))
            {
                var intent = new Intent(this, typeof(RutineDetailsActivity));
                intent.PutExtra("Rutine", rutine.id);
                this.StartActivity(intent);
                Finish();
            }
        }
コード例 #6
0
        private void AgregarDieta(object sender, EventArgs e)
        {
            Dieta diet = new Dieta();
            var   name = FindViewById <EditText>(Resource.Id.dietNameAdd);

            diet.name = name.Text;
            var content = FindViewById <EditText>(Resource.Id.dietDescriptionAdd);

            diet.content = content.Text;
            var kcal = FindViewById <EditText>(Resource.Id.dietKcalAdd);

            if (kcal.Text != "")
            {
                diet.kcal = int.Parse(kcal.Text);
            }
            else
            {
                diet.kcal = 0;
            }
            if (!(diet.name.Trim() != "" && diet.content.Trim() != ""))
            {
                Toast.MakeText(this, "Debe llenar todos los campos", ToastLength.Short).Show();
                return;
            }
            if (diet.findAndLoad(this, diet.name))
            {
                Toast.MakeText(this, "La dieta ya esta registrada", ToastLength.Short).Show();
            }
            else
            {
                diet.save(this);
                name.Text    = "";
                content.Text = "";
                kcal.Text    = "";
                Finish();
            }
        }