How do I create a login form to open the next appropriate form?

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 1
Reputation: Rraeyinde is an unknown quantity at this point 
Solved Threads: 0
Rraeyinde Rraeyinde is offline Offline
Newbie Poster

How do I create a login form to open the next appropriate form?

 
0
  #1
Oct 5th, 2008
Hi guys. This is a cry for help from a desperate student!!! I don't expect you to do this for me I just need my mistake to be pointed out to me.

I'm creating a c# application which acts as a learning program to be used by teachers and learners. The teachers use it for their admin tasks and the learners use it for practising maths excercises. But before they can get to that they need to login to open the appropriate task window.

I have created two tabkes in Access one for teachers one for learners. The tables both contain the columns LogID, Name, Surname, Password, Class. The login form I've created requests the logId AND the password. and there is a combobox were the user can select whether they are a teacher or a learner.

what I want to do is ,when the Log in button is clicked, if the teacher option is selected in the combobox I want the program to check if the logid and password is in the same row in the teacherlog table in my database. and the same for the appropriate table if learner is selected in the combobox.

if the logid and password does exist then I want the next form to be opened for the user. If the user is a teacher the Teachers administration form should be opened, and if the user is a learner the learners task form should be opened.

NB. I have to use Visual Studio 2005, I must program in C#, I have to use ADO.net

Also please note that I am new to any form of programming language, C# being the first language I have learnt, so I am well aware that my mistake or rather problem is probably something that is simple for an experienced programmer. THANK YOU in advance for any help that is offered, it is really going to be appreciated.

the code that I am going to include shows no errors but it won't open the next form once I click the log in button.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Data.OleDb;
  9.  
  10. namespace MathsNumeracy
  11. {
  12. public partial class LogIn : Form
  13. {
  14. private string sConnection;
  15. private OleDbConnection dbConn;
  16. private OleDbCommand dbCmd;
  17. private Learner1 aLearner;
  18. private Teacher1 aTeacher;
  19. private OleDbDataReader dbReader;
  20. private string sql;
  21.  
  22.  
  23. public LogIn()
  24. {
  25. InitializeComponent();
  26. }
  27.  
  28. private void btnPrevious_Click(object sender, EventArgs e)
  29. {
  30. Form1 start = new Form1();
  31. this.Hide();
  32. start.ShowDialog();
  33. }
  34.  
  35. private void btnLogIn_Click(object sender, EventArgs e)
  36. {
  37. try
  38. {
  39. sConnection = "Provider = Microsoft.Jet.OLEDB.4.0;" +
  40. "DataSource = MathsNumeracy.mdb";
  41. dbConn = new OleDbConnection(sConnection);
  42. dbConn.Open();
  43.  
  44. if (cmbStatus.Text.ToString() == "Teacher")
  45. {
  46. sql = "Select LogID, Password From TeacherLog;";
  47. dbCmd = new OleDbCommand();
  48. dbCmd.CommandText = sql;
  49. dbCmd.Connection = dbConn;
  50.  
  51. dbReader = dbCmd.ExecuteReader();
  52.  
  53. while (dbReader.Read())
  54. {
  55. aTeacher = new Teacher1(dbReader["LogID"].ToString(),dbReader["Name"].ToString(),dbReader["Surname"].ToString(), dbReader["Password"].ToString(), dbReader["Class"].ToString());
  56. if ((dbReader["LogID"].ToString() == txtLogID.Text) && (dbReader["Password"].ToString() == txtPassword.Text))
  57. {
  58. TeacherAdmin tAdmin = new TeacherAdmin();
  59. this.Hide();
  60. tAdmin.ShowDialog();
  61. this.Show();
  62. }
  63.  
  64. }
  65.  
  66.  
  67. }
  68. else
  69. if (cmbStatus.Text.ToString() == "Learner")
  70. {
  71. sql = "Select * From LearnerLog;";
  72. dbCmd = new OleDbCommand();
  73. dbCmd.CommandText = sql;
  74. dbCmd.Connection = dbConn;
  75.  
  76. dbReader = dbCmd.ExecuteReader();
  77.  
  78. while (dbReader.Read())
  79. {
  80. aLearner = new Learner1(dbReader["LogID"].ToString(), dbReader["Name"].ToString(), dbReader["Surname"].ToString(), dbReader["Password"].ToString(), dbReader["Class"].ToString());
  81.  
  82. if ((dbReader["LogID"].ToString() == txtLogID.Text) && (dbReader["Password"].ToString() == txtPassword.Text))
  83. {
  84. LearnerTasks lTasks = new LearnerTasks();
  85. this.Hide();
  86. lTasks.ShowDialog();
  87. this.Show();
  88. }
  89. }
  90.  
  91.  
  92. }
  93. dbReader.Close();
  94. dbConn.Close();
  95. }
  96. catch(System.Exception exc)
  97. {
  98. this.lblError.Text = exc.Message;
  99. }
  100. }
  101.  
  102.  
  103. }
  104. }

ANY HELP WILL BE APPRECIATED ESPECIALLY SINCE I HAVE A DEADLINE FAST APPROACHING AND I STILL NEED TO FINISH MY OTHER CODING.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: How do I create a login form to open the next appropriate form?

 
0
  #2
Oct 5th, 2008
Then I would suggest you use the debug and step through your code, as it implies its not reaching the stage where it would show the dialogs you're expecting.

It would be easier to see in debug mode as to why it doesnt work as it will show you the values of everything
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 6
Reputation: okutbay is an unknown quantity at this point 
Solved Threads: 0
okutbay okutbay is offline Offline
Newbie Poster

Re: How do I create a login form to open the next appropriate form?

 
0
  #3
Oct 5th, 2008
first i think its a bad idea using try catchs while you were learning... let the errors blow your program... )

comment the unsuspected or unnecessary code...

check your code line by line as you are a debugger... Check all possible ways...

if you are sure the code is right that shows the form then you have problem with if statements...

debugging is always the key...

p.s.: i'm not a windows programmer... but i think you can try show the form first... then later close (or hide) the opener form...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1419 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC