protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
    {
        // weonly process commands with a datasource (our image buttons)
        if (e.CommandSource == null)
        {
            return;
        }
        string typeOfControl = e.CommandSource.GetType().ToString();

        if (typeOfControl.Equals("System.Web.UI.WebControls.ImageButton"))
        {
            int         id   = 0;
            ImageButton imgb = (ImageButton)e.CommandSource;
            if (imgb.ID != "New" && imgb.ID != "Exit")
            {
                id = (int)e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex][e.Item.OwnerTableView.DataKeyNames[0]];
            }
            switch (imgb.ID)
            {
            case "Select":
                break;

            case "Edit":
                break;

            case "Delete":
                pay = (from p in ctx.GeneralPayments
                       where p.GeneralPaymentId == id
                       select p).FirstOrDefault <GeneralPayment>();
                CntAriCli.GeneralPaymentDelete(pay, ctx);
                RefreshGrid(true);
                break;
            }
        }
    }
    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 UnloadData(GeneralPayment pay)
    {
        if (pay != null)
        {
            serviceNote = pay.ServiceNote;
            CntAriCli.GeneralPaymentDelete(pay, ctx);
        }
        Clinic        clinic      = CntAriCli.GetClinic(int.Parse(rdcbClinic.SelectedValue), ctx);
        PaymentMethod payMethod   = CntAriCli.GetPaymentMethod(int.Parse(rdcbPaymentMethod.SelectedValue), ctx);
        DateTime      payDate     = (DateTime)rddpGeneralPaymentDate.SelectedDate;
        Decimal       amount      = (decimal)txtAmount.Value;
        string        description = txtComments.Text;

        pay = CntAriCli.GeneralPaymentNew(clinic, serviceNote, amount, payMethod, payDate, description, ctx);
    }
    protected bool DataOk(GeneralPayment gpy)
    {
        decimal actValue = 0;
        decimal oldValue = 0;

        actValue = (decimal)txtAmount.Value;
        if (gpy != null)
        {
            oldValue = gpy.Amount;
        }
        if (actValue > CntAriCli.GetUnpaid(serviceNote, ctx) + oldValue)
        {
            return(false);
        }
        return(true);
    }
 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 void LoadData(GeneralPayment pay)
 {
     LoadClinicCombo(pay.Clinic);
     LoadPaymentMethodCombo(pay.PaymentMethod);
     rddpGeneralPaymentDate.SelectedDate = pay.PaymentDate;
     if (pay != null)
     {
         txtGeneralPaymentId.Text = pay.GeneralPaymentId.ToString();
         txtAmount.Value          = (double)pay.Amount;
         txtServiceNoteData.Text  = String.Format("{0} ({1:dd/MM/yy})", pay.ServiceNote.Customer.ComercialName, pay.ServiceNote.ServiceNoteDate);
     }
     else
     {
         txtServiceNoteData.Text = String.Format("{0} ({1:dd/MM/yy})", serviceNote.Customer.ComercialName, serviceNote.ServiceNoteDate);
         txtAmount.Value         = (double)CntAriCli.GetUnpaid(serviceNote, ctx);
     }
     txtComments.Text = pay.Description;
 }
 protected void LoadData(GeneralPayment pay)
 {
     LoadClinicCombo(pay);
     LoadPaymentMethodCombo(pay);
     if (pay != null)
     {
         txtGeneralPaymentId.Text = pay.GeneralPaymentId.ToString();
         txtAmount.Value          = (double)pay.Amount;
         //txtAmount.Text = String.Format("{0:#.#}", pay.Amount);
         txtServiceNoteData.Text = String.Format("{0} ({1:dd/MM/yy})", pay.ServiceNote.Customer.ComercialName, pay.ServiceNote.ServiceNoteDate);
     }
     else
     {
         txtServiceNoteData.Text = String.Format("{0} ({1:dd/MM/yy})", snote.Customer.ComercialName, snote.ServiceNoteDate);
         txtAmount.Value         = (double)CntAriCli.GetUnpaid(snote, ctx);
         //txtAmount.Text = string.Format("{0:#.#}", CntAriCli.GetUnpaid(snote, ctx));
     }
 }
    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);
    }
    protected void LoadClinicCombo(GeneralPayment gp)
    {
        Clinic clinic = null;

        if (gp != null)
        {
            clinic = gp.Clinic;
        }
        rdcbClinic.Items.Clear();
        foreach (Clinic c in CntAriCli.GetClinics(ctx))
        {
            rdcbClinic.Items.Add(new RadComboBoxItem(c.Name, c.ClinicId.ToString()));
        }
        if (clinic != null)
        {
            rdcbClinic.SelectedValue = clinic.ClinicId.ToString();
        }
        else
        {
            rdcbClinic.Items.Add(new RadComboBoxItem(" ", ""));
            rdcbClinic.SelectedValue = "";
        }
    }
Ejemplo n.º 10
0
    protected void LoadPaymentMethodCombo(GeneralPayment gp)
    {
        PaymentMethod pm = null;

        if (gp != null)
        {
            pm = gp.PaymentMethod;
        }
        // clear previous items
        rdcbPaymentMethod.Items.Clear();
        foreach (PaymentMethod pm2 in ctx.PaymentMethods)
        {
            rdcbPaymentMethod.Items.Add(new RadComboBoxItem(pm2.Name, pm2.PaymentMethodId.ToString()));
        }
        if (pm != null)
        {
            rdcbPaymentMethod.SelectedValue = pm.PaymentMethodId.ToString();
        }
        else
        {
            rdcbPaymentMethod.Items.Add(new RadComboBoxItem(" ", ""));
            rdcbPaymentMethod.SelectedValue = "";
        }
    }