public List <Models.CustomerView1> SearchCus(Models.CustomerView1 cus) { Dao.CusDao cusDao = new Dao.CusDao(); var dt = cusDao.GetCusGridByCondition(cus); return(this.MapCusData(dt)); }
public DataTable GetCusGridByCondition(Models.CustomerView1 cus) { DataTable dt = new DataTable(); string sql = @"SELECT * FROM Sales.Customers a JOIN CodeTable b ON a.ContactTitle = b.CodeID WHERE (CustomerID = @CustomerID OR @CustomerID = 0) AND (CompanyName LIKE @CompanyName OR @CompanyName IS NULL) AND (ContactName LIKE @ContactName OR @ContactName IS NULL) AND (ContactTitle = @ContactTitle OR @ContactTitle IS NULL ) AND b.CodeType='Title' "; try { using (SqlConnection conn = new SqlConnection(this.DBConn)) { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.Add(new SqlParameter("@CustomerID", cus.CustomerID == 0 ? 0 : cus.CustomerID)); cmd.Parameters.Add(new SqlParameter("@CompanyName", cus.CompanyName == null ? null : cus.CompanyName)); cmd.Parameters.Add(new SqlParameter("@ContactName", cus.ContactName == null ? null : cus.ContactName)); cmd.Parameters.Add(new SqlParameter("@ContactTitle", cus.ContactTitle == null ? string.Empty : cus.ContactTitle)); SqlDataAdapter sqlAdapter = new SqlDataAdapter(cmd); sqlAdapter.Fill(dt); conn.Close(); } } catch (Exception e) { var a = e; } return(dt); }
public JsonResult SearchCus(Models.Customers cus) { Services.CusServices cusService = new Services.CusServices(); var cusData = new Models.CustomerView1(); cusData.CustomerID = Convert.ToInt16(cus.CustomerID); cusData.CompanyName = "%" + Convert.ToString(cus.CompanyName) + "%"; cusData.ContactName = "%" + Convert.ToString(cus.ContactName) + "%"; cusData.ContactTitle = "000" + Convert.ToString(cus.ContactTitle); var data = cusService.SearchCus(cusData); return(this.Json(data, JsonRequestBehavior.AllowGet)); }