public PartialViewResult CustomerList(int? page) { int pageIndex = 0; int pageSize = PageSize; CustomerList thecustomerlist = null; List<CustomerList> customerList = new List<CustomerList>(); var qryCustomers = db.CustomersContactAddresses.Join(db.Customers, ctad => ctad.CustomerId, cst => cst.Id, (ctad, cst) => new { ctad, cst }).OrderBy(cact => cact.cst.CustomerNo); if (qryCustomers.Count() > 0) { foreach (var item in qryCustomers) { thecustomerlist = new CustomerList(); thecustomerlist.Id = item.cst.Id; thecustomerlist.CustomerNo = item.cst.CustomerNo; thecustomerlist.CompanyName = item.ctad.CompanyName; thecustomerlist.FirstName = item.ctad.FirstName; thecustomerlist.LastName = item.ctad.LastName; thecustomerlist.State = item.ctad.State; thecustomerlist.Country = item.ctad.Country; thecustomerlist.Tel = item.ctad.Tel; customerList.Add(thecustomerlist); } } //Set the page if (page == null) { pageIndex = 1; } else { pageIndex = Convert.ToInt32(page); } var onePageOfData = customerList.ToPagedList(pageIndex, pageSize); ViewBag.OnePageOfData = onePageOfData; return PartialView(customerList.ToPagedList(pageIndex, pageSize)); }
private DataTable GetCustomerListTable() { long telHlp = 0; long faxHlp = 0; string telfmt = "000-000-0000"; string szTel = string.Empty; DataTable table = null; DataRow row = null; CustomerList thecustomerlist = null; List<CustomerList> customerList = new List<CustomerList>(); var qryCustomers = db.CustomersContactAddresses.Join(db.Customers, ctad => ctad.CustomerId, cst => cst.Id, (ctad, cst) => new { ctad, cst }).OrderBy(cact => cact.cst.CustomerNo); if (qryCustomers.Count() > 0) { foreach (var item in qryCustomers) { if (string.IsNullOrEmpty(item.ctad.Tel)) { szTel = "0"; } else { szTel = item.ctad.Tel; } telHlp = Convert.ToInt64(szTel); szTel = string.Format("{0}", telHlp.ToString(telfmt)); thecustomerlist = new CustomerList(); thecustomerlist.Id = item.cst.Id; thecustomerlist.CustomerNo = item.cst.CustomerNo; thecustomerlist.CompanyName = item.ctad.CompanyName; thecustomerlist.FirstName = item.ctad.FirstName; thecustomerlist.LastName = item.ctad.LastName; thecustomerlist.State = item.ctad.State; thecustomerlist.Country = item.ctad.Country; thecustomerlist.Tel = szTel; customerList.Add(thecustomerlist); } } table = new DataTable("CustomerList"); // Set the header DataColumn col01 = new DataColumn("CustomerNo", System.Type.GetType("System.String")); DataColumn col02 = new DataColumn("CompanyName", System.Type.GetType("System.String")); DataColumn col03 = new DataColumn("ContactName", System.Type.GetType("System.String")); DataColumn col04 = new DataColumn("Tel", System.Type.GetType("System.String")); DataColumn col05 = new DataColumn("State", System.Type.GetType("System.String")); DataColumn col06 = new DataColumn("Country", System.Type.GetType("System.String")); table.Columns.Add(col01); table.Columns.Add(col02); table.Columns.Add(col03); table.Columns.Add(col04); table.Columns.Add(col05); table.Columns.Add(col06); //Set the data row foreach (var item in customerList) { row = table.NewRow(); row["CustomerNo"] = item.CustomerNo; row["CompanyName"] = item.CompanyName; row["ContactName"] = string.Format("{0} {1}", item.FirstName, item.LastName); ; row["Tel"] = item.Tel; row["State"] = item.State; row["Country"] = item.Country; table.Rows.Add(row); } return table; }