FrmMain: Better user information.

This commit is contained in:
2020-09-05 13:47:05 +02:00
parent cf308b09a2
commit acf85f968e
2 changed files with 132 additions and 29 deletions

View File

@@ -40,8 +40,13 @@
this.txtMinerName = new System.Windows.Forms.TextBox(); this.txtMinerName = new System.Windows.Forms.TextBox();
this.txtFrom = new System.Windows.Forms.TextBox(); this.txtFrom = new System.Windows.Forms.TextBox();
this.txtTo = new System.Windows.Forms.TextBox(); this.txtTo = new System.Windows.Forms.TextBox();
this.txtAmount = new System.Windows.Forms.TextBox(); this.numAmount = new System.Windows.Forms.NumericUpDown();
this.btnClearFrom = new System.Windows.Forms.Button();
this.btnClearTo = new System.Windows.Forms.Button();
this.btnClearAmount = new System.Windows.Forms.Button();
this.lsbUsers = new System.Windows.Forms.ListBox();
this.grpAddTransaction.SuspendLayout(); this.grpAddTransaction.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numAmount)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// lsbTransactions // lsbTransactions
@@ -49,25 +54,22 @@
this.lsbTransactions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.lsbTransactions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left))); | System.Windows.Forms.AnchorStyles.Left)));
this.lsbTransactions.FormattingEnabled = true; this.lsbTransactions.FormattingEnabled = true;
this.lsbTransactions.Location = new System.Drawing.Point(12, 12); this.lsbTransactions.Location = new System.Drawing.Point(12, 129);
this.lsbTransactions.Name = "lsbTransactions"; this.lsbTransactions.Name = "lsbTransactions";
this.lsbTransactions.Size = new System.Drawing.Size(225, 303); this.lsbTransactions.Size = new System.Drawing.Size(225, 368);
this.lsbTransactions.TabIndex = 0; this.lsbTransactions.TabIndex = 0;
// //
// lsbPendingTransactions // lsbPendingTransactions
// //
this.lsbPendingTransactions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lsbPendingTransactions.FormattingEnabled = true; this.lsbPendingTransactions.FormattingEnabled = true;
this.lsbPendingTransactions.Location = new System.Drawing.Point(243, 12); this.lsbPendingTransactions.Location = new System.Drawing.Point(12, 12);
this.lsbPendingTransactions.Name = "lsbPendingTransactions"; this.lsbPendingTransactions.Name = "lsbPendingTransactions";
this.lsbPendingTransactions.Size = new System.Drawing.Size(225, 277); this.lsbPendingTransactions.Size = new System.Drawing.Size(225, 82);
this.lsbPendingTransactions.TabIndex = 1; this.lsbPendingTransactions.TabIndex = 1;
// //
// btnMine // btnMine
// //
this.btnMine.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnMine.Location = new System.Drawing.Point(162, 100);
this.btnMine.Location = new System.Drawing.Point(393, 297);
this.btnMine.Name = "btnMine"; this.btnMine.Name = "btnMine";
this.btnMine.Size = new System.Drawing.Size(75, 23); this.btnMine.Size = new System.Drawing.Size(75, 23);
this.btnMine.TabIndex = 2; this.btnMine.TabIndex = 2;
@@ -77,23 +79,26 @@
// //
// grpAddTransaction // grpAddTransaction
// //
this.grpAddTransaction.Controls.Add(this.txtAmount); this.grpAddTransaction.Controls.Add(this.btnClearAmount);
this.grpAddTransaction.Controls.Add(this.btnClearTo);
this.grpAddTransaction.Controls.Add(this.btnClearFrom);
this.grpAddTransaction.Controls.Add(this.numAmount);
this.grpAddTransaction.Controls.Add(this.txtTo); this.grpAddTransaction.Controls.Add(this.txtTo);
this.grpAddTransaction.Controls.Add(this.txtFrom); this.grpAddTransaction.Controls.Add(this.txtFrom);
this.grpAddTransaction.Controls.Add(this.lblAmount); this.grpAddTransaction.Controls.Add(this.lblAmount);
this.grpAddTransaction.Controls.Add(this.lblTo); this.grpAddTransaction.Controls.Add(this.lblTo);
this.grpAddTransaction.Controls.Add(this.lblFrom); this.grpAddTransaction.Controls.Add(this.lblFrom);
this.grpAddTransaction.Controls.Add(this.btnAdd); this.grpAddTransaction.Controls.Add(this.btnAdd);
this.grpAddTransaction.Location = new System.Drawing.Point(474, 12); this.grpAddTransaction.Location = new System.Drawing.Point(243, 12);
this.grpAddTransaction.Name = "grpAddTransaction"; this.grpAddTransaction.Name = "grpAddTransaction";
this.grpAddTransaction.Size = new System.Drawing.Size(155, 135); this.grpAddTransaction.Size = new System.Drawing.Size(175, 132);
this.grpAddTransaction.TabIndex = 3; this.grpAddTransaction.TabIndex = 3;
this.grpAddTransaction.TabStop = false; this.grpAddTransaction.TabStop = false;
this.grpAddTransaction.Text = "Add transaction"; this.grpAddTransaction.Text = "Add transaction";
// //
// btnAdd // btnAdd
// //
this.btnAdd.Location = new System.Drawing.Point(72, 97); this.btnAdd.Location = new System.Drawing.Point(94, 97);
this.btnAdd.Name = "btnAdd"; this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23); this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 0; this.btnAdd.TabIndex = 0;
@@ -130,38 +135,82 @@
// //
// txtMinerName // txtMinerName
// //
this.txtMinerName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.txtMinerName.Location = new System.Drawing.Point(69, 103);
this.txtMinerName.Location = new System.Drawing.Point(287, 300);
this.txtMinerName.Name = "txtMinerName"; this.txtMinerName.Name = "txtMinerName";
this.txtMinerName.Size = new System.Drawing.Size(100, 20); this.txtMinerName.Size = new System.Drawing.Size(87, 20);
this.txtMinerName.TabIndex = 4; this.txtMinerName.TabIndex = 4;
// //
// txtFrom // txtFrom
// //
this.txtFrom.Location = new System.Drawing.Point(47, 19); this.txtFrom.Location = new System.Drawing.Point(47, 19);
this.txtFrom.Name = "txtFrom"; this.txtFrom.Name = "txtFrom";
this.txtFrom.Size = new System.Drawing.Size(100, 20); this.txtFrom.Size = new System.Drawing.Size(95, 20);
this.txtFrom.TabIndex = 4; this.txtFrom.TabIndex = 4;
// //
// txtTo // txtTo
// //
this.txtTo.Location = new System.Drawing.Point(47, 45); this.txtTo.Location = new System.Drawing.Point(47, 45);
this.txtTo.Name = "txtTo"; this.txtTo.Name = "txtTo";
this.txtTo.Size = new System.Drawing.Size(100, 20); this.txtTo.Size = new System.Drawing.Size(95, 20);
this.txtTo.TabIndex = 5; this.txtTo.TabIndex = 5;
// //
// txtAmount // numAmount
// //
this.txtAmount.Location = new System.Drawing.Point(47, 71); this.numAmount.Location = new System.Drawing.Point(47, 71);
this.txtAmount.Name = "txtAmount"; this.numAmount.Maximum = new decimal(new int[] {
this.txtAmount.Size = new System.Drawing.Size(100, 20); -1,
this.txtAmount.TabIndex = 6; 2147483647,
0,
0});
this.numAmount.Name = "numAmount";
this.numAmount.Size = new System.Drawing.Size(95, 20);
this.numAmount.TabIndex = 7;
//
// btnClearFrom
//
this.btnClearFrom.Location = new System.Drawing.Point(148, 19);
this.btnClearFrom.Name = "btnClearFrom";
this.btnClearFrom.Size = new System.Drawing.Size(21, 20);
this.btnClearFrom.TabIndex = 8;
this.btnClearFrom.Text = "X";
this.btnClearFrom.UseVisualStyleBackColor = true;
this.btnClearFrom.Click += new System.EventHandler(this.btnClearFrom_Click);
//
// btnClearTo
//
this.btnClearTo.Location = new System.Drawing.Point(148, 45);
this.btnClearTo.Name = "btnClearTo";
this.btnClearTo.Size = new System.Drawing.Size(21, 20);
this.btnClearTo.TabIndex = 9;
this.btnClearTo.Text = "X";
this.btnClearTo.UseVisualStyleBackColor = true;
this.btnClearTo.Click += new System.EventHandler(this.btnClearTo_Click);
//
// btnClearAmount
//
this.btnClearAmount.Location = new System.Drawing.Point(148, 71);
this.btnClearAmount.Name = "btnClearAmount";
this.btnClearAmount.Size = new System.Drawing.Size(21, 20);
this.btnClearAmount.TabIndex = 10;
this.btnClearAmount.Text = "X";
this.btnClearAmount.UseVisualStyleBackColor = true;
this.btnClearAmount.Click += new System.EventHandler(this.btnClearAmount_Click);
//
// lsbUsers
//
this.lsbUsers.FormattingEnabled = true;
this.lsbUsers.Location = new System.Drawing.Point(243, 150);
this.lsbUsers.Name = "lsbUsers";
this.lsbUsers.Size = new System.Drawing.Size(175, 134);
this.lsbUsers.TabIndex = 5;
this.lsbUsers.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.lsbUsers_MouseDoubleClick);
// //
// FrmMain // FrmMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(651, 338); this.ClientSize = new System.Drawing.Size(430, 521);
this.Controls.Add(this.lsbUsers);
this.Controls.Add(this.txtMinerName); this.Controls.Add(this.txtMinerName);
this.Controls.Add(this.grpAddTransaction); this.Controls.Add(this.grpAddTransaction);
this.Controls.Add(this.btnMine); this.Controls.Add(this.btnMine);
@@ -172,6 +221,7 @@
this.Text = "BasicBlockChain"; this.Text = "BasicBlockChain";
this.grpAddTransaction.ResumeLayout(false); this.grpAddTransaction.ResumeLayout(false);
this.grpAddTransaction.PerformLayout(); this.grpAddTransaction.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numAmount)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@@ -183,7 +233,6 @@
private System.Windows.Forms.ListBox lsbPendingTransactions; private System.Windows.Forms.ListBox lsbPendingTransactions;
private System.Windows.Forms.Button btnMine; private System.Windows.Forms.Button btnMine;
private System.Windows.Forms.GroupBox grpAddTransaction; private System.Windows.Forms.GroupBox grpAddTransaction;
private System.Windows.Forms.TextBox txtAmount;
private System.Windows.Forms.TextBox txtTo; private System.Windows.Forms.TextBox txtTo;
private System.Windows.Forms.TextBox txtFrom; private System.Windows.Forms.TextBox txtFrom;
private System.Windows.Forms.Label lblAmount; private System.Windows.Forms.Label lblAmount;
@@ -191,5 +240,10 @@
private System.Windows.Forms.Label lblFrom; private System.Windows.Forms.Label lblFrom;
private System.Windows.Forms.Button btnAdd; private System.Windows.Forms.Button btnAdd;
private System.Windows.Forms.TextBox txtMinerName; private System.Windows.Forms.TextBox txtMinerName;
private System.Windows.Forms.Button btnClearAmount;
private System.Windows.Forms.Button btnClearTo;
private System.Windows.Forms.Button btnClearFrom;
private System.Windows.Forms.NumericUpDown numAmount;
private System.Windows.Forms.ListBox lsbUsers;
} }
} }

