Ok la maggior parte dei problemi li ho risolti.. vi posto i codici dei due Form:
Form 1
Codice PHP:
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 MySQLDriverCS;
using System.Configuration;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
string host = ConfigurationSettings.AppSettings["host"];
string muser = ConfigurationSettings.AppSettings["muser"];
string mpsw = ConfigurationSettings.AppSettings["mpsw"];
string db = ConfigurationSettings.AppSettings["db"];
string port = ConfigurationSettings.AppSettings["port"];
MySQLConnection conn = new MySQLConnection("Location="+host+";User ID="+muser+";Password="+mpsw+";Data Source="+db+";Port="+port+"");
string user = textBox1.Text;
string psw = textBox2.Text;
MySQLCommand cmd = new MySQLCommand("SELECT pwd FROM D_users WHERE ( user = \"" + user + "\" )", conn);
string prova = "";
try
{
conn.Open();
MySQLDataReader mread = cmd.ExecuteReaderEx();
while (mread.Read())
{
prova = mread.GetString(0);
}
}
catch (Exception g)
{
MessageBox.Show("Errore : " + g + "");
}
if (psw == "")
{
MessageBox.Show("La password inserita non corrisponde all'username, prova a correggere i dati o contatta l'amministratore");
}
else if (psw == prova)
{
Form2 frm = new Form2();
frm.ver = true;
frm.controllo();
this.Close();
}
else
{
MessageBox.Show("La password inserita non corrisponde all'username, prova a correggere i dati o contatta l'amministratore");
}
}
private void button1_Click(object sender, EventArgs e)
{
Form3 frm = new Form3();
frm.Show();
}
}
}
Form 2:
Codice PHP:
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 MySQLDriverCS;
using System.Configuration;
namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
public bool ver;
public void controllo()
{
if (ver == false)
{
MessageBox.Show("Non hai effettuato il login" + "\r\n" + "Non hai i diritti necessari per effettuare una ricerca");
this.Close();
}
}
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Form1 frm1 = new Form1();
frm1.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
this.controllo();
string host = ConfigurationSettings.AppSettings["host"];
string muser = ConfigurationSettings.AppSettings["muser"];
string mpsw = ConfigurationSettings.AppSettings["mpsw"];
string db = ConfigurationSettings.AppSettings["db"];
string port = ConfigurationSettings.AppSettings["port"];
MySQLConnection conn = new MySQLConnection("Location=" + host + ";User ID=" + muser + ";Password=" + mpsw + ";Data Source=" + db + ";Port=" + port + "");
decimal tmp = numericUpDown1.Value;
int dd = Convert.ToInt32(tmp);
tmp = numericUpDown2.Value;
int mm = Convert.ToInt32(tmp);
tmp = numericUpDown3.Value;
int aa = Convert.ToInt32(tmp);
string testo = "";
string temp;
string riga = "=================";
MySQLCommand cmd = new MySQLCommand("SELECT materia,compiti FROM d_compiti WHERE ( giorno = \"" + aa + "-" + mm + "-" + dd + "\" )", conn);
try
{
conn.Open();
MySQLDataReader mread = cmd.ExecuteReaderEx();
while (mread.Read())
{
temp = mread.GetString(0);
testo = (testo+"\r\n"+temp+":\r\n");
temp = mread.GetString(1);
testo = (testo + "\r\n" + temp + "\r\n" +riga );
}
textBox1.Text = testo;
}
catch (Exception g)
{
MessageBox.Show("Errore : " + g + "");
}
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
}
}
}
Il problema č che, una volta effettuato il login il form2 , non imposta la bool ver su true..
Probabilmente sbaglio su come si passa una variabile valorizzata da un form all'altro.. ma cercando su internet mi sembrava si facesse proprio cosė....