Пример #1
0
        private void btnFindCommodity_Click(object sender, RoutedEventArgs e)
        {
            // Initialize the context and the binding collection 
            context = new TopCarrotEntities(topCarrotDataUri);
            context.SendingRequest += new EventHandler<SendingRequestEventArgs>(context_SendingRequest);
            commodityPluCodes = new DataServiceCollection<CommodityPluCode>(context);
            //Show the progress bar
            pageIndicators.ShowProgress(this);  


            if (UserInputUtilities.IsPluCode(txtCommodityToFind.Text))
            {
                txtblkInstructions.Text = "By PLU code entered";
                SearchQuery = from CommodityPluCode PluData in context.CommodityPluCodes
                            where PluData.PLU == txtCommodityToFind.Text.ToString()
                            select PluData;
            }
            if (UserInputUtilities.IsCropNumber(txtCommodityToFind.Text))
            {
                txtblkInstructions.Text = "By crop ID entered";
                SearchQuery = from CommodityPluCode PluData in context.CommodityPluCodes
                              where PluData.Commodity == txtCommodityToFind.Text.ToUpper()
                              select PluData;
            }
            else
            {
                txtblkInstructions.Text = "By commondity name entered";
                SearchQuery = from CommodityPluCode PluData in context.CommodityPluCodes
                            where PluData.Commodity == txtCommodityToFind.Text.ToUpper()
                            select PluData;
            }

            // Register for the LoadCompleted event.
            commodityPluCodes.LoadCompleted
               += new EventHandler<LoadCompletedEventArgs>(commodityPluCodes_LoadCompleted);


            // Load the customers feed by executing the LINQ query.
            commodityPluCodes.LoadAsync(SearchQuery);

        }
        /// <summary>
        /// Gets the details of the PLU or commodity that was selected on the Search By page
        /// </summary>
        /// <param name="PluId">The PLUID from the SQL table which is the same as the table ID</param>
        private void GetDetailInformation(int PluId)
        {
            // Initialize the context and the binding collection 
            context = new TopCarrotEntities(topCarrotDataUri);
            commodityPluCodes = new DataServiceCollection<CommodityPluCode>(context);

            // Define a LINQ query that returns all customers.
            var query = from CommodityPluCode PluData in context.CommodityPluCodes
                        where PluData.PLUId == PluId
                        select PluData;

            // Register for the LoadCompleted event.
            commodityPluCodes.LoadCompleted
                += new EventHandler<LoadCompletedEventArgs>(commodityPluCodes_LoadCompleted);

            // Load the customers feed by executing the LINQ query.
            commodityPluCodes.LoadAsync(query);
        }