我在项目逻辑上遇到麻烦。我需要将文本框中的用户输入(地址)保存到Arraylist或List中。然后,当用户单击“后退”按钮时,访问阵列列表或列表并显示存储的值。我在逻辑上遇到麻烦,创建了arraylist,并且当用户单击添加按钮时,值将添加到arraylist。问题是我不明白如何将存储的值一起发布,即城市,州,邮政编码,ID全部存储在数组中,后退按钮如何分配所有正确的值?我希望它位于应用程序右侧的ComboBox允许用户选择状态的位置。选择状态后,将在列表框中显示发往该状态的所有程序包的程序包ID号。我正在寻找有关如何使这项工作的建议或技巧。感谢您的任何帮助。
已编辑
public partial class MainWindow : Window
{
//these lines of code imports the date/time function and the random function
DateTime time = DateTime.Now;
Random rnd = new Random();
String addresses;
String cities;
String states;
String zipcodes;
string num = "";
public List<Order> orderlist = new List<Order>();
public class Order
{
public string city { set; get; }
public string zipcode { set; get; }
public string state { set; get; }
public string orderNum { set; get; }
public string address { set; get; }
}
public MainWindow()
{
InitializeComponent();
}
private void scanBtn_Click(object sender, RoutedEventArgs e)
{
//this displays the current date and time in the arrived at textbox
arrivedAtTextbox.Text = "" + time;
//this code generates a random number and converts to a string to be displayed
int id = rnd.Next(1000);
num = id.ToString();
packageIDTextbox.Text = num;
//these lines of code enables the fields after the scan button was clicked
addressTextbox.IsEnabled = true;
cityTextbox.IsEnabled = true;
zipCodeTextbox.IsEnabled = true;
stateComboBox.IsEnabled = true;
//this code sets the focus to the address field
addressTextbox.Focus();
addresses = addressTextbox.Text;
cities = cityTextbox.Text;
zipcodes = zipCodeTextbox.Text;
states = stateComboBox.Text;
}
//Add Button
private void addBtn_Click(object sender, RoutedEventArgs e)
{
Order data = new Order();
data.address = addresses;
data.city = cities;
data.zipcode = zipcodes;
data.state = states;
data.orderNum = num;
orderlist.Add(data);
}
//Remove Button
private void Button_Click(object sender, RoutedEventArgs e)
{
foreach (var order in orderlist)
{
}
}
//Next Button
private void Button_Click_1(object sender, RoutedEventArgs e)
{
foreach (var order in orderlist)
{
}
}
}