Exemple #1
0
    protected void calcularDescuento(int idPaciente)
    {
        txtDescuento.Text = "0";

        var paciente = (from pac in db.Pacientes
                        where pac.ID_Paciente == idPaciente
                        select pac).Single();

        var tieneObraSocial = (from pacPlan in db.PacientePlans
                               where pacPlan.ID_Paciente == paciente.ID_Paciente
                               select pacPlan).Any();

        if (tieneObraSocial)
        {
            PacientePlan planMasReciente = (from pacPlan in db.PacientePlans
                                            where pacPlan.ID_Paciente == paciente.ID_Paciente
                                            orderby pacPlan.FechaFin descending
                                            select pacPlan).First();

            DateTime hoy = DateTime.Today;

            if (DateTime.Compare(hoy, Convert.ToDateTime(planMasReciente.FechaInicio)) >= 0 && DateTime.Compare(hoy, Convert.ToDateTime(planMasReciente.FechaFin)) <= 0)
            {
                var plan = (from p in db.Plans
                            where p.ID_Plan == planMasReciente.ID_Plan
                            select p).Single();

                txtDescuento.Text = (plan.Descuento * 100).ToString();
            }
        }
    }
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        ClinicaDataContext db = new ClinicaDataContext();

        var temp = (from pac in db.Pacientes
                    where pac.ID_Paciente == Convert.ToInt32(Request.QueryString["id"])
                    select pac).Single();

        var nuevoPlan = new PacientePlan();

        nuevoPlan.ID_Paciente = temp.ID_Paciente;
        nuevoPlan.Habilitado  = true;
        nuevoPlan.ID_Plan     = Convert.ToInt32(ddlPlan.SelectedValue);
        nuevoPlan.Estado      = "Activo";
        nuevoPlan.FechaInicio = Convert.ToDateTime(txtFechaInicio.Text);
        nuevoPlan.FechaFin    = Convert.ToDateTime(txtFechaFin.Text);
        db.PacientePlans.InsertOnSubmit(nuevoPlan);
        db.SubmitChanges();
        grdPlanPaciente.DataBind();

        newObraSocial.Visible = false;
        newPlan.Visible       = false;
        fechaInicio.Visible   = false;
        fechaFin.Visible      = false;
        btnCancelar.Visible   = false;
        btnGuardar.Visible    = false;
    }