Exemplo n.º 1
0
        public static void SetPartyToSearchCriteria(DetachedCriteria selectCriteria, DetachedCriteria selectCountCriteria, string partyToCode, string orderType, string userCode)
        {
            if (partyToCode != null && partyToCode.Trim() != string.Empty)
            {
                //如果用户选择了PartyTo,直接用用户选择的值查询
                selectCriteria.Add(Expression.Eq("pt.Code", partyToCode.Trim()));
                selectCountCriteria.Add(Expression.Eq("pt.Code", partyToCode.Trim()));
            }
            else  //如果用户没有选择PartyFrom,根据用户权限过滤
            {
                if (orderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
                {
                    //供货路线
                    DetachedCriteria[] ptCrieteria = SecurityHelper.GetPartyPermissionCriteria(userCode,
                                                                                               BusinessConstants.CODE_MASTER_PARTY_TYPE_VALUE_REGION, BusinessConstants.CODE_MASTER_PARTY_TYPE_VALUE_CUSTOMER);

                    selectCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                            ));

                    selectCountCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                            ));
                }
                else if (orderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
                {
                    //发货路线
                    DetachedCriteria[] ptCrieteria = SecurityHelper.GetPartyPermissionCriteria(userCode,
                                                                                               BusinessConstants.CODE_MASTER_PARTY_TYPE_VALUE_REGION, BusinessConstants.CODE_MASTER_PARTY_TYPE_VALUE_CUSTOMER);

                    selectCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                            ));

                    selectCountCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                            ));
                }
                else if (orderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PRODUCTION)
                {
                    DetachedCriteria[] regionCrieteria = SecurityHelper.GetRegionPermissionCriteria(userCode);

                    //生产
                    selectCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));

                    selectCountCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));
                }
                else if (orderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_INSPECTION)
                {
                    //检验路线
                    DetachedCriteria[] regionCrieteria = SecurityHelper.GetRegionPermissionCriteria(userCode);
                    selectCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));

                    selectCountCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));
                }
                else if (orderType == BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER)
                {
                    //移库路线
                    DetachedCriteria[] regionCrieteria = SecurityHelper.GetRegionPermissionCriteria(userCode);
                    selectCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));

                    selectCountCriteria.Add(
                        Expression.Or(
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[0]),
                            Subqueries.PropertyIn("pt.Code", regionCrieteria[1])
                            ));
                }
                //else if (orderType == BusinessConstants.ORDER_MODULETYPE_VALUE_PROCUREMENTCONFIRM)
                //{
                //    //发货确认
                //    DetachedCriteria[] ptCrieteria = SecurityHelper.GetPartyPermissionCriteria(userCode, BusinessConstants.CODE_MASTER_PARTY_TYPE_VALUE_CUSTOMER);

                //    selectCriteria.Add(
                //        Expression.Or(
                //            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                //            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                //    ));

                //    selectCountCriteria.Add(
                //        Expression.Or(
                //            Subqueries.PropertyIn("pt.Code", ptCrieteria[0]),
                //            Subqueries.PropertyIn("pt.Code", ptCrieteria[1])
                //    ));
                //}
            }
        }
