|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
[C#]LoginForm e MainForm
Salve a tutti
![]() Allora, ho questa situazione: 1 form di login 1 main form Vorrei che dopo aver effettuato il login sull'apposito form, il main form venisse abilitato. I tre sorgenti sono: Codice:
//Program.cs using System; using System.Collections.Generic; using System.Windows.Forms; namespace TestPSql { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } } } Codice:
//MainForm.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace TestPSql { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { this.Enabled = false; LoginForm f = new LoginForm(); f.ShowDialog(); } } } Codice:
//LoginForm.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Text; using System.Windows.Forms; namespace TestPSql { public partial class LoginForm : Form { public LoginForm() { InitializeComponent(); } private bool IsNotEmpty(TextBox t) { if (t.Text.Length == 0) { LoginError.SetError(t, "CAMPO OBBLIGATORIO"); return false; } else { LoginError.SetError(t, ""); return true; } } private void btnLogin_Click(object sender, EventArgs e) { if (IsNotEmpty(txtUserName) && IsNotEmpty(txtPassword)) { try { DbConnection db = new DbConnection(); using (Npgsql.NpgsqlConnection cn = new Npgsql.NpgsqlConnection(db.ConnectionString)) { cn.Open(); Npgsql.NpgsqlParameter[] p = new Npgsql.NpgsqlParameter[2]; p[0] = new Npgsql.NpgsqlParameter("@user", DbType.String); p[0].Value = txtUserName.Text; p[1] = new Npgsql.NpgsqlParameter("@password", DbType.String); p[1].Value = txtPassword.Text; string loginString = "SELECT COUNT(id_operatore) FROM t_operatori WHERE username = @user AND password = md5(@password)"; Npgsql.NpgsqlCommand cmd = new Npgsql.NpgsqlCommand(loginString, cn); foreach (Npgsql.NpgsqlParameter par in p) { cmd.Parameters.Add(par); } int i = Int32.Parse(cmd.ExecuteScalar().ToString()); if (i > 0) { LoginError.SetError(panError, ""); this.Close(); } else { LoginError.SetError(panError, "AUTENTICAZIONE FALLITA"); } } } catch (Npgsql.NpgsqlException ex) { LoginError.SetError(panError, ex.ErrorSql); } } } private void btnCancel_Click(object sender, EventArgs e) { Application.Exit(); } } } ![]() RaouL.
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek ![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
mmm.. al momento ho risolto così:
Codice:
foreach(Form f in Application.OpenForms) { if(f.IsMdiContainer && !f.IsDisposed) { f.Enabled = true; } } ![]() RaouL.
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 18:14.