Advertisement
Xsufu

Банковский счёт WinForms

Oct 27th, 2020 (edited)
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Bank_Application {
  12.     public partial class Form1 : Form {
  13.  
  14.         Queue<BankAccount> accounts = new Queue<BankAccount>();
  15.  
  16.         public Form1() {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         class BankAccount {
  21.  
  22.             //Номер лицевого счёта
  23.             string AccNum;
  24.             //Размер процента вклада
  25.             int procent;
  26.  
  27.             //Конструктор по умолчанию
  28.             public BankAccount() {
  29.                 AccNum = "";
  30.                 procent = 0;
  31.             }
  32.  
  33.             //Аксессор для номера счёта
  34.             public string AccNumA {
  35.                 get {
  36.                     return AccNum;
  37.                 }
  38.  
  39.                 set {
  40.                     AccNum = value;
  41.                 }
  42.             }
  43.  
  44.             //Аксессор для процентов
  45.             public int ProcentA {
  46.                 get {
  47.                     return procent;
  48.                 }
  49.  
  50.                 set {
  51.                     procent = value;
  52.                 }
  53.             }
  54.         }
  55.  
  56.         private void button1_Click(object sender, EventArgs e) {
  57.             labelAccNum.Visible = true;
  58.             labelProcent.Visible = true;
  59.             textBoxNumInput.Visible = true;
  60.             textBoxProcentInput.Visible = true;
  61.             buttonAdd.Visible = true;
  62.             textBox1.Visible = false;
  63.         }
  64.  
  65.         private void Form1_Load(object sender, EventArgs e) {
  66.             accounts.Enqueue(new BankAccount() { ProcentA = 13, AccNumA = "4234623" });
  67.             accounts.Enqueue(new BankAccount() { ProcentA = 10, AccNumA = "7862384" });
  68.             accounts.Enqueue(new BankAccount() { ProcentA = 8, AccNumA = "5465487" });
  69.             accounts.Enqueue(new BankAccount() { ProcentA = 14, AccNumA = "6541516" });
  70.             accounts.Enqueue(new BankAccount() { ProcentA = 18, AccNumA = "8794657" });
  71.         }
  72.  
  73.         private void buttonAdd_Click(object sender, EventArgs e) {
  74.             BankAccount nev = new BankAccount();
  75.             if (textBoxNumInput.TextLength != 0)
  76.                 nev.AccNumA = textBoxNumInput.Text;
  77.             if (textBoxProcentInput.TextLength != 0)
  78.                 nev.ProcentA = Int32.Parse(textBoxProcentInput.Text);
  79.             accounts.Enqueue(nev);
  80.         }
  81.  
  82.         private void buttonPrint_Click(object sender, EventArgs e) {
  83.             textBox1.Visible = true;
  84.             List<string> Num = new List<string>();
  85.             List<int> Prc = new List<int>();
  86.             foreach (BankAccount a in accounts) {
  87.                 Num.Add(a.AccNumA);
  88.                 Prc.Add(a.ProcentA);
  89.             }
  90.             String[] Meta = new string[Num.Count()];
  91.             string data;
  92.             for (int i = 0; i<Num.Count(); i++) {
  93.                 data =  $"{Num[i]}, {Convert.ToString(Prc[i])}%";
  94.                 Meta[i] = data;
  95.             }
  96.             textBox1.Lines = Meta;
  97.         }
  98.  
  99.         private void buttonDelete_Click(object sender, EventArgs e) {
  100.             buttonDeleteNum.Visible = true;
  101.             buttonDeleteProcent.Visible = true;
  102.             labelAccNum.Visible = false;
  103.             labelProcent.Visible = false;
  104.             textBoxNumInput.Visible = false;
  105.             textBoxProcentInput.Visible = false;
  106.             buttonAdd.Visible = false;
  107.             buttonDelete2.Visible = true;
  108.             textBox1.Visible = false;
  109.         }
  110.  
  111.         private void buttonDeleteNum_Click(object sender, EventArgs e) {
  112.             textBoxDeleteNum.Visible = true;
  113.             textBoxDeleteProcent.Visible = false;
  114.             label4DeleteProcent.Visible = false;
  115.             label4DeleteNum.Visible = true;
  116.             textBox1.Visible = false;
  117.         }
  118.  
  119.         private void buttonDeleteProcent_Click(object sender, EventArgs e) {
  120.             textBoxDeleteNum.Visible = false;
  121.             textBoxDeleteProcent.Visible = true;
  122.             label4DeleteProcent.Visible = true;
  123.             label4DeleteNum.Visible = false;
  124.             textBox1.Visible = false;
  125.         }
  126.  
  127.         private void textBoxDeleteProcent_TextChanged(object sender, EventArgs e) {
  128.  
  129.         }
  130.  
  131.         private void buttonDelete2_Click(object sender, EventArgs e) {
  132.             BankAccount delete = new BankAccount();
  133.             BankAccount now = new BankAccount();
  134.  
  135.             if (textBoxDeleteNum.TextLength != 0) {
  136.                 delete.AccNumA = textBoxDeleteNum.Text;
  137.                 for (int i = 0; i < accounts.Count; i++) {
  138.                     now = accounts.Dequeue();
  139.                     if (now.AccNumA != delete.AccNumA) {
  140.                         accounts.Enqueue(now);
  141.                     }
  142.                 }
  143.             }
  144.  
  145.             else {
  146.                 delete.ProcentA = Int32.Parse(textBoxDeleteProcent.Text);
  147.                 for (int i = 0; i < accounts.Count; i++) {
  148.                     now = accounts.Dequeue();
  149.                     if (now.ProcentA != delete.ProcentA) {
  150.                         accounts.Enqueue(now);
  151.                     }
  152.                 }
  153.             }
  154.             MessageBox.Show("Элемент успешно удалён");
  155.  
  156.         }
  157.  
  158.         private void button3_Click(object sender, EventArgs e) {
  159.             textBoxDeleteNum.Visible = false;
  160.             label4DeleteNum.Visible = false;
  161.             textBox1.Visible = false;
  162.             textBoxDeleteProcent.Visible = false;
  163.             label4DeleteProcent.Visible = false;
  164.             labelAccNum.Visible = false;
  165.             labelProcent.Visible = false;
  166.             textBoxNumInput.Visible = false;
  167.             textBoxProcentInput.Visible = false;
  168.             buttonAdd.Visible = false;
  169.             buttonDeleteNum.Visible = false;
  170.             buttonDeleteProcent.Visible = false;
  171.             buttonDelete2.Visible = false;
  172.  
  173.             BankAccount max = new BankAccount();
  174.             max = accounts.Peek();
  175.             foreach (BankAccount p in accounts) {
  176.                 if (p.ProcentA > max.ProcentA) {
  177.                     max.ProcentA = p.ProcentA;
  178.                     max.AccNumA = p.AccNumA;
  179.                 }
  180.             }
  181.  
  182.             MessageBox.Show($"Максимальный процент: {max.ProcentA} на счёте {max.AccNumA}");
  183.         }
  184.     }
  185. }
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement