/// <summary> /// Handles the SelectedIndexChanged event of the cboQualifications control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void cboQualifications_SelectedIndexChanged(object sender, EventArgs e) { ListItem item = cboQualifications.SelectedItem; if (item != null) { using (NHibernate.ISession session = new SessionScopeWrapper()) { ILead lead = GetCurrentLead(); if (lead != null) { IQualificationCategory currentCategory = lead.QualificationCategory; if (currentCategory != null) { IList <IQualification> qualifications = GetQualifications(currentCategory); if (qualifications != null) { IList <ILeadQualification> lead_qualifications = GetLeadQualifications(currentCategory, qualifications, lead); if (lead_qualifications != null) { if (lead_qualifications.Count > 0) { string confirmation = htxtConfirmation.Value; if (!string.IsNullOrEmpty(confirmation)) { const string cFalse = "false"; if (confirmation.ToLower() == cFalse) { cboQualifications.SelectedValue = currentCategory.Id.ToString(); return; } } foreach (ILeadQualification lead_qual in lead_qualifications) { lead_qual.Delete(); } lead_qualifications.Clear(); } } } } IQualificationCategory category = EntityFactory.GetById <IQualificationCategory>(item.Value); if (category != null) { lead.QualificationCategory = category; session.Update(lead); } } } } }
/// <summary> /// Gets the collection of Qualification entities for the QualificationCategory. /// </summary> /// <param name="qualificationCategory">The QualificationCategory</param> /// <returns></returns> protected static IList <IQualification> GetQualifications(IQualificationCategory qualificationCategory) { using (new SessionScopeWrapper()) { IRepository <IQualification> rep = EntityFactory.GetRepository <IQualification>(); IQueryable qry = (IQueryable)rep; IExpressionFactory ep = qry.GetExpressionFactory(); ICriteria crt = qry.CreateCriteria(); crt.Add(ep.Eq("QualificationCategory", qualificationCategory)); crt.AddOrder(ep.Asc("SortPosition")); IList <IQualification> list = crt.List <IQualification>(); return(list); } }
/// <summary> /// Gets a collection of LeadQualfication entities based on the parameters. /// </summary> /// <param name="qualificationCategory">The QualificationCategory.</param> /// <param name="qualifications">The Qualifications.</param> /// <param name="lead">The Lead.</param> /// <returns></returns> protected static IList <ILeadQualification> GetLeadQualifications(IQualificationCategory qualificationCategory, IList <IQualification> qualifications, ILead lead) { using (new SessionScopeWrapper()) { IRepository <ILeadQualification> rep = EntityFactory.GetRepository <ILeadQualification>(); IQueryable qry = (IQueryable)rep; IExpressionFactory ep = qry.GetExpressionFactory(); ICriteria crt = qry.CreateCriteria(); IJunction all = ep.Conjunction(); all.Add(ep.Eq("Lead", lead)); all.Add(ep.In("Qualification", (System.Collections.ICollection)qualifications)); crt.Add(all); IList <ILeadQualification> list = crt.List <ILeadQualification>(); return(list); } }
/// <summary> /// Gets the collection of Qualification entities for the QualificationCategory. /// </summary> /// <param name="qualificationCategory">The QualificationCategory</param> /// <returns></returns> protected static IList<IQualification> GetQualifications(IQualificationCategory qualificationCategory) { using (new SessionScopeWrapper()) { IRepository<IQualification> rep = EntityFactory.GetRepository<IQualification>(); IQueryable qry = (IQueryable)rep; IExpressionFactory ep = qry.GetExpressionFactory(); ICriteria crt = qry.CreateCriteria(); crt.Add(ep.Eq("QualificationCategory", qualificationCategory)); crt.AddOrder(ep.Asc("SortPosition")); IList<IQualification> list = crt.List<IQualification>(); return list; } }
/// <summary> /// Gets a collection of LeadQualfication entities based on the parameters. /// </summary> /// <param name="qualificationCategory">The QualificationCategory.</param> /// <param name="qualifications">The Qualifications.</param> /// <param name="lead">The Lead.</param> /// <returns></returns> protected static IList<ILeadQualification> GetLeadQualifications(IQualificationCategory qualificationCategory, IList<IQualification> qualifications, ILead lead) { using (new SessionScopeWrapper()) { IRepository<ILeadQualification> rep = EntityFactory.GetRepository<ILeadQualification>(); IQueryable qry = (IQueryable)rep; IExpressionFactory ep = qry.GetExpressionFactory(); ICriteria crt = qry.CreateCriteria(); IJunction all = ep.Conjunction(); all.Add(ep.Eq("Lead", lead)); all.Add(ep.In("Qualification", (System.Collections.ICollection)qualifications)); crt.Add(all); IList<ILeadQualification> list = crt.List<ILeadQualification>(); return list; } }
/// <summary> /// Loads the LeadQualification entities and displays the corresponding data for the current Lead. /// </summary> protected void LoadLeadQualifications() { ILead lead = GetCurrentLead(); IQualificationCategory currentCategory = null; if (lead != null) { currentCategory = lead.QualificationCategory; } if (currentCategory == null) { /* Set the list to the first category?...or the last selected category? */ ListItem selected_item = cboQualifications.SelectedItem; if (selected_item != null) { currentCategory = EntityFactory.GetById <IQualificationCategory>(selected_item.Value); } } else { ListItem item; item = cboQualifications.Items.FindByValue(currentCategory.Id.ToString()); if (item != null) { cboQualifications.SelectedValue = item.Value; } } ILeadQualification lead_qual; IList <IQualification> qualifications = GetQualifications(currentCategory); IList <ILeadQualification> lead_qualifications = GetLeadQualifications(currentCategory, qualifications, lead); string strChkStyle; string strTxtStyle; string strNotes; bool bChecked; bool bShowNotes; bool bVisible; string qualId; int sortPos; string desc; for (int i = 0; i < 8; i++) { if (i < qualifications.Count) { IQualification qual = qualifications[i]; bVisible = qual.Visible.HasValue ? qual.Visible.Value : false; if (bVisible) { lead_qual = FindLeadQualification(qual, lead_qualifications); bChecked = (lead_qual != null) ? (lead_qual.Checked.HasValue ? lead_qual.Checked.Value : false) : false; strNotes = (lead_qual != null) ? lead_qual.Notes : string.Empty; bShowNotes = qual.ShowNotes.HasValue ? qual.ShowNotes.Value : false; strChkStyle = (bVisible) ? string.Empty : cDisplayNone; strTxtStyle = (bShowNotes) ? string.Empty : cDisplayNone; qualId = qual.Id.ToString(); sortPos = qual.SortPosition.Value; desc = qual.Description; System.Web.UI.HtmlControls.HtmlTableRow container = (System.Web.UI.HtmlControls.HtmlTableRow) this.FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "table-row"; } else { System.Web.UI.HtmlControls.HtmlTableRow container = (System.Web.UI.HtmlControls.HtmlTableRow) this.FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "None"; continue; } } else { System.Web.UI.HtmlControls.HtmlTableRow container = (System.Web.UI.HtmlControls.HtmlTableRow) this.FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "None"; continue; } switch (sortPos) { case 1: chkQualificationSelected1.Style.Value = strChkStyle; chkQualificationSelected1.Checked = bChecked; chkQualificationSelected1_lz.Style.Value = strChkStyle; txtQualificationDescription1.Style.Value = strTxtStyle; txtQualificationDescription1.Text = strNotes; chkQualificationSelected1_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected1, txtQualificationDescription1, qualId); break; case 2: chkQualificationSelected2.Style.Value = strChkStyle; chkQualificationSelected2.Checked = bChecked; chkQualificationSelected2_lz.Style.Value = strChkStyle; txtQualificationDescription2.Style.Value = strTxtStyle; txtQualificationDescription2.Text = strNotes; chkQualificationSelected2_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected2, txtQualificationDescription2, qualId); break; case 3: chkQualificationSelected3.Style.Value = strChkStyle; chkQualificationSelected3.Checked = bChecked; chkQualificationSelected3_lz.Style.Value = strChkStyle; txtQualificationDescription3.Style.Value = strTxtStyle; txtQualificationDescription3.Text = strNotes; chkQualificationSelected3_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected3, txtQualificationDescription3, qualId); break; case 4: chkQualificationSelected4.Style.Value = strChkStyle; chkQualificationSelected4.Checked = bChecked; chkQualificationSelected4_lz.Style.Value = strChkStyle; txtQualificationDescription4.Style.Value = strTxtStyle; txtQualificationDescription4.Text = strNotes; chkQualificationSelected4_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected4, txtQualificationDescription4, qualId); break; case 5: chkQualificationSelected5.Style.Value = strChkStyle; chkQualificationSelected5.Checked = bChecked; chkQualificationSelected5_lz.Style.Value = strChkStyle; txtQualificationDescription5.Style.Value = strTxtStyle; txtQualificationDescription5.Text = strNotes; chkQualificationSelected5_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected5, txtQualificationDescription5, qualId); break; case 6: chkQualificationSelected6.Style.Value = strChkStyle; chkQualificationSelected6.Checked = bChecked; chkQualificationSelected6_lz.Style.Value = strChkStyle; txtQualificationDescription6.Style.Value = strTxtStyle; txtQualificationDescription6.Text = strNotes; chkQualificationSelected6_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected6, txtQualificationDescription6, qualId); break; case 7: chkQualificationSelected7.Style.Value = strChkStyle; chkQualificationSelected7.Checked = bChecked; chkQualificationSelected7_lz.Style.Value = strChkStyle; txtQualificationDescription7.Style.Value = strTxtStyle; txtQualificationDescription7.Text = strNotes; chkQualificationSelected7_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected7, txtQualificationDescription7, qualId); break; case 8: chkQualificationSelected8.Style.Value = strChkStyle; chkQualificationSelected8.Checked = bChecked; chkQualificationSelected8_lz.Style.Value = strChkStyle; txtQualificationDescription8.Style.Value = strTxtStyle; txtQualificationDescription8.Text = strNotes; chkQualificationSelected8_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected8, txtQualificationDescription8, qualId); break; default: System.Web.UI.HtmlControls.HtmlTableRow container = (System.Web.UI.HtmlControls.HtmlTableRow) this.FindControl("container" + i); container.Visible = false; break; } } }
/// <summary> /// Loads the LeadQualification entities and displays the corresponding data for the current Lead. /// </summary> protected void LoadLeadQualifications() { ILead lead = GetCurrentLead(); IQualificationCategory currentCategory = lead.QualificationCategory; IList <IQualification> qualifications = GetQualifications(currentCategory); IList <ILeadQualification> leadQualifications = GetLeadQualifications(currentCategory, qualifications, lead); for (int i = 0; i < 8; i++) { string strChkStyle; string strTxtStyle; string strNotes; bool bChecked; string qualId; int sortPos; string desc; if (i < qualifications.Count) { IQualification qual = qualifications[i]; bool bVisible = qual.Visible ?? false; if (bVisible) { ILeadQualification leadQual = FindLeadQualification(qual, leadQualifications); bChecked = (leadQual != null) && (leadQual.Checked ?? false); strNotes = (leadQual != null) ? leadQual.Notes : string.Empty; bool bShowNotes = qual.ShowNotes ?? false; strChkStyle = (bVisible) ? string.Empty : cDisplayNone; strTxtStyle = (bShowNotes) ? string.Empty : cDisplayNone; qualId = qual.Id.ToString(); sortPos = qual.SortPosition.Value; desc = qual.Description; HtmlTableRow container = (HtmlTableRow)FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "table-row"; } else { HtmlTableRow container = (HtmlTableRow)FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "None"; continue; } } else { HtmlTableRow container = (HtmlTableRow)FindControl("container" + (i + 1)); container.Style[HtmlTextWriterStyle.Display] = "None"; continue; } switch (sortPos) { case 1: chkQualificationSelected1.Style.Value = strChkStyle; chkQualificationSelected1.Checked = bChecked; chkQualificationSelected1_lz.Style.Value = strChkStyle; txtQualificationDescription1.Style.Value = strTxtStyle; txtQualificationDescription1.Text = strNotes; chkQualificationSelected1_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected1, txtQualificationDescription1, qualId); break; case 2: chkQualificationSelected2.Style.Value = strChkStyle; chkQualificationSelected2.Checked = bChecked; chkQualificationSelected2_lz.Style.Value = strChkStyle; txtQualificationDescription2.Style.Value = strTxtStyle; txtQualificationDescription2.Text = strNotes; chkQualificationSelected2_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected2, txtQualificationDescription2, qualId); break; case 3: chkQualificationSelected3.Style.Value = strChkStyle; chkQualificationSelected3.Checked = bChecked; chkQualificationSelected3_lz.Style.Value = strChkStyle; txtQualificationDescription3.Style.Value = strTxtStyle; txtQualificationDescription3.Text = strNotes; chkQualificationSelected3_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected3, txtQualificationDescription3, qualId); break; case 4: chkQualificationSelected4.Style.Value = strChkStyle; chkQualificationSelected4.Checked = bChecked; chkQualificationSelected4_lz.Style.Value = strChkStyle; txtQualificationDescription4.Style.Value = strTxtStyle; txtQualificationDescription4.Text = strNotes; chkQualificationSelected4_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected4, txtQualificationDescription4, qualId); break; case 5: chkQualificationSelected5.Style.Value = strChkStyle; chkQualificationSelected5.Checked = bChecked; chkQualificationSelected5_lz.Style.Value = strChkStyle; txtQualificationDescription5.Style.Value = strTxtStyle; txtQualificationDescription5.Text = strNotes; chkQualificationSelected5_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected5, txtQualificationDescription5, qualId); break; case 6: chkQualificationSelected6.Style.Value = strChkStyle; chkQualificationSelected6.Checked = bChecked; chkQualificationSelected6_lz.Style.Value = strChkStyle; txtQualificationDescription6.Style.Value = strTxtStyle; txtQualificationDescription6.Text = strNotes; chkQualificationSelected6_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected6, txtQualificationDescription6, qualId); break; case 7: chkQualificationSelected7.Style.Value = strChkStyle; chkQualificationSelected7.Checked = bChecked; chkQualificationSelected7_lz.Style.Value = strChkStyle; txtQualificationDescription7.Style.Value = strTxtStyle; txtQualificationDescription7.Text = strNotes; chkQualificationSelected7_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected7, txtQualificationDescription7, qualId); break; case 8: chkQualificationSelected8.Style.Value = strChkStyle; chkQualificationSelected8.Checked = bChecked; chkQualificationSelected8_lz.Style.Value = strChkStyle; txtQualificationDescription8.Style.Value = strTxtStyle; txtQualificationDescription8.Text = strNotes; chkQualificationSelected8_lz.Text = desc; AddQualficationIdAttributeTo(chkQualificationSelected8, txtQualificationDescription8, qualId); break; default: HtmlTableRow container = (HtmlTableRow)FindControl("container" + i); container.Visible = false; break; } } }