private static List <MyCustomerBL> BuildFromTable(DataTable dtTable) { List <MyCustomerBL> list = new List <MyCustomerBL>(); if (dtTable != null) { foreach (DataRow dr in dtTable.Rows) { MyCustomerBL thisMember = new MyCustomerBL(dr); list.Add(thisMember); } } return(list); }
public int CompareTo(MyCustomerBL au2, String comparisonType) { String baseComparisonType = comparisonType; Int32 compareResult = 0; Int32 descFlag = 1; //-1 for descending, + 1 for ascending, multiply by compare result String name = String.Empty; String au2Name = String.Empty; if (comparisonType.Contains("DESC")) { descFlag = -1; string[] compArr = comparisonType.Split(new Char[] { ' ' }); if (compArr.Length > 0) { baseComparisonType = compArr[0]; } } switch (comparisonType) { case "PhoneASC": descFlag = 1; compareResult = strPhone.CompareTo(au2.strPhone); break; case "PhoneDESC": descFlag = -1; compareResult = strPhone.CompareTo(au2.strPhone); break; case "NameASC": descFlag = 1; compareResult = strUserName.CompareTo(au2.strUserName); break; case "NameDESC": descFlag = -1; compareResult = strUserName.CompareTo(au2.strUserName); break; case "DateInASC": descFlag = 1; if (null != dtInDate) { compareResult = dtInDate.Value.CompareTo(au2.dtInDate); } break; case "DateInDESC": descFlag = -1; if (null != dtInDate) { compareResult = dtInDate.Value.CompareTo(au2.dtInDate); } break; case "DateOutASC": descFlag = 1; if (null != dtOutDate) { compareResult = dtOutDate.Value.CompareTo(au2.dtOutDate); } break; case "DateOutDESC": descFlag = -1; if (null != dtOutDate) { compareResult = dtOutDate.Value.CompareTo(au2.dtOutDate); } break; case "EmailASC": descFlag = 1; compareResult = strEmail.CompareTo(au2.strEmail); break; case "EmailDESC": descFlag = -1; compareResult = strEmail.CompareTo(au2.strEmail); break; case "UpdatedDateASC": descFlag = 1; if (null != dtUpdatedDate) { compareResult = dtUpdatedDate.Value.CompareTo(au2.dtUpdatedDate); } break; case "UpdatedDateDESC": descFlag = -1; if (null != dtUpdatedDate) { compareResult = dtUpdatedDate.Value.CompareTo(au2.dtUpdatedDate); } break; case "DateASC": descFlag = 1; if (null != dtUpdatedDate) { compareResult = dtUpdatedDate.Value.CompareTo(au2.dtUpdatedDate); } break; case "DateDESC": descFlag = -1; if (null != dtUpdatedDate) { compareResult = dtUpdatedDate.Value.CompareTo(au2.dtUpdatedDate); } break; case "NotificationASC": descFlag = 1; compareResult = String.IsNullOrEmpty(strPushNotificationDeviceId).CompareTo(String.IsNullOrEmpty(au2.strPushNotificationDeviceId)); break; case "NotificationDESC": descFlag = -1; compareResult = String.IsNullOrEmpty(strPushNotificationDeviceId).CompareTo(String.IsNullOrEmpty(au2.strPushNotificationDeviceId)); break; case "Company NameASC": descFlag = 1; compareResult = companyName.CompareTo(au2.companyName); break; case "Company NameDESC": descFlag = -1; compareResult = companyName.CompareTo(au2.companyName); break; case "Agent NameASC": descFlag = 1; compareResult = strAgentName.CompareTo(au2.strAgentName); break; case "Agent NameDESC": descFlag = -1; compareResult = strAgentName.CompareTo(au2.strAgentName); break; case "Estimator NameASC": descFlag = 1; compareResult = strEstimatorName.CompareTo(au2.strEstimatorName); break; case "Estimator NameDESC": descFlag = -1; compareResult = strEstimatorName.CompareTo(au2.strEstimatorName); break; case "LastNameASC": descFlag = 1; compareResult = strLastName.CompareTo(au2.strLastName); break; case "LastNameDESC": descFlag = -1; compareResult = strLastName.CompareTo(au2.strLastName); break; case "UserNameASC": descFlag = 1; compareResult = strUserName.CompareTo(au2.strUserName); break; case "UserNameDESC": descFlag = -1; compareResult = strUserName.CompareTo(au2.strUserName); break; case "StatusASC": descFlag = 1; if (null != strStatusOfVehicle && null != au2.strStatusOfVehicle) { compareResult = strStatusOfVehicle.CompareTo(au2.strStatusOfVehicle); } break; case "StatusDESC": descFlag = -1; if (null != strStatusOfVehicle && null != au2.strStatusOfVehicle) { compareResult = strStatusOfVehicle.CompareTo(au2.strStatusOfVehicle); } break; case "DeliveryDateASC": descFlag = 1; if (null != dtDeliveryDate) { compareResult = dtDeliveryDate.Value.CompareTo(au2.dtDeliveryDate); } break; case "DeliveryDateDESC": descFlag = -1; if (null != dtDeliveryDate) { compareResult = dtDeliveryDate.Value.CompareTo(au2.dtDeliveryDate); } break; case "ShopNameASC": descFlag = 1; if (null != strShopName && null != au2.strShopName) { compareResult = strShopName.CompareTo(au2.strShopName); } break; case "ShopNameDESC": descFlag = -1; if (null != strShopName && null != au2.strShopName) { compareResult = strShopName.CompareTo(au2.strShopName); } break; default: descFlag = 1; compareResult = strUserName.CompareTo(au2.strUserName); break; } return(compareResult * descFlag); //desc flag of -1 returns negative result for descending sort }