Esempio n. 1
0
        //konstruktor funkcije koji instancira klasu server i pokreće dvije dretve
        //koje obavljaju posao UDP i TCP servera (na klijentu)
        public frmDataGrid()
        {
            InitializeComponent();

            Server server             = new Server(this);
            Thread listeningUDPThread = new Thread(new ThreadStart(server.startUDPServer));

            listeningUDPThread.IsBackground = true;
            listeningUDPThread.Start();
            Thread listeningTCPThread = new Thread(new ThreadStart(server.startTCPServer));

            listeningTCPThread.IsBackground = true;
            listeningTCPThread.Start();

            //ukoliko ne postoji direktorij za datoteke, kreira ga
            FileHandling.createFileDirectory();

            //uploada datoteke na servis a preko njega u bazu
            newFolder.uploadFilesToService();

            //instanciranje servisa i dohvaćanje podataka s njega u obliku tablice
            serviceWCF.Service1Client client = new serviceWCF.Service1Client();
            DataTable table = client.getData(helper.Name);

            dgvData.DataSource = table;
            client.Close();
            dgvDownloads.DataSource = newFolder.fillMyFiles();
            createDownDgv();
        }
Esempio n. 2
0
        //klik na login -> provjera unesenog imena i provjera konekcije s bazom
        private void button1_Click(object sender, EventArgs e)
        {
            bool usernameOK = false;

            //ako nije uneseno prazno polje
            if (txtUsername.Text != "")
            {
                helper.Name = txtUsername.Text;
                usernameOK  = true;
            }
            else
            {
                usernameOK = false;
                MessageBox.Show("Please enter your username.");
            }
            string strHostName = "";

            try
            {
                serviceWCF.Service1Client client = new serviceWCF.Service1Client();      //instanciranje WCf servisa

                //dobivanje vanjske IP adrese računala
                strHostName = System.Net.Dns.GetHostName();
                IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
                IPAddress[] addr    = ipEntry.AddressList;
                helper.IP = addr[addr.Length - 2].ToString();

                Match result = Regex.Match(helper.IP, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
                if (!result.Success)
                {
                    helper.IP = "127.0.0.1";
                }

                //ako je korisničko ime pravilno
                if (usernameOK)
                {
                    try
                    {
                        //provjera konekcije s servisom
                        if (client.checkConnection() == 1)
                        {
                            FileHandling checkUser = new FileHandling();

                            //ako ime nije slobodno
                            if (checkUser.checkUsername() == 1)
                            {
                                MessageBox.Show("Ime se koristi.");
                                helper.Name = "";
                            }
                            else
                            {
                                //zatvaranje konekcije s servisom i login forme,
                                //te instanciranje i prikaz forme sa DataGrid-om
                                client.Close();
                                this.Close();
                                frmDataGrid fdg = new frmDataGrid();
                                fdg.Show();
                            }
                        }
                    }
                    // ukoliko servis nije dostupan
                    catch
                    {
                        MessageBox.Show("There has been a probem with connecting to server. Please try again.");
                        helper.Name = "";
                    }
                }
            }
            //ukoliko servis nije dostupan
            catch
            {
                MessageBox.Show("There has been a probem with connecting to server. Please try again.");
                helper.Name = "";
            }
        }
Esempio n. 3
0
        //osvježavanje liste datoteka koje se nalaze na lokalnom računalu
        private void refreshMyFiles_Click(object sender, EventArgs e)
        {
            FileHandling fh = new FileHandling();

            dgvDownloads.DataSource = fh.fillMyFiles();
        }
Esempio n. 4
0
        //klik na login -> provjera unesenog imena i provjera konekcije s bazom
        private void button1_Click(object sender, EventArgs e)
        {
            bool usernameOK = false;
                //ako nije uneseno prazno polje
                if (txtUsername.Text != "")
                {
                    helper.Name = txtUsername.Text;
                    usernameOK = true;
                }
                else
                {
                    usernameOK = false;
                    MessageBox.Show("Please enter your username.");
                }
                string strHostName = "";
                try
                {
                    serviceWCF.Service1Client client = new serviceWCF.Service1Client();  //instanciranje WCf servisa

                    //dobivanje vanjske IP adrese računala
                    strHostName = System.Net.Dns.GetHostName();
                    IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
                    IPAddress[] addr = ipEntry.AddressList;
                    helper.IP = addr[addr.Length - 2].ToString();

                    Match result = Regex.Match(helper.IP, @"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
                    if (!result.Success)
                        helper.IP = "127.0.0.1";

                    //ako je korisničko ime pravilno
                    if (usernameOK)
                    {
                        try
                        {
                            //provjera konekcije s servisom
                            if (client.checkConnection() == 1)
                            {
                                FileHandling checkUser = new FileHandling();

                                //ako ime nije slobodno
                                if (checkUser.checkUsername() == 1)
                                {
                                    MessageBox.Show("Ime se koristi.");
                                    helper.Name = "";
                                }
                                else
                                {
                                    //zatvaranje konekcije s servisom i login forme,
                                    //te instanciranje i prikaz forme sa DataGrid-om
                                    client.Close();
                                    this.Close();
                                    frmDataGrid fdg = new frmDataGrid();
                                    fdg.Show();
                                }
                            }
                        }
                        // ukoliko servis nije dostupan
                        catch
                        {
                            MessageBox.Show("There has been a probem with connecting to server. Please try again.");
                            helper.Name = "";
                        }
                    }
                }
                //ukoliko servis nije dostupan
                catch
                {
                    MessageBox.Show("There has been a probem with connecting to server. Please try again.");
                    helper.Name = "";
                }
        }