Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 111 characters in body
Source Link
lemunk
  • 2.7k
  • 14
  • 59
  • 89
namespace RepSalesNetAnalysis { public partial class LoginForm : Form { public bool letsGO = false; public LoginForm() { InitializeComponent(); } private static DataTable LookupUser(string Username) { const string connStr = "Server=10asaf;" + "Database=dfafa;" + "uid=bufaf;" + "pwd=dridfsdf;" + "Connect Timdf0;"; //"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select password From dbo.UserTable (NOLOCK) Where UserName = @UserName"; DataTable result = new DataTable(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Username; using (SqlDataReader dr = cmd.ExecuteReader()) { result.Load(dr); } } } return result; } private void buttonLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textUser.Text)) { //Focus box before showing a message textUser.Focus(); MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); //Focus again afterwards, sometimes people double click message boxes and select another control accidentally textUser.Focus(); return; } else if (string.IsNullOrEmpty(textPass.Text)) { textPass.Focus(); MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } //OK they enter a user and pass, lets see if they can authenticate using (DataTable dt = LookupUser(textUser.Text)) { if (dt.Rows.Count == 0) { textUser.Focus(); MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textUser.Focus(); return; } else { string dbPassword = Convert.ToString(dt.Rows[0]["Password"]); string appPassword = Convert.ToString(textPass.Text); //we store the password as encrypted in the DB //MessageBox.Show Console.WriteLine(string.Compare(dbPassword, appPassword)); if (string.Compare(dbPassword, appPassword) == 0) { //LOAD FORM1 here!!! //hide this form hmmm   Form1 formDialogResult = new Form1();DialogResult.OK; form this.ShowClose(); } else { //You may want to use the same error message so they can't tell which field they got wrong textPass.Focus(); MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } } } } } 
namespace RepSalesNetAnalysis { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LoginForm fLogin = new LoginForm(); if (fLogin.ShowDialog() == DialogResult.OK) { Application.Run(new LoginFormForm1()); } else { Application.Exit(); } } } } 
namespace RepSalesNetAnalysis { public partial class LoginForm : Form { public bool letsGO = false; public LoginForm() { InitializeComponent(); } private static DataTable LookupUser(string Username) { const string connStr = "Server=10asaf;" + "Database=dfafa;" + "uid=bufaf;" + "pwd=dridfsdf;" + "Connect Timdf0;"; //"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select password From dbo.UserTable (NOLOCK) Where UserName = @UserName"; DataTable result = new DataTable(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Username; using (SqlDataReader dr = cmd.ExecuteReader()) { result.Load(dr); } } } return result; } private void buttonLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textUser.Text)) { //Focus box before showing a message textUser.Focus(); MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); //Focus again afterwards, sometimes people double click message boxes and select another control accidentally textUser.Focus(); return; } else if (string.IsNullOrEmpty(textPass.Text)) { textPass.Focus(); MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } //OK they enter a user and pass, lets see if they can authenticate using (DataTable dt = LookupUser(textUser.Text)) { if (dt.Rows.Count == 0) { textUser.Focus(); MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textUser.Focus(); return; } else { string dbPassword = Convert.ToString(dt.Rows[0]["Password"]); string appPassword = Convert.ToString(textPass.Text); //we store the password as encrypted in the DB //MessageBox.Show Console.WriteLine(string.Compare(dbPassword, appPassword)); if (string.Compare(dbPassword, appPassword) == 0) { //LOAD FORM1 here!!! //hide this form hmmm   Form1 form = new Form1(); form.Show(); } else { //You may want to use the same error message so they can't tell which field they got wrong textPass.Focus(); MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } } } } } 
namespace RepSalesNetAnalysis { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm()); } } } 
namespace RepSalesNetAnalysis { public partial class LoginForm : Form { public bool letsGO = false; public LoginForm() { InitializeComponent(); } private static DataTable LookupUser(string Username) { const string connStr = "Server=10asaf;" + "Database=dfafa;" + "uid=bufaf;" + "pwd=dridfsdf;" + "Connect Timdf0;"; //"Data Source=apex2006sql;Initial Catalog=Leather;Integrated Security=True;"; const string query = "Select password From dbo.UserTable (NOLOCK) Where UserName = @UserName"; DataTable result = new DataTable(); using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(query, conn)) { cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = Username; using (SqlDataReader dr = cmd.ExecuteReader()) { result.Load(dr); } } } return result; } private void buttonLogin_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textUser.Text)) { //Focus box before showing a message textUser.Focus(); MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); //Focus again afterwards, sometimes people double click message boxes and select another control accidentally textUser.Focus(); return; } else if (string.IsNullOrEmpty(textPass.Text)) { textPass.Focus(); MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } //OK they enter a user and pass, lets see if they can authenticate using (DataTable dt = LookupUser(textUser.Text)) { if (dt.Rows.Count == 0) { textUser.Focus(); MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); textUser.Focus(); return; } else { string dbPassword = Convert.ToString(dt.Rows[0]["Password"]); string appPassword = Convert.ToString(textPass.Text); //we store the password as encrypted in the DB //MessageBox.Show Console.WriteLine(string.Compare(dbPassword, appPassword)); if (string.Compare(dbPassword, appPassword) == 0) { DialogResult = DialogResult.OK;  this.Close(); } else { //You may want to use the same error message so they can't tell which field they got wrong textPass.Focus(); MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); textPass.Focus(); return; } } } } } 
namespace RepSalesNetAnalysis { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); LoginForm fLogin = new LoginForm(); if (fLogin.ShowDialog() == DialogResult.OK) { Application.Run(new Form1()); } else { Application.Exit(); } } } } 
added 1 characters in body
Source Link
Sathyajith Bhat
  • 22k
  • 22
  • 102
  • 141

iI have 3 classes: Form1, LoginForm and program.

What iI want it to do is hide loginform just before iI show form1.

howHow do iI do this since i cantI can't use loginform.hide();

here'sHere's code:

i have 3 classes: Form1, LoginForm and program.

What i want it to do is hide loginform just before i show form1.

how do i do this since i cant use loginform.hide();

here's code:

I have 3 classes: Form1, LoginForm and program.

What I want it to do is hide loginform just before I show form1.

How do I do this since I can't use loginform.hide();

Here's code:

deleted 32 characters in body
Source Link
John Saunders
  • 161.9k
  • 26
  • 252
  • 403

c# how to close this.form

hi guys i have 3 classes: Form1, LoginForm and program.

hereshere's code:

many thanks in advance!

c# how to close this.form

hi guys i have 3 classes: Form1, LoginForm and program.

heres code:

many thanks in advance!

how to close this.form

i have 3 classes: Form1, LoginForm and program.

here's code:

edited tags
Link
svick
  • 246.6k
  • 54
  • 407
  • 536
Loading
Source Link
lemunk
  • 2.7k
  • 14
  • 59
  • 89
Loading