Beispiel #1
0
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            PropertyCompare comp       = new PropertyCompare(prop, sortDirection);
            List <T>        sortedList = new List <T>(this);

            sortedList.Sort(comp);
            ResetItems(sortedList); ResetBindings();
            sortDirection = sortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending;
        }
Beispiel #2
0
        public void EqualTest()
        {
            pcTest pt1 = new pcTest {
                Name = "1"
            };
            PropertyCompare <pcTest> pcCompare = new PropertyCompare <pcTest>("Name");

            Assert.AreEqual(pcCompare.Compare(pt1, pt1), 0);
        }
Beispiel #3
0
        public void CompareTest()
        {
            pcTest pt1 = new pcTest {
                Name = "1"
            };
            pcTest pt2 = new pcTest {
                Name = "2"
            };
            PropertyCompare <pcTest> pcCompare = new PropertyCompare <pcTest>("Name");

            Assert.IsTrue(pcCompare.Compare(pt1, pt2) < 0);
        }
    static void Main()
    {
        Report a = new Report {
            Id = 1, ProjectId = 13
        },
               b = new Report {
            Id = 1, ProjectId = 13
        },
               c = new Report {
            Id = 1, ProjectId = 12
        };

        Console.WriteLine(PropertyCompare.Equal(a, b));
        Console.WriteLine(PropertyCompare.Equal(a, c));
    }
        protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
        {
            _sortProperty  = prop;
            _sortDirection = direction;

            PropertyCompare comp       = new PropertyCompare(prop, _sortDirection);
            List <T>        sortedList = new List <T>(this);

            sortedList.Sort(comp);
            ResetItems(sortedList);

            ResetBindings();

            // toggle sort
            _sortDirection = (_sortDirection == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending;
        }
Beispiel #6
0
        public void NullExceptionTest()
        {
            pcTest pt1 = new pcTest {
                PC = new pc {
                    Name = "1"
                }
            };
            pcTest pt2 = new pcTest {
                PC = new pc {
                    Name = "2"
                }
            };
            PropertyCompare <pcTest> pcCompare = new PropertyCompare <pcTest>();

            Assert.IsTrue(pcCompare.Compare(pt1, pt2) < 0);
        }
        public bool AddIfHasChangePolitico(dynamic registroImportacao, Politico actualPolitico)
        {
            var politico  = (Politico)_mapper.Map <Politico>(registroImportacao);
            var hasChange = !PropertyCompare.Equal(politico, actualPolitico,
                                                   nameof(politico.Id),
                                                   nameof(politico.ImportacaoId),
                                                   nameof(politico.Importacao));

            if (hasChange)
            {
                actualPolitico = _mapper.Map <Politico, Politico>(politico, actualPolitico);
                actualPolitico.SetImportacao(this);
                _politicos.Add(actualPolitico);
                AddDomainEvent(new PoliticoChangedDomainEvent(actualPolitico));
            }
            return(hasChange);
        }
Beispiel #8
0
        public void StringPropContainsConstant()
        {
            var person = new Person()
            {
                FirstName = "Andrew"
            };

            var propCompareCondition = new PropertyCompare()
            {
                PropertyName  = "FirstName",
                PropertyValue = "dr",
                Operator      = PropertyCompareOps.Contains
            };
            var evalRes = propCompareCondition.Evaluate(this.svcProvider, person);

            Assert.IsTrue(evalRes);
        }
Beispiel #9
0
        public void StringPropEqualToConstant()
        {
            var person = new Person()
            {
                FirstName = "Fred"
            };

            var propCompareCondition = new PropertyCompare()
            {
                PropertyName  = "FirstName",
                PropertyValue = "Fred",
                Operator      = PropertyCompareOps.AreEqual
            };
            var evalRes = propCompareCondition.Evaluate(this.svcProvider, person);

            Assert.IsTrue(evalRes);
        }
Beispiel #10
0
        public void ComparePropertyNotFound()
        {
            var person = new Person()
            {
                FirstName   = "Bugs",
                LastName    = "Bunny",
                DateOfBirth = new DateTime(1965, 2, 17)
            };

            var propCompareCondition = new PropertyCompare()
            {
                PropertyName  = "Age",
                PropertyValue = 50,
                Operator      = PropertyCompareOps.GreaterThan
            };

            propCompareCondition.Evaluate(this.svcProvider, person);
        }
Beispiel #11
0
        public void IntPropGreaterThanConstant()
        {
            var person = new Person()
            {
                FirstName   = "Bugs",
                LastName    = "Bunny",
                DateOfBirth = new DateTime(1965, 2, 17)
            };

            var propCompareCondition = new PropertyCompare()
            {
                PropertyName  = "AgeInYears",
                PropertyValue = 50,
                Operator      = PropertyCompareOps.GreaterThan
            };
            var evalRes = propCompareCondition.Evaluate(this.svcProvider, person);

            Assert.IsTrue(evalRes);
        }
Beispiel #12
0
        protected override void ApplySortCore(PropertyDescriptor prop,
                                              ListSortDirection direction)
        {
            //sortProperty = prop;
            //sortDirection = direction;

            PropertyCompare comp       = new PropertyCompare(prop, sortDirection);
            List <T>        sortedList = new List <T>(this);

            try
            {
                sortedList.Sort(comp);
            }
            catch (Exception) {
                // What if not sortable?
            }
            ResetItems(sortedList);

            ResetBindings();
            sortDirection = sortDirection == ListSortDirection.Ascending ?
                            ListSortDirection.Descending : ListSortDirection.Ascending;
        }
Beispiel #13
0
        public bool RenewalStorageGroupZones(List <StorageGroupsByZonesDTO> storageGroupZones)
        {
            bool result;

            var dbSideRusult = mapper.Map <IEnumerable <StorageGroupZones>, List <StorageGroupZonesDTO> >(StorageGroupZones.GetAll());

            var linqSideRusult = storageGroupZones.Select(s => new StorageGroupZonesDTO
            {
                StorageGroupZoneId = s.StorageGroupZoneId ?? 0,
                StorageGroupId     = s.StorageGroupId,
                ZoneNameId         = s.ZoneNameId ?? 0
            }).ToList();

            var ids = dbSideRusult.Select(s => s.StorageGroupZoneId)
                      .Union(linqSideRusult.Select(s => s.StorageGroupZoneId));

            var fullResult = (from i in ids
                              join db in dbSideRusult on i equals db.StorageGroupZoneId into j_db
                              from db in j_db.DefaultIfEmpty()
                              join linq in linqSideRusult on i equals linq.StorageGroupZoneId into j_linq
                              from linq in j_linq.DefaultIfEmpty()
                              select new { db, linq })
                             .ToList();

            string caseStr;
            int    storageGroupZoneId = 0;

            try
            {
                for (int i = 0; i < fullResult.Count(); i++)
                {
                    caseStr = (fullResult[i].db == null) ? "add" :
                              (fullResult[i].linq == null) ? "delete" :
                              (!PropertyCompare.Equal <StorageGroupZonesDTO>(fullResult[i].db, fullResult[i].linq)) ? "update" : "";

                    switch (caseStr)
                    {
                    case "add":
                    {
                        StorageGroupZones.Create(mapper.Map <StorageGroupZones>(fullResult[i].linq));
                    }
                    break;

                    case "update":
                    {
                        storageGroupZoneId = fullResult[i].linq.StorageGroupZoneId;
                        var eGroup = StorageGroupZones.GetAll().SingleOrDefault(c => c.StorageGroupZoneId == storageGroupZoneId);

                        StorageGroupZones.Update((mapper.Map <StorageGroupZonesDTO, StorageGroupZones>(fullResult[i].linq, eGroup)));
                    }
                    break;

                    case "delete":
                    {
                        storageGroupZoneId = fullResult[i].db.StorageGroupZoneId;
                        StorageGroupZones.Delete(StorageGroupZones.GetAll().FirstOrDefault(c => c.StorageGroupZoneId == storageGroupZoneId));
                    }
                    break;
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Действие отменено.\n" + ex.Message, "Сохранение", MessageBoxButtons.OK, MessageBoxIcon.Information);
                result = false;
            }

            return(result);
        }
Beispiel #14
0
 public void ExceptionTest1()
 {
     PropertyCompare <pcTest> pcCompare = new PropertyCompare <pcTest>(t => t.Field);
 }