public DeliveryPoints GetDeliveryPoints(DateTime startDate, DateTime lastUpated) { DeliveryPoints points = null; const string CSV_DELIM = ","; //Update a collection (dataset) of all delivery points try { //Clear and fetch new data points = new DeliveryPoints(); DataSet ds = fillDataset(USP_DELIVERYPOINTS, TBL_DELIVERYPOINTS, new object[] { startDate }); if (ds != null) { //Create a dataset of containing unique entries DeliveryPointDS _ds = new DeliveryPointDS(); _ds.Merge(ds); DeliveryPointDS rds = new DeliveryPointDS(); rds.Merge(_ds.DeliveryPointTable.Select("", "Account ASC")); Hashtable ht = new Hashtable(); string acct = ""; for (int i = 0; i < rds.DeliveryPointTable.Rows.Count; i++) { //Remove duplicate account entries acct = rds.DeliveryPointTable[i].Account; if (ht.ContainsKey(acct)) { rds.DeliveryPointTable[i].Delete(); } else { ht.Add(acct, null); //Keep track of keys (unique accounts) } } rds.AcceptChanges(); //Modify data for (int i = 0; i < rds.DeliveryPointTable.Rows.Count; i++) { //Set command as follows: // A: OpenDate > lastpDated; U: OpenDate <= lastUpdated DateTime opened = rds.DeliveryPointTable[i].OpenDate; rds.DeliveryPointTable[i].Command = (opened.CompareTo(lastUpated) > 0) ? "A" : "U"; //Remove commas from address fields rds.DeliveryPointTable[i].Building = rds.DeliveryPointTable[i].Building.Replace(CSV_DELIM, " "); rds.DeliveryPointTable[i].Address = rds.DeliveryPointTable[i].Address.Replace(CSV_DELIM, " "); rds.DeliveryPointTable[i].StopComment = rds.DeliveryPointTable[i].StopComment.Replace(CSV_DELIM, " "); //Add each point to the collection DeliveryPoint point = new DeliveryPoint(rds.DeliveryPointTable[i]); points.Add(point); } } } catch (Exception ex) { throw ex; } return(points); }
public static DeliveryPoints GetDeliveryPoints(DateTime startDate, DateTime lastUpated) { //Get delivery points DeliveryPoints points = null; try { _Client = new DeliveryPointsServiceClient(); points = _Client.GetDeliveryPoints(startDate, lastUpated); _Client.Close(); } catch (FaultException fe) { throw new ApplicationException("GetDeliveryPoints() service error.", fe); } catch (TimeoutException te) { _Client.Abort(); throw new ApplicationException("GetDeliveryPoints() timeout error.", te); } catch (CommunicationException ce) { _Client.Abort(); throw new ApplicationException("GetDeliveryPoints() communication error.", ce); } return(points); }