Advertisement
Guest User

Forms

a guest
Aug 18th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.47 KB | None | 0 0
  1. using MySql.Data.MySqlClient;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Net;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13.  
  14. namespace Rack
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.  
  19.      
  20.         public Form1()
  21.         {
  22.             InitializeComponent();
  23.             checkInternetState();
  24.             checkforUpdates();
  25.            
  26.         }
  27.         // Zostanie użyte w przyszłości
  28.         public float version = 1.1f;
  29.  
  30.         public static int loggedUserID = -1;
  31.         public bool czyjestPol = false;
  32.         public bool logged1 = false;
  33.         public bool logged2 = false;
  34.  
  35.         void checkforUpdates()
  36.         {
  37.             if(czyjestPol == false)
  38.             {
  39.                 return;
  40.             }
  41.             System.Net.WebClient wc = new System.Net.WebClient();
  42.             string a = wc.DownloadString("http://www.rack.c0.pl/update.txt");
  43.             string b = wc.DownloadString("http://www.rack.c0.pl/updatelink.txt");
  44.             if (a == "1")
  45.             {
  46.                 MessageBox.Show("Wymagana Aktualizacja. Ctrl + V w przeglądarce w miejscu na url. " + b);
  47.                 string z = "Wymagana Aktualizacja. Link: " + b;
  48.                 System.Windows.Forms.Clipboard.SetText(b);
  49.             }
  50.         }
  51.        
  52.         void checkInternetState(){
  53.             try
  54.             {
  55.                 using (var klient = new WebClient())
  56.                 {
  57.                     using (var strumien = klient.OpenRead("https://www.google.com"))
  58.                     {
  59.                         checkBox2.Checked = true;
  60.                         checkBox2.Text = "połączony";
  61.                         checkBox2.BackColor = Color.Green;
  62.                         czyjestPol = true;
  63.                     }
  64.                 }
  65.             }
  66.             catch
  67.             {
  68.                 checkBox2.Checked = false;
  69.                 checkBox2.Text = "brak połączenia";
  70.                 checkBox2.BackColor = Color.Red;
  71.                 czyjestPol = false;
  72.             }
  73.             if (czyjestPol)
  74.             {
  75.                 panel1.Show();
  76.             }
  77.             else {
  78.                 panel1.Hide();
  79.             }
  80.         }
  81.  
  82.         private void exit(object sender, EventArgs e)
  83.         {
  84.             System.Diagnostics.Process.GetCurrentProcess().Kill();
  85.         }
  86.  
  87.         private void Zaloguj_Click(object sender, EventArgs e)
  88.         {
  89.             try
  90.             {
  91.                 System.Net.WebClient wc = new System.Net.WebClient();
  92.                 string a = wc.DownloadString("http://www.rack.c0.pl/User1/ID.txt");
  93.                 string b = wc.DownloadString("http://www.rack.c0.pl/User2/ID.txt");
  94.                 if (textBox1.Text ==  a)
  95.                 {
  96.                     logged1 = true;
  97.                     loggedUserID = 1;
  98.                 }
  99.                 if (textBox1.Text == b) {
  100.  
  101.                     logged1 = true;
  102.                     loggedUserID = 2;
  103.                 }
  104.  
  105.             }
  106.             catch
  107.             {
  108.                 MessageBox.Show("Nie wpisałeś ID lub nie masz połączenia");
  109.             }
  110.             try
  111.             {
  112.                 System.Net.WebClient wc = new System.Net.WebClient();
  113.                 string a = wc.DownloadString("http://www.rack.c0.pl/User1/pass.txt");
  114.                 string b = wc.DownloadString("http://www.rack.c0.pl/User2/pass.txt");
  115.                 if (textBox2.Text == a || textBox2.Text == b)
  116.                 {
  117.                    
  118.                     logged2 = true;
  119.                 }
  120.             }
  121.             catch
  122.             {
  123.                 MessageBox.Show("Nie wpisałeś hasła lub nie masz połączenia");
  124.             }
  125.             if (logged1 && logged2) {
  126.                 MessageBox.Show("Zalogowano Pomyślnie","Informacja",MessageBoxButtons.OK,MessageBoxIcon.Information);
  127.                 Form2 x = new Form2();
  128.                 x.Show();
  129.                 this.Hide();
  130.             }
  131.         }
  132.     }
  133. }
  134.  
  135. using System;
  136. using System.Collections.Generic;
  137. using System.ComponentModel;
  138. using System.Data;
  139. using System.Diagnostics;
  140. using System.Drawing;
  141. using System.Linq;
  142. using System.Text;
  143. using System.Threading.Tasks;
  144. using System.Windows.Forms;
  145.  
  146. namespace Rack
  147. {
  148.     public partial class Form2 : Form
  149.     {
  150.         private bool consoleopen = false;
  151.         public int userID = -1;
  152.         public Form2()
  153.         {
  154.             InitializeComponent();
  155.             initializeGames();
  156.             ustawConsole();
  157.         }
  158.  
  159.         void initializeGames() {
  160.             if (getIDfromForm1)
  161.             {
  162.                 userID = Form1.loggedUserID;
  163.             }
  164.             if(userID == 1)
  165.             {
  166.                 System.Net.WebClient wc = new System.Net.WebClient();
  167.                 string a = wc.DownloadString("http://www.rack.c0.pl/User1/gra1.txt");
  168.                 if (a == "1")
  169.                 {
  170.                     panel1.Show();
  171.                 }
  172.                 else {
  173.                     panel1.Hide();
  174.                 }
  175.                 string b = wc.DownloadString("http://www.rack.c0.pl/User1/gra2.txt");
  176.                 if (b == "1")
  177.                 {
  178.                     panel2.Show();
  179.                 }
  180.                 else
  181.                 {
  182.                     panel2.Hide();
  183.                 }
  184.             }
  185.             if (userID == 2)
  186.             {
  187.                 System.Net.WebClient wc = new System.Net.WebClient();
  188.                 string a = wc.DownloadString("http://www.rack.c0.pl/User2/gra1.txt");
  189.                 if (a == "1")
  190.                 {
  191.                     panel1.Show();
  192.                 }
  193.                 else {
  194.                     panel1.Hide();
  195.                 }
  196.                 string b = wc.DownloadString("http://www.rack.c0.pl/User2/gra2.txt");
  197.                 if (b == "1")
  198.                 {
  199.                     panel2.Show();
  200.                 }
  201.                 else
  202.                 {
  203.                     panel2.Hide();
  204.                 }
  205.             }
  206.         }
  207.  
  208.         private void button2_Click(object sender, EventArgs e)
  209.         {
  210.             Form1 y = new Form1();
  211.             y.Show();
  212.             this.Hide();          
  213.         }
  214.  
  215.         private void button1_Click(object sender, EventArgs e)
  216.         {
  217.             Process.Start("notepad.exe");
  218.         }
  219.  
  220.         private void download(object sender, EventArgs e)
  221.         {
  222.             System.Net.WebClient wc = new System.Net.WebClient();
  223.             string a = wc.DownloadString("http://www.rack.c0.pl/User2/gra1.txt");
  224.         }
  225.  
  226.         private void downloadTest06(object sender, EventArgs e)
  227.         {
  228.             webBrowser1.Navigate("http://download850.mediafire.com/2j7dkhwr98dg/kgoxw293765ib3e/test-06.rar");
  229.         }
  230.  
  231.         private void kill(object sender, FormClosedEventArgs e)
  232.         {
  233.             Process.GetCurrentProcess().Kill();
  234.         }
  235.  
  236.         private void button4_Click(object sender, EventArgs e)
  237.         {
  238.             if (consoleopen)
  239.             {
  240.                 consoleopen = false;
  241.             }
  242.             else
  243.             {
  244.                 consoleopen = true;
  245.             }
  246.             ustawConsole();
  247.         }
  248.         void ustawConsole()
  249.         {
  250.             if (consoleopen)
  251.             {
  252.                 textBox1.Show();
  253.                 textBox2.Show();
  254.             }
  255.             else
  256.             {
  257.  
  258.                 textBox1.Hide();
  259.                 textBox2.Hide();
  260.             }
  261.         }
  262.  
  263.         public bool getIDfromForm1 = true;
  264.         public int NowOnForm = 0;
  265.         private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  266.         {
  267.             string x = "";
  268.             if(e.KeyChar == '\r')
  269.             {
  270.                 x = textBox2.Text;
  271.                 textBox2.Text = "";
  272.                 switch (x)
  273.                 {
  274.                     case "mkd form2":
  275.                         textBox1.Text += "\r\n Pomyślnie Ustawiono MKD na 2";
  276.                         NowOnForm = 2;
  277.                         break;
  278.                     case "mkd form1":
  279.                         textBox1.Text += "\r\n Pomyślnie Ustawiono MKD na 1";
  280.                         NowOnForm = 1;
  281.                         break;
  282.                     case "s panel1":
  283.                         if(NowOnForm == 2) {
  284.                             textBox1.Text += "\r\n Pomyślnie pokazano panel1";
  285.                             panel1.Show();
  286.                         }
  287.                         break;
  288.                     case "s panel2":
  289.                         if (NowOnForm == 2)
  290.                         {
  291.                             textBox1.Text += "\r\n Pomyślnie pokazano panel2";
  292.                             panel2.Show();
  293.                         }
  294.                         break;
  295.                     case "h panel1":
  296.                         if (NowOnForm == 2)
  297.                         {
  298.                             textBox1.Text += "\r\n Pomyślnie schowano panel1";
  299.                             panel1.Hide();
  300.                         }
  301.                         break;
  302.                     case "h panel2":
  303.                         if (NowOnForm == 2)
  304.                         {
  305.                             textBox1.Text += "\r\n Pomyślnie schowano panel2";
  306.                             panel2.Hide();
  307.                         }
  308.                         break;
  309.                     case "exit":
  310.                         Process.GetCurrentProcess().Kill();
  311.                         break;
  312.                     case "logout":
  313.                         Form1 y = new Form1();
  314.                         y.Show();
  315.                         this.Hide();
  316.                         break;
  317.                     case "u log 1":
  318.                         getIDfromForm1 = false;
  319.                         userID = 1;
  320.                         initializeGames();
  321.                         textBox1.Text += "\r\n Pomyślnie zmieniono użytkownika";
  322.                         break;
  323.                     case "u log 2":
  324.                         getIDfromForm1 = false;
  325.                         userID = 2;
  326.                         initializeGames();
  327.                         textBox1.Text += "\r\n Pomyślnie zmieniono użytkownika";
  328.                         break;
  329.                     case "u log 3":    
  330.                         break;
  331.                     case "":
  332.                         break;
  333.                 }
  334.             }
  335.         }
  336.     }
  337. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement