只用一次循环开销 将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式

     /// <summary>
     ///
将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式 /// </summary> /// <param name="list"></param> /// <returns></returns> private BookingInShopListDataContract[] GenDistinctList(List<BookingInShopListDataContract> list) { //定义实际要返回到界面的aimList List<BookingInShopListDataContract> aimList = new List<BookingInShopListDataContract>(); string bookingNo = string.Empty; string repairType = string.Empty; BookingInShopListDataContract cloneDC = new BookingInShopListDataContract(); BookingInShopListDataContract addDC = null; if (list.Count == 0) { return aimList.ToArray(); } foreach (var item in list) { if (string.IsNullOrEmpty(bookingNo)) { bookingNo = item.BookingNo; repairType = item.RepairTypeName; } else if (bookingNo == item.BookingNo) { if (!string.IsNullOrEmpty(item.RepairTypeName)) { repairType = repairType + "," + item.RepairTypeName; } } else { AddNewCloneDC(addDC, cloneDC, bookingNo, repairType, aimList); cloneDC = new BookingInShopListDataContract(); bookingNo = item.BookingNo; repairType = item.RepairTypeName; } addDC = item; } AddNewCloneDC(addDC, cloneDC, bookingNo, repairType, aimList); return aimList.ToArray(); } private void AddNewCloneDC(BookingInShopListDataContract aAddDC, BookingInShopListDataContract aCloneDC, string aBookingNo, string aRepairType, List<BookingInShopListDataContract> aAimList) { aCloneDC.BookingNo = aBookingNo; aCloneDC.BookingStatus = aAddDC.BookingStatus; aCloneDC.OwnerName = aAddDC.OwnerName; aCloneDC.OwnerPhone = aAddDC.OwnerPhone; aCloneDC.CarLicenseNo = aAddDC.CarLicenseNo; aCloneDC.FrameNo = aAddDC.FrameNo; aCloneDC.BookComeTime = aAddDC.BookComeTime; aCloneDC.BookEndTime = aAddDC.BookEndTime; aCloneDC.Receiver = aAddDC.Receiver; aCloneDC.ReceiverName = aAddDC.ReceiverName; aCloneDC.OpertatorName = aAddDC.OpertatorName; aCloneDC.RepairTypeName = aRepairType; aCloneDC.SolicitType = aAddDC.SolicitType; aAimList.Add(aCloneDC); }

 

posted @ 2015-02-26 08:40  沙耶  阅读(288)  评论(0编辑  收藏  举报