/// <summary>
        /// 以entities为数据打印(例如滞箱费减免联系单)
        /// </summary>
        /// <param name="entities"></param>
        public void FillDataSet(object[] entities)
        {
            ISearchExpression se = null;

            foreach (object entity in entities)
            {
                if (se == null)
                {
                    se = SearchExpression.Parse(EntityHelper.ReplaceEntity(m_reportInfo.SearchExpression, entity));
                }
                else
                {
                    se = SearchExpression.Or(se, SearchExpression.Parse(EntityHelper.ReplaceEntity(m_reportInfo.SearchExpression, entity)));
                }
            }
            for (int i = 0; i < m_reportDataInfos.Count; ++i)
            {
                object data = m_sms[i].GetData(se, null);
                System.Collections.IEnumerable dataList = data as System.Collections.IEnumerable;
                if (dataList == null)
                {
                    dataList = (data as System.Data.DataTable).DefaultView;
                }

                FillDataSet(i, dataList);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ISearchExpression GetSearchExpression()
        {
            if (this.Value != null && this.Value != this.NullValue && this.Value.ToString() != this.NullText)
            {
                GridColumnInfo info = this.ParentColumn.Tag as GridColumnInfo;
                if (info != null)
                {
                    string searchPropertyName = GetSearchPropertyName(info);

                    ISearchExpression ret = SearchExpression.Like(searchPropertyName, this.Value);

                    object searchValue = this.Value;
                    if (searchValue != null && info.CellViewerManager == "Combo")
                    {
                        string nvName = Feng.Windows.Utils.GridColumnInfoHelper.GetNameValueMappingName(info, true);
                        searchValue = Feng.Utils.NameValueControlHelper.GetMultiValue(nvName, searchValue.ToString());

                        ret = SearchExpression.Or(ret, SearchExpression.Eq(searchPropertyName, searchValue));
                    }

                    return(ret);
                }
            }

            return(null);
            //object value;
            //if (this.IsBeingEdited)
            //{
            //    value = ((FilterEditor)this.CellEditorManager).TemplateControl.SelectedValue;
            //}
            //else
            //{
            //    value = this.Value;
            //}

            //if (m_filterItems.ContainsKey(value.ToString()))
            //{
            //    return m_filterItems[value.ToString()];
            //}
            //else
            //{
            //    // 因为Filter有保存,但是里面的内容有变化,所以可能产生无内容的情况
            //    // this.Value = s_anyText; // 但是还是保存Value
            //    return m_filterItems[s_anyText];
            //}
        }
        //private void ProcessCmd(DbCommand cmd)
        //{
        //    foreach (string s in m_funcParams)
        //    {
        //        if (!cmd.Parameters.Contains(s))
        //        {
        //            cmd.CommandText = cmd.CommandText.Replace(s, "default");
        //        }
        //        else
        //        {
        //            // remove like %
        //            string likeString = cmd.Parameters[s].Value as string;
        //            if (!string.IsNullOrEmpty(likeString))
        //            {
        //                if (likeString[0] == '%' && likeString[likeString.Length - 1] == '%')
        //                {
        //                    cmd.Parameters[s].Value = likeString.Substring(1, likeString.Length - 2);
        //                }
        //            }

        //            // remove where clause
        //            int idx = cmd.CommandText.IndexOf("WHERE");
        //            idx = cmd.CommandText.IndexOf(s, idx);

        //            int idx2 = idx;

        //            // jump to "=, >="
        //            idx2--;
        //            while (cmd.CommandText[idx2] == ' ')
        //                idx2--;

        //            // jump to space
        //            idx2--;
        //            while (cmd.CommandText[idx2] != ' ')
        //                idx2--;

        //            // jump to propertyName
        //            idx2--;
        //            while (cmd.CommandText[idx2] == ' ')
        //                idx2--;

        //            // jump to space
        //            idx2--;
        //            while (cmd.CommandText[idx2] != ' ')
        //                idx2--;

        //            cmd.CommandText = cmd.CommandText.Replace(cmd.CommandText.Substring(idx2 + 1, idx - idx2 - 1 + s.Length), "1 = 1");
        //        }
        //    }
        //}

        private ISearchExpression RemoveFunctionParamSearchExpression(ISearchExpression se, Dictionary <string, object> deletedParam)
        {
            if (se == null)
            {
                return(null);
            }
            if (se is LogicalExpression)
            {
                LogicalExpression le = se as LogicalExpression;
                ISearchExpression ls = RemoveFunctionParamSearchExpression(le.LeftHandSide, deletedParam);
                ISearchExpression rs = RemoveFunctionParamSearchExpression(le.RightHandSide, deletedParam);
                switch (le.LogicOperator)
                {
                case LogicalOperator.And:
                    return(SearchExpression.And(ls, rs));

                case LogicalOperator.Or:
                    return(SearchExpression.Or(ls, rs));

                case LogicalOperator.Not:
                    return(SearchExpression.Not(ls));

                default:
                    throw new NotSupportedException("Not Supported LogicalOperator!");
                }
            }
            else if (se is SimpleExpression)
            {
                SimpleExpression cse = se as SimpleExpression;

                string paramName = SearchManager.CreateParamName(cse, null);
                if (Array.IndexOf(m_funcParams, paramName) != -1)
                {
                    deletedParam[paramName] = cse.Values;
                    return(null);
                }
                else
                {
                    return(cse);
                }
            }
            else
            {
                return(se);
            }
        }
        internal static ISearchExpression GetSearchExpressionFromGrid(IArchiveMasterForm sourceForm, GridRelatedAddressInfo info, bool onlyFirstOne)
        {
            if (sourceForm == null)
            {
                throw new ArgumentException("未能找到父窗体!", "sourceForm");
            }

            if (info.RelatedType == GridRelatedType.ByRows)
            {
                if (sourceForm.MasterGrid == null)
                {
                    throw new ArgumentException("未能找到主表格!", "sourceForm");
                }

                List <object> selectedEntities = new List <object>();
                if (sourceForm.MasterGrid.GridControl.SelectedRows.Count == 0)
                {
                    Xceed.Grid.Row     row     = sourceForm.MasterGrid.CurrentRow;
                    Xceed.Grid.DataRow dataRow = row as Xceed.Grid.DataRow;
                    if (dataRow != null && dataRow.Visible &&
                        (Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid) == info.GridLevel || string.IsNullOrEmpty(info.GridLevel)))
                    {
                        selectedEntities.Add(dataRow.Tag);
                    }
                }
                else
                {
                    foreach (Xceed.Grid.Row row in sourceForm.MasterGrid.GridControl.SelectedRows)
                    {
                        if (!row.Visible)
                        {
                            continue;
                        }

                        Xceed.Grid.DataRow dataRow = row as Xceed.Grid.DataRow;
                        if (dataRow == null)
                        {
                            continue;
                        }

                        if (Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid) == info.GridLevel ||
                            string.IsNullOrEmpty(info.GridLevel))
                        {
                            selectedEntities.Add(dataRow.Tag);
                        }
                        else
                        {
                            foreach (Xceed.Grid.DetailGrid dg in dataRow.DetailGrids)
                            {
                                GetDetailGridRows(info, dataRow.DetailGrids[0], selectedEntities);
                            }
                        }

                        if (onlyFirstOne && selectedEntities.Count > 0)
                        {
                            break;
                        }
                    }
                }

                if (selectedEntities.Count == 0)
                {
                    throw new InvalidOperationException("请选择表格行!");
                }


                Dictionary <string, string> exps = new Dictionary <string, string>();
                foreach (object entity in selectedEntities)
                {
                    //if (entity.GetType() != Feng.Utils.ReflectionHelper.GetTypeFromName(info.EntityType))
                    //    continue;

                    string exp = EntityHelper.ReplaceEntity(info.SearchExpression, entity);
                    exps[exp] = exp;
                }
                ISearchExpression se = null;
                foreach (string exp in exps.Keys)
                {
                    ISearchExpression subSearch = SearchExpression.Parse(exp);
                    if (se == null)
                    {
                        se = subSearch;
                    }
                    else
                    {
                        se = SearchExpression.Or(se, subSearch);
                    }
                }
                return(se);

                //string[] fromColumns = info.FromColumnName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //for (int i = 0; i < fromColumns.Length; ++i)
                //{
                //    fromColumns[i] = fromColumns[i].Replace(":", ".");
                //}
                //int count = fromColumns.Length;
                //string[] toColumns = info.ToColumnName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //Debug.Assert(count == toColumns.Length, "FromColumnName必须和ToColumnName内容个数相同");

                //ArrayList[] selected = new ArrayList[count];

                //for (int i = 0; i < count; ++i)
                //{
                //    selected[i] = new ArrayList();
                //    string columnName = fromColumns[i];

                //    foreach (object entity in selectedEntities)
                //    {
                //        object o = EntityHelper.GetPropertyValue(entity, columnName);
                //        //if (o != null && !string.IsNullOrEmpty(o.ToString()))
                //        {
                //            selected[i].Add(o);
                //        }
                //    }
                //}
            }
            else
            {
                throw new NotSupportedException("Not Supported now!");
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="searchConditions"></param>
        /// <param name="searchOrders"></param>
        public virtual void FillSearchConditions(IList <ISearchExpression> searchConditions, IList <ISearchOrder> searchOrders)
        {
            if (Order.HasValue)
            {
                if (Order.Value)
                {
                    searchOrders.Add(SearchOrder.Asc(PropertyNameToSearch));
                }
                else
                {
                    searchOrders.Add(SearchOrder.Desc(PropertyNameToSearch));
                }
            }

            if (IsNull)
            {
                if (!IsNot)
                {
                    if (SearchNullUseFull)
                    {
                        searchConditions.Add(SearchExpression.IsNull(PropertyNameToSearch));
                    }
                    else
                    {
                        string[] ss = this.Navigator.Split(new char[] { '.', ':' }, StringSplitOptions.RemoveEmptyEntries);
                        searchConditions.Add(SearchExpression.IsNull(ss[0]));
                    }
                }
                else
                {
                    searchConditions.Add(SearchExpression.IsNotNull(PropertyNameToSearch));
                }
            }
            else
            {
                if (SelectedDataValue1 == null && SelectedDataValue2 == null)
                {
                    return;
                }

                if (SelectedDataValue1 != null && SelectedDataValue2 == null)
                {
                    if (!IsNot)
                    {
                        searchConditions.Add(SearchExpression.Ge(PropertyNameToSearch, this.SelectedDataValue1));
                    }
                    else
                    {
                        searchConditions.Add(SearchExpression.Lt(PropertyNameToSearch, this.SelectedDataValue1));
                    }
                }
                else if (SelectedDataValue1 == null && SelectedDataValue2 != null)
                {
                    if (!IsNot)
                    {
                        searchConditions.Add(SearchExpression.Le(PropertyNameToSearch, this.SelectedDataValue2));
                    }
                    else
                    {
                        searchConditions.Add(SearchExpression.Gt(PropertyNameToSearch, this.SelectedDataValue2));
                    }
                }
                else
                {
                    if (!IsNot)
                    {
                        searchConditions.Add(SearchExpression.And(SearchExpression.Ge(PropertyNameToSearch, this.SelectedDataValue1),
                                                                  SearchExpression.Le(PropertyNameToSearch, this.SelectedDataValue2)));
                    }
                    else
                    {
                        searchConditions.Add(SearchExpression.Or(SearchExpression.Lt(PropertyNameToSearch, this.SelectedDataValue1),
                                                                 SearchExpression.Gt(PropertyNameToSearch, this.SelectedDataValue2)));
                    }
                }
            }

            if (!string.IsNullOrEmpty(this.AdditionalSearchExpression))
            {
                searchConditions.Add(SearchExpression.Parse(this.AdditionalSearchExpression));
            }
        }
示例#6
0
文件: Helper.cs 项目: qq5013/mERP-HD
        /// <summary>
        /// 根据人员类型(委托人,承运人,收货人)和业务类型(进口,出口。。)生成查询条件
        /// 在"参数备案_人员单位"中有一列是Role,为此客户对应的数据库角色名。
        /// 例如,用户admin属于角色(货代角色1,收货人角色2),则990001(货代1)Role=货代角色1。当用admin登录后,可按照货代1查询
        /// </summary>
        /// <param name="人员类型"></param>
        /// <param name="业务类型"></param>
        /// <returns></returns>
        public static ISearchExpression GetConstraitByRole(人员类型 人员类型, 业务类型 业务类型)
        {
            if (System.Web.HttpContext.Current.User.Identity == null)
            {
                return(null);
            }

            string name = System.Web.HttpContext.Current.User.Identity.Name;

            //name = "100000";

            string[] roles;
            using (var pm = new Feng.UserManager.ProviderManager())
            {
                roles = pm.DefaultProvider.CreateUserManager().GetRoles(System.Web.Security.Membership.ApplicationName, name);
            }

            System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM 参数备案_人员单位 WHERE Role IN (");

            if (roles.Length == 0)
            {
                return(null);
            }

            for (int i = 0; i < roles.Length; ++i)
            {
                string paraNameI = "@Role" + i.ToString();
                cmd.CommandText += paraNameI;
                if (i != roles.Length - 1)
                {
                    cmd.CommandText += ",";
                }

                cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter(paraNameI, roles[i]));
            }
            cmd.CommandText += ')';

            System.Data.DataTable dt = Feng.Data.DbHelper.Instance.ExecuteDataTable(cmd);

            //for (int i = 0; i < roles.Length; ++i)
            //{
            //    string paraNameI = "'" + roles[i].ToString() + "'";
            //    cmd.CommandText += paraNameI;
            //    if (i != roles.Length - 1)
            //    {
            //        cmd.CommandText += ",";
            //    }
            //}
            //cmd.CommandText += ')';
            //System.Data.DataTable dt = DBManager.GetDateTable(cmd);

            Dictionary <人员类型, string> dict = new Dictionary <人员类型, string> {
                { 人员类型.委托人, "委托人" },
                { 人员类型.承运人, "承运人" }, { 人员类型.收货人, "收货人" }
            };

            ISearchExpression se = null;

            foreach (System.Data.DataRow row in dt.Rows)
            {
                if (!row["业务类型"].ToString().Contains(((int)业务类型).ToString("00") + ","))
                {
                    continue;
                }
                if (!row["角色用途"].ToString().Contains(((int)人员类型).ToString("00") + ","))
                {
                    continue;
                }

                ISearchExpression sse = null;// SearchExpression.Eq("ClientId", row["ClientId"].ToString());
                if (人员类型 != 人员类型.货代)
                {
                    sse = SearchExpression.Eq(dict[人员类型], row["编号"]); // SearchExpression.And(sse, SearchExpression.Eq(dict[人员类型], row["编号"]));
                }
                if (se == null)
                {
                    se = sse;
                }
                else
                {
                    if (sse != null)
                    {
                        se = SearchExpression.Or(se, sse);
                    }
                }
            }
            return(se);
        }