public List <String> ConvertToNumber(Dictionary <string, int> orderOverload, Models.CustomerList CustomerList, String PartOfName) { if (PartOfName == "first_name") { //Convert first name too number values assigned to sort order data //Dictionary to store cust info as a number (key) and cust info as chars (value) var firstNameAsNum = new List <string>(); foreach (Models.Customer cust in CustomerList.customers) { //stores customer first name as number with "/" serperating each value String infoToNum = ""; char[] firstName; //store customer's first name in char array firstName = cust.first_name.ToCharArray(); /*Create string of numbers seperated by "/" * Look up char value in sort order and get numeric val for char * Add string of nums to list*/ foreach (char letter in firstName) { if (orderOverload.ContainsKey(letter.ToString())) { infoToNum += orderOverload[letter.ToString()].ToString() + "/"; } else { infoToNum = 0.ToString(); } } if (!firstNameAsNum.Contains(infoToNum)) { firstNameAsNum.Add(infoToNum); } } return(firstNameAsNum); } if (PartOfName == "last_name") { //Convert last name too number values assigned to sort order data //Dictionary to store cust info as a number (key) and cust info as chars (value) var lastNameAsNum = new List <string>(); foreach (Models.Customer cust in CustomerList.customers) { String infoToNum = ""; char[] lastName; lastName = cust.last_name.ToCharArray(); foreach (char letter in lastName) { if (orderOverload.ContainsKey(letter.ToString())) { infoToNum += orderOverload[letter.ToString()].ToString() + "/"; } else { infoToNum = 0.ToString(); } } if (!lastNameAsNum.Contains(infoToNum)) { lastNameAsNum.Add(infoToNum); } } return(lastNameAsNum); } if (PartOfName == "middle_name") { //Convert middle name too number values assigned to sort order data //Dictionary to store cust info as a number (key) and cust info as chars (value) var middleNameAsNum = new List <string>(); foreach (Models.Customer cust in CustomerList.customers) { String infoToNum = ""; char[] middleName; if (cust.middle_name != null) { middleName = cust.middle_name.ToCharArray(); foreach (char letter in middleName) { if (orderOverload.ContainsKey(letter.ToString())) { infoToNum += orderOverload[letter.ToString()].ToString() + "/"; } else { infoToNum = 0.ToString(); } } if (!middleNameAsNum.Contains(infoToNum)) { middleNameAsNum.Add(infoToNum); } } else { if (!middleNameAsNum.Contains("0")) { middleNameAsNum.Add("0"); } } } return(middleNameAsNum); } return(null); }
public string LoadCustomerData(string strName, string strAddress, string strphone, bool?isMember, string strFrId, string orderByColumn, string orderOrientation) { StringBuilder response = new StringBuilder(); int count, index, totalCount; //int iAcnum = (strAcnum == "" ? 0 : Convert.ToInt32(strAcnum)); int iFrId = (strFrId == "" ? 0 : Convert.ToInt32(strFrId)); if (orderByColumn == null) { orderByColumn = "CustomerID"; } if (orderOrientation == null) { orderOrientation = "asc"; } if ((Session["strFrId"] != null) && (Session["strFrId"].ToString() != strFrId)) { index = 0; Session["posStart"] = null; Session["totalCount"] = null; Session["count"] = null; Session["orderBy"] = null; Session["direction"] = null; } if ((Session["direction"] != null) && (Session["direction"].ToString().Equals(orderOrientation) == false)) { index = 0; Session["posStart"] = null; Session["totalCount"] = null; Session["count"] = null; Session["orderBy"] = null; Session["direction"] = null; } Session["strFrId"] = strFrId; Session["orderBy"] = orderByColumn; Session["direction"] = orderOrientation; CustomerList cList = new Models.CustomerList(); //CustomerList custData; List <CustomerList> custDataList = new List <Models.CustomerList>(); Session["txtName"] = strName; Session["txtAddress"] = strAddress; Session["txtPhoneNumber"] = strphone; Session["chkmember"] = isMember; if (iFrId == 0) { iFrId = 56; } var customerData = (from cust in db.tbl_Customer join loc in db.tbl_Locations on cust.CustomerID equals loc.ActvieCustomerID into loc_1 join cInfo in db.tbl_Customer_Info on cust.CustomerID equals cInfo.CustomerID into cInfo_1 join mInfo in db.tbl_Customer_Members on cust.CustomerID equals mInfo.CustomerID into mInfo_1 from loc in loc_1.DefaultIfEmpty() from cInfo in cInfo_1.DefaultIfEmpty() from mInfo in mInfo_1.DefaultIfEmpty() where loc.BilltoCustomerID != null && cInfo.CustomerID != null && cInfo.FranchiseID == iFrId select new { cInfo.FranchiseID, cust.CustomerID, cust.CustomerName, cust.CompanyName, loc.Address, loc.State, loc.City, loc.PostalCode, cust.EMail, PhoneNumber = (from c in db.tbl_Contacts where c.PhoneTypeID == 2 && c.CustomerID == cust.CustomerID select c.PhoneNumber).FirstOrDefault(), MemberType = "", Exp_date = "", Scheduled = "", AgeRecords = 2, House = "", mInfo.StartDate, mInfo.EndDate }).Distinct().ToList(); //var customerInfoData = db.tbl_Customer_Info.Where(ci => ci.FranchiseID == iFrId).ToList(); // Session variables initialisation if ((Session["posStart"] != null) && (Session["posStart"].ToString() != "")) { index = int.Parse(Session["posStart"].ToString()); } else { index = 0; } if ((Session["count"] != null) && (Session["count"].ToString() != "")) { count = int.Parse(Session["count"].ToString()); Session["count"] = count; } else { count = customerData.Count < 20 ? customerData.Count : 20; } if (index == 0) { totalCount = customerData.Count; Session["totalCount"] = totalCount; } else { totalCount = int.Parse(Session["totalCount"].ToString()); } if (orderOrientation == "asc") { switch (orderByColumn) { case "0": customerData = customerData.OrderBy(t => t.CustomerID).Skip(index).Take(count).ToList(); break; case "1": customerData = customerData.OrderBy(t => t.CustomerName).Skip(index).Take(count).ToList(); break; case "2": customerData = customerData.OrderBy(t => t.CompanyName).Skip(index).Take(count).ToList(); break; case "3": customerData = customerData.OrderBy(t => t.Address).Skip(index).Take(count).ToList(); break; case "4": customerData = customerData.OrderBy(t => t.State).Skip(index).Take(count).ToList(); break; case "5": customerData = customerData.OrderBy(t => t.City).Skip(index).Take(count).ToList(); break; case "6": customerData = customerData.OrderBy(t => t.PhoneNumber).Skip(index).Take(count).ToList(); break; case "7": customerData = customerData.OrderBy(t => t.EMail).Skip(index).Take(count).ToList(); break; //case "8": // customerData = customerData.OrderBy(t => t.b).Skip(index).Take(count).ToList(); // break; default: customerData = customerData.OrderBy(t => t.CustomerID).Skip(index).Take(count).ToList(); break; } } else if (orderOrientation == "des") { switch (orderByColumn) { case "0": customerData = customerData.OrderByDescending(t => t.CustomerID).Skip(index).Take(count).ToList(); break; case "1": customerData = customerData.OrderByDescending(t => t.CustomerName).Skip(index).Take(count).ToList(); break; case "2": customerData = customerData.OrderByDescending(t => t.CompanyName).Skip(index).Take(count).ToList(); break; case "3": customerData = customerData.OrderByDescending(t => t.Address).Skip(index).Take(count).ToList(); break; case "4": customerData = customerData.OrderByDescending(t => t.State).Skip(index).Take(count).ToList(); break; case "5": customerData = customerData.OrderByDescending(t => t.City).Skip(index).Take(count).ToList(); break; case "6": customerData = customerData.OrderByDescending(t => t.PhoneNumber).Skip(index).Take(count).ToList(); break; case "7": customerData = customerData.OrderByDescending(t => t.EMail).Skip(index).Take(count).ToList(); break; //case "8": // customerData = customerData.OrderBy(t => t.b).Skip(index).Take(count).ToList(); // break; default: customerData = customerData.OrderByDescending(t => t.CustomerID).Skip(index).Take(count).ToList(); break; } } else { customerData = customerData.OrderBy(t => t.CustomerID).Skip(index).Take(count).ToList(); } if (strAddress != null && strAddress != "") { customerData = (from c in customerData where c.Address.ToLower().Contains(strAddress.ToLower()) select c).ToList(); } if (strName != null && strName != "") { customerData = (from c in customerData where c.CustomerName.ToLower().Contains(strName.ToLower()) select c).ToList(); } if (strphone != null && strphone != "") { customerData = (from c in customerData where (c.PhoneNumber == null ? "" : c.PhoneNumber).Replace("(", "").Replace(")", "").Replace("-", "").Contains(strphone.Replace("(", "").Replace(")", "").Replace("-", "")) select c).ToList(); } if (isMember == true) { customerData = (from c in customerData where c.StartDate != null select c).ToList(); } response.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?><rows total_count='" + totalCount + "' pos='" + index + "'>"); foreach (var cData in customerData) { response.Append("<row id='" + index + "'>"); response.Append("<cell><![CDATA[" + cData.CustomerID + "]]></cell>"); response.Append("<cell><![CDATA[" + cData.CustomerName + "]]></cell>"); response.Append("<cell><![CDATA[" + cData.CompanyName + "]]></cell>"); response.Append("<cell><![CDATA[" + cData.Address + "]]></cell>"); response.Append("<cell><![CDATA[" + cData.State + "]]></cell>"); response.Append("<cell><![CDATA[" + cData.City + "]]></cell>"); if (cData.PhoneNumber != null) { response.Append("<cell><![CDATA[" + cData.PhoneNumber + "]]></cell>"); } else { response.Append("<cell><![CDATA[</cell>"); } response.Append("<cell><![CDATA[" + cData.EMail + "]]></cell>"); response.Append("<cell><![CDATA[" + 0 + "]]></cell>"); response.Append("</row>"); index++; } response.Append("</rows>"); Session["posStart"] = index; return(response.ToString()); }