public CustController() { repo = RepositoryHelper.Get客戶資料Repository(); ViewBag.CategoryList = from item in repo.Get客戶分類List() select new SelectListItem { Text = item, Value = item }; }
// GET: 客戶資料 public ActionResult Index(string clientName, string clientType, string sortOrder) { #region 排序欄位 ViewBag.sort客戶名稱 = string.IsNullOrEmpty(sortOrder) ? "客戶名稱_desc" : ""; ViewBag.sort統一編號 = sortOrder == "統一編號" ? "統一編號_desc" : "統一編號"; ViewBag.sort電話 = sortOrder == "電話" ? "電話_desc" : "電話"; ViewBag.sort傳真 = sortOrder == "傳真" ? "傳真_desc" : "傳真"; ViewBag.sort地址 = sortOrder == "地址" ? "地址_desc" : "地址"; ViewBag.sortEmail = sortOrder == "Email" ? "Email_desc" : "Email"; ViewBag.sort客戶分類 = sortOrder == "客戶分類" ? "客戶分類_desc" : "客戶分類"; #endregion var data = 客戶repo.GetQueryData(clientName, clientType, sortOrder); List <SelectListItem> type = 客戶repo.Get客戶分類List(); ViewBag.clientType = type; return(View(data)); }
// GET: 客戶資料 public ActionResult Index(string sortOrder, string SearchValue, string 分類ListSelect) { ViewBag.客戶名稱Sort = String.IsNullOrEmpty(sortOrder) ? "客戶名稱_desc" : ""; ViewBag.統一編號Sort = sortOrder == "統一編號" ? "統一編號_desc" : "統一編號"; ViewBag.電話Sort = sortOrder == "電話" ? "電話_desc" : "電話"; ViewBag.傳真Sort = sortOrder == "傳真" ? "傳真_desc" : "傳真"; ViewBag.地址Sort = sortOrder == "地址" ? "地址_desc" : "地址"; ViewBag.EmailSort = sortOrder == "Email" ? "Email_desc" : "Email"; ViewBag.客戶分類Sort = sortOrder == "客戶分類" ? "客戶分類_desc" : "客戶分類"; var Custs = String.IsNullOrEmpty(分類ListSelect) ? repo.All() : repo.Find分類(分類ListSelect); if (!String.IsNullOrEmpty(SearchValue)) { Custs = Custs.Where(c => c.客戶名稱.Contains(SearchValue) || c.統一編號.Contains(SearchValue) || c.電話.Contains(SearchValue) || c.傳真.Contains(SearchValue) || c.地址.Contains(SearchValue) || c.Email.Contains(SearchValue) ); } ViewData["分類List"] = repo.Get客戶分類List(); switch (sortOrder) { case "客戶名稱_desc": Custs = Custs.OrderByDescending(s => s.客戶名稱); break; case "統一編號": Custs = Custs.OrderBy(s => s.統一編號); break; case "統一編號_desc": Custs = Custs.OrderByDescending(s => s.統一編號); break; case "電話": Custs = Custs.OrderBy(s => s.電話); break; case "電話_desc": Custs = Custs.OrderByDescending(s => s.電話); break; case "傳真": Custs = Custs.OrderBy(s => s.傳真); break; case "傳真_desc": Custs = Custs.OrderByDescending(s => s.傳真); break; case "地址": Custs = Custs.OrderBy(s => s.地址); break; case "地址_desc": Custs = Custs.OrderByDescending(s => s.地址); break; case "Email": Custs = Custs.OrderBy(s => s.Email); break; case "Email_desc": Custs = Custs.OrderByDescending(s => s.Email); break; case "客戶分類": Custs = Custs.OrderBy(s => s.客戶分類); break; case "客戶分類_desc": Custs = Custs.OrderByDescending(s => s.客戶分類); break; default: Custs = Custs.OrderBy(s => s.客戶名稱); break; } TempData["ExcelModel"] = Custs.ToList(); return(View(Custs.ToList())); }