Exemplo n.º 2
0
        public static object[] CollectDetailParam(IDictionary <string, string> dic, List <string> statusList, List <string> typeList, bool newItem)
        {
            string orderNo       = (dic == null || !dic.ContainsKey("OrderNo")) ? null : dic["OrderNo"];
            string flow          = (dic == null || !dic.ContainsKey("Flow")) ? null : dic["Flow"];
            string partyFrom     = (dic == null || !dic.ContainsKey("PartyFrom")) ? null : dic["PartyFrom"];
            string partyTo       = (dic == null || !dic.ContainsKey("PartyTo")) ? null : dic["PartyTo"];
            string moduleType    = (dic == null || !dic.ContainsKey("ModuleType")) ? null : dic["ModuleType"];
            string locationFrom  = (dic == null || !dic.ContainsKey("LocationFrom")) ? null : dic["LocationFrom"];
            string locationTo    = (dic == null || !dic.ContainsKey("LocationTo")) ? null : dic["LocationTo"];
            string moduleSubType = (dic == null || !dic.ContainsKey("ModuleSubType")) ? null : dic["ModuleSubType"];
            string priority      = (dic == null || !dic.ContainsKey("Priority")) ? null : dic["Priority"];
            string createUser    = (dic == null || !dic.ContainsKey("CreateUser")) ? null : dic["CreateUser"];
            string startDate     = (dic == null || !dic.ContainsKey("StartDate")) ? null : dic["StartDate"];
            string endDate       = (dic == null || !dic.ContainsKey("EndDate")) ? null : dic["EndDate"];
            string currentUser   = (dic == null || !dic.ContainsKey("CurrentUser")) ? null : dic["CurrentUser"];

            DetachedCriteria selectCriteria      = DetachedCriteria.For(typeof(OrderDetail));
            DetachedCriteria selectCountCriteria = DetachedCriteria.For(typeof(OrderDetail))
                                                   .SetProjection(Projections.Count("Id"));
            IDictionary <string, string> alias = new Dictionary <string, string>();

            selectCriteria.CreateAlias("OrderHead", "od");
            selectCriteria.CreateAlias("od.PartyFrom", "pf");
            selectCriteria.CreateAlias("od.PartyTo", "pt");
            selectCountCriteria.CreateAlias("OrderHead", "od");
            selectCountCriteria.CreateAlias("od.PartyFrom", "pf");
            selectCountCriteria.CreateAlias("od.PartyTo", "pt");
            alias.Add("PartyFrom", "pf");
            alias.Add("PartyTo", "pt");

            #region 设置订单Type查询条件
            selectCriteria.Add(Expression.In("od.Type", typeList));
            selectCountCriteria.Add(Expression.In("od.Type", typeList));
            #endregion

            #region 设置订单SubType查询条件
            if (moduleSubType != null && moduleSubType != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.SubType", moduleSubType));
                selectCountCriteria.Add(Expression.Eq("od.SubType", moduleSubType));
            }
            #endregion

            selectCriteria.Add(Expression.Eq("od.IsNewItem", newItem));
            selectCountCriteria.Add(Expression.Eq("od.IsNewItem", newItem));

            if (orderNo != null && orderNo != string.Empty)
            {
                selectCriteria.Add(Expression.Like("od.OrderNo", orderNo, MatchMode.Start));
                selectCountCriteria.Add(Expression.Like("od.OrderNo", orderNo, MatchMode.Start));
            }

            if (priority != null && priority != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.Priority", priority));
                selectCountCriteria.Add(Expression.Eq("od.Priority", priority));
            }

            #region partyFrom
            if (partyFrom != null && partyFrom != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("pf.Code", partyFrom));
                selectCountCriteria.Add(Expression.Eq("pf.Code", partyFrom));
            }
            else if (moduleType != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_PROCUREMENT)
            {
                #region partyFrom
                SecurityHelper.SetPartyFromSearchCriteria(
                    selectCriteria, selectCountCriteria, partyFrom, moduleType, currentUser);
                #endregion
            }
            #endregion

            #region partyTo
            if (partyTo != null && partyTo != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("pt.Code", partyTo));
                selectCountCriteria.Add(Expression.Eq("pt.Code", partyTo));
            }
            else if (moduleType != BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_DISTRIBUTION)
            {
                #region partyTo
                SecurityHelper.SetPartyToSearchCriteria(
                    selectCriteria, selectCountCriteria, partyTo, moduleType, currentUser);
                #endregion
            }
            #endregion

            if (locationFrom != null && locationFrom != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.LocationFrom.Code", locationFrom));
                selectCountCriteria.Add(Expression.Eq("od.LocationFrom.Code", locationFrom));
            }

            if (locationTo != null && locationTo != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.LocationTo.Code", locationTo));
                selectCountCriteria.Add(Expression.Eq("od.LocationTo.Code", locationTo));
            }

            if (flow != null && flow != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.Flow", flow));
                selectCountCriteria.Add(Expression.Eq("od.Flow", flow));
            }

            if (createUser != null && createUser != string.Empty)
            {
                selectCriteria.Add(Expression.Eq("od.CreateUser.Code", createUser));
                selectCountCriteria.Add(Expression.Eq("od.CreateUser.Code", createUser));
            }

            #region date
            if (startDate != null && startDate != string.Empty)
            {
                selectCriteria.Add(Expression.Ge("od.CreateDate", DateTime.Parse(startDate)));
                selectCountCriteria.Add(Expression.Ge("od.CreateDate", DateTime.Parse(startDate)));
            }
            if (endDate != null && endDate != string.Empty)
            {
                selectCriteria.Add(Expression.Lt("od.CreateDate", DateTime.Parse(endDate).AddDays(1)));
                selectCountCriteria.Add(Expression.Lt("od.CreateDate", DateTime.Parse(endDate).AddDays(1)));
            }
            #endregion

            #region status
            if (statusList != null && statusList.Count > 0)
            {
                selectCriteria.Add(Expression.In("od.Status", statusList));
                selectCountCriteria.Add(Expression.In("od.Status", statusList));
            }
            #endregion
            return(new object[] { selectCriteria, selectCountCriteria, alias, false });
        }