Files
Stockinfo/StockInfo/frmPerson.cs

86 lines
2.6 KiB
C#

using DataDomain;
using StockDAL.Interface;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace StockInfo
{
public partial class frmPerson : Form
{
private readonly IPersonRepository _personRepository;
private readonly IAddressRepository _addressRepository;
public frmPerson(IPersonRepository personRepository, IAddressRepository addressRepository)
{
InitializeComponent();
_personRepository = personRepository;
_addressRepository = addressRepository;
}
public int PersonId { get; set; }
public int HomeAddressId { get; set; }
public int InvoiceAddressId { get; set; }
private void btnAddSave_Click(object sender, EventArgs e)
{
}
private void frmPerson_Load(object sender, EventArgs e)
{
var person = _personRepository.GetPersonById(PersonId);
initializeAllFields();
if (person != null)
{
HomeAddressId = person.HomeAddress;
InvoiceAddressId = person.InvoiceAddress;
fillFieldsFromPerson(person);
}
}
private void fillFieldsFromPerson(Person person)
{
txtFirstName.Text = person.FirstName;
txtLastName.Text = person.LastName;
txtNickName.Text = person.NickName;
txtPersonNr.Text = person.Born;
txtComment.Text = person.Comments;
txtClearingNo.Text = person.ClearingNo.ToString();
txtAccountNr.Text = person.AccountNo.ToString();
var address = _addressRepository.GetAddressById(HomeAddressId);
if (address != null)
{
txtStreet.Text = address.Street;
txtStreet2.Text = address.Street2;
txtZipCode.Text = address.Zipcode.ToString();
txtDestination.Text = address.Destination;
txtNation.Text = address.Nation;
}
}
private void initializeAllFields()
{
txtFirstName.Text = "";
txtLastName.Text = "";
txtNickName.Text = "";
txtPersonNr.Text = "";
txtComment.Text = "";
txtClearingNo.Text = "";
txtAccountNr.Text = "";
txtStreet.Text = "";
txtStreet2.Text = "";
txtZipCode.Text = "";
txtDestination.Text = "";
txtNation.Text = "";
}
}
}