View File

@@ -16,12 +16,12 @@ namespace BasicBlockChain
private void btnAdd_Click(object sender, EventArgs e) private void btnAdd_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(txtTo.Text) || string.IsNullOrEmpty(txtFrom.Text) || string.IsNullOrEmpty(txtAmount.Text)) { return; } if (string.IsNullOrEmpty(txtTo.Text) || string.IsNullOrEmpty(txtFrom.Text)) { return; }
long amount = Convert.ToInt64(txtAmount.Text); long amount = (long)numAmount.Value;
_nullCoin.AddTransaction(new Transaction(txtFrom.Text, txtTo.Text, amount, DateTime.UtcNow)); _nullCoin.AddTransaction(new Transaction(txtFrom.Text, txtTo.Text, amount, DateTime.UtcNow));
txtTo.Text = string.Empty; txtTo.Text = string.Empty;
txtFrom.Text = string.Empty; txtFrom.Text = string.Empty;
txtAmount.Text = string.Empty; numAmount.Value = 0;
Lists_Update(); Lists_Update();
} }
@@ -32,6 +32,21 @@ namespace BasicBlockChain
Lists_Update(); Lists_Update();
} }
private void btnClearFrom_Click(object sender, EventArgs e)
{
txtFrom.Text = string.Empty;
}
private void btnClearTo_Click(object sender, EventArgs e)
{
txtTo.Text = string.Empty;
}
private void btnClearAmount_Click(object sender, EventArgs e)
{
numAmount.Value = 0;
}
private void Lists_Update() private void Lists_Update()
{ {
lsbTransactions.Items.Clear(); lsbTransactions.Items.Clear();
@@ -48,11 +63,45 @@ namespace BasicBlockChain
{ {
lsbPendingTransactions.Items.Add(Transaction_ToString(transaction)); lsbPendingTransactions.Items.Add(Transaction_ToString(transaction));
} }
lsbUsers.Items.Clear();
foreach (string user in _nullCoin.Users)
{
long amount = _nullCoin.GetMicroCoinBalance(user);
lsbUsers.Items.Add(new Wallet { User = user, Amount = amount });
}
}
public class Wallet
{
public string User { get; set; }
public long Amount { get; set; }
public override string ToString()
{
return string.Format("{0} - {1}", User, Amount);
}
} }
private string Transaction_ToString(Transaction transaction) private string Transaction_ToString(Transaction transaction)
{ {
return string.Format("{0} - {1} - {2} - {3}", transaction.Date, transaction.Sender, transaction.Receiver, transaction.MicroCoinAmount); return string.Format("{0} - {1} - {2} - {3}", transaction.Date, transaction.Sender, transaction.Receiver, transaction.MicroCoinAmount);
} }
private void lsbUsers_MouseDoubleClick(object sender, MouseEventArgs e)
{
Wallet wallet = (Wallet)lsbUsers.SelectedItem;
if (wallet == null) { return; }
if (string.IsNullOrEmpty(txtFrom.Text))
{
txtFrom.Text = wallet.User;
return;
}
if (string.IsNullOrEmpty(txtTo.Text))
{
txtTo.Text = wallet.User;
return;
}
}
} }
} }