public ActionResult _AjaxList(GridCommand command, SequenceMasterSearchModel searchModel)
 {
     this.GetCommand(ref command, searchModel);
     if (!this.CheckSearchModelIsNull(searchModel))
     {
         return PartialView(new GridModel(new List<SequenceMaster>()));
     }
     SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<SequenceMaster>(searchStatementModel, command));
 }
 public ActionResult List(GridCommand command, SequenceMasterSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     if (this.CheckSearchModelIsNull(searchCacheModel.SearchObject))
     {
         TempData["_AjaxMessage"] = "";
     }
     else
     {
         SaveWarningMessage(Resources.SYS.ErrorMessage.Errors_NoConditions);
     }
     if (searchCacheModel.isBack == true)
     {
         ViewBag.Page = searchCacheModel.Command.Page == 0 ? 1 : searchCacheModel.Command.Page;
     }
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
 public ActionResult DetailList(GridCommand command, SequenceMasterSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     if (this.CheckSearchModelIsNull(searchCacheModel.SearchObject))
     {
         TempData["_AjaxMessage"] = "";
         
         IList<SequenceDetail> list = genericMgr.FindAll<SequenceDetail>(PrepareSearchDetailStatement(command, searchModel)); //GetPageData<OrderDetail>(searchStatementModel, command);
         int value = Convert.ToInt32(base.systemMgr.GetEntityPreferenceValue(EntityPreference.CodeEnum.MaxRowSizeOnPage));
         if (list.Count > value)
         {
             SaveWarningMessage(string.Format(Resources.EXT.ControllerLan.Con_DataExceedRow, value));
         }
         return View(list.Take(value));
     }
     else
     {
         SaveWarningMessage(Resources.SYS.ErrorMessage.Errors_NoConditions);
         return View(new List<SequenceDetail>());
     }
 }
        private string PrepareSearchDetailStatement(GridCommand command, SequenceMasterSearchModel searchModel)
        {
            StringBuilder Sb = new StringBuilder();
            string whereStatement = " select  d from SequenceDetail as d  where exists (select 1 from SequenceMaster  as o"
                                    + " where o.SequenceNo=d.SequenceNo ";

            Sb.Append(whereStatement);
            if (searchModel.Flow != null)
            {
                Sb.Append(string.Format(" and o.Flow = '{0}'", searchModel.Flow));
            }

            if (searchModel.Status != null)
            {
                Sb.Append(string.Format(" and o.Status = '{0}'", searchModel.Status));
            }
            if (!string.IsNullOrEmpty(searchModel.SequenceNo))
            {
                Sb.Append(string.Format(" and o.SequenceNo like '{0}%'", searchModel.SequenceNo));
            }
            if (!string.IsNullOrEmpty(searchModel.PartyFrom))
            {
                Sb.Append(string.Format(" and o.PartyFrom = '{0}'", searchModel.PartyFrom));
            }
            if (!string.IsNullOrEmpty(searchModel.PartyTo))
            {
                Sb.Append(string.Format(" and o.PartyTo = '{0}'", searchModel.PartyTo));

            }
            string str = Sb.ToString();
            
            SecurityHelper.AddPartyFromAndPartyToPermissionStatement(ref str, "o", "Type", "o", "PartyFrom", "o", "PartyTo", com.Sconit.CodeMaster.OrderType.Procurement, true);
            if (searchModel.StartTime != null & searchModel.EndTime != null)
            {
                Sb.Append(string.Format(" and o.CreateDate between '{0}' and '{1}'", searchModel.StartTime, searchModel.EndTime));
                // HqlStatementHelper.AddBetweenStatement("StartTime", searchModel.DateFrom, searchModel.DateTo, "o", ref whereStatement, param);
            }
            else if (searchModel.StartTime != null & searchModel.EndTime == null)
            {
                Sb.Append(string.Format(" and o.CreateDate >= '{0}'", searchModel.StartTime));

            }
            else if (searchModel.StartTime == null & searchModel.EndTime != null)
            {
                Sb.Append(string.Format(" and o.CreateDate <= '{0}'", searchModel.EndTime));

            }

            Sb.Append(" )");

            if (!string.IsNullOrEmpty(searchModel.Item))
            {
                Sb.Append(string.Format(" and  d.Item like '{0}%'", searchModel.Item));

            }
            if (!string.IsNullOrEmpty(searchModel.TraceCode))
            {
                Sb.Append(string.Format(" and  d.TraceCode like '{0}%'", searchModel.TraceCode));

            }
            return Sb.ToString();
        }
        private SearchStatementModel PrepareSearchStatement(GridCommand command, SequenceMasterSearchModel searchModel)
        {
            string whereStatement = string.Empty;
            IList<object> param = new List<object>();
            
            SecurityHelper.AddPartyFromAndPartyToPermissionStatement(ref whereStatement, "s", "OrderType", "s", "PartyFrom", "s", "PartyTo", com.Sconit.CodeMaster.OrderType.Procurement, false);

            HqlStatementHelper.AddLikeStatement("SequenceNo", searchModel.SequenceNo, HqlStatementHelper.LikeMatchMode.Start, "s", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("Flow", searchModel.Flow, "s", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("PartyFrom", searchModel.PartyFrom, "s", ref whereStatement, param);
            HqlStatementHelper.AddEqStatement("PartyTo", searchModel.PartyTo, "s", ref whereStatement, param);

            if (searchModel.StartTime!= null & searchModel.EndTime != null)
            {
                HqlStatementHelper.AddBetweenStatement("CreateDate", searchModel.StartTime, searchModel.EndTime, "s", ref whereStatement, param);
            }
            else if (searchModel.StartTime != null & searchModel.EndTime == null)
            {
                HqlStatementHelper.AddGeStatement("CreateDate", searchModel.StartTime, "s", ref whereStatement, param);
            }
            else if (searchModel.StartTime == null & searchModel.EndTime != null)
            {
                HqlStatementHelper.AddLeStatement("CreateDate", searchModel.EndTime, "s", ref whereStatement, param);
            }
            if (command.SortDescriptors.Count > 0)
            {
                if (command.SortDescriptors[0].Member == "SequenceMasterStatusDescription")
                {
                    command.SortDescriptors[0].Member = "Status";
                }
                else if (command.SortDescriptors[0].Member == "OrderTypeDescription")
                {
                    command.SortDescriptors[0].Member = "OrderType";
                }
            }


            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);
            if (command.SortDescriptors.Count == 0)
            {
                sortingStatement = " order by s.CreateDate desc";
            }
            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement = selectStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }