Esempio n. 1
0
        private void btnFtp_Click(object sender, EventArgs e)
        {
            ftptext.Text = "Please wait while uploading your data";



            Thread backgroundThread = new Thread(new ThreadStart(() =>
            {
                DBAccessClass db = new DBAccessClass();

                db.openConnection();

                DataTable dt = db.getExpensesOfAll();


                pathtodownload = Path.GetTempPath();
                pathtodownload = pathtodownload + "ftp-";
                Console.WriteLine(pathtodownload);
                dt.WriteToCsvFile(pathtodownload + "admin.csv");
                string ufilename = pathtodownload + "admin.csv";
                db.closeConnection();



                Upload("ftp://" + ftpserver, "dvta", "p@ssw0rd", @pathtodownload + "admin.csv");
                Console.WriteLine(@pathtodownload + "admin.csv");
            }));

            backgroundThread.Start();
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Do you want to clear all your expenses?", "Caution", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                DBAccessClass db = new DBAccessClass();
                db.openConnection();

                Microsoft.Win32.RegistryKey key;
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("dvta");

                String email = (string)key.GetValue("email", "null");

                if (db.clearExpenses(email))
                {
                    MessageBox.Show("Success");
                }
                else
                {
                    MessageBox.Show("Failed");
                }

                db.closeConnection();
            }

            else
            {
                Console.WriteLine("User chose not to clear the expenses");
            }
        }
        private void btnFtp_Click(object sender, EventArgs e)
        {
            ftptext.Text = "Please wait while uploading your data";

            Thread backgroundThread = new Thread(new ThreadStart(() =>
            {
                DBAccessClass db = new DBAccessClass();

                db.openConnection();

                DataTable dt = db.getExpensesOfAll();

                //pathtodownload = Environment.GetEnvironmentVariable("USERPROFILE") + @"\" + "Downloads";
                pathtodownload = Path.GetTempPath();


                dt.WriteToCsvFile(pathtodownload + "admin.csv");

                db.closeConnection();

                Upload("ftp://192.168.56.110", "dvta", "p@ssw0rd", @pathtodownload + "admin.csv");

                //cleaning up - Delete files in temp folder

                try
                {
                    System.IO.Directory.Delete(@pathtodownload, true);
                }
                catch (Exception exp) {
                    Console.WriteLine(exp);
                }
            }));

            backgroundThread.Start();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            // Establish the connection to the server.
            dBAccess = new DBAccessClass();
            try
            {
                dBAccess.OpenConnection();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return;
            }
            Console.WriteLine("Connected to the SQL server...");

            TcpListener listener = null;

            try
            {
                // Start the server on localhost (for now...).
                listener = new TcpListener(IPAddress.Parse("0.0.0.0"), 1337);
                listener.Start();
                Console.WriteLine("DVTA Server Started...");

                while (true)
                {
                    TcpClient client = listener.AcceptTcpClient();
                    Console.WriteLine("Accepted new connection from a client...");  //Should probably log the IP here...too lazy to do it now.

                    Thread t = new Thread(ProcessClientRequest);
                    t.Start(client);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                // Stop the server.
                if (null != listener)
                {
                    listener.Stop();
                }
                // Close the DB connection.
                dBAccess.closeConnection();
            }
        }
        private void btnView_Click(object sender, EventArgs e)
        {
            DBAccessClass db = new DBAccessClass();

            db.openConnection();

            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("dvta");

            String email = (string)key.GetValue("email", "null");

            returnvalue = db.viewExpenses(email);

            dataGridView1.DataSource = returnvalue;

            db.closeConnection();
        }
Esempio n. 6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Microsoft.Win32.RegistryKey key;
            key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("dvta");

            String email = (string)key.GetValue("email", "null");

            String   dat   = textDate.Text.Trim();
            String   item  = textItem.Text.Trim();
            String   price = textPrice.Text.Trim();
            DateTime now   = DateTime.Now;
            String   time  = now.ToString("T");

            if (dat == string.Empty || item == string.Empty || price == string.Empty || email == string.Empty || time == string.Empty)
            {
                MessageBox.Show("Please enter all the fields!");
                return;
            }
            else
            {
                DBAccessClass db = new DBAccessClass();

                db.openConnection();

                //Read system time and insert it into the database

                if (db.addExpenses(dat, item, price, email, time))
                {
                    textDate.Text  = "";
                    textItem.Text  = "";
                    textPrice.Text = "";
                    time           = "";

                    MessageBox.Show("Data saved succesfully");
                }
                else
                {
                    MessageBox.Show("Failed");
                }

                db.closeConnection();
            }
        }
        private void btnReg_Click(object sender, EventArgs e)
        {
            String username        = txtRegUsername.Text.Trim();
            String password        = txtRegPass.Text.Trim();
            String confirmpassword = txtRegCfmPass.Text.Trim();
            String email           = txtRegEmail.Text.Trim();

            if (username == string.Empty || password == string.Empty || confirmpassword == string.Empty || email == string.Empty)
            {
                MessageBox.Show("Please enter all the fields!");
                return;
            }
            else
            {
                if (password != confirmpassword)
                {
                    MessageBox.Show("Passwords do not match");
                    return;
                }
                else
                {
                    DBAccessClass db = new DBAccessClass();

                    db.openConnection();

                    if (db.RegisterUser(username, password, email))
                    {
                        txtRegUsername.Text = "";
                        txtRegPass.Text     = "";
                        txtRegCfmPass.Text  = "";
                        txtRegEmail.Text    = "";
                        MessageBox.Show("Registration Success");
                    }
                    else
                    {
                        MessageBox.Show("Registration Failed");
                    }

                    db.closeConnection();
                }
            }
        }
Esempio n. 8
0
        // Fixed her up a bit. Works ok now.
        public static void HandleTestDBConnection(TcpClient client, string arguments)
        {
            string[] data = new string[2];

            string responseString = String.Empty;
            string server         = String.Empty;
            string database       = String.Empty;

            try
            {
                data    = arguments.Split(new char[] { ' ' }, 2);
                data[1] = data[1].Trim('\0').Trim('\n');    // Handles the excess newline and null characters at the end of the datastream.

                if (Server.adminHash != data[0])
                {
                    responseString = "Invalid ClientHash!\nYou are not an admin!";
                }
                else
                {
                    XmlDocument doc = new XmlDocument();
                    string      xml = "<?xml version='1.0' encoding='utf-8'?><data><server>127.0.0.1\\SQLEXPRESS</server><database>" + data[1] + "</database></data>";
                    try
                    {
                        // This looks a bit lame, but this is the easiest way I can create an XML injection.
                        doc.LoadXml(xml);

                        foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                        {
                            if ("server" == node.Name)
                            {
                                //Console.WriteLine(node.InnerText);
                                server = node.InnerText;
                            }
                            else if ("database" == node.Name)
                            {
                                //Console.WriteLine(node.InnerText);
                                database = node.InnerText;
                            }
                        }

                        Console.WriteLine("Testing DB connection to {0}\\{1}", server, database);

                        try
                        {
                            DBAccessClass testAccess = new DBAccessClass();
                            testAccess.OpenTestConnection(server, database);

                            responseString = "Successfully connected to the following instance: " + server + "\nDatabase used:" + database;
                            Console.WriteLine(responseString);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                            responseString = e.ToString();
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        responseString  = "The XML file read:\n" + xml;
                        responseString += "\nThe error:\n" + e.ToString();
                    }
                }
            }
            catch (Exception)
            {
                responseString = "Wrong number of arguments!";
            }

            NetworkStream stream = client.GetStream();

            byte[] response = Encoding.UTF8.GetBytes(responseString);
            stream.Write(response, 0, response.Length);

            client.Close();
        }
Esempio n. 9
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            String username = txtLgnUsername.Text.Trim();
            String password = txtLgnPass.Text.Trim();

            if (username == string.Empty || password == string.Empty)
            {
                MessageBox.Show("Please enter all the fields!");
                return;
            }

            DBAccessClass db = new DBAccessClass();

            db.openConnection();

            SqlDataReader data = db.checkLogin(username, password);

            if (data.HasRows)
            {
                String user;
                String pass;
                String email;
                int    isadmin = 0;

                /* Microsoft.Win32.RegistryKey myRegKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Details");
                 * String uname = (String)myRegKey.GetValue("username", null);
                 * String pass = (String)myRegKey.GetValue("password", null);*/

                while (data.Read())
                {
                    user    = data.GetString(1);
                    pass    = data.GetString(2);
                    email   = data.GetString(3);
                    isadmin = (int)data.GetValue(4);

                    if (user != "admin")
                    {
                        Microsoft.Win32.RegistryKey key;
                        key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("dvta");
                        key.SetValue("username", user);
                        key.SetValue("password", pass);
                        key.SetValue("email", email);
                        key.SetValue("isLoggedIn", "true");
                        key.Close();
                    }
                }
                txtLgnUsername.Text = "";
                txtLgnPass.Text     = "";

                //redirecting to main screen

                if (isadmin != 1)
                {
                    this.Close();
                    Main main = new Main();
                    main.ShowDialog();
                    Application.Exit();
                }
                else
                {
                    this.Hide();
                    Admin admin = new Admin();
                    admin.ShowDialog();
                    Application.Exit();
                }

                return;
            }
            else
            {
                MessageBox.Show("Invalid Login");
                txtLgnUsername.Text = "";
                txtLgnPass.Text     = "";
            }
            db.closeConnection();
        }