Added possibilities for owners and there addresses
This commit is contained in:
@ -19,5 +19,37 @@ namespace StockDAL
|
|||||||
select adr).FirstOrDefault();
|
select adr).FirstOrDefault();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Address SaveAddress(Address address)
|
||||||
|
{
|
||||||
|
using var context = new StockContext();
|
||||||
|
var entity = (from adr in context.Addresses
|
||||||
|
where adr.Id == address.Id
|
||||||
|
select adr).FirstOrDefault();
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
entity = new Address
|
||||||
|
{
|
||||||
|
Street = address.Street,
|
||||||
|
Street2 = address.Street2,
|
||||||
|
Zipcode = address.Zipcode,
|
||||||
|
Destination = address.Destination,
|
||||||
|
Nation = address.Nation
|
||||||
|
};
|
||||||
|
context.Addresses.Add(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entity.Street = address.Street;
|
||||||
|
entity.Street2 = address.Street2;
|
||||||
|
entity.Zipcode = address.Zipcode;
|
||||||
|
entity.Destination = address.Destination;
|
||||||
|
entity.Nation = address.Nation;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,5 +19,57 @@ namespace StockDAL
|
|||||||
select prs).FirstOrDefault();
|
select prs).FirstOrDefault();
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Person> GetAllOwners()
|
||||||
|
{
|
||||||
|
using var context = new StockContext();
|
||||||
|
var output = context.Persons;
|
||||||
|
return output.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Person SavePerson(Person person)
|
||||||
|
{
|
||||||
|
using var context = new StockContext();
|
||||||
|
|
||||||
|
var entity = (from prs in context.Persons
|
||||||
|
where prs.Id == person.Id
|
||||||
|
select prs).FirstOrDefault();
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
entity = new Person
|
||||||
|
{
|
||||||
|
AccountNo = person.AccountNo,
|
||||||
|
Born = person.Born,
|
||||||
|
ClearingNo = person.ClearingNo,
|
||||||
|
Comments = person.Comments,
|
||||||
|
FirstName = person.FirstName,
|
||||||
|
HomeAddress = person.HomeAddress,
|
||||||
|
InvoiceAddress = person.InvoiceAddress,
|
||||||
|
LastName = person.LastName,
|
||||||
|
NickName = person.NickName
|
||||||
|
};
|
||||||
|
context.Persons.Add(entity);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entity.AccountNo = person.AccountNo;
|
||||||
|
entity.Born = person.Born;
|
||||||
|
entity.ClearingNo = person.ClearingNo;
|
||||||
|
entity.Comments = person.Comments;
|
||||||
|
entity.FirstName = person.FirstName;
|
||||||
|
entity.HomeAddress = person.HomeAddress;
|
||||||
|
entity.InvoiceAddress = person.InvoiceAddress;
|
||||||
|
entity.LastName = person.LastName;
|
||||||
|
entity.NickName = person.NickName;
|
||||||
|
}
|
||||||
|
|
||||||
|
context.SaveChanges();
|
||||||
|
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,5 +10,6 @@ namespace StockDAL.Interface
|
|||||||
public interface IAddressRepository
|
public interface IAddressRepository
|
||||||
{
|
{
|
||||||
Address GetAddressById(int AddressId);
|
Address GetAddressById(int AddressId);
|
||||||
|
Address SaveAddress(Address address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,8 @@ namespace StockDAL.Interface
|
|||||||
{
|
{
|
||||||
public interface IPersonRepository
|
public interface IPersonRepository
|
||||||
{
|
{
|
||||||
|
IEnumerable<Person> GetAllOwners();
|
||||||
Person GetPersonById(int personId);
|
Person GetPersonById(int personId);
|
||||||
|
Person SavePerson(Person person);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
StockInfo/Stocks.db-shm
Normal file
BIN
StockInfo/Stocks.db-shm
Normal file
Binary file not shown.
0
StockInfo/Stocks.db-wal
Normal file
0
StockInfo/Stocks.db-wal
Normal file
40
StockInfo/frmInitial.Designer.cs
generated
40
StockInfo/frmInitial.Designer.cs
generated
@ -47,9 +47,9 @@ namespace StockInfo
|
|||||||
this.ofdOpener = new System.Windows.Forms.OpenFileDialog();
|
this.ofdOpener = new System.Windows.Forms.OpenFileDialog();
|
||||||
this.lblStockRows = new System.Windows.Forms.Label();
|
this.lblStockRows = new System.Windows.Forms.Label();
|
||||||
this.gpOwners = new System.Windows.Forms.GroupBox();
|
this.gpOwners = new System.Windows.Forms.GroupBox();
|
||||||
this.comboBox1 = new System.Windows.Forms.ComboBox();
|
|
||||||
this.btnEditPerson = new System.Windows.Forms.Button();
|
|
||||||
this.btnConnShares = new System.Windows.Forms.Button();
|
this.btnConnShares = new System.Windows.Forms.Button();
|
||||||
|
this.btnEditPerson = new System.Windows.Forms.Button();
|
||||||
|
this.cmbOwners = new System.Windows.Forms.ComboBox();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.gB1.SuspendLayout();
|
this.gB1.SuspendLayout();
|
||||||
this.gbStockMgmnt.SuspendLayout();
|
this.gbStockMgmnt.SuspendLayout();
|
||||||
@ -230,7 +230,7 @@ namespace StockInfo
|
|||||||
//
|
//
|
||||||
this.gpOwners.Controls.Add(this.btnConnShares);
|
this.gpOwners.Controls.Add(this.btnConnShares);
|
||||||
this.gpOwners.Controls.Add(this.btnEditPerson);
|
this.gpOwners.Controls.Add(this.btnEditPerson);
|
||||||
this.gpOwners.Controls.Add(this.comboBox1);
|
this.gpOwners.Controls.Add(this.cmbOwners);
|
||||||
this.gpOwners.Location = new System.Drawing.Point(589, 385);
|
this.gpOwners.Location = new System.Drawing.Point(589, 385);
|
||||||
this.gpOwners.Name = "gpOwners";
|
this.gpOwners.Name = "gpOwners";
|
||||||
this.gpOwners.Size = new System.Drawing.Size(252, 141);
|
this.gpOwners.Size = new System.Drawing.Size(252, 141);
|
||||||
@ -238,13 +238,16 @@ namespace StockInfo
|
|||||||
this.gpOwners.TabStop = false;
|
this.gpOwners.TabStop = false;
|
||||||
this.gpOwners.Text = "ShareOwners";
|
this.gpOwners.Text = "ShareOwners";
|
||||||
//
|
//
|
||||||
// comboBox1
|
// btnConnShares
|
||||||
//
|
//
|
||||||
this.comboBox1.FormattingEnabled = true;
|
this.btnConnShares.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||||
this.comboBox1.Location = new System.Drawing.Point(6, 33);
|
this.btnConnShares.Location = new System.Drawing.Point(120, 82);
|
||||||
this.comboBox1.Name = "comboBox1";
|
this.btnConnShares.Name = "btnConnShares";
|
||||||
this.comboBox1.Size = new System.Drawing.Size(152, 23);
|
this.btnConnShares.Size = new System.Drawing.Size(108, 23);
|
||||||
this.comboBox1.TabIndex = 0;
|
this.btnConnShares.TabIndex = 4;
|
||||||
|
this.btnConnShares.Text = "Connect Shares";
|
||||||
|
this.btnConnShares.UseVisualStyleBackColor = true;
|
||||||
|
this.btnConnShares.Click += new System.EventHandler(this.btnConnShares_Click);
|
||||||
//
|
//
|
||||||
// btnEditPerson
|
// btnEditPerson
|
||||||
//
|
//
|
||||||
@ -257,16 +260,14 @@ namespace StockInfo
|
|||||||
this.btnEditPerson.UseVisualStyleBackColor = true;
|
this.btnEditPerson.UseVisualStyleBackColor = true;
|
||||||
this.btnEditPerson.Click += new System.EventHandler(this.btnEditPerson_Click);
|
this.btnEditPerson.Click += new System.EventHandler(this.btnEditPerson_Click);
|
||||||
//
|
//
|
||||||
// btnConnShares
|
// cmbOwners
|
||||||
//
|
//
|
||||||
this.btnConnShares.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
this.cmbOwners.FormattingEnabled = true;
|
||||||
this.btnConnShares.Location = new System.Drawing.Point(120, 82);
|
this.cmbOwners.Location = new System.Drawing.Point(6, 33);
|
||||||
this.btnConnShares.Name = "btnConnShares";
|
this.cmbOwners.Name = "cmbOwners";
|
||||||
this.btnConnShares.Size = new System.Drawing.Size(108, 23);
|
this.cmbOwners.Size = new System.Drawing.Size(152, 23);
|
||||||
this.btnConnShares.TabIndex = 4;
|
this.cmbOwners.TabIndex = 0;
|
||||||
this.btnConnShares.Text = "Connect Shares";
|
this.cmbOwners.SelectedIndexChanged += new System.EventHandler(this.cmbOwners_SelectedIndexChanged);
|
||||||
this.btnConnShares.UseVisualStyleBackColor = true;
|
|
||||||
this.btnConnShares.Click += new System.EventHandler(this.btnConnShares_Click);
|
|
||||||
//
|
//
|
||||||
// frmInitial
|
// frmInitial
|
||||||
//
|
//
|
||||||
@ -288,6 +289,7 @@ namespace StockInfo
|
|||||||
this.Text = "Stock Overview";
|
this.Text = "Stock Overview";
|
||||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmInitial_FormClosing);
|
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmInitial_FormClosing);
|
||||||
this.Load += new System.EventHandler(this.Form1_Load);
|
this.Load += new System.EventHandler(this.Form1_Load);
|
||||||
|
this.Shown += new System.EventHandler(this.frmInitial_Shown);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
this.gB1.ResumeLayout(false);
|
this.gB1.ResumeLayout(false);
|
||||||
this.gB1.PerformLayout();
|
this.gB1.PerformLayout();
|
||||||
@ -320,7 +322,7 @@ namespace StockInfo
|
|||||||
private System.Windows.Forms.GroupBox gpOwners;
|
private System.Windows.Forms.GroupBox gpOwners;
|
||||||
private System.Windows.Forms.Button btnConnShares;
|
private System.Windows.Forms.Button btnConnShares;
|
||||||
private System.Windows.Forms.Button btnEditPerson;
|
private System.Windows.Forms.Button btnEditPerson;
|
||||||
private System.Windows.Forms.ComboBox comboBox1;
|
private System.Windows.Forms.ComboBox cmbOwners;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -178,5 +178,27 @@ namespace StockInfo
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void frmInitial_Shown(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadCmbOwners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadCmbOwners()
|
||||||
|
{
|
||||||
|
var owners = _personRepository.GetAllOwners();
|
||||||
|
if (owners.Count() > 0)
|
||||||
|
{
|
||||||
|
foreach (var person in owners)
|
||||||
|
{
|
||||||
|
var itemIndex = cmbOwners.Items.Add($"{person.FirstName} {person.LastName} ({person.NickName})");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cmbOwners_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
40
StockInfo/frmPerson.Designer.cs
generated
40
StockInfo/frmPerson.Designer.cs
generated
@ -40,6 +40,7 @@ namespace StockInfo
|
|||||||
this.txtLastName = new System.Windows.Forms.TextBox();
|
this.txtLastName = new System.Windows.Forms.TextBox();
|
||||||
this.label5 = new System.Windows.Forms.Label();
|
this.label5 = new System.Windows.Forms.Label();
|
||||||
this.gbAddress = new System.Windows.Forms.GroupBox();
|
this.gbAddress = new System.Windows.Forms.GroupBox();
|
||||||
|
this.txtDestination = new System.Windows.Forms.TextBox();
|
||||||
this.txtNation = new System.Windows.Forms.TextBox();
|
this.txtNation = new System.Windows.Forms.TextBox();
|
||||||
this.label10 = new System.Windows.Forms.Label();
|
this.label10 = new System.Windows.Forms.Label();
|
||||||
this.txtZipCode = new System.Windows.Forms.TextBox();
|
this.txtZipCode = new System.Windows.Forms.TextBox();
|
||||||
@ -55,7 +56,6 @@ namespace StockInfo
|
|||||||
this.txtAccountNr = new System.Windows.Forms.TextBox();
|
this.txtAccountNr = new System.Windows.Forms.TextBox();
|
||||||
this.btnAddSave = new System.Windows.Forms.Button();
|
this.btnAddSave = new System.Windows.Forms.Button();
|
||||||
this.btnClose = new System.Windows.Forms.Button();
|
this.btnClose = new System.Windows.Forms.Button();
|
||||||
this.txtDestination = new System.Windows.Forms.TextBox();
|
|
||||||
this.gbAddress.SuspendLayout();
|
this.gbAddress.SuspendLayout();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -80,7 +80,7 @@ namespace StockInfo
|
|||||||
this.txtComment.Location = new System.Drawing.Point(113, 162);
|
this.txtComment.Location = new System.Drawing.Point(113, 162);
|
||||||
this.txtComment.Name = "txtComment";
|
this.txtComment.Name = "txtComment";
|
||||||
this.txtComment.Size = new System.Drawing.Size(188, 23);
|
this.txtComment.Size = new System.Drawing.Size(188, 23);
|
||||||
this.txtComment.TabIndex = 3;
|
this.txtComment.TabIndex = 5;
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
//
|
//
|
||||||
@ -96,7 +96,7 @@ namespace StockInfo
|
|||||||
this.txtPersonNr.Location = new System.Drawing.Point(113, 133);
|
this.txtPersonNr.Location = new System.Drawing.Point(113, 133);
|
||||||
this.txtPersonNr.Name = "txtPersonNr";
|
this.txtPersonNr.Name = "txtPersonNr";
|
||||||
this.txtPersonNr.Size = new System.Drawing.Size(188, 23);
|
this.txtPersonNr.Size = new System.Drawing.Size(188, 23);
|
||||||
this.txtPersonNr.TabIndex = 5;
|
this.txtPersonNr.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// label3
|
// label3
|
||||||
//
|
//
|
||||||
@ -112,7 +112,7 @@ namespace StockInfo
|
|||||||
this.txtNickName.Location = new System.Drawing.Point(113, 104);
|
this.txtNickName.Location = new System.Drawing.Point(113, 104);
|
||||||
this.txtNickName.Name = "txtNickName";
|
this.txtNickName.Name = "txtNickName";
|
||||||
this.txtNickName.Size = new System.Drawing.Size(188, 23);
|
this.txtNickName.Size = new System.Drawing.Size(188, 23);
|
||||||
this.txtNickName.TabIndex = 7;
|
this.txtNickName.TabIndex = 3;
|
||||||
//
|
//
|
||||||
// label4
|
// label4
|
||||||
//
|
//
|
||||||
@ -128,7 +128,7 @@ namespace StockInfo
|
|||||||
this.txtLastName.Location = new System.Drawing.Point(113, 75);
|
this.txtLastName.Location = new System.Drawing.Point(113, 75);
|
||||||
this.txtLastName.Name = "txtLastName";
|
this.txtLastName.Name = "txtLastName";
|
||||||
this.txtLastName.Size = new System.Drawing.Size(188, 23);
|
this.txtLastName.Size = new System.Drawing.Size(188, 23);
|
||||||
this.txtLastName.TabIndex = 9;
|
this.txtLastName.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// label5
|
// label5
|
||||||
//
|
//
|
||||||
@ -159,12 +159,19 @@ namespace StockInfo
|
|||||||
this.gbAddress.TabStop = false;
|
this.gbAddress.TabStop = false;
|
||||||
this.gbAddress.Text = "Addresses";
|
this.gbAddress.Text = "Addresses";
|
||||||
//
|
//
|
||||||
|
// txtDestination
|
||||||
|
//
|
||||||
|
this.txtDestination.Location = new System.Drawing.Point(148, 106);
|
||||||
|
this.txtDestination.Name = "txtDestination";
|
||||||
|
this.txtDestination.Size = new System.Drawing.Size(146, 23);
|
||||||
|
this.txtDestination.TabIndex = 12;
|
||||||
|
//
|
||||||
// txtNation
|
// txtNation
|
||||||
//
|
//
|
||||||
this.txtNation.Location = new System.Drawing.Point(84, 135);
|
this.txtNation.Location = new System.Drawing.Point(84, 135);
|
||||||
this.txtNation.Name = "txtNation";
|
this.txtNation.Name = "txtNation";
|
||||||
this.txtNation.Size = new System.Drawing.Size(210, 23);
|
this.txtNation.Size = new System.Drawing.Size(210, 23);
|
||||||
this.txtNation.TabIndex = 9;
|
this.txtNation.TabIndex = 13;
|
||||||
//
|
//
|
||||||
// label10
|
// label10
|
||||||
//
|
//
|
||||||
@ -180,7 +187,7 @@ namespace StockInfo
|
|||||||
this.txtZipCode.Location = new System.Drawing.Point(84, 106);
|
this.txtZipCode.Location = new System.Drawing.Point(84, 106);
|
||||||
this.txtZipCode.Name = "txtZipCode";
|
this.txtZipCode.Name = "txtZipCode";
|
||||||
this.txtZipCode.Size = new System.Drawing.Size(58, 23);
|
this.txtZipCode.Size = new System.Drawing.Size(58, 23);
|
||||||
this.txtZipCode.TabIndex = 7;
|
this.txtZipCode.TabIndex = 11;
|
||||||
//
|
//
|
||||||
// label9
|
// label9
|
||||||
//
|
//
|
||||||
@ -196,7 +203,7 @@ namespace StockInfo
|
|||||||
this.txtStreet2.Location = new System.Drawing.Point(84, 77);
|
this.txtStreet2.Location = new System.Drawing.Point(84, 77);
|
||||||
this.txtStreet2.Name = "txtStreet2";
|
this.txtStreet2.Name = "txtStreet2";
|
||||||
this.txtStreet2.Size = new System.Drawing.Size(210, 23);
|
this.txtStreet2.Size = new System.Drawing.Size(210, 23);
|
||||||
this.txtStreet2.TabIndex = 5;
|
this.txtStreet2.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// label8
|
// label8
|
||||||
//
|
//
|
||||||
@ -212,7 +219,7 @@ namespace StockInfo
|
|||||||
this.txtStreet.Location = new System.Drawing.Point(84, 48);
|
this.txtStreet.Location = new System.Drawing.Point(84, 48);
|
||||||
this.txtStreet.Name = "txtStreet";
|
this.txtStreet.Name = "txtStreet";
|
||||||
this.txtStreet.Size = new System.Drawing.Size(210, 23);
|
this.txtStreet.Size = new System.Drawing.Size(210, 23);
|
||||||
this.txtStreet.TabIndex = 3;
|
this.txtStreet.TabIndex = 9;
|
||||||
//
|
//
|
||||||
// label7
|
// label7
|
||||||
//
|
//
|
||||||
@ -232,6 +239,7 @@ namespace StockInfo
|
|||||||
this.rdbInvoiceAddr.TabIndex = 1;
|
this.rdbInvoiceAddr.TabIndex = 1;
|
||||||
this.rdbInvoiceAddr.Text = "Invoice Address";
|
this.rdbInvoiceAddr.Text = "Invoice Address";
|
||||||
this.rdbInvoiceAddr.UseVisualStyleBackColor = true;
|
this.rdbInvoiceAddr.UseVisualStyleBackColor = true;
|
||||||
|
this.rdbInvoiceAddr.CheckedChanged += new System.EventHandler(this.rdbInvoiceAddr_CheckedChanged);
|
||||||
//
|
//
|
||||||
// rdbHome
|
// rdbHome
|
||||||
//
|
//
|
||||||
@ -240,17 +248,18 @@ namespace StockInfo
|
|||||||
this.rdbHome.Location = new System.Drawing.Point(7, 23);
|
this.rdbHome.Location = new System.Drawing.Point(7, 23);
|
||||||
this.rdbHome.Name = "rdbHome";
|
this.rdbHome.Name = "rdbHome";
|
||||||
this.rdbHome.Size = new System.Drawing.Size(103, 19);
|
this.rdbHome.Size = new System.Drawing.Size(103, 19);
|
||||||
this.rdbHome.TabIndex = 0;
|
this.rdbHome.TabIndex = 8;
|
||||||
this.rdbHome.TabStop = true;
|
this.rdbHome.TabStop = true;
|
||||||
this.rdbHome.Text = "Home Address";
|
this.rdbHome.Text = "Home Address";
|
||||||
this.rdbHome.UseVisualStyleBackColor = true;
|
this.rdbHome.UseVisualStyleBackColor = true;
|
||||||
|
this.rdbHome.CheckedChanged += new System.EventHandler(this.rdbInvoiceAddr_CheckedChanged);
|
||||||
//
|
//
|
||||||
// txtClearingNo
|
// txtClearingNo
|
||||||
//
|
//
|
||||||
this.txtClearingNo.Location = new System.Drawing.Point(113, 191);
|
this.txtClearingNo.Location = new System.Drawing.Point(113, 191);
|
||||||
this.txtClearingNo.Name = "txtClearingNo";
|
this.txtClearingNo.Name = "txtClearingNo";
|
||||||
this.txtClearingNo.Size = new System.Drawing.Size(42, 23);
|
this.txtClearingNo.Size = new System.Drawing.Size(42, 23);
|
||||||
this.txtClearingNo.TabIndex = 12;
|
this.txtClearingNo.TabIndex = 6;
|
||||||
//
|
//
|
||||||
// label6
|
// label6
|
||||||
//
|
//
|
||||||
@ -266,7 +275,7 @@ namespace StockInfo
|
|||||||
this.txtAccountNr.Location = new System.Drawing.Point(161, 191);
|
this.txtAccountNr.Location = new System.Drawing.Point(161, 191);
|
||||||
this.txtAccountNr.Name = "txtAccountNr";
|
this.txtAccountNr.Name = "txtAccountNr";
|
||||||
this.txtAccountNr.Size = new System.Drawing.Size(152, 23);
|
this.txtAccountNr.Size = new System.Drawing.Size(152, 23);
|
||||||
this.txtAccountNr.TabIndex = 13;
|
this.txtAccountNr.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// btnAddSave
|
// btnAddSave
|
||||||
//
|
//
|
||||||
@ -287,13 +296,6 @@ namespace StockInfo
|
|||||||
this.btnClose.Text = "Close";
|
this.btnClose.Text = "Close";
|
||||||
this.btnClose.UseVisualStyleBackColor = true;
|
this.btnClose.UseVisualStyleBackColor = true;
|
||||||
//
|
//
|
||||||
// txtDestination
|
|
||||||
//
|
|
||||||
this.txtDestination.Location = new System.Drawing.Point(148, 106);
|
|
||||||
this.txtDestination.Name = "txtDestination";
|
|
||||||
this.txtDestination.Size = new System.Drawing.Size(146, 23);
|
|
||||||
this.txtDestination.TabIndex = 10;
|
|
||||||
//
|
|
||||||
// frmPerson
|
// frmPerson
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using DataDomain;
|
using DataDomain;
|
||||||
|
using Helpers;
|
||||||
using StockDAL.Interface;
|
using StockDAL.Interface;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -16,6 +17,7 @@ namespace StockInfo
|
|||||||
{
|
{
|
||||||
private readonly IPersonRepository _personRepository;
|
private readonly IPersonRepository _personRepository;
|
||||||
private readonly IAddressRepository _addressRepository;
|
private readonly IAddressRepository _addressRepository;
|
||||||
|
private bool radioOk = false;
|
||||||
|
|
||||||
public frmPerson(IPersonRepository personRepository, IAddressRepository addressRepository)
|
public frmPerson(IPersonRepository personRepository, IAddressRepository addressRepository)
|
||||||
{
|
{
|
||||||
@ -32,6 +34,66 @@ namespace StockInfo
|
|||||||
private void btnAddSave_Click(object sender, EventArgs e)
|
private void btnAddSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
(Person person, bool OK) = validatePerson();
|
||||||
|
if (OK)
|
||||||
|
{
|
||||||
|
person = _personRepository.SavePerson(person);
|
||||||
|
PersonId = person.Id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private (Person person, bool OK) validatePerson()
|
||||||
|
{
|
||||||
|
var person = new Person();
|
||||||
|
person.Id = PersonId;
|
||||||
|
person.FirstName = txtFirstName.Text;
|
||||||
|
person.LastName = txtLastName.Text;
|
||||||
|
person.NickName = txtNickName.Text;
|
||||||
|
person.ClearingNo = txtClearingNo.Text.IsNumeric()?int.Parse(txtClearingNo.Text):0;
|
||||||
|
person.AccountNo = txtAccountNr.Text.IsNumeric() ? int.Parse(txtAccountNr.Text) : 0;
|
||||||
|
person.Born = txtPersonNr.Text;
|
||||||
|
person.Comments = txtComment.Text;
|
||||||
|
HomeAddressId = AddressSave();
|
||||||
|
person.HomeAddress = HomeAddressId;
|
||||||
|
person.InvoiceAddress = InvoiceAddressId;
|
||||||
|
return (person, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int AddressSave()
|
||||||
|
{
|
||||||
|
var retval = 0;
|
||||||
|
bool changed = false;
|
||||||
|
Address address = new Address();
|
||||||
|
(address.Street, changed) = checkString(txtStreet.Text);
|
||||||
|
(address.Street2, changed) = checkString(txtStreet2.Text);
|
||||||
|
(address.Zipcode, changed) = checkInt(txtZipCode.Text);
|
||||||
|
(address.Destination, changed) = checkString(txtDestination.Text);
|
||||||
|
(address.Nation, changed) = checkString(txtNation.Text);
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
retval =_addressRepository.SaveAddress(address).Id;
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (string, bool ) checkString(string text)
|
||||||
|
{
|
||||||
|
bool chgd = !string.IsNullOrWhiteSpace(text);
|
||||||
|
return (text, chgd);
|
||||||
|
}
|
||||||
|
private (int, bool) checkInt(string text)
|
||||||
|
{
|
||||||
|
bool chgd = false;
|
||||||
|
if(!string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
chgd = int.Parse(text) > 0;
|
||||||
|
}
|
||||||
|
return (chgd?int.Parse(text):0, chgd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void frmPerson_Load(object sender, EventArgs e)
|
private void frmPerson_Load(object sender, EventArgs e)
|
||||||
@ -55,7 +117,12 @@ namespace StockInfo
|
|||||||
txtComment.Text = person.Comments;
|
txtComment.Text = person.Comments;
|
||||||
txtClearingNo.Text = person.ClearingNo.ToString();
|
txtClearingNo.Text = person.ClearingNo.ToString();
|
||||||
txtAccountNr.Text = person.AccountNo.ToString();
|
txtAccountNr.Text = person.AccountNo.ToString();
|
||||||
var address = _addressRepository.GetAddressById(HomeAddressId);
|
ShowAddressFrom(HomeAddressId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowAddressFrom(int AddrId)
|
||||||
|
{
|
||||||
|
var address = _addressRepository.GetAddressById(AddrId);
|
||||||
if (address != null)
|
if (address != null)
|
||||||
{
|
{
|
||||||
txtStreet.Text = address.Street;
|
txtStreet.Text = address.Street;
|
||||||
@ -75,11 +142,44 @@ namespace StockInfo
|
|||||||
txtComment.Text = "";
|
txtComment.Text = "";
|
||||||
txtClearingNo.Text = "";
|
txtClearingNo.Text = "";
|
||||||
txtAccountNr.Text = "";
|
txtAccountNr.Text = "";
|
||||||
|
ClearAddress();
|
||||||
|
HomeAddressId = 0;
|
||||||
|
InvoiceAddressId = 0;
|
||||||
|
rdbHome.Checked = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ClearAddress()
|
||||||
|
{
|
||||||
txtStreet.Text = "";
|
txtStreet.Text = "";
|
||||||
txtStreet2.Text = "";
|
txtStreet2.Text = "";
|
||||||
txtZipCode.Text = "";
|
txtZipCode.Text = "";
|
||||||
txtDestination.Text = "";
|
txtDestination.Text = "";
|
||||||
txtNation.Text = "";
|
txtNation.Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rdbInvoiceAddr_CheckedChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (!radioOk)
|
||||||
|
{
|
||||||
|
if (rdbInvoiceAddr.Checked)
|
||||||
|
{
|
||||||
|
HomeAddressId = AddressSave();
|
||||||
|
ClearAddress();
|
||||||
|
ShowAddressFrom(InvoiceAddressId);
|
||||||
|
radioOk = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InvoiceAddressId = AddressSave();
|
||||||
|
ClearAddress();
|
||||||
|
ShowAddressFrom(HomeAddressId);
|
||||||
|
radioOk = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
radioOk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user