public List <Models.Customer> GetCustomerDataByCondition(Models.Customer customer) { DataTable dt = new DataTable(); var sql = @"SELECT CustomerID,CompanyName,ContactName,CodeVal FROM Sales.Customers a join dbo.CodeTable b on a.ContactTitle = b.CodeId WHERE CodeType = 'TITLE' and (CustomerID LIKE '%'+@CustomerID+'%' OR CustomerID = '') AND (CompanyName LIKE '%'+@CompanyName+'%' OR CompanyName='') AND (ContactName LIKE '%'+@ContactName+'%' OR ContactName='') AND (CodeVal LIKE '%' + @CodeVal+'%' OR CodeVal='') AND ContactTitle = ''"; using (SqlConnection conn = new SqlConnection(this.GetDBConnectionString())) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add(new SqlParameter("@CustomerID", customer.CustomerID == null ? string.Empty :customer.CustomerID)); cmd.Parameters.Add(new SqlParameter("@CompanyName", customer.CompanyName == null ? string.Empty : customer.CompanyName)); cmd.Parameters.Add(new SqlParameter("@ContactName", customer.ContactName == null ? string.Empty : customer.ContactName)); cmd.Parameters.Add(new SqlParameter("@CodeVal", customer.CodeVal == null ? string.Empty : customer.CodeVal)); SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); sqlAdapter.Fill(dt); conn.Close(); } Service.CustomerService cus = new Service.CustomerService(); return(cus.MapCustomerData(dt)); }
public JsonResult DoInsertCustomer(Models.Customer customer) { Service.CustomerService customerService = new Service.CustomerService(); int orderid = customerService.InsertCustomer(customer); ModelState.Clear(); JsonResult result = this.Json(orderid, JsonRequestBehavior.AllowGet); return(result); }
/// <summary> /// Read /// </summary> /// <param name="arg"></param> /// <returns></returns> public JsonResult Read(Models.CustomerSearchArg arg) { try { Service.CustomerService customerService = new Service.CustomerService(); JsonResult result = this.Json(customerService.GetCustomerByCondition(arg), JsonRequestBehavior.AllowGet); return(result); } catch (Exception) { return(this.Json(false)); } }
//查詢 public JsonResult getQueryData(Models.Customer customer) { try { Service.CustomerService customerservice = new Service.CustomerService(); JsonResult json = this.Json(customerservice.GetCustomerData(customer), JsonRequestBehavior.AllowGet); return(json); } catch (Exception) { return(Json(false)); } }
public JsonResult DeleteCustomer(Models.DeleteJson customer) { try { string customerId = customer.CustomerId; Service.CustomerService orderService = new Service.CustomerService(); int result = orderService.DeleteCustomerById(customerId); if (result >= 1) { return(this.Json(true)); } else { return(this.Json(false)); } } catch (Exception) { return(this.Json(false)); } }
public CustomerController(Service.CustomerService _customerService) { customerService = _customerService; }