public ActionResult List(GridCommand command, OrderItemTraceSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
 public ActionResult _AjaxList(GridCommand command, OrderItemTraceSearchModel searchModel)
 {
     SearchStatementModel searchStatementModel = this.PrepareSearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<OrderItemTraceResult>(searchStatementModel, command));
 }
        private SearchStatementModel PrepareSearchStatement(GridCommand command, OrderItemTraceSearchModel searchModel)
        {
            string whereStatement = " where 1=1 ";

            IList<object> param = new List<object>();
            string traceCodeStatement = string.Empty;
            if (!string.IsNullOrWhiteSpace(searchModel.TraceCodes))
            {
                string traceCodes = searchModel.TraceCodes.Replace("\r\n", ",");
                traceCodes = traceCodes.Replace("\n", ",");
                string[] traceCodeArr = traceCodes.Split(',');
                for (int i = 0; i < traceCodeArr.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(traceCodeStatement))
                    {
                        traceCodeStatement = " and TraceCode in (? ";
                    }
                    else
                    {
                        traceCodeStatement += " ,? ";
                    }
                    param.Add(traceCodeArr[i]);
                }
                whereStatement += traceCodeStatement + " ) ";
            }

            string supplierStatement = string.Empty;
            if (!string.IsNullOrWhiteSpace(searchModel.Suppliers))
            {
                string suppliers = searchModel.Suppliers.Replace("\r\n", ",");
                suppliers = suppliers.Replace("\n", ",");
                string[] supplierArr = suppliers.Split(',');
                for (int i = 0; i < supplierArr.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(supplierStatement))
                    {
                        supplierStatement = " and Supplier in (? ";
                    }
                    else
                    {
                        supplierStatement += " ,? ";
                    }
                    param.Add(supplierArr[i]);
                }
                whereStatement += supplierStatement + " ) ";  
            }

            string lotNoStatement = string.Empty;
            if (!string.IsNullOrWhiteSpace(searchModel.LotNos))
            {
                string lotNos = searchModel.LotNos.Replace("\r\n", ",");
                lotNos = lotNos.Replace("\n", ",");
                string[] lotNoArr = lotNos.Split(',');
                for (int i = 0; i < lotNoArr.Length; i++)
                {
                    if (string.IsNullOrWhiteSpace(lotNoStatement))
                    {
                        lotNoStatement = " and LotNo in (? ";
                    }
                    else
                    {
                        lotNoStatement += " ,? ";
                    }
                    param.Add(lotNoArr[i]);
                }
                whereStatement += lotNoStatement + " ) ";
            }

            HqlStatementHelper.AddLikeStatement("BarCode", searchModel.BarCode,HqlStatementHelper.LikeMatchMode.Anywhere, "r", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("Item", searchModel.Item, "r", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("OpReference", searchModel.OpReference, "r", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("TraceCode", searchModel.TraceCode, "r", ref whereStatement, param);

            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement = selectStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }