/// <summary>
        /// The load planning table data.
        /// </summary>
        /// <param name="factory">
        /// The factory.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <param name="idList">
        /// The id list.
        /// </param>
        /// <returns>
        /// The StruSoft.Impact.V120.ProjectManager.Core.TableGrid.PlanningData.
        /// </returns>
        public static PlanningData LoadPlanningTableData( string factory, string project, string user, int[] idList )
        {
            string company = Util.FactoryToCompany( factory );
            project = Util.CorrectProjectName( project );

            List<PlanningElementData> planningElementDataList;

            using( ImpactDatabase service = new ImpactDatabase() )
            {
                string query = GetPlanningElementDataQuery( factory, project, idList ).ToString();
                string factoryQuery = GetFactoryQuery( factory, project, user ).ToString();
                string divisionQuery = GetPlanningDivisionQuery( company ).ToString();

                // Get all the specified elements.
                planningElementDataList = service.GetAll( query, ReadPlanningElementData );

                var elementStatusStandard = service.GetAll( 
                    GetElementStatusStandardQuery( company ), 
                    column => new ElementStatusStandard
                        {
                            StatusId    = column[0].Cast<int>(), 
                            Description = column[1].Cast<string>(), 
                            ColorIndex  = column[2].Cast<int>(), 
                        }).ToDictionary( item => item.StatusId );

                var factoryDataList = service.GetAll( factoryQuery, column => new Factory( column[0].Cast<string>(), column[1].Cast<string>() ) );
                factoryDataList.Add( Factory.External );

                var divisionDataList = service.GetAll( divisionQuery, column => column[0].Cast<string>() );

                foreach( var planningElement in planningElementDataList )
                {
                    ElementStatusStandard standard;

                    if( elementStatusStandard.TryGetValue( planningElement.Status, out standard ) )
                    {
                        planningElement.StatusDescription = standard.Description;
                    }

                    if( 0 == string.Compare( planningElement.ProducingFactory, ProjectBrowserLoader.ProducingFactoryExternalValue, true ) )
                    {
                        planningElement.ProducingFactory = Factory.External.Number;
                    }
                }

                PlanningData planningData = new PlanningData( planningElementDataList, divisionDataList, factoryDataList );

                return planningData;
            }
        }