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 == "Estimate" select p).FirstOrDefault<Process>(); per = CntAriCli.GetPermission(user.UserGroup, proc, ctx); btnAccept.Visible = per.Modify; } // LoadComboInsurance(); // if (Request.QueryString["EstimateId"] != null) { estId = Int32.Parse(Request.QueryString["EstimateId"]); est = CntAriCli.GetEstimate(estId, ctx); } // if (Request.QueryString["EstimateLineId"] != null) { estlId = Int32.Parse(Request.QueryString["EstimateLineId"]); estl = CntAriCli.GetEstimateLine(estlId, ctx); LoadData(estl); } }
protected void btnEstimate_Click(object sender, ImageClickEventArgs e) { if (!CreateChange()) return; // check if string command = ""; if (req.Estimates.Count > 0) { // There's a replay already Estimate est = req.Estimates[0]; command = String.Format("EditEstimateRecord('{0}','{1}');", est.EstimateId, req.RequestId); } else { Estimate est = new Estimate(); est.User = user; est.FullName = req.FullName; est.Request = req; est.EstimateDate = DateTime.Now; if (req.Patient != null) est.FullName = req.Patient.FullName; else est.FullName = req.FullName; ctx.Add(est); ctx.SaveChanges(); if (req.Service != null) { if (req.Patient != null && req.Patient.Customer != null && req.Patient.Customer.Policies.Count > 0) { Policy pol = req.Patient.Customer.Policies[0]; InsuranceService inss = (from i in ctx.InsuranceServices where i.Insurance == pol.Insurance && i.Service.ServiceId == req.Service.ServiceId select i).FirstOrDefault<InsuranceService>(); if (inss != null) { // estimate line EstimateLine estl = new EstimateLine(); est.Comments = ""; estl.Estimate = est; estl.InsuranceService = inss; estl.Amount = inss.Price; estl.Discount = 0; estl.Description = inss.Service.Name; ctx.Add(estl); est.Total = estl.Amount; ctx.SaveChanges(); } } } command = String.Format("EditEstimateRecord('{0}','{1}');", est.EstimateId, req.RequestId); } // string command = "CloseAndRebind('')"; RadAjaxManager1.ResponseScripts.Add(command); }
protected bool CreateChange() { if (!DataOk()) return false; if (estl == null) { estl = new EstimateLine(); UnloadData(estl); ctx.Add(estl); } else { estl = CntAriCli.GetEstimateLine(estlId, ctx); UnloadData(estl); } ctx.SaveChanges(); return true; }
protected void UnloadData(EstimateLine estl) { estl.Description = txtDescription.Text; estl.Amount = (decimal)txtAmount.Value; estl.Discount = decimal.Parse(txtDiscount.Text); estl.InsuranceService = CntAriCli.GetInsuranceService(int.Parse(rdcInsuranceService.SelectedValue), ctx); if (est != null) { estl.Estimate = est; } }
protected void LoadData(EstimateLine estl) { txtEstimateLineId.Text = estl.EstimateLineId.ToString(); txtDescription.Text = estl.Description; txtAmount.Value = (double)estl.Amount; txtDiscount.Text = String.Format("{0:0.00}",estl.Discount); txtTotal.Value = (double)(estl.Amount - estl.Discount); Insurance iSelect = estl.InsuranceService.Insurance; InsuranceService iServ = estl.InsuranceService; if (iSelect != null) { rdcbInsurance.SelectedValue = iSelect.InsuranceId.ToString(); } // if (iServ != null) { rdcInsuranceService.Items.Clear(); rdcInsuranceService.Items.Add(new RadComboBoxItem(iServ.Service.Name, iServ.InsuranceServiceId.ToString())); rdcInsuranceService.SelectedValue = iServ.InsuranceServiceId.ToString(); } }