Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.37 KB | None | 0 0
  1. using Manager;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace Manager
  13. {
  14. public partial class Form1 : Form
  15. {
  16. Config config;
  17. ReceivePacket rc;
  18. Manager man;
  19. public Form1(Manager man1)
  20. {
  21. man = man1;
  22. InitializeComponent();
  23. button2.Enabled = false;
  24.  
  25. }
  26.  
  27. private void Form1_Load(object sender, EventArgs e)
  28. {
  29.  
  30. }
  31.  
  32. private void label3_Click(object sender, EventArgs e)
  33. {
  34.  
  35. }
  36.  
  37. private void label4_Click(object sender, EventArgs e)
  38. {
  39.  
  40. }
  41.  
  42. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  43. {
  44.  
  45. }
  46. public void Data(string data1)
  47. {
  48.  
  49. listBox1.Invoke(new Action(delegate ()
  50. {
  51. listBox1.DrawMode = DrawMode.OwnerDrawVariable;
  52. listBox1.MeasureItem += lst_MeasureItem;
  53. listBox1.DrawItem += lst_DrawItem;
  54. listBox1.Items.Add(data1);
  55. }));
  56. }
  57.  
  58. private void lst_MeasureItem(object sender, MeasureItemEventArgs e)
  59. {
  60. e.ItemHeight = (int)e.Graphics.MeasureString(listBox1.Items[e.Index].ToString(), listBox1.Font, listBox1.Width).Height;
  61. }
  62.  
  63. private void lst_DrawItem(object sender, DrawItemEventArgs e)
  64. {
  65. e.DrawBackground();
  66. e.DrawFocusRectangle();
  67. e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
  68. }
  69. public void getConfig(Config config1)
  70. {
  71. config = config1;
  72. for (int i = 0; i < config.configs.Count(); i++)
  73. {
  74. if (config.configs[i].routerName.Equals("R1"))
  75. listBox2.Items.Add(config.cout(i));
  76. if (config.configs[i].routerName.Equals("R2"))
  77. listBox3.Items.Add(config.cout(i));
  78. if (config.configs[i].routerName.Equals("R3"))
  79. listBox4.Items.Add(config.cout(i));
  80. if (config.configs[i].routerName.Equals("R4"))
  81. listBox5.Items.Add(config.cout(i));
  82. if (config.configs[i].routerName.Equals("R5"))
  83. listBox6.Items.Add(config.cout(i));
  84. }
  85. }
  86.  
  87.  
  88.  
  89. private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
  90. {
  91. button2.Enabled = true;
  92. }
  93.  
  94. private void button2_Click(object sender, EventArgs e)
  95. {
  96.  
  97. if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage1"])
  98. {
  99. int tmp1 = listBox2.SelectedIndex;
  100. listBox2.Items.RemoveAt(tmp1);
  101. config.delete(tmp1);
  102.  
  103. }
  104. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])
  105. {
  106. int tmp1 = listBox3.SelectedIndex;
  107. listBox3.Items.RemoveAt(tmp1);
  108. config.delete(tmp1+listBox2.Items.Count);
  109.  
  110. }
  111. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage3"])
  112. {
  113. int tmp1 = listBox4.SelectedIndex;
  114. listBox4.Items.RemoveAt(tmp1);
  115. config.delete(tmp1 + listBox2.Items.Count + listBox3.Items.Count);
  116.  
  117. }
  118. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage4"])
  119. {
  120. int tmp1 = listBox5.SelectedIndex;
  121. listBox5.Items.RemoveAt(tmp1);
  122. config.delete(tmp1 + listBox2.Items.Count + listBox3.Items.Count + listBox4.Items.Count);
  123.  
  124. }
  125. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage5"])
  126. {
  127. int tmp1 = listBox6.SelectedIndex;
  128. listBox6.Items.RemoveAt(tmp1);
  129. config.delete(tmp1 + listBox2.Items.Count + listBox3.Items.Count + listBox4.Items.Count + listBox5.Items.Count);
  130.  
  131. }
  132. button2.Enabled = false;
  133.  
  134. StringBuilder sb = new StringBuilder();
  135.  
  136. string name = tabControl1.SelectedTab.Text;
  137.  
  138. for (int i = 0; i < config.configs.Count; i++)
  139. {
  140. sb.Append(config.configs[i].inLabel + " " + config.configs[i].outLabel + " " + config.configs[i].inPort + " " + config.configs[i].outPort + " " + config.configs[i].routerName + " " + config.configs[i].newLabel + " " + config.configs[i].labelAction + " " + config.configs[i].operationID + " ");
  141. }
  142.  
  143. man.SendNewTable(name, sb.ToString());
  144.  
  145. }
  146. private void button1_Click(object sender, EventArgs e)
  147. {
  148. int number = 0;
  149. if (int.TryParse(textBox1.Text.Trim(), out number) && int.TryParse(textBox2.Text.Trim(), out number) && int.TryParse(textBox3.Text.Trim(), out number) && int.TryParse(textBox4.Text.Trim(), out number))
  150. {
  151. //textBox value is a number; 3 cyfry 2 cyfry 3 cyfry 2 cyfry
  152. if (textBox1.TextLength > 2 && textBox2.TextLength > 1 && textBox3.TextLength > 2 && textBox4.TextLength > 1)
  153. {
  154. if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage1"])//your specific tabname
  155. {
  156. listBox2.Items.Add(" " + textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text);
  157. }
  158. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage2"])//your specific tabname
  159. {
  160. listBox3.Items.Add(" " + textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text);
  161. }
  162. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage3"])//your specific tabname
  163. {
  164. listBox4.Items.Add(" " + textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text);
  165. }
  166. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage4"])//your specific tabname
  167. {
  168. listBox5.Items.Add(" " + textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text);
  169. }
  170. else if (tabControl1.SelectedTab == tabControl1.TabPages["tabPage5"])//your specific tabname
  171. {
  172. listBox6.Items.Add(" " + textBox1.Text + " " + textBox2.Text + " " + textBox3.Text + " " + textBox4.Text);
  173. }
  174.  
  175. //Config config1 = new Config(Int32.Parse(textBox1.Text), Int32.Parse(textBox2.Text.ToString()), Int32.Parse(textBox3.Text.ToString()), Int32.Parse(textBox4.Text.ToString()), tabControl1.SelectedTab.Text);
  176. //config.configs.Add(config1);
  177. }
  178. }
  179. else
  180. {
  181. MessageBox.Show("Wpisana wartosc musi byc liczba");
  182. }
  183.  
  184.  
  185. StringBuilder sb = new StringBuilder();
  186. string name = tabControl1.SelectedTab.Text;
  187. int howmany = config.configs.Count();
  188. Config cfg = new Config(Int32.Parse(textBox1.Text), textBox3.Text, Int32.Parse(textBox2.Text), textBox4.Text, "-", "SWAP", howmany+1, name);
  189. config.configs.Add(cfg);
  190.  
  191. for (int i = 0; i < config.configs.Count; i++)
  192. {
  193. sb.Append(config.configs[i].inLabel + " " + config.configs[i].outLabel + " " + config.configs[i].inPort + " " + config.configs[i].outPort + " " + config.configs[i].routerName + " " + config.configs[i].newLabel + " " + config.configs[i].labelAction + " " + config.configs[i].operationID + " ");
  194. }
  195.  
  196. rc.StartSending(sb.ToString());
  197.  
  198.  
  199.  
  200. }
  201. private void textBox2_TextChanged(object sender, EventArgs e)
  202. {
  203.  
  204. }
  205. private void textBox3_TextChanged(object sender, EventArgs e)
  206. {
  207.  
  208. }
  209.  
  210. private void textBox4_TextChanged(object sender, EventArgs e)
  211. {
  212.  
  213. }
  214.  
  215. private void textBox1_TextChanged(object sender, EventArgs e)
  216. {
  217.  
  218. }
  219.  
  220. private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
  221. {
  222. button2.Enabled = true;
  223. }
  224.  
  225. private void listBox4_SelectedIndexChanged(object sender, EventArgs e)
  226. {
  227. button2.Enabled = true;
  228. }
  229.  
  230. private void listBox5_SelectedIndexChanged(object sender, EventArgs e)
  231. {
  232. button2.Enabled = true;
  233. }
  234.  
  235. private void listBox6_SelectedIndexChanged(object sender, EventArgs e)
  236. {
  237. button2.Enabled = true;
  238. }
  239.  
  240. public void getReceiver(ReceivePacket rc1)
  241. {
  242. rc = rc1;
  243. }
  244. }
  245.  
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement