protected void UnloadData(ProfessionalInvoiceLine invl)
 {
     invl.ProfessionalInvoice = inv;
     taxTypeId    = Int32.Parse(rdcbTaxType.SelectedValue);
     invl.TaxType = CntAriCli.GetTaxType(taxTypeId, ctx);
     //if (txtTicketId.Text != "")
     //{
     //    ticketId = Int32.Parse(txtTicketId.Text);
     //    invl.Ticket = CntAriCli.GetTicket(ticketId, ctx);
     //}
     //invl.User = CntAriCli.GetUser(user.UserId, ctx);
     invl.Description   = txtDescription.Text;
     invl.TaxPercentage = Decimal.Parse(txtTaxPercentage.Text);
     invl.Amount        = Decimal.Parse(txtAmount.Text);
 }
 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 == "profInvoice"
                         select p).FirstOrDefault <Process>();
         per = CntAriCli.GetPermission(user.UserGroup, proc, ctx);
         btnAccept.Visible = per.Modify;
     }
     //
     if (Request.QueryString["InvoiceId"] != null)
     {
         invoiceId = Int32.Parse(Request.QueryString["InvoiceId"]);
         inv       = CntAriCli.GetProfessionalInvoice(invoiceId, ctx);
         LoadInvoiceData();
     }
     else
     {
         //TODO: What to do if there is not an invoice
     }
     if (Session["Clinic"] != null)
     {
         cl = (Clinic)Session["Clinic"];
     }
     //
     if (Request.QueryString["InvoiceLineId"] != null)
     {
         invoiceLineId = Int32.Parse(Request.QueryString["InvoiceLineId"]);
         invl          = CntAriCli.GetProfessionalInvoiceLine(invoiceLineId, ctx);
         LoadData(invl);
     }
     else
     {
         LoadTaxTypeCombo(null);
     }
 }
 protected bool CreateChange()
 {
     if (!DataOk())
     {
         return(false);
     }
     if (invl == null)
     {
         invl = new ProfessionalInvoiceLine();
         UnloadData(invl);
         ctx.Add(invl);
     }
     else
     {
         invl = CntAriCli.GetProfessionalInvoiceLine(invoiceLineId, ctx);
         UnloadData(invl);
     }
     ctx.SaveChanges();
     return(true);
 }
 protected void LoadData(ProfessionalInvoiceLine invl)
 {
     txtInvoiceLineId.Text = invl.InvoiceLineId.ToString();
     inv  = invl.ProfessionalInvoice;
     taxt = invl.TaxType;
     LoadInvoiceData();
     //tck = invl.Ticket;
     //if (tck != null)
     //{
     //    txtTicketId.Text = tck.TicketId.ToString();
     //    txtTicketData.Text = String.Format("{0} ({1}: {2:###,##0.00})"
     //        , tck.Policy.Customer.FullName
     //        , tck.Description
     //        , tck.Amount);
     //}
     LoadTaxTypeCombo(taxt);
     txtDescription.Text   = invl.Description;
     txtTaxPercentage.Text = String.Format("{0:##0.00}", invl.TaxPercentage);
     txtAmount.Text        = String.Format("{0:###,##0.00}", invl.Amount);
 }
        protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                // we only 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":
                        invl = CntAriCli.GetProfessionalInvoiceLine(id, ctx);
                        ctx.Delete(invl);
                        ctx.SaveChanges();
                        RefreshGrid(true);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Label lbl = (Label)this.Parent.FindControl("lblMessage");
                lbl.Text = ex.Message;
            }
        }