private static void GetDetailGridRows(GridRelatedAddressInfo info, Xceed.Grid.DetailGrid detailGrid, List <object> selectedEntities)
 {
     foreach (Xceed.Grid.DataRow dataRow in detailGrid.DataRows)
     {
         if (info.GridLevel == Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid) ||
             string.IsNullOrEmpty(info.GridLevel))
         {
             selectedEntities.Add(dataRow.Tag);
         }
         else
         {
             foreach (Xceed.Grid.DetailGrid dg in dataRow.DetailGrids)
             {
                 GetDetailGridRows(info, dg, selectedEntities);
             }
         }
     }
 }
 private static void GetDetailGridRows(GridRelatedAddressInfo info, Xceed.Grid.DetailGrid detailGrid, List<object> selectedEntities)
 {
     foreach (Xceed.Grid.DataRow dataRow in detailGrid.DataRows)
     {
         if (info.GridLevel == Feng.Grid.MyGrid.GetGridLevel(dataRow.ParentGrid)
             || string.IsNullOrEmpty(info.GridLevel))
         {
             selectedEntities.Add(dataRow.Tag);
         }
         else
         {
             foreach (Xceed.Grid.DetailGrid dg in dataRow.DetailGrids)
             {
                 GetDetailGridRows(info, dg, selectedEntities);
             }
         }
     }
 }
        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!");
            }
        }
        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!");
            }
        }