• Nenhum resultado encontrado

Λίγο πριν τελειώσουμε με αυτήν την παρουσίαση, θα ήταν καλό να παραθέσουμε και λίγο χώρο για την παρουσίαση τσυ πηγαίου κώδικα για τον οποίο κοπιάσαμε τόσο πολύ και ήμαστε υπερήφανοι. Στις επόμενες σελίδες θα μπορέσετε να μελετήσετε λεπτομερώς όλα τα κομμάτια που συζητήθηκαν παραπάνω, καθώς και κομμάτια που παραλείψαμε λόγω του βοηθητικού τους ρόλου.

using System;

using System.Collections.Generic;

using System.Text;

using System.Data;

using Systera.Windows.Forms;

using System.Drawing;

using System.10;

using System.Xml;

using System.Net.Sockets;

using System.Threading;

using MySql.Data.MySqlClient;

using System.Data.OracleClient;

using System.Data.SqlClient;

namespace myLibrary {

public class EnviromentSettings {

private int ServerPort;

public string DatabaseName;

public string DBMS;

public int SQLPort;

public string SQLIP_A;

public string SQLIP_B;

public string SQLIP_C;

public string SQLIP_D;

public EnviromentSettings() i

StreamReader rd = new

StreamReader(Application.StartupPath.ToStringO + " W s e t t i n g s .conf");

//StreamReader rd = new

StreamReader ("C: WServerDirectoryWsettings . conf ") ; StreamReader rd2 = new

StreamReader(Application.StartupPath.ToStringO + " W port.conf”);

//StreamReader rd2 = new StreamReader ("C: W S e r v e r D i rectoryWport. conf") ;

SQLIP_A = rd.ReadLine0 ; SQLIP_B = rd.ReadLine0 ; SQLIP_C = rd.ReadLine0 ; SQLIP_D = rd.ReadLine0 ; SQLPort = int.Parse(rd.ReadLine0);

DatabaseName = rd.ReadLine();

DBMS = r d .ReadLine();

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμογών

ServerPort = rd2.Close 0 ;

it. Parse (rd2.ReadLine() ) ;

public class ImportExport {

struct myObject public public public public public public public

string type;

Point point;

int colorRed;

int colorGreen;

int colorBlue;

string text;

Size size;

bool visible;

public void ExportToXml(Form a, string serial) {

XmlTextWriter writer = new

XmlTextWriter(Application.StartupPath.ToStringO + "\\E:

serial + ".xml", null);

//XmlTextWriter writer = new

XmlTextWriter ("C: WClientD i r e c t o r y W E x p o r t s W " + serial

".xml",null);

writer.Formatting = Formatting.Indented;

writer.WriteStartDocument{);

writer.WriteComment("this is my comment");

writer.WriteStartElement("root");

a.Controls.Count; i++)

writer.WriteStartElement("Object");

writer.WriteStartElement("Type");

writer.WriteString(a.Controls[i].ToString());

writer.WriteEndElement();

writer.WriteStartElement("Name");

writer.WriteString(a.Controls[i].Name.ToString());

writer.WriteEndElement();

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξανωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών_____________

writer.WriteStartElement("Υ”);

writer.WriteString(a.Controls[i].Location.Y.ToString{));

writer.WriteEndElement() ; writer.WriteEndElementO;

writer.WriteStartElement("Green") ;

writer.WriteStartElement("Blue");

writer.WriteString (a.Controls [i] .BaclcColor. B. ToString () ) ; writer.WriteEndElement() ; writer.WriteEndElement() ; writer.WriteStartElement("Text") ;

writer.WriteString(a.Controls[i].Text.ToString()) ; writer.WriteEndElement();

writer.WriteStartElement("Height");

writer.WriteString(a.Controls[i].Height.ToString());

writer.WriteEndElement();

writer.WriteStartElement("Width");

writer.WriteString(a.Controls[i].Width.ToString());

writer.WriteEndElement();

writer.WriteStartElement("Visible");

writer.WriteString(a .Controls[i ].Visible.ToString());

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndElement();

writer.WriteEndDocument();

writer.Close();

public void ImportFromXml(Form a, string serial) i

XmlTextReader reader = new

XmlTextReader (Application.StartupPath.ToString() + " W D o w n l o a d s W " + serial + ".xml");

//XmlTextReader reader = new

XmlTextReader("C:\\ClientDirectory\\Downloads\\" + serial + ".xml");

myObj ect mo = new myObj e c t ();

reader.WhitespaceHandling = WhitespaceHandling.None;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

while (reader.Read()) {

if (reader.NodeType == XmlNodeType.Element ) ί

if (reader.Name.ToStringO == "Object") {

reader.ReadToFollowing("Type");

reader.Read();

mo.type = r e a d e r . V a l u e . S p l i t [0];

reader.ReadToFollowing{"Name");

reader.Read 0 ;

mo. name = reader.Value.ToStringO;

reader.ReadToFollowing("X");

reader.Read 0 ; mo.point.X = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Y");

reader.Read 0 ; int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Red");

reader.Rea d ();

mo.colorRed = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Green");

reader.Read 0 ; mo.colorGreen = int.Parse(reader.Value.ToStringO);

reader.ReadToFollowing("Blue");

reader.Read();

mo.colorBlue = int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Text");

reader.Read();

the text element node the next node

if (reader.NodeType ==

XmlNodeType.Element)//if this node is an element, means that i value is assigned

//find

reader.Read();

mo.size.Height = it. Par se (reader. Value. ToString () ) ;

= reader.Value.ToStringO;

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

mo.size.Height = int.Parse(reader.Value.ToStringO) ;

}

reader.ReadToFollowing("Width”);

reader.Read 0 ; mo.size.Width = int.Parse(reader.Value.ToString());

reader.ReadToFollowing("Visible");

reader.Rea d ();

mo.visible = bool.Parse(reader.Value.ToStringO);

for (int i = 0; : a .Controls.Count; i++)

(a.Controls [i] .ToStringO .SplitC, ' ) [0] ==

a.Controls[i].Name == mo.name)

Color.FromArgb(mo.colorRed,

} }//for }//if }//if }//while

a.Controls[i].Location = mo.point;

a.Controls[i].Size = mo.size;

a.Controls[i].BackColor = ).colorGreen, m o .colorBlue);

a.Controls[i].Text = mo.text;

a.Controls[i].Visible = mo.visible;

brea)c;

public class Client public string ConnectToIP;

public int ConnectToPort;

public Client() {

StreamReader reader = new

StreamReader(Application.StartupPath.ToStringO + " W s e t t i n g s .conf");

//StreamReader reader = new StreamReader ("C: WClientDirectoryWsettings. conf") ;

ConnectToIP = reader.ReadLine0 +

ConnectToIP = ConnectToIP + reader.ReadLine() + ConnectToIP “ ConnectToIP + reader.ReadLine() + ConnectToIP = ConnectToIP + reader.ReadLine();

ConnectToPort = int.Parse(reader.ReadLine());

)

public void Upload(string serialNum, string IP, int port) {

try

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

TcpClient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

Networ)cStream networkstream = tcpclient.GetStream();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

string line, s = Application.StartupPath.ToString() h

" W E x p o r t s W " ;

//string line, s = "C:\\ClientDirectory\\Exports\\";

sendread. SendLine ("upload", tcpclient, networkstream); //send upload signal

Console.ReadLine();

sendread.SendLine(serialNum, tcpclient, networkstream); //send clients serial number

Console.ReadLine();

int linesNum = filemanager.CountFileLines(s + serialNum + ".xml"); //count the lines of the file

sendread.SendLine(linesNum.ToString0 , tcpclient, networkstream); //send the lines of the file

FileStream fstrm = new FileStream(s + serialNum +

".xml", FileMode.Open, FileAccess.Read);

StreamReader rw = new StreamReader(fstrm);

while ((line = rw.ReadLine()) != null)

networkstream);

sendread.SendLine(line, tcpclient, //send every line of the file

Console.ReadLine();

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

} )//Upload

public void Download(string serialNum, string IP, : port ) string temp;

int NumOfLines = 0;

string path = Application.StartupPath.ToString() +

" W t m p W " ;

//string path = "C: W C l i e n t D i r e c t o r y W t m p W " ; string repository = Application.StartupPath.ToString() +

"\\Downloads\\";

//string repository = "C: WClientDireo t o r y W D o w n l o a d s W " ; string data;

try

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

TcpClient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

NetworkStream networkstream = tcpclient.GetStream();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

sendread.SendLine("download", tcpclient, networkstream); //send download signal

sendread.SendLine(serialNum, tcpclient, networkstream); //send serial number

networkstream)

temp = sendread.ReadLine(tcpclient, networkstream);

NumOfLines = int.Parse(temp);

for (int i = 0; i < NumOfLines; i++) //read every {

data = sendread.ReadLine(tcpclient,

filemanager.AddLine(path + serialNum + ".xml".

}

System.10.File.Copy(path + serialNum + "

repository + serialNum + ".xml", true);

System.10.File.Delete(path + serialNum ^ }

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

public string login(string username, string password, string IP, int port)

{

string serial = "-1";

try {

Tcpclient tcpclient = new TcpClient(IP, port);//create tcp client for SendFileLine method

Networkstream networkstream = tcpclient.GetStream();

SendRead sendread = new SendRead();

FileManager filemanager = new FileManager();

sendread.SendLine("login", tcpclient, networkstream);

//send login s

networkstream)

sendread.SendLine(username, tcpclient.

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

networkstream);

sendread.SendLine(password, tcpclient,

serial = sendread.ReadLine(tcpclient, networkstream);

}

catch (Exception e) {

MessageBox.Show(e.Message.ToStringO);

} return serial;

}//login

public class ThreadedTcpSrvr (

private TcpListener client;

private Thread myTCPserver;

public ThreadedTcpSrvr() {

int result = 0;

StreamReader reader = new

StreamReader(Application.StartupPath.ToString() + " W p o r t .conf");

//StreamReader reader = new StreamReader("C:WServerDirectoryWport.conf");

if (int.TryParse(reader.ReadLine0 , out result)) {

if (result != 0) (

client = new TcpListener(result);

} }

client = new TcpListener(1800);

reader.Close 0 ;

public void TCPserverLoop() {

client.Start();

while ('client. PendingO)

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και ατιοθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

Thread.Sleep(1000);

ConnectionThread newconnection = new ConnectionThread();

newconnection.threadListener = this.client;

Thread newthread = new Thread(new

public void TerminateTCPserver() {

this.myTCPserver.Abort 0 ; }

public void StartTCPserver() {

this.myTCPserver.Start();

public class ConnectionThread {

public TcpListener threadListener;

//private static int connections = 0;

public void ServeUpload(TcpClient tc, NetworkStream ns) {

string serial;

string temp;

string path = Application.StartupPath.ToString() +

" W t m p W " ;

//string path = "C: W S e r v e r D i r e c t o r y W t m p W " ; string repository = Application.StartupPath.ToString() ■

"WReposi t o r y W " ;

//string repository =

"C: W ServerDirectoryWRepositoryW" ; int NumOfLines = 0 ;

SQLRelated sqlrelated = new SQLRelated();

SQLRelated.SQLstruct sqlstruct = new SQLRelated.SQLstruct();

EnviromentSettings envset = new EnviromentSettings();

FileManager filemanager = new FileManager();

SendRead sendread = new SendRead();

try i

switch (envset.DBMS) {

case "ORACLE":

sqlstruct =

sqlrelated.CheckUserExistanceOracle(int.Parse(serial), envset);

break;

case "MySQL":

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξαγωνή και αποθήκευση ρυθμίσεων νραφικού περιβάλλσντος εφαρμονών

sqlstruct =

sqlrelated.CheckDserExistanceMySQL(int.Parse(serial), envset);

break;

case "MSSQLServer":

sqlstruct =

sqlrelated.CheckUserExistanceMSSQLServer(int.Parse(serial), envset);

if (sqlstruct.password.Length != 0 &&

sqlstruct.username.Length != 0) {

temp = sendread.ReadLine(tc, ns);

if (int.TryParse(temp, out NumOfLines)) //check if the signal is a number

NumOfLines = int.Parse(temp);

System.10.File.Copy((path + serial + ".xml"), (repository + serial + ".xml"), true);

System.10.File.Delete(path + serial + ".xml");

) }

catch (Exception e) {

Console.WriteLine(e.Message) ;

public void ServeDownload(TcpClient tc, NetworkStream ns) (

string temp;

string line;

int serial = 0;

int counter = 0;

string path = Application.StartupPath.ToString() +

"WRepos i t o r y W " ;

//string path = "C: WServerDirectoryWRepositoryW";

SQLRelated sqlrelated = new SQLRelated();

SQLRelated.SQLstruct sqlstruct = new SQLRelated.SQLstruct 0 ;

EnviromentSettings envset = new EnviromentSettings();

SendRead sendread = new SendReadO;

FileManager filemanager = new FileManager();

Δημιουρνία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

try {

temp = sendread.ReadLine(to, ns); //read the serial number of the client

if (int.TryParse {temp, out serial)) //checlc if the signal is a number

i

serial = int.Parse(temp);

switch (envset.DBMS) {

case "ORACLE":

sqlstruct = sqlrelated.CheclcUserExistanceOracle (serial, envset) ;

brealc;

case "MySQL":

sqlstruct = sqlrelated. Chec)iUserExistanceMySQL (serial, envset) ;

break;

case "MSSQLServer":

sqlstruct =

sqlrelated.CheckUserExistanceMSSQLServer(serial, envset);

if (sqlstruct.password.Length != 0 &&

sqlstruct.username.Length != 0)

counter = filemanager.CountFileLines(path H sendread.SendLine(counter.ToString(), tc.

■s);

FileStream fstrm = new FileStream(path + temp + ".xml", FileMode.Open, FileAccess.Read, FileShare.Read);

StreamReader rw = new StreamReader(fstrm);

while {(line = rw.ReadLine{)) != null) {

sendread.SendLine(line, tc, ns); //send every line of the file

catch (Exception e) {

Console.WriteLine(e.ToString{));

} }//ServeDownload

public void ServeLogin(TcpClient tc, NetworkStr<

(

string username;

string password;

string serial = "-1";

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ ρυθμίσεων γραφυιού περιβάλλοντος εφαρμογών

int temp = 0 ;

SQLRelated sqlrelated = new SQLRelated();

EnviromentSettings envset = new EnviromentSettings();

SendRead sendread = new SendRead();

username = sendread.ReadLine{tc, ns);

password = sendread.ReadLine(tc, ns);

switch (envset.DBMS) {

case "ORACLE":

temp =

sqlrelated.RetrieveSerialOracle(username, password, envset);

brea)c;

case "MySQL":

temp =

sqlrelated.RetrieveSerialMySQL(username, password, envset);

b r e a k ; case "MSSQLServer":

temp =

sqlrelated.RetrieveSerialMSSQLServer(username, password, envset);

break;

)

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / //check if the user exists in the database and return the serial

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / if (temp != 0)

{

sendread.SendLine(temp.ToString(), tc, ns);

} {

//store the serial into the serial string sendread.SendLine(serial, tc, ns);

} }

catch (Exception e) {

Console.WriteLine( e .ToString());

) }//Servelogin

public void HandleConnection() {

string responseData;

byte[] data = new byte[1024];

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

connections",

SendRead sendobj = new SendRead();

TcpClient client = threadListener.AcceptTcpClient();

NetworkStream ns = client.GetStream();

/ / c o n n e c tio n s + + ;

//Console.WriteLine("New client accepted: {0} active connections);

while (true) {

responseData = sendobj.ReadLine(client, ns);

if (responseData == "upload") {

this.ServeUpload(client, ns);

)

else if (responseData == "download") (

this.ServeDownload(client, ns);

}

else if (responseData == "login") {

this.ServeLogin(client, ns);

) { )

connections", ns.CloseO ; client.Close();

//connections— ;

//Console.WriteLine("Client disconnected: (0) active connections 1;

public class SendRead

public string ReadLine(TcpClient tc, NetworkStream ns)

byte[] data = new b y t e [1024];

if (ns.CanRead && ns.CanWrite)

Τμήμα Βιομηχανικής Πληροφορικής T.E .I. Καβάλας

Δημιουρνία δυναμικής βιβλιοθήκης y ia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

5.Read(data, 0, data.Length);

.3.Write(data, 0, recv) ;

this stream");

if (ins.CanRead) {

Console.WriteLine("cannot write data to this tc.Close();

} {

if (Ins.CanWrite) {

Console.WriteLine("cannot read data from tc.CloseO ;

}

catch (Exception e) i

Console.WriteLine(e);

public void SendLine(string content, TcpClient tc, NetworJcStream ns) //Give the content of the file in order transmit it

byte[] data = new b yt e [1024];

if (ns.CanWrite && ns.CanRead) {

data = new byte[1024];

data = Encoding.ASCII.GetBytes(content);

ns.Write(data, 0, data.Length);

ns.Read(data, 0, data.Length);

String returndata = Encoding.ASCII.GetString(data) ;

Console.WriteLine("Host returned:

returndata);

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

this stream");

if (Ins.CanRead) ί

Console.WriteLine("cannot write data to this tc.Close();

) {

if {Ins.CanWrite) ί

Console.WriteLine("cannot read data from tc.Close 0 ;

}

public class FileManager {

public void AddLine(string filename, string data) {

FileStream fstrm = new FileStream(filename, FileMode.Append, FileAccess.Write);

StreamWriter wr = new StreamWriter(fstrm);

if (fstrm.CanWrite) {

wr.WriteLine(data);

public int CountFileLines(string path) {

int NumOfLines = 0;

string line;

try {

FileStream fstrm = : FileMode.Open, FileAccess.Read);

StreamReader rw = n if (fstrm.CanRead) {

while ((line = rw {

NumOfLines++;

iw FileStream (path, I StreamReader(fstrm) ;

j.ReadLineO ) != null)

fstrm.Close 0 ;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών___________

Check the path");

)

fstrm.Close();

rw.CloseO;

Console.WriteLine("Cannot read from this file.

catch (Exception e) {

Console.WriteLine(e.ToString());

}

return NumOfLines;

public class SQLRelated (

public struct SQLstruct public string username;

public string password;

public int RetrieveSerialMySQL(string username, string pwd, EnviromentSettings env)

(

string query = "SELECT id FROM users WHERE username = + username + "' AND pwd = '" + pwd +

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;";

//string connectionstringMySQL =

"datasource=localhost;username=antigoni;password=tasos;database=diplo

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

while (reader.ReadO ) (

result = (int)reader["id"];

reader.Close();

reader = null;

dbcmd.Dispose();

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

dbcmd = null;

dbcon.CloseO ; dbcon = null;

)

catch (Exception e) {

MessageBox.Show(e.ToString());

return result;

}

pxoblic int RetrieveSerialOracle (string username, string pwd, EnviromentSettings env)

{

int result = 0;

try ί

string query = "SELECT id FROM users WHERE username = '" + username + "' AND pwd = '" + pwd + " ;

//string connectionstringOracle = "Data Source=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new

OracleConnection(connectionstringOracle); //Oracle connection

= dbcon.CreateCommandO;

while (reader.Read 0) {

result = int.Parse(reader["id"].ToStringO);

) reader.Close 0 ; reader = null;

dbcmd.CommandText = query;

dbcmd.ExecuteNonQuery();

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

}

catch (Exception e) {

MessageBox.Show(e.ToStringO);

) return result;

)

public int RetrieveSerialMSSQLServer(string username, string pwd, EnviromentSettings env)

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξαγωνή και αποθήκευση ______________ ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

try (

string query = "SELECT id FROM users WHERE username = + username + AND pwd = '" + pwd +

//string connectionstringMSSQLServer = "Server =" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP C + + env.SQLIP_D + Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Server

“localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ",1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database = diploma; User ID = antigoni; Password

= tasos";

string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

IDbConnection dbcon = new

SqlConnection(connectionstringMSSQLServer); //MSSQL Server connection

IDbCommand dbcmd = dbcon.CreateCommand{);

dbcon.Open();

dbcmd.CommandText = query;

IDataReader reader = dbcmd.ExecuteReader();

while (reader.Read0) (

result = (int)reader["id"];

}

reader.CloseO ; reader = null;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

)

catch (Exception e) {

MessageBox.Show(e.ToString());

} return result;

public SQLstruct CheckUserExistanceMySQL(int serial, EnviromentSettings env)

SQLstruct mystruct = r try

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

string query = "SELECT username, pwd FROM users WHERE id = '" + serial + "';";

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;

//string connectionstringMySQL =

"datasource=localhost;username=antigoni;password=tasos;database=diplo

IDbConnection dbcon = new

MySqlConnection(connectionstringMySQL); //Default connection is MySQL;

IDbCoiranand dbcmd = dbcon.CreateCommand() ; dbcon.Open{);

while (reader.Read())

mystruct.username = reader["username"].ToStringO;

mystruct.password = reader["pwd"].ToString();

)

reader.Close 0 ; reader = null;

db cmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

}

catch (Exception e) (

MessageBox.Show(e.ToStringO);

}

return mystruct;

SQLstruct mystruct = new SQLstruct();

try ί

string query = "SELECT username, pwd FROM users WHERE id = '" + serial + "'";

//string connectionstringOracle = "Data Source=" + env.SQLIP_A + "." + env.SQLIPB + "." + env.SQLIP_C + "." + env.SQLIP_D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;Dser ID=antigoni;Password=tasos";

IDbConnection dbcon = new

OracleConnection(connectionstringOracle); //Oracle connection IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ______________ ρυθμίσεων γραφικού περιβάλλοντος εφαρμονών

dbcmd.ConimandText = query;

IDataReader reader = dbcmd.ExecuteReader();

while (reader.ReadO ) {

mystruct.username = reader["username"].ToStringO;

^ mystruct.password = reader["pwd"].ToString();

reader.CloseO ; reader = null;

dbcmd.CommandText = query;

dbcmd.ExecuteNonQueryO;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close{);

dbcon = null;

catch (Exception e) {

MessageBox.Show(e.ToString());

return mystruct;

)

public SQLstruct CheckUserExistanceMSSQLServer(int serial

EnviromentSettings env) '

i

SQLstruct mystruct = new SQLstruct();

try {

string query = "SELECT username, pwd FROM users WHERE id = '

//string connectionstringMSSQLServer =

’." + env.SQLIPB + "." + env.SQLIP_C +

’; Database = diploma; User ID = antigoni; Password = env.SQLIP_A

env.SQLIP_D tasos";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = tasos";

//string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + "." + env.SQLIP_C + "." + env.SQLIP_D + ",1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database - diploma; User ID = antigoni; Password string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωγή και αποθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

IDbConnection dbcon = new SqlConnection(connectionstringMSSQLServer);

IDbCommand dbcmd = dbcon.CreateCoiranand();

dbcon.O p e n ();

while (reader.Read()) mystruct

.1

reader["username"].ToString();

mystruct.password = reader["pwd"].ToString();

)

reader.Close();

reader = null;

dbcmd.Dispose();

dbcmd = null;

dbcon.Close () ; dbcon = null;

}

catch (Exception e) {

MessageBox.Show(e.ToString());

}

return mystruct;

try {

string query = "INSERT INTO diploma.users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + "' , + pwi + "■, '" + first_name + "','" + last_name + "', ·" + birthdate + "');"

string connectionstringMySQL = "datasource=" + env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + "." + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;";

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης για την εξανωνή και αποθήκευση ρυθμίσεων νραφικού περιβάλλοντος εφαρμονών

}

catch (Exceptit

public bool CreateAccountOracle(string usr, string pwd, string first_name, string last_name, string birthdate, EnviromentSettings env)

{ try (

//string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + + pwd +

+ first_name + + last_name + "', + birthdate + string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ("' + usr + + pwd +

+ first_name + + last_name + to_date(" + birthdate H

",’YYYYMMDD'))";

//string connectionstringOracle = "Data Source=" + env. S Q L I P A + "." + e n v.SQLIPB + "." + env.SQ L I P C + "." + env.SQ L I P D + ";User ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new OracleConnection(connectionstringOracle);

dbcmd.CommandText = query;

dbcmd.ExecuteScalar0 ; MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close 0 ; dbcon = null;

}

catch (Exception e)

public bool CreateAccountMSSQLServer(string usr, string pwd, string first_name, string last_name, string birthdate,

EnviromentSettings env)

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και ατχοθήκευση ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών

string query = "INSERT INTO users(username, pwd, first_name, last_name, birthdate) VALUES ('" + usr + + pwd +

+ first_name + + last_name + + birthdate + //string connectionstringMSSQLServer = "Server =" + env.SQLIP_A + + env.SQLIP_B + "." + env.SQLIP_C + + env.SQLIP_D + Database = diploma; User ID = antigoni; Password =

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = //string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + "." + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP D + ", 1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos;";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database = diploma; User ID = antigoni; Password string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

IDbConnection dbcon = new SqlConnection(connectionstringMSSQLServer) ;

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Ope n ();

MessageBox.Show("User Created!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close();

dbcon = null;

return true;

)

catch (Exception e)

public bool DeleteAccountMySQL(string usr, string pwd, string lame, string last_name, string birthdate, EnviromentSettings

string query = usr + "' AND pwd = '" + pwd H ' AND last_name = "' + last_n;

’DELETE FROM users WHERE username = '"

"' AND first_ncime = '" + first_name + t\e + "' AND birthdate = '" + birthdate

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουρνία δυναμικής βιβλιοθήκης yia την εξανωνή και αποθήκευση ρυθμίσεων νραφικσύ περιβάλλοντος εφαρμογών

string connectionstringMySQL = "datasource=" + env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";username=antigoni;password=tasos;database=diploma;'

IDbConnection dbcon = new MySqlConnection(connectionstringMySQL);

IDbConunand dbcmd = dbcon.CreateCommand() ; dbcon.Ope n () ;

MessageBox.Sh o w ("User Deleted!");

dbcmd.Dispose{) ; dbcmd = null;

dbcon.Close();

dbcon = null;

return true;

}

catch (Exception e) {

MessageBox.Show(e.Message);

return false;

public bool DeleteAccountOracle(string usr, string pwd, string first_name, string last_name, string birthdate, EnviromentSettings env)

{ try {

string query = "DELETE FROM users WHERE username = + usr + "' AND pwd = '" + pwd + "' AND f irst_name = '" + first_naii AND last_name = "' + last_name + AND birthdate = to_date(" H birthdate + ",'YYYYMMDD')";

//string connectionstringOracle = "Data Source=" h env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ";Oser ID=antigoni;Password=tasos";

string connectionstringOracle = "Data Source=diploma;User ID=antigoni;Password=tasos";

IDbConnection dbcon = new OracleConnection(connectionstringOracle);

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

MessageBox.Show("User Deleted!");

dbcmd.Dispose();

dbcmd = null;

dbcon.Close 0 ; dbcon = null;

return true;

Τμήμα Βιομηχανικής Πληροφορικής

Δημιουργία δυναμικής βιβλιοθήκης για την εξαγωγή και αποθήκευση ______________ρυθμίσεων γραφικού περιβάλλοντος εφαρμογών_____________

catch (Exception e)

public bool DeleteAocountMSSQLServer(string usr string first_name, string last_name, string birthdate, EnviromentSettings env)

string query = "DELETE FROM users WHERE username = '"

usr + "' AND pwd = " ’ + pwd + "' AND first_name = '" + first_name + ' AND last_name = '" + last_name + "' AND birthdate = '" + birthdate

//string connectionstringMSSQLServer = + env.SQLIP_B + + env.SQLIP_C + + Database = diploma; User ID = antigoni; Password =

"Server =" - env.SQLIP_A -(

env.SQLIP_D ■(

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = tasos; Password = antigoni";

//string connectionstringMSSQLServer = "Server

=localhost; Database = diploma; User ID = antigoni; Password = //string connectionstringMSSQLServer = "Data Source="

+ env.SQLIP_A + + env.SQLIP_B + + env.SQLIP_C + + env.SQLIP_D + ",1433;Network Library=DBMSSOCN;Initial Catalog=diploma;User ID=antigoni;Password=tasos; ";

//string connectionstringMSSQLServer = "Server

=laptop\\sqlexpress; Database = diploma; User ID = antigoni; Password string connectionstringMSSQLServer = "Server =" + env.DatabaseName + "; Database = diploma; User ID = antigoni;

Password = tasos";

IDbConnection dbcon = new

SqlConnection(connectionstringMSSQLServer); //Default connection is MySQL;

IDbCommand dbcmd = dbcon.CreateCommand();

dbcon.Open();

dbcmd.CommandText = query;

dbcmd.ExecuteReader() ; MessageBox.Show("User Deleted!");

dbcmd.Dispose() ; dbcmd = null;

dbcon.Close();

dbcon = null;

return true;

}

catch (Exception e)

Τμήμα Βιομηχανικής Πληροφορικής

Documentos relacionados