在用户和服务器之间传递数据

时间:2013-07-25 01:59:42

标签: c# visual-studio-2010 windows-phone-7 windows-phone-8 windows-phone

我正在尝试通过restsharp将数据从用户传输到服务器。下面是我使用的代码。我收到一条错误“当前上下文中不存在名称'InitializeComponent'”

我该如何调试?有任何逻辑错误吗?

'using System;
 using System.Net;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Ink;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Shapes;
 using Microsoft.Phone.Controls;
 using RestSharp;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
 using System.Linq;


 namespace Miser_sApp
 {
     public class RestSharp
     {
         public partial class SearchResults : PhoneApplicationPage
         {
             public static float _latitude, _longitude;
             public static DateTime _date, _time;
             public static string _name, _details;
             public static int _number, _amount, _uid;
             RestClient client;
             RestRequest request;

             int index;
             connect Connect;
             public SearchResults()
             {
                 InitializeComponent();
                 load();

             }
             private RestClient InitializeX()
             {
                 var client = new RestClient("//localhost" + Panorama1.username1 +                "&pro_type=" + Panorama1.number1 + "&pro_name=" + Panorama1.details1 + "&lat=" + Panorama1.lat1 + "&lon=" + Panorama1.lon1);
                 return client;
                 // request = new RestRequest(Method.GET);
             }
             public void load()
             {
                 client = InitializeX();
                 //MessageBox.Show("InternalInitialize Done");
                 request = new RestRequest(Method.POST);

                 client.ExecuteAsync<connect>(request, (response) =>
                 {
                     //   MessageBox.Show(response.Data.ToString());
                     Connect = response.Data;
                     if (response.Data == null || Connect.last == null || Connect == null)
                     {
                         MessageBox.Show("NO ITEMS FOUND");
                         NavigationService.Navigate(new Uri("/Personal.xaml", UriKind.Relative));

                     }
                     // name1.Items.Add(rootObject3.Details[0].ProductName);
                     //results.Items.Clear();
                     //int i = 0;
                     else
                         foreach (var row3 in Connect.last)
                         {
                             results.Items.Add("NAME-" + row3.Name + '\n' + "Details-" + row3.Details + '\n' + "Date-" + row3.Date + '\n' + "Amount-" + row3.Amount + '\n' + "userId-" + row3.Uid + '\n' + "---------------------------------------------------------------");
                         }
                 });

             }




             private void Button_Click(object sender, RoutedEventArgs e)
             {

                 Konnect d = Connect.last[index];
                 _name = d.Name;
                 _date = d.Date;
                 _time = d.Time;
                 _uid = d.Uid;
                 _amount = d.Amount;
                 _details = d.Details;
                 _latitude = d.Latitude;
                 _longitude = d.Longitude;

                 NavigationService.Navigate(new Uri("/Panaroma1.xaml", UriKind.Relative));


             }

             private void results_SelectionChanged(object sender, SelectionChangedEventArgs e)
             {
                 index = results.SelectedIndex;
             }

         }
         public class Konnect
         {
             public string Name { get; set; }
             public DateTime Date { get; set; }
             public DateTime Time { get; set; }
             public int Uid { get; set; }
             public String Details { get; set; }
             public int Amount { get; set; }
             public float Latitude { get; set; }
             public float Longitude { get; set; }
         }

         public class connect
         {
             public List<Konnect> last { get; set; }
         }

     }
 }

1 个答案:

答案 0 :(得分:0)

这意味着InitializeComponent();方法不存在。在下面的代码中。这可能是一个参考问题。这也可能意味着设计器文件存在问题,因为Designer支持需要它。运行调试器时,可以尝试单步执行该方法。此外,错误发生在哪里?它是运行时错误还是在您尝试编译时发生?如果它是编译错误,则意味着该方法不存在,您需要创建它或删除该方法中的引用。

public SearchResults()
{
    InitializeComponent();
    load();

}

编辑:

您可能在designer.cs文件中缺少此部分。请注意,这是基于win表单应用程序。您将需要研究此方法对于您尝试继承的类的位置。即PhoneApplicationPage类

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.Text = "Form1";
    }
    #endregion

我刚创建了一个新应用,它会自动为我生成这个。你必须删除它或其他东西。