Register System GUI Source

Results 1 to 9 of 9
  1. #1
    Sorcerer Supreme Hexadecimal is offline
    Member +Rank
    Dec 2010 Join Date
    424Posts

    Register System GUI Source

    Do with it what you will, it's incomplete, messy and I just don't even know :]. Tired of working with it so here's a register system, 6 hours of time was put into it and it's still not completed so. Most people will find it useless since they don't actually like to program, they just like to take things.

    Program.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows.Forms;
    
    namespace RegisterSystemGUI
    {
        static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }
    Log.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    
    namespace RegisterSystemGUI
    {
        public class Log
        {
            public static void DumpLog(StreamReader r)
            {
                string str;
                while ((str = r.ReadLine()) != null)
                {
                    Console.WriteLine(str);
                }
                r.Close();
            }
    
            public void EventLog(string logMessage, TextWriter w)
            {
                w.Write("\r\nLog Entry :");
                w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
                w.WriteLine("{0}", logMessage);
                w.WriteLine("-------------------------------------");
                w.Flush();
            }
    
        }
    }
    Database.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    using MySql.Data.MySqlClient;
    using System.Threading;
    using System.IO;
    
    namespace RegisterSystemGUI
    {
        class Database
        {
            Form1 blah;
            Connections DBC = new Connections();
            Log Logger = new Log();
            Config Config = new Config();
            public bool NewRow = false;
    
            public Database(Form1 frm)
            {
                blah = frm;
            }
    
            #region Scan Function
            public void Scan()
            {
                int CachedRows = CurrentRows();
                MySqlDataReader Reading;
                MySqlCommand Command = new MySqlCommand("SELECT * FROM users_tbl", DBC.Base());
                Reading = Command.ExecuteReader();
                while (true)
                {
                    if (CurrentRows() > CachedRows)
                    {
                        Reading.Read();
                        NewRow = true;
                        GetRowData("users_tbl", "username, password, email, IP");
                        SetOld("users_tbl");
                    }
                    CachedRows = CurrentRows();
                    Thread.Sleep(3000);
                }
            }
            #endregion
    
            #region Current Row Function
            public int CurrentRows()
            {
                MySqlDataReader Reader;
                MySqlCommand Command = new MySqlCommand("SELECT COUNT(*) AS count FROM users_tbl", DBC.Base());
                Reader = Command.ExecuteReader();
                Reader.Read();
                int Value = Convert.ToInt32(Reader[0]);
                Reader.Close();
                return Value;
            }
            #endregion
    
            #region Get Row Data Function
            public void GetRowData(string Table, string Fields)
            {
                MySqlDataReader Data;
                MySqlCommand Return = new MySqlCommand("SELECT " + Fields + " FROM " + Table + " WHERE status = 'new'", DBC.Base());
                Data = Return.ExecuteReader();
                while (Data.Read())
                {
                    if (NewRow)
                    {
                        Object[] values = new Object[Data.FieldCount];
                        int fieldCount = Data.GetValues(values);
    
                        #region Variables
                        string UserName = (string)values[0]; //Username
                        string Password = (string)values[1]; //PasswordHash
                        string Email = (string)values[2];    //Email
                        string IP = (string)values[3];       //IP Address
                        #endregion
    
                        MySqlCommand/*SqlCommand*/ FLYFF = new MySqlCommand/*SqlCommand*/("INSERT INTO flyff_tbl (username, password, email, IP) VALUES ('" + UserName + "', '" + Password + "', '" + Email + "', '" + IP + "')", DBC.Base());
                        try
                        {
                            FLYFF.ExecuteScalar();
                        }
                        catch(Exception e)
                        {
                            using (StreamWriter writer = File.AppendText("Log.txt"))
                            {
                                Logger.EventLog(e.ToString(), writer);
                                writer.Close();
                            }
                        }
                        blah.setText("The username '" + UserName + "' has been registered with the IP '" + IP + "'");
                        using (StreamWriter writer = File.AppendText("Log.txt"))
                        {
                            Logger.EventLog("The username '" + UserName + "' has been registered with the IP '" + IP + "'", writer);
                            writer.Close();
                        }
    
                        blah.setCurrent(CurrentRows().ToString());
    
                    }
                }
            }
            #endregion
    
            #region Set Old Function
            public void SetOld(string Table)
            {
                MySqlCommand SetOld = new MySqlCommand("UPDATE " + Table + " SET status = 'old' WHERE status = 'new'", DBC.Base());
                try
                {
                    SetOld.ExecuteScalar();
                }
                catch(Exception e)
                {
                    using (StreamWriter writer = File.AppendText("Log.txt"))
                    {
                        Logger.EventLog(e.ToString(), writer);
                        writer.Close();
                    }
                }
            }
            #endregion
    
            #region Custom Base Query
            public MySqlCommand BaseQuery(string Command)
            {
                MySqlCommand BaseQuery = new MySqlCommand(Command, DBC.Base());
                try
                {
                    BaseQuery.ExecuteScalar();
                }
                catch
                {
                    blah.ThrowError("Invalid syntax.");
                }
                return BaseQuery;
            }
            #endregion
        }
    
        public class Connections
        {
            Log Logger = new Log();
            Config Config = new Config();
    
            #region Base MySQL
            public MySqlConnection Base()
            {
                #region Connection String
                MySqlConnectionStringBuilder ConString = new MySqlConnectionStringBuilder();
                ConString.Server = "";
                ConString.UserID = "";
                ConString.Password = "";
                ConString.Database = "";
                ConString.Port = 3306;
                #endregion
    
                MySqlConnection Base = new MySqlConnection(ConString.ToString());
    
                #region Open Connection
                try
                {
                    Base.Open();
                }
                catch(Exception e)
                {
                    using (StreamWriter writer = File.AppendText("Log.txt"))
                    {
                        Logger.EventLog(e.ToString(), writer);
                        writer.Close();
                    }
                }
                #endregion
                return Base;
            }
            #endregion
    
            #region MSSQL Connection
            public SqlConnection MsqlConnection()
            {
                #region Connection String
                SqlConnectionStringBuilder ConString = new SqlConnectionStringBuilder();
                ConString.DataSource = ""; //Read from ini
                ConString.UserID = "";     //Read from ini
                ConString.Password = "";   //Read from ini
                #endregion
    
                SqlConnection MSSQL = new SqlConnection(ConString.ToString());
    
                #region Open Connection
                try
                {
                    MSSQL.Open();
                }
                catch(Exception e)
                {
                    using (StreamWriter writer = File.AppendText("Log.txt"))
                    {
                        Logger.EventLog(e.ToString(), writer);
                        writer.Close();
                    }
                }
                #endregion
    
                return MSSQL;
            }
            #endregion 
    
            #region MySQL Connection 
            #endregion
        }
    }
    Form1.cs
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;
    
    namespace RegisterSystemGUI
    {
        public partial class Form1 : Form
        {
            Database DB;
            Thread t;
            delegate void SetTextCallback(string text);
            public Form1()
            {
                DB = new Database(this);
                InitializeComponent();
            }
    
            public void setText(string text)
            {
                if (this.label1.InvokeRequired)
                {
                   SetTextCallback d = new SetTextCallback(setText);
                    this.Invoke(d, new object[] { text });
                }
                else
                {
                    this.label1.Text = text;
                }
    
            }
    
            public void setCurrent(string Current)
            {
                if (this.label3.InvokeRequired)
                {
                    SetTextCallback d = new SetTextCallback(setCurrent);
                    this.Invoke(d, new object[] { Current });
                }
                else
                {
                    this.label3.Text = Current;
                }
            }
    
            private void reloadConfigToolStripMenuItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void quitToolStripMenuItem_Click_1(object sender, EventArgs e)
            {
                Application.Exit();
            }
    
            private void startToolStripMenuItem_Click(object sender, EventArgs e)
            {
                label1.Text = "Register System started.";
    
                t = new Thread(new ThreadStart(DB.Scan));
                t.IsBackground = true;
                t.Start();
            }
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Form2 Frm2 = new Form2();
                Frm2.Show();
            }
    
            private void contactToolStripMenuItem_Click(object sender, EventArgs e)
            {
                Form3 Frm3 = new Form3();
                Frm3.Show();
            }
    
            private void label1_Click(object sender, EventArgs e)
            {
                label1.Text = "";
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                DB.BaseQuery(textBox1.Text);
            }
    
            public void ThrowError(String ErrorMessage)
            {
                MessageBox.Show(ErrorMessage);
            }
        }
    }
    The entire of idea of this started on, what do I do if I have something that runs on MSSQL, such as flyff, and something that runs on MySQL such as PHPBB. This code basically checks every few seconds for a new row, once a new row is created it then executes columns from that row to other databases. It's far from finished and I planned to go much farther with it, but I'm not sure at the moment so I'm just going to release.
    Done functions:
    Logging
    Checking for new row
    BlahBlahBlah..

    TODO:
    Configuration
    Plugin System (Was actually going make it compatible with all major forums, laziness kicked in)
    Add column updates (Like if a user changed password)

    Hope someone makes use for it.


  2. #2
    Sorcerer Supreme Johnny is offline
    Member +Rank
    Jun 2010 Join Date
    U.S.ALocation
    477Posts

    Re: Register System GUI Source

    hm might have to try and use it for something. well if i can understand how to add new functions and how to make them do stuff : P (haven't gotten into the book im reading on c++ yet) but thanks hope someone can use this for a project as well

  3. #3
    Sorcerer Supreme Hexadecimal is offline
    Member +Rank
    Dec 2010 Join Date
    424Posts

    Re: Register System GUI Source

    It's C#, could be easily converted into C++ though.

  4. #4
    i sell platypus Improved is offline
    Grand MasterRank
    Jun 2009 Join Date
    DenmarkLocation
    2,819Posts

    Re: Register System GUI Source

    Since when did you begin learning C#?

  5. #5
    Sorcerer Supreme Hexadecimal is offline
    Member +Rank
    Dec 2010 Join Date
    424Posts

    Re: Register System GUI Source

    Quote Originally Posted by spikensbror View Post
    Worst naming convention I've ever seen in my life.
    Form1 and blah. nuff said
    I love how you keep commenting on my threads, acting as if I give a damn what you say. You aren't a god.

    Quote Originally Posted by Improved View Post
    Since when did you begin learning C#?
    Actually, It's Gage's system. He just released it on my account because all of his are banned. But to answer that question in MY point of view, I have tried to learn some C#. I'm not great with it. <.<
    Last edited by Hexadecimal; 20-09-11 at 10:20 PM.

  6. #6
    0xC0FFEE spikensbror is offline
    Grand MasterRank
    Dec 2006 Join Date
    SwedenLocation
    1,855Posts

    Re: Register System GUI Source

    Quote Originally Posted by Apixenz View Post
    I love how you keep commenting on my threads, acting as if I give a damn what you say. You aren't a god.
    Never said I am, never said you would.

  7. #7
    i sell platypus Improved is offline
    Grand MasterRank
    Jun 2009 Join Date
    DenmarkLocation
    2,819Posts

    Re: Register System GUI Source

    Quote Originally Posted by Apixenz View Post
    Actually, It's Gage's system. He just released it on my account because all of his are banned. But to answer that question in MY point of view, I have tried to learn some C#. I'm not great with it. <.<

    That makes a lot more sense :P

  8. #8
    MC Web Designs Matt Clarke is offline
    Grand MasterRank
    Oct 2010 Join Date
    UKLocation
    933Posts

    Re: Register System GUI Source

    I guess this was just a project, but its good.

  9. #9
    Sorcerer Supreme Hexadecimal is offline
    Member +Rank
    Dec 2010 Join Date
    424Posts

    Re: Register System GUI Source

    If it matters oh so much...

    public Database(Interface I)
    {
    GUI = I;
    }

    then

    public partial class Interface : Form
    {
    Database DB;
    Thread t;
    delegate void SetTextCallback(string text);
    public Interface()
    {
    DB = new Database(this);
    InitializeComponent();
    }
    Oh so hard and matters so much..



Advertisement