Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 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. using System.IO;
  11.  
  12. namespace WindowsFormsApp18
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private void btn_load_Click(object sender, EventArgs e)
  22. {
  23. OpenFileDialog loadDialog = new OpenFileDialog();
  24. loadDialog.Filter = "txt files (*.txt)|*.txt";
  25. if (loadDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  26. {
  27. textBox1.Clear();
  28. StreamReader file = new StreamReader(loadDialog.OpenFile());
  29.  
  30. string write;
  31. while((write = file.ReadLine()) != null)
  32. {
  33. textBox1.AppendText(write + "\n");
  34. }
  35.  
  36. file.Close();
  37.  
  38. }
  39. }
  40.  
  41. private void btn_save_Click(object sender, EventArgs e)
  42. {
  43.  
  44. SaveFileDialog saveDialog = new SaveFileDialog();
  45. saveDialog.Filter = "txt files (*.txt)|*.txt";
  46. if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  47. {
  48. StreamWriter file = new StreamWriter(saveDialog.OpenFile());
  49.  
  50. foreach(string text in textBox1.Lines)
  51. {
  52. file.WriteLine(text);
  53. file.Flush();
  54. }
  55. file.Close();
  56.  
  57. }
  58. textBox1.Clear();
  59.  
  60. }
  61.  
  62. private void btn_calculate_Click(object sender, EventArgs e)
  63. {
  64.  
  65. List<string> output = new List<string>();
  66.  
  67. foreach(string text in textBox1.Lines)
  68. {
  69.  
  70. /*if (text.Any(char.IsDigit))
  71. {
  72. output.Add(text)
  73. return;
  74. }*/
  75.  
  76. double a, b;
  77. char c;
  78. string[] znak = text.Split(new Char[] { ' ' });
  79.  
  80. a = Double.Parse(znak[0]);
  81. b = Double.Parse(znak[2]);
  82. c = Char.Parse(znak[1]);
  83. switch (c)
  84. {
  85. case '+': output.Add( a.ToString() + " + " + b.ToString() + " = " + (a + b).ToString() + "\n" ); break;
  86. case '*': output.Add( a.ToString() + " * " + b.ToString() + " = " + (a * b).ToString() + "\n"); break;
  87. case '-': output.Add( a.ToString() + " - " + b.ToString() + " = " + (a - b).ToString() + "\n"); break;
  88. case '/': output.Add( a.ToString() + " / " + b.ToString() + " = " + (a / b).ToString() + "\n"); break;
  89. case '^': output.Add( a.ToString() + " ^ " + b.ToString() + " = " + (Math.Pow(a,b)).ToString() + "\n"); break;
  90. }
  91.  
  92. }
  93.  
  94. textBox1.Clear();
  95.  
  96. foreach(string text in output)
  97. {
  98. textBox1.AppendText(text);
  99. }
  100.  
  101. }
  102.  
  103. private void btn_transform_Click(object sender, EventArgs e)
  104. {
  105.  
  106. List<string> output = new List<string>();
  107.  
  108. foreach(string text in textBox1.Lines)
  109. {
  110. output.Add(text.ToLower());
  111. }
  112.  
  113. textBox1.Clear();
  114.  
  115. foreach(string text in output)
  116. {
  117. textBox1.AppendText(text + "\n");
  118. }
  119.  
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement