private static int CompareByZipCode(PostalList x, PostalList y) { if (x == null) { if (y == null) { // If x is null and y is null, they're // equal. return(0); } else { // If x is null and y is not null, y // is greater. return(-1); } } else { // If x is not null... // if (y == null) // ...and y is null, x is greater. { return(1); } else { // ...and y is not null, compare the // lengths of the two strings. // int retval = x.Zipcode.Length.CompareTo(y.Zipcode.Length); if (retval != 0) { // If the strings are not of equal length, // the longer string is greater. // return(retval); } else { // If the strings are of equal length, // sort them with ordinary string comparison. // return(x.Zipcode.CompareTo(y.Zipcode)); } } } }
//Record procedures public override bool ProcessRecord(IDataRecord record) { string departament = GetStringFieldValue(record, "DepartamentField").Trim(); string product = GetStringFieldValue(record, "ProductField").Trim(); string address = GetStringFieldValue(record, "AddressField").Trim(); string zipcode = GetStringFieldValue(record, "ZipCodeField").Trim(); string recipient = GetStringFieldValue(record, "RecipientField").Trim(); double mass = GetDoubleFieldValue(record, "MassField"); Package package = new Package(new Product(product, mass)); Destination dest = new Destination(new Address(zipcode, address), recipient, package); //If group is absent - add new if (!_fillingLists.ContainsKey(zipcode)) { PostalList list = new PostalList(zipcode, departament, package); list.Destinations.Add(dest); _fillingLists[zipcode] = list; } else { PostalList list = _fillingLists[zipcode]; //We may add dest to list if (MassLimit == 0 || list.Mass < MassLimit) { list.Destinations.Add(dest); } else { //Move sending list to closed _filledLists.Add(list); //Add dest to empty list PostalList newlist = new PostalList(zipcode, departament, package); newlist.Destinations.Add(dest); _fillingLists[zipcode] = newlist; } } return(true); }