Owners and addresses works
This commit is contained in:
@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Text.Json;
|
||||
using System.IO;
|
||||
using Helpers;
|
||||
|
||||
namespace StockInfo
|
||||
{
|
||||
@ -25,6 +26,7 @@ namespace StockInfo
|
||||
private frmMyStocks stockWindow;
|
||||
private frmSelling sellWindow;
|
||||
private frmPerson personWindow;
|
||||
public int SelectedPersonId { get; set; } = 0;
|
||||
|
||||
public frmInitial(
|
||||
IStockRepository stockMemberRepository,
|
||||
@ -170,8 +172,10 @@ namespace StockInfo
|
||||
{
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
personWindow = new frmPerson(_personRepository, _addressRepository);
|
||||
personWindow.PersonId = SelectedPersonId;
|
||||
Cursor.Current = DefaultCursor;
|
||||
personWindow.ShowDialog();
|
||||
LoadCmbOwners();
|
||||
}
|
||||
|
||||
private void btnConnShares_Click(object sender, EventArgs e)
|
||||
@ -186,19 +190,21 @@ namespace StockInfo
|
||||
|
||||
private void LoadCmbOwners()
|
||||
{
|
||||
cmbOwners.Items.Clear();
|
||||
var owners = _personRepository.GetAllOwners();
|
||||
if (owners.Count() > 0)
|
||||
{
|
||||
foreach (var person in owners)
|
||||
{
|
||||
var itemIndex = cmbOwners.Items.Add($"{person.FirstName} {person.LastName} ({person.NickName})");
|
||||
var itemIndex = cmbOwners.Items.Add(new ComboboxItem ($"{person.FirstName} {person.LastName} ({person.NickName})",person.Id));
|
||||
}
|
||||
}
|
||||
cmbOwners.Items.Add(new ComboboxItem($"< ny person> ", 0));
|
||||
}
|
||||
|
||||
private void cmbOwners_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
SelectedPersonId = ((ComboboxItem)cmbOwners.SelectedItem).HiddenValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
StockInfo/frmPerson.Designer.cs
generated
1
StockInfo/frmPerson.Designer.cs
generated
@ -295,6 +295,7 @@ namespace StockInfo
|
||||
this.btnClose.TabIndex = 15;
|
||||
this.btnClose.Text = "Close";
|
||||
this.btnClose.UseVisualStyleBackColor = true;
|
||||
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
|
||||
//
|
||||
// frmPerson
|
||||
//
|
||||
|
||||
@ -28,7 +28,9 @@ namespace StockInfo
|
||||
|
||||
public int PersonId { get; set; }
|
||||
public int HomeAddressId { get; set; }
|
||||
public int CheckHomeAddressId { get; set; }
|
||||
public int InvoiceAddressId { get; set; }
|
||||
public int CheckInvoiceAddressId { get; set; }
|
||||
|
||||
|
||||
private void btnAddSave_Click(object sender, EventArgs e)
|
||||
@ -38,7 +40,8 @@ namespace StockInfo
|
||||
if (OK)
|
||||
{
|
||||
person = _personRepository.SavePerson(person);
|
||||
PersonId = person.Id;
|
||||
initializeAllFields();
|
||||
PersonId = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -58,17 +61,27 @@ namespace StockInfo
|
||||
person.AccountNo = txtAccountNr.Text.IsNumeric() ? int.Parse(txtAccountNr.Text) : 0;
|
||||
person.Born = txtPersonNr.Text;
|
||||
person.Comments = txtComment.Text;
|
||||
HomeAddressId = AddressSave();
|
||||
if (rdbHome.Checked)
|
||||
{
|
||||
HomeAddressId = AddressSave(HomeAddressId);
|
||||
}
|
||||
else
|
||||
{
|
||||
InvoiceAddressId = AddressSave(InvoiceAddressId);
|
||||
}
|
||||
person.HomeAddress = HomeAddressId;
|
||||
CheckHomeAddressId = HomeAddressId;
|
||||
person.InvoiceAddress = InvoiceAddressId;
|
||||
CheckInvoiceAddressId = InvoiceAddressId;
|
||||
return (person, true);
|
||||
}
|
||||
|
||||
private int AddressSave()
|
||||
private int AddressSave(int AddressId)
|
||||
{
|
||||
var retval = 0;
|
||||
bool changed = false;
|
||||
Address address = new Address();
|
||||
(address.Id, changed) = checkInt(AddressId.ToString());
|
||||
(address.Street, changed) = checkString(txtStreet.Text);
|
||||
(address.Street2, changed) = checkString(txtStreet2.Text);
|
||||
(address.Zipcode, changed) = checkInt(txtZipCode.Text);
|
||||
@ -103,7 +116,9 @@ namespace StockInfo
|
||||
if (person != null)
|
||||
{
|
||||
HomeAddressId = person.HomeAddress;
|
||||
CheckHomeAddressId = person.HomeAddress;
|
||||
InvoiceAddressId = person.InvoiceAddress;
|
||||
CheckInvoiceAddressId = person.InvoiceAddress;
|
||||
fillFieldsFromPerson(person);
|
||||
}
|
||||
}
|
||||
@ -145,6 +160,8 @@ namespace StockInfo
|
||||
ClearAddress();
|
||||
HomeAddressId = 0;
|
||||
InvoiceAddressId = 0;
|
||||
CheckHomeAddressId = 0;
|
||||
CheckInvoiceAddressId = 0;
|
||||
rdbHome.Checked = true;
|
||||
}
|
||||
|
||||
@ -163,14 +180,14 @@ namespace StockInfo
|
||||
{
|
||||
if (rdbInvoiceAddr.Checked)
|
||||
{
|
||||
HomeAddressId = AddressSave();
|
||||
HomeAddressId = AddressSave(HomeAddressId);
|
||||
ClearAddress();
|
||||
ShowAddressFrom(InvoiceAddressId);
|
||||
radioOk = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
InvoiceAddressId = AddressSave();
|
||||
InvoiceAddressId = AddressSave(InvoiceAddressId);
|
||||
ClearAddress();
|
||||
ShowAddressFrom(HomeAddressId);
|
||||
radioOk = true;
|
||||
@ -181,5 +198,17 @@ namespace StockInfo
|
||||
radioOk = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void btnClose_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (HomeAddressId != CheckHomeAddressId || InvoiceAddressId != CheckInvoiceAddressId)
|
||||
{
|
||||
MessageBox.Show("NB Save info first to insure not losing addresses");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user