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

本文关键字:数据 之间 服务器 用户 | 更新日期: 2023-09-27 18:24:43

我正试图通过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; }
         }
     }
 }

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

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

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

编辑:

您的designer.cs文件中可能缺少此部分。请注意,这是基于一个获胜表单应用程序。您需要研究这个方法在您试图继承的类中的位置。即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

我刚刚创建了一个新的应用程序,它自动为我生成了这个。你一定删除了它或其他什么。