My C# code for combo buddy


SUBMITTED BY: Guest

DATE: March 6, 2015, 7:39 a.m.

FORMAT: C#

SIZE: 5.6 kB

HITS: 18846

  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. namespace ComboBuddy
  12. {
  13. public partial class ComboBuddy : Form
  14. {
  15. public ComboBuddy()
  16. {
  17. InitializeComponent();
  18. }
  19. private void _okLabel1_Click(object sender, EventArgs e)
  20. {
  21. }
  22. private void fButton1_Click(object sender, EventArgs e)
  23. {
  24. int dupeCounter = 0;
  25. OpenFileDialog diag = new OpenFileDialog();
  26. String text = "";
  27. if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  28. {
  29. StreamReader sr = new StreamReader(File.OpenRead(diag.FileName));
  30. while (sr.Peek() >= 0)
  31. {
  32. text = sr.ReadLine();
  33. if (listBox1.Items.Contains(text))
  34. {
  35. dupeCounter += 1;
  36. }
  37. else if (text != null)
  38. {
  39. listBox1.Items.Add(text);
  40. }
  41. }
  42. sr.Close();
  43. }
  44. else
  45. {
  46. MessageBox.Show("Please Select a File Path");
  47. }
  48. MessageBox.Show(dupeCounter + " Duplicates Removed");
  49. }
  50. private void fButton2_Click(object sender, EventArgs e)
  51. {
  52. listBox1.Items.Clear();
  53. }
  54. private void fButton3_Click(object sender, EventArgs e)
  55. {
  56. OpenFileDialog diag2 = new OpenFileDialog();
  57. if (diag2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  58. {
  59. StreamWriter sw = new StreamWriter(File.OpenWrite(diag2.FileName));
  60. foreach (string item in listBox1.Items)
  61. {
  62. sw.Write(item);
  63. }
  64. sw.Dispose();
  65. MessageBox.Show("Export Complete");
  66. }
  67. }
  68. private void meteButtonBlue2_Click(object sender, EventArgs e)
  69. {
  70. string user, pass;
  71. int pos;
  72. if (delimText.Text == "" || delimText.Text.Length > 1)
  73. {
  74. MessageBox.Show("Delimeter is empty or contains more than 1 character", "Error");
  75. }
  76. else
  77. {
  78. foreach (string item in listBox1.Items)
  79. {
  80. pos = item.IndexOf(delimText.Text);
  81. if (pos != -1)
  82. {
  83. user = item.Substring(0, pos);
  84. pass = item.Substring(pos + 1);
  85. ListViewItem lvi = new ListViewItem(user);
  86. lvi.SubItems.Add(pass);
  87. listView1.Items.Add(lvi);
  88. }
  89. }
  90. }
  91. }
  92. private void meteButtonBlue3_Click(object sender, EventArgs e)
  93. {
  94. listBox1.Sorted = true;
  95. MessageBox.Show("Put in order A->Z");
  96. }
  97. private void meteButtonBlue4_Click(object sender, EventArgs e)
  98. {
  99. if (listBox1.Sorted == true)
  100. {
  101. for (int i = 0; i < listBox1.Items.Count / 2; i++)
  102. {
  103. var tmp = listBox1.Items[i];
  104. listBox1.Items[i] = listBox1.Items[listBox1.Items.Count - i - 1];
  105. listBox1.Items[listBox1.Items.Count - i - 1] = tmp;
  106. }
  107. MessageBox.Show("Put in Z->A Order");
  108. }
  109. else
  110. {
  111. listBox1.Sorted = true;
  112. for (int i = 0; i < listBox1.Items.Count / 2; i++)
  113. {
  114. var tmp = listBox1.Items[i];
  115. listBox1.Items[i] = listBox1.Items[listBox1.Items.Count - i - 1];
  116. listBox1.Items[listBox1.Items.Count - i - 1] = tmp;
  117. }
  118. MessageBox.Show("Put in Z->A Order");
  119. }
  120. }
  121. private void meteButtonGreen1_Click(object sender, EventArgs e)
  122. {
  123. listView1.Items.Clear();
  124. }
  125. private void meteButtonGreen2_Click(object sender, EventArgs e)
  126. {
  127. OpenFileDialog diag3 = new OpenFileDialog();
  128. if (diag3.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  129. {
  130. StreamWriter sw2 = new StreamWriter(File.OpenWrite(diag3.FileName));
  131. foreach (ListViewItem item in listView1.Items)
  132. {
  133. sw2.WriteLine(item.Text);
  134. }
  135. sw2.WriteLine();
  136. sw2.WriteLine();
  137. //Code that exports the subitems as well
  138. sw2.Dispose();
  139. }
  140. else
  141. {
  142. MessageBox.Show("Error occurred. Did not write.");
  143. }
  144. }
  145. }
  146. }

comments powered by Disqus