Esempio n. 1
0
        private TreeNode GetNode(CompanyWrapper current, Dictionary <int, bool> filter)
        {
            if (!_foundCompanies.ContainsKey(current.RecordID))
            {
                _foundCompanies.Add(current.RecordID, current);

                char c = current.Title.ToLower()[0];

                List <CompanyWrapper> letterWrappers;
                if (!_wrappersByLetter.TryGetValue(c, out letterWrappers))
                {
                    letterWrappers = new List <CompanyWrapper>();
                    _wrappersByLetter.Add(c, letterWrappers);
                }

                letterWrappers.Add(current);
            }

            var node = new TreeNode(current.Title, GetChildNodes(current, filter).ToArray())
            {
                Tag        = current.RecordID,
                ImageIndex = 0
            };

            node.Expand();

            return(node);
        }
Esempio n. 2
0
 private static void companyWrapper(ServiceOperationResult serviceOperationResult, System.Collections.Generic.List <Company> companyList)
 {
     foreach (var company in companyList)
     {
         var wr = new CompanyWrapper();
         wr.WrappCompany(company);
         serviceOperationResult.CompanyWrappers.Add(wr);
     }
 }
Esempio n. 3
0
        private void noFlickerListView1_DoubleClick(object sender, EventArgs e)
        {
            CompanyWrapper selectedCompany = SelectedCompany;

            if (selectedCompany != null && CompanyDoubleClicked != null)
            {
                CompanyDoubleClicked(selectedCompany);
            }
        }
Esempio n. 4
0
        private void LoadCompany(int companyId)
        {
            var company = companyId != 0 ? _companyRepository.GetById(companyId) : new Company();

            Company = new CompanyWrapper(company);

            if (companyId == 0)
            {
                _companyRepository.Add(company);
            }


            Employees.Clear();
            AvailableEmployees.Clear();
            var employees = _employeeRepository.GetAll();

            foreach (var employee in employees)
            {
                if (employee.CompanyId == null)
                {
                    AvailableEmployees.Add(new LookupItem
                    {
                        Id            = employee.Id,
                        DisplayMember = employee.LastName + " " + employee.FirstName
                    });

                    continue;
                }

                if (employee.CompanyId != companyId)
                {
                    continue;
                }

                Employees.Add(new LookupItem
                {
                    Id            = employee.Id,
                    DisplayMember = employee.LastName + " " + employee.FirstName
                });
            }

            Company.PropertyChanged += (s, e) =>
            {
                if (!IsDirty)
                {
                    IsDirty = _employeeRepository.HasChanges();
                    SaveCommand.RaiseCanExecuteChanged();
                }
                if (e.PropertyName == nameof(Company.Name))
                {
                    IsDirty = _companyRepository.HasChanges();
                    SaveCommand.RaiseCanExecuteChanged();
                }
            };
        }
Esempio n. 5
0
        private CompanyWrapper Get(List <CompanyWrapper> wrappers, int recordId, bool delete)
        {
            CompanyWrapper wrapper = wrappers.FirstOrDefault(x => x.RecordID == recordId);

            if (wrapper != null && delete)
            {
                wrappers.Remove(wrapper);
            }

            return(wrapper);
        }
        private void OnAddExecute()
        {
            var wrapper = new CompanyWrapper(new Company());

            wrapper.PropertyChanged += Wrapper_PropertyChanged;
            _companyRepository.Add(wrapper.Model);
            Companies.Add(wrapper);

            //trigger the validation
            wrapper.Name = "";
        }
Esempio n. 7
0
        private Dictionary <int, bool> FindMatches(CompanyWrapper wrapper, string text)
        {
            Dictionary <int, bool> matches = new Dictionary <int, bool>();

            if (IsMatch(wrapper, text))
            {
                if (!matches.ContainsKey(wrapper.RecordID))
                {
                    matches.Add(wrapper.RecordID, true);
                }
            }

            return(matches);
        }
Esempio n. 8
0
        private IEnumerable <TreeNode> GetChildNodes(CompanyWrapper current, Dictionary <int, bool> filter)
        {
            if (current.RelatedCompanies != null)
            {
                foreach (var child in current.RelatedCompanies)
                {
                    if (filter != null && !filter.ContainsKey(child.RecordID))
                    {
                        continue;
                    }

                    yield return(GetNode(child, filter));
                }
            }
        }
        private void MapObjectToProps(Client.Entities.Company company)
        {
            Company = new CompanyWrapper(company);

            if (company.GLAccounts != null)
            {
                AccountTypes = new List <string>(Company.GLAccounts.Select(x => x.AccountType).Distinct().OrderBy(x => x).ToList());
                BalanceTypes = new List <string>(Company.GLAccounts.Select(x => x.BalanceType).Distinct().OrderBy(x => x).ToList());
            }

            if (company.CompanyAddresses != null)
            {
                DefaultShippingAddress = Company.CompanyAddresses.Where(type => type.AddressType == QIQOAddressType.Shipping).FirstOrDefault();
                DefaultBillingAddress  = Company.CompanyAddresses.Where(type => type.AddressType == QIQOAddressType.Billing).FirstOrDefault();
            }
            Company.PropertyChanged += Context_PropertyChanged;
        }
        public override async Task LoadAsync(int id)
        {
            Id = id;
            foreach (var wrapper in Companies)
            {
                wrapper.PropertyChanged -= Wrapper_PropertyChanged;
            }

            Companies.Clear();

            var companies = await _companyRepository.GetAllAsync();

            foreach (var model in companies)
            {
                var wrapper = new CompanyWrapper(model);
                wrapper.PropertyChanged += Wrapper_PropertyChanged;
                Companies.Add(wrapper);
            }
        }
Esempio n. 11
0
        public void Load(CompanyWrapper companyWrapper)
        {
            var newCompany = new Company
            {
                FullName  = "NewCompany",
                Form      = new CompanyForm(),
                Employees = new List <Employee>()
            };

            CompanyWrapper = companyWrapper ?? new CompanyWrapper(newCompany);

            CompanyWrapper.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(CompanyWrapper.IsChanged) ||
                    e.PropertyName == nameof(CompanyWrapper.IsValid))
                {
                    InvalidateCommands();
                }
            };

            InvalidateCommands();
        }
Esempio n. 12
0
        protected void InsertCompany()
        {
            CompanyWrapper company = companyTreeView1.SelectedCompany;

            if (company == null)
            {
                Globals.SitecoreAddin.Log("DealsDrugsCompaniesControl.InsertCompany: Trying to add a company when none are selected!");
                return;
            }

            Range selection = Globals.SitecoreAddin.Application.Selection.Range;

            selection.Text      = company.Title;
            selection.Font.Bold = -1;
            selection.Collapse(WdCollapseDirection.wdCollapseEnd);
            selection.Text      = " ";
            selection.Font.Bold = 0;
            selection.Collapse(WdCollapseDirection.wdCollapseEnd);
            selection.Select();

            //InsertLinkIntoDocument("C", company.RecordNumber, company.URL, CompanyTooltip);
        }
Esempio n. 13
0
        public void CompanyParentChildRelations()
        {
            var parent = new CompanyWrapper(new Company {
                FullName = "ParentCompany"
            });
            var child1 = new CompanyWrapper(new Company {
                FullName = "ChildCompany1"
            });
            var child2 = new CompanyWrapper(new Company {
                FullName = "ChildCompany2"
            });

            child1.ParentCompany = parent;
            Assert.IsTrue(parent.ChildCompanies.Contains(child1));

            child2.ParentCompany = parent;
            Assert.IsTrue(parent.ChildCompanies.Contains(child2));

            child1.ParentCompany = null;
            Assert.IsFalse(parent.ChildCompanies.Contains(child1));

            parent.ChildCompanies.Add(child1);
            Assert.AreEqual(parent, child1.ParentCompany);
        }
Esempio n. 14
0
 private void companyTreeView1_CompanyDoubleClicked(CompanyWrapper wrapper)
 {
     InsertCompany();
 }
Esempio n. 15
0
        private ContactWrapper ToContactWrapper(Contact contact)
        {
            ContactWrapper result;

            if (contact is Person)
            {
                var people = (Person)contact;

                var peopleWrapper = new PersonWrapper(people);

                if (people.CompanyID > 0)
                {
                    peopleWrapper.Company = ToContactBaseWrapper(DaoFactory.GetContactDao().GetByID(people.CompanyID));
                }

                result = peopleWrapper;
            }
            else if (contact is Company)
            {
                result = new CompanyWrapper((Company)contact);
            }
            else
            {
                throw new ArgumentException();
            }

            if (contact.StatusID > 0)
            {
                result.ContactType = GetContactTypeByID(contact.StatusID);
            }

            result.TaskCount     = DaoFactory.GetTaskDao().GetTasksCount(contact.ID);
            result.HaveLateTasks = DaoFactory.GetTaskDao().HaveLateTask(contact.ID);

            var contactInfos = new List <ContactInfoWrapper>();
            var addresses    = new List <Address>();

            var data = DaoFactory.GetContactInfoDao().GetList(contact.ID, null, null, null);

            foreach (var contactInfo in data)
            {
                if (contactInfo.InfoType == ContactInfoType.Address)
                {
                    addresses.Add(new Address(contactInfo));
                }
                else
                {
                    contactInfos.Add(new ContactInfoWrapper(contactInfo));
                }
            }

            result.Addresses  = addresses;
            result.CommonData = contactInfos;

            if (contact is Person)
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Person, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();
            }
            else
            {
                result.CustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Company, contact.ID, false).ConvertAll(item => new CustomFieldWrapper(item)).ToSmartList();
            }

            return(result);
        }
Esempio n. 16
0
        private IEnumerable <ContactWrapper> ToListContactWrapper(List <Contact> itemList)
        {
            if (itemList.Count == 0)
            {
                return(new List <ContactWrapper>());
            }

            var result = new List <ContactWrapper>();

            var personsIDs = new List <int>();
            var companyIDs = new List <int>();
            var contactIDs = new int[itemList.Count];

            for (int index = 0; index < itemList.Count; index++)
            {
                var contact = itemList[index];

                if (contact is Company)
                {
                    companyIDs.Add(contact.ID);
                }
                else if (contact is Person)
                {
                    personsIDs.Add(contact.ID);
                }

                contactIDs[index] = itemList[index].ID;
            }


            var contactTypeIDs = itemList.Select(item => item.StatusID).Distinct().ToArray();
            var contactInfos   = new Dictionary <int, List <ContactInfoWrapper> >();

            var haveLateTask = DaoFactory.GetTaskDao().HaveLateTask(contactIDs);
            var contactType  = DaoFactory.GetListItemDao().GetItems(contactTypeIDs).ToDictionary(item => item.ID,
                                                                                                 item =>
                                                                                                 ToContactType(item));

            var personsCustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Person,
                                                                                    personsIDs.ToArray());

            var companyCustomFields = DaoFactory.GetCustomFieldDao().GetEnityFields(EntityType.Company,
                                                                                    companyIDs.ToArray());


            var customFields = personsCustomFields.Union(companyCustomFields).GroupBy(item => item.EntityID).ToDictionary(
                item => item.Key, item => item.Select(x => ToCustomFieldWrapper(x)));


            var addresses = new Dictionary <int, List <Address> >();
            var taskCount = DaoFactory.GetTaskDao().GetTasksCount(contactIDs);

            var contactTags = DaoFactory.GetTagDao().GetEntitiesTags(EntityType.Contact);

            DaoFactory.GetContactInfoDao().GetAll(contactIDs).ForEach(
                item =>
            {
                if (item.InfoType == ContactInfoType.Address)
                {
                    if (!addresses.ContainsKey(item.ContactID))
                    {
                        addresses.Add(item.ContactID, new List <Address>
                        {
                            new Address(item)
                        });
                    }
                    else
                    {
                        addresses[item.ContactID].Add(new Address(item));
                    }
                }
                else
                {
                    if (!contactInfos.ContainsKey(item.ContactID))
                    {
                        contactInfos.Add(item.ContactID, new List <ContactInfoWrapper> {
                            new ContactInfoWrapper(item)
                        });
                    }
                    else
                    {
                        contactInfos[item.ContactID].Add(new ContactInfoWrapper(item));
                    }
                }
            }
                );

            foreach (var contact in itemList)
            {
                ContactWrapper contactWrapper;

                if (contact is Person)
                {
                    var people = (Person)contact;

                    var peopleWrapper = new PersonWrapper(people);

                    if (people.CompanyID > 0)
                    {
                        Contact peopleCompany;

                        if (companyIDs.Contains(people.CompanyID))
                        {
                            peopleCompany = itemList.Find(item => item.ID == people.CompanyID);
                        }
                        else
                        {
                            peopleCompany = DaoFactory.GetContactDao().GetByID(people.CompanyID);
                        }

                        peopleWrapper.Company = ToContactBaseWrapper(peopleCompany);
                    }

                    contactWrapper = peopleWrapper;
                }
                else if (contact is Company)
                {
                    contactWrapper = new CompanyWrapper((Company)contact);
                }
                else
                {
                    throw new ArgumentException();
                }

                if (contactTags.ContainsKey(contact.ID))
                {
                    contactWrapper.Tags = contactTags[contact.ID];
                }

                if (addresses.ContainsKey(contact.ID))
                {
                    contactWrapper.Addresses = addresses[contact.ID];
                }

                if (contactInfos.ContainsKey(contact.ID))
                {
                    contactWrapper.CommonData = contactInfos[contact.ID];
                }
                else
                {
                    contactWrapper.CommonData = new List <ContactInfoWrapper>();
                }

                if (contactType.ContainsKey(contact.StatusID))
                {
                    contactWrapper.ContactType = contactType[contact.StatusID];
                }

                if (haveLateTask.ContainsKey(contact.ID))
                {
                    contactWrapper.HaveLateTasks = haveLateTask[contact.ID];
                }
                else
                {
                    contactWrapper.HaveLateTasks = false;
                }

                if (customFields.ContainsKey(contact.ID))
                {
                    contactWrapper.CustomFields = customFields[contact.ID];
                }
                else
                {
                    contactWrapper.CustomFields = new List <CustomFieldWrapper>();
                }

                if (taskCount.ContainsKey(contact.ID))
                {
                    contactWrapper.TaskCount = taskCount[contact.ID];
                }
                else
                {
                    contactWrapper.TaskCount = 0;
                }

                result.Add(contactWrapper);
            }

            return(result);
        }
Esempio n. 17
0
        private IEnumerable <CompanyWrapper> GetWithRelated()
        {
            DCDManager dcdMgr = new DCDManager();

            // build a dictionary of all of the companies, key is the company id
            Dictionary <int, Company> allCompanies = dcdMgr.GetAllCompanies().ToDictionary(x => x.RecordId, x => x);

            // pull down a list of all related companies
            RelatedCompany[] allRelatedCompanies = dcdMgr.GetAllRelatedCompanies().ToArray();

            // our results dictionary, key is the company id
            Dictionary <int, CompanyWrapper> results = new Dictionary <int, CompanyWrapper>();

            // keep track of where a company is when it's inserted into "RelatedCompanies" so we don't have to dig through every companies
            // RelatedCompanies to try to find a company.
            Dictionary <int, List <CompanyWrapper> > pointers = new Dictionary <int, List <CompanyWrapper> >();

            // gather all of the "Root Companies" because there are a ton of duplicates.
            RelatedCompany[] rootCompanies =
                (from i in allRelatedCompanies
                 where i.CompanyRecordId.ToString() == i.RelatedCompanyRecordNumber
                 orderby i.RelatedCompanyPath ascending
                 select i).ToArray();

            // build out the wrappers we're going to return.
            foreach (var relatedCompany in rootCompanies)
            {
                Company        currentCompany = allCompanies[relatedCompany.CompanyRecordId];
                CompanyWrapper wrapper        = new CompanyWrapper {
                    RecordID = currentCompany.RecordId, RecordNumber = currentCompany.RecordNumber, Title = currentCompany.Title, Parent = null
                };
                results.Add(relatedCompany.CompanyRecordId, wrapper);
            }

            // iterate through all of our root companies
            foreach (var relatedCompany in rootCompanies)
            {
                // split the path by '/' to get all of the seperate results.
                string[] pieces = relatedCompany.RelatedCompanyPath.Split('/');

                // ignore paths with no slash, because they don't have parents.
                if (pieces.Length == 1)
                {
                    continue;
                }

                // join all of the pieces except for the last piece to give us the parent of the current item
                string parent = string.Join("/", pieces.Take(pieces.Length - 1).ToArray());

                // get the parent from our root companies
                RelatedCompany parentCompany = rootCompanies.FirstOrDefault(x => x.RelatedCompanyPath == parent);

                // check to make sure it's legit and isn't itself for some reason.
                if (parentCompany == null || parentCompany.CompanyRecordId == relatedCompany.CompanyRecordId)
                {
                    continue;
                }

                // get the parent from the "results" dictionary
                CompanyWrapper parentWrapper = Get(results, pointers, parentCompany.CompanyRecordId, false);

                // check to make sure it exists.
                if (parentWrapper == null)
                {
                    continue;
                }

                // get the current item from the results collection and delete it from wherever it is.
                CompanyWrapper current = Get(results, pointers, relatedCompany.CompanyRecordId, true);

                if (current == null)
                {
                    continue;
                }

                // keep track of where we're putting it.
                pointers[current.RecordID] = parentWrapper.RelatedCompanies;

                if (parentWrapper.RelatedCompanies == null)
                {
                    parentWrapper.RelatedCompanies = new List <CompanyWrapper>();
                }

                // add it to it's parent.
                parentWrapper.RelatedCompanies.Add(current);
            }

            // just select the values (the CompanyWrappers)
            List <CompanyWrapper> returnWrappers = results.Select(x => x.Value).ToList();

            // recursively sort all of the results
            Sort(returnWrappers);

            return(returnWrappers);
        }
Esempio n. 18
0
 private void OnSaveExecute()
 {
     CompanyWrapper.AcceptChanges();
     _unitOfWork.Complete();
 }
Esempio n. 19
0
 private void OnResetExecute()
 {
     CompanyWrapper.RejectChanges();
 }
Esempio n. 20
0
 private bool IsMatch(CompanyWrapper wrapper, string text)
 {
     return(wrapper.Title.StartsWith(text, StringComparison.InvariantCultureIgnoreCase));
 }