1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
public interface Iuser
{
string U_LOGIN { get;}
string U_SID { get;}
string U_PORT { get;}
}
public class user : Iuser
{
private string _login = "";
private string _sid = "";
private string _port;
public user()
{
}
public user(string login):this()
{
U_LOGIN = login;
U_SID = login;
U_PORT = login; //Les instanciations de U_SID et U_PORT se font à partir de login
}
public string IAmConnected()
{
DataSet oDataSet;
OdbcDataAdapter oDataAdapter;
DateTime dt = DateTime.Now;
BD bd = new BD();
OdbcConnection con = bd.Connect();
oDataAdapter = new OdbcDataAdapter("select * from connected", con);
oDataSet = new DataSet("Connected");
oDataAdapter.Fill(oDataSet, "Connected");
oDataAdapter.InsertCommand = new OdbcCommand("INSERT INTO connected(LOGIN,SID,DATE,HOUR) Values(?,?,?,?)", con);
oDataAdapter.InsertCommand.Parameters.Add("@LOGIN", OdbcType.VarChar, 10, "LOGIN");
oDataAdapter.InsertCommand.Parameters.Add("@SID", OdbcType.VarChar, 10, "SID");
oDataAdapter.InsertCommand.Parameters.Add("@DATE", OdbcType.VarChar, 10, "DATE");
oDataAdapter.InsertCommand.Parameters.Add("@HOUR", OdbcType.VarChar, 10, "HOUR");
DataRow oDataRow;
oDataRow = oDataSet.Tables["Connected"].NewRow();
oDataRow["LOGIN"] = this._login;
oDataRow["SID"] = this._sid;
oDataRow["DATE"] = dt.Year.ToString().Substring(2,2)+dt.Month.ToString("d2")+dt.Day.ToString("d2");
oDataRow["HOUR"] = dt.Hour.ToString("d2")+dt.Minute.ToString("d2");
oDataSet.Tables["Connected"].Rows.Add(oDataRow);
try
{
oDataAdapter.Update(oDataSet, "Connected");
}
catch (Exception e)
{
return e.Message.ToString();
}
con.Close();
return "1";
}
public string CreateEnvironment(string login)
{
int[] ASCII_TAB = new int[62];
char[] CODE_TAB = new char[10];
string CODE = "";
Random rnd = new Random();
int total = 0;
string NewDir = new Path().StoreDir+"\\"+this._login+"\\";
//Génération du code aléatoire
for (int i = 48; i <= 57; i++) { ASCII_TAB[total] = i; total++; }
for (int i = 65; i <= 90; i++) { ASCII_TAB[total] = i; total++; }
for (int i = 97; i <= 122; i++) { ASCII_TAB[total] = i; total++; }
for (int j = 0; j < CODE_TAB.Length; j++)
{
CODE_TAB[j] = Convert.ToChar((int)ASCII_TAB[rnd.Next(0,61)]);
CODE += CODE_TAB[j].ToString();
}
//Vérification existence du dossier et création
if (System.IO.Directory.Exists(NewDir+CODE))
{
CreateEnvironment(this._login);
}
else
{
System.IO.Directory.CreateDirectory(NewDir+CODE);
}
//On retourne le nom du répertoire
return CODE;
}
public string GetPort(string login)
{
BD MyBD = new BD();
OdbcConnection con = MyBD.Connect();
OdbcCommand MyCommand = new OdbcCommand();
MyCommand.Connection = con;
MyCommand.CommandText = "SELECT PORT FROM login_port WHERE LOGIN=\'" + login + "\'";
OdbcDataReader MyDataReader;
MyDataReader = MyCommand.ExecuteReader();
Int16 res = 0;
while (MyDataReader.Read())
{
res = MyDataReader.GetInt16(0);
}
con.Close();
return res.ToString();
}
//Accesseur
public string U_LOGIN
{
get { return this._login; }
set { this._login = value; }
}
public string U_SID
{
get { return this._sid; }
set { if (value != "") { this._sid = this.CreateEnvironment(value); }; }
}
public string U_PORT
{
get { return this._port; }
set { if (value != "") { this._port = GetPort(U_LOGIN); } else { this._port = ""; } }
}
} |