コード例 #1
0
 /// <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");
     }
 }
コード例 #2
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);
    }
コード例 #3
0
    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);
    }
コード例 #4
0
    /// <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();
    }
コード例 #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);
    }
コード例 #6
0
 /// <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);
     }
 }
コード例 #7
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);
    }
コード例 #8
0
    /// <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);
    }
コード例 #9
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);
        }
コード例 #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);
    }
コード例 #11
0
    /// <summary>
    /// Gets the contact targets via a join through Account.
    /// </summary>
    /// <returns></returns>
    private IList GetAccountTargets()
    {
        IList contactList;

        try
        {
            IQueryable         query       = (IQueryable)EntityFactory.GetRepository <IContact>();
            IExpressionFactory expressions = query.GetExpressionFactory();
            IProjections       projections = query.GetProjectionsFactory();
            ICriteria          criteria    = query.CreateCriteria("a1")
                                             .CreateCriteria("Account", "account")
                                             .CreateCriteria("Addresses", "address")
                                             .SetProjection(projections.ProjectionList()
                                                            .Add(projections.Distinct(projections.Property("Id")))
                                                            .Add(projections.Property("FirstName"))
                                                            .Add(projections.Property("LastName"))
                                                            .Add(projections.Property("AccountName"))
                                                            .Add(projections.Property("Email"))
                                                            .Add(projections.Property("address.City"))
                                                            .Add(projections.Property("address.State"))
                                                            .Add(projections.Property("address.PostalCode"))
                                                            .Add(projections.Property("WorkPhone")));
            AddExpressionsCriteria(criteria, expressions);
            contactList = criteria.List();
        }
        catch (QueryException nex)
        {
            log.Error("The call to ManageTargets.GetAccountTargets() failed", nex);
            string message = GetLocalResourceObject("QueryError").ToString();
            if (nex.Message.Contains("could not resolve property"))
            {
                message += "  " + GetLocalResourceObject("QueryErrorInvalidParameter");
            }

            throw new ValidationException(message);
        }
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(contactList);
    }
コード例 #12
0
    /// <summary>
    /// Gets a list of the Lead targets.
    /// </summary>
    /// <returns></returns>
    private IList GetLeadTargets()
    {
        IQueryable         query       = (IQueryable)EntityFactory.GetRepository <ILead>();
        IExpressionFactory expressions = query.GetExpressionFactory();
        IProjections       projections = query.GetProjectionsFactory();
        ICriteria          criteria    = query.CreateCriteria("a1")
                                         .CreateCriteria("Addresses", "address")
                                         .SetProjection(projections.ProjectionList()
                                                        .Add(projections.Distinct(projections.Property("Id")))
                                                        .Add(projections.Property("FirstName"))
                                                        .Add(projections.Property("LastName"))
                                                        .Add(projections.Property("Company"))
                                                        .Add(projections.Property("Email"))
                                                        .Add(projections.Property("address.City"))
                                                        .Add(projections.Property("address.State"))
                                                        .Add(projections.Property("address.PostalCode"))
                                                        .Add(projections.Property("WorkPhone")));

        AddExpressionsCriteria(criteria, expressions);
        // NOTE: The generic exception handler was removed since the exception was rethrown; this exception would be logged twice otherwise.
        // We may want to throw a UserObservableApplicationException in the future.
        return(criteria.List());
    }
コード例 #13
0
    /// <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;
        }
    }
コード例 #14
0
    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;
        }
    }
コード例 #15
0
    /// <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)));
            }
        }
    }
コード例 #16
0
    /// <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)));
                }
            }
        }
    }
コード例 #17
0
 /// <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);
     }
 }