Hi
I work at the moment on a database wish refer several customers. I've create a page with textboxes, each with specific x:name (FirstnameFrame, LastnameFrame, BirthdateFrame,...).
I've a first class for customer :
And a second for create the list :
I have a problem at the lines 21 and 22. I would like to create a list like that :
So is there a way to assign Firstname, Lastname, Birthdate,... in a variable "i" at each loop ?
To have a code like that :
Thank you for your help.
I work at the moment on a database wish refer several customers. I've create a page with textboxes, each with specific x:name (FirstnameFrame, LastnameFrame, BirthdateFrame,...).
I've a first class for customer :
C#:
[SerializableAttribute]
public class Customer
{
public string Frame { get; set; }
public string Value { get; set; }
}
And a second for create the list :
C#:
public partial class CreatingFile : Window
{
public List<Customer> customerData = new List<Customer>();
public string info;
public string filePath => $@"C:\Users\computer\Sofwares\Visual Studio\UserCodes\Customer file\Customer file\data\{info}.save";
public IEnumerable<Control> Controls { get; private set; }
public CreatingFile()
{
InitializeComponent();
}
private void SaveBtnClick(object sender, RoutedEventArgs e)
{
Customer data = new Customer();
foreach (Control item in Controls)
{
if (item is TextBox)
{
data.Frame = /*Missing value*/;
data.Value = /*Missing value*/;
customerData.Add(data);
}
}
info = $"{NameFrame.Text}_{LastnameFrame.Text}_{PasswordFrame.Text}";
Serialise.Save(filePath, customer);
Application.Current.Shutdown();
}
I have a problem at the lines 21 and 22. I would like to create a list like that :
C#:
| Frame | Value |
Index 0 | FirstnameFrame.Name | FirstnameFrame.Text |
Index 1 | LastnameFrame.Name | LastnameFrame.Text |
Index 2 | BirthdateFrame.Name | BirthdateFrame.Text |
Index 3 |...
So is there a way to assign Firstname, Lastname, Birthdate,... in a variable "i" at each loop ?
To have a code like that :
C#:
private void SaveBtnClick(object sender, RoutedEventArgs e)
{
Customer data = new Customer();
string i;
foreach (Control item in Controls)
{
if (item is TextBox)
{
data.Frame = {i}Frame.Name;
data.Value = {i}Frame.Text;
customerData.Add(data);
}
}
info = $"{NameFrame.Text}_{LastnameFrame.Text}_{PasswordFrame.Text}";
Serialise.Save(filePath, customer);
Application.Current.Shutdown();
}
Thank you for your help.