Ejemplo n.º 1
0
        public IParamBuilder CreateDetailParamBuilder(TableResolver masterResolver,
                                                      TableResolver detailResolver, IInputData input)
        {
            TkDebug.AssertNotNull(masterResolver, "masterResolver", this);
            TkDebug.AssertNotNull(detailResolver, "detailResolver", this);
            TkDebug.AssertNotNull(input, "input", this);

            string[] keyArray = Array.ConvertAll(masterResolver.GetKeyFieldArray(),
                                                 field => field.NickName);
            if (ObjectUtil.ArrayEqual(keyArray, fMasterFields))
            {
                if (fDetailFields.Length == 1)
                {
                    if (fManyToMany == null)
                    {
                        return(SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                              detailResolver.GetFieldInfo(fDetailFields[0]),
                                                              input.QueryString[fMasterFields[0]]));
                    }
                    else
                    {
                        return(GetManyToManyParamBuilder(detailResolver,
                                                         input.QueryString[fMasterFields[0]]));
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        IParamBuilder[] builders = new IParamBuilder[fDetailFields.Length];
                        for (int i = 0; i < fDetailFields.Length; ++i)
                        {
                            builders[i] = SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                                         detailResolver.GetFieldInfo(fDetailFields[i]),
                                                                         input.QueryString[fMasterFields[i]]);
                        }

                        return(ParamBuilder.CreateParamBuilder(builders));
                    }
                    else
                    {
                        return(ThrowErrorManyToManyMode());
                    }
                }
            }
            else
            {
                DataRow row = masterResolver.Query(input.QueryString);
                if (fDetailFields.Length == 1)
                {
                    if (fManyToMany == null)
                    {
                        return(SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                              detailResolver.GetFieldInfo(fDetailFields[0]), row[fMasterFields[0]]));
                    }
                    else
                    {
                        return(GetManyToManyParamBuilder(detailResolver, row[fMasterFields[0]]));
                    }
                }
                else
                {
                    if (fManyToMany == null)
                    {
                        IParamBuilder[] builders = new IParamBuilder[fDetailFields.Length];
                        for (int i = 0; i < fDetailFields.Length; ++i)
                        {
                            builders[i] = SqlParamBuilder.CreateEqualSql(detailResolver.Context,
                                                                         detailResolver.GetFieldInfo(fDetailFields[i]),
                                                                         row[fMasterFields[i]]);
                        }

                        return(ParamBuilder.CreateParamBuilder(builders));
                    }
                    else
                    {
                        return(ThrowErrorManyToManyMode());
                    }
                }
            }
        }