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
Log.csCode: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()); } } }
Database.csCode: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(); } } }
Form1.csCode: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 } }
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.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); } } }
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.


Reply With Quote


