Esempio n. 1
0
 public SearchDao(DbContextManager <CrmDbContext> dbContextManager,
                  TenantManager tenantManager,
                  DaoFactory daoFactory,
                  SecurityContext securityContext,
                  CrmSecurity crmSecurity,
                  TenantUtil tenantUtil,
                  PathProvider pathProvider,
                  FactoryIndexerTask tasksDtoIndexer,
                  FactoryIndexerInvoice invoicesDtoIndexer,
                  IOptionsMonitor <ILog> logger,
                  ICache ascCache,
                  WebImageSupplier webImageSupplier,
                  BundleSearch bundleSearch,
                  IMapper mapper
                  ) :
     base(dbContextManager,
          tenantManager,
          securityContext,
          logger,
          ascCache,
          mapper)
 {
     _daoFactory            = daoFactory;
     _factoryIndexerTask    = tasksDtoIndexer;
     _factoryIndexerInvoice = invoicesDtoIndexer;
     _crmSecurity           = crmSecurity;
     _tenantUtil            = tenantUtil;
     _pathProvider          = pathProvider;
     _webImageSupplier      = webImageSupplier;
     _bundleSearch          = bundleSearch;
 }
Esempio n. 2
0
 public DealDao(DbContextManager <CrmDbContext> dbContextManager,
                TenantManager tenantManager,
                SecurityContext securityContext,
                CrmSecurity crmSecurity,
                FactoryIndexerDeal factoryIndexer,
                FilesIntegration filesIntegration,
                TenantUtil tenantUtil,
                AuthorizationManager authorizationManager,
                IOptionsMonitor <ILog> logger,
                ICache ascCache,
                IMapper mapper,
                BundleSearch bundleSearch) :
     base(dbContextManager,
          tenantManager,
          securityContext,
          logger,
          ascCache,
          mapper)
 {
     _crmSecurity          = crmSecurity;
     _factoryIndexer       = factoryIndexer;
     _filesIntegration     = filesIntegration;
     _bundleSearch         = bundleSearch;
     _mapper               = mapper;
     _tenantUtil           = tenantUtil;
     _authorizationManager = authorizationManager;
 }
        public MainForm(Postgres postgres, OracleDB oracle)
        {
            this.postgres = postgres;
            this.oracle   = oracle;
            lookup        = new LookUp(postgres, oracle);

            InitializeComponent();

            if (Properties.Settings.Default.LOAD_KITS_ON_START)
            {
                LoadEFCKitNumbers();
            }

            LoosePieceSearch lps = new LoosePieceSearch(postgres, oracle, lookup);
            BundleSearch     bs  = new BundleSearch(postgres, oracle, lookup);

            lps.Dock = DockStyle.Fill;
            bs.Dock  = DockStyle.Fill;

            mainForTabControl.TabPages[0].Controls.Add(bs);
            mainForTabControl.TabPages[1].Controls.Add(lps);
        }
Esempio n. 4
0
        private Exp WhereConditional(
            ICollection <int> exceptIDs,
            String searchText,
            Guid responsibleID,
            int milestoneID,
            IEnumerable <String> tags,
            int contactID,
            DealMilestoneStatus?stageType,
            bool?contactAlsoIsParticipant)
        {
            var conditions = new List <Exp>();

            var ids = new List <int>();

            if (!String.IsNullOrEmpty(searchText))
            {
                searchText = searchText.Trim();

                var keywords = searchText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();

                if (keywords.Length > 0)
                {
                    if (!BundleSearch.TrySelectOpportunity(searchText, out ids))
                    {
                        conditions.Add(BuildLike(new[] { "tblDeal.title", "tblDeal.description" }, keywords));
                    }
                    else if (ids.Count == 0)
                    {
                        return(null);
                    }
                }
            }

            if (tags != null && tags.Any())
            {
                ids = SearchByTags(EntityType.Opportunity, ids.ToArray(), tags);

                if (ids.Count == 0)
                {
                    return(null);
                }
            }

            if (contactID > 0)
            {
                if (contactAlsoIsParticipant.HasValue && contactAlsoIsParticipant.Value)
                {
                    var relativeContactsID = GetRelativeToEntity(contactID, EntityType.Opportunity, null).ToList();

                    if (relativeContactsID.Count == 0)
                    {
                        conditions.Add(Exp.Eq("tblDeal.contact_id", contactID));
                    }
                    else
                    {
                        if (ids.Count > 0)
                        {
                            ids = relativeContactsID.Intersect(ids).ToList();

                            if (ids.Count == 0)
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            ids = relativeContactsID;
                        }
                    }
                }
                else
                {
                    conditions.Add(Exp.Eq("tblDeal.contact_id", contactID));
                }
            }

            if (0 < milestoneID && milestoneID < int.MaxValue)
            {
                conditions.Add(Exp.Eq("tblDeal.deal_milestone_id", milestoneID));
            }

            if (responsibleID != Guid.Empty)
            {
                conditions.Add(Exp.Eq("tblDeal.responsible_id", responsibleID));
            }

            if (stageType != null)
            {
                conditions.Add(Exp.Eq("tblDM.status", (int)stageType.Value));
            }

            if (ids.Count > 0)
            {
                if (exceptIDs.Count > 0)
                {
                    ids = ids.Except(exceptIDs).ToList();
                    if (ids.Count == 0)
                    {
                        return(null);
                    }
                }

                conditions.Add(Exp.In("tblDeal.id", ids));
            }
            else if (exceptIDs.Count > 0)
            {
                conditions.Add(!Exp.In("tblDeal.id", exceptIDs.ToArray()));
            }

            if (conditions.Count == 0)
            {
                return(null);
            }

            return(conditions.Count == 1 ? conditions[0] : conditions.Aggregate((i, j) => i & j));
        }
Esempio n. 5
0
        public SearchResultItem[] Search(String searchText)
        {
            var keywords = searchText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                           .ToArray();

            if (keywords.Length == 0)
            {
                return(new List <SearchResultItem>().ToArray());
            }

            _fullTextSearchEnable = BundleSearch.Support(EntityType.Case) &&
                                    BundleSearch.Support(EntityType.Contact) &&
                                    BundleSearch.Support(EntityType.Opportunity) &&
                                    BundleSearch.Support(EntityType.Task) &&
                                    BundleSearch.Support(EntityType.Invoice);

            if (_fullTextSearchEnable)
            {
                _findedIDs = new Dictionary <EntityType, IEnumerable <int> >();

                List <int> casesId;
                if (BundleSearch.TrySelectCase(searchText, out casesId))
                {
                    _findedIDs.Add(EntityType.Case, casesId);
                }

                List <int> contactsId;
                if (BundleSearch.TrySelectContact(searchText, out contactsId))
                {
                    _findedIDs.Add(EntityType.Contact, contactsId);
                }

                List <int> dealsId;
                if (BundleSearch.TrySelectOpportunity(searchText, out dealsId))
                {
                    _findedIDs.Add(EntityType.Opportunity, dealsId);
                }

                List <int> tasksId;
                if (FactoryIndexer <TasksWrapper> .TrySelectIds(r => r.MatchAll(searchText), out tasksId))
                {
                    _findedIDs.Add(EntityType.Task, tasksId);
                }

                List <int> invoicesId;
                if (FactoryIndexer <InvoicesWrapper> .TrySelectIds(r => r.MatchAll(searchText), out invoicesId))
                {
                    _findedIDs.Add(EntityType.Invoice, invoicesId);
                }
            }
            else
            {
                _findedIDs = SearchByCustomFields(keywords)
                             .Union(SearchByRelationshipEvent(keywords))
                             .Union(SearchByContactInfos(keywords))
                             .ToLookup(pair => pair.Key, pair => pair.Value)
                             .ToDictionary(group => group.Key, group => group.First());
            }


            var searchQuery = GetSearchQuery(keywords);

            if (searchQuery == null)
            {
                return(new SearchResultItem[0]);
            }

            return(ToSearchResultItem(Db.ExecuteList(searchQuery)));
        }
Esempio n. 6
0
 private bool IncludeToSearch(EntityType entityType)
 {
     return(!BundleSearch.Support(entityType) || _findedIDs.ContainsKey(entityType));
 }
Esempio n. 7
0
        private Exp BuildWhereExp(EntityType entityType, String[] keywords)
        {
            Exp where = Exp.Empty;

            if (_findedIDs.ContainsKey(entityType))
            {
                where = Exp.In("id", _findedIDs[entityType].ToArray());
            }

            if (BundleSearch.Support(entityType))
            {
                return(where);
            }

            Exp byField;

            switch (entityType)
            {
            case EntityType.Contact:
                byField = BuildLike(new[]
                {
                    "first_name",
                    "last_name",
                    "company_name",
                    "title",
                    "notes"
                }, keywords);
                break;

            case EntityType.Opportunity:
                byField = BuildLike(new[]
                {
                    "title",
                    "description"
                }, keywords);
                break;

            case EntityType.Task:
                byField = BuildLike(new[]
                {
                    "title",
                    "description"
                }, keywords);
                break;

            case EntityType.Case:
                byField = BuildLike(new[]
                {
                    "title"
                }, keywords);
                break;

            case EntityType.Invoice:
                byField = BuildLike(new[]
                {
                    "number",
                    "description"
                }, keywords);
                break;

            default:
                throw new ArgumentException();
            }

            if (where != Exp.Empty)
            {
                where &= byField;
            }
            else
            {
                where = byField;
            }

            return(where);
        }
Esempio n. 8
0
        private Exp WhereConditional(
            ICollection <int> exceptIDs,
            String searchText,
            int contactID,
            bool?isClosed,
            IEnumerable <String> tags)
        {
            var conditions = new List <Exp>();

            var ids = new List <int>();

            if (!String.IsNullOrEmpty(searchText))
            {
                searchText = searchText.Trim();

                var keywords = searchText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                               .ToArray();

                if (keywords.Length > 0)
                {
                    if (!BundleSearch.TrySelectCase(searchText, out ids))
                    {
                        conditions.Add(BuildLike(new[] { "title" }, keywords));
                    }
                    else if (!ids.Any())
                    {
                        return(null);
                    }
                }
            }

            if (contactID > 0)
            {
                var sqlQuery = new SqlQuery("crm_entity_contact")
                               .Select("entity_id")
                               .Where(Exp.Eq("contact_id", contactID) & Exp.Eq("entity_type", (int)EntityType.Case));

                if (ids.Count > 0)
                {
                    sqlQuery.Where(Exp.In("entity_id", ids));
                }

                ids = Db.ExecuteList(sqlQuery).Select(item => Convert.ToInt32(item[0])).ToList();
                if (ids.Count == 0)
                {
                    return(null);
                }
            }

            if (isClosed.HasValue)
            {
                conditions.Add(Exp.Eq("is_closed", isClosed));
            }

            if (tags != null && tags.Any())
            {
                ids = SearchByTags(EntityType.Case, ids.ToArray(), tags);

                if (ids.Count == 0)
                {
                    return(null);
                }
            }

            if (ids.Count > 0)
            {
                if (exceptIDs.Count > 0)
                {
                    ids = ids.Except(exceptIDs).ToList();

                    if (ids.Count == 0)
                    {
                        return(null);
                    }
                }

                conditions.Add(Exp.In("id", ids));
            }
            else if (exceptIDs.Count > 0)
            {
                conditions.Add(!Exp.In("id", exceptIDs.ToArray()));
            }

            if (conditions.Count == 0)
            {
                return(null);
            }

            return(conditions.Count == 1 ? conditions[0] : conditions.Aggregate((i, j) => i & j));
        }