示例#1
0
        private void BtnCalc_Click(object sender, EventArgs e)
        {
            BlockchainLibrary.Block[] blocks = new BlockchainLibrary.Block[_chain.Length];
            _chain.BlockChain.ToList().CopyTo(blocks);

            for (int i = 0, j = 0; i < GridPanel.Controls.Count && j < _chain.Length; i++)
            {
                if (GridPanel.Controls[i] is MetroFramework.Controls.MetroPanel)
                {
                    var panel      = GridPanel.Controls[i] as MetroFramework.Controls.MetroPanel;
                    var txtHash    = panel.Controls[0] as MetroFramework.Controls.MetroTextBox;
                    var txtContext = panel.Controls[1] as MetroFramework.Controls.MetroTextBox;

                    if (j > 0)
                    {
                        blocks[j].SetprevHash(blocks[j - 1].GetHash());
                    }
                    blocks[j].SetData(txtContext.Text);

                    if (blocks[j].IsCorrect() == false)
                    {
                        panel.UseCustomBackColor = true;
                        panel.BackColor          = Color.PaleVioletRed;
                    }
                    else
                    {
                        panel.BackColor          = SystemColors.Control;
                        panel.UseCustomBackColor = false;
                    }
                    txtHash.Text = blocks[j].GetHash();

                    j++;
                }
            }
        }
示例#2
0
        private void LoadData(BlockchainLibrary.Block block)
        {
            var panel = new MetroFramework.Controls.MetroPanel()
            {
                Anchor      = (AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top),
                Size        = GetSizePanel,
                Location    = new System.Drawing.Point(curLocation.X, curLocation.Y),
                BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            };

            panel.Controls.Clear();

            var txtHash = new MetroFramework.Controls.MetroTextBox
            {
                Anchor   = (AnchorStyles.Left | AnchorStyles.Top),
                Text     = block.Hash,
                Enabled  = false,
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtHash.Width, Height = GetSizeTxtHash.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtHash.X, GetLocationTxtHash.Y)
            };

            panel.Controls.Add(txtHash);

            var txtContent = new MetroFramework.Controls.MetroTextBox
            {
                Anchor    = (AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Top),
                Text      = block.Data.Content,
                Multiline = true,
                ReadOnly  = true,
                Size      = new System.Drawing.Size()
                {
                    Width = GetSizeTxtContent.Width, Height = GetSizeTxtContent.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtContent.X, GetLocationTxtContent.Y)
            };

            panel.Controls.Add(txtContent);

            var txtUser = new MetroFramework.Controls.MetroTextBox
            {
                Anchor   = (AnchorStyles.Left | AnchorStyles.Bottom),
                Text     = block.UserFrom.Login,
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtUser.Width, Height = GetSizeTxtUser.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtUser.X, GetLocationTxtUser.Y)
            };

            panel.Controls.Add(txtUser);

            var txtMoney = new MetroFramework.Controls.MetroTextBox
            {
                Anchor   = (AnchorStyles.Left | AnchorStyles.Bottom),
                Text     = block.Money.ToString() + " $",
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtMoney.Width, Height = GetSizeTxtMoney.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtMoney.X, GetLocationTxtMoney.Y)
            };

            panel.Controls.Add(txtMoney);

            var txtDateTime = new MetroFramework.Controls.MetroTextBox
            {
                Anchor   = (AnchorStyles.Left | AnchorStyles.Bottom),
                Text     = block.CreatedOn.ToString(),
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtDateTime.Width, Height = GetSizeTxtDateTime.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtDateTime.X, GetLocationTxtDateTime.Y)
            };

            panel.Controls.Add(txtDateTime);

            var txtPrevHash = new MetroFramework.Controls.MetroTextBox
            {
                Anchor   = (AnchorStyles.Left | AnchorStyles.Bottom),
                Text     = block.PreviousHash,
                ReadOnly = true,
                Size     = new System.Drawing.Size()
                {
                    Width = GetSizeTxtHash.Width, Height = GetSizeTxtHash.Height
                },
                Location = new System.Drawing.Point(GetLocationTxtPrevHash.X, GetLocationTxtPrevHash.Y)
            };

            panel.Controls.Add(txtPrevHash);

            curGrid.Controls.Add(panel);
            curLocation = new Point(panel.Location.X + panel.Width + OFFSET, panel.Location.Y);
        }