示例#1
0
        public void FillDetailTable(TableResolver masterResolver, TableResolver detailResolver)
        {
            TkDebug.AssertNotNull(masterResolver, "masterResolver", this);
            TkDebug.AssertNotNull(detailResolver, "detailResolver", this);

            if ((fType & RelationType.OnlyFill) != RelationType.OnlyFill)
            {
                return;
            }
            DataTable table = masterResolver.HostTable;

            TkDebug.AssertNotNull(table, string.Format(ObjectUtil.SysCulture, "主表{0}不存在",
                                                       masterResolver.TableName), this);

            foreach (DataRow row in table.Rows)
            {
                string filterSql = FilterSql == null ? string.Empty
                    : Expression.Execute(FilterSql, masterResolver.Source);
                if (Top == 0)
                {
                    if (fDetailFields.Length == 1)
                    {
                        if (fManyToMany == null)
                        {
                            detailResolver.SelectWithParam(filterSql, OrderBy,
                                                           fDetailFields[0], row[fMasterFields[0]]);
                        }
                        else
                        {
                            IParamBuilder container = GetDetailParamBuilder(detailResolver, row, filterSql);

                            detailResolver.Select(container, OrderBy);
                        }
                    }
                    else
                    {
                        if (fManyToMany == null)
                        {
                            object[] masterValues = new object[fMasterFields.Length];
                            for (int i = 0; i < fMasterFields.Length; ++i)
                            {
                                masterValues[i] = row[fMasterFields[i]];
                            }
                            detailResolver.SelectWithParams(filterSql, OrderBy, fDetailFields, masterValues);
                        }
                        else
                        {
                            ThrowErrorManyToManyMode();
                        }
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        object[]      values  = (from item in fMasterFields select row[item]).ToArray();
                        IParamBuilder builder = detailResolver.CreateParamBuilder(filterSql, fDetailFields, values);
                        detailResolver.SelectTopRows(Top, builder, OrderBy);
                    }
                    else
                    {
                        if (fDetailFields.Length == 1)
                        {
                            IParamBuilder container = GetDetailParamBuilder(detailResolver, row, filterSql);

                            detailResolver.SelectTopRows(Top, container, OrderBy);
                        }
                        else
                        {
                            ThrowErrorManyToManyMode();
                        }
                    }
                }
            }
            detailResolver.AddVirtualFields();
        }