Exemple #1
0
    private IList <IImportHistoryItem> GetHistoryItems(IImportHistory importHistory, string itemType, string sortField, bool ascending)
    {
        IList <IImportHistoryItem>       items    = null;
        IRepository <IImportHistoryItem> repItems = EntityFactory.GetRepository <IImportHistoryItem>();
        IQueryable         qryItems = (IQueryable)repItems;
        IExpressionFactory expItems = qryItems.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria critItems = qryItems.CreateCriteria();
        critItems.Add(expItems.Eq("ImportHistoryId", importHistory.Id));
        if (!string.IsNullOrEmpty(itemType))
        {
            critItems.Add(expItems.Eq("ItemType", itemType));
        }
        if (!String.IsNullOrEmpty(sortField))
        {
            if (ascending)
            {
                critItems.AddOrder(expItems.Asc(sortField));
            }
            else
            {
                critItems.AddOrder(expItems.Desc(sortField));
            }
        }

        items = critItems.List <IImportHistoryItem>();
        return(items);
    }
    private Sage.Entity.Interfaces.IContact GetPrimaryContactFor(Sage.Entity.Interfaces.IAccount account)
    {
        Object result;
        IRepository <Sage.Entity.Interfaces.IContact> rep = Sage.Platform.EntityFactory.GetRepository <Sage.Entity.Interfaces.IContact>();
        IQueryable         qry = (IQueryable)rep;
        IExpressionFactory ep  = qry.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
        crit.Add(ep.Eq("Account", account));
        crit.Add(ep.Eq("IsPrimary", true));
        result = crit.UniqueResult <Sage.Entity.Interfaces.IContact>();
        return((result != null) ? (Sage.Entity.Interfaces.IContact)result : null);
    }
 /// <summary>
 /// Aborts the import.
 /// </summary>
 /// <param name="importHistory">The import history.</param>
 private void AbortImport(IImportHistory importHistory)
 {
     try
     {
         IRepository <IImportHistory> rep        = EntityFactory.GetRepository <IImportHistory>();
         IQueryable         qry                  = (IQueryable)rep;
         IExpressionFactory ep                   = qry.GetExpressionFactory();
         Sage.Platform.Repository.ICriteria crit = qry.CreateCriteria();
         crit.Add(ep.Eq("Id", importHistory.Id));
         IProjections projections = qry.GetProjectionsFactory();
         crit.SetProjection(projections.Property("ProcessState"));
         object state = crit.UniqueResult();
         if (state != null)
         {
             ImportProcessState processState = (ImportProcessState)Enum.Parse(typeof(ImportProcessState), state.ToString());
             if (!processState.Equals(ImportProcessState.Completed) || !processState.Equals(ImportProcessState.Abort))
             {
                 SetProcessState(importHistory.Id.ToString(), Enum.GetName(typeof(ImportProcessState), ImportProcessState.Abort), "Aborted");
             }
         }
     }
     catch (Exception)
     {
         //throw new ApplicationException("Error getting process state");
     }
 }
Exemple #4
0
    /// <summary>
    /// Gets the product list.
    /// </summary>
    /// <returns></returns>
    public object GetProductList()
    {
        IRepository <Product> productRep     = EntityFactory.GetRepository <Product>();
        IQueryable            qryableProduct = (IQueryable)productRep;
        IExpressionFactory    expProduct     = qryableProduct.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria criteriaProduct = qryableProduct.CreateCriteria();

        if (_State.NameFilter != string.Empty)
        {
            SearchParameter enumCondition = (SearchParameter)_State.NameCond;
            criteriaProduct.Add(GetExpression(expProduct, enumCondition, "Name", _State.NameFilter));
        }

        if (_State.DescFilter != string.Empty)
        {
            SearchParameter enumCondition = (SearchParameter)_State.DescCond;
            criteriaProduct.Add(GetExpression(expProduct, enumCondition, "Description", _State.DescFilter));
        }

        if (_State.SKUFilter != string.Empty)
        {
            SearchParameter enumCondition = (SearchParameter)_State.SKUCond;
            criteriaProduct.Add(GetExpression(expProduct, enumCondition, "ActualId", _State.SKUFilter));
        }

        if (_State.FamilyFilter != string.Empty)
        {
            SearchParameter enumCondition = SearchParameter.EqualTo;
            criteriaProduct.Add(GetExpression(expProduct, enumCondition, "Family", _State.FamilyFilter));
        }

        if (_State.StatusFilter != string.Empty)
        {
            SearchParameter enumCondition = SearchParameter.EqualTo;
            criteriaProduct.Add(GetExpression(expProduct, enumCondition, "Status", _State.StatusFilter));
        }

        if (chkPackage.Checked)
        {
        }

        List <Product> ProductList = criteriaProduct.List <Product>() as List <Product>;

        return(ProductList);
    }
Exemple #5
0
    private IList <IOpportunity> GetResellerOppList(IAccount account)
    {
        IList <IOpportunity> list = null;

        using (new SessionScopeWrapper())
        {
            IRepository <IOpportunity> rep         = EntityFactory.GetRepository <IOpportunity>();
            IQueryable         qry                 = (IQueryable)rep;
            IExpressionFactory ep                  = qry.GetExpressionFactory();
            Sage.Platform.Repository.ICriteria crt = qry.CreateCriteria();
            crt.Add(ep.Eq("Reseller", account));
            list = crt.List <IOpportunity>();
        }
        return(list);
    }
 /// <summary>
 /// Adds the comma delimited strings to the expression factory.
 /// </summary>
 /// <param name="criteria">The criteria.</param>
 /// <param name="expressions">The expressions.</param>
 /// <param name="text">The text.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="clause">The clause.</param>
 private static void AddCommaDelimitedStringsToExpression(ICriteria criteria, IExpressionFactory expressions, String text,
                                                          String propertyName, SearchParameter clause)
 {
     if (!string.IsNullOrEmpty(text))
     {
         string[]            values     = text.Split(',');
         IList <IExpression> expression = values.Select(value => GetExpression(expressions, clause, propertyName, value)).ToList();
         IJunction           junction   = expressions.Disjunction();
         foreach (IExpression e in expression)
         {
             junction.Add(e);
         }
         criteria.Add(junction);
     }
 }
    /// <summary>
    /// Loads the product grid.
    /// </summary>
    protected void LoadProductGrid()
    {
        SearchParameter           enumValue  = (SearchParameter)ddlFilterBy.SelectedIndex;
        IRepository <ILeadSource> leadSource = EntityFactory.GetRepository <ILeadSource>();
        IQueryable         query             = (IQueryable)leadSource;
        IExpressionFactory exp      = query.GetExpressionFactory();
        ICriteria          criteria = query.CreateCriteria();

        criteria.Add(GetExpression(exp, enumValue, GetEntityPropertyValue(), txtLookupValue.Text));

        IList list = criteria.List();

        grdCampaignLeadSource.DataSource = list;
        grdCampaignLeadSource.DataBind();
    }
Exemple #8
0
        public static IActivity getNextActivity(string oppid)
        {
            IRepository <IActivity> actRep = EntityFactory.GetRepository <IActivity>();
            IQueryable         qryableAct  = (IQueryable)actRep;
            IExpressionFactory expAct      = qryableAct.GetExpressionFactory();

            Sage.Platform.Repository.ICriteria critAct = qryableAct.CreateCriteria();

            IList <IActivity> ActivityList = critAct.Add(
                expAct.Eq("OpportunityId", oppid))
                                             .AddOrder(expAct.Asc("StartDate"))
                                             .List <IActivity>();

            if ((ActivityList != null) && (ActivityList.Count > 0))
            {
                return(ActivityList[0]);
            }
            return(null);
        }
    /// <summary>
    /// Shows the sales process info.
    /// </summary>
    /// <param name="opportunity">The opportunity.</param>
    /// <returns></returns>
    private bool ShowSalesProcessInfo(IOpportunity opportunity)
    {
        bool result = false;

        if (GetOpportunityStatusMatch(opportunity, "Open") ||
            GetOpportunityStatusMatch(opportunity, "Inactive"))
        {
            IRepository <ISalesProcesses> rep = EntityFactory.GetRepository <ISalesProcesses>();
            IQueryable         qry            = (IQueryable)rep;
            IExpressionFactory ep             = qry.GetExpressionFactory();
            ICriteria          crit           = qry.CreateCriteria();
            crit.Add(ep.Eq("EntityId", opportunity.Id.ToString()));
            IProjection proj = qry.GetProjectionsFactory().Count("Id");
            crit.SetProjection(proj);
            int count = (int)crit.UniqueResult();
            result = (count > 0);
        }
        return(result);
    }
