Ejemplo n.º 1
0
        //重构查询器
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryName">查询构建器的主键名称</param>
        /// <param name="keys">查询条件key</param>
        /// <param name="values">查询 条件values</param>
        /// <returns></returns>
        public ModelObject findModel(String queryName, String[] keys, string[] values)
        {
            ImanQuery query = null;

            // Get the service stub
            SavedQueryService     queryService = SavedQueryService.getService(Session.getConnection());
            DataManagementService dmService    = DataManagementService.getService(Session.getConnection());

            try
            {
                // *****************************
                // Execute the service operation
                // *****************************
                GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();


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

                // Find one called 'Item Name'
                for (int i = 0; i < savedQueries.Queries.Length; i++)
                {
                    if (savedQueries.Queries[i].Name.Equals(queryName))
                    {
                        query = savedQueries.Queries[i].Query;
                        break;
                    }
                }
            }
            catch (ServiceException e)
            {
                return(null);
            }

            if (query == null)
            {
                return(null);
            }

            try
            {
                SavedQueryInput[] savedQueryInput = new SavedQueryInput[1];
                savedQueryInput[0]                = new SavedQueryInput();
                savedQueryInput[0].Query          = query;
                savedQueryInput[0].MaxNumToReturn = 25;
                savedQueryInput[0].LimitListCount = 0;
                savedQueryInput[0].LimitList      = new Teamcenter.Soa.Client.Model.ModelObject[0];
                savedQueryInput[0].Entries        = keys;//Attribute in Query to search by
                savedQueryInput[0].Values         = values;
                savedQueryInput[0].MaxNumToReturn = 25;



                ExecuteSavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
                SavedQueryResults           found            = savedQueryResult.ArrayOfResults[0];

                ModelObject[] modelObjs = found.Objects;


                return(modelObjs[0]);
            }
            catch (ServiceException e)
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public void queryItems()
        {
            ImanQuery query = null;

            // Get the service stub
            SavedQueryService     queryService = SavedQueryService.getService(Session.getConnection());
            DataManagementService dmService    = DataManagementService.getService(Session.getConnection());

            try
            {
                // *****************************
                // Execute the service operation
                // *****************************
                GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();


                if (savedQueries.Queries.Length == 0)
                {
                    Console.Out.WriteLine("There are no saved queries in the system.");
                    return;
                }

                // Find one called 'Item Name'
                for (int i = 0; i < savedQueries.Queries.Length; i++)
                {
                    if (savedQueries.Queries[i].Name.Equals("MY_WEB_ITEM_REVISION"))
                    {
                        query = savedQueries.Queries[i].Query;
                        break;
                    }
                }
            }
            catch (ServiceException e)
            {
                Console.Out.WriteLine("GetSavedQueries service request failed.");
                Console.Out.WriteLine(e.Message);
                return;
            }

            if (query == null)
            {
                Console.WriteLine("There is not an 'Item Name' query.");
                return;
            }

            try
            {
                // Search for all Items, returning a maximum of 25 objects
                QueryInput[] savedQueryInput = new QueryInput[1];
                savedQueryInput[0]                = new QueryInput();
                savedQueryInput[0].Query          = query;
                savedQueryInput[0].MaxNumToReturn = 25;
                savedQueryInput[0].LimitList      = new Teamcenter.Soa.Client.Model.ModelObject[0];
                //savedQueryInput[0].Entries = new String[] { "Name", "ItemID" };
                //savedQueryInput[0].Values = new String[2];
                //savedQueryInput[0].Values[0] = "Maxtt-Test";
                //savedQueryInput[0].Values[1] = "000090";

                savedQueryInput[0].Entries = new String[] { "iid", "vid" };
                savedQueryInput[0].Values  = new String[] { "*90", "001" };

                //*****************************
                //Execute the service operation
                //*****************************
                SavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
                QueryResults         found            = savedQueryResult.ArrayOfResults[0];


                System.Console.Out.WriteLine("");
                System.Console.Out.WriteLine("Found Items:");
                // Page through the results 10 at a time
                for (int i = 0; i < found.ObjectUIDS.Length; i += 10)
                {
                    int pageSize = (i + 10 < found.ObjectUIDS.Length) ? 10 : found.ObjectUIDS.Length - i;

                    String[] uids = new String[pageSize];
                    for (int j = 0; j < pageSize; j++)
                    {
                        uids[j] = found.ObjectUIDS[i + j];
                    }
                    ServiceData   sd        = dmService.LoadObjects(uids);
                    ModelObject[] foundObjs = new ModelObject[sd.sizeOfPlainObjects()];
                    for (int k = 0; k < sd.sizeOfPlainObjects(); k++)
                    {
                        foundObjs[k] = sd.GetPlainObject(k);
                    }

                    Session.printObjects(foundObjs);
                }
            }
            catch (ServiceException e)
            {
                Console.Out.WriteLine("ExecuteSavedQuery service request failed.");
                Console.Out.WriteLine(e.Message);
                return;
            }
        }
Ejemplo n.º 3
0
        private static ModelObject[] QueryObjects(String QueryName, String[] SQEntries, String[] SQValues)
        {
            ImanQuery query = null;

            List <String> ObjectidList = new List <String>();

            // Get the service stub
            SavedQueryService     queryService = SavedQueryService.getService(Teamcenter.ClientX.Session.getConnection());
            DataManagementService dmService    = DataManagementService.getService(Teamcenter.ClientX.Session.getConnection());

            try
            {
                GetSavedQueriesResponse savedQueries = queryService.GetSavedQueries();


                if (savedQueries.Queries.Length == 0)
                {
                    Console.Out.WriteLine("There are no saved queries in the system.");
                    return(null);
                }

                // Find one called 'Item Name'
                for (int i = 0; i < savedQueries.Queries.Length; i++)
                {
                    if (savedQueries.Queries[i].Name.Equals(QueryName))
                    {
                        query = savedQueries.Queries[i].Query;
                        break;
                    }
                }
            }
            catch (ServiceException e)
            {
                Console.Out.WriteLine("GetSavedQueries service request failed.");
                Console.Out.WriteLine(e.Message);
                return(null);
            }

            if (query == null)
            {
                Console.WriteLine("There is no saved Query with the name\"" + QueryName + "\" query.");
                return(null);
            }

            try
            {
                // Search for all Items, returning a maximum of 25 objects
                QueryInput[] savedQueryInput = new QueryInput[1];
                savedQueryInput[0]                = new QueryInput();
                savedQueryInput[0].Query          = query;
                savedQueryInput[0].MaxNumToReturn = 0;
                savedQueryInput[0].LimitList      = new Teamcenter.Soa.Client.Model.ModelObject[0];
                savedQueryInput[0].Entries        = SQEntries; // new String[] { "ID" };
                savedQueryInput[0].Values         = SQValues;  //new String[1];
                //savedQueryInput[0].Values[0] = "*";

                //*****************************
                //Execute the service operation
                //*****************************
                SavedQueriesResponse savedQueryResult = queryService.ExecuteSavedQueries(savedQueryInput);
                QueryResults         found            = savedQueryResult.ArrayOfResults[0];


                System.Console.Out.WriteLine("");
                System.Console.Out.WriteLine("Found Items:");

                String[] uids = new String[found.ObjectUIDS.Length];

                // Page through the results 10 at a time
                for (int i = 0; i < found.ObjectUIDS.Length; i++)
                {
                    uids[i] = found.ObjectUIDS[i];
                }

                ServiceData   sd        = dmService.LoadObjects(uids);
                ModelObject[] foundObjs = new ModelObject[sd.sizeOfPlainObjects()];

                for (int k = 0; k < sd.sizeOfPlainObjects(); k++)
                {
                    foundObjs[k] = sd.GetPlainObject(k);
                }

                //Teamcenter.ClientX.Session.printObjects(foundObjs);

                return(foundObjs);
            }
            catch (ServiceException e)
            {
                Console.Out.WriteLine("ExecuteSavedQuery service request failed.");
                Console.Out.WriteLine(e.Message);
                return(null);
            }
            return(null);
        }