protected void Page_Init(object sender, EventArgs e)
    {
        ctx = new AriClinicContext("AriClinicContext");
        // security control, it must be a user logged
        if (Session["User"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        else
        {
            user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
            Process proc = (from p in ctx.Processes
                            where p.Code == "payment"
                            select p).FirstOrDefault <Process>();
            per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
            btnAccept.Visible = per.Modify;
        }
        if (Session["Clinic"] != null)
        {
            cl = (Clinic)Session["Clinic"];
        }
        //

        //
        if (Request.QueryString["ServiceNoteId"] != null)
        {
            serviceNoteId = int.Parse(Request.QueryString["ServiceNoteId"]);
            snote         = CntAriCli.GetServiceNote(serviceNoteId, ctx);
            // calcute total amount and total payments
            //txtServiceNoteData.Text = String.Format("ID:{0} Fecha:{1:dd/MM/yy} Total:{2} Pagado:{3}",
            //    snote.ServiceNoteId,
            //    snote.ServiceNoteDate,
            //    CntAriCli.GetServiceNoteAmount(snote),
            //    CntAriCli.GetServiceNoteAmountPay(snote));
            txtServiceNoteData.Text = String.Format("{0} ({1:dd/MM/yy}) T:{2:0.00} P:{3:0.00}", snote.Customer.ComercialName, snote.ServiceNoteDate, snote.Total, snote.Paid);
            txtAmount.Value         = (double)CntAriCli.GetUnpaid(snote, ctx);
            //txtAmount.Text = string.Format("{0:#.#}", CntAriCli.GetUnpaid(snote, ctx));
            SetFocus(rdcbClinic);
        }

        if (Request.QueryString["GeneralPaymentId"] != null)
        {
            paymentId = Int32.Parse(Request.QueryString["GeneralPaymentId"]);
            gpay      = CntAriCli.GetGeneralPayment(paymentId, ctx);
            LoadData(gpay);
        }
        else
        {
            rddpGeneralPaymentDate.SelectedDate = DateTime.Now;
            LoadPaymentMethodCombo(null);
            LoadClinicCombo(null);
        }
    }
 protected void Page_Init(object sender, EventArgs e)
 {
     ctx = new AriClinicContext("AriClinicContext");
     if (Session["User"] == null)
     {
         Response.Redirect("Default.aspx");
     }
     else
     {
         user = CntAriCli.GetUser((Session["User"] as User).UserId, ctx);
         Process proc = (from p in ctx.Processes
                         where p.Code == "payment"
                         select p).FirstOrDefault <Process>();
         permission        = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
         btnAccept.Visible = permission.Modify;
     }
     if (Session["Clinic"] != null)
     {
         clinic = (Clinic)Session["Clinic"];
     }
     if (Request.QueryString["ServiceNoteId"] != null)
     {
         serviceNoteId           = int.Parse(Request.QueryString["ServiceNoteId"]);
         serviceNote             = CntAriCli.GetServiceNote(serviceNoteId, ctx);
         txtServiceNoteData.Text = String.Format("{0} ({1:dd/MM/yy}) T:{2:0.00} P:{3:0.00}", serviceNote.Customer.ComercialName, serviceNote.ServiceNoteDate, serviceNote.Total, serviceNote.Paid);
         txtAmount.Value         = (double)CntAriCli.GetUnpaid(serviceNote, ctx);
         if (serviceNote.Clinic != null)
         {
             clinic = serviceNote.Clinic;
         }
         SetFocus(rdcbClinic);
     }
     if (Request.QueryString["GeneralPaymentId"] != null)
     {
         generalPaymentId = Int32.Parse(Request.QueryString["GeneralPaymentId"]);
         generalPayment   = CntAriCli.GetGeneralPayment(generalPaymentId, ctx);
         serviceNote      = generalPayment.ServiceNote;
         LoadData(generalPayment);
     }
     else
     {
         rddpGeneralPaymentDate.SelectedDate = DateTime.Now;
         LoadPaymentMethodCombo(null);
         LoadClinicCombo(clinic);
     }
 }
    protected bool CreateChange()
    {
        if (!DataOk(generalPayment))
        {
            return(false);
        }
        if (generalPayment == null)
        {
            UnloadData(generalPayment);
        }
        else
        {
            generalPayment = CntAriCli.GetGeneralPayment(generalPaymentId, ctx);
            UnloadData(generalPayment);
        }
        // update payments in related ticket

        return(true);
    }