Exemple #10
0
    /// <summary>
    /// Gets the package list.
    /// </summary>
    /// <returns></returns>
    private object GetPackageList()
    {
        IRepository <Package> PackageRep     = EntityFactory.GetRepository <Package>();
        IQueryable            qryablePackage = (IQueryable)PackageRep;
        IExpressionFactory    expPackage     = qryablePackage.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria criteriaPackage = qryablePackage.CreateCriteria();

        if (_State.NameFilter != string.Empty)
        {
            SearchParameter enumCondition = (SearchParameter)_State.NameCond;
            criteriaPackage.Add(GetExpression(expPackage, enumCondition, "Name", _State.NameFilter));
        }

        //_criteriaPackage.SetFetchMode("PackageProducts", Sage.Platform.Repository.FetchMode.Join);

        List <Package> PackageList = criteriaPackage.List <Package>() as List <Package>;

        return(PackageList);
    }
    /// <summary>
    /// Loads the product grid.
    /// </summary>
    protected void LoadProductGrid()
    {
        try
        {
            if (EntityContext != null && EntityContext.EntityType == typeof(ICampaign))
            {
                SearchParameter           enumValue  = (SearchParameter)ddlFilterBy.SelectedIndex;
                IRepository <ILeadSource> leadSource = EntityFactory.GetRepository <ILeadSource>();
                IQueryable         query             = (IQueryable)leadSource;
                IExpressionFactory exp      = query.GetExpressionFactory();
                ICriteria          criteria = query.CreateCriteria();
                criteria.Add(GetExpression(exp, enumValue, GetEntityPropertyValue(), txtLookupValue.Text));

                IList list = criteria.List();
                grdCampaignLeadSource.DataSource = list;
                grdCampaignLeadSource.DataBind();
            }
        }
        catch (Exception ex)
        {
            log.Error(ex.Message);
            throw;
        }
    }
    protected override void  OnFormBound()
    {
        base.OnFormBound();

        bool bFoundActivityPhoneCall   = false;
        bool bFoundActivityAppointment = false;
        bool bFoundActivityToDo        = false;

        bool bFoundHistoryPhoneCall   = false;
        bool bFoundHistoryAppointment = false;
        bool bFoundHistoryToDo        = false;
        bool bFoundHistoryLetter      = false;
        bool bFoundHistoryEmail       = false;
        bool bFoundHistoryFax         = false;

        NextCallDate.Text      = string.Empty;
        NextCallUser.Text      = string.Empty;
        NextCallRegarding.Text = string.Empty;

        NextMeetDate.Text      = string.Empty;
        NextMeetUser.Text      = string.Empty;
        NextMeetRegarding.Text = string.Empty;

        NextToDoDate.Text      = string.Empty;
        NextToDoUser.Text      = string.Empty;
        NextToDoRegarding.Text = string.Empty;

        LastCallDate.Text      = string.Empty;
        LastCallUser.Text      = string.Empty;
        LastCallRegarding.Text = string.Empty;

        LastMeetDate.Text      = string.Empty;
        LastMeetUser.Text      = string.Empty;
        LastMeetRegarding.Text = string.Empty;

        LastToDoDate.Text      = string.Empty;
        LastToDoUser.Text      = string.Empty;
        LastToDoRegarding.Text = string.Empty;

        LastLetterDate.Text      = string.Empty;
        LastLetterUser.Text      = string.Empty;
        LastLetterRegarding.Text = string.Empty;

        LastEmailDate.Text      = string.Empty;
        LastEmailUser.Text      = string.Empty;
        LastEmailRegarding.Text = string.Empty;

        LastFaxDate.Text      = string.Empty;
        LastFaxUser.Text      = string.Empty;
        LastFaxRegarding.Text = string.Empty;

        LastUpdateDate.Text = string.Empty;
        LastUpdateUser.Text = string.Empty;

        var opportunity = (IOpportunity)BindingSource.Current;
        var entityId    = opportunity.Id.ToString();

        IRepository <Activity> actRep     = EntityFactory.GetRepository <Activity>();
        IQueryable             qryableAct = (IQueryable)actRep;
        IExpressionFactory     expAct     = qryableAct.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria critAct = qryableAct.CreateCriteria();

        var activityList = critAct.Add(
            expAct.Eq("OpportunityId", entityId))
                           .AddOrder(expAct.Asc("StartDate"))
                           .List <Activity>();

        if (activityList != null)
        {
            foreach (Activity oppActivity in activityList)
            {
                switch (oppActivity.Type)
                {
                case ActivityType.atPhoneCall:
                    if (!bFoundActivityPhoneCall)
                    {
                        NextCallDate.Text       = oppActivity.StartDate.ToShortDateString();
                        NextCallUser.Text       = Sage.SalesLogix.Security.User.GetById(oppActivity.UserId).UserInfo.UserName;
                        NextCallRegarding.Text  = oppActivity.Description;
                        bFoundActivityPhoneCall = true;
                    }
                    break;

                case ActivityType.atAppointment:
                    if (!bFoundActivityAppointment)
                    {
                        NextMeetDate.Text         = oppActivity.StartDate.ToShortDateString();
                        NextMeetUser.Text         = Sage.SalesLogix.Security.User.GetById(oppActivity.UserId).UserInfo.UserName;
                        NextMeetRegarding.Text    = oppActivity.Description;
                        bFoundActivityAppointment = true;
                    }
                    break;

                case ActivityType.atToDo:
                    if (!bFoundActivityToDo)
                    {
                        NextToDoDate.Text      = oppActivity.StartDate.ToShortDateString();
                        NextToDoUser.Text      = Sage.SalesLogix.Security.User.GetById(oppActivity.UserId).UserInfo.UserName;
                        NextToDoRegarding.Text = oppActivity.Description;
                        bFoundActivityToDo     = true;
                    }
                    break;
                }
            }
        }

        IRepository <History> hisRep     = EntityFactory.GetRepository <History>();
        IQueryable            qryableHis = (IQueryable)hisRep;
        IExpressionFactory    expHis     = qryableHis.GetExpressionFactory();

        Sage.Platform.Repository.ICriteria critHis = qryableHis.CreateCriteria();

        var historyList = critHis.Add(
            expHis.Eq("OpportunityId", entityId))
                          .AddOrder(expHis.Desc("CompletedDate"))
                          .List <History>();

        if (historyList != null)
        {
            foreach (History oppHistory in historyList)
            {
                switch (oppHistory.Type)
                {
                case HistoryType.atPhoneCall:
                    if (!bFoundHistoryPhoneCall)
                    {
                        LastCallDate.Text      = oppHistory.CompletedDate.ToShortDateString();
                        LastCallUser.Text      = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastCallRegarding.Text = oppHistory.Description;
                        bFoundHistoryPhoneCall = true;
                    }
                    break;

                case HistoryType.atAppointment:
                    if (!bFoundHistoryAppointment)
                    {
                        LastMeetDate.Text        = oppHistory.CompletedDate.ToShortDateString();
                        LastMeetUser.Text        = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastMeetRegarding.Text   = oppHistory.Description;
                        bFoundHistoryAppointment = true;
                    }
                    break;

                case HistoryType.atToDo:
                    if (!bFoundHistoryToDo)
                    {
                        LastToDoDate.Text      = oppHistory.CompletedDate.ToShortDateString();
                        LastToDoUser.Text      = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastToDoRegarding.Text = oppHistory.Description;
                        bFoundHistoryToDo      = true;
                    }
                    break;

                case HistoryType.atLiterature:
                    if (!bFoundHistoryLetter)
                    {
                        LastLetterDate.Text      = oppHistory.CompletedDate.ToShortDateString();
                        LastLetterUser.Text      = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastLetterRegarding.Text = oppHistory.Description;
                        bFoundHistoryLetter      = true;
                    }
                    break;

                case HistoryType.atEMail:
                    if (!bFoundHistoryEmail)
                    {
                        LastEmailDate.Text      = oppHistory.CompletedDate.ToShortDateString();
                        LastEmailUser.Text      = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastEmailRegarding.Text = oppHistory.Description;
                        bFoundHistoryEmail      = true;
                    }
                    break;

                case HistoryType.atFax:
                    if (!bFoundHistoryFax)
                    {
                        LastFaxDate.Text      = oppHistory.CompletedDate.ToShortDateString();
                        LastFaxUser.Text      = Sage.SalesLogix.Security.User.GetById(oppHistory.UserId).UserInfo.UserName;
                        LastFaxRegarding.Text = oppHistory.Description;
                        bFoundHistoryFax      = true;
                    }
                    break;
                }
            }
        }

        DateTime md = new DateTime();

        if (opportunity.ModifyDate.HasValue)
        {
            md = Convert.ToDateTime(opportunity.ModifyDate);
            LastUpdateDate.Text = md.ToShortDateString();
        }

        IUser user = EntityFactory.GetById <IUser>(opportunity.ModifyUser);

        if (user != null)
        {
            LastUpdateUser.Text = user.UserInfo.UserName;
        }
    }
    /// <summary>
    /// Adds the expressions criteria.
    /// </summary>
    /// <param name="criteria">The criteria.</param>
    /// <param name="expressions">The expressions.</param>
    /// <returns></returns>
    private void AddExpressionsCriteria(ICriteria criteria, IExpressionFactory expressions)
    {
        if (criteria != null)
        {
            SearchParameter clause;
            Boolean         isLeads          = (rdgIncludeType.SelectedIndex == 0);
            Boolean         isPrimaryContact = (rdgIncludeType.SelectedIndex == 1);
            Boolean         isIndividual     = (rdgIncludeType.SelectedIndex == 3);

            criteria.Add(expressions.Eq("address.IsPrimary", true));
            if (isPrimaryContact)
            {
                criteria.Add(expressions.Eq("a1.IsPrimary", true));
            }
            if (chkCompany.Checked)
            {
                clause = (SearchParameter)lbxCompany.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.Company", txtCompany.Text)
                                 : GetExpression(expressions, clause, "account.AccountName", txtCompany.Text));
            }
            if (chkIndustry.Checked)
            {
                clause = (SearchParameter)lbxIndustry.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.Industry", pklIndustry.PickListValue)
                                 : GetExpression(expressions, clause, "account.Industry", pklIndustry.PickListValue));
            }
            if (chkSIC.Checked)
            {
                clause = (SearchParameter)lbxSIC.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.SICCode", txtSIC.Text)
                                 : GetExpression(expressions, clause, "account.SicCode", txtSIC.Text));
            }
            if (chkTitle.Checked)
            {
                clause = (SearchParameter)lbxTitle.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "a1.Title", pklTitle.PickListValue));
            }
            if (chkProducts.Checked && !isLeads)
            {
                criteria.CreateCriteria("account.AccountProducts", "product");
                clause = (SearchParameter)lbxProducts.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "product.ProductName", lueProducts.Text));
            }
            if (chkStatus.Checked)
            {
                clause = (SearchParameter)lbxStatus.SelectedIndex;
                if (isLeads || isIndividual)
                {
                    criteria.Add(GetExpression(expressions, clause, "a1.Status", pklStatus.PickListValue));
                }
                else
                {
                    criteria.Add(GetExpression(expressions, clause, "account.Status", pklStatus.PickListValue));
                }
            }
            if (!chkSolicit.Checked)
            {
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotSolicit", false), expressions.IsNull("a1.DoNotSolicit")));
            }
            if (!chkEmail.Checked)
            {
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotEmail", false), expressions.IsNull("a1.DoNotEmail")));
            }
            if (!chkCall.Checked)
            {
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotPhone", false), expressions.IsNull("a1.DoNotPhone")));
            }
            if (!chkMail.Checked)
            {
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotMail", false), expressions.IsNull("a1.DoNotMail")));
            }
            if (!chkFax.Checked)
            {
                criteria.Add(isLeads
                                 ? expressions.Or(expressions.Eq("a1.DoNotFAX", false),
                                                  expressions.IsNull("a1.DoNotFAX"))
                                 : expressions.Or(expressions.Eq("a1.DoNotFax", false),
                                                  expressions.IsNull("a1.DoNotFax")));
            }
            if (chkCity.Checked)
            {
                clause = (SearchParameter)lbxCity.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtCity.Text, "address.City", clause);
            }
            if (chkState.Checked)
            {
                clause = (SearchParameter)lbxState.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtState.Text, "address.State", clause);
            }
            if (chkZip.Checked)
            {
                clause = (SearchParameter)lbxZip.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtZip.Text, "address.PostalCode", clause);
            }
            if (chkLeadSource.Checked && rdgIncludeType.SelectedIndex != 3)
            {
                switch (rdgIncludeType.SelectedIndex)
                {
                case 0:
                    criteria.CreateCriteria("a1.LeadSource", "leadsource");
                    break;

                case 3:
                    criteria.CreateCriteria("a1.LeadSources", "leadsource");
                    break;

                default:
                    criteria.CreateCriteria("account.LeadSource", "leadsource");
                    break;
                }
                clause = (SearchParameter)lbxLeadSource.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "leadsource.Description", lueLeadSource.Text));
            }
            if (chkImportSource.Checked)
            {
                clause = (SearchParameter)lbxImportSource.SelectedIndex;
                if (isLeads || isIndividual)
                {
                    criteria.Add(GetExpression(expressions, clause, "a1.ImportSource", pklImportSource.PickListValue));
                }
                else
                {
                    criteria.Add(GetExpression(expressions, clause, "account.ImportSource", pklImportSource.PickListValue));
                }
            }
            if (!string.IsNullOrEmpty(dtpCreateFromDate.Text))
            {
                if (chkCreateDate.Checked && (isLeads || isIndividual))
                {
                    criteria.Add(expressions.Between("a1.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
                }
                else if (chkCreateDate.Checked)
                {
                    criteria.Add(expressions.Between("account.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
                }
            }
        }
    }
    /// <summary>
    /// Adds the expressions criteria.
    /// </summary>
    /// <param name="criteria">The criteria.</param>
    /// <param name="expressions">The expressions.</param>
    /// <returns></returns>
    private void AddExpressionsCriteria(ICriteria criteria, IExpressionFactory expressions)
    {
        if (criteria != null)
        {
            SearchParameter clause;
            Boolean isLeads = (rdgIncludeType.SelectedIndex == 0);
            Boolean isPrimaryContact = (rdgIncludeType.SelectedIndex == 1);
            Boolean isIndividual = (rdgIncludeType.SelectedIndex == 3);

            criteria.Add(expressions.Eq("address.IsPrimary", true));
            if (isPrimaryContact)
            {
                criteria.Add(expressions.Eq("a1.IsPrimary", true));
            }
            if (chkCompany.Checked)
            {
                clause = (SearchParameter)lbxCompany.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.Company", txtCompany.Text)
                                 : GetExpression(expressions, clause, "account.AccountName", txtCompany.Text));
            }
            if (chkIndustry.Checked)
            {
                clause = (SearchParameter)lbxIndustry.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.Industry", pklIndustry.PickListValue)
                                 : GetExpression(expressions, clause, "account.Industry", pklIndustry.PickListValue));
            }
            if (chkSIC.Checked)
            {
                clause = (SearchParameter)lbxSIC.SelectedIndex;
                criteria.Add(isLeads
                                 ? GetExpression(expressions, clause, "a1.SICCode", txtSIC.Text)
                                 : GetExpression(expressions, clause, "account.SicCode", txtSIC.Text));
            }
            if (chkTitle.Checked)
            {
                clause = (SearchParameter)lbxTitle.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "a1.Title", pklTitle.PickListValue));
            }
            if (chkProducts.Checked && !isLeads)
            {
                criteria.CreateCriteria("account.AccountProducts", "product");
                clause = (SearchParameter)lbxProducts.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "product.ProductName", lueProducts.Text));
            }
            if (chkStatus.Checked)
            {
                clause = (SearchParameter)lbxStatus.SelectedIndex;
                if (isLeads || isIndividual)
                    criteria.Add(GetExpression(expressions, clause, "a1.Status", pklStatus.PickListValue));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.Status", pklStatus.PickListValue));
            }
            if (!chkSolicit.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotSolicit", false), expressions.IsNull("a1.DoNotSolicit")));
            if (!chkEmail.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotEmail", false), expressions.IsNull("a1.DoNotEmail")));
            if (!chkCall.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotPhone", false), expressions.IsNull("a1.DoNotPhone")));
            if (!chkMail.Checked)
                criteria.Add(expressions.Or(expressions.Eq("a1.DoNotMail", false), expressions.IsNull("a1.DoNotMail")));
            if (!chkFax.Checked)
            {
                criteria.Add(isLeads
                                 ? expressions.Or(expressions.Eq("a1.DoNotFAX", false),
                                                  expressions.IsNull("a1.DoNotFAX"))
                                 : expressions.Or(expressions.Eq("a1.DoNotFax", false),
                                                  expressions.IsNull("a1.DoNotFax")));
            }
            if (chkCity.Checked)
            {
                clause = (SearchParameter)lbxCity.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtCity.Text, "address.City", clause);
            }
            if (chkState.Checked)
            {
                clause = (SearchParameter)lbxState.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtState.Text, "address.State", clause);
            }
            if (chkZip.Checked)
            {
                clause = (SearchParameter)lbxZip.SelectedIndex;
                AddCommaDelimitedStringsToExpression(criteria, expressions, txtZip.Text, "address.PostalCode", clause);
            }
            if (chkLeadSource.Checked && rdgIncludeType.SelectedIndex != 3)
            {
                switch (rdgIncludeType.SelectedIndex)
                {
                    case 0:
                        criteria.CreateCriteria("a1.LeadSource", "leadsource");
                        break;
                    case 3:
                        criteria.CreateCriteria("a1.LeadSources", "leadsource");
                        break;
                    default:
                        criteria.CreateCriteria("account.LeadSource", "leadsource");
                        break;
                }
                clause = (SearchParameter)lbxLeadSource.SelectedIndex;
                criteria.Add(GetExpression(expressions, clause, "leadsource.Description", lueLeadSource.Text));
            }
            if (chkImportSource.Checked)
            {
                clause = (SearchParameter)lbxImportSource.SelectedIndex;
                if (isLeads || isIndividual)
                    criteria.Add(GetExpression(expressions, clause, "a1.ImportSource", pklImportSource.PickListValue));
                else
                    criteria.Add(GetExpression(expressions, clause, "account.ImportSource", pklImportSource.PickListValue));
            }
            if (!string.IsNullOrEmpty(dtpCreateFromDate.Text))
            {
                if (chkCreateDate.Checked && (isLeads || isIndividual))
                    criteria.Add(expressions.Between("a1.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
                else if (chkCreateDate.Checked)
                    criteria.Add(expressions.Between("account.CreateDate", CheckForNullDate(dtpCreateFromDate.DateTimeValue), CheckForNullDate(dtpCreateToDate.DateTimeValue)));
            }
        }
    }
 /// <summary>
 /// Adds the comma delimited strings to the expression factory.
 /// </summary>
 /// <param name="criteria">The criteria.</param>
 /// <param name="expressions">The expressions.</param>
 /// <param name="text">The text.</param>
 /// <param name="propertyName">Name of the property.</param>
 /// <param name="clause">The clause.</param>
 private static void AddCommaDelimitedStringsToExpression(ICriteria criteria, IExpressionFactory expressions, String text,
     String propertyName, SearchParameter clause)
 {
     if (!string.IsNullOrEmpty(text))
     {
         string[] values = text.Split(',');
         IList<IExpression> expression = values.Select(value => GetExpression(expressions, clause, propertyName, value)).ToList();
         IJunction junction = expressions.Disjunction();
         foreach (IExpression e in expression)
         {
             junction.Add(e);
         }
         criteria.Add(junction);
     }
 }