private DataTable GetVendorListTable() { long telHlp = 0; long faxHlp = 0; string telfmt = "000-000-0000"; string szTel = ""; DataTable table = null; DataRow row = null; VendorList thevendorlist = null; List<VendorList> vendorList = new List<VendorList>(); var qryVendors = db.VendorsContactAddresses.Join(db.Vendors, ctad => ctad.VendorId, cst => cst.Id, (ctad, cst) => new { ctad, cst }).OrderBy(cact => cact.cst.VendorNo); if (qryVendors.Count() > 0) { foreach (var item in qryVendors) { if (string.IsNullOrEmpty(item.ctad.Tel)) { szTel = "0"; } else { szTel = item.ctad.Tel; } telHlp = Convert.ToInt64(szTel); szTel = string.Format("{0}", telHlp.ToString(telfmt)); thevendorlist = new VendorList(); thevendorlist.Id = item.cst.Id; thevendorlist.VendorNo = item.cst.VendorNo; thevendorlist.CompanyName = item.ctad.CompanyName; thevendorlist.FirstName = item.ctad.FirstName; thevendorlist.LastName = item.ctad.LastName; thevendorlist.State = item.ctad.State; thevendorlist.Country = item.ctad.Country; thevendorlist.Tel = szTel; vendorList.Add(thevendorlist); } } table = new DataTable("VendorList"); // Set the header DataColumn col01 = new DataColumn("VendorNo", 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 vendorList) { row = table.NewRow(); row["VendorNo"] = item.VendorNo; 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; }
public PartialViewResult VendorList(int? page) { int pageIndex = 0; int pageSize = PageSize; VendorList thevendorlist = null; List<VendorList> vendorList = new List<VendorList>(); var qryVendors = db.VendorsContactAddresses.Join(db.Vendors, ctad => ctad.VendorId, cst => cst.Id, (ctad, cst) => new { ctad, cst }).OrderBy(cact => cact.cst.VendorNo); if (qryVendors.Count() > 0) { foreach (var item in qryVendors) { thevendorlist = new VendorList(); thevendorlist.Id = item.cst.Id; thevendorlist.VendorNo = item.cst.VendorNo; thevendorlist.CompanyName = item.ctad.CompanyName; thevendorlist.FirstName = item.ctad.FirstName; thevendorlist.LastName = item.ctad.LastName; thevendorlist.State = item.ctad.State; thevendorlist.Country = item.ctad.Country; thevendorlist.Tel = item.ctad.Tel; vendorList.Add(thevendorlist); } } //Set the page if (page == null) { pageIndex = 1; } else { pageIndex = Convert.ToInt32(page); } var onePageOfData = vendorList.ToPagedList(pageIndex, pageSize); ViewBag.OnePageOfData = onePageOfData; return PartialView(vendorList.ToPagedList(pageIndex, pageSize